Bug 1502811 - Templatize IsWrappedInstanceOfBuiltin and IsPossiblyWrappedInstanceOfBuiltin intrinsics. r=Waldo
authorAndré Bargull <andre.bargull@gmail.com>
Mon, 29 Oct 2018 05:42:43 -0700
changeset 443374 dc596db0d11dc01cbd260c572447f6ab2b2155ac
parent 443373 89349ce25fe3e40fb2805a1aeaeda86e00374f6c
child 443375 5428178c96e28858e11537b849c6694f3f2205b2
push id34955
push userrgurzau@mozilla.com
push dateMon, 29 Oct 2018 22:01:36 +0000
treeherdermozilla-central@4c7772c170a1 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersWaldo
bugs1502811
milestone65.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 1502811 - Templatize IsWrappedInstanceOfBuiltin and IsPossiblyWrappedInstanceOfBuiltin intrinsics. r=Waldo
js/src/builtin/TypedArray.js
js/src/jit-test/tests/self-hosting/is-possibly-wrapped-typed-array.js
js/src/vm/SelfHosting.cpp
--- a/js/src/builtin/TypedArray.js
+++ b/js/src/builtin/TypedArray.js
@@ -976,17 +976,17 @@ function TypedArraySet(overloaded, offse
 
     // Steps 9-10.
     var targetBuffer = GetAttachedArrayBuffer(target);
 
     // Step 11.
     var targetLength = TypedArrayLength(target);
 
     // Steps 12 et seq.
-    if (IsPossiblyWrappedTypedArray(overloaded))
+    if (IsObject(overloaded) && IsPossiblyWrappedTypedArray(overloaded))
         return SetFromTypedArray(target, overloaded, targetOffset, targetLength);
 
     return SetFromNonTypedArray(target, overloaded, targetOffset, targetLength, targetBuffer);
 }
 
 // ES2017 draft rev 6859bb9ccaea9c6ede81d71e5320e3833b92cb3e
 // 22.2.3.24 %TypedArray%.prototype.slice ( start, end )
 function TypedArraySlice(start, end) {
--- a/js/src/jit-test/tests/self-hosting/is-possibly-wrapped-typed-array.js
+++ b/js/src/jit-test/tests/self-hosting/is-possibly-wrapped-typed-array.js
@@ -13,23 +13,16 @@ var declareSamples = `
         { value: new Uint8ClampedArray(1), expected: true }
     ];
 
     var allObjectSamples = [
         { value: new Array(1), expected: false },
         { value: {}, expected: false },
         { value: { length: 1 }, expected: false }
     ];
-
-    var allNonObjectSamples = [
-        { value: "a", expected: false },
-        { value: 1.2, expected: false },
-        { value: true, expected: false },
-        { value: Symbol("a"), expected: false }
-    ];
 `;
 
 // Create a new global to wrap with cross compartment wrappers.
 var g = newGlobal();
 evaluate(declareSamples)
 g.evaluate(declareSamples);
 
 var assertCode = `function (value, expected) {
@@ -57,95 +50,42 @@ function checkSamples(samples) {
             var e = samples[i];
             if (!e) continue;
             spinInJit = spinInJit && assert(e.value, e.expected);
         }
     } while(!spinInJit);
 }
 
 // Check a mix of samples from each type.
-function test(a, b, c, d, e, f) {
+function test(a, b, c, d) {
     var samples = [
         a == -1 ? null : allTypedArraySamples[a],
         b == -1 ? null : allObjectSamples[b],
-        c == -1 ? null : allNonObjectSamples[c],
-        d == -1 ? null : g.allTypedArraySamples[d],
-        e == -1 ? null : g.allObjectSamples[e],
-        f == -1 ? null : g.allNonObjectSamples[f]
+        c == -1 ? null : g.allTypedArraySamples[c],
+        d == -1 ? null : g.allObjectSamples[d],
     ];
 
     checkSamples(samples);
 }
 
 // Check all samples.
 checkSamples(allTypedArraySamples);
 checkSamples(allObjectSamples);
-checkSamples(allNonObjectSamples);
 checkSamples(g.allTypedArraySamples);
 checkSamples(g.allObjectSamples);
-checkSamples(g.allNonObjectSamples);
 
 // Check combinations mixing 2 elements from different types.
-test(-1, -1, -1, -1,  0,  0);
-test(-1, -1, -1,  0, -1,  0);
-test(-1, -1, -1,  0,  0, -1);
-test(-1, -1,  0, -1, -1,  0);
-test(-1, -1,  0, -1,  0, -1);
-test(-1, -1,  0,  0, -1, -1);
-test(-1,  0, -1, -1, -1,  0);
-test(-1,  0, -1, -1,  0, -1);
-test(-1,  0, -1,  0, -1, -1);
-test(-1,  0,  0, -1, -1, -1);
-test( 0, -1, -1, -1, -1,  0);
-test( 0, -1, -1, -1,  0, -1);
-test( 0, -1, -1,  0, -1, -1);
-test( 0, -1,  0, -1, -1, -1);
-test( 0,  0, -1, -1, -1, -1);
+test(-1, -1,  0,  0);
+test(-1,  0, -1,  0);
+test(-1,  0,  0, -1);
+test( 0, -1, -1,  0);
+test( 0, -1,  0, -1);
+test( 0,  0, -1, -1);
+test( 0,  0, -1,  0);
 
 // Check combinations mixing 3 elements from different types.
-test(-1, -1, -1,  0,  0,  0);
-test(-1, -1,  0, -1,  0,  0);
-test(-1, -1,  0,  0, -1,  0);
-test(-1, -1,  0,  0,  0, -1);
-test(-1,  0, -1, -1,  0,  0);
-test(-1,  0, -1,  0, -1,  0);
-test(-1,  0, -1,  0,  0, -1);
-test(-1,  0,  0, -1, -1,  0);
-test(-1,  0,  0, -1,  0, -1);
-test(-1,  0,  0,  0, -1, -1);
-test( 0, -1, -1, -1,  0,  0);
-test( 0, -1, -1,  0, -1,  0);
-test( 0, -1, -1,  0,  0, -1);
-test( 0, -1,  0, -1, -1,  0);
-test( 0, -1,  0, -1,  0, -1);
-test( 0, -1,  0,  0, -1, -1);
-test( 0,  0, -1, -1, -1,  0);
-test( 0,  0, -1, -1,  0, -1);
-test( 0,  0, -1,  0, -1, -1);
-test( 0,  0,  0, -1, -1, -1);
+test(-1,  0,  0,  0);
+test( 0, -1,  0,  0);
+test( 0,  0, -1,  0);
+test( 0,  0,  0, -1);
 
 // Check combinations mixing 4 elements from different types.
-test(-1, -1,  0,  0,  0,  0);
-test(-1,  0, -1,  0,  0,  0);
-test(-1,  0,  0, -1,  0,  0);
-test(-1,  0,  0,  0, -1,  0);
-test(-1,  0,  0,  0,  0, -1);
-test( 0, -1, -1,  0,  0,  0);
-test( 0, -1,  0, -1,  0,  0);
-test( 0, -1,  0,  0, -1,  0);
-test( 0, -1,  0,  0,  0, -1);
-test( 0,  0, -1, -1,  0,  0);
-test( 0,  0, -1,  0, -1,  0);
-test( 0,  0, -1,  0,  0, -1);
-test( 0,  0,  0, -1, -1,  0);
-test( 0,  0,  0, -1,  0, -1);
-test( 0,  0,  0,  0, -1, -1);
-
-// Check combinations mixing 5 elements from different types.
-test(-1,  0,  0,  0,  0,  0);
-test( 0, -1,  0,  0,  0,  0);
-test( 0,  0, -1,  0,  0,  0);
-test( 0,  0,  0, -1,  0,  0);
-test( 0,  0,  0,  0, -1,  0);
-test( 0,  0,  0,  0,  0, -1);
-
-// Check combinations mixing 6 elements from different types.
-test( 0,  0,  0,  0,  0,  0);
+test( 0,  0,  0,  0);
--- a/js/src/vm/SelfHosting.cpp
+++ b/js/src/vm/SelfHosting.cpp
@@ -225,16 +225,58 @@ intrinsic_GuardToBuiltin(JSContext* cx, 
     if (args[0].toObject().is<T>()) {
         args.rval().setObject(args[0].toObject());
         return true;
     }
     args.rval().setNull();
     return true;
 }
 
+template<typename T>
+static bool
+intrinsic_IsWrappedInstanceOfBuiltin(JSContext* cx, unsigned argc, Value* vp)
+{
+    CallArgs args = CallArgsFromVp(argc, vp);
+    MOZ_ASSERT(args.length() == 1);
+    MOZ_ASSERT(args[0].isObject());
+
+    JSObject* obj = &args[0].toObject();
+    if (!obj->is<WrapperObject>()) {
+        args.rval().setBoolean(false);
+        return true;
+    }
+
+    JSObject* unwrapped = CheckedUnwrap(obj);
+    if (!unwrapped) {
+        ReportAccessDenied(cx);
+        return false;
+    }
+
+    args.rval().setBoolean(unwrapped->is<T>());
+    return true;
+}
+
+template<typename T>
+static bool
+intrinsic_IsPossiblyWrappedInstanceOfBuiltin(JSContext* cx, unsigned argc, Value* vp)
+{
+    CallArgs args = CallArgsFromVp(argc, vp);
+    MOZ_ASSERT(args.length() == 1);
+    MOZ_ASSERT(args[0].isObject());
+
+    JSObject* obj = CheckedUnwrap(&args[0].toObject());
+    if (!obj) {
+        ReportAccessDenied(cx);
+        return false;
+    }
+
+    args.rval().setBoolean(obj->is<T>());
+    return true;
+}
+
 /**
  * Self-hosting intrinsic returning the original constructor for a builtin
  * the name of which is the first and only argument.
  *
  * The return value is guaranteed to be the original constructor even if
  * content code changed the named binding on the global object.
  *
  * This intrinsic shouldn't be called directly. Instead, the
@@ -929,44 +971,16 @@ intrinsic_GeneratorSetClosed(JSContext* 
 
     GeneratorObject* genObj = &args[0].toObject().as<GeneratorObject>();
     genObj->setClosed();
     return true;
 }
 
 template<typename T>
 static bool
-intrinsic_IsWrappedArrayBuffer(JSContext* cx, unsigned argc, Value* vp)
-{
-    CallArgs args = CallArgsFromVp(argc, vp);
-    MOZ_ASSERT(args.length() == 1);
-
-    if (!args[0].isObject()) {
-        args.rval().setBoolean(false);
-        return true;
-    }
-
-    JSObject* obj = &args[0].toObject();
-    if (!obj->is<WrapperObject>()) {
-        args.rval().setBoolean(false);
-        return true;
-    }
-
-    JSObject* unwrapped = CheckedUnwrap(obj);
-    if (!unwrapped) {
-        ReportAccessDenied(cx);
-        return false;
-    }
-
-    args.rval().setBoolean(unwrapped->is<T>());
-    return true;
-}
-
-template<typename T>
-static bool
 intrinsic_ArrayBufferByteLength(JSContext* cx, unsigned argc, Value* vp)
 {
     CallArgs args = CallArgsFromVp(argc, vp);
     MOZ_ASSERT(args.length() == 1);
     MOZ_ASSERT(args[0].isObject());
     MOZ_ASSERT(args[0].toObject().is<T>());
 
     size_t byteLength = args[0].toObject().as<T>().byteLength();
@@ -1076,37 +1090,16 @@ intrinsic_GetTypedArrayKind(JSContext* c
     JSObject* obj = &args[0].toObject();
     Scalar::Type type = JS_GetArrayBufferViewType(obj);
 
     args.rval().setInt32(static_cast<int32_t>(type));
     return true;
 }
 
 static bool
-intrinsic_IsPossiblyWrappedTypedArray(JSContext* cx, unsigned argc, Value* vp)
-{
-    CallArgs args = CallArgsFromVp(argc, vp);
-    MOZ_ASSERT(args.length() == 1);
-
-    bool isTypedArray = false;
-    if (args[0].isObject()) {
-        JSObject* obj = CheckedUnwrap(&args[0].toObject());
-        if (!obj) {
-            ReportAccessDenied(cx);
-            return false;
-        }
-
-        isTypedArray = obj->is<TypedArrayObject>();
-    }
-
-    args.rval().setBoolean(isTypedArray);
-    return true;
-}
-
-static bool
 intrinsic_TypedArrayBuffer(JSContext* cx, unsigned argc, Value* vp)
 {
     CallArgs args = CallArgsFromVp(argc, vp);
     MOZ_ASSERT(args.length() == 1);
     MOZ_ASSERT(TypedArrayObject::is(args[0]));
 
     Rooted<TypedArrayObject*> tarray(cx, &args[0].toObject().as<TypedArrayObject>());
     if (!TypedArrayObject::ensureHasBuffer(cx, tarray)) {
@@ -2550,19 +2543,19 @@ static const JSFunctionSpec intrinsic_fu
 
     JS_INLINABLE_FN("GuardToArrayBuffer",
           intrinsic_GuardToBuiltin<ArrayBufferObject>,             1,0,
           IntrinsicGuardToArrayBuffer),
     JS_INLINABLE_FN("GuardToSharedArrayBuffer",
           intrinsic_GuardToBuiltin<SharedArrayBufferObject>,       1,0,
           IntrinsicGuardToSharedArrayBuffer),
     JS_FN("IsWrappedArrayBuffer",
-          intrinsic_IsWrappedArrayBuffer<ArrayBufferObject>,            1,0),
+          intrinsic_IsWrappedInstanceOfBuiltin<ArrayBufferObject>,      1,0),
     JS_FN("IsWrappedSharedArrayBuffer",
-          intrinsic_IsWrappedArrayBuffer<SharedArrayBufferObject>,      1,0),
+          intrinsic_IsWrappedInstanceOfBuiltin<SharedArrayBufferObject>, 1,0),
 
     JS_INLINABLE_FN("ArrayBufferByteLength",
                     intrinsic_ArrayBufferByteLength<ArrayBufferObject>, 1,0,
                     IntrinsicArrayBufferByteLength),
     JS_INLINABLE_FN("PossiblyWrappedArrayBufferByteLength",
                     intrinsic_PossiblyWrappedArrayBufferByteLength<ArrayBufferObject>, 1,0,
                     IntrinsicPossiblyWrappedArrayBufferByteLength),
     JS_FN("ArrayBufferCopyData",
@@ -2576,17 +2569,18 @@ static const JSFunctionSpec intrinsic_fu
           intrinsic_ArrayBufferCopyData<SharedArrayBufferObject>,       6,0),
     JS_FN("SharedArrayBuffersMemorySame",
           intrinsic_SharedArrayBuffersMemorySame,                       2,0),
 
     JS_FN("GetTypedArrayKind", intrinsic_GetTypedArrayKind,             1,0),
     JS_INLINABLE_FN("IsTypedArray",
                     intrinsic_IsInstanceOfBuiltin<TypedArrayObject>,    1,0,
                     IntrinsicIsTypedArray),
-    JS_INLINABLE_FN("IsPossiblyWrappedTypedArray",intrinsic_IsPossiblyWrappedTypedArray,1,0,
+    JS_INLINABLE_FN("IsPossiblyWrappedTypedArray",
+                    intrinsic_IsPossiblyWrappedInstanceOfBuiltin<TypedArrayObject>, 1,0,
                     IntrinsicIsPossiblyWrappedTypedArray),
 
     JS_FN("TypedArrayBuffer",        intrinsic_TypedArrayBuffer,        1,0),
     JS_FN("TypedArrayByteOffset",    intrinsic_TypedArrayByteOffset,    1,0),
     JS_FN("TypedArrayElementShift",  intrinsic_TypedArrayElementShift,  1,0),
 
     JS_INLINABLE_FN("TypedArrayLength", intrinsic_TypedArrayLength,     1,0,
                     IntrinsicTypedArrayLength),