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

Function V8ValueAppendToCefListValue

src/subprocess/v8utils.cpp:32–105  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

30}
31
32void V8ValueAppendToCefListValue(CefRefPtr<CefV8Value> v8Value,
33 CefRefPtr<CefListValue> listValue,
34 int nestingLevel) {
35 if (!v8Value->IsValid()) {
36 LOG(ERROR) << "[Renderer process] V8ValueAppendToCefListValue():"
37 " IsValid() failed";
38 return;
39 }
40 if (nestingLevel > 8) {
41 LOG(ERROR) << "[Renderer process] V8ValueAppendToCefListValue():"
42 " max nesting level (8) exceeded";
43 return;
44 }
45 if (v8Value->IsUndefined() || v8Value->IsNull()) {
46 listValue->SetNull((int)listValue->GetSize());
47 } else if (v8Value->IsBool()) {
48 listValue->SetBool((int)listValue->GetSize(), v8Value->GetBoolValue());
49 } else if (v8Value->IsInt()) {
50 listValue->SetInt((int)listValue->GetSize(), v8Value->GetIntValue());
51 } else if (v8Value->IsUInt()) {
52 uint32 uint32_value = v8Value->GetUIntValue();
53 CefRefPtr<CefBinaryValue> binaryValue = CefBinaryValue::Create(
54 &uint32_value, sizeof(uint32_value));
55 listValue->SetBinary((int)listValue->GetSize(), binaryValue);
56 } else if (v8Value->IsDouble()) {
57 listValue->SetDouble((int)listValue->GetSize(),
58 v8Value->GetDoubleValue());
59 } else if (v8Value->IsDate()) {
60 // TODO: in time_utils.pyx there are already functions for
61 // converting cef_time_t to python DateTime, we could easily
62 // add a new function for converting the python DateTime to
63 // string and then to CefString and expose the function using
64 // the "public" keyword. But how do we get the cef_time_t
65 // structure from the CefTime class? GetDateValue() returns
66 // CefTime class.
67 listValue->SetNull((int)listValue->GetSize());
68 } else if (v8Value->IsString()) {
69 listValue->SetString((int)listValue->GetSize(), v8Value->GetStringValue());
70 } else if (v8Value->IsArray()) {
71 // Check for IsArray() must happen before the IsObject() check.
72 int length = v8Value->GetArrayLength();
73 CefRefPtr<CefListValue> newListValue = CefListValue::Create();
74 for (int i = 0; i < length; ++i) {
75 V8ValueAppendToCefListValue(v8Value->GetValue(i), newListValue,
76 nestingLevel + 1);
77 }
78 listValue->SetList((int)listValue->GetSize(), newListValue);
79 } else if (v8Value->IsFunction()) {
80 // Check for IsFunction() must happen before the IsObject() check.
81 if (CefV8Context::InContext()) {
82 CefRefPtr<CefV8Context> context = \
83 CefV8Context::GetCurrentContext();
84 CefRefPtr<CefFrame> frame = context->GetFrame();
85 std::string strCallbackId = PutJavascriptCallback(frame, v8Value);
86 /* strCallbackId = '####cefpython####' \
87 '{"what"=>"javascript-callback", ..}' */
88 listValue->SetString((int)listValue->GetSize(), strCallbackId);
89 } else {

Callers 2

Calls 2

PutJavascriptCallbackFunction · 0.85

Tested by

no test coverage detected