History

V8 QObject pointer handling changes

ksuprynowicz committed 3 years ago

Commit cae1e111 parent 5e5003f6 files · +72 −34Browse files

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

Unified · Split

libraries/script-engine/src/v8/ScriptObjectV8Proxy.cpp+61−24
@@ -66,6 +66,7 @@ private: // storage · 65 unmodified lines
6666 ScriptObjectV8Proxy::ScriptObjectV8Proxy(ScriptEngineV8* engine, QObject* object, bool ownsObject, const ScriptEngine::QObjectWrapOptions& options) :
6767 _engine(engine), _wrapOptions(options), _ownsObject(ownsObject), _object(object) {
6868 //_v8ObjectTemplate(engine->getIsolate(), v8::ObjectTemplate::New(engine->getIsolate())
69+ Q_ASSERT(_engine != nullptr);
6970 investigate();
7071 }
7172
@@ -451,21 +452,40 @@ void ScriptObjectV8Proxy::v8Get(v8::Local<v8::Name> name, const v8::PropertyCall · 379 unmodified lines
451452 return;
452453 }
453454 V8ScriptValue object(proxy->_engine, objectV8);
454− Q_ASSERT(name->IsString());
455− V8ScriptString nameString(proxy->_engine, v8::Local<v8::String>::Cast(name));
456− uint id;
457− QueryFlags flags = proxy->queryProperty(object, nameString, HandlesReadAccess, &id);
458− if (flags) {
459− V8ScriptValue value = proxy->property(object, nameString, id);
460− info.GetReturnValue().Set(value.get());
455+ if (!name->IsString() && !name->IsSymbol()) {
456+ QString notStringMessage("ScriptObjectV8Proxy::v8Get: " + proxy->_engine->scriptValueDebugDetailsV8(V8ScriptValue(proxy->_engine, name)));
457+ qDebug(scriptengine) << notStringMessage;
458+ Q_ASSERT(false);
459+ }
460+ v8::Local<v8::String> v8NameString;
461+ /*if (name->IsString()) {
462+ v8NameString = v8::Local<v8::String>::Cast(name);
461463 } else {
462− v8::Local<v8::Value> property;
463− if(info.This()->GetInternalField(2).As<v8::Object>()->Get(proxy->_engine->getContext(), name).ToLocal(&property)) {
464− info.GetReturnValue().Set(property);
465− } else {
466− qDebug(scriptengine) << "Value not found: " << *utf8Value;
464+ if (!name->ToString(info.GetIsolate()->GetCurrentContext()).ToLocal(&v8NameString)) {
465+ Q_ASSERT(false);
467466 }
468467 }
468+
469+ if (name->IsSymbol()) {
470+ qDebug(scriptengine) << "ScriptObjectV8Proxy::v8Set: symbol: " + nameString.toQString();
471+ }*/
472+ if (name->IsString()) {
473+ V8ScriptString nameString(proxy->_engine, v8::Local<v8::String>::Cast(name));
474+ uint id;
475+ QueryFlags flags = proxy->queryProperty(object, nameString, HandlesReadAccess, &id);
476+ if (flags) {
477+ V8ScriptValue value = proxy->property(object, nameString, id);
478+ info.GetReturnValue().Set(value.get());
479+ return;
480+ }
481+ }
482+
483+ v8::Local<v8::Value> property;
484+ if(info.This()->GetInternalField(2).As<v8::Object>()->Get(proxy->_engine->getContext(), name).ToLocal(&property)) {
485+ info.GetReturnValue().Set(property);
486+ } else {
487+ qDebug(scriptengine) << "Value not found: " << *utf8Value;
488+ }
469489 }
470490
471491 void ScriptObjectV8Proxy::v8Set(v8::Local<v8::Name> name, v8::Local<v8::Value> value, const v8::PropertyCallbackInfo<v8::Value>& info) {
@@ -480,22 +500,39 @@ void ScriptObjectV8Proxy::v8Set(v8::Local<v8::Name> name, v8::Local<v8::Value> v · 8 unmodified lines
480500 return;
481501 }
482502 V8ScriptValue object(proxy->_engine, objectV8);
483− Q_ASSERT(name->IsString());
484− V8ScriptString nameString(proxy->_engine, v8::Local<v8::String>::Cast(name));
485− //V8ScriptString nameString(info.GetIsolate(), name->ToString(proxy->_engine->getContext()).ToLocalChecked());
486− uint id;
487− QueryFlags flags = proxy->queryProperty(object, nameString, HandlesWriteAccess, &id);
488− if (flags) {
489− proxy->setProperty(object, nameString, id, V8ScriptValue(proxy->_engine, value));
490− info.GetReturnValue().Set(value);
503+ if (!name->IsString() && !name->IsSymbol()) {
504+ QString notStringMessage("ScriptObjectV8Proxy::v8Set: " + proxy->_engine->scriptValueDebugDetailsV8(V8ScriptValue(proxy->_engine, name)));
505+ qDebug(scriptengine) << notStringMessage;
506+ Q_ASSERT(false);
507+ }
508+ /*v8::Local<v8::String> v8NameString;
509+ if (name->IsString()) {
510+ v8NameString = v8::Local<v8::String>::Cast(name);
491511 } else {
492− // V8TODO: Should it be v8::Object or v8::Local<v8::Object>?
493− if (info.This()->GetInternalField(2).As<v8::Object>()->Set(proxy->_engine->getContext(), name, value).FromMaybe(false)) {
512+ if (!name->ToString(info.GetIsolate()->GetCurrentContext()).ToLocal(&v8NameString)) {
513+ Q_ASSERT(false);
514+ }
515+ }
516+ if (name->IsSymbol()) {
517+ qDebug(scriptengine) << "ScriptObjectV8Proxy::v8Set: symbol: " + nameString.toQString();
518+ }*/
519+ //V8ScriptString nameString(info.GetIsolate(), name->ToString(proxy->_engine->getContext()).ToLocalChecked());
520+ if (name->IsString()) {
521+ V8ScriptString nameString(proxy->_engine, v8::Local<v8::String>::Cast(name));
522+ uint id;
523+ QueryFlags flags = proxy->queryProperty(object, nameString, HandlesWriteAccess, &id);
524+ if (flags) {
525+ proxy->setProperty(object, nameString, id, V8ScriptValue(proxy->_engine, value));
494526 info.GetReturnValue().Set(value);
495− } else {
496− qDebug(scriptengine) << "Set failed: " << *utf8Value;
527+ return;
497528 }
498529 }
530+ // V8TODO: Should it be v8::Object or v8::Local<v8::Object>?
531+ if (info.This()->GetInternalField(2).As<v8::Object>()->Set(proxy->_engine->getContext(), name, value).FromMaybe(false)) {
532+ info.GetReturnValue().Set(value);
533+ } else {
534+ qDebug(scriptengine) << "Set failed: " << *utf8Value;
535+ }
499536 }
500537
501538 void ScriptObjectV8Proxy::v8GetPropertyNames(const v8::PropertyCallbackInfo<v8::Array>& info) {