MCPcopy Create free account
hub / github.com/cztomczak/cefpython / V8ObjectToCefDictionaryValue

Function V8ObjectToCefDictionaryValue

src/subprocess/v8utils.cpp:107–198  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

105}
106
107CefRefPtr<CefDictionaryValue> V8ObjectToCefDictionaryValue(
108 CefRefPtr<CefV8Value> v8Object,
109 int nestingLevel) {
110 if (!v8Object->IsValid()) {
111 LOG(ERROR) << "[Renderer process] V8ObjectToCefDictionaryValue():"
112 " IsValid() failed";
113 return CefDictionaryValue::Create();
114 }
115 if (nestingLevel > 8) {
116 LOG(ERROR) << "[Renderer process] V8ObjectToCefDictionaryValue():"
117 " max nesting level (8) exceeded";
118 return CefDictionaryValue::Create();
119 }
120 if (!v8Object->IsObject()) {
121 LOG(ERROR) << "[Renderer process] V8ObjectToCefDictionaryValue():"
122 " IsObject() failed";
123 return CefDictionaryValue::Create();
124 }
125 CefRefPtr<CefDictionaryValue> ret = CefDictionaryValue::Create();
126 std::vector<CefString> keys;
127 if (!v8Object->GetKeys(keys)) {
128 LOG(ERROR) << "[Renderer process] V8ObjectToCefDictionaryValue():"
129 " GetKeys() failed";
130 return ret;
131 }
132 for (std::vector<CefString>::iterator it = keys.begin(); \
133 it != keys.end(); ++it) {
134 CefString key = *it;
135 CefRefPtr<CefV8Value> v8Value = v8Object->GetValue(key);
136 if (v8Value->IsUndefined() || v8Value->IsNull()) {
137 ret->SetNull(key);
138 } else if (v8Value->IsBool()) {
139 ret->SetBool(key, v8Value->GetBoolValue());
140 } else if (v8Value->IsInt()) {
141 ret->SetInt(key, v8Value->GetIntValue());
142 } else if (v8Value->IsUInt()) {
143 uint32 uint32_value = v8Value->GetUIntValue();
144 CefRefPtr<CefBinaryValue> binaryValue = CefBinaryValue::Create(
145 &uint32_value, sizeof(uint32_value));
146 ret->SetBinary(key, binaryValue);
147 } else if (v8Value->IsDouble()) {
148 ret->SetDouble(key, v8Value->GetDoubleValue());
149 } else if (v8Value->IsDate()) {
150 // TODO: in time_utils.pyx there are already functions for
151 // converting cef_time_t to python DateTime, we could easily
152 // add a new function for converting the python DateTime to
153 // string and then to CefString and expose the function using
154 // the "public" keyword. But how do we get the cef_time_t
155 // structure from the CefTime class? GetDateValue() returns
156 // CefTime class.
157 ret->SetNull(key);
158 } else if (v8Value->IsString()) {
159 ret->SetString(key, v8Value->GetStringValue());
160 } else if (v8Value->IsArray()) {
161 // Check for IsArray() must happen before the IsObject() check.
162 int length = v8Value->GetArrayLength();
163 CefRefPtr<CefListValue> newListValue = CefListValue::Create();
164 for (int i = 0; i < length; ++i) {

Callers 1

Calls 2

PutJavascriptCallbackFunction · 0.85

Tested by

no test coverage detected