Changeset 243200 in webkit


Ignore:
Timestamp:
Mar 20, 2019 6:55:54 AM (5 years ago)
Author:
Carlos Garcia Campos
Message:

[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):

Location:
trunk/Source/JavaScriptCore
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/API/glib/JSCValue.cpp

    r239427 r243200  
    2222
    2323#include "APICast.h"
     24#include "APIUtils.h"
    2425#include "JSCCallbackFunction.h"
    2526#include "JSCClassPrivate.h"
     
    10371038
    10381039    JSCValuePrivate* priv = value->priv;
    1039     GRefPtr<JSCValue> descriptor = adoptGRef(jsc_value_new_object(priv->context.get(), nullptr, nullptr));
    1040     GRefPtr<JSCValue> trueValue = adoptGRef(jsc_value_new_boolean(priv->context.get(), TRUE));
    1041     if (flags & JSC_VALUE_PROPERTY_CONFIGURABLE)
    1042         jsc_value_object_set_property(descriptor.get(), "configurable", trueValue.get());
    1043     if (flags & JSC_VALUE_PROPERTY_ENUMERABLE)
    1044         jsc_value_object_set_property(descriptor.get(), "enumerable", trueValue.get());
    1045     if (propertyValue)
    1046         jsc_value_object_set_property(descriptor.get(), "value", propertyValue);
    1047     if (flags & JSC_VALUE_PROPERTY_WRITABLE)
    1048         jsc_value_object_set_property(descriptor.get(), "writable", trueValue.get());
    1049     GRefPtr<JSCValue> object = adoptGRef(jsc_context_get_value(priv->context.get(), "Object"));
    1050     GRefPtr<JSCValue> result = adoptGRef(jsc_value_object_invoke_method(object.get(), "defineProperty",
    1051         JSC_TYPE_VALUE, value, G_TYPE_STRING, propertyName, JSC_TYPE_VALUE, descriptor.get(), G_TYPE_NONE));
     1040    auto* jsContext = jscContextGetJSContext(priv->context.get());
     1041    JSC::ExecState* exec = toJS(jsContext);
     1042    JSC::VM& vm = exec->vm();
     1043    JSC::JSLockHolder locker(vm);
     1044    auto scope = DECLARE_CATCH_SCOPE(vm);
     1045
     1046    JSC::JSValue jsValue = toJS(exec, priv->jsValue);
     1047    JSC::JSObject* object = jsValue.toObject(exec);
     1048    JSValueRef exception = nullptr;
     1049    if (handleExceptionIfNeeded(scope, exec, &exception) == ExceptionStatus::DidThrow) {
     1050        jscContextHandleExceptionIfNeeded(priv->context.get(), exception);
     1051        return;
     1052    }
     1053
     1054    auto name = OpaqueJSString::tryCreate(String::fromUTF8(propertyName));
     1055    if (!name)
     1056        return;
     1057
     1058    JSC::PropertyDescriptor descriptor;
     1059    descriptor.setValue(toJS(exec, propertyValue->priv->jsValue));
     1060    descriptor.setEnumerable(flags & JSC_VALUE_PROPERTY_ENUMERABLE);
     1061    descriptor.setConfigurable(flags & JSC_VALUE_PROPERTY_CONFIGURABLE);
     1062    descriptor.setWritable(flags & JSC_VALUE_PROPERTY_WRITABLE);
     1063    object->methodTable(vm)->defineOwnProperty(object, exec, name->identifier(&vm), descriptor, true);
     1064    if (handleExceptionIfNeeded(scope, exec, &exception) == ExceptionStatus::DidThrow) {
     1065        jscContextHandleExceptionIfNeeded(priv->context.get(), exception);
     1066        return;
     1067    }
    10521068}
    10531069
     
    10771093
    10781094    JSCValuePrivate* priv = value->priv;
    1079     GRefPtr<JSCValue> descriptor = adoptGRef(jsc_value_new_object(priv->context.get(), nullptr, nullptr));
    1080     GRefPtr<JSCValue> trueValue = adoptGRef(jsc_value_new_boolean(priv->context.get(), TRUE));
    1081     if (flags & JSC_VALUE_PROPERTY_CONFIGURABLE)
    1082         jsc_value_object_set_property(descriptor.get(), "configurable", trueValue.get());
    1083     if (flags & JSC_VALUE_PROPERTY_ENUMERABLE)
    1084         jsc_value_object_set_property(descriptor.get(), "enumerable", trueValue.get());
    1085 
    1086     JSC::ExecState* exec = toJS(jscContextGetJSContext(priv->context.get()));
     1095    auto* jsContext = jscContextGetJSContext(priv->context.get());
     1096    JSC::ExecState* exec = toJS(jsContext);
    10871097    JSC::VM& vm = exec->vm();
    10881098    JSC::JSLockHolder locker(vm);
     1099    auto scope = DECLARE_CATCH_SCOPE(vm);
     1100
     1101    JSC::JSValue jsValue = toJS(exec, priv->jsValue);
     1102    JSC::JSObject* object = jsValue.toObject(exec);
     1103    JSValueRef exception = nullptr;
     1104    if (handleExceptionIfNeeded(scope, exec, &exception) == ExceptionStatus::DidThrow) {
     1105        jscContextHandleExceptionIfNeeded(priv->context.get(), exception);
     1106        return;
     1107    }
     1108
     1109    auto name = OpaqueJSString::tryCreate(String::fromUTF8(propertyName));
     1110    if (!name)
     1111        return;
     1112
     1113    JSC::PropertyDescriptor descriptor;
     1114    descriptor.setEnumerable(flags & JSC_VALUE_PROPERTY_ENUMERABLE);
     1115    descriptor.setConfigurable(flags & JSC_VALUE_PROPERTY_CONFIGURABLE);
    10891116    if (getter) {
    10901117        GRefPtr<GClosure> closure = adoptGRef(g_cclosure_new(getter, userData, reinterpret_cast<GClosureNotify>(reinterpret_cast<GCallback>(destroyNotify))));
    1091         auto* functionObject = toRef(JSC::JSCCallbackFunction::create(vm, exec->lexicalGlobalObject(), "get"_s,
    1092             JSC::JSCCallbackFunction::Type::Method, nullptr, WTFMove(closure), propertyType, Vector<GType> { }));
    1093         GRefPtr<JSCValue> function = jscContextGetOrCreateValue(priv->context.get(), functionObject);
    1094         jsc_value_object_set_property(descriptor.get(), "get", function.get());
     1118        auto function = JSC::JSCCallbackFunction::create(vm, exec->lexicalGlobalObject(), "get"_s,
     1119            JSC::JSCCallbackFunction::Type::Method, nullptr, WTFMove(closure), propertyType, Vector<GType> { });
     1120        descriptor.setGetter(function);
    10951121    }
    10961122    if (setter) {
    10971123        GRefPtr<GClosure> closure = adoptGRef(g_cclosure_new(setter, userData, getter ? nullptr : reinterpret_cast<GClosureNotify>(reinterpret_cast<GCallback>(destroyNotify))));
    1098         auto* functionObject = toRef(JSC::JSCCallbackFunction::create(vm, exec->lexicalGlobalObject(), "set"_s,
    1099             JSC::JSCCallbackFunction::Type::Method, nullptr, WTFMove(closure), G_TYPE_NONE, Vector<GType> { propertyType }));
    1100         GRefPtr<JSCValue> function = jscContextGetOrCreateValue(priv->context.get(), functionObject);
    1101         jsc_value_object_set_property(descriptor.get(), "set", function.get());
    1102     }
    1103     GRefPtr<JSCValue> object = adoptGRef(jsc_context_get_value(priv->context.get(), "Object"));
    1104     GRefPtr<JSCValue> result = adoptGRef(jsc_value_object_invoke_method(object.get(), "defineProperty",
    1105         JSC_TYPE_VALUE, value, G_TYPE_STRING, propertyName, JSC_TYPE_VALUE, descriptor.get(), G_TYPE_NONE));
     1124        auto function = JSC::JSCCallbackFunction::create(vm, exec->lexicalGlobalObject(), "set"_s,
     1125            JSC::JSCCallbackFunction::Type::Method, nullptr, WTFMove(closure), G_TYPE_NONE, Vector<GType> { propertyType });
     1126        descriptor.setSetter(function);
     1127    }
     1128    object->methodTable(vm)->defineOwnProperty(object, exec, name->identifier(&vm), descriptor, true);
     1129    if (handleExceptionIfNeeded(scope, exec, &exception) == ExceptionStatus::DidThrow) {
     1130        jscContextHandleExceptionIfNeeded(priv->context.get(), exception);
     1131        return;
     1132    }
    11061133}
    11071134
  • trunk/Source/JavaScriptCore/ChangeLog

    r243192 r243200  
     12019-03-20  Carlos Garcia Campos  <cgarcia@igalia.com>
     2
     3        [GLIB] Optimize jsc_value_object_define_property_data|accessor
     4        https://bugs.webkit.org/show_bug.cgi?id=195679
     5
     6        Reviewed by Saam Barati.
     7
     8        Use direct C++ call instead of using the JSC GLib API to create the descriptor object and invoke Object.defineProperty().
     9
     10        * API/glib/JSCValue.cpp:
     11        (jsc_value_object_define_property_data):
     12        (jsc_value_object_define_property_accessor):
     13
    1142019-03-19  Devin Rousso  <drousso@apple.com>
    215
Note: See TracChangeset for help on using the changeset viewer.