History

fix some formatting

RTUnreal committed 9 months ago

Commit 5eeade71 parent 00e681b1 file · +37 −37Browse files

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

Unified · Split

libraries/script-engine/src/v8/ScriptEngineV8.cpp+37−37
@@ -436,48 +436,48 @@ void ScriptEngineV8::registerGetterSetter(ScriptEngineScopeGuard* scopeGuard, co · 435 unmodified lines
436436 Q_ASSERT(scopeGuard && dynamic_cast<ScriptEngineScopeGuardV8*>(scopeGuard));
437437 Q_ASSERT(QThread::currentThread() == thread());
438438
439− Q_ASSERT(_v8Isolate->IsCurrent());
440− v8::HandleScope handleScope(_v8Isolate);
441− auto context = getContext();
442− v8::Context::Scope contextScope(context);
439+ Q_ASSERT(_v8Isolate->IsCurrent());
440+ v8::HandleScope handleScope(_v8Isolate);
441+ auto context = getContext();
442+ v8::Context::Scope contextScope(context);
443443
444− ScriptValue setterFunction = newFunction(setter, 1);
445− ScriptValue getterFunction = newFunction(getter);
446− V8ScriptValue unwrappedGetter = ScriptValueV8Wrapper::fullUnwrap(this, getterFunction);
447− V8ScriptValue unwrappedSetter = ScriptValueV8Wrapper::fullUnwrap(this, setterFunction);
448− v8::PropertyDescriptor propertyDescriptor(unwrappedGetter.get(), unwrappedSetter.get());
449−
450− if (!parent.isNull() && !parent.isEmpty()) {
451− ScriptValue object = globalObject().property(parent);
452− if (object.isValid()) {
453− V8ScriptValue v8parent = ScriptValueV8Wrapper::fullUnwrap(this, object);
454− Q_ASSERT(v8parent.get()->IsObject());
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 {
444+ ScriptValue setterFunction = newFunction(setter, 1);
445+ ScriptValue getterFunction = newFunction(getter);
446+ V8ScriptValue unwrappedGetter = ScriptValueV8Wrapper::fullUnwrap(this, getterFunction);
447+ V8ScriptValue unwrappedSetter = ScriptValueV8Wrapper::fullUnwrap(this, setterFunction);
448+ v8::PropertyDescriptor propertyDescriptor(unwrappedGetter.get(), unwrappedSetter.get());
449+
450+ if (!parent.isNull() && !parent.isEmpty()) {
451+ ScriptValue object = globalObject().property(parent);
452+ if (object.isValid()) {
453+ V8ScriptValue v8parent = ScriptValueV8Wrapper::fullUnwrap(this, object);
454+ Q_ASSERT(v8parent.get()->IsObject());
455+ v8::Local<v8::Object> v8ParentObject = v8::Local<v8::Object>::Cast(v8parent.get());
475456 v8::Local<v8::String> v8propertyName =
476457 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";
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;
479465 }
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: ";
480473 }
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+ }
481481 }
482482
483483 v8::Local<v8::Context> ScriptEngineV8::getContext() {