Bug 1246750 - fix argument ordering to futexWakeOrRequeue + test cases. r=bbouvier
authorLars T Hansen <lhansen@mozilla.com>
Mon, 08 Feb 2016 21:39:47 +0100
changeset 283607 4a6b1b2a915774e8e2fd0b73b2a98a389bdc1318
parent 283606 92029305820c163ad08e1cbb5e8783f96d8c49b9
child 283608 2c4cc4d1ac2e60239e8b80a65f5f791c254dd19f
push id29988
push usercbook@mozilla.com
push dateWed, 10 Feb 2016 10:47:59 +0000
treeherdermozilla-central@7042e8a19f94 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbbouvier
bugs1246750
milestone47.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 1246750 - fix argument ordering to futexWakeOrRequeue + test cases. r=bbouvier
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);