Title: [243995] releases/WebKitGTK/webkit-2.24/Source/_javascript_Core
Revision
243995
Author
carlo...@webkit.org
Date
2019-04-08 03:44:38 -0700 (Mon, 08 Apr 2019)

Log Message

Merge r243200 - [GLIB] Optimize jsc_value_object_define_property_data|accessor
https://bugs.webkit.org/show_bug.cgi?id=195679

Reviewed by Saam Barati.

Use direct C++ call instead of using the JSC GLib API to create the descriptor object and invoke Object.defineProperty().

* API/glib/JSCValue.cpp:
(jsc_value_object_define_property_data):
(jsc_value_object_define_property_accessor):

Modified Paths

Diff

Modified: releases/WebKitGTK/webkit-2.24/Source/_javascript_Core/API/APIUtils.h (243994 => 243995)


--- releases/WebKitGTK/webkit-2.24/Source/_javascript_Core/API/APIUtils.h	2019-04-08 10:44:34 UTC (rev 243994)
+++ releases/WebKitGTK/webkit-2.24/Source/_javascript_Core/API/APIUtils.h	2019-04-08 10:44:38 UTC (rev 243995)
@@ -57,7 +57,7 @@
     if (returnedExceptionRef)
         *returnedExceptionRef = toRef(exec, exception);
 #if ENABLE(REMOTE_INSPECTOR)
-    VM& vm = exec->vm();
+    JSC::VM& vm = exec->vm();
     vm.vmEntryGlobalObject(exec)->inspectorController().reportAPIException(exec, JSC::Exception::create(vm, exception));
 #endif
 }

Modified: releases/WebKitGTK/webkit-2.24/Source/_javascript_Core/API/glib/JSCValue.cpp (243994 => 243995)


--- releases/WebKitGTK/webkit-2.24/Source/_javascript_Core/API/glib/JSCValue.cpp	2019-04-08 10:44:34 UTC (rev 243994)
+++ releases/WebKitGTK/webkit-2.24/Source/_javascript_Core/API/glib/JSCValue.cpp	2019-04-08 10:44:38 UTC (rev 243995)
@@ -21,6 +21,7 @@
 #include "JSCValue.h"
 
 #include "APICast.h"
+#include "APIUtils.h"
 #include "JSCCallbackFunction.h"
 #include "JSCClassPrivate.h"
 #include "JSCContextPrivate.h"
@@ -1036,19 +1037,34 @@
     g_return_if_fail(propertyName);
 
     JSCValuePrivate* priv = value->priv;
