Changeset 275569 in webkit


Ignore:
Timestamp:
Apr 6, 2021 4:28:53 PM (3 years ago)
Author:
Alexey Shvayka
Message:

Symbol and BigInt wrapper objects should perform OrdinaryToPrimitive
https://bugs.webkit.org/show_bug.cgi?id=224208

Reviewed by Yusuke Suzuki.

JSTests:

  • stress/bigint-object-ordinary-toprimitive.js: Added.
  • stress/symbol-object-ordinary-toprimitive.js: Added.

Source/JavaScriptCore:

ES6 introduced Symbol.toPrimitive as the only way to override ToPrimitive;
if it's nullish, OrdinaryToPrimitive [1] is performed unconditionally.

This patch removes two redundant defaultValue() overrides, fixing JSC to call
(possibly userland) toString() / valueOf() methods of a) Symbol objects whose
Symbol.toPrimitive was removed, and b) BigInt wrapper objects.

Aligns JSC with V8 and SpiderMonkey. Coercion of primitives is unaffected.
Also, removes dummy BigIntObject::internalValue() override.

[1]: https://tc39.es/ecma262/#sec-toprimitive (step 2.d)

  • runtime/BigIntObject.cpp:

(JSC::BigIntObject::defaultValue): Deleted.

  • runtime/BigIntObject.h:
  • runtime/SymbolObject.cpp:

(JSC::SymbolObject::defaultValue): Deleted.

  • runtime/SymbolObject.h:
Location:
trunk
Files:
2 added
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/JSTests/ChangeLog

    r275544 r275569  
     12021-04-06  Alexey Shvayka  <shvaikalesh@gmail.com>
     2
     3        Symbol and BigInt wrapper objects should perform OrdinaryToPrimitive
     4        https://bugs.webkit.org/show_bug.cgi?id=224208
     5
     6        Reviewed by Yusuke Suzuki.
     7
     8        * stress/bigint-object-ordinary-toprimitive.js: Added.
     9        * stress/symbol-object-ordinary-toprimitive.js: Added.
     10
    1112021-04-06  Alexey Shvayka  <shvaikalesh@gmail.com>
    212
  • trunk/Source/JavaScriptCore/ChangeLog

    r275544 r275569  
     12021-04-06  Alexey Shvayka  <shvaikalesh@gmail.com>
     2
     3        Symbol and BigInt wrapper objects should perform OrdinaryToPrimitive
     4        https://bugs.webkit.org/show_bug.cgi?id=224208
     5
     6        Reviewed by Yusuke Suzuki.
     7
     8        ES6 introduced Symbol.toPrimitive as the only way to override ToPrimitive;
     9        if it's nullish, OrdinaryToPrimitive [1] is performed unconditionally.
     10
     11        This patch removes two redundant defaultValue() overrides, fixing JSC to call
     12        (possibly userland) toString() / valueOf() methods of a) Symbol objects whose
     13        Symbol.toPrimitive was removed, and b) BigInt wrapper objects.
     14
     15        Aligns JSC with V8 and SpiderMonkey. Coercion of primitives is unaffected.
     16        Also, removes dummy BigIntObject::internalValue() override.
     17
     18        [1]: https://tc39.es/ecma262/#sec-toprimitive (step 2.d)
     19
     20        * runtime/BigIntObject.cpp:
     21        (JSC::BigIntObject::defaultValue): Deleted.
     22        * runtime/BigIntObject.h:
     23        * runtime/SymbolObject.cpp:
     24        (JSC::SymbolObject::defaultValue): Deleted.
     25        * runtime/SymbolObject.h:
     26
    1272021-04-06  Alexey Shvayka  <shvaikalesh@gmail.com>
    228
  • trunk/Source/JavaScriptCore/runtime/BigIntObject.cpp

    r262388 r275569  
    5757}
    5858
    59 JSValue BigIntObject::defaultValue(const JSObject* object, JSGlobalObject*, PreferredPrimitiveType)
    60 {
    61     const BigIntObject* bigIntObject = jsCast<const BigIntObject*>(object);
    62     return bigIntObject->internalValue();
    63 }
    64 
    6559} // namespace JSC
  • trunk/Source/JavaScriptCore/runtime/BigIntObject.h

    r261159 r275569  
    4545    DECLARE_EXPORT_INFO;
    4646
    47     JSValue internalValue() const { return JSWrapperObject::internalValue(); }
    48 
    4947    static Structure* createStructure(VM& vm, JSGlobalObject* globalObject, JSValue prototype)
    5048    {
    5149        return Structure::create(vm, globalObject, prototype, TypeInfo(ObjectType, StructureFlags), info());
    5250    }
    53 
    54     static JSValue defaultValue(const JSObject*, JSGlobalObject*, PreferredPrimitiveType);
    5551
    5652private:
  • trunk/Source/JavaScriptCore/runtime/SymbolObject.cpp

    r261895 r275569  
    4848}
    4949
    50 JSValue SymbolObject::defaultValue(const JSObject* object, JSGlobalObject*, PreferredPrimitiveType)
    51 {
    52     const SymbolObject* symbolObject = jsCast<const SymbolObject*>(object);
    53     return symbolObject->internalValue();
    54 }
    55 
    5650} // namespace JSC
  • trunk/Source/JavaScriptCore/runtime/SymbolObject.h

    r261159 r275569  
    6161    }
    6262
    63     static JSValue defaultValue(const JSObject*, JSGlobalObject*, PreferredPrimitiveType);
    64 
    6563private:
    6664    JS_EXPORT_PRIVATE void finishCreation(VM&, Symbol*);
Note: See TracChangeset for help on using the changeset viewer.