History

Added ScriptValue::getPropertyNames

ksuprynowicz committed 3 years ago

Commit ec3e87d1 parent e114d864 files · +40 −0Browse files

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

Unified · Split

libraries/script-engine/src/v8/ScriptValueV8Wrapper.cpp+27−0
@@ -454,6 +454,33 @@ bool ScriptValueV8Wrapper::strictlyEquals(const ScriptValue& other) const { · 453 unmodified lines
454 return unwrappedOther ? _value.constGet()->StrictEquals(unwrappedOther->toV8Value().constGet()) : false;454 return unwrappedOther ? _value.constGet()->StrictEquals(unwrappedOther->toV8Value().constGet()) : false;
455}455}
456 456
457inline QList<QString> ScriptValueV8Wrapper::getPropertyNames() const {
458 auto isolate = _engine->getIsolate();
459 v8::Locker locker(isolate);
460 v8::Isolate::Scope isolateScope(isolate);
461 v8::HandleScope handleScope(isolate);
462 auto context = _engine->getContext();
463 v8::Context::Scope contextScope(context);
464 v8::Local<v8::Value> value = _value.constGet();
465 if (value->IsNullOrUndefined()) {
466 return QList<QString>();
467 }
468 if (!value->IsObject()) {
469 return QList<QString>();
470 }
471 v8::Local<v8::Object> object = v8::Local<v8::Object>::Cast(value);
472 v8::Local<v8::Array> array;
473 if (!object->GetPropertyNames(context).ToLocal(&array)) {
474 return QList<QString>();
475 }
476 QList<QString> names;
477 for (uint32_t n = 0; n < array->Length(); n++) {
478 v8::Local<v8::String> name = array->Get(context, n).ToLocalChecked()->ToString(context).ToLocalChecked();
479 names.append(*v8::String::Utf8Value(isolate, name));
480 }
481 return names;
482}
483
457bool ScriptValueV8Wrapper::toBool() const {484bool ScriptValueV8Wrapper::toBool() const {
458 auto isolate = _engine->getIsolate();485 auto isolate = _engine->getIsolate();
459 v8::Locker locker(isolate);486 v8::Locker locker(isolate);

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