diff options
Diffstat (limited to 'deps/v8/test/mjsunit/d8')
-rw-r--r-- | deps/v8/test/mjsunit/d8/d8-worker-script.js | 39 | ||||
-rw-r--r-- | deps/v8/test/mjsunit/d8/d8-worker-script.txt | 8 | ||||
-rw-r--r-- | deps/v8/test/mjsunit/d8/d8-worker-sharedarraybuffer.js | 4 | ||||
-rw-r--r-- | deps/v8/test/mjsunit/d8/d8-worker-spawn-worker.js | 4 | ||||
-rw-r--r-- | deps/v8/test/mjsunit/d8/d8-worker.js | 24 |
5 files changed, 73 insertions, 6 deletions
diff --git a/deps/v8/test/mjsunit/d8/d8-worker-script.js b/deps/v8/test/mjsunit/d8/d8-worker-script.js new file mode 100644 index 0000000000..7c5d595b2b --- /dev/null +++ b/deps/v8/test/mjsunit/d8/d8-worker-script.js @@ -0,0 +1,39 @@ +// Copyright 2015 the V8 project authors. All rights reserved. +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following +// disclaimer in the documentation and/or other materials provided +// with the distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived +// from this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +// Verify that the Worker constrcutor by default treats its first argument +// as the filename of a script load and run. + +// Resources: test/mjsunit/d8/d8-worker-script.txt + +if (this.Worker) { + var w = new Worker('test/mjsunit/d8/d8-worker-script.txt'); + assertEquals("Starting worker", w.getMessage()); + w.postMessage(""); + assertEquals("DONE", w.getMessage()); + w.terminate(); +} diff --git a/deps/v8/test/mjsunit/d8/d8-worker-script.txt b/deps/v8/test/mjsunit/d8/d8-worker-script.txt new file mode 100644 index 0000000000..9254cea4f4 --- /dev/null +++ b/deps/v8/test/mjsunit/d8/d8-worker-script.txt @@ -0,0 +1,8 @@ +// Worker script used by d8-worker-script.js. +// This file is named `.txt` to prevent it being treated as a test itself. + +onmessage = function(m) { + postMessage('DONE'); +} + +postMessage('Starting worker'); diff --git a/deps/v8/test/mjsunit/d8/d8-worker-sharedarraybuffer.js b/deps/v8/test/mjsunit/d8/d8-worker-sharedarraybuffer.js index 0a15413ea3..f166ca2eb1 100644 --- a/deps/v8/test/mjsunit/d8/d8-worker-sharedarraybuffer.js +++ b/deps/v8/test/mjsunit/d8/d8-worker-sharedarraybuffer.js @@ -45,7 +45,7 @@ if (this.Worker) { Atomics.store(ta, 0, 100); };`; - var w = new Worker(workerScript); + var w = new Worker(workerScript, {type: 'string'}); var sab = new SharedArrayBuffer(16); var ta = new Uint32Array(sab); @@ -84,7 +84,7 @@ if (this.Worker) { var id; var workers = []; for (id = 0; id < 4; ++id) { - workers[id] = new Worker(workerScript); + workers[id] = new Worker(workerScript, {type: 'string'}); workers[id].postMessage({sab: sab, id: id}); } diff --git a/deps/v8/test/mjsunit/d8/d8-worker-spawn-worker.js b/deps/v8/test/mjsunit/d8/d8-worker-spawn-worker.js index a114d8587e..621ec253bc 100644 --- a/deps/v8/test/mjsunit/d8/d8-worker-spawn-worker.js +++ b/deps/v8/test/mjsunit/d8/d8-worker-spawn-worker.js @@ -27,14 +27,14 @@ if (this.Worker) { var workerScript = - `var w = new Worker('postMessage(42)'); + `var w = new Worker('postMessage(42)', {type: 'string'}); onmessage = function(parentMsg) { w.postMessage(parentMsg); var childMsg = w.getMessage(); postMessage(childMsg); };`; - var w = new Worker(workerScript); + var w = new Worker(workerScript, {type: 'string'}); w.postMessage(9); assertEquals(42, w.getMessage()); } diff --git a/deps/v8/test/mjsunit/d8/d8-worker.js b/deps/v8/test/mjsunit/d8/d8-worker.js index a73d7b1706..afc03f5c8b 100644 --- a/deps/v8/test/mjsunit/d8/d8-worker.js +++ b/deps/v8/test/mjsunit/d8/d8-worker.js @@ -97,7 +97,21 @@ if (this.Worker) { return ab; } - var w = new Worker(workerScript); + assertThrows(function() { + // Second arg must be 'options' object + new Worker(workerScript, 123); + }); + + assertThrows(function() { + new Worker('test/mjsunit/d8/d8-worker.js', {type: 'invalid'}); + }); + + assertThrows(function() { + // worker type defaults to 'classic' which tries to load from file + new Worker(workerScript); + }); + + var w = new Worker(workerScript, {type: 'string'}); assertEquals("Starting worker", w.getMessage()); @@ -140,6 +154,12 @@ if (this.Worker) { w.postMessage(ab2, [ab2]); assertEquals(0, ab2.byteLength); // ArrayBuffer should be neutered. + // Attempting to transfer the same ArrayBuffer twice should throw. + assertThrows(function() { + var ab3 = createArrayBuffer(4); + w.postMessage(ab3, [ab3, ab3]); + }); + assertEquals("undefined", typeof foo); // Read a message from the worker. @@ -150,7 +170,7 @@ if (this.Worker) { // Make sure that the main thread doesn't block forever in getMessage() if // the worker dies without posting a message. - var w2 = new Worker(''); + var w2 = new Worker('', {type: 'string'}); var msg = w2.getMessage(); assertEquals(undefined, msg); } |