Changeset 260733 in webkit


Ignore:
Timestamp:
Apr 26, 2020 3:54:45 PM (4 years ago)
Author:
Alexey Shvayka
Message:

Symbol should have Construct? internal method
https://bugs.webkit.org/show_bug.cgi?id=211050

Reviewed by Yusuke Suzuki.

JSTests:

  • stress/is-constructor.js:
  • test262/expectations.yaml: Mark 2 test cases as passing.

Source/JavaScriptCore:

This change introduces constructSymbol() method, which unconditionally throws
a TypeError, since its presence is observable when, for example, Symbol is a
ProxyTarget? itself [1]. Aligns JSC with the spec [2], V8, and SpiderMonkey.

[1]: https://tc39.es/ecma262/#sec-proxycreate (step 7.b)
[2]: https://tc39.es/ecma262/#constructor

  • runtime/SymbolConstructor.cpp:

(JSC::SymbolConstructor::SymbolConstructor):
(JSC::constructSymbol):

Location:
trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/JSTests/ChangeLog

    r260732 r260733  
     12020-04-26  Alexey Shvayka  <shvaikalesh@gmail.com>
     2
     3        Symbol should have [[Construct]] internal method
     4        https://bugs.webkit.org/show_bug.cgi?id=211050
     5
     6        Reviewed by Yusuke Suzuki.
     7
     8        * stress/is-constructor.js:
     9        * test262/expectations.yaml: Mark 2 test cases as passing.
     10
    1112020-04-26  Alexey Shvayka  <shvaikalesh@gmail.com>
    212
  • trunk/JSTests/stress/is-constructor.js

    r233377 r260733  
    3838assert(isConstructor(Set));
    3939assert(isConstructor(String));
     40assert(isConstructor(Symbol));
    4041assert(isConstructor(WeakMap));
    4142assert(isConstructor(WeakSet));
     
    6667assert(!isConstructor(Array.prototype));
    6768
    68 // Symbol is not a constructor.
    69 assert(!isConstructor(Symbol));
    70 
    7169// Getters / setters are not constructors.
    7270assert(!isConstructor(Object.getOwnPropertyDescriptor({get f(){}}, "f").get));
     
    9290assert(!isConstructor(JSON.stringify));
    9391assert(!isConstructor(Promise.all));
     92assert(!isConstructor(Proxy.revocable));
    9493assert(!isConstructor(Symbol.for));
    9594assert(!isConstructor(Array.prototype.push));
    9695
    9796// Proxy and bound functions carry forward non-constructor-ness.
    98 assert(!isConstructor(new Proxy(Symbol, {})));
     97assert(isConstructor(new Proxy(Symbol, {})));
     98assert(isConstructor(Symbol.bind(null)));
    9999assert(!isConstructor(new Proxy(Math.cos, {})));
    100 assert(!isConstructor(Symbol.bind(null)));
    101100assert(!isConstructor(Math.cos.bind(null)));
  • trunk/JSTests/test262/expectations.yaml

    r260732 r260733  
    16161616  default: 'TypeError: null is not a function'
    16171617  strict mode: 'TypeError: null is not a function'
    1618 test/built-ins/Symbol/is-constructor.js:
    1619   default: 'Test262Error: Expected true but got false'
    1620   strict mode: 'Test262Error: Expected true but got false'
    16211618test/built-ins/ThrowTypeError/extensible.js:
    16221619  default: 'Test262Error: Expected SameValue(«true», «false») to be true'
  • trunk/Source/JavaScriptCore/ChangeLog

    r260732 r260733  
     12020-04-26  Alexey Shvayka  <shvaikalesh@gmail.com>
     2
     3        Symbol should have [[Construct]] internal method
     4        https://bugs.webkit.org/show_bug.cgi?id=211050
     5
     6        Reviewed by Yusuke Suzuki.
     7
     8        This change introduces constructSymbol() method, which unconditionally throws
     9        a TypeError, since its presence is observable when, for example, Symbol is a
     10        [[ProxyTarget]] itself [1]. Aligns JSC with the spec [2], V8, and SpiderMonkey.
     11
     12        [1]: https://tc39.es/ecma262/#sec-proxycreate (step 7.b)
     13        [2]: https://tc39.es/ecma262/#constructor
     14
     15        * runtime/SymbolConstructor.cpp:
     16        (JSC::SymbolConstructor::SymbolConstructor):
     17        (JSC::constructSymbol):
     18
    1192020-04-26  Alexey Shvayka  <shvaikalesh@gmail.com>
    220
  • trunk/Source/JavaScriptCore/runtime/SymbolConstructor.cpp

    r252520 r260733  
    5858
    5959static EncodedJSValue JSC_HOST_CALL callSymbol(JSGlobalObject*, CallFrame*);
     60static EncodedJSValue JSC_HOST_CALL constructSymbol(JSGlobalObject*, CallFrame*);
    6061
    6162SymbolConstructor::SymbolConstructor(VM& vm, Structure* structure)
    62     : InternalFunction(vm, structure, callSymbol, nullptr)
     63    : InternalFunction(vm, structure, callSymbol, constructSymbol)
    6364{
    6465}
     
    9091    RETURN_IF_EXCEPTION(scope, { });
    9192    return JSValue::encode(Symbol::createWithDescription(vm, string));
     93}
     94
     95static EncodedJSValue JSC_HOST_CALL constructSymbol(JSGlobalObject* globalObject, CallFrame* callFrame)
     96{
     97    VM& vm = globalObject->vm();
     98    auto scope = DECLARE_THROW_SCOPE(vm);
     99    return throwVMError(globalObject, scope, createNotAConstructorError(globalObject, callFrame->jsCallee()));
    92100}
    93101
Note: See TracChangeset for help on using the changeset viewer.