Bug 1146295: Make some arguments facultative in splat/with functions; r=h4writer
authorBenjamin Bouvier <benj@benj.me>
Tue, 24 Mar 2015 16:32:49 +0100
changeset 266577 98cf094bbc05aabe17ce31160da27bc119a630d7
parent 266576 57bd743ef57b9351edda09b932d548aa8390f062
child 266578 aab8f3243cd00af301cd7f6885a892483ad9e0f0
push id830
push userraliiev@mozilla.com
push dateFri, 19 Jun 2015 19:24:37 +0000
treeherdermozilla-release@932614382a68 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersh4writer
bugs1146295
milestone39.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 1146295: Make some arguments facultative in splat/with functions; r=h4writer
js/src/builtin/SIMD.cpp
js/src/tests/ecma_7/SIMD/splat.js
js/src/tests/ecma_7/SIMD/with.js
--- a/js/src/builtin/SIMD.cpp
+++ b/js/src/builtin/SIMD.cpp
@@ -687,24 +687,25 @@ BinaryFunc(JSContext *cx, unsigned argc,
 
 template<typename V, template<typename T> class OpWith>
 static bool
 FuncWith(JSContext *cx, unsigned argc, Value *vp)
 {
     typedef typename V::Elem Elem;
 
     CallArgs args = CallArgsFromVp(argc, vp);
-    if (args.length() != 2 || !IsVectorObject<V>(args[0]))
+    // Only the first argument is mandatory
+    if (args.length() < 1 || !IsVectorObject<V>(args[0]))
         return ErrorBadArgs(cx);
 
     Elem *vec = TypedObjectMemory<Elem *>(args[0]);
     Elem result[V::lanes];
 
     Elem value;
-    if (!V::toType(cx, args[1], &value))
+    if (!V::toType(cx, args.get(1), &value))
         return false;
 
     for (unsigned i = 0; i < V::lanes; i++)
         result[i] = OpWith<Elem>::apply(i, value, vec[i]);
     return StoreResult<V>(cx, args, result);
 }
 
 template<typename V>
@@ -851,21 +852,18 @@ FuncConvertBits(JSContext *cx, unsigned 
 
 template<typename Vret>
 static bool
 FuncSplat(JSContext *cx, unsigned argc, Value *vp)
 {
     typedef typename Vret::Elem RetElem;
 
     CallArgs args = CallArgsFromVp(argc, vp);
-    if (args.length() != 1)
-        return ErrorBadArgs(cx);
-
     RetElem arg;
-    if (!Vret::toType(cx, args[0], &arg))
+    if (!Vret::toType(cx, args.get(0), &arg))
         return false;
 
     RetElem result[Vret::lanes];
     for (unsigned i = 0; i < Vret::lanes; i++)
         result[i] = arg;
     return StoreResult<Vret>(cx, args, result);
 }
 
--- a/js/src/tests/ecma_7/SIMD/splat.js
+++ b/js/src/tests/ecma_7/SIMD/splat.js
@@ -18,21 +18,24 @@ function TestSplatX2(type, inputs, coerc
 
 function test() {
     function TestError(){};
 
     var good = {valueOf: () => 19.89};
     var bad = {valueOf: () => { throw new TestError(); }};
 
     TestSplatX4('int32x4', [0, undefined, 3.5, 42, -1337, INT32_MAX, INT32_MAX + 1, good], (x) => x | 0);
+    assertEqX4(SIMD.int32x4.splat(), [0, 0, 0, 0]);
     assertThrowsInstanceOf(() => SIMD.int32x4.splat(bad), TestError);
 
     TestSplatX4('float32x4', [0, undefined, 3.5, 42, -13.37, Infinity, NaN, -0, good], (x) => Math.fround(x));
+    assertEqX4(SIMD.float32x4.splat(), [NaN, NaN, NaN, NaN]);
     assertThrowsInstanceOf(() => SIMD.float32x4.splat(bad), TestError);
 
     TestSplatX2('float64x2', [0, undefined, 3.5, 42, -13.37, Infinity, NaN, -0, good], (x) => +x);
+    assertEqX4(SIMD.float64x2.splat(), [NaN, NaN]);
     assertThrowsInstanceOf(() => SIMD.float64x2.splat(bad), TestError);
 
     if (typeof reportCompare === "function")
         reportCompare(true, true);
 }
 
 test();
--- a/js/src/tests/ecma_7/SIMD/with.js
+++ b/js/src/tests/ecma_7/SIMD/with.js
@@ -53,37 +53,40 @@ function test() {
   var float32x4inputs = [
       [float32x4(1, 2, 3, 4), 5],
       [float32x4(1.87, 2.08, 3.84, 4.17), Math.fround(13.37)],
       [float32x4(NaN, -0, Infinity, -Infinity), 0]
   ];
   testType('float32x4', float32x4inputs);
 
   var v = float32x4inputs[1][0];
+  assertEqX4(float32x4.withX(v), withX(simdToArray(v), NaN));
   assertEqX4(float32x4.withX(v, good), withX(simdToArray(v), good | 0));
   assertThrowsInstanceOf(() => float32x4.withX(v, bad), TestError);
 
   var float64x2inputs = [
       [float64x2(1, 2), 5],
       [float64x2(1.87, 2.08), Math.fround(13.37)],
       [float64x2(NaN, -0), 0]
   ];
   testType('float64x2', float64x2inputs);
 
   var v = float64x2inputs[1][0];
+  assertEqX4(float64x2.withX(v), withX(simdToArray(v), NaN));
   assertEqX4(float64x2.withX(v, good), withX(simdToArray(v), good | 0));
   assertThrowsInstanceOf(() => float64x2.withX(v, bad), TestError);
 
   var int32x4inputs = [
       [int32x4(1, 2, 3, 4), 5],
       [int32x4(INT32_MIN, INT32_MAX, 3, 4), INT32_MIN],
   ];
   testType('int32x4', int32x4inputs);
 
   var v = int32x4inputs[1][0];
+  assertEqX4(int32x4.withX(v), withX(simdToArray(v), 0));
   assertEqX4(int32x4.withX(v, good), withX(simdToArray(v), good | 0));
   assertThrowsInstanceOf(() => int32x4.withX(v, bad), TestError);
 
   if (typeof reportCompare === "function")
     reportCompare(true, true);
 }
 
 test();