WebKit Bugzilla
Attachment 341725 Details for
Bug 179002
: [ESNext][BigInt] Implement support for addition operations
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
[patch]
Patch
bug-179002-20180601000019.patch (text/plain), 60.80 KB, created by
Caio Lima
on 2018-05-31 20:00:21 PDT
(
hide
)
Description:
Patch
Filename:
MIME Type:
Creator:
Caio Lima
Created:
2018-05-31 20:00:21 PDT
Size:
60.80 KB
patch
obsolete
>Subversion Revision: 232321 >diff --git a/Source/JavaScriptCore/ChangeLog b/Source/JavaScriptCore/ChangeLog >index 2873e04e9224815d9beda548aa9d01486fd7c29d..fba303ba7519753d6da75929db79d4d1d86add69 100644 >--- a/Source/JavaScriptCore/ChangeLog >+++ b/Source/JavaScriptCore/ChangeLog >@@ -1,3 +1,31 @@ >+2018-05-31 Caio Lima <ticaiolima@gmail.com> >+ >+ [ESNext][BigInt] Implement support for addition operations >+ https://bugs.webkit.org/show_bug.cgi?id=179002 >+ >+ Reviewed by NOBODY (OOPS!). >+ >+ This patch is implementing support to BigInt Operands into binary "+" >+ and binary "-" operators. Right now, we have limited support to DFG >+ and FTL JIT layers, but he plan is to improve this support in future >+ patches. >+ >+ * jit/JITOperations.cpp: >+ * runtime/CommonSlowPaths.cpp: >+ (JSC::SLOW_PATH_DECL): >+ * runtime/JSBigInt.cpp: >+ (JSC::JSBigInt::add): >+ (JSC::JSBigInt::sub): >+ (JSC::JSBigInt::absoluteAdd): >+ (JSC::JSBigInt::absoluteSub): >+ (JSC::JSBigInt::toObject const): >+ * runtime/JSBigInt.h: >+ * runtime/JSCJSValueInlines.h: >+ * runtime/Operations.cpp: >+ (JSC::jsAddSlowCase): >+ * runtime/Operations.h: >+ (JSC::jsSub): >+ > 2018-05-30 Daniel Bates <dabates@apple.com> > > Web Inspector: Annotate Same-Site cookies >diff --git a/Source/JavaScriptCore/jit/JITOperations.cpp b/Source/JavaScriptCore/jit/JITOperations.cpp >index e788d648a4abe249b4465fc4028ba71d11f19dd4..e6ae25732594f67c1a0095e3adde48e603d09707 100644 >--- a/Source/JavaScriptCore/jit/JITOperations.cpp >+++ b/Source/JavaScriptCore/jit/JITOperations.cpp >@@ -2816,34 +2816,23 @@ EncodedJSValue JIT_OPERATION operationArithNegateOptimize(ExecState* exec, Encod > return JSValue::encode(jsNumber(-number)); > } > >-ALWAYS_INLINE static EncodedJSValue unprofiledSub(VM& vm, ExecState* exec, EncodedJSValue encodedOp1, EncodedJSValue encodedOp2) >+ALWAYS_INLINE static EncodedJSValue unprofiledSub(ExecState* exec, EncodedJSValue encodedOp1, EncodedJSValue encodedOp2) > { >- auto scope = DECLARE_THROW_SCOPE(vm); > JSValue op1 = JSValue::decode(encodedOp1); > JSValue op2 = JSValue::decode(encodedOp2); >- >- double a = op1.toNumber(exec); >- RETURN_IF_EXCEPTION(scope, encodedJSValue()); >- scope.release(); >- double b = op2.toNumber(exec); >- return JSValue::encode(jsNumber(a - b)); >+ >+ return JSValue::encode(jsSub(exec, op1, op2)); > } > >-ALWAYS_INLINE static EncodedJSValue profiledSub(VM& vm, ExecState* exec, EncodedJSValue encodedOp1, EncodedJSValue encodedOp2, ArithProfile& arithProfile, bool shouldObserveLHSAndRHSTypes = true) >+ALWAYS_INLINE static EncodedJSValue profiledSub(ExecState* exec, EncodedJSValue encodedOp1, EncodedJSValue encodedOp2, ArithProfile& arithProfile, bool shouldObserveLHSAndRHSTypes = true) > { >- auto scope = DECLARE_THROW_SCOPE(vm); > JSValue op1 = JSValue::decode(encodedOp1); > JSValue op2 = JSValue::decode(encodedOp2); > > if (shouldObserveLHSAndRHSTypes) > arithProfile.observeLHSAndRHS(op1, op2); > >- double a = op1.toNumber(exec); >- RETURN_IF_EXCEPTION(scope, encodedJSValue()); >- double b = op2.toNumber(exec); >- RETURN_IF_EXCEPTION(scope, encodedJSValue()); >- >- JSValue result = jsNumber(a - b); >+ JSValue result = jsSub(exec, op1, op2); > arithProfile.observeResult(result); > return JSValue::encode(result); > } >@@ -2852,7 +2841,7 @@ EncodedJSValue JIT_OPERATION operationValueSub(ExecState* exec, EncodedJSValue e > { > VM* vm = &exec->vm(); > NativeCallFrameTracer tracer(vm, exec); >- return unprofiledSub(*vm, exec, encodedOp1, encodedOp2); >+ return unprofiledSub(exec, encodedOp1, encodedOp2); > } > > EncodedJSValue JIT_OPERATION operationValueSubProfiled(ExecState* exec, EncodedJSValue encodedOp1, EncodedJSValue encodedOp2, ArithProfile* arithProfile) >@@ -2862,7 +2851,7 @@ EncodedJSValue JIT_OPERATION operationValueSubProfiled(ExecState* exec, EncodedJ > VM* vm = &exec->vm(); > NativeCallFrameTracer tracer(vm, exec); > >- return profiledSub(*vm, exec, encodedOp1, encodedOp2, *arithProfile); >+ return profiledSub(exec, encodedOp1, encodedOp2, *arithProfile); > } > > EncodedJSValue JIT_OPERATION operationValueSubOptimize(ExecState* exec, EncodedJSValue encodedOp1, EncodedJSValue encodedOp2, JITSubIC* subIC) >@@ -2879,7 +2868,7 @@ EncodedJSValue JIT_OPERATION operationValueSubOptimize(ExecState* exec, EncodedJ > exec->codeBlock()->dumpMathICStats(); > #endif > >- return unprofiledSub(*vm, exec, encodedOp1, encodedOp2); >+ return unprofiledSub(exec, encodedOp1, encodedOp2); > } > > EncodedJSValue JIT_OPERATION operationValueSubNoOptimize(ExecState* exec, EncodedJSValue encodedOp1, EncodedJSValue encodedOp2, JITSubIC*) >@@ -2887,7 +2876,7 @@ EncodedJSValue JIT_OPERATION operationValueSubNoOptimize(ExecState* exec, Encode > VM* vm = &exec->vm(); > NativeCallFrameTracer tracer(vm, exec); > >- return unprofiledSub(*vm, exec, encodedOp1, encodedOp2); >+ return unprofiledSub(exec, encodedOp1, encodedOp2); > } > > EncodedJSValue JIT_OPERATION operationValueSubProfiledOptimize(ExecState* exec, EncodedJSValue encodedOp1, EncodedJSValue encodedOp2, JITSubIC* subIC) >@@ -2905,7 +2894,7 @@ EncodedJSValue JIT_OPERATION operationValueSubProfiledOptimize(ExecState* exec, > exec->codeBlock()->dumpMathICStats(); > #endif > >- return profiledSub(*vm, exec, encodedOp1, encodedOp2, *arithProfile, false); >+ return profiledSub(exec, encodedOp1, encodedOp2, *arithProfile, false); > } > > EncodedJSValue JIT_OPERATION operationValueSubProfiledNoOptimize(ExecState* exec, EncodedJSValue encodedOp1, EncodedJSValue encodedOp2, JITSubIC* subIC) >@@ -2915,7 +2904,7 @@ EncodedJSValue JIT_OPERATION operationValueSubProfiledNoOptimize(ExecState* exec > > ArithProfile* arithProfile = subIC->arithProfile(); > ASSERT(arithProfile); >- return profiledSub(*vm, exec, encodedOp1, encodedOp2, *arithProfile); >+ return profiledSub(exec, encodedOp1, encodedOp2, *arithProfile); > } > > void JIT_OPERATION operationProcessTypeProfilerLog(ExecState* exec) >diff --git a/Source/JavaScriptCore/runtime/CommonSlowPaths.cpp b/Source/JavaScriptCore/runtime/CommonSlowPaths.cpp >index 363ebdf451b43013cbfb6ee5723e8d34613eba7a..6e7727bcc1a245cfdc491694162a636a8a4cf1e4 100644 >--- a/Source/JavaScriptCore/runtime/CommonSlowPaths.cpp >+++ b/Source/JavaScriptCore/runtime/CommonSlowPaths.cpp >@@ -517,10 +517,24 @@ SLOW_PATH_DECL(slow_path_sub) > BEGIN(); > JSValue left = OP_C(2).jsValue(); > JSValue right = OP_C(3).jsValue(); >- double a = left.toNumber(exec); >- if (UNLIKELY(throwScope.exception())) >- RETURN(JSValue()); >- double b = right.toNumber(exec); >+ auto leftNumeric = left.toNumeric(exec); >+ CHECK_EXCEPTION(); >+ auto rightNumeric = right.toNumeric(exec); >+ CHECK_EXCEPTION(); >+ >+ if (WTF::holds_alternative<JSBigInt*>(leftNumeric) || WTF::holds_alternative<JSBigInt*>(rightNumeric)) { >+ if (WTF::holds_alternative<JSBigInt*>(leftNumeric) && WTF::holds_alternative<JSBigInt*>(rightNumeric)) { >+ JSBigInt* result = JSBigInt::sub(exec->vm(), WTF::get<JSBigInt*>(leftNumeric), WTF::get<JSBigInt*>(rightNumeric)); >+ RETURN_WITH_PROFILING(result, { >+ updateArithProfileForBinaryArithOp(exec, pc, result, left, right); >+ }); >+ } >+ >+ THROW(createTypeError(exec, "Invalid mix of BigInt and other type in subtraction.")); >+ } >+ >+ double a = WTF::get<double>(leftNumeric); >+ double b = WTF::get<double>(rightNumeric); > JSValue result = jsNumber(a - b); > RETURN_WITH_PROFILING(result, { > updateArithProfileForBinaryArithOp(exec, pc, result, left, right); >@@ -539,7 +553,7 @@ SLOW_PATH_DECL(slow_path_div) > > if (WTF::holds_alternative<JSBigInt*>(leftNumeric) || WTF::holds_alternative<JSBigInt*>(rightNumeric)) { > if (WTF::holds_alternative<JSBigInt*>(leftNumeric) && WTF::holds_alternative<JSBigInt*>(rightNumeric)) { >- JSValue result(JSBigInt::divide(exec, WTF::get<JSBigInt*>(leftNumeric), WTF::get<JSBigInt*>(rightNumeric))); >+ JSBigInt* result = JSBigInt::divide(exec, WTF::get<JSBigInt*>(leftNumeric), WTF::get<JSBigInt*>(rightNumeric)); > CHECK_EXCEPTION(); > RETURN_WITH_PROFILING(result, { > updateArithProfileForBinaryArithOp(exec, pc, result, left, right); >diff --git a/Source/JavaScriptCore/runtime/JSBigInt.cpp b/Source/JavaScriptCore/runtime/JSBigInt.cpp >index 854523335eeb5bc21aefc5db1502fcd2e17fa2c7..00d544950385aecc46a801fe4d504f18782e5608 100644 >--- a/Source/JavaScriptCore/runtime/JSBigInt.cpp >+++ b/Source/JavaScriptCore/runtime/JSBigInt.cpp >@@ -359,6 +359,40 @@ JSBigInt* JSBigInt::remainder(ExecState* state, JSBigInt* x, JSBigInt* y) > return remainder->rightTrim(vm); > } > >+JSBigInt* JSBigInt::add(VM& vm, JSBigInt* x, JSBigInt* y) >+{ >+ bool xSign = x->sign(); >+ >+ // x + y == x + y >+ // -x + -y == -(x + y) >+ if (xSign == y->sign()) >+ return absoluteAdd(vm, x, y, xSign); >+ >+ // x + -y == x - y == -(y - x) >+ // -x + y == y - x == -(x - y) >+ ComparisonResult comparisonResult = absoluteCompare(x, y); >+ if (comparisonResult == ComparisonResult::GreaterThan || comparisonResult == ComparisonResult::Equal) >+ return absoluteSub(vm, x, y, xSign); >+ >+ return absoluteSub(vm, y, x, !xSign); >+} >+ >+JSBigInt* JSBigInt::sub(VM& vm, JSBigInt* x, JSBigInt* y) >+{ >+ bool xSign = x->sign(); >+ if (xSign != y->sign()) { >+ // x - (-y) == x + y >+ // (-x) - y == -(x + y) >+ return absoluteAdd(vm, x, y, xSign); >+ } >+ // x - y == -(y - x) >+ // (-x) - (-y) == y - x == -(x - y) >+ ComparisonResult comparisonResult = absoluteCompare(x, y); >+ if (comparisonResult == ComparisonResult::GreaterThan || comparisonResult == ComparisonResult::Equal) >+ return absoluteSub(vm, x, y, xSign); >+ >+ return absoluteSub(vm, y, x, !xSign); >+} > > #if USE(JSVALUE32_64) > #define HAVE_TWO_DIGIT 1 >@@ -657,6 +691,85 @@ inline JSBigInt::ComparisonResult JSBigInt::absoluteCompare(JSBigInt* x, JSBigIn > return x->digit(i) > y->digit(i) ? ComparisonResult::GreaterThan : ComparisonResult::LessThan; > } > >+JSBigInt* JSBigInt::absoluteAdd(VM& vm, JSBigInt* x, JSBigInt* y, bool resultSign) >+{ >+ if (x->length() < y->length()) >+ return absoluteAdd(vm, y, x, resultSign); >+ >+ if (x->isZero()) { >+ ASSERT(y->isZero()); >+ return x; >+ } >+ >+ if (y->isZero()) >+ return resultSign == x->sign() ? x : unaryMinus(vm, x); >+ >+ JSBigInt* result = JSBigInt::createWithLength(vm, x->length() + 1); >+ ASSERT(result); >+ Digit carry = 0; >+ unsigned i = 0; >+ for (; i < y->length(); i++) { >+ Digit newCarry = 0; >+ Digit sum = digitAdd(x->digit(i), y->digit(i), newCarry); >+ sum = digitAdd(sum, carry, newCarry); >+ result->setDigit(i, sum); >+ carry = newCarry; >+ } >+ >+ for (; i < x->length(); i++) { >+ Digit newCarry = 0; >+ Digit sum = digitAdd(x->digit(i), carry, newCarry); >+ result->setDigit(i, sum); >+ carry = newCarry; >+ } >+ >+ result->setDigit(i, carry); >+ result->setSign(resultSign); >+ >+ return result->rightTrim(vm); >+} >+ >+JSBigInt* JSBigInt::absoluteSub(VM& vm, JSBigInt* x, JSBigInt* y, bool resultSign) >+{ >+ ComparisonResult comparisonResult = absoluteCompare(x, y); >+ ASSERT(x->length() >= y->length()); >+ ASSERT(comparisonResult == ComparisonResult::GreaterThan || comparisonResult == ComparisonResult::Equal); >+ >+ if (x->isZero()) { >+ ASSERT(y->isZero()); >+ return x; >+ } >+ >+ if (y->isZero()) >+ return resultSign == x->sign() ? x : unaryMinus(vm, x); >+ >+ if (comparisonResult == ComparisonResult::Equal) >+ return JSBigInt::createZero(vm); >+ >+ JSBigInt* result = JSBigInt::createWithLength(vm, x->length()); >+ Digit borrow = 0; >+ unsigned i = 0; >+ for (; i < y->length(); i++) { >+ Digit newBorrow = 0; >+ Digit difference = digitSub(x->digit(i), y->digit(i), newBorrow); >+ difference = digitSub(difference, borrow, newBorrow); >+ result->setDigit(i, difference); >+ borrow = newBorrow; >+ } >+ >+ for (; i < x->length(); i++) { >+ Digit newBorrow = 0; >+ Digit difference = digitSub(x->digit(i), borrow, newBorrow); >+ result->setDigit(i, difference); >+ borrow = newBorrow; >+ } >+ >+ ASSERT(!borrow); >+ result->setSign(resultSign); >+ result->rightTrim(vm); >+ return result; >+} >+ > // Divides {x} by {divisor}, returning the result in {quotient} and {remainder}. > // Mathematically, the contract is: > // quotient = (x - remainder) / divisor, with 0 <= remainder < divisor. >@@ -1228,9 +1341,9 @@ inline void JSBigInt::setDigit(unsigned n, Digit value) > ASSERT(n < length()); > dataStorage()[n] = value; > } >-JSObject* JSBigInt::toObject(ExecState* exec, JSGlobalObject* globalObject) const >+JSObject* JSBigInt::toObject(ExecState* state, JSGlobalObject* globalObject) const > { >- return BigIntObject::create(exec->vm(), globalObject, const_cast<JSBigInt*>(this)); >+ return BigIntObject::create(state->vm(), globalObject, const_cast<JSBigInt*>(this)); > } > > bool JSBigInt::equalsToNumber(JSValue numValue) >diff --git a/Source/JavaScriptCore/runtime/JSBigInt.h b/Source/JavaScriptCore/runtime/JSBigInt.h >index 28e24aa35e24b4c447cbf52b5c8411b2a5e32646..180bf223b8dddf06be6dd9d4f67e2e2d9019c0b6 100644 >--- a/Source/JavaScriptCore/runtime/JSBigInt.h >+++ b/Source/JavaScriptCore/runtime/JSBigInt.h >@@ -107,6 +107,8 @@ public: > > ComparisonResult static compareToDouble(JSBigInt* x, double y); > >+ static JSBigInt* add(VM&, JSBigInt* x, JSBigInt* y); >+ static JSBigInt* sub(VM&, JSBigInt* x, JSBigInt* y); > static JSBigInt* divide(ExecState*, JSBigInt* x, JSBigInt* y); > static JSBigInt* remainder(ExecState*, JSBigInt* x, JSBigInt* y); > static JSBigInt* unaryMinus(VM&, JSBigInt* x); >@@ -169,6 +171,8 @@ private: > JSBigInt* rightTrim(VM&); > > void inplaceMultiplyAdd(Digit multiplier, Digit part); >+ static JSBigInt* absoluteAdd(VM&, JSBigInt* x, JSBigInt* y, bool resultSign); >+ static JSBigInt* absoluteSub(VM&, JSBigInt* x, JSBigInt* y, bool resultSign); > > static size_t offsetOfData(); > Digit* dataStorage(); >diff --git a/Source/JavaScriptCore/runtime/JSCJSValueInlines.h b/Source/JavaScriptCore/runtime/JSCJSValueInlines.h >index f9dc308e704eb7e69f3fba9905dc040dd7ef1090..4ba9d507deb5fb5c566ee675b2cf11b10df49c11 100644 >--- a/Source/JavaScriptCore/runtime/JSCJSValueInlines.h >+++ b/Source/JavaScriptCore/runtime/JSCJSValueInlines.h >@@ -25,6 +25,7 @@ > > #pragma once > >+#include "CatchScope.h" > #include "Error.h" > #include "ExceptionHelpers.h" > #include "Identifier.h" >diff --git a/Source/JavaScriptCore/runtime/Operations.cpp b/Source/JavaScriptCore/runtime/Operations.cpp >index 57aec03367afcf45f51e584fe36855955a8c17ae..25ca9dbd41369e8fc642389b68e69d74fb111169 100644 >--- a/Source/JavaScriptCore/runtime/Operations.cpp >+++ b/Source/JavaScriptCore/runtime/Operations.cpp >@@ -23,6 +23,7 @@ > #include "Operations.h" > > #include "Error.h" >+#include "JSBigInt.h" > #include "JSCInlines.h" > #include "JSObject.h" > #include "JSString.h" >@@ -64,10 +65,22 @@ NEVER_INLINE JSValue jsAddSlowCase(CallFrame* callFrame, JSValue v1, JSValue v2) > return jsString(callFrame, p1String, asString(p2)); > } > >- double p1Number = p1.toNumber(callFrame); >+ auto leftNumeric = p1.toNumeric(callFrame); > RETURN_IF_EXCEPTION(scope, { }); >- scope.release(); >- return jsNumber(p1Number + p2.toNumber(callFrame)); >+ auto rightNumeric = p2.toNumeric(callFrame); >+ RETURN_IF_EXCEPTION(scope, { }); >+ >+ if (WTF::holds_alternative<JSBigInt*>(leftNumeric) || WTF::holds_alternative<JSBigInt*>(rightNumeric)) { >+ if (WTF::holds_alternative<JSBigInt*>(leftNumeric) && WTF::holds_alternative<JSBigInt*>(rightNumeric)) >+ return JSBigInt::add(vm, WTF::get<JSBigInt*>(leftNumeric), WTF::get<JSBigInt*>(rightNumeric)); >+ >+ throwTypeError(callFrame, scope, ASCIILiteral("Invalid mix of BigInt and other type in addition.")); >+ return { }; >+ } >+ >+ double p1Number = WTF::get<double>(leftNumeric); >+ double p2Number = WTF::get<double>(rightNumeric); >+ return jsNumber(p1Number + p2Number); > } > > JSValue jsTypeStringForValue(VM& vm, JSGlobalObject* globalObject, JSValue v) >diff --git a/Source/JavaScriptCore/runtime/Operations.h b/Source/JavaScriptCore/runtime/Operations.h >index 9a97ba95eee8f725612bab70c7b8bb271c736ac9..a3862fec6917918a4041363eb3969940301106eb 100644 >--- a/Source/JavaScriptCore/runtime/Operations.h >+++ b/Source/JavaScriptCore/runtime/Operations.h >@@ -327,6 +327,29 @@ ALWAYS_INLINE JSValue jsAdd(CallFrame* callFrame, JSValue v1, JSValue v2) > return jsAddSlowCase(callFrame, v1, v2); > } > >+ALWAYS_INLINE JSValue jsSub(ExecState* state, JSValue v1, JSValue v2) >+{ >+ VM& vm = state->vm(); >+ auto scope = DECLARE_THROW_SCOPE(vm); >+ >+ auto leftNumeric = v1.toNumeric(state); >+ RETURN_IF_EXCEPTION(scope, { }); >+ auto rightNumeric = v2.toNumeric(state); >+ RETURN_IF_EXCEPTION(scope, { }); >+ >+ if (WTF::holds_alternative<JSBigInt*>(leftNumeric) || WTF::holds_alternative<JSBigInt*>(rightNumeric)) { >+ if (WTF::holds_alternative<JSBigInt*>(leftNumeric) && WTF::holds_alternative<JSBigInt*>(rightNumeric)) >+ return JSBigInt::sub(vm, WTF::get<JSBigInt*>(leftNumeric), WTF::get<JSBigInt*>(rightNumeric)); >+ >+ throwTypeError(state, scope, ASCIILiteral("Invalid mix of BigInt and other type in subtraction.")); >+ return { }; >+ } >+ >+ double a = WTF::get<double>(leftNumeric); >+ double b = WTF::get<double>(rightNumeric); >+ return jsNumber(a - b); >+} >+ > ALWAYS_INLINE JSValue jsMul(ExecState* state, JSValue v1, JSValue v2) > { > VM& vm = state->vm(); >diff --git a/JSTests/ChangeLog b/JSTests/ChangeLog >index aa28cad5dfc96039067b7bbb03dbd07927aab028..0a0ba197af45e595a1d696889dff800e15607873 100644 >--- a/JSTests/ChangeLog >+++ b/JSTests/ChangeLog >@@ -1,3 +1,27 @@ >+2018-05-31 Caio Lima <ticaiolima@gmail.com> >+ >+ [ESNext][BigInt] Implement support for addition operations >+ https://bugs.webkit.org/show_bug.cgi?id=179002 >+ >+ Reviewed by NOBODY (OOPS!). >+ >+ * bigIntTests.yaml: >+ * stress/addition-order-evaluation.js: Added. >+ * stress/big-int-add-wrapped-value.js: Added. >+ * stress/big-int-addition-basic.js: Added. >+ * stress/big-int-addition-jit.js: Added. >+ * stress/big-int-addition-memory-stress.js: Added. >+ * stress/big-int-addition-string-coercion.js: Added. >+ * stress/big-int-addition-to-primitive-precedence.js: Added. >+ * stress/big-int-addition-to-primitive.js: Added. >+ * stress/big-int-addition-type-error.js: Added. >+ * stress/big-int-no-conversion-to-number.js: >+ * stress/big-int-sub-wrapped-value.js: Added. >+ * stress/big-int-subtraction-basic.js: Added. >+ * stress/big-int-subtraction-jit.js: Added. >+ * stress/big-int-subtraction-type-error.js: Added. >+ * stress/sub-order-evaluation.js: Added. >+ > 2018-05-30 Keith Miller <keith_miller@apple.com> > > Unreviewed, uncomment erroneously commented test code. >diff --git a/JSTests/bigIntTests.yaml b/JSTests/bigIntTests.yaml >index cafa96ae565e3ba17eed59d43b5a904aac08952a..1ac1fdbcee306f2b26d102c2dbae473be14283ba 100644 >--- a/JSTests/bigIntTests.yaml >+++ b/JSTests/bigIntTests.yaml >@@ -163,3 +163,38 @@ > - path: stress/big-int-mod-jit.js > cmd: runBigIntEnabled > >+- path: stress/big-int-add-wrapped-value.js >+ cmd: runBigIntEnabled >+ >+- path: stress/big-int-addition-basic.js >+ cmd: runBigIntEnabled >+ >+- path: stress/big-int-addition-jit.js >+ cmd: runBigIntEnabled >+ >+- path: stress/big-int-addition-memory-stress.js >+ cmd: runBigIntEnabled >+ >+- path: stress/big-int-addition-string-coercion.js >+ cmd: runBigIntEnabled >+ >+- path: stress/big-int-addition-to-primitive-precedence.js >+ cmd: runBigIntEnabled >+ >+- path: stress/big-int-addition-to-primitive.js >+ cmd: runBigIntEnabled >+ >+- path: stress/big-int-addition-type-error.js >+ cmd: runBigIntEnabled >+ >+- path: stress/big-int-sub-wrapped-value.js >+ cmd: runBigIntEnabled >+ >+- path:stress/big-int-subtraction-basic.js >+ cmd: runBigIntEnabled >+ >+- path: stress/big-int-subtraction-jit.js >+ cmd: runBigIntEnabled >+ >+- path: stress/big-int-subtraction-type-error.js >+ cmd: runBigIntEnabled >diff --git a/JSTests/stress/addition-order-evaluation.js b/JSTests/stress/addition-order-evaluation.js >new file mode 100644 >index 0000000000000000000000000000000000000000..d06f1aa70ca4242dc26c42a3a10cf6abe019751a >--- /dev/null >+++ b/JSTests/stress/addition-order-evaluation.js >@@ -0,0 +1,23 @@ >+function assert(a, message) { >+ if (!a) >+ throw new Error(message); >+} >+ >+let o = { >+ valueOf: function () { throw new Error("Oops"); } >+}; >+ >+try { >+ let n = Symbol("3") + o; >+ assert(false, message + ": Should throw Error, but executed without exception"); >+} catch (e) { >+ assert(e.message === "Oops","Expected Error('Oops'), got: " + e); >+} >+ >+try { >+ let n = o + Symbol("3"); >+ assert(false, message + ": Should throw Error, but executed without exception"); >+} catch (e) { >+ assert(e.message === "Oops","Expected Error('Oops'), got: " + e); >+} >+ >diff --git a/JSTests/stress/big-int-add-wrapped-value.js b/JSTests/stress/big-int-add-wrapped-value.js >new file mode 100644 >index 0000000000000000000000000000000000000000..8a378bfbce6e35ea69347993271c1b7890225756 >--- /dev/null >+++ b/JSTests/stress/big-int-add-wrapped-value.js >@@ -0,0 +1,37 @@ >+//@ runBigIntEnabled >+ >+assert = { >+ sameValue: function (input, expected, message) { >+ if (input !== expected) >+ throw new Error(message); >+ } >+}; >+ >+function testAdd(x, y, z, message) { >+ assert.sameValue(x + y, z, message); >+ assert.sameValue(y + x, z, message); >+} >+ >+testAdd(Object(2n), 1n, 3n, "ToPrimitive: unbox object with internal slot"); >+ >+let o = { >+ [Symbol.toPrimitive]: function() { >+ return 2n; >+ } >+}; >+testAdd(o, 1n, 3n, "ToPrimitive: @@toPrimitive"); >+ >+o = { >+ valueOf: function() { >+ return 2n; >+ } >+}; >+testAdd(o, 1n, 3n, "ToPrimitive: valueOf"); >+ >+o = { >+ toString: function() { >+ return 2n; >+ } >+} >+testAdd(o, 1n, 3n, "ToPrimitive: toString"); >+ >diff --git a/JSTests/stress/big-int-addition-basic.js b/JSTests/stress/big-int-addition-basic.js >new file mode 100644 >index 0000000000000000000000000000000000000000..9e57febe5e27c2152e54546b1b2b44caaf8f032f >--- /dev/null >+++ b/JSTests/stress/big-int-addition-basic.js >@@ -0,0 +1,169 @@ >+//@ runBigIntEnabled >+ >+assert = { >+ sameValue: function (input, expected, message) { >+ if (input !== expected) >+ throw new Error(message); >+ } >+}; >+ >+function testAdd(x, y, z) { >+ assert.sameValue(x + y, z, x + " + " + y + " = " + z); >+ assert.sameValue(y + x, z, y + " + " + x + " = " + z); >+} >+ >+testAdd(10n, 239n, 249n); >+testAdd(0xFEDCBA9876543210n, 0xFEDCBA9876543210n, 0x1FDB97530ECA86420n); >+testAdd(0xFEDCBA9876543210n, 0xFEDCBA987654320Fn, 0x1FDB97530ECA8641Fn); >+testAdd(0xFEDCBA9876543210n, 0xFEDCBA98n, 0xFEDCBA997530ECA8n); >+testAdd(0xFEDCBA9876543210n, 0xFEDCBA97n, 0xFEDCBA997530ECA7n); >+testAdd(0xFEDCBA9876543210n, 0x1234n, 0xFEDCBA9876544444n); >+testAdd(0xFEDCBA9876543210n, 0x3n, 0xFEDCBA9876543213n); >+testAdd(0xFEDCBA9876543210n, 0x2n, 0xFEDCBA9876543212n); >+testAdd(0xFEDCBA9876543210n, 0x1n, 0xFEDCBA9876543211n); >+testAdd(0xFEDCBA9876543210n, 0x0n, 0xFEDCBA9876543210n); >+testAdd(0xFEDCBA9876543210n, -0x1n, 0xFEDCBA987654320Fn); >+testAdd(0xFEDCBA9876543210n, -0x2n, 0xFEDCBA987654320En); >+testAdd(0xFEDCBA9876543210n, -0x3n, 0xFEDCBA987654320Dn); >+testAdd(0xFEDCBA9876543210n, -0x1234n, 0xFEDCBA9876541FDCn); >+testAdd(0xFEDCBA9876543210n, -0xFEDCBA97n, 0xFEDCBA9777777779n); >+testAdd(0xFEDCBA9876543210n, -0xFEDCBA98n, 0xFEDCBA9777777778n); >+testAdd(0xFEDCBA9876543210n, -0xFEDCBA987654320Fn, 0x1n); >+testAdd(0xFEDCBA9876543210n, -0xFEDCBA9876543210n, 0x0n); >+testAdd(0xFEDCBA987654320Fn, 0xFEDCBA987654320Fn, 0x1FDB97530ECA8641En); >+testAdd(0xFEDCBA987654320Fn, 0xFEDCBA98n, 0xFEDCBA997530ECA7n); >+testAdd(0xFEDCBA987654320Fn, 0xFEDCBA97n, 0xFEDCBA997530ECA6n); >+testAdd(0xFEDCBA987654320Fn, 0x1234n, 0xFEDCBA9876544443n); >+testAdd(0xFEDCBA987654320Fn, 0x3n, 0xFEDCBA9876543212n); >+testAdd(0xFEDCBA987654320Fn, 0x2n, 0xFEDCBA9876543211n); >+testAdd(0xFEDCBA987654320Fn, 0x1n, 0xFEDCBA9876543210n); >+testAdd(0xFEDCBA987654320Fn, 0x0n, 0xFEDCBA987654320Fn); >+testAdd(0xFEDCBA987654320Fn, -0x1n, 0xFEDCBA987654320En); >+testAdd(0xFEDCBA987654320Fn, -0x2n, 0xFEDCBA987654320Dn); >+testAdd(0xFEDCBA987654320Fn, -0x3n, 0xFEDCBA987654320Cn); >+testAdd(0xFEDCBA987654320Fn, -0x1234n, 0xFEDCBA9876541FDBn); >+testAdd(0xFEDCBA987654320Fn, -0xFEDCBA97n, 0xFEDCBA9777777778n); >+testAdd(0xFEDCBA987654320Fn, -0xFEDCBA98n, 0xFEDCBA9777777777n); >+testAdd(0xFEDCBA987654320Fn, -0xFEDCBA987654320Fn, 0x0n); >+testAdd(0xFEDCBA987654320Fn, -0xFEDCBA9876543210n, -0x1n); >+testAdd(0xFEDCBA98n, 0xFEDCBA98n, 0x1FDB97530n); >+testAdd(0xFEDCBA98n, 0xFEDCBA97n, 0x1FDB9752Fn); >+testAdd(0xFEDCBA98n, 0x1234n, 0xFEDCCCCCn); >+testAdd(0xFEDCBA98n, 0x3n, 0xFEDCBA9Bn); >+testAdd(0xFEDCBA98n, 0x2n, 0xFEDCBA9An); >+testAdd(0xFEDCBA98n, 0x1n, 0xFEDCBA99n); >+testAdd(0xFEDCBA98n, 0x0n, 0xFEDCBA98n); >+testAdd(0xFEDCBA98n, -0x1n, 0xFEDCBA97n); >+testAdd(0xFEDCBA98n, -0x2n, 0xFEDCBA96n); >+testAdd(0xFEDCBA98n, -0x3n, 0xFEDCBA95n); >+testAdd(0xFEDCBA98n, -0x1234n, 0xFEDCA864n); >+testAdd(0xFEDCBA98n, -0xFEDCBA97n, 0x1n); >+testAdd(0xFEDCBA98n, -0xFEDCBA98n, 0x0n); >+testAdd(0xFEDCBA98n, -0xFEDCBA987654320Fn, -0xFEDCBA9777777777n); >+testAdd(0xFEDCBA98n, -0xFEDCBA9876543210n, -0xFEDCBA9777777778n); >+testAdd(0xFEDCBA97n, 0xFEDCBA97n, 0x1FDB9752En); >+testAdd(0xFEDCBA97n, 0x1234n, 0xFEDCCCCBn); >+testAdd(0xFEDCBA97n, 0x3n, 0xFEDCBA9An); >+testAdd(0xFEDCBA97n, 0x2n, 0xFEDCBA99n); >+testAdd(0xFEDCBA97n, 0x1n, 0xFEDCBA98n); >+testAdd(0xFEDCBA97n, 0x0n, 0xFEDCBA97n); >+testAdd(0xFEDCBA97n, -0x1n, 0xFEDCBA96n); >+testAdd(0xFEDCBA97n, -0x2n, 0xFEDCBA95n); >+testAdd(0xFEDCBA97n, -0x3n, 0xFEDCBA94n); >+testAdd(0xFEDCBA97n, -0x1234n, 0xFEDCA863n); >+testAdd(0xFEDCBA97n, -0xFEDCBA97n, 0x0n); >+testAdd(0xFEDCBA97n, -0xFEDCBA98n, -0x1n); >+testAdd(0xFEDCBA97n, -0xFEDCBA987654320Fn, -0xFEDCBA9777777778n); >+testAdd(0xFEDCBA97n, -0xFEDCBA9876543210n, -0xFEDCBA9777777779n); >+testAdd(0x1234n, 0x1234n, 0x2468n); >+testAdd(0x1234n, 0x3n, 0x1237n); >+testAdd(0x1234n, 0x2n, 0x1236n); >+testAdd(0x1234n, 0x1n, 0x1235n); >+testAdd(0x1234n, 0x0n, 0x1234n); >+testAdd(0x1234n, -0x1n, 0x1233n); >+testAdd(0x1234n, -0x2n, 0x1232n); >+testAdd(0x1234n, -0x3n, 0x1231n); >+testAdd(0x1234n, -0x1234n, 0x0n); >+testAdd(0x1234n, -0xFEDCBA97n, -0xFEDCA863n); >+testAdd(0x1234n, -0xFEDCBA98n, -0xFEDCA864n); >+testAdd(0x1234n, -0xFEDCBA987654320Fn, -0xFEDCBA9876541FDBn); >+testAdd(0x1234n, -0xFEDCBA9876543210n, -0xFEDCBA9876541FDCn); >+testAdd(0x3n, 0x3n, 0x6n); >+testAdd(0x3n, 0x2n, 0x5n); >+testAdd(0x3n, 0x1n, 0x4n); >+testAdd(0x3n, 0x0n, 0x3n); >+testAdd(0x3n, -0x1n, 0x2n); >+testAdd(0x3n, -0x2n, 0x1n); >+testAdd(0x3n, -0x3n, 0x0n); >+testAdd(0x3n, -0x1234n, -0x1231n); >+testAdd(0x3n, -0xFEDCBA97n, -0xFEDCBA94n); >+testAdd(0x3n, -0xFEDCBA98n, -0xFEDCBA95n); >+testAdd(0x3n, -0xFEDCBA987654320Fn, -0xFEDCBA987654320Cn); >+testAdd(0x3n, -0xFEDCBA9876543210n, -0xFEDCBA987654320Dn); >+testAdd(0x2n, 0x2n, 0x4n); >+testAdd(0x2n, 0x1n, 0x3n); >+testAdd(0x2n, 0x0n, 0x2n); >+testAdd(0x2n, -0x1n, 0x1n); >+testAdd(0x2n, -0x2n, 0x0n); >+testAdd(0x2n, -0x3n, -0x1n); >+testAdd(0x2n, -0x1234n, -0x1232n); >+testAdd(0x2n, -0xFEDCBA97n, -0xFEDCBA95n); >+testAdd(0x2n, -0xFEDCBA98n, -0xFEDCBA96n); >+testAdd(0x2n, -0xFEDCBA987654320Fn, -0xFEDCBA987654320Dn); >+testAdd(0x2n, -0xFEDCBA9876543210n, -0xFEDCBA987654320En); >+testAdd(0x1n, 0x1n, 0x2n); >+testAdd(0x1n, 0x0n, 0x1n); >+testAdd(0x1n, -0x1n, 0x0n); >+testAdd(0x1n, -0x2n, -0x1n); >+testAdd(0x1n, -0x3n, -0x2n); >+testAdd(0x1n, -0x1234n, -0x1233n); >+testAdd(0x1n, -0xFEDCBA97n, -0xFEDCBA96n); >+testAdd(0x1n, -0xFEDCBA98n, -0xFEDCBA97n); >+testAdd(0x1n, -0xFEDCBA987654320Fn, -0xFEDCBA987654320En); >+testAdd(0x1n, -0xFEDCBA9876543210n, -0xFEDCBA987654320Fn); >+testAdd(0x0n, 0x0n, 0x0n); >+testAdd(0x0n, -0x1n, -0x1n); >+testAdd(0x0n, -0x2n, -0x2n); >+testAdd(0x0n, -0x3n, -0x3n); >+testAdd(0x0n, -0x1234n, -0x1234n); >+testAdd(0x0n, -0xFEDCBA97n, -0xFEDCBA97n); >+testAdd(0x0n, -0xFEDCBA98n, -0xFEDCBA98n); >+testAdd(0x0n, -0xFEDCBA987654320Fn, -0xFEDCBA987654320Fn); >+testAdd(0x0n, -0xFEDCBA9876543210n, -0xFEDCBA9876543210n); >+testAdd(-0x1n, -0x1n, -0x2n); >+testAdd(-0x1n, -0x2n, -0x3n); >+testAdd(-0x1n, -0x3n, -0x4n); >+testAdd(-0x1n, -0x1234n, -0x1235n); >+testAdd(-0x1n, -0xFEDCBA97n, -0xFEDCBA98n); >+testAdd(-0x1n, -0xFEDCBA98n, -0xFEDCBA99n); >+testAdd(-0x1n, -0xFEDCBA987654320Fn, -0xFEDCBA9876543210n); >+testAdd(-0x1n, -0xFEDCBA9876543210n, -0xFEDCBA9876543211n); >+testAdd(-0x2n, -0x2n, -0x4n); >+testAdd(-0x2n, -0x3n, -0x5n); >+testAdd(-0x2n, -0x1234n, -0x1236n); >+testAdd(-0x2n, -0xFEDCBA97n, -0xFEDCBA99n); >+testAdd(-0x2n, -0xFEDCBA98n, -0xFEDCBA9An); >+testAdd(-0x2n, -0xFEDCBA987654320Fn, -0xFEDCBA9876543211n); >+testAdd(-0x2n, -0xFEDCBA9876543210n, -0xFEDCBA9876543212n); >+testAdd(-0x3n, -0x3n, -0x6n); >+testAdd(-0x3n, -0x1234n, -0x1237n); >+testAdd(-0x3n, -0xFEDCBA97n, -0xFEDCBA9An); >+testAdd(-0x3n, -0xFEDCBA98n, -0xFEDCBA9Bn); >+testAdd(-0x3n, -0xFEDCBA987654320Fn, -0xFEDCBA9876543212n); >+testAdd(-0x3n, -0xFEDCBA9876543210n, -0xFEDCBA9876543213n); >+testAdd(-0x1234n, -0x1234n, -0x2468n); >+testAdd(-0x1234n, -0xFEDCBA97n, -0xFEDCCCCBn); >+testAdd(-0x1234n, -0xFEDCBA98n, -0xFEDCCCCCn); >+testAdd(-0x1234n, -0xFEDCBA987654320Fn, -0xFEDCBA9876544443n); >+testAdd(-0x1234n, -0xFEDCBA9876543210n, -0xFEDCBA9876544444n); >+testAdd(-0xFEDCBA97n, -0xFEDCBA97n, -0x1FDB9752En); >+testAdd(-0xFEDCBA97n, -0xFEDCBA98n, -0x1FDB9752Fn); >+testAdd(-0xFEDCBA97n, -0xFEDCBA987654320Fn, -0xFEDCBA997530ECA6n); >+testAdd(-0xFEDCBA97n, -0xFEDCBA9876543210n, -0xFEDCBA997530ECA7n); >+testAdd(-0xFEDCBA98n, -0xFEDCBA98n, -0x1FDB97530n); >+testAdd(-0xFEDCBA98n, -0xFEDCBA987654320Fn, -0xFEDCBA997530ECA7n); >+testAdd(-0xFEDCBA98n, -0xFEDCBA9876543210n, -0xFEDCBA997530ECA8n); >+testAdd(-0xFEDCBA987654320Fn, -0xFEDCBA987654320Fn, -0x1FDB97530ECA8641En); >+testAdd(-0xFEDCBA987654320Fn, -0xFEDCBA9876543210n, -0x1FDB97530ECA8641Fn); >+testAdd(-0xFEDCBA9876543210n, -0xFEDCBA9876543210n, -0x1FDB97530ECA86420n); >+ >diff --git a/JSTests/stress/big-int-addition-jit.js b/JSTests/stress/big-int-addition-jit.js >new file mode 100644 >index 0000000000000000000000000000000000000000..1158e0a0c1241a6dfa3bbdd6a3da958d3326285f >--- /dev/null >+++ b/JSTests/stress/big-int-addition-jit.js >@@ -0,0 +1,19 @@ >+//@ runBigIntEnabled >+ >+let assert = { >+ sameValue: function(i, e, m) { >+ if (i !== e) >+ throw new Error(m); >+ } >+} >+ >+function bigIntAddition(x, y) { >+ return x + y; >+} >+noInline(bigIntAddition); >+ >+for (let i = 0; i < 10000; i++) { >+ let r = bigIntAddition(3n, 10n); >+ assert.sameValue(r, 13n, 3n + " + " + 10n + " = " + r); >+} >+ >diff --git a/JSTests/stress/big-int-addition-memory-stress.js b/JSTests/stress/big-int-addition-memory-stress.js >new file mode 100644 >index 0000000000000000000000000000000000000000..8b1aeb1975cb3e027814e65a633db513f506c39c >--- /dev/null >+++ b/JSTests/stress/big-int-addition-memory-stress.js >@@ -0,0 +1,14 @@ >+//@ runBigIntEnabled >+ >+function assert(a) { >+ if (!a) >+ throw new Error("Bad assertion"); >+} >+ >+let a = 0n; >+for (let i = 0; i < 1000000; i++) { >+ a += 30n; >+} >+ >+assert(a === 30000000n); >+ >diff --git a/JSTests/stress/big-int-addition-string-coercion.js b/JSTests/stress/big-int-addition-string-coercion.js >new file mode 100644 >index 0000000000000000000000000000000000000000..bbde05a346ed71a9f3ae82599e375ab31bb09892 >--- /dev/null >+++ b/JSTests/stress/big-int-addition-string-coercion.js >@@ -0,0 +1,25 @@ >+//@ runBigIntEnabled >+ >+function assert(input, expected) { >+ if (input !== expected) >+ throw new Error("Bad!"); >+} >+ >+assert(-1n + "", "-1"); >+assert("" + -1n, "-1"); >+assert(0n + "", "0"); >+assert("" + 0n, "0"); >+assert(1n + "", "1"); >+assert("" + 1n, "1"); >+assert(123456789000000000000000n + "", "123456789000000000000000"); >+assert("" + 123456789000000000000000n, "123456789000000000000000"); >+assert(-123456789000000000000000n + "", "-123456789000000000000000"); >+assert("" + -123456789000000000000000n, "-123456789000000000000000"); >+ >+assert([] + -123456789000000000000000n, "-123456789000000000000000"); >+assert(-123456789000000000000000n + [], "-123456789000000000000000"); >+ >+let a = {}; >+assert(a + 3n, "[object Object]3"); >+assert(3n + a, "3[object Object]"); >+ >diff --git a/JSTests/stress/big-int-addition-to-primitive-precedence.js b/JSTests/stress/big-int-addition-to-primitive-precedence.js >new file mode 100644 >index 0000000000000000000000000000000000000000..cdedc142fc645c23f00b1e8c309246472ec12672 >--- /dev/null >+++ b/JSTests/stress/big-int-addition-to-primitive-precedence.js >@@ -0,0 +1,39 @@ >+//@ runBigIntEnabled >+ >+assert = { >+ sameValue: function (input, expected, message) { >+ if (input !== expected) >+ throw new Error(message); >+ } >+}; >+ >+function testAdd(x, y, z, message) { >+ assert.sameValue(x + y, z, message); >+ assert.sameValue(y + x, z, message); >+} >+ >+testAdd(Object(2n), 1n, 3n, "ToPrimitive: unbox object with internal slot"); >+ >+let o = { >+ [Symbol.toPrimitive]: function() { >+ return 2n; >+ }, >+ valueOf: function () { >+ throw new Error("Should never execute it"); >+ }, >+ toString: function () { >+ throw new Error("Should never execute it"); >+ } >+}; >+testAdd(o, 1n, 3n, "ToPrimitive: @@toPrimitive"); >+ >+o = { >+ valueOf: function() { >+ return 2n; >+ }, >+ toString: function () { >+ throw new Error("Should never execute it"); >+ } >+}; >+testAdd(o, 1n, 3n, "ToPrimitive: valueOf"); >+ >diff --git a/JSTests/stress/big-int-addition-to-primitive.js b/JSTests/stress/big-int-addition-to-primitive.js >new file mode 100644 >index 0000000000000000000000000000000000000000..2f65f9c5396e517ca673f2e0e1f63b43da228f86 >--- /dev/null >+++ b/JSTests/stress/big-int-addition-to-primitive.js >@@ -0,0 +1,39 @@ >+//@ runBigIntEnabled >+ >+function assert(a) { >+ if (!a) >+ throw new Error("Bad assertion"); >+} >+ >+assert.sameValue = function (input, expected, message) { >+ if (input !== expected) >+ throw new Error(message); >+} >+ >+function testAdd(x, y, z) { >+ assert.sameValue(x + y, z, x + " + " + y + " = " + z); >+ assert.sameValue(y + x, z, y + " + " + x + " = " + z); >+} >+ >+let o = { >+ [Symbol.toPrimitive]: function () { return 300000000000000n; } >+} >+ >+testAdd(500000000000438n, o, 800000000000438n); >+ >+o.valueOf = function () { >+ throw new Error("Should never execute it"); >+}; >+ >+testAdd(700000000000438n, o, 1000000000000438n); >+ >+o.toString = function () { >+ throw new Error("Should never execute it"); >+}; >+ >+testAdd(700000000000438n, o, 1000000000000438n); >+ >+delete o.valueOf; >+ >+testAdd(700000000000438n, o, 1000000000000438n); >+ >diff --git a/JSTests/stress/big-int-addition-type-error.js b/JSTests/stress/big-int-addition-type-error.js >new file mode 100644 >index 0000000000000000000000000000000000000000..e2f824c0d9ff1ddc43a4cd60ab93f0f64124a480 >--- /dev/null >+++ b/JSTests/stress/big-int-addition-type-error.js >@@ -0,0 +1,104 @@ >+//@ runBigIntEnabled >+ >+function assert(a, message) { >+ if (!a) >+ throw new Error(message); >+} >+ >+function assertThrowTypeError(a, b, message) { >+ try { >+ let n = a + b; >+ assert(false, message + ": Should throw TypeError, but executed without exception"); >+ } catch (e) { >+ assert(e instanceof TypeError, message + ": expected TypeError, got: " + e); >+ } >+} >+ >+assertThrowTypeError(30n, Symbol("foo"), "BigInt + Symbol"); >+assertThrowTypeError(Symbol("bar"), 18757382984821n, "Symbol + BigInt"); >+assertThrowTypeError(30n, 3320, "BigInt + Int32"); >+assertThrowTypeError(33256, 18757382984821n, "Int32 + BigInt"); >+assertThrowTypeError(30n, 0.543, "BigInt + Double"); >+assertThrowTypeError(230.19293, 18757382984821n, "Double + BigInt"); >+assertThrowTypeError(30n, NaN, "BigInt + NaN"); >+assertThrowTypeError(NaN, 18757382984821n, "NaN + BigInt"); >+assertThrowTypeError(30n, NaN, "BigInt + NaN"); >+assertThrowTypeError(NaN, 18757382984821n, "NaN + BigInt"); >+assertThrowTypeError(30n, +Infinity, "BigInt + NaN"); >+assertThrowTypeError(+Infinity, 18757382984821n, "NaN + BigInt"); >+assertThrowTypeError(30n, -Infinity, "BigInt + -Infinity"); >+assertThrowTypeError(-Infinity, 18757382984821n, "-Infinity + BigInt"); >+assertThrowTypeError(30n, null, "BigInt + null"); >+assertThrowTypeError(null, 18757382984821n, "null + BigInt"); >+assertThrowTypeError(30n, undefined, "BigInt + undefined"); >+assertThrowTypeError(undefined, 18757382984821n, "undefined + BigInt"); >+assertThrowTypeError(30n, true, "BigInt + true"); >+assertThrowTypeError(true, 18757382984821n, "true + BigInt"); >+assertThrowTypeError(30n, false, "BigInt + false"); >+assertThrowTypeError(false, 18757382984821n, "false + BigInt"); >+ >+// Error when returning from object >+ >+let o = { >+ valueOf: function () { return Symbol("Foo"); } >+}; >+ >+assertThrowTypeError(30n, o, "BigInt + Object.valueOf returning Symbol"); >+assertThrowTypeError(o, 18757382984821n, "Object.valueOf returning Symbol + BigInt"); >+ >+o = { >+ valueOf: function () { return 33256; } >+}; >+ >+assertThrowTypeError(30n, o, "BigInt + Object.valueOf returning Int32"); >+assertThrowTypeError(o, 18757382984821n, "Object.valueOf returning Int32 + BigInt"); >+ >+o = { >+ valueOf: function () { return 0.453; } >+}; >+ >+assertThrowTypeError(30n, o, "BigInt + Object.valueOf returning Double"); >+assertThrowTypeError(o, 18757382984821n, "Object.valueOf returning Double + BigInt"); >+ >+o = { >+ toString: function () { return Symbol("Foo"); } >+}; >+ >+assertThrowTypeError(30n, o, "BigInt + Object.toString returning Symbol"); >+assertThrowTypeError(o, 18757382984821n, "Object.toString returning Symbol + BigInt"); >+ >+o = { >+ toString: function () { return 33256; } >+}; >+ >+assertThrowTypeError(30n, o, "BigInt + Object.toString returning Int32"); >+assertThrowTypeError(o, 18757382984821n, "Object.toString returning Int32 + BigInt"); >+ >+o = { >+ toString: function () { return 0.453; } >+}; >+ >+assertThrowTypeError(30n, o, "BigInt + Object.toString returning Double"); >+assertThrowTypeError(o, 18757382984821n, "Object.toString returning Double + BigInt"); >+ >+o = { >+ [Symbol.toPrimitive]: function () { return Symbol("Foo"); } >+}; >+ >+assertThrowTypeError(30n, o, "BigInt + Object.@@toPrimitive returning Symbol"); >+assertThrowTypeError(o, 18757382984821n, "Object.@@toPrimitive returning Symbol + BigInt"); >+ >+o = { >+ [Symbol.toPrimitive]: function () { return 33256; } >+}; >+ >+assertThrowTypeError(30n, o, "BigInt + Object.@@toPrimitive returning Int32"); >+assertThrowTypeError(o, 18757382984821n, "Object.@@toPrimitive returning Int32 + BigInt"); >+ >+o = { >+ [Symbol.toPrimitive]: function () { return 0.453; } >+}; >+ >+assertThrowTypeError(30n, o, "BigInt + Object.@@toPrimitive returning Double"); >+assertThrowTypeError(o, 18757382984821n, "Object.@@toPrimitive returning Double + BigInt"); >+ >diff --git a/JSTests/stress/big-int-no-conversion-to-number.js b/JSTests/stress/big-int-no-conversion-to-number.js >index f380b5752267cea10c613ba14c37e3d7c2f511b0..1406128d1dea02b0827f196f5898d11f77dc3e0b 100644 >--- a/JSTests/stress/big-int-no-conversion-to-number.js >+++ b/JSTests/stress/big-int-no-conversion-to-number.js >@@ -7,6 +7,6 @@ try { > message = error.message; > } > >-if (message !== "Conversion from 'BigInt' to 'number' is not allowed.") { >+if (message !== "Invalid mix of BigInt and other type in addition.") { > throw new Error("Error message has changed to something unexpected"); > } >diff --git a/JSTests/stress/big-int-sub-wrapped-value.js b/JSTests/stress/big-int-sub-wrapped-value.js >new file mode 100644 >index 0000000000000000000000000000000000000000..5b18880f8a74a9cc1cd351da2d51c0f5fb9246da >--- /dev/null >+++ b/JSTests/stress/big-int-sub-wrapped-value.js >@@ -0,0 +1,36 @@ >+//@ runBigIntEnabled >+ >+assert = { >+ sameValue: function (input, expected, message) { >+ if (input !== expected) >+ throw new Error(message); >+ } >+}; >+ >+function testSub(x, y, z, message) { >+ assert.sameValue(x - y, z, message); >+} >+ >+testSub(Object(2n), 1n, 1n, "ToPrimitive: unbox object with internal slot"); >+ >+let o = { >+ [Symbol.toPrimitive]: function() { >+ return 2n; >+ } >+}; >+testSub(o, 1n, 1n, "ToPrimitive: @@toPrimitive"); >+ >+o = { >+ valueOf: function() { >+ return 2n; >+ } >+}; >+testSub(o, 1n, 1n, "ToPrimitive: valueOf"); >+ >+o = { >+ toString: function() { >+ return 2n; >+ } >+} >+testSub(o, 1n, 1n, "ToPrimitive: toString"); >+ >diff --git a/JSTests/stress/big-int-subtraction-basic.js b/JSTests/stress/big-int-subtraction-basic.js >new file mode 100644 >index 0000000000000000000000000000000000000000..90213242b76245e20e98ed5a19ab915ff061e8b9 >--- /dev/null >+++ b/JSTests/stress/big-int-subtraction-basic.js >@@ -0,0 +1,303 @@ >+//@ runBigIntEnabled >+ >+assert = { >+ sameValue: function (input, expected, message) { >+ if (input !== expected) >+ throw new Error(message); >+ } >+}; >+ >+function testSub(x, y, z) { >+ assert.sameValue(x - y, z, x + " - " + y + " = " + z); >+} >+ >+testSub(0xFEDCBA9876543210n, 0xFEDCBA9876543210n, 0x0n); >+testSub(0xFEDCBA9876543210n, 0xFEDCBA987654320Fn, 0x1n); >+testSub(0xFEDCBA9876543210n, 0xFEDCBA98n, 0xFEDCBA9777777778n); >+testSub(0xFEDCBA9876543210n, 0xFEDCBA97n, 0xFEDCBA9777777779n); >+testSub(0xFEDCBA9876543210n, 0x1234n, 0xFEDCBA9876541FDCn); >+testSub(0xFEDCBA9876543210n, 0x3n, 0xFEDCBA987654320Dn); >+testSub(0xFEDCBA9876543210n, 0x2n, 0xFEDCBA987654320En); >+testSub(0xFEDCBA9876543210n, 0x1n, 0xFEDCBA987654320Fn); >+testSub(0xFEDCBA9876543210n, 0x0n, 0xFEDCBA9876543210n); >+testSub(0xFEDCBA9876543210n, -0x1n, 0xFEDCBA9876543211n); >+testSub(0xFEDCBA9876543210n, -0x2n, 0xFEDCBA9876543212n); >+testSub(0xFEDCBA9876543210n, -0x3n, 0xFEDCBA9876543213n); >+testSub(0xFEDCBA9876543210n, -0x1234n, 0xFEDCBA9876544444n); >+testSub(0xFEDCBA9876543210n, -0xFEDCBA97n, 0xFEDCBA997530ECA7n); >+testSub(0xFEDCBA9876543210n, -0xFEDCBA98n, 0xFEDCBA997530ECA8n); >+testSub(0xFEDCBA9876543210n, -0xFEDCBA987654320Fn, 0x1FDB97530ECA8641Fn); >+testSub(0xFEDCBA9876543210n, -0xFEDCBA9876543210n, 0x1FDB97530ECA86420n); >+testSub(0xFEDCBA987654320Fn, 0xFEDCBA9876543210n, -0x1n); >+testSub(0xFEDCBA987654320Fn, 0xFEDCBA987654320Fn, 0x0n); >+testSub(0xFEDCBA987654320Fn, 0xFEDCBA98n, 0xFEDCBA9777777777n); >+testSub(0xFEDCBA987654320Fn, 0xFEDCBA97n, 0xFEDCBA9777777778n); >+testSub(0xFEDCBA987654320Fn, 0x1234n, 0xFEDCBA9876541FDBn); >+testSub(0xFEDCBA987654320Fn, 0x3n, 0xFEDCBA987654320Cn); >+testSub(0xFEDCBA987654320Fn, 0x2n, 0xFEDCBA987654320Dn); >+testSub(0xFEDCBA987654320Fn, 0x1n, 0xFEDCBA987654320En); >+testSub(0xFEDCBA987654320Fn, 0x0n, 0xFEDCBA987654320Fn); >+testSub(0xFEDCBA987654320Fn, -0x1n, 0xFEDCBA9876543210n); >+testSub(0xFEDCBA987654320Fn, -0x2n, 0xFEDCBA9876543211n); >+testSub(0xFEDCBA987654320Fn, -0x3n, 0xFEDCBA9876543212n); >+testSub(0xFEDCBA987654320Fn, -0x1234n, 0xFEDCBA9876544443n); >+testSub(0xFEDCBA987654320Fn, -0xFEDCBA97n, 0xFEDCBA997530ECA6n); >+testSub(0xFEDCBA987654320Fn, -0xFEDCBA98n, 0xFEDCBA997530ECA7n); >+testSub(0xFEDCBA987654320Fn, -0xFEDCBA987654320Fn, 0x1FDB97530ECA8641En); >+testSub(0xFEDCBA987654320Fn, -0xFEDCBA9876543210n, 0x1FDB97530ECA8641Fn); >+testSub(0xFEDCBA98n, 0xFEDCBA9876543210n, -0xFEDCBA9777777778n); >+testSub(0xFEDCBA98n, 0xFEDCBA987654320Fn, -0xFEDCBA9777777777n); >+testSub(0xFEDCBA98n, 0xFEDCBA98n, 0x0n); >+testSub(0xFEDCBA98n, 0xFEDCBA97n, 0x1n); >+testSub(0xFEDCBA98n, 0x1234n, 0xFEDCA864n); >+testSub(0xFEDCBA98n, 0x3n, 0xFEDCBA95n); >+testSub(0xFEDCBA98n, 0x2n, 0xFEDCBA96n); >+testSub(0xFEDCBA98n, 0x1n, 0xFEDCBA97n); >+testSub(0xFEDCBA98n, 0x0n, 0xFEDCBA98n); >+testSub(0xFEDCBA98n, -0x1n, 0xFEDCBA99n); >+testSub(0xFEDCBA98n, -0x2n, 0xFEDCBA9An); >+testSub(0xFEDCBA98n, -0x3n, 0xFEDCBA9Bn); >+testSub(0xFEDCBA98n, -0x1234n, 0xFEDCCCCCn); >+testSub(0xFEDCBA98n, -0xFEDCBA97n, 0x1FDB9752Fn); >+testSub(0xFEDCBA98n, -0xFEDCBA98n, 0x1FDB97530n); >+testSub(0xFEDCBA98n, -0xFEDCBA987654320Fn, 0xFEDCBA997530ECA7n); >+testSub(0xFEDCBA98n, -0xFEDCBA9876543210n, 0xFEDCBA997530ECA8n); >+testSub(0xFEDCBA97n, 0xFEDCBA9876543210n, -0xFEDCBA9777777779n); >+testSub(0xFEDCBA97n, 0xFEDCBA987654320Fn, -0xFEDCBA9777777778n); >+testSub(0xFEDCBA97n, 0xFEDCBA98n, -0x1n); >+testSub(0xFEDCBA97n, 0xFEDCBA97n, 0x0n); >+testSub(0xFEDCBA97n, 0x1234n, 0xFEDCA863n); >+testSub(0xFEDCBA97n, 0x3n, 0xFEDCBA94n); >+testSub(0xFEDCBA97n, 0x2n, 0xFEDCBA95n); >+testSub(0xFEDCBA97n, 0x1n, 0xFEDCBA96n); >+testSub(0xFEDCBA97n, 0x0n, 0xFEDCBA97n); >+testSub(0xFEDCBA97n, -0x1n, 0xFEDCBA98n); >+testSub(0xFEDCBA97n, -0x2n, 0xFEDCBA99n); >+testSub(0xFEDCBA97n, -0x3n, 0xFEDCBA9An); >+testSub(0xFEDCBA97n, -0x1234n, 0xFEDCCCCBn); >+testSub(0xFEDCBA97n, -0xFEDCBA97n, 0x1FDB9752En); >+testSub(0xFEDCBA97n, -0xFEDCBA98n, 0x1FDB9752Fn); >+testSub(0xFEDCBA97n, -0xFEDCBA987654320Fn, 0xFEDCBA997530ECA6n); >+testSub(0xFEDCBA97n, -0xFEDCBA9876543210n, 0xFEDCBA997530ECA7n); >+testSub(0x1234n, 0xFEDCBA9876543210n, -0xFEDCBA9876541FDCn); >+testSub(0x1234n, 0xFEDCBA987654320Fn, -0xFEDCBA9876541FDBn); >+testSub(0x1234n, 0xFEDCBA98n, -0xFEDCA864n); >+testSub(0x1234n, 0xFEDCBA97n, -0xFEDCA863n); >+testSub(0x1234n, 0x1234n, 0x0n); >+testSub(0x1234n, 0x3n, 0x1231n); >+testSub(0x1234n, 0x2n, 0x1232n); >+testSub(0x1234n, 0x1n, 0x1233n); >+testSub(0x1234n, 0x0n, 0x1234n); >+testSub(0x1234n, -0x1n, 0x1235n); >+testSub(0x1234n, -0x2n, 0x1236n); >+testSub(0x1234n, -0x3n, 0x1237n); >+testSub(0x1234n, -0x1234n, 0x2468n); >+testSub(0x1234n, -0xFEDCBA97n, 0xFEDCCCCBn); >+testSub(0x1234n, -0xFEDCBA98n, 0xFEDCCCCCn); >+testSub(0x1234n, -0xFEDCBA987654320Fn, 0xFEDCBA9876544443n); >+testSub(0x1234n, -0xFEDCBA9876543210n, 0xFEDCBA9876544444n); >+testSub(0x3n, 0xFEDCBA9876543210n, -0xFEDCBA987654320Dn); >+testSub(0x3n, 0xFEDCBA987654320Fn, -0xFEDCBA987654320Cn); >+testSub(0x3n, 0xFEDCBA98n, -0xFEDCBA95n); >+testSub(0x3n, 0xFEDCBA97n, -0xFEDCBA94n); >+testSub(0x3n, 0x1234n, -0x1231n); >+testSub(0x3n, 0x3n, 0x0n); >+testSub(0x3n, 0x2n, 0x1n); >+testSub(0x3n, 0x1n, 0x2n); >+testSub(0x3n, 0x0n, 0x3n); >+testSub(0x3n, -0x1n, 0x4n); >+testSub(0x3n, -0x2n, 0x5n); >+testSub(0x3n, -0x3n, 0x6n); >+testSub(0x3n, -0x1234n, 0x1237n); >+testSub(0x3n, -0xFEDCBA97n, 0xFEDCBA9An); >+testSub(0x3n, -0xFEDCBA98n, 0xFEDCBA9Bn); >+testSub(0x3n, -0xFEDCBA987654320Fn, 0xFEDCBA9876543212n); >+testSub(0x3n, -0xFEDCBA9876543210n, 0xFEDCBA9876543213n); >+testSub(0x2n, 0xFEDCBA9876543210n, -0xFEDCBA987654320En); >+testSub(0x2n, 0xFEDCBA987654320Fn, -0xFEDCBA987654320Dn); >+testSub(0x2n, 0xFEDCBA98n, -0xFEDCBA96n); >+testSub(0x2n, 0xFEDCBA97n, -0xFEDCBA95n); >+testSub(0x2n, 0x1234n, -0x1232n); >+testSub(0x2n, 0x3n, -0x1n); >+testSub(0x2n, 0x2n, 0x0n); >+testSub(0x2n, 0x1n, 0x1n); >+testSub(0x2n, 0x0n, 0x2n); >+testSub(0x2n, -0x1n, 0x3n); >+testSub(0x2n, -0x2n, 0x4n); >+testSub(0x2n, -0x3n, 0x5n); >+testSub(0x2n, -0x1234n, 0x1236n); >+testSub(0x2n, -0xFEDCBA97n, 0xFEDCBA99n); >+testSub(0x2n, -0xFEDCBA98n, 0xFEDCBA9An); >+testSub(0x2n, -0xFEDCBA987654320Fn, 0xFEDCBA9876543211n); >+testSub(0x2n, -0xFEDCBA9876543210n, 0xFEDCBA9876543212n); >+testSub(0x1n, 0xFEDCBA9876543210n, -0xFEDCBA987654320Fn); >+testSub(0x1n, 0xFEDCBA987654320Fn, -0xFEDCBA987654320En); >+testSub(0x1n, 0xFEDCBA98n, -0xFEDCBA97n); >+testSub(0x1n, 0xFEDCBA97n, -0xFEDCBA96n); >+testSub(0x1n, 0x1234n, -0x1233n); >+testSub(0x1n, 0x3n, -0x2n); >+testSub(0x1n, 0x2n, -0x1n); >+testSub(0x1n, 0x1n, 0x0n); >+testSub(0x1n, 0x0n, 0x1n); >+testSub(0x1n, -0x1n, 0x2n); >+testSub(0x1n, -0x2n, 0x3n); >+testSub(0x1n, -0x3n, 0x4n); >+testSub(0x1n, -0x1234n, 0x1235n); >+testSub(0x1n, -0xFEDCBA97n, 0xFEDCBA98n); >+testSub(0x1n, -0xFEDCBA98n, 0xFEDCBA99n); >+testSub(0x1n, -0xFEDCBA987654320Fn, 0xFEDCBA9876543210n); >+testSub(0x1n, -0xFEDCBA9876543210n, 0xFEDCBA9876543211n); >+testSub(0x0n, 0xFEDCBA9876543210n, -0xFEDCBA9876543210n); >+testSub(0x0n, 0xFEDCBA987654320Fn, -0xFEDCBA987654320Fn); >+testSub(0x0n, 0xFEDCBA98n, -0xFEDCBA98n); >+testSub(0x0n, 0xFEDCBA97n, -0xFEDCBA97n); >+testSub(0x0n, 0x1234n, -0x1234n); >+testSub(0x0n, 0x3n, -0x3n); >+testSub(0x0n, 0x2n, -0x2n); >+testSub(0x0n, 0x1n, -0x1n); >+testSub(0x0n, 0x0n, 0x0n); >+testSub(0x0n, -0x1n, 0x1n); >+testSub(0x0n, -0x2n, 0x2n); >+testSub(0x0n, -0x3n, 0x3n); >+testSub(0x0n, -0x1234n, 0x1234n); >+testSub(0x0n, -0xFEDCBA97n, 0xFEDCBA97n); >+testSub(0x0n, -0xFEDCBA98n, 0xFEDCBA98n); >+testSub(0x0n, -0xFEDCBA987654320Fn, 0xFEDCBA987654320Fn); >+testSub(0x0n, -0xFEDCBA9876543210n, 0xFEDCBA9876543210n); >+testSub(-0x1n, 0xFEDCBA9876543210n, -0xFEDCBA9876543211n); >+testSub(-0x1n, 0xFEDCBA987654320Fn, -0xFEDCBA9876543210n); >+testSub(-0x1n, 0xFEDCBA98n, -0xFEDCBA99n); >+testSub(-0x1n, 0xFEDCBA97n, -0xFEDCBA98n); >+testSub(-0x1n, 0x1234n, -0x1235n); >+testSub(-0x1n, 0x3n, -0x4n); >+testSub(-0x1n, 0x2n, -0x3n); >+testSub(-0x1n, 0x1n, -0x2n); >+testSub(-0x1n, 0x0n, -0x1n); >+testSub(-0x1n, -0x1n, 0x0n); >+testSub(-0x1n, -0x2n, 0x1n); >+testSub(-0x1n, -0x3n, 0x2n); >+testSub(-0x1n, -0x1234n, 0x1233n); >+testSub(-0x1n, -0xFEDCBA97n, 0xFEDCBA96n); >+testSub(-0x1n, -0xFEDCBA98n, 0xFEDCBA97n); >+testSub(-0x1n, -0xFEDCBA987654320Fn, 0xFEDCBA987654320En); >+testSub(-0x1n, -0xFEDCBA9876543210n, 0xFEDCBA987654320Fn); >+testSub(-0x2n, 0xFEDCBA9876543210n, -0xFEDCBA9876543212n); >+testSub(-0x2n, 0xFEDCBA987654320Fn, -0xFEDCBA9876543211n); >+testSub(-0x2n, 0xFEDCBA98n, -0xFEDCBA9An); >+testSub(-0x2n, 0xFEDCBA97n, -0xFEDCBA99n); >+testSub(-0x2n, 0x1234n, -0x1236n); >+testSub(-0x2n, 0x3n, -0x5n); >+testSub(-0x2n, 0x2n, -0x4n); >+testSub(-0x2n, 0x1n, -0x3n); >+testSub(-0x2n, 0x0n, -0x2n); >+testSub(-0x2n, -0x1n, -0x1n); >+testSub(-0x2n, -0x2n, 0x0n); >+testSub(-0x2n, -0x3n, 0x1n); >+testSub(-0x2n, -0x1234n, 0x1232n); >+testSub(-0x2n, -0xFEDCBA97n, 0xFEDCBA95n); >+testSub(-0x2n, -0xFEDCBA98n, 0xFEDCBA96n); >+testSub(-0x2n, -0xFEDCBA987654320Fn, 0xFEDCBA987654320Dn); >+testSub(-0x2n, -0xFEDCBA9876543210n, 0xFEDCBA987654320En); >+testSub(-0x3n, 0xFEDCBA9876543210n, -0xFEDCBA9876543213n); >+testSub(-0x3n, 0xFEDCBA987654320Fn, -0xFEDCBA9876543212n); >+testSub(-0x3n, 0xFEDCBA98n, -0xFEDCBA9Bn); >+testSub(-0x3n, 0xFEDCBA97n, -0xFEDCBA9An); >+testSub(-0x3n, 0x1234n, -0x1237n); >+testSub(-0x3n, 0x3n, -0x6n); >+testSub(-0x3n, 0x2n, -0x5n); >+testSub(-0x3n, 0x1n, -0x4n); >+testSub(-0x3n, 0x0n, -0x3n); >+testSub(-0x3n, -0x1n, -0x2n); >+testSub(-0x3n, -0x2n, -0x1n); >+testSub(-0x3n, -0x3n, 0x0n); >+testSub(-0x3n, -0x1234n, 0x1231n); >+testSub(-0x3n, -0xFEDCBA97n, 0xFEDCBA94n); >+testSub(-0x3n, -0xFEDCBA98n, 0xFEDCBA95n); >+testSub(-0x3n, -0xFEDCBA987654320Fn, 0xFEDCBA987654320Cn); >+testSub(-0x3n, -0xFEDCBA9876543210n, 0xFEDCBA987654320Dn); >+testSub(-0x1234n, 0xFEDCBA9876543210n, -0xFEDCBA9876544444n); >+testSub(-0x1234n, 0xFEDCBA987654320Fn, -0xFEDCBA9876544443n); >+testSub(-0x1234n, 0xFEDCBA98n, -0xFEDCCCCCn); >+testSub(-0x1234n, 0xFEDCBA97n, -0xFEDCCCCBn); >+testSub(-0x1234n, 0x1234n, -0x2468n); >+testSub(-0x1234n, 0x3n, -0x1237n); >+testSub(-0x1234n, 0x2n, -0x1236n); >+testSub(-0x1234n, 0x1n, -0x1235n); >+testSub(-0x1234n, 0x0n, -0x1234n); >+testSub(-0x1234n, -0x1n, -0x1233n); >+testSub(-0x1234n, -0x2n, -0x1232n); >+testSub(-0x1234n, -0x3n, -0x1231n); >+testSub(-0x1234n, -0x1234n, 0x0n); >+testSub(-0x1234n, -0xFEDCBA97n, 0xFEDCA863n); >+testSub(-0x1234n, -0xFEDCBA98n, 0xFEDCA864n); >+testSub(-0x1234n, -0xFEDCBA987654320Fn, 0xFEDCBA9876541FDBn); >+testSub(-0x1234n, -0xFEDCBA9876543210n, 0xFEDCBA9876541FDCn); >+testSub(-0xFEDCBA97n, 0xFEDCBA9876543210n, -0xFEDCBA997530ECA7n); >+testSub(-0xFEDCBA97n, 0xFEDCBA987654320Fn, -0xFEDCBA997530ECA6n); >+testSub(-0xFEDCBA97n, 0xFEDCBA98n, -0x1FDB9752Fn); >+testSub(-0xFEDCBA97n, 0xFEDCBA97n, -0x1FDB9752En); >+testSub(-0xFEDCBA97n, 0x1234n, -0xFEDCCCCBn); >+testSub(-0xFEDCBA97n, 0x3n, -0xFEDCBA9An); >+testSub(-0xFEDCBA97n, 0x2n, -0xFEDCBA99n); >+testSub(-0xFEDCBA97n, 0x1n, -0xFEDCBA98n); >+testSub(-0xFEDCBA97n, 0x0n, -0xFEDCBA97n); >+testSub(-0xFEDCBA97n, -0x1n, -0xFEDCBA96n); >+testSub(-0xFEDCBA97n, -0x2n, -0xFEDCBA95n); >+testSub(-0xFEDCBA97n, -0x3n, -0xFEDCBA94n); >+testSub(-0xFEDCBA97n, -0x1234n, -0xFEDCA863n); >+testSub(-0xFEDCBA97n, -0xFEDCBA97n, 0x0n); >+testSub(-0xFEDCBA97n, -0xFEDCBA98n, 0x1n); >+testSub(-0xFEDCBA97n, -0xFEDCBA987654320Fn, 0xFEDCBA9777777778n); >+testSub(-0xFEDCBA97n, -0xFEDCBA9876543210n, 0xFEDCBA9777777779n); >+testSub(-0xFEDCBA98n, 0xFEDCBA9876543210n, -0xFEDCBA997530ECA8n); >+testSub(-0xFEDCBA98n, 0xFEDCBA987654320Fn, -0xFEDCBA997530ECA7n); >+testSub(-0xFEDCBA98n, 0xFEDCBA98n, -0x1FDB97530n); >+testSub(-0xFEDCBA98n, 0xFEDCBA97n, -0x1FDB9752Fn); >+testSub(-0xFEDCBA98n, 0x1234n, -0xFEDCCCCCn); >+testSub(-0xFEDCBA98n, 0x3n, -0xFEDCBA9Bn); >+testSub(-0xFEDCBA98n, 0x2n, -0xFEDCBA9An); >+testSub(-0xFEDCBA98n, 0x1n, -0xFEDCBA99n); >+testSub(-0xFEDCBA98n, 0x0n, -0xFEDCBA98n); >+testSub(-0xFEDCBA98n, -0x1n, -0xFEDCBA97n); >+testSub(-0xFEDCBA98n, -0x2n, -0xFEDCBA96n); >+testSub(-0xFEDCBA98n, -0x3n, -0xFEDCBA95n); >+testSub(-0xFEDCBA98n, -0x1234n, -0xFEDCA864n); >+testSub(-0xFEDCBA98n, -0xFEDCBA97n, -0x1n); >+testSub(-0xFEDCBA98n, -0xFEDCBA98n, 0x0n); >+testSub(-0xFEDCBA98n, -0xFEDCBA987654320Fn, 0xFEDCBA9777777777n); >+testSub(-0xFEDCBA98n, -0xFEDCBA9876543210n, 0xFEDCBA9777777778n); >+testSub(-0xFEDCBA987654320Fn, 0xFEDCBA9876543210n, -0x1FDB97530ECA8641Fn); >+testSub(-0xFEDCBA987654320Fn, 0xFEDCBA987654320Fn, -0x1FDB97530ECA8641En); >+testSub(-0xFEDCBA987654320Fn, 0xFEDCBA98n, -0xFEDCBA997530ECA7n); >+testSub(-0xFEDCBA987654320Fn, 0xFEDCBA97n, -0xFEDCBA997530ECA6n); >+testSub(-0xFEDCBA987654320Fn, 0x1234n, -0xFEDCBA9876544443n); >+testSub(-0xFEDCBA987654320Fn, 0x3n, -0xFEDCBA9876543212n); >+testSub(-0xFEDCBA987654320Fn, 0x2n, -0xFEDCBA9876543211n); >+testSub(-0xFEDCBA987654320Fn, 0x1n, -0xFEDCBA9876543210n); >+testSub(-0xFEDCBA987654320Fn, 0x0n, -0xFEDCBA987654320Fn); >+testSub(-0xFEDCBA987654320Fn, -0x1n, -0xFEDCBA987654320En); >+testSub(-0xFEDCBA987654320Fn, -0x2n, -0xFEDCBA987654320Dn); >+testSub(-0xFEDCBA987654320Fn, -0x3n, -0xFEDCBA987654320Cn); >+testSub(-0xFEDCBA987654320Fn, -0x1234n, -0xFEDCBA9876541FDBn); >+testSub(-0xFEDCBA987654320Fn, -0xFEDCBA97n, -0xFEDCBA9777777778n); >+testSub(-0xFEDCBA987654320Fn, -0xFEDCBA98n, -0xFEDCBA9777777777n); >+testSub(-0xFEDCBA987654320Fn, -0xFEDCBA987654320Fn, 0x0n); >+testSub(-0xFEDCBA987654320Fn, -0xFEDCBA9876543210n, 0x1n); >+testSub(-0xFEDCBA9876543210n, 0xFEDCBA9876543210n, -0x1FDB97530ECA86420n); >+testSub(-0xFEDCBA9876543210n, 0xFEDCBA987654320Fn, -0x1FDB97530ECA8641Fn); >+testSub(-0xFEDCBA9876543210n, 0xFEDCBA98n, -0xFEDCBA997530ECA8n); >+testSub(-0xFEDCBA9876543210n, 0xFEDCBA97n, -0xFEDCBA997530ECA7n); >+testSub(-0xFEDCBA9876543210n, 0x1234n, -0xFEDCBA9876544444n); >+testSub(-0xFEDCBA9876543210n, 0x3n, -0xFEDCBA9876543213n); >+testSub(-0xFEDCBA9876543210n, 0x2n, -0xFEDCBA9876543212n); >+testSub(-0xFEDCBA9876543210n, 0x1n, -0xFEDCBA9876543211n); >+testSub(-0xFEDCBA9876543210n, 0x0n, -0xFEDCBA9876543210n); >+testSub(-0xFEDCBA9876543210n, -0x1n, -0xFEDCBA987654320Fn); >+testSub(-0xFEDCBA9876543210n, -0x2n, -0xFEDCBA987654320En); >+testSub(-0xFEDCBA9876543210n, -0x3n, -0xFEDCBA987654320Dn); >+testSub(-0xFEDCBA9876543210n, -0x1234n, -0xFEDCBA9876541FDCn); >+testSub(-0xFEDCBA9876543210n, -0xFEDCBA97n, -0xFEDCBA9777777779n); >+testSub(-0xFEDCBA9876543210n, -0xFEDCBA98n, -0xFEDCBA9777777778n); >+testSub(-0xFEDCBA9876543210n, -0xFEDCBA987654320Fn, -0x1n); >+testSub(-0xFEDCBA9876543210n, -0xFEDCBA9876543210n, 0x0n); >+ >diff --git a/JSTests/stress/big-int-subtraction-jit.js b/JSTests/stress/big-int-subtraction-jit.js >new file mode 100644 >index 0000000000000000000000000000000000000000..cb081aafb817bc39dfe56c23121c6781261c949b >--- /dev/null >+++ b/JSTests/stress/big-int-subtraction-jit.js >@@ -0,0 +1,19 @@ >+//@ runBigIntEnabled >+ >+let assert = { >+ sameValue: function(i, e, m) { >+ if (i !== e) >+ throw new Error(m); >+ } >+} >+ >+function bigIntAddition(x, y) { >+ return x - y; >+} >+noInline(bigIntAddition); >+ >+for (let i = 0; i < 10000; i++) { >+ let r = bigIntAddition(3n, 10n); >+ assert.sameValue(r, -7n, 3n + " - " + 10n + " = " + r); >+} >+ >diff --git a/JSTests/stress/big-int-subtraction-type-error.js b/JSTests/stress/big-int-subtraction-type-error.js >new file mode 100644 >index 0000000000000000000000000000000000000000..74ac48a589e3330c0c6c755032661740c4b06ce7 >--- /dev/null >+++ b/JSTests/stress/big-int-subtraction-type-error.js >@@ -0,0 +1,125 @@ >+//@ runBigIntEnabled >+ >+function assert(a, message) { >+ if (!a) >+ throw new Error(message); >+} >+ >+function assertThrowTypeError(a, b, message) { >+ try { >+ let n = a - b; >+ assert(false, message + ": Should throw TypeError, but executed without exception"); >+ } catch (e) { >+ assert(e instanceof TypeError, message + ": expected TypeError, got: " + e); >+ } >+} >+ >+assertThrowTypeError(30n, Symbol("foo"), "BingInt - Symbol"); >+assertThrowTypeError(Symbol("bar"), 18757382984821n, "Symbol - BigInt"); >+assertThrowTypeError(30n, 3320, "BingInt - Int32"); >+assertThrowTypeError(33256, 18757382984821n, "Int32 - BigInt"); >+assertThrowTypeError(30n, 0.543, "BingInt - Double"); >+assertThrowTypeError(230.19293, 18757382984821n, "Double - BigInt"); >+assertThrowTypeError(18757382984821n, "abc", "BigInt - String"); >+assertThrowTypeError("def", 18757382984821n, "String - BigInt"); >+assertThrowTypeError(18757382984821n, "", "BigInt - Empty String"); >+assertThrowTypeError("", 18757382984821n, "Empty - BigInt"); >+assertThrowTypeError(18757382984821n, NaN, "BigInt - NaN"); >+assertThrowTypeError(NaN, 18757382984821n, "NaN - BigInt"); >+assertThrowTypeError(18757382984821n, undefined, "BigInt - undefined"); >+assertThrowTypeError(undefined, 18757382984821n, "undefined - BigInt"); >+assertThrowTypeError(18757382984821n, true, "BigInt - true"); >+assertThrowTypeError(true, 18757382984821n, "true - BigInt"); >+assertThrowTypeError(18757382984821n, false, "BigInt - false"); >+assertThrowTypeError(false, 18757382984821n, "false - BigInt"); >+assertThrowTypeError(18757382984821n, +Infinity, "BigInt - Infinity"); >+assertThrowTypeError(+Infinity, 18757382984821n, "Infinity - BigInt"); >+assertThrowTypeError(18757382984821n, -Infinity, "BigInt - -Infinity"); >+assertThrowTypeError(-Infinity, 18757382984821n, "-Infinity - BigInt"); >+ >+// Error when returning from object >+ >+let o = { >+ valueOf: function () { return Symbol("Foo"); } >+}; >+ >+assertThrowTypeError(30n, o, "BingInt - Object.valueOf returning Symbol"); >+assertThrowTypeError(o, 18757382984821n, "Object.valueOf returning Symbol - BigInt"); >+ >+o = { >+ valueOf: function () { return 33256; } >+}; >+ >+assertThrowTypeError(30n, o, "BingInt - Object.valueOf returning Int32"); >+assertThrowTypeError(o, 18757382984821n, "Object.valueOf returning Int32 - BigInt"); >+ >+o = { >+ valueOf: function () { return 0.453; } >+}; >+ >+assertThrowTypeError(30n, o, "BingInt - Object.valueOf returning Double"); >+assertThrowTypeError(o, 18757382984821n, "Object.valueOf returning Double - BigInt"); >+ >+o = { >+ valueOf: function () { return ""; } >+}; >+ >+assertThrowTypeError(30n, o, "BingInt - Object.valueOf returning String"); >+assertThrowTypeError(o, 18757382984821n, "Object.valueOf returning String - BigInt"); >+ >+o = { >+ toString: function () { return Symbol("Foo"); } >+}; >+ >+assertThrowTypeError(30n, o, "BingInt - Object.toString returning Symbol"); >+assertThrowTypeError(o, 18757382984821n, "Object.toString returning Symbol - BigInt"); >+ >+o = { >+ toString: function () { return 33256; } >+}; >+ >+assertThrowTypeError(30n, o, "BingInt - Object.toString returning Int32"); >+assertThrowTypeError(o, 18757382984821n, "Object.toString returning Int32 - BigInt"); >+ >+o = { >+ toString: function () { return 0.453; } >+}; >+ >+assertThrowTypeError(30n, o, "BingInt - Object.toString returning Double"); >+assertThrowTypeError(o, 18757382984821n, "Object.toString returning Double - BigInt"); >+ >+o = { >+ toString: function () { return "abc"; } >+}; >+ >+assertThrowTypeError(30n, o, "BingInt - Object.toString returning String"); >+assertThrowTypeError(o, 18757382984821n, "Object.toString returning String - BigInt"); >+ >+o = { >+ [Symbol.toPrimitive]: function () { return Symbol("Foo"); } >+}; >+ >+assertThrowTypeError(30n, o, "BingInt - Object.@@toPrimitive returning Symbol"); >+assertThrowTypeError(o, 18757382984821n, "Object.@@toPrimitive returning Symbol - BigInt"); >+ >+o = { >+ [Symbol.toPrimitive]: function () { return 33256; } >+}; >+ >+assertThrowTypeError(30n, o, "BingInt - Object.@@toPrimitive returning Int32"); >+assertThrowTypeError(o, 18757382984821n, "Object.@@toPrimitive returning Int32 - BigInt"); >+ >+o = { >+ [Symbol.toPrimitive]: function () { return 0.453; } >+}; >+ >+assertThrowTypeError(30n, o, "BingInt - Object.@@toPrimitive returning Double"); >+assertThrowTypeError(o, 18757382984821n, "Object.@@toPrimitive returning Double - BigInt"); >+ >+o = { >+ [Symbol.toPrimitive]: function () { return "Abc"; } >+}; >+ >+assertThrowTypeError(30n, o, "BingInt - Object.@@toPrimitive returning String"); >+assertThrowTypeError(o, 18757382984821n, "Object.@@toPrimitive returning String - BigInt"); >+ >diff --git a/JSTests/stress/sub-order-evaluation.js b/JSTests/stress/sub-order-evaluation.js >new file mode 100644 >index 0000000000000000000000000000000000000000..21f923431bb98f25021d1eddc278555412c43463 >--- /dev/null >+++ b/JSTests/stress/sub-order-evaluation.js >@@ -0,0 +1,27 @@ >+function assert(a, message) { >+ if (!a) >+ throw new Error(message); >+} >+ >+function assertThrowTypeError(a, b, message) { >+ try { >+ let n = a - b; >+ assert(false, message + ": Should throw TypeError, but executed without exception"); >+ } catch (e) { >+ assert(e instanceof TypeError, message + ": expected TypeError, got: " + e); >+ } >+} >+ >+let o = { >+ valueOf: function () { throw new Error("Oops"); } >+}; >+ >+assertThrowTypeError(Symbol("3"), o, "Symbol + Object should throw TypeError"); >+ >+try { >+ let n = o - Symbol("3"); >+ assert(false, message + ": Should throw Error, but executed without exception"); >+} catch (e) { >+ assert(e.message === "Oops","Expected Error('Oops'), got: " + e); >+} >+
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Flags:
ysuzuki
:
review+
Actions:
View
|
Formatted Diff
|
Diff
Attachments on
bug 179002
:
331884
|
331885
|
331886
|
331887
|
331888
|
332079
|
332085
|
332096
|
332097
|
332101
|
332106
|
332144
|
332146
|
332195
|
332317
|
332318
|
332320
|
341725
|
341759
|
341815
|
341860