Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(24)

Unified Diff: test/mjsunit/d8-worker.js

Issue 1218553004: Change d8 Worker API so it takes a string instead of a function. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: use template strings Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/d8.cc ('k') | test/mjsunit/d8-worker-sharedarraybuffer.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/mjsunit/d8-worker.js
diff --git a/test/mjsunit/d8-worker.js b/test/mjsunit/d8-worker.js
index ef02ca5b405815ca5252886b4cfe46d4ead4dfbc..f172fb160338338476473503e54514cb1a994bde 100644
--- a/test/mjsunit/d8-worker.js
+++ b/test/mjsunit/d8-worker.js
@@ -29,65 +29,64 @@
// spawns a new OS thread and isolate, and runs it concurrently with the
// current running thread.
-function f() {
- postMessage("Starting worker");
- // Set a global variable; should not be visible outside of the worker's
- // context.
- foo = 100;
-
- var c = 0;
- onmessage = function(m) {
- switch (c++) {
- case 0:
- if (m !== undefined) throw new Error("undefined");
- break;
- case 1:
- if (m !== null) throw new Error("null");
- break;
- case 2:
- if (m !== true) throw new Error("true");
- break;
- case 3:
- if (m !== false) throw new Error("false");
- break;
- case 4:
- if (m !== 100) throw new Error("Number");
- break;
- case 5:
- if (m !== "hi") throw new Error("String");
- break;
- case 6:
- if (JSON.stringify(m) !== '[4,true,"bye"]') throw new Error("Array");
- break;
- case 7:
- if (JSON.stringify(m) !== '{"a":1,"b":2.5,"c":"three"}')
- throw new Error("Object");
- break;
- case 8:
- var ab = m;
- var t = new Uint32Array(ab);
- if (ab.byteLength !== 16)
- throw new Error("ArrayBuffer clone byteLength");
- for (var i = 0; i < 4; ++i)
- if (t[i] !== i)
- throw new Error("ArrayBuffer clone value " + i);
- break;
- case 9:
- var ab = m;
- var t = new Uint32Array(ab);
- if (ab.byteLength !== 32)
- throw new Error("ArrayBuffer transfer byteLength");
- for (var i = 0; i < 8; ++i)
- if (t[i] !== i)
- throw new Error("ArrayBuffer transfer value " + i);
- break;
- }
-
- if (c == 10) {
- postMessage("DONE");
- }
- }
-}
+var workerScript =
+ `postMessage('Starting worker');
+// Set a global variable; should not be visible outside of the worker's
+// context.
+ foo = 100;
+ var c = 0;
+ onmessage = function(m) {
+ switch (c++) {
+ case 0:
+ if (m !== undefined) throw new Error('undefined');
+ break;
+ case 1:
+ if (m !== null) throw new Error('null');
+ break;
+ case 2:
+ if (m !== true) throw new Error('true');
+ break;
+ case 3:
+ if (m !== false) throw new Error('false');
+ break;
+ case 4:
+ if (m !== 100) throw new Error('Number');
+ break;
+ case 5:
+ if (m !== 'hi') throw new Error('String');
+ break;
+ case 6:
+ if (JSON.stringify(m) !== '[4,true,\"bye\"]') {
+ throw new Error('Array');
+ }
+ break;
+ case 7:
+ if (JSON.stringify(m) !== \"{'a':1,'b':2.5,'c':'three'}\")
+ throw new Error('Object');
+ break;
+ case 8:
+ var ab = m;
+ var t = new Uint32Array(ab);
+ if (ab.byteLength !== 16)
+ throw new Error('ArrayBuffer clone byteLength');
+ for (var i = 0; i < 4; ++i)
+ if (t[i] !== i)
+ throw new Error('ArrayBuffer clone value ' + i);
+ break;
+ case 9:
+ var ab = m;
+ var t = new Uint32Array(ab);
+ if (ab.byteLength !== 32)
+ throw new Error('ArrayBuffer transfer byteLength');
+ for (var i = 0; i < 8; ++i)
+ if (t[i] !== i)
+ throw new Error('ArrayBuffer transfer value ' + i);
+ break;
+ }
+ if (c == 10) {
+ postMessage('DONE');
+ }
+ };`;
if (this.Worker) {
@@ -99,7 +98,7 @@ if (this.Worker) {
return ab;
}
- var w = new Worker(f);
+ var w = new Worker(workerScript);
assertEquals("Starting worker", w.getMessage());
@@ -132,8 +131,7 @@ if (this.Worker) {
// Make sure that the main thread doesn't block forever in getMessage() if
// the worker dies without posting a message.
- function f2() {}
- var w2 = new Worker(f2);
+ var w2 = new Worker('');
var msg = w2.getMessage();
assertEquals(undefined, msg);
}
« no previous file with comments | « src/d8.cc ('k') | test/mjsunit/d8-worker-sharedarraybuffer.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698