node/deps/v8/test/mjsunit/wasm/log-code-after-post-message.js
Michaël Zasso 9d7cd9b864
deps: update V8 to 12.8.374.13
PR-URL: https://github.com/nodejs/node/pull/54077
Reviewed-By: Jiawen Geng <technicalcute@gmail.com>
Reviewed-By: Richard Lau <rlau@redhat.com>
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
Reviewed-By: Marco Ippolito <marcoippolito54@gmail.com>
2024-08-16 16:03:01 +02:00

45 lines
1.5 KiB
JavaScript

// Copyright 2022 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.
d8.file.execute("test/mjsunit/wasm/wasm-module-builder.js");
function workerCode() {
function WorkerOnProfileEnd(profile) {
postMessage(profile.indexOf('foo'));
}
onmessage = ({data:wasm_module}) => {
WebAssembly.instantiate(wasm_module, {q: {func: d8.profiler.triggerSample}})
.then(instance => {
instance.exports.foo();
console.profileEnd();
});
};
d8.profiler.setOnProfileEndListener(WorkerOnProfileEnd);
// Code logging happens for all code objects when profiling gets started,
// and when new code objects appear after profiling has started. We want to
// test the second scenario here. As new code objects appear as the
// parameter of {OnMessage}, we have to start profiling already here before
// {onMessage} is called.
console.profile();
postMessage('Starting worker');
}
const worker = new Worker(workerCode, {type: 'function'});
assertEquals("Starting worker", worker.getMessage());
const builder = new WasmModuleBuilder();
const sig_index = builder.addType(kSig_v_v);
const imp_index = builder.addImport("q", "func", sig_index);
builder.addFunction('foo', kSig_v_v)
.addBody([
kExprCallFunction, imp_index,
])
.exportFunc();
const wasm_module = builder.toModule();
worker.postMessage(wasm_module);
assertTrue(worker.getMessage() > 0);