MCPcopy Create free account
hub / github.com/nodejs/node / workerScript

Function workerScript

deps/v8/test/test262/harness-agent.js:21–72  ·  view source on GitHub ↗
(script)

Source from the content-addressed store, hash-verified

19var WORKER_REPORT_LOC = 3;
20
21function workerScript(script) {
22 return `
23 var index;
24 var i32a = null;
25 var broadcasts = [];
26 var pendingReceiver = null;
27
28 function handleBroadcast() {
29 if (pendingReceiver && broadcasts.length > 0) {
30 pendingReceiver.apply(null, broadcasts.shift());
31 pendingReceiver = null;
32 }
33 };
34
35 var onmessage = function({data:msg}) {
36 switch (msg.kind) {
37 case 'start':
38 i32a = msg.i32a;
39 index = msg.index;
40 (0, eval)(\`${script}\`);
41 break;
42
43 case 'broadcast':
44 Atomics.add(i32a, ${BROADCAST_LOC}, 1);
45 broadcasts.push([msg.sab, msg.id]);
46 handleBroadcast();
47 break;
48 }
49 };
50
51 var $262 = {
52 agent: {
53 receiveBroadcast(receiver) {
54 pendingReceiver = receiver;
55 handleBroadcast();
56 },
57
58 report(msg) {
59 postMessage(String(msg));
60 Atomics.add(i32a, ${WORKER_REPORT_LOC} + index, 1);
61 },
62
63 sleep(s) { Atomics.wait(i32a, ${SLEEP_LOC}, 0, s); },
64
65 leaving() {},
66
67 monotonicNow() {
68 return performance.now();
69 }
70 }
71 };`;
72}
73
74var agent = {
75 start(script) {

Callers 1

startFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected