Showing the changes to libraries/script-engine/src/v8/ScriptEngineV8.cpp (1 of 1 file). Show all
Unified · Split
| @@ -436,48 +436,48 @@ void ScriptEngineV8::registerGetterSetter(ScriptEngineScopeGuard* scopeGuard, co · 435 unmodified lines | |||
| 436 | Q_ASSERT(scopeGuard && dynamic_cast<ScriptEngineScopeGuardV8*>(scopeGuard)); | 436 | Q_ASSERT(scopeGuard && dynamic_cast<ScriptEngineScopeGuardV8*>(scopeGuard)); |
| 437 | Q_ASSERT(QThread::currentThread() == thread()); | 437 | Q_ASSERT(QThread::currentThread() == thread()); |
| 438 | 438 | ||
| 439 | Q_ASSERT(_v8Isolate->IsCurrent()); | 439 | Q_ASSERT(_v8Isolate->IsCurrent()); |
| 440 | v8::HandleScope handleScope(_v8Isolate); | 440 | v8::HandleScope handleScope(_v8Isolate); |
| 441 | auto context = getContext(); | 441 | auto context = getContext(); |
| 442 | v8::Context::Scope contextScope(context); | 442 | v8::Context::Scope contextScope(context); |
| 443 | 443 | ||
| 444 | ScriptValue setterFunction = newFunction(setter, 1); | 444 | ScriptValue setterFunction = newFunction(setter, 1); |
| 445 | ScriptValue getterFunction = newFunction(getter); | 445 | ScriptValue getterFunction = newFunction(getter); |
| 446 | V8ScriptValue unwrappedGetter = ScriptValueV8Wrapper::fullUnwrap(this, getterFunction); | 446 | V8ScriptValue unwrappedGetter = ScriptValueV8Wrapper::fullUnwrap(this, getterFunction); |
| 447 | V8ScriptValue unwrappedSetter = ScriptValueV8Wrapper::fullUnwrap(this, setterFunction); | 447 | V8ScriptValue unwrappedSetter = ScriptValueV8Wrapper::fullUnwrap(this, setterFunction); |
| 448 | v8::PropertyDescriptor propertyDescriptor(unwrappedGetter.get(), unwrappedSetter.get()); | 448 | v8::PropertyDescriptor propertyDescriptor(unwrappedGetter.get(), unwrappedSetter.get()); |
| 449 | 449 | ||
| 450 | if (!parent.isNull() && !parent.isEmpty()) { | 450 | if (!parent.isNull() && !parent.isEmpty()) { |
| 451 | ScriptValue object = globalObject().property(parent); | 451 | ScriptValue object = globalObject().property(parent); |
| 452 | if (object.isValid()) { | 452 | if (object.isValid()) { |
| 453 | V8ScriptValue v8parent = ScriptValueV8Wrapper::fullUnwrap(this, object); | 453 | V8ScriptValue v8parent = ScriptValueV8Wrapper::fullUnwrap(this, object); |
| 454 | Q_ASSERT(v8parent.get()->IsObject()); | 454 | Q_ASSERT(v8parent.get()->IsObject()); |
| 455 | v8::Local<v8::Object> v8ParentObject = v8::Local<v8::Object>::Cast(v8parent.get()); | 455 | v8::Local<v8::Object> v8ParentObject = v8::Local<v8::Object>::Cast(v8parent.get()); |
| 456 | v8::Local<v8::String> v8propertyName = | ||
| 457 | v8::String::NewFromUtf8(_v8Isolate, name.toStdString().c_str()).ToLocalChecked(); | ||
| 458 | v8::Local<v8::Object> v8ObjectToSetProperty; | ||
| 459 | ScriptObjectV8Proxy *proxy = ScriptObjectV8Proxy::unwrapProxy(V8ScriptValue(this, v8ParentObject)); | ||
| 460 | // If object is ScriptObjectV8Proxy, then setting property needs to be handled differently | ||
| 461 | if (proxy) { | ||
| 462 | v8ObjectToSetProperty = v8ParentObject->GetInternalField(2).As<v8::Object>(); | ||
| 463 | } else { | ||
| 464 | v8ObjectToSetProperty = v8ParentObject; | ||
| 465 | } | ||
| 466 | if (!v8ObjectToSetProperty->DefineProperty(context, v8propertyName, propertyDescriptor).FromMaybe(false)) { | ||
| 467 | qCDebug(scriptengine_v8) << "DefineProperty failed for registerGetterSetter \"" << name << "\" for parent: \"" | ||
| 468 | << parent << "\""; | ||
| 469 | } | ||
| 470 | } else { | ||
| 471 | qCDebug(scriptengine_v8) << "Parent object \"" << parent << "\" for registerGetterSetter \"" << name | ||
| 472 | << "\" is not valid: "; | ||
| 473 | } | ||
| 474 | } else { | ||
| 475 | v8::Local<v8::String> v8propertyName = | 456 | v8::Local<v8::String> v8propertyName = |
| 476 | v8::String::NewFromUtf8(_v8Isolate, name.toStdString().c_str()).ToLocalChecked(); | 457 | v8::String::NewFromUtf8(_v8Isolate, name.toStdString().c_str()).ToLocalChecked(); |
| 477 | if (!context->Global()->DefineProperty(context, v8propertyName, propertyDescriptor).FromMaybe(false)) { | 458 | v8::Local<v8::Object> v8ObjectToSetProperty; |
| 478 | qCDebug(scriptengine_v8) << "DefineProperty failed for registerGetterSetter \"" << name << "\" for global object"; | 459 | ScriptObjectV8Proxy *proxy = ScriptObjectV8Proxy::unwrapProxy(V8ScriptValue(this, v8ParentObject)); |
| 460 | // If object is ScriptObjectV8Proxy, then setting property needs to be handled differently | ||
| 461 | if (proxy) { | ||
| 462 | v8ObjectToSetProperty = v8ParentObject->GetInternalField(2).As<v8::Object>(); | ||
| 463 | } else { | ||
| 464 | v8ObjectToSetProperty = v8ParentObject; | ||
| 479 | } | 465 | } |
| 466 | if (!v8ObjectToSetProperty->DefineProperty(context, v8propertyName, propertyDescriptor).FromMaybe(false)) { | ||
| 467 | qCDebug(scriptengine_v8) << "DefineProperty failed for registerGetterSetter \"" << name << "\" for parent: \"" | ||
| 468 | << parent << "\""; | ||
| 469 | } | ||
| 470 | } else { | ||
| 471 | qCDebug(scriptengine_v8) << "Parent object \"" << parent << "\" for registerGetterSetter \"" << name | ||
| 472 | << "\" is not valid: "; | ||
| 480 | } | 473 | } |
| 474 | } else { | ||
| 475 | v8::Local<v8::String> v8propertyName = | ||
| 476 | v8::String::NewFromUtf8(_v8Isolate, name.toStdString().c_str()).ToLocalChecked(); | ||
| 477 | if (!context->Global()->DefineProperty(context, v8propertyName, propertyDescriptor).FromMaybe(false)) { | ||
| 478 | qCDebug(scriptengine_v8) << "DefineProperty failed for registerGetterSetter \"" << name << "\" for global object"; | ||
| 479 | } | ||
| 480 | } | ||
| 481 | } | 481 | } |
| 482 | 482 | ||
| 483 | v8::Local<v8::Context> ScriptEngineV8::getContext() { | 483 | v8::Local<v8::Context> ScriptEngineV8::getContext() { |