2018-06-28 00:39:19 +00:00
|
|
|
// Copyright 2018 the V8 project authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
|
|
// found in the LICENSE file.
|
|
|
|
|
|
|
|
load("test/mjsunit/wasm/wasm-module-builder.js");
|
|
|
|
|
2018-07-16 09:53:05 +00:00
|
|
|
(function TestPostModule() {
|
2018-06-28 00:39:19 +00:00
|
|
|
let builder = new WasmModuleBuilder();
|
|
|
|
builder.addFunction("add", kSig_i_ii)
|
2019-10-08 12:38:48 +00:00
|
|
|
.addBody([kExprLocalGet, 0, kExprLocalGet, 1, kExprI32Add])
|
2018-06-28 00:39:19 +00:00
|
|
|
.exportFunc();
|
|
|
|
|
|
|
|
let module = builder.toModule();
|
|
|
|
|
2021-01-25 12:19:05 +00:00
|
|
|
function workerCode() {
|
2018-06-28 00:39:19 +00:00
|
|
|
onmessage = function(module) {
|
|
|
|
try {
|
|
|
|
let instance = new WebAssembly.Instance(module);
|
|
|
|
let result = instance.exports.add(40, 2);
|
|
|
|
postMessage(result);
|
|
|
|
} catch(e) {
|
|
|
|
postMessage('ERROR: ' + e);
|
|
|
|
}
|
|
|
|
}
|
2021-01-25 12:19:05 +00:00
|
|
|
}
|
2018-06-28 00:39:19 +00:00
|
|
|
|
2021-01-25 12:19:05 +00:00
|
|
|
let worker = new Worker(workerCode, {type: 'function'});
|
2018-06-28 00:39:19 +00:00
|
|
|
worker.postMessage(module);
|
|
|
|
assertEquals(42, worker.getMessage());
|
|
|
|
worker.terminate();
|
2018-07-16 09:53:05 +00:00
|
|
|
})();
|