-    GRefPtr<JSCValue> descriptor = adoptGRef(jsc_value_new_object(priv->context.get(), nullptr, nullptr));
-    GRefPtr<JSCValue> trueValue = adoptGRef(jsc_value_new_boolean(priv->context.get(), TRUE));
-    if (flags & JSC_VALUE_PROPERTY_CONFIGURABLE)
-        jsc_value_object_set_property(descriptor.get(), "configurable", trueValue.get());
-    if (flags & JSC_VALUE_PROPERTY_ENUMERABLE)
-        jsc_value_object_set_property(descriptor.get(), "enumerable", trueValue.get());
-    if (propertyValue)
-        jsc_value_object_set_property(descriptor.get(), "value", propertyValue);
-    if (flags & JSC_VALUE_PROPERTY_WRITABLE)
-        jsc_value_object_set_property(descriptor.get(), "writable", trueValue.get());
-    GRefPtr<JSCValue> object = adoptGRef(jsc_context_get_value(priv->context.get(), "Object"));
-    GRefPtr<JSCValue> result = adoptGRef(jsc_value_object_invoke_method(object.get(), "defineProperty",
-        JSC_TYPE_VALUE, value, G_TYPE_STRING, propertyName, JSC_TYPE_VALUE, descriptor.get(), G_TYPE_NONE));
+    auto* jsContext = jscContextGetJSContext(priv->context.get());
+    JSC::ExecState* exec = toJS(jsContext);
+    JSC::VM& vm = exec->vm();
+    JSC::JSLockHolder locker(vm);
+    auto scope = DECLARE_CATCH_SCOPE(vm);
+
+    JSC::JSValue jsValue = toJS(exec, priv->jsValue);
+    JSC::JSObject* object = jsValue.toObject(exec);
+    JSValueRef exception = nullptr;
+    if (handleExceptionIfNeeded(scope, exec, &exception) == ExceptionStatus::DidThrow) {
+        jscContextHandleExceptionIfNeeded(priv->context.get(), exception);
+        return;
+    }
+
+    auto name = OpaqueJSString::tryCreate(String::fromUTF8(propertyName));
+    if (!name)
+        return;
+
+    JSC::PropertyDescriptor descriptor;
+    descriptor.setValue(toJS(exec, propertyValue->priv->jsValue));
+    descriptor.setEnumerable(flags & JSC_VALUE_PROPERTY_ENUMERABLE);
+    descriptor.setConfigurable(flags & JSC_VALUE_PROPERTY_CONFIGURABLE);
+    descriptor.setWritable(flags & JSC_VALUE_PROPERTY_WRITABLE);
+    object->methodTable(vm)->defineOwnProperty(object, exec, name->identifier(&vm), descriptor, true);
+    if (handleExceptionIfNeeded(scope, exec, &exception) == ExceptionStatus::DidThrow) {
+        jscContextHandleExceptionIfNeeded(priv->context.get(), exception);
+        return;
+    }
 }
 
 /**
@@ -1076,33 +1092,44 @@
     g_return_if_fail(getter || setter);
 
     JSCValuePrivate* priv = value->priv;
-    GRefPtr<JSCValue> descriptor = adoptGRef(jsc_value_new_object(priv->context.get(), nullptr, nullptr));
-    GRefPtr<JSCValue> trueValue = adoptGRef(jsc_value_new_boolean(priv->context.get(), TRUE));
-    if (flags & JSC_VALUE_PROPERTY_CONFIGURABLE)
-        jsc_value_object_set_property(descriptor.get(), "configurable", trueValue.get());
-    if (flags & JSC_VALUE_PROPERTY_ENUMERABLE)
-        jsc_value_object_set_property(descriptor.get(), "enumerable", trueValue.get());
-
-    JSC::ExecState* exec = toJS(jscContextGetJSContext(priv->context.get()));
+    auto* jsContext = jscContextGetJSContext(priv->context.get());
+    JSC::ExecState* exec = toJS(jsContext);
     JSC::VM& vm = exec->vm();
     JSC::JSLockHolder locker(vm);
+    auto scope = DECLARE_CATCH_SCOPE(vm);
+
+    JSC::JSValue jsValue = toJS(exec, priv->jsValue);
+    JSC::JSObject* object = jsValue.toObject(exec);
+    JSValueRef exception = nullptr;
+    if (handleExceptionIfNeeded(scope, exec, &exception) == ExceptionStatus::DidThrow) {
+        jscContextHandleExceptionIfNeeded(priv->context.get(), exception);
+        return;
+    }
+
+    auto name = OpaqueJSString::tryCreate(String::fromUTF8(propertyName));
+    if (!name)
+        return;
+
+    JSC::PropertyDescriptor descriptor;
+    descriptor.setEnumerable(flags & JSC_VALUE_PROPERTY_ENUMERABLE);
+    descriptor.setConfigurable(flags & JSC_VALUE_PROPERTY_CONFIGURABLE);
     if (getter) {
         GRefPtr<GClosure> closure = adoptGRef(g_cclosure_new(getter, userData, reinterpret_cast<GClosureNotify>(reinterpret_cast<GCallback>(destroyNotify))));
-        auto* functionObject = toRef(JSC::JSCCallbackFunction::create(vm, exec->lexicalGlobalObject(), "get"_s,
-            JSC::JSCCallbackFunction::Type::Method, nullptr, WTFMove(closure), propertyType, Vector<GType> { }));
-        GRefPtr<JSCValue> function = jscContextGetOrCreateValue(priv->context.get(), functionObject);
-        jsc_value_object_set_property(descriptor.get(), "get", function.get());
+        auto function = JSC::JSCCallbackFunction::create(vm, exec->lexicalGlobalObject(), "get"_s,
+            JSC::JSCCallbackFunction::Type::Method, nullptr, WTFMove(closure), propertyType, Vector<GType> { });
+        descriptor.setGetter(function);
     }
     if (setter) {
         GRefPtr<GClosure> closure = adoptGRef(g_cclosure_new(setter, userData, getter ? nullptr : reinterpret_cast<GClosureNotify>(reinterpret_cast<GCallback>(destroyNotify))));
-        auto* functionObject = toRef(JSC::JSCCallbackFunction::create(vm, exec->lexicalGlobalObject(), "set"_s,
-            JSC::JSCCallbackFunction::Type::Method, nullptr, WTFMove(closure), G_TYPE_NONE, Vector<GType> { propertyType }));
-        GRefPtr<JSCValue> function = jscContextGetOrCreateValue(priv->context.get(), functionObject);
-        jsc_value_object_set_property(descriptor.get(), "set", function.get());
+        auto function = JSC::JSCCallbackFunction::create(vm, exec->lexicalGlobalObject(), "set"_s,
+            JSC::JSCCallbackFunction::Type::Method, nullptr, WTFMove(closure), G_TYPE_NONE, Vector<GType> { propertyType });
+        descriptor.setSetter(function);
     }
-    GRefPtr<JSCValue> object = adoptGRef(jsc_context_get_value(priv->context.get(), "Object"));
-    GRefPtr<JSCValue> result = adoptGRef(jsc_value_object_invoke_method(object.get(), "defineProperty",
-        JSC_TYPE_VALUE, value, G_TYPE_STRING, propertyName, JSC_TYPE_VALUE, descriptor.get(), G_TYPE_NONE));
+    object->methodTable(vm)->defineOwnProperty(object, exec, name->identifier(&vm), descriptor, true);
+    if (handleExceptionIfNeeded(scope, exec, &exception) == ExceptionStatus::DidThrow) {
+        jscContextHandleExceptionIfNeeded(priv->context.get(), exception);
+        return;
+    }
 }
 
 static GRefPtr<JSCValue> jscValueFunctionCreate(JSCContext* context, const char* name, GCallback callback, gpointer userData, GDestroyNotify destroyNotify, GType returnType, Optional<Vector<GType>>&& parameters)

Modified: releases/WebKitGTK/webkit-2.24/Source/_javascript_Core/ChangeLog (243994 => 243995)


--- releases/WebKitGTK/webkit-2.24/Source/_javascript_Core/ChangeLog	2019-04-08 10:44:34 UTC (rev 243994)
+++ releases/WebKitGTK/webkit-2.24/Source/_javascript_Core/ChangeLog	2019-04-08 10:44:38 UTC (rev 243995)
@@ -1,3 +1,16 @@
+2019-03-20  Carlos Garcia Campos  <cgar...@igalia.com>
+
+        [GLIB] Optimize jsc_value_object_define_property_data|accessor
+        https://bugs.webkit.org/show_bug.cgi?id=195679
+
+        Reviewed by Saam Barati.
+
+        Use direct C++ call instead of using the JSC GLib API to create the descriptor object and invoke Object.defineProperty().
+
+        * API/glib/JSCValue.cpp:
+        (jsc_value_object_define_property_data):
+        (jsc_value_object_define_property_accessor):
+
 2019-03-12  Mark Lam  <mark....@apple.com>
 
         The HasIndexedProperty node does GC.
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to