Index: chrome/test/data/wasm/wasm_tests.js |
diff --git a/chrome/test/data/wasm/wasm_tests.js b/chrome/test/data/wasm/wasm_tests.js |
new file mode 100644 |
index 0000000000000000000000000000000000000000..e3b191ada9edbe745828fe1aad6f177ce109ed51 |
--- /dev/null |
+++ b/chrome/test/data/wasm/wasm_tests.js |
@@ -0,0 +1,39 @@ |
+// Copyright 2016 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+// Utility function. Use this to return data back to the C++ test. |
+function respondToTestHarness(data) { |
+ if (!window.domAutomationController) { |
+ console.log("ERROR: no automation controller available"); |
+ return; |
+ } |
+ window.domAutomationController.send(data); |
+} |
+ |
+var xhrReadyState_DONE = 4; |
jsbell
2016/08/18 16:48:02
You can rely on XMLHttpRequest.DONE being defined
Mircea Trofin
2016/08/18 17:34:08
Oh! Nice!
why the "but"? Would we run these tests
jsbell
2016/08/18 18:13:14
Just that if you replace XHR with fetch() you don'
Mircea Trofin
2016/08/18 23:02:59
Done.
|
+ |
+// Compile a module here, but instantiate it in a worker. |
+// Tests serialization/deserialization. |
+// The file incrementer.wasm is fetched from //v8/test/mjsunit/wasm. The |
+// C test needs to setup the server to include that path. |
+function test_instantiateInWorker() { |
+ var req = new XMLHttpRequest(); |
jsbell
2016/08/18 16:48:02
... can you use fetch() here instead of XHR since
Mircea Trofin
2016/08/18 17:34:08
Acknowledged.
Mircea Trofin
2016/08/18 23:02:59
Done.
|
+ req.addEventListener('load', function(e) { |
+ if (req.readyState === xhrReadyState_DONE) { |
+ var data = req.response; |
+ var mod = new WebAssembly.Module(data); |
+ var worker = new Worker("wasm_serialization_worker.js"); |
+ worker.postMessage(mod); |
+ worker.onmessage = function(event) { |
+ respondToTestHarness(event.data); |
+ } |
+ } |
+ }); |
+ req.addEventListener('error', function(e) { |
+ respondToTestHarness('error: ' + e); |
+ }); |
+ req.open('GET', 'incrementer.wasm', true); |
+ req.responseType = 'arraybuffer'; |
+ req.send(); |
+} |