History

Added debug function to list object members

ksuprynowicz committed 3 years ago

Commit 5f2c13d1 parent ed968e14 files · +33 −2Browse files

Showing the changes to libraries/script-engine/src/v8/ScriptEngineV8.cpp (1 of 4 files). Show all

Unified · Split

libraries/script-engine/src/v8/ScriptEngineV8.cpp+29−0
@@ -821,6 +821,9 @@ ScriptValue ScriptEngineV8::evaluateInClosure(const ScriptValue& _closure, · 820 unmodified lines
821821
822822 ScriptValue result;
823823 //auto context = pushContext();
824+
825+ // V8TODO: a lot of functions rely on _v8Context, which was not updated here
826+ // It might cause trouble
824827 {
825828 v8::Context::Scope contextScope(closureContext);
826829 const V8ScriptValue& closure = unwrappedClosure->toV8Value();
@@ -1527,6 +1530,32 @@ QString ScriptEngineV8::scriptValueDebugDetails(const ScriptValue &value) { · 700 unmodified lines
15271530 return scriptValueDebugDetailsV8(v8Value);
15281531 }
15291532
1533+QString ScriptEngineV8::scriptValueDebugListMembers(const ScriptValue &value) {
1534+ V8ScriptValue v8Value = ScriptValueV8Wrapper::fullUnwrap(this, value);
1535+ return scriptValueDebugDetailsV8(v8Value);
1536+}
1537+
1538+QString ScriptEngineV8::scriptValueDebugListMembersV8(const V8ScriptValue &v8Value) {
1539+ v8::Locker locker(_v8Isolate);
1540+ v8::Isolate::Scope isolateScope(_v8Isolate);
1541+ v8::HandleScope handleScope(_v8Isolate);
1542+ v8::Context::Scope contextScope(getContext());
1543+
1544+ QString membersString("");
1545+ if (v8Value.constGet()->IsObject()) {
1546+ v8::Local<v8::String> membersStringV8;
1547+ v8::Local<v8::Object> object = v8::Local<v8::Object>::Cast(v8Value.constGet());
1548+ auto names = object->GetPropertyNames(getContext()).ToLocalChecked();
1549+ if (v8::JSON::Stringify(getContext(), object).ToLocal(&membersStringV8)) {
1550+ membersString = QString(*v8::String::Utf8Value(_v8Isolate, membersStringV8));
1551+ }
1552+ membersString = QString(*v8::String::Utf8Value(_v8Isolate, membersStringV8));
1553+ } else {
1554+ membersString = QString(" Is not an object");
1555+ }
1556+ return membersString;
1557+}
1558+
15301559 QString ScriptEngineV8::scriptValueDebugDetailsV8(const V8ScriptValue &v8Value) {
15311560 v8::Locker locker(_v8Isolate);
15321561 v8::Isolate::Scope isolateScope(_v8Isolate);

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t