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
66ScriptObjectV8Proxy::ScriptObjectV8Proxy(ScriptEngineV8* engine, QObject* object, bool ownsObject, const ScriptEngine::QObjectWrapOptions& options) :66ScriptObjectV8Proxy::ScriptObjectV8Proxy(ScriptEngineV8* engine, QObject* object, bool ownsObject, const ScriptEngine::QObjectWrapOptions& options) :
67 _engine(engine), _wrapOptions(options), _ownsObject(ownsObject), _object(object) {67 _engine(engine), _wrapOptions(options), _ownsObject(ownsObject), _object(object) {
68 //_v8ObjectTemplate(engine->getIsolate(), v8::ObjectTemplate::New(engine->getIsolate())68 //_v8ObjectTemplate(engine->getIsolate(), v8::ObjectTemplate::New(engine->getIsolate())
69 Q_ASSERT(_engine != nullptr);
69 investigate();70 investigate();
70}71}
71 72
@@ -451,21 +452,40 @@ void ScriptObjectV8Proxy::v8Get(v8::Local<v8::Name> name, const v8::PropertyCall · 379 unmodified lines
451 return;452 return;
452 }453 }
453 V8ScriptValue object(proxy->_engine, objectV8);454 V8ScriptValue object(proxy->_engine, objectV8);
454 Q_ASSERT(name->IsString());455 if (!name->IsString() && !name->IsSymbol()) {
455 V8ScriptString nameString(proxy->_engine, v8::Local<v8::String>::Cast(name));456 QString notStringMessage("ScriptObjectV8Proxy::v8Get: " + proxy->_engine->scriptValueDebugDetailsV8(V8ScriptValue(proxy->_engine, name)));
456 uint id;457 qDebug(scriptengine) << notStringMessage;
457 QueryFlags flags = proxy->queryProperty(object, nameString, HandlesReadAccess, &id);458 Q_ASSERT(false);
458 if (flags) {459 }
459 V8ScriptValue value = proxy->property(object, nameString, id);460 v8::Local<v8::String> v8NameString;
460 info.GetReturnValue().Set(value.get());461 /*if (name->IsString()) {
462 v8NameString = v8::Local<v8::String>::Cast(name);
461 } else {463 } else {
462 v8::Local<v8::Value> property;464 if (!name->ToString(info.GetIsolate()->GetCurrentContext()).ToLocal(&v8NameString)) {
463 if(info.This()->GetInternalField(2).As<v8::Object>()->Get(proxy->_engine->getContext(), name).ToLocal(&property)) {465 Q_ASSERT(false);
464 info.GetReturnValue().Set(property);
465 } else {
466 qDebug(scriptengine) << "Value not found: " << *utf8Value;
467 }466 }
468 }467 }
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 }
469}489}
470 490
471void ScriptObjectV8Proxy::v8Set(v8::Local<v8::Name> name, v8::Local<v8::Value> value, const v8::PropertyCallbackInfo<v8::Value>& info) {491void 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
480 return;500 return;
481 }501 }
482 V8ScriptValue object(proxy->_engine, objectV8);502 V8ScriptValue object(proxy->_engine, objectV8);
483 Q_ASSERT(name->IsString());503 if (!name->IsString() && !name->IsSymbol()) {
484 V8ScriptString nameString(proxy->_engine, v8::Local<v8::String>::Cast(name));504 QString notStringMessage("ScriptObjectV8Proxy::v8Set: " + proxy->_engine->scriptValueDebugDetailsV8(V8ScriptValue(proxy->_engine, name)));
485 //V8ScriptString nameString(info.GetIsolate(), name->ToString(proxy->_engine->getContext()).ToLocalChecked());505 qDebug(scriptengine) << notStringMessage;
486 uint id;506 Q_ASSERT(false);
487 QueryFlags flags = proxy->queryProperty(object, nameString, HandlesWriteAccess, &id);507 }
488 if (flags) {508 /*v8::Local<v8::String> v8NameString;
489 proxy->setProperty(object, nameString, id, V8ScriptValue(proxy->_engine, value));509 if (name->IsString()) {
490 info.GetReturnValue().Set(value);510 v8NameString = v8::Local<v8::String>::Cast(name);
491 } else {511 } else {
492 // V8TODO: Should it be v8::Object or v8::Local<v8::Object>?512 if (!name->ToString(info.GetIsolate()->GetCurrentContext()).ToLocal(&v8NameString)) {
493 if (info.This()->GetInternalField(2).As<v8::Object>()->Set(proxy->_engine->getContext(), name, value).FromMaybe(false)) {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));
494 info.GetReturnValue().Set(value);526 info.GetReturnValue().Set(value);
495 } else {527 return;
496 qDebug(scriptengine) << "Set failed: " << *utf8Value;
497 }528 }
498 }529 }
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 }
499}536}
500 537
501void ScriptObjectV8Proxy::v8GetPropertyNames(const v8::PropertyCallbackInfo<v8::Array>& info) {538void ScriptObjectV8Proxy::v8GetPropertyNames(const v8::PropertyCallbackInfo<v8::Array>& info) {