Changeset 252877 in webkit


Ignore:
Timestamp:
Nov 26, 2019 12:24:57 AM (4 years ago)
Author:
Carlos Garcia Campos
Message:

[GLIB] The API lock should be held before calling JSC::createTypeError
https://bugs.webkit.org/show_bug.cgi?id=204573

Reviewed by Mark Lam.

We are missing it in several places. This is causing a crash in test /jsc/object after r252298.

  • API/glib/JSCContext.cpp:

(jscContextGArrayToJSArray):
(jscContextJSArrayToGArray):
(jscContextGValueToJSValue):
(jscContextJSValueToGValue):

  • API/glib/JSCValue.cpp:

(jsc_value_new_array):
(jscValueCallFunction):

Location:
trunk/Source/JavaScriptCore
Files:
3 edited

Legend:

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

    r251425 r252877  
    272272{
    273273    JSCContextPrivate* priv = context->priv;
     274    JSC::JSGlobalObject* globalObject = toJS(priv->jsContext.get());
     275    JSC::JSLockHolder locker(globalObject);
     276
    274277    auto* jsArray = JSObjectMakeArray(priv->jsContext.get(), 0, nullptr, exception);
    275278    if (*exception)
     
    290293            JSObjectSetPropertyAtIndex(priv->jsContext.get(), jsArrayObject, i, jscValueGetJSValue(JSC_VALUE(item)), exception);
    291294        else
    292             *exception = toRef(JSC::createTypeError(toJS(priv->jsContext.get()), makeString("invalid item type in GPtrArray")));
     295            *exception = toRef(JSC::createTypeError(globalObject, makeString("invalid item type in GPtrArray")));
    293296
    294297        if (*exception)
     
    302305{
    303306    JSCContextPrivate* priv = context->priv;
     307    JSC::JSGlobalObject* globalObject = toJS(priv->jsContext.get());
     308    JSC::JSLockHolder locker(globalObject);
     309
    304310    if (JSValueIsNull(priv->jsContext.get(), jsArray))
    305311        return nullptr;
    306312
    307313    if (!JSValueIsArray(priv->jsContext.get(), jsArray)) {
    308         *exception = toRef(JSC::createTypeError(toJS(priv->jsContext.get()), makeString("invalid js type for GPtrArray")));
     314        *exception = toRef(JSC::createTypeError(globalObject, makeString("invalid js type for GPtrArray")));
    309315        return nullptr;
    310316    }
     
    338344{
    339345    JSCContextPrivate* priv = context->priv;
     346    JSC::JSGlobalObject* globalObject = toJS(priv->jsContext.get());
     347    JSC::JSLockHolder locker(globalObject);
     348
    340349    if (JSValueIsNull(priv->jsContext.get(), jsArray))
    341350        return nullptr;
    342351
    343352    if (!JSValueIsArray(priv->jsContext.get(), jsArray)) {
    344         *exception = toRef(JSC::createTypeError(toJS(priv->jsContext.get()), makeString("invalid js type for GStrv")));
     353        *exception = toRef(JSC::createTypeError(globalObject, makeString("invalid js type for GStrv")));
    345354        return nullptr;
    346355    }
     
    367376        auto jsValueItem = jscContextGetOrCreateValue(context, jsItem);
    368377        if (!jsc_value_is_string(jsValueItem.get())) {
    369             *exception = toRef(JSC::createTypeError(toJS(priv->jsContext.get()), makeString("invalid js type for GStrv: item ", String::number(i), " is not a string")));
     378            *exception = toRef(JSC::createTypeError(globalObject, makeString("invalid js type for GStrv: item ", String::number(i), " is not a string")));
    370379            return nullptr;
    371380        }
     
    380389{
    381390    JSCContextPrivate* priv = context->priv;
     391    JSC::JSGlobalObject* globalObject = toJS(priv->jsContext.get());
     392    JSC::JSLockHolder locker(globalObject);
    382393
    383394    switch (g_type_fundamental(G_VALUE_TYPE(value))) {
     
    447458    }
    448459
    449     *exception = toRef(JSC::createTypeError(toJS(priv->jsContext.get()), makeString("unsupported type ", g_type_name(G_VALUE_TYPE(value)))));
     460    *exception = toRef(JSC::createTypeError(globalObject, makeString("unsupported type ", g_type_name(G_VALUE_TYPE(value)))));
    450461    return JSValueMakeUndefined(priv->jsContext.get());
    451462}
     
    454465{
    455466    JSCContextPrivate* priv = context->priv;
     467    JSC::JSGlobalObject* globalObject = toJS(priv->jsContext.get());
     468    JSC::JSLockHolder locker(globalObject);
     469
    456470    g_value_init(value, type);
    457 
    458471    auto fundamentalType = g_type_fundamental(G_VALUE_TYPE(value));
    459472    switch (fundamentalType) {
     
    529542                }
    530543
    531                 *exception = toRef(JSC::createTypeError(toJS(priv->jsContext.get()), "invalid pointer type"_s));
     544                *exception = toRef(JSC::createTypeError(globalObject, "invalid pointer type"_s));
    532545                return;
    533546            }
     
    540553            g_value_set_object(value, wrappedObject);
    541554        else
    542             *exception = toRef(JSC::createTypeError(toJS(priv->jsContext.get()), "wrapped object is not a GObject"_s));
     555            *exception = toRef(JSC::createTypeError(globalObject, "wrapped object is not a GObject"_s));
    543556        break;
    544557    }
     
    565578    case G_TYPE_VARIANT:
    566579    default:
    567         *exception = toRef(JSC::createTypeError(toJS(priv->jsContext.get()), makeString("unsupported type ", g_type_name(G_VALUE_TYPE(value)))));
     580        *exception = toRef(JSC::createTypeError(globalObject, makeString("unsupported type ", g_type_name(G_VALUE_TYPE(value)))));
    568581        break;
    569582    }
  • trunk/Source/JavaScriptCore/API/glib/JSCValue.cpp

    r251425 r252877  
    473473    g_return_val_if_fail(JSC_IS_CONTEXT(context), nullptr);
    474474
    475     JSValueRef exception = nullptr;
    476475    auto* jsContext = jscContextGetJSContext(context);
     476    JSC::JSGlobalObject* globalObject = toJS(jsContext);
     477    JSC::JSLockHolder locker(globalObject);
     478
     479    JSValueRef exception = nullptr;
    477480    auto* jsArray = JSObjectMakeArray(jsContext, 0, nullptr, &exception);
    478481    if (jscContextHandleExceptionIfNeeded(context, exception))
     
    492495        G_VALUE_COLLECT_INIT(&item, itemType, args, G_VALUE_NOCOPY_CONTENTS, &error.outPtr());
    493496        if (error) {
    494             exception = toRef(JSC::createTypeError(toJS(jsContext), makeString("failed to collect array item: ", error.get())));
     497            exception = toRef(JSC::createTypeError(globalObject, makeString("failed to collect array item: ", error.get())));
    495498            jscContextHandleExceptionIfNeeded(context, exception);
    496499            jsArray = nullptr;
     
    879882    JSCValuePrivate* priv = value->priv;
    880883    auto* jsContext = jscContextGetJSContext(priv->context.get());
     884    JSC::JSGlobalObject* globalObject = toJS(jsContext);
     885    JSC::JSLockHolder locker(globalObject);
    881886
    882887    JSValueRef exception = nullptr;
     
    888893        G_VALUE_COLLECT_INIT(&parameter, parameterType, args, G_VALUE_NOCOPY_CONTENTS, &error.outPtr());
    889894        if (error) {
    890             exception = toRef(JSC::createTypeError(toJS(jsContext), makeString("failed to collect function paramater: ", error.get())));
     895            exception = toRef(JSC::createTypeError(globalObject, makeString("failed to collect function paramater: ", error.get())));
    891896            jscContextHandleExceptionIfNeeded(priv->context.get(), exception);
    892897            return adoptGRef(jsc_value_new_undefined(priv->context.get()));
  • trunk/Source/JavaScriptCore/ChangeLog

    r252875 r252877  
     12019-11-26  Carlos Garcia Campos  <cgarcia@igalia.com>
     2
     3        [GLIB] The API lock should be held before calling JSC::createTypeError
     4        https://bugs.webkit.org/show_bug.cgi?id=204573
     5
     6        Reviewed by Mark Lam.
     7
     8        We are missing it in several places. This is causing a crash in test /jsc/object after r252298.
     9
     10        * API/glib/JSCContext.cpp:
     11        (jscContextGArrayToJSArray):
     12        (jscContextJSArrayToGArray):
     13        (jscContextGValueToJSValue):
     14        (jscContextJSValueToGValue):
     15        * API/glib/JSCValue.cpp:
     16        (jsc_value_new_array):
     17        (jscValueCallFunction):
     18
    1192019-11-25  Yusuke Suzuki  <ysuzuki@apple.com>
    220
Note: See TracChangeset for help on using the changeset viewer.