- Revision
- 285317
- Author
- [email protected]
- Date
- 2021-11-04 15:55:12 -0700 (Thu, 04 Nov 2021)
Log Message
We need to PreferNumber when calling toPrimitive for coercion to BigInt
https://bugs.webkit.org/show_bug.cgi?id=232720
Patch by Alexey Shvayka <[email protected]> on 2021-11-04
Reviewed by Saam Barati.
JSTests:
* stress/big-int-constructor.js:
* stress/bigint-asintn.js:
* stress/bigint-asuintn.js:
Source/_javascript_Core:
The difference between "default" and "number" hints is observable only via
Symbol.toPrimitive method.
This patch aligns hints in ToBigInt [1] and BigInt constructor [2] with the
spec, V8, and SpiderMonkey.
[1]: https://tc39.es/ecma262/#sec-tobigint (step 1)
[2]: https://tc39.es/ecma262/#sec-bigint-constructor-number-value (step 2)
* runtime/BigIntConstructor.cpp:
(JSC::JSC_DEFINE_HOST_FUNCTION):
* runtime/JSCJSValue.cpp:
(JSC::JSValue::toBigInt const):
Modified Paths
Diff
Modified: trunk/JSTests/ChangeLog (285316 => 285317)
--- trunk/JSTests/ChangeLog 2021-11-04 21:58:31 UTC (rev 285316)
+++ trunk/JSTests/ChangeLog 2021-11-04 22:55:12 UTC (rev 285317)
@@ -1,3 +1,14 @@
+2021-11-04 Alexey Shvayka <[email protected]>
+
+ We need to PreferNumber when calling toPrimitive for coercion to BigInt
+ https://bugs.webkit.org/show_bug.cgi?id=232720
+
+ Reviewed by Saam Barati.
+
+ * stress/big-int-constructor.js:
+ * stress/bigint-asintn.js:
+ * stress/bigint-asuintn.js:
+
2021-11-04 Mikhail R. Gadelha <[email protected]>
Unskip tests disabled because of the recent 32 bits issues
Modified: trunk/JSTests/stress/big-int-constructor.js (285316 => 285317)
--- trunk/JSTests/stress/big-int-constructor.js 2021-11-04 21:58:31 UTC (rev 285316)
+++ trunk/JSTests/stress/big-int-constructor.js 2021-11-04 22:55:12 UTC (rev 285317)
@@ -226,6 +226,16 @@
n = BigInt(o);
assert(n.toString() === "3256");
+o = {
+ [Symbol.toPrimitive](hint) {
+ this.toPrimitiveHint = hint;
+ return 42;
+ }
+}
+
+n = BigInt(o);
+assert(o.toPrimitiveHint === "number");
+
// Assertion thows
assertThrowSyntaxError("aba");
Modified: trunk/JSTests/stress/bigint-asintn.js (285316 => 285317)
--- trunk/JSTests/stress/bigint-asintn.js 2021-11-04 21:58:31 UTC (rev 285316)
+++ trunk/JSTests/stress/bigint-asintn.js 2021-11-04 22:55:12 UTC (rev 285317)
@@ -26,7 +26,8 @@
let toIndex = false;
let toBigInt = false;
let index = {
- [Symbol.toPrimitive]() {
+ [Symbol.toPrimitive](hint) {
+ shouldBe(hint, "number");
shouldBe(toIndex, false);
shouldBe(toBigInt, false);
toIndex = true;
@@ -34,7 +35,8 @@
}
};
let bigint = {
- [Symbol.toPrimitive]() {
+ [Symbol.toPrimitive](hint) {
+ shouldBe(hint, "number");
shouldBe(toIndex, true);
shouldBe(toBigInt, false);
toBigInt = true;
Modified: trunk/JSTests/stress/bigint-asuintn.js (285316 => 285317)
--- trunk/JSTests/stress/bigint-asuintn.js 2021-11-04 21:58:31 UTC (rev 285316)
+++ trunk/JSTests/stress/bigint-asuintn.js 2021-11-04 22:55:12 UTC (rev 285317)
@@ -26,7 +26,8 @@
let toIndex = false;
let toBigInt = false;
let index = {
- [Symbol.toPrimitive]() {
+ [Symbol.toPrimitive](hint) {
+ shouldBe(hint, "number");
shouldBe(toIndex, false);
shouldBe(toBigInt, false);
toIndex = true;
@@ -34,7 +35,8 @@
}
};
let bigint = {
- [Symbol.toPrimitive]() {
+ [Symbol.toPrimitive](hint) {
+ shouldBe(hint, "number");
shouldBe(toIndex, true);
shouldBe(toBigInt, false);
toBigInt = true;
Modified: trunk/Source/_javascript_Core/ChangeLog (285316 => 285317)
--- trunk/Source/_javascript_Core/ChangeLog 2021-11-04 21:58:31 UTC (rev 285316)
+++ trunk/Source/_javascript_Core/ChangeLog 2021-11-04 22:55:12 UTC (rev 285317)
@@ -1,3 +1,24 @@
+2021-11-04 Alexey Shvayka <[email protected]>
+
+ We need to PreferNumber when calling toPrimitive for coercion to BigInt
+ https://bugs.webkit.org/show_bug.cgi?id=232720
+
+ Reviewed by Saam Barati.
+
+ The difference between "default" and "number" hints is observable only via
+ Symbol.toPrimitive method.
+
+ This patch aligns hints in ToBigInt [1] and BigInt constructor [2] with the
+ spec, V8, and SpiderMonkey.
+
+ [1]: https://tc39.es/ecma262/#sec-tobigint (step 1)
+ [2]: https://tc39.es/ecma262/#sec-bigint-constructor-number-value (step 2)
+
+ * runtime/BigIntConstructor.cpp:
+ (JSC::JSC_DEFINE_HOST_FUNCTION):
+ * runtime/JSCJSValue.cpp:
+ (JSC::JSValue::toBigInt const):
+
2021-11-03 Yusuke Suzuki <[email protected]>
[JSC] Clean up StructureStubInfo initialization
Modified: trunk/Source/_javascript_Core/runtime/BigIntConstructor.cpp (285316 => 285317)
--- trunk/Source/_javascript_Core/runtime/BigIntConstructor.cpp 2021-11-04 21:58:31 UTC (rev 285316)
+++ trunk/Source/_javascript_Core/runtime/BigIntConstructor.cpp 2021-11-04 22:55:12 UTC (rev 285317)
@@ -78,7 +78,7 @@
auto scope = DECLARE_THROW_SCOPE(vm);
JSValue value = callFrame->argument(0);
- JSValue primitive = value.toPrimitive(globalObject);
+ JSValue primitive = value.toPrimitive(globalObject, PreferNumber);
RETURN_IF_EXCEPTION(scope, encodedJSValue());
if (primitive.isInt32()) {
Modified: trunk/Source/_javascript_Core/runtime/JSCJSValue.cpp (285316 => 285317)
--- trunk/Source/_javascript_Core/runtime/JSCJSValue.cpp 2021-11-04 21:58:31 UTC (rev 285316)
+++ trunk/Source/_javascript_Core/runtime/JSCJSValue.cpp 2021-11-04 22:55:12 UTC (rev 285317)
@@ -96,7 +96,7 @@
VM& vm = globalObject->vm();
auto scope = DECLARE_THROW_SCOPE(vm);
- JSValue primitive = toPrimitive(globalObject);
+ JSValue primitive = toPrimitive(globalObject, PreferNumber);
RETURN_IF_EXCEPTION(scope, { });
if (primitive.isBigInt())