⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 245332 in webkit


Ignore:
Timestamp:
May 15, 2019, 11:20:49 AM (7 years ago)
Author:
Alan Coon
Message:

Cherry-pick r244996. rdar://problem/50754980

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

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@244996 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Location:
branches/safari-607.2.1.2-branch
Files:
1 added
8 edited

Legend:

Unmodified
Added
Removed
  • branches/safari-607.2.1.2-branch/JSTests/ChangeLog

    r245331 r245332  
     12019-05-15  Alan Coon  <alancoon@apple.com>
     2
     3        Cherry-pick r244996. rdar://problem/50754980
     4
     5    [JSC] We should check OOM for description string of Symbol
     6    https://bugs.webkit.org/show_bug.cgi?id=197634
     7   
     8    Reviewed by Keith Miller.
     9   
     10    JSTests:
     11   
     12    * stress/check-symbol-description-oom.js: Added.
     13    (shouldThrow):
     14   
     15    Source/JavaScriptCore:
     16   
     17    When resoling JSString for description of Symbol, we should check OOM error.
     18    We also change JSValueMakeSymbol(..., nullptr) to returning a symbol value
     19    without description, (1) to simplify the code and (2) give a way for JSC API
     20    to create a symbol value without description.
     21   
     22    * API/JSValueRef.cpp:
     23    (JSValueMakeSymbol):
     24    * API/tests/testapi.cpp:
     25    (TestAPI::symbolsTypeof):
     26    (TestAPI::symbolsDescription):
     27    (testCAPIViaCpp):
     28    * dfg/DFGOperations.cpp:
     29    * runtime/Symbol.cpp:
     30    (JSC::Symbol::createWithDescription):
     31    * runtime/Symbol.h:
     32    * runtime/SymbolConstructor.cpp:
     33    (JSC::callSymbol):
     34   
     35    git-svn-id: https://svn.webkit.org/repository/webkit/trunk@244996 268f45cc-cd09-0410-ab3c-d52691b4dbfc
     36
     37    2019-05-06  Yusuke Suzuki  <ysuzuki@apple.com>
     38
     39            [JSC] We should check OOM for description string of Symbol
     40            https://bugs.webkit.org/show_bug.cgi?id=197634
     41
     42            Reviewed by Keith Miller.
     43
     44            * stress/check-symbol-description-oom.js: Added.
     45            (shouldThrow):
     46
    1472019-05-15  Alan Coon  <alancoon@apple.com>
    248
  • branches/safari-607.2.1.2-branch/Source/JavaScriptCore/API/JSValueRef.cpp

    r237009 r245332  
    331331    }
    332332    ExecState* exec = toJS(ctx);
    333     JSLockHolder locker(exec);
    334     auto scope = DECLARE_CATCH_SCOPE(exec->vm());
    335 
    336     JSString* jsDescription = jsString(exec, description ? description->string() : String());
    337     RETURN_IF_EXCEPTION(scope, nullptr);
    338 
    339     return toRef(exec, Symbol::create(exec, jsDescription));
     333    VM& vm = exec->vm();
     334    JSLockHolder locker(exec);
     335
     336    if (!description)
     337        return toRef(exec, Symbol::create(vm));
     338    return toRef(exec, Symbol::createWithDescription(vm, description->string()));
    340339}
    341340
  • branches/safari-607.2.1.2-branch/Source/JavaScriptCore/API/tests/testapi.cpp

    r236805 r245332  
    130130    void basicSymbol();
    131131    void symbolsTypeof();
     132    void symbolsDescription();
    132133    void symbolsGetPropertyForKey();
    133134    void symbolsSetPropertyForKey();
     
    268269
    269270static const char* isSymbolFunction = "(function isSymbol(symbol) { return typeof(symbol) === 'symbol'; })";
     271static const char* getSymbolDescription = "(function getSymbolDescription(symbol) { return symbol.description; })";
    270272static const char* getFunction = "(function get(object, key) { return object[key]; })";
    271273static const char* setFunction = "(function set(object, key, value) { object[key] = value; })";
     
    281283void TestAPI::symbolsTypeof()
    282284{
    283     APIString description("dope");
    284     JSValueRef symbol = JSValueMakeSymbol(context, description);
    285     check(functionReturnsTrue(isSymbolFunction, symbol), "JSValueMakeSymbol makes a symbol value");
     285    {
     286        JSValueRef symbol = JSValueMakeSymbol(context, nullptr);
     287        check(functionReturnsTrue(isSymbolFunction, symbol), "JSValueMakeSymbol makes a symbol value");
     288    }
     289    {
     290        APIString description("dope");
     291        JSValueRef symbol = JSValueMakeSymbol(context, description);
     292        check(functionReturnsTrue(isSymbolFunction, symbol), "JSValueMakeSymbol makes a symbol value");
     293    }
     294}
     295
     296void TestAPI::symbolsDescription()
     297{
     298    {
     299        JSValueRef symbol = JSValueMakeSymbol(context, nullptr);
     300        auto result = callFunction(getSymbolDescription, symbol);
     301        check(JSValueIsStrictEqual(context, result.value(), JSValueMakeUndefined(context)), "JSValueMakeSymbol with nullptr description produces a symbol value without description");
     302    }
     303    {
     304        APIString description("dope");
     305        JSValueRef symbol = JSValueMakeSymbol(context, description);
     306        auto result = callFunction(getSymbolDescription, symbol);
     307        check(JSValueIsStrictEqual(context, result.value(), JSValueMakeString(context, description)), "JSValueMakeSymbol with description string produces a symbol value with description");
     308    }
    286309}
    287310
     
    495518    RUN(basicSymbol());
    496519    RUN(symbolsTypeof());
     520    RUN(symbolsDescription());
    497521    RUN(symbolsGetPropertyForKey());
    498522    RUN(symbolsSetPropertyForKey());
  • branches/safari-607.2.1.2-branch/Source/JavaScriptCore/ChangeLog

    r245331 r245332  
     12019-05-15  Alan Coon  <alancoon@apple.com>
     2
     3        Cherry-pick r244996. rdar://problem/50754980
     4
     5    [JSC] We should check OOM for description string of Symbol
     6    https://bugs.webkit.org/show_bug.cgi?id=197634
     7   
     8    Reviewed by Keith Miller.
     9   
     10    JSTests:
     11   
     12    * stress/check-symbol-description-oom.js: Added.
     13    (shouldThrow):
     14   
     15    Source/JavaScriptCore:
     16   
     17    When resoling JSString for description of Symbol, we should check OOM error.
     18    We also change JSValueMakeSymbol(..., nullptr) to returning a symbol value
     19    without description, (1) to simplify the code and (2) give a way for JSC API
     20    to create a symbol value without description.
     21   
     22    * API/JSValueRef.cpp:
     23    (JSValueMakeSymbol):
     24    * API/tests/testapi.cpp:
     25    (TestAPI::symbolsTypeof):
     26    (TestAPI::symbolsDescription):
     27    (testCAPIViaCpp):
     28    * dfg/DFGOperations.cpp:
     29    * runtime/Symbol.cpp:
     30    (JSC::Symbol::createWithDescription):
     31    * runtime/Symbol.h:
     32    * runtime/SymbolConstructor.cpp:
     33    (JSC::callSymbol):
     34   
     35    git-svn-id: https://svn.webkit.org/repository/webkit/trunk@244996 268f45cc-cd09-0410-ab3c-d52691b4dbfc
     36
     37    2019-05-06  Yusuke Suzuki  <ysuzuki@apple.com>
     38
     39            [JSC] We should check OOM for description string of Symbol
     40            https://bugs.webkit.org/show_bug.cgi?id=197634
     41
     42            Reviewed by Keith Miller.
     43
     44            When resoling JSString for description of Symbol, we should check OOM error.
     45            We also change JSValueMakeSymbol(..., nullptr) to returning a symbol value
     46            without description, (1) to simplify the code and (2) give a way for JSC API
     47            to create a symbol value without description.
     48
     49            * API/JSValueRef.cpp:
     50            (JSValueMakeSymbol):
     51            * API/tests/testapi.cpp:
     52            (TestAPI::symbolsTypeof):
     53            (TestAPI::symbolsDescription):
     54            (testCAPIViaCpp):
     55            * dfg/DFGOperations.cpp:
     56            * runtime/Symbol.cpp:
     57            (JSC::Symbol::createWithDescription):
     58            * runtime/Symbol.h:
     59            * runtime/SymbolConstructor.cpp:
     60            (JSC::callSymbol):
     61
    1622019-05-15  Alan Coon  <alancoon@apple.com>
    263
  • branches/safari-607.2.1.2-branch/Source/JavaScriptCore/dfg/DFGOperations.cpp

    r240426 r245332  
    22732273    VM& vm = exec->vm();
    22742274    NativeCallFrameTracer tracer(&vm, exec);
    2275 
    2276     return Symbol::create(exec, description);
     2275    auto scope = DECLARE_THROW_SCOPE(vm);
     2276
     2277    String string = description->value(exec);
     2278    RETURN_IF_EXCEPTION(scope, nullptr);
     2279
     2280    return Symbol::createWithDescription(vm, string);
    22772281}
    22782282
  • branches/safari-607.2.1.2-branch/Source/JavaScriptCore/runtime/Symbol.cpp

    r235712 r245332  
    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;
  • branches/safari-607.2.1.2-branch/Source/JavaScriptCore/runtime/Symbol.h

    r232404 r245332  
    5353
    5454    static Symbol* create(VM&);
    55     static Symbol* create(ExecState*, JSString* description);
     55    static Symbol* createWithDescription(VM&, const String&);
    5656    JS_EXPORT_PRIVATE static Symbol* create(VM&, SymbolImpl& uid);
    5757
  • branches/safari-607.2.1.2-branch/Source/JavaScriptCore/runtime/SymbolConstructor.cpp

    r233122 r245332  
    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.