From 31c2fea74af66d60dceab608b1cfdd9a3f08a7db Mon Sep 17 00:00:00 2001 From: Dylan Conway <35280289+dylan-conway@users.noreply.github.com> Date: Wed, 22 Mar 2023 18:09:51 -0700 Subject: A couple bug fixes (#2458) * fix valid status code range * update path * highwatermark option * throw DOMException * remove extra transpiler output * more transpiler tests * comment * get index not quickly * replace with `getDirectIndex` * update abort test * throw out of range status code * promisify test fix * move stdio test instance files * working crypto tests * allow duplicate set-cookie headers * different formatting * revert, fix will be in different pr * it is called * use min buffer size * fix url tests * null origin for other protocols * remove overload * add very large file test * await * coerce to int64 * 64 * no cast * add todo blob url tests * use `tryConvertToInt52` --- src/bun.js/bindings/bindings.cpp | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) (limited to 'src/bun.js/bindings/bindings.cpp') diff --git a/src/bun.js/bindings/bindings.cpp b/src/bun.js/bindings/bindings.cpp index a5af29128..f43bfd4b8 100644 --- a/src/bun.js/bindings/bindings.cpp +++ b/src/bun.js/bindings/bindings.cpp @@ -478,12 +478,10 @@ bool Bun__deepEquals(JSC__JSGlobalObject* globalObject, JSValue v1, JSValue v2, } for (uint64_t i = 0; i < length; i++) { - // array holes come back as empty values with tryGetIndexQuickly() JSValue left = o1->canGetIndexQuickly(i) ? o1->getIndexQuickly(i) : o1->tryGetIndexQuickly(i); RETURN_IF_EXCEPTION(*scope, false); - JSValue right = o2->canGetIndexQuickly(i) ? o2->getIndexQuickly(i) : o2->tryGetIndexQuickly(i); @@ -2834,9 +2832,28 @@ int32_t JSC__JSValue__toInt32(JSC__JSValue JSValue0) return JSC::JSValue::decode(JSValue0).asInt32(); } +// truncates values larger than int32 int32_t JSC__JSValue__coerceToInt32(JSC__JSValue JSValue0, JSC__JSGlobalObject* arg1) { JSC::JSValue value = JSC::JSValue::decode(JSValue0); + if (value.isCell() && value.isHeapBigInt()) { + return static_cast(value.toBigInt64(arg1)); + } + return value.toInt32(arg1); +} + +int64_t JSC__JSValue__coerceToInt64(JSC__JSValue JSValue0, JSC__JSGlobalObject* arg1) +{ + JSValue value = JSValue::decode(JSValue0); + if (value.isCell() && value.isHeapBigInt()) { + return value.toBigInt64(arg1); + } + + int64_t result = tryConvertToInt52(value.asDouble()); + if (result != JSValue::notInt52) { + return result; + } + return value.toInt32(arg1); } -- cgit v1.2.3