Bug 1246750 - fix argument ordering to futexWakeOrRequeue + test cases. r=bbouvier, a=lizzard
authorLars T Hansen <lhansen@mozilla.com>
Mon, 08 Feb 2016 21:39:47 +0100
changeset 303955 931ae236e361c52ace6f1270596e5d27dc592553
parent 303954 6ed468649dea177e404c9ea4f9c9afe847bb34ba
child 303956 eb1aa0960ac20757cc1cf9dff2cf0765955a3067
push id9068
push usercbook@mozilla.com
push dateMon, 15 Feb 2016 14:13:10 +0000
treeherdermozilla-aurora@2a42ee967471 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbbouvier, lizzard
bugs1246750
milestone46.0a2
Bug 1246750 - fix argument ordering to futexWakeOrRequeue + test cases. r=bbouvier, a=lizzard
js/src/builtin/AtomicsObject.cpp
js/src/tests/shell/futex-apis.js
--- a/js/src/builtin/AtomicsObject.cpp
+++ b/js/src/builtin/AtomicsObject.cpp
@@ -872,18 +872,18 @@ js::atomics_futexWake(JSContext* cx, uns
 
 bool
 js::atomics_futexWakeOrRequeue(JSContext* cx, unsigned argc, Value* vp)
 {
     CallArgs args = CallArgsFromVp(argc, vp);
     HandleValue objv = args.get(0);
     HandleValue idx1v = args.get(1);
     HandleValue countv = args.get(2);
-    HandleValue valv = args.get(3);
-    HandleValue idx2v = args.get(4);
+    HandleValue idx2v = args.get(3);
+    HandleValue valv = args.get(4);
     MutableHandleValue r = args.rval();
 
     Rooted<TypedArrayObject*> view(cx, nullptr);
     if (!GetSharedTypedArray(cx, objv, &view))
         return false;
     if (view->type() != Scalar::Int32)
         return ReportBadArrayType(cx);
     uint32_t offset1;
new file mode 100644
--- /dev/null
+++ b/js/src/tests/shell/futex-apis.js
@@ -0,0 +1,118 @@
+// |reftest| skip-if(!xulRuntime.shell)
+/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * Any copyright is dedicated to the Public Domain.
+ * http://creativecommons.org/licenses/publicdomain/
+ */
+
+if (!(this.SharedArrayBuffer && this.Atomics)) {
+    reportCompare(true,true);
+    quit(0);
+}
+
+// Checks for parameter validation of futex API.  ALl of these test
+// cases should throw exceptions during parameter validation, before
+// we check whether any waiting should be done.
+
+let ab = new ArrayBuffer(16);
+let sab = new SharedArrayBuffer(16);
+
+//////////////////////////////////////////////////////////////////////
+//
+// The view must be an Int32Array on a SharedArrayBuffer.
+
+// Check against non-TypedArray cases.
+
+{
+    let values = [null,
+		  undefined,
+		  true,
+		  false,
+		  new Boolean(true),
+		  10,
+		  3.14,
+		  new Number(4),
+		  "Hi there",
+		  new Date,
+		  /a*utomaton/g,
+		  { password: "qumquat" },
+		  new DataView(new ArrayBuffer(10)),
+		  new ArrayBuffer(128),
+		  new SharedArrayBuffer(128),
+		  new Error("Ouch"),
+		  [1,1,2,3,5,8],
+		  ((x) => -x),
+		  new Map(),
+		  new Set(),
+		  new WeakMap(),
+		  new WeakSet(),
+		  this.Promise ? new Promise(() => "done") : null,
+		  Symbol("halleluja"),
+		  // TODO: Proxy?
+		  Object,
+		  Int32Array,
+		  Date,
+		  Math,
+		  Atomics ];
+
+    for ( let i=0 ; i < values.length ; i++ ) {
+	let view = values[i];
+	assertThrowsInstanceOf(() => Atomics.futexWait(view, 0, 0), TypeError);
+	assertThrowsInstanceOf(() => Atomics.futexWake(view, 0), TypeError);
+	assertThrowsInstanceOf(() => Atomics.futexWakeOrRequeue(view, 0, 0, 1, 0), TypeError);
+    }
+}
+
+// Check against TypedArray on non-shared memory cases.
+
+{
+    let views = [Int8Array, Uint8Array, Int16Array, Uint16Array, Int32Array, Uint32Array];
+
+    for ( let View of views ) {
+	let view = new View(ab);
+
+	assertThrowsInstanceOf(() => Atomics.futexWait(view, 0, 0), TypeError);
+	assertThrowsInstanceOf(() => Atomics.futexWake(view, 0), TypeError);
+	assertThrowsInstanceOf(() => Atomics.futexWakeOrRequeue(view, 0, 0, 1, 0), TypeError);
+    }
+}
+
+// Check against TypedArray on shared memory, but wrong view type
+
+{
+    let views = [Int8Array, Uint8Array, Int16Array, Uint16Array, Uint32Array,
+		 Uint8ClampedArray, Float32Array, Float64Array];
+
+    for ( let View of views ) {
+	let view = new View(sab);
+
+	assertThrowsInstanceOf(() => Atomics.futexWait(view, 0, 0), TypeError);
+	assertThrowsInstanceOf(() => Atomics.futexWake(view, 0), TypeError);
+	assertThrowsInstanceOf(() => Atomics.futexWakeOrRequeue(view, 0, 0, 1, 0), TypeError);
+    }
+}
+
+//////////////////////////////////////////////////////////////////////
+//
+// The indices must be in the range of the array
+
+{
+    let view = new Int32Array(sab);
+
+    let indices = [ (view) => -1,
+		    (view) => view.length,
+		    (view) => view.length*2,
+		    (view) => undefined,
+		    (view) => '3.5',
+		    (view) => { password: "qumquat" } ];
+
+    for ( let iidx=0 ; iidx < indices.length ; iidx++ ) {
+	let Idx = indices[iidx](view);
+	assertThrowsInstanceOf(() => Atomics.futexWait(view, Idx, 10), RangeError);
+	assertThrowsInstanceOf(() => Atomics.futexWake(view, Idx), RangeError);
+	assertThrowsInstanceOf(() => Atomics.futexWakeOrRequeue(view, Idx, 5, 0, 0), RangeError);
+	assertThrowsInstanceOf(() => Atomics.futexWakeOrRequeue(view, 0, 5, Idx, 0), RangeError);
+    }
+}
+
+reportCompare(true,true);