From eb495182d2341c828787d522e7deab3e432ef975 Mon Sep 17 00:00:00 2001 From: Alexey Andreev Date: Mon, 22 Mar 2021 15:13:40 +0300 Subject: [PATCH] JS: fix runtime for Safari --- .../org/teavm/backend/javascript/runtime.js | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/core/src/main/resources/org/teavm/backend/javascript/runtime.js b/core/src/main/resources/org/teavm/backend/javascript/runtime.js index 3bcd3de66..e680f7bc1 100644 --- a/core/src/main/resources/org/teavm/backend/javascript/runtime.js +++ b/core/src/main/resources/org/teavm/backend/javascript/runtime.js @@ -670,10 +670,17 @@ if (typeof BigInt !== 'function') { } else { $rt_doubleToLongBits = function(n) { $rt_numberConversionView.setFloat64(0, n, true); - return $rt_numberConversionView.getBigInt64(0, true); + // For compatibility with Safari + var lo = $rt_numberConversionView.getInt32(0, true); + var hi = $rt_numberConversionView.getInt32(4, true); + return BigInt.asIntN(64, BigInt.asUintN(32, BigInt(lo)) | (BigInt(hi) << BigInt(32))); } $rt_longBitsToDouble = function(n) { - $rt_numberConversionView.setBigInt64(0, n, true); + // For compatibility with Safari + var hi = Number(BigInt.asIntN(32, n >> BigInt(32))); + var lo = Number(BigInt.asIntN(32, n & BigInt(0xFFFFFFFF))); + $rt_numberConversionView.setInt32(0, lo, true); + $rt_numberConversionView.setInt32(4, hi, true); return $rt_numberConversionView.getFloat64(0, true); } } @@ -806,7 +813,7 @@ if (typeof BigInt !== "function") { } else { Long_ZERO = BigInt(0); Long_create = function(lo, hi) { - return BigInt.asIntN(64, BigInt(lo) | (BigInt(hi) << BigInt(32))); + return BigInt.asIntN(64, BigInt.asUintN(32, BigInt(lo)) | (BigInt(hi) << BigInt(32))); } Long_fromInt = function(val) { return BigInt(val);