Title: [268322] trunk
Revision
268322
Author
ysuz...@apple.com
Date
2020-10-11 11:14:28 -0700 (Sun, 11 Oct 2020)

Log Message

[JSC] BigInt constructor should be constructible while it always throws an error
https://bugs.webkit.org/show_bug.cgi?id=217575

Reviewed by Darin Adler.

JSTests:

* stress/is-constructor.js:
* stress/non-constructable-constructors.js: Added.
(shouldThrow):

Source/_javascript_Core:

In terms of the spec, BigInt constructor should be a constructor. So we should put constructBigIntConstructor function instead of nullptr.
But it should always throw a TypeError. Error message looks a bit awkward ("TypeError: function is not a constructor..."), but this looks
most intuitive to users. Note that V8 and SpiderMonkey throw similar messages ("is not a constructor").

* runtime/BigIntConstructor.cpp:
(JSC::BigIntConstructor::BigIntConstructor):
(JSC::JSC_DEFINE_HOST_FUNCTION):

Modified Paths

Added Paths

Diff

Modified: trunk/JSTests/ChangeLog (268321 => 268322)


--- trunk/JSTests/ChangeLog	2020-10-11 18:03:14 UTC (rev 268321)
+++ trunk/JSTests/ChangeLog	2020-10-11 18:14:28 UTC (rev 268322)
@@ -1,5 +1,16 @@
 2020-10-11  Yusuke Suzuki  <ysuz...@apple.com>
 
+        [JSC] BigInt constructor should be constructible while it always throws an error
+        https://bugs.webkit.org/show_bug.cgi?id=217575
+
+        Reviewed by Darin Adler.
+
+        * stress/is-constructor.js:
+        * stress/non-constructable-constructors.js: Added.
+        (shouldThrow):
+
+2020-10-11  Yusuke Suzuki  <ysuz...@apple.com>
+
         [JSC] LowerCase when LanguageTag checks duplicate variants
         https://bugs.webkit.org/show_bug.cgi?id=217571
 

Modified: trunk/JSTests/stress/is-constructor.js (268321 => 268322)


--- trunk/JSTests/stress/is-constructor.js	2020-10-11 18:03:14 UTC (rev 268321)
+++ trunk/JSTests/stress/is-constructor.js	2020-10-11 18:14:28 UTC (rev 268322)
@@ -26,6 +26,7 @@
 // Builtin constructors.
 assert(isConstructor(Array));
 assert(isConstructor(ArrayBuffer));
+assert(isConstructor(BigInt));
 assert(isConstructor(Boolean));
 assert(isConstructor(Date));
 assert(isConstructor(Error));

Added: trunk/JSTests/stress/non-constructable-constructors.js (0 => 268322)


--- trunk/JSTests/stress/non-constructable-constructors.js	                        (rev 0)
+++ trunk/JSTests/stress/non-constructable-constructors.js	2020-10-11 18:14:28 UTC (rev 268322)
@@ -0,0 +1,19 @@
+function shouldThrow(func, errorMessage) {
+    var errorThrown = false;
+    var error = null;
+    try {
+        func();
+    } catch (e) {
+        errorThrown = true;
+        error = e;
+    }
+    if (!errorThrown)
+        throw new Error('not thrown');
+    if (String(error) !== errorMessage)
+        throw new Error(`bad error: ${String(error)}`);
+}
+
+shouldThrow(() => new Symbol(), `TypeError: function is not a constructor (evaluating 'new Symbol()')`);
+shouldThrow(() => new Symbol(Symbol("Hey")), `TypeError: function is not a constructor (evaluating 'new Symbol(Symbol("Hey"))')`);
+shouldThrow(() => new BigInt(), `TypeError: function is not a constructor (evaluating 'new BigInt()')`);
+shouldThrow(() => new BigInt(0), `TypeError: function is not a constructor (evaluating 'new BigInt(0)')`);

Modified: trunk/Source/_javascript_Core/ChangeLog (268321 => 268322)


--- trunk/Source/_javascript_Core/ChangeLog	2020-10-11 18:03:14 UTC (rev 268321)
+++ trunk/Source/_javascript_Core/ChangeLog	2020-10-11 18:14:28 UTC (rev 268322)
@@ -1,5 +1,20 @@
 2020-10-11  Yusuke Suzuki  <ysuz...@apple.com>
 
+        [JSC] BigInt constructor should be constructible while it always throws an error
+        https://bugs.webkit.org/show_bug.cgi?id=217575
+
+        Reviewed by Darin Adler.
+
+        In terms of the spec, BigInt constructor should be a constructor. So we should put constructBigIntConstructor function instead of nullptr.
+        But it should always throw a TypeError. Error message looks a bit awkward ("TypeError: function is not a constructor..."), but this looks
+        most intuitive to users. Note that V8 and SpiderMonkey throw similar messages ("is not a constructor").
+
+        * runtime/BigIntConstructor.cpp:
+        (JSC::BigIntConstructor::BigIntConstructor):
+        (JSC::JSC_DEFINE_HOST_FUNCTION):
+
+2020-10-11  Yusuke Suzuki  <ysuz...@apple.com>
+
         [JSC] LowerCase when LanguageTag checks duplicate variants
         https://bugs.webkit.org/show_bug.cgi?id=217571
 

Modified: trunk/Source/_javascript_Core/runtime/BigIntConstructor.cpp (268321 => 268322)


--- trunk/Source/_javascript_Core/runtime/BigIntConstructor.cpp	2020-10-11 18:03:14 UTC (rev 268321)
+++ trunk/Source/_javascript_Core/runtime/BigIntConstructor.cpp	2020-10-11 18:14:28 UTC (rev 268322)
@@ -55,9 +55,10 @@
 */
 
 static JSC_DECLARE_HOST_FUNCTION(callBigIntConstructor);
+static JSC_DECLARE_HOST_FUNCTION(constructBigIntConstructor);
 
 BigIntConstructor::BigIntConstructor(VM& vm, Structure* structure)
-    : InternalFunction(vm, structure, callBigIntConstructor, nullptr)
+    : InternalFunction(vm, structure, callBigIntConstructor, constructBigIntConstructor)
 {
 }
 
@@ -129,6 +130,13 @@
     RELEASE_AND_RETURN(scope, JSValue::encode(toBigInt(globalObject, primitive)));
 }
 
+JSC_DEFINE_HOST_FUNCTION(constructBigIntConstructor, (JSGlobalObject* globalObject, CallFrame* callFrame))
+{
+    VM& vm = globalObject->vm();
+    auto scope = DECLARE_THROW_SCOPE(vm);
+    return throwVMError(globalObject, scope, createNotAConstructorError(globalObject, callFrame->jsCallee()));
+}
+
 JSC_DEFINE_HOST_FUNCTION(bigIntConstructorFuncAsUintN, (JSGlobalObject* globalObject, CallFrame* callFrame))
 {
     VM& vm = globalObject->vm();
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to