Bug 1536695 - Part 2: Support infallible conversion for BigInt types. r=jandem
authorAndré Bargull <andre.bargull@gmail.com>
Thu, 11 Apr 2019 14:08:33 +0000
changeset 469051 cb9e9d32e5213700d73b041daa4971f6a4785497
parent 469050 a40f5c68f454d5e9ab2066cc298681ba4da134fc
child 469052 5b6bf24882cee31b0d344a0fe1f5f7d5076d3cec
push id35856
push usercsabou@mozilla.com
push dateFri, 12 Apr 2019 03:19:48 +0000
treeherdermozilla-central@940684cd1065 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjandem
bugs1536695
milestone68.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1536695 - Part 2: Support infallible conversion for BigInt types. r=jandem Differential Revision: https://phabricator.services.mozilla.com/D26119
js/src/vm/TypedArrayObject-inl.h
--- a/js/src/vm/TypedArrayObject-inl.h
+++ b/js/src/vm/TypedArrayObject-inl.h
@@ -19,16 +19,17 @@
 
 #include "jsnum.h"
 
 #include "builtin/Array.h"
 #include "gc/Zone.h"
 #include "jit/AtomicOperations.h"
 #include "js/Conversions.h"
 #include "js/Value.h"
+#include "vm/BigIntType.h"
 #include "vm/JSContext.h"
 #include "vm/NativeObject.h"
 
 #include "gc/ObjectKind-inl.h"
 #include "vm/ObjectOperations-inl.h"
 
 namespace js {
 
@@ -639,22 +640,38 @@ class ElementSpecific {
 
     js_free(data);
     return true;
   }
 
   static bool canConvertInfallibly(const Value& v) {
     if (TypeIDOfType<T>::id == Scalar::BigInt64 ||
         TypeIDOfType<T>::id == Scalar::BigUint64) {
-      return false;
+      // Numbers, Null, Undefined, and Symbols throw a TypeError. Strings may
+      // OOM and Objects may have side-effects.
+      return v.isBigInt() || v.isBoolean();
     }
+    // BigInts and Symbols throw a TypeError. Strings may OOM and Objects may
+    // have side-effects.
     return v.isNumber() || v.isBoolean() || v.isNull() || v.isUndefined();
   }
 
   static T infallibleValueToNative(const Value& v) {
+    if (TypeIDOfType<T>::id == Scalar::BigInt64) {
+      if (v.isBigInt()) {
+        return T(BigInt::toInt64(v.toBigInt()));
+      }
+      return T(v.toBoolean());
+    }
+    if (TypeIDOfType<T>::id == Scalar::BigUint64) {
+      if (v.isBigInt()) {
+        return T(BigInt::toUint64(v.toBigInt()));
+      }
+      return T(v.toBoolean());
+    }
     if (v.isInt32()) {
       return T(v.toInt32());
     }
     if (v.isDouble()) {
       return doubleToNative(v.toDouble());
     }
     if (v.isBoolean()) {
       return T(v.toBoolean());