Changeset 244996 in webkit


Ignore:
Timestamp:
May 6, 2019 5:29:09 PM (5 years ago)
Author:
ysuzuki@apple.com
Message:

[JSC] We should check OOM for description string of Symbol
https://bugs.webkit.org/show_bug.cgi?id=197634

Reviewed by Keith Miller.

JSTests:

  • stress/check-symbol-description-oom.js: Added.

(shouldThrow):

Source/JavaScriptCore:

When resoling JSString for description of Symbol, we should check OOM error.
We also change JSValueMakeSymbol(..., nullptr) to returning a symbol value
without description, (1) to simplify the code and (2) give a way for JSC API
to create a symbol value without description.

  • API/JSValueRef.cpp:

(JSValueMakeSymbol):

  • API/tests/testapi.cpp:

(TestAPI::symbolsTypeof):
(TestAPI::symbolsDescription):
(testCAPIViaCpp):

  • dfg/DFGOperations.cpp:
  • runtime/Symbol.cpp:

(JSC::Symbol::createWithDescription):

  • runtime/Symbol.h:
  • runtime/SymbolConstructor.cpp:

(JSC::callSymbol):

Location:
trunk
Files:
1 added
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/JSTests/ChangeLog

    r244981 r244996  
     12019-05-06  Yusuke Suzuki  <ysuzuki@apple.com>
     2
     3        [JSC] We should check OOM for description string of Symbol
     4        https://bugs.webkit.org/show_bug.cgi?id=197634
     5
     6        Reviewed by Keith Miller.
     7
     8        * stress/check-symbol-description-oom.js: Added.
     9        (shouldThrow):
     10
    1112019-05-06  Yusuke Suzuki  <ysuzuki@apple.com>
    212
  • trunk/Source/JavaScriptCore/API/JSValueRef.cpp

    r244088 r244996  
    332332    }
    333333    ExecState* exec = toJS(ctx);
    334     JSLockHolder locker(exec);
    335     auto scope = DECLARE_CATCH_SCOPE(exec->vm());
    336 
    337     JSString* jsDescription = jsString(exec, description ? description->string() : String());
    338     RETURN_IF_EXCEPTION(scope, nullptr);
    339 
    340     return toRef(exec, Symbol::create(exec, jsDescription));
     334    VM& vm = exec->vm();
     335    JSLockHolder locker(exec);
     336
     337    if (!description)
     338        return toRef(exec, Symbol::create(vm));
     339    return toRef(exec, Symbol::createWithDescription(vm, description->string()));
    341340}
    342341
  • trunk/Source/JavaScriptCore/API/tests/testapi.cpp

    r244694 r244996  
    131131    void basicSymbol();
    132132    void symbolsTypeof();
     133    void symbolsDescription();
    133134    void symbolsGetPropertyForKey();
    134135    void symbolsSetPropertyForKey();
     
    269270
    270271static const char* isSymbolFunction = "(function isSymbol(symbol) { return typeof(symbol) === 'symbol'; })";
     272static const char* getSymbolDescription = "(function getSymbolDescription(symbol) { return symbol.description; })";
    271273static const char* getFunction = "(function get(object, key) { return object[key]; })";
    272274static const char* setFunction = "(function set(object, key, value) { object[key] = value; })";
     
    282284void TestAPI::symbolsTypeof()
    283285{
    284     APIString description("dope");
    285     JSValueRef symbol = JSValueMakeSymbol(context, description);
    286     check(functionReturnsTrue(isSymbolFunction, symbol), "JSValueMakeSymbol makes a symbol value");
     286    {
     287        JSValueRef symbol = JSValueMakeSymbol(context, nullptr);
     288        check(functionReturnsTrue(isSymbolFunction, symbol), "JSValueMakeSymbol makes a symbol value");
     289    }
     290    {
     291        APIString description("dope");
     292        JSValueRef symbol = JSValueMakeSymbol(context, description);
     293        check(functionReturnsTrue(isSymbolFunction, symbol), "JSValueMakeSymbol makes a symbol value");
     294    }
     295}
     296
     297void TestAPI::symbolsDescription()
     298{
     299    {
     300        JSValueRef symbol = JSValueMakeSymbol(context, nullptr);
     301        auto result = callFunction(getSymbolDescription, symbol);
     302        check(JSValueIsStrictEqual(context, result.value(), JSValueMakeUndefined(context)), "JSValueMakeSymbol with nullptr description produces a symbol value without description");
     303    }
     304    {
     305        APIString description("dope");
     306        JSValueRef symbol = JSValueMakeSymbol(context, description);
     307        auto result = callFunction(getSymbolDescription, symbol);
     308        check(JSValueIsStrictEqual(context, result.value(), JSValueMakeString(context, description)), "JSValueMakeSymbol with description string produces a symbol value with description");
     309    }
    287310}
    288311
     
    492515    RUN(basicSymbol());
    493516    RUN(symbolsTypeof());
     517    RUN(symbolsDescription());
    494518    RUN(symbolsGetPropertyForKey());
    495519    RUN(symbolsSetPropertyForKey());
  • trunk/Source/JavaScriptCore/ChangeLog

    r244987 r244996  
     12019-05-06  Yusuke Suzuki  <ysuzuki@apple.com>
     2
     3        [JSC] We should check OOM for description string of Symbol
     4        https://bugs.webkit.org/show_bug.cgi?id=197634
     5
     6        Reviewed by Keith Miller.
     7
     8        When resoling JSString for description of Symbol, we should check OOM error.
     9        We also change JSValueMakeSymbol(..., nullptr) to returning a symbol value
     10        without description, (1) to simplify the code and (2) give a way for JSC API
     11        to create a symbol value without description.
     12
     13        * API/JSValueRef.cpp:
     14        (JSValueMakeSymbol):
     15        * API/tests/testapi.cpp:
     16        (TestAPI::symbolsTypeof):
     17        (TestAPI::symbolsDescription):
     18        (testCAPIViaCpp):
     19        * dfg/DFGOperations.cpp:
     20        * runtime/Symbol.cpp:
     21        (JSC::Symbol::createWithDescription):
     22        * runtime/Symbol.h:
     23        * runtime/SymbolConstructor.cpp:
     24        (JSC::callSymbol):
     25
    1262019-05-06  Keith Rollin  <krollin@apple.com>
    227
  • trunk/Source/JavaScriptCore/dfg/DFGOperations.cpp

    r244764 r244996  
    22922292    VM& vm = exec->vm();
    22932293    NativeCallFrameTracer tracer(&vm, exec);
    2294 
    2295     return Symbol::create(exec, description);
     2294    auto scope = DECLARE_THROW_SCOPE(vm);
     2295
     2296    String string = description->value(exec);
     2297    RETURN_IF_EXCEPTION(scope, nullptr);
     2298
     2299    return Symbol::createWithDescription(vm, string);
    22962300}
    22972301
  • trunk/Source/JavaScriptCore/runtime/Symbol.cpp

    r242991 r244996  
    117117}
    118118
    119 Symbol* Symbol::create(ExecState* exec, JSString* description)
     119Symbol* Symbol::createWithDescription(VM& vm, const String& description)
    120120{
    121     VM& vm = exec->vm();
    122     String desc = description->value(exec);
    123     Symbol* symbol = new (NotNull, allocateCell<Symbol>(vm.heap)) Symbol(vm, desc);
     121    Symbol* symbol = new (NotNull, allocateCell<Symbol>(vm.heap)) Symbol(vm, description);
    124122    symbol->finishCreation(vm);
    125123    return symbol;
  • trunk/Source/JavaScriptCore/runtime/Symbol.h

    r242991 r244996  
    4747
    4848    static Symbol* create(VM&);
    49     static Symbol* create(ExecState*, JSString* description);
     49    static Symbol* createWithDescription(VM&, const String&);
    5050    JS_EXPORT_PRIVATE static Symbol* create(VM&, SymbolImpl& uid);
    5151
  • trunk/Source/JavaScriptCore/runtime/SymbolConstructor.cpp

    r242991 r244996  
    8080static EncodedJSValue JSC_HOST_CALL callSymbol(ExecState* exec)
    8181{
     82    VM& vm = exec->vm();
     83    auto scope = DECLARE_THROW_SCOPE(vm);
     84
    8285    JSValue description = exec->argument(0);
    8386    if (description.isUndefined())
    84         return JSValue::encode(Symbol::create(exec->vm()));
    85     return JSValue::encode(Symbol::create(exec, description.toString(exec)));
     87        return JSValue::encode(Symbol::create(vm));
     88
     89    String string = description.toWTFString(exec);
     90    RETURN_IF_EXCEPTION(scope, { });
     91    return JSValue::encode(Symbol::createWithDescription(vm, string));
    8692}
    8793
Note: See TracChangeset for help on using the changeset viewer.