Upload Kmake

This commit is contained in:
Gorochu
2026-05-26 23:36:42 -07:00
parent ba051b2f74
commit 555ec72358
41615 changed files with 13344630 additions and 1 deletions

1
deps/v8/test/mjsunit/d8/.gitignore vendored Normal file
View File

@ -0,0 +1 @@
v8_trace.json

View File

@ -0,0 +1,7 @@
// 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.
// Flags: -- 1 2 3
assertEquals(["1", "2", "3"], arguments);

View File

@ -0,0 +1,21 @@
// Copyright 2024 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.
//
// Flags: --expose-gc
// Quitting from within a FR cleanup task should not hang d8.
const reg = new FinalizationRegistry(() => {
console.log("Quitting");
quit(0);
});
reg.register({});
function gcLoop() {
console.log("Running GC loop");
gc();
setTimeout(gcLoop);
}
gcLoop();

View File

@ -0,0 +1,69 @@
// Copyright 2021 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.
// Tests for a more fuzzable way for creating workers based on functions.
(function TestWorker() {
function workerCode1() {
onmessage = function() {
postMessage('hi');
}
}
let w = new Worker(workerCode1, {type: 'function'});
w.postMessage('');
assertEquals('hi', w.getMessage());
})();
(function TestPassingNumberParam() {
function workerCode2(n) {
onmessage = function() {
postMessage('worker ' + (n + 1));
}
}
w = new Worker(workerCode2, {type: 'function', arguments: [2021]});
w.postMessage('');
assertEquals('worker 2022', w.getMessage());
})();
(function TestPassingStringParam() {
function workerCode3(s) {
onmessage = function() {
postMessage('worker ' + s);
}
}
w = new Worker(workerCode3, {type: 'function', arguments: ['hello']});
w.postMessage('');
assertEquals('worker hello', w.getMessage());
})();
(function TestPassingObjectParam() {
function workerCode4(o) {
onmessage = function() {
postMessage('worker ' + (o.x + 1));
}
}
w = new Worker(workerCode4, {type: 'function', arguments: [{x: 1}]});
w.postMessage('');
assertEquals('worker 2', w.getMessage());
})();
(function TestPassingFunctionParam() {
function workerCode5(f) {
eval(f);
onmessage = function() {
postMessage('worker ' + func());
}
}
let config = {'func': function func() { return 'hi';} };
w = new Worker(workerCode5, {type: 'function',
arguments: [config.func.toString()]});
w.postMessage('');
assertEquals('worker hi', w.getMessage());
})();

View File

@ -0,0 +1,8 @@
// 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.
// Flags: test/mjsunit/modules-skip-1.mjs test/mjsunit/modules-skip-1.mjs
// Just test that d8 doesn't crash when running the same module on the
// command line twice.

192
deps/v8/test/mjsunit/d8/d8-os.js vendored Normal file
View File

@ -0,0 +1,192 @@
// Copyright 2009 the V8 project authors. All rights reserved.
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following
// disclaimer in the documentation and/or other materials provided
// with the distribution.
// * Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// Test the OS module of d8. This test only makes sense with d8. It
// only does non-trivial work on Unix since os.system() is not currently
// implemented on Windows, and even if it were then many of the things
// we are calling would not be available.
var TEST_DIR = "/tmp/d8-os-test-directory-" + ((Math.random() * (1<<30)) | 0);
function arg_error(str) {
try {
eval(str);
} catch (e) {
assertTrue(/rgument/.test(e), str);
}
}
const kOsNameValues = ['linux', 'macos', 'windows', 'android', 'unknown'];
assertTrue(kOsNameValues.includes(os.name));
assertTrue(os.d8Path.length > 0);
function str_error(str) {
var e = new Object();
e.toString = function() { throw new Error("foo bar"); }
try {
eval(str);
} catch (exception) {
assertTrue(/tring conversion/.test(exception), str);
}
}
if (this.os && os.system) {
// Ensure that we have a valid working directory.
os.chdir("/tmp");
try {
// Delete the dir if it is lying around from last time.
os.system("ls", [TEST_DIR]);
os.system("rm", ["-r", TEST_DIR]);
} catch (e) {
}
os.mkdirp(TEST_DIR);
try {
// Check the chdir worked.
os.system('ls', [TEST_DIR]);
// Simple create dir.
os.mkdirp(TEST_DIR + "/dir");
// Create dir in dir.
os.mkdirp(TEST_DIR + "/dir/foo");
// Check that they are there.
os.system('ls', [TEST_DIR + '/dir/foo']);
// Check that we can detect when something is not there.
assertThrows("os.system('ls', [TEST_DIR + '/dir/bar']);");
// Check that mkdirp makes intermediate directories.
os.mkdirp(TEST_DIR + "/dir2/foo");
os.system("ls", [TEST_DIR + "/dir2/foo"]);
// Check that mkdirp doesn't mind if the dir is already there.
os.mkdirp(TEST_DIR + "/dir2/foo");
os.mkdirp(TEST_DIR + "/dir2/foo/");
// Check that mkdirp can cope with trailing /
os.mkdirp(TEST_DIR + "/dir3/");
os.system("ls", [TEST_DIR + "/dir3"]);
// Check that we get an error if the name is taken by a file.
os.system("sh", ["-c", "echo foo > " + TEST_DIR + "/file1"]);
os.system("ls", [TEST_DIR + "/file1"]);
assertThrows("os.mkdirp(TEST_DIR + '/file1');");
assertThrows("os.mkdirp(TEST_DIR + '/file1/foo');");
assertThrows("os.mkdirp(TEST_DIR + '/file1/');");
assertThrows("os.mkdirp(TEST_DIR + '/file1/foo/');");
// Create a dir we cannot read.
os.mkdirp(TEST_DIR + "/dir4", 0);
// This test fails if you are root since root can read any dir.
assertThrows("os.chdir(TEST_DIR + '/dir4');");
os.rmdir(TEST_DIR + "/dir4");
assertThrows("os.chdir(TEST_DIR + '/dir4');");
// Set umask. This changes the umask for the whole process and is
// the reason why the test cannot be run multi-threaded.
var old_umask = os.umask(0777);
// Create a dir we cannot read.
os.mkdirp(TEST_DIR + "/dir5");
// This test fails if you are root since root can read any dir.
assertThrows("os.chdir(TEST_DIR + '/dir5');");
os.rmdir(TEST_DIR + "/dir5");
assertThrows("os.chdir(TEST_DIR + '/dir5');");
os.umask(old_umask);
os.mkdirp(TEST_DIR + "/hest/fisk/../fisk/ged");
os.system("ls", [TEST_DIR + "/hest/fisk/ged"]);
os.setenv("FOO", "bar");
var environment = os.system("printenv");
assertTrue(/FOO=bar/.test(environment));
// Check we time out.
var have_sleep = true;
var have_echo = true;
try {
os.system("ls", ["/bin/sleep"]);
} catch (e) {
have_sleep = false;
}
try {
os.system("ls", ["/bin/echo"]);
} catch (e) {
have_echo = false;
}
if (have_sleep) {
assertThrows("os.system('sleep', ['2000'], 20);");
// Check we time out with total time.
assertThrows("os.system('sleep', ['2000'], -1, 20);");
// Check that -1 means no timeout.
os.system('sleep', ['1'], -1, -1);
}
// Check that we don't fill up the process table with zombies.
// Disabled because it's too slow.
if (have_echo) {
//for (var i = 0; i < 65536; i++) {
assertEquals("baz\n", os.system("echo", ["baz"]));
//}
}
// Too few args.
arg_error("os.umask();");
arg_error("os.system();");
arg_error("os.mkdirp();");
arg_error("os.chdir();");
arg_error("os.setenv();");
arg_error("os.rmdir();");
// Too many args.
arg_error("os.setenv('FOO=bar');");
arg_error("os.umask(0, 0);");
arg_error("os.system('ls', [], -1, -1, -1);");
arg_error("os.mkdirp('foo', 0, 0)");
arg_error("os.chdir('foo', 'bar')");
arg_error("os.rmdir('foo', 'bar');");
// Wrong kind of args.
arg_error("os.umask([]);");
arg_error("os.system('ls', 'foo');");
arg_error("os.system('ls', 123);");
arg_error("os.system('ls', [], 'foo');");
arg_error("os.system('ls', [], -1, 'foo');");
arg_error("os.mkdirp('foo', 'bar');");
// Test broken toString().
str_error("os.system(e);");
str_error("os.system('ls', [e]);");
str_error("os.system('ls', ['.', e]);");
str_error("os.system('ls', [e, '.']);");
str_error("os.mkdirp(e);");
str_error("os.setenv(e, 'goo');");
str_error("os.setenv('goo', e);");
str_error("os.chdir(e);");
str_error("os.rmdir(e);");
} finally {
os.system("rm", ["-r", TEST_DIR]);
}
}

View File

@ -0,0 +1,57 @@
// Copyright 2013 the V8 project authors. All rights reserved.
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following
// disclaimer in the documentation and/or other materials provided
// with the distribution.
// * Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// Flags: --allow-natives-syntax
// Test the performance.now() function of d8. This test only makes sense with
// d8.
if (this.performance && performance.now) {
(function run() {
var start_test = performance.now();
// Let the retry run for maximum 100ms to reduce flakiness.
for (var start = performance.now();
start - start_test < 100;
start = performance.now()) {
var end = performance.now();
assertTrue(start >= start_test);
assertTrue(end >= start);
while (end - start == 0) {
var next = performance.now();
assertTrue(next >= end);
end = next;
}
if (end - start <= 1) {
// Found (sub-)millisecond granularity.
return;
} else {
print("Timer difference too big: " + (end - start) + "ms");
}
}
assertTrue(false);
})()
}

View File

@ -0,0 +1,13 @@
// Copyright 2021 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.
(function TestExplicitRealmScope() {
const r1 = Realm.create();
Realm.eval(r1, 'globalThis.foo = 42;');
const foo1 = Realm.eval(r1, 'globalThis.foo;');
assertEquals(42, foo1);
const r2 = Realm.create();
const foo2 = Realm.eval(r2, 'globalThis.foo;');
assertEquals(undefined, foo2);
})();

View File

@ -0,0 +1,15 @@
// Copyright 2025 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.
// Flags: --stress-incremental-marking
function workerLoop() {
import('data:text/javascript,export function f(){}');
this.postMessage(true);
}
const w = new Worker(workerLoop, {
type: "function"
});
w.getMessage();

View File

@ -0,0 +1,23 @@
// Copyright 2024 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.
const worker = new Worker(function() {
onmessage = function(e) {
// No mjsunit.js in the worker scope, so no assertEquals.
// TODO(leszeks): Make importScripts work with paths relative to the
// worker or caller script.
// assertEquals({text: "ping"}, e.data);
print(JSON.stringify(e.data));
postMessage({text: "pong", reply_to: e.data});
close();
}
}, {type: 'function'});
worker.postMessage({text: "ping"});
worker.onmessage = function(e) {
print(JSON.stringify(e.data));
assertEquals({text: "pong", reply_to: {text: "ping"}}, e.data);
};

View File

@ -0,0 +1,39 @@
// Copyright 2015 the V8 project authors. All rights reserved.
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following
// disclaimer in the documentation and/or other materials provided
// with the distribution.
// * Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// Verify that the Worker constrcutor by default treats its first argument
// as the filename of a script load and run.
// Resources: test/mjsunit/d8/d8-worker-script.txt
if (this.Worker) {
var w = new Worker('test/mjsunit/d8/d8-worker-script.txt');
assertEquals("Starting worker", w.getMessage());
w.postMessage("");
assertEquals("DONE", w.getMessage());
w.terminate();
}

View File

@ -0,0 +1,8 @@
// Worker script used by d8-worker-script.js.
// This file is named `.txt` to prevent it being treated as a test itself.
onmessage = function({data:m}) {
postMessage('DONE');
}
postMessage('Starting worker');

View File

@ -0,0 +1,103 @@
// Copyright 2015 the V8 project authors. All rights reserved.
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following
// disclaimer in the documentation and/or other materials provided
// with the distribution.
// * Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
if (this.Worker) {
(function TestClone() {
var workerScript =
`onmessage = function({data:m}) {
var sab = m;
var ta = new Uint32Array(sab);
if (sab.byteLength !== 16) {
throw new Error('SharedArrayBuffer clone byteLength');
}
for (var i = 0; i < 4; ++i) {
if (ta[i] !== i) {
throw new Error('SharedArrayBuffer clone value ' + i);
}
}
// Atomically update ta[0]
Atomics.store(ta, 0, 100);
};`;
var w = new Worker(workerScript, {type: 'string'});
var sab = new SharedArrayBuffer(16);
var ta = new Uint32Array(sab);
for (var i = 0; i < 4; ++i) {
ta[i] = i;
}
// Clone SharedArrayBuffer
w.postMessage(sab);
assertEquals(16, sab.byteLength); // ArrayBuffer should not be detached.
// Spinwait for the worker to update ta[0]
var ta0;
while ((ta0 = Atomics.load(ta, 0)) == 0) {}
assertEquals(100, ta0);
w.terminate();
assertEquals(16, sab.byteLength); // Still not detached.
})();
(function TestCloneMulti() {
var workerScript =
`onmessage = function({data:msg}) {
var sab = msg.sab;
var id = msg.id;
var ta = new Uint32Array(sab);
Atomics.store(ta, id, 1);
postMessage(id);
};`;
var sab = new SharedArrayBuffer(16);
var ta = new Uint32Array(sab);
var id;
var workers = [];
for (id = 0; id < 4; ++id) {
workers[id] = new Worker(workerScript, {type: 'string'});
workers[id].postMessage({sab: sab, id: id});
}
// Spinwait for each worker to update ta[id]
var count = 0;
while (count < 4) {
for (id = 0; id < 4; ++id) {
if (Atomics.compareExchange(ta, id, 1, -1) == 1) {
// Worker is finished.
assertEquals(id, workers[id].getMessage());
workers[id].terminate();
count++;
}
}
}
})();
}

View File

@ -0,0 +1,42 @@
// Copyright 2019 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.
// Flags: --stress-runs=1
const kBatchSize = 10;
const kNumBatches = 10;
function RunWorkerBatch(count) {
let script = `postMessage(42)`;
// Launch workers.
let workers = new Array(count);
for (let i = 0; i < count; i++) {
workers[i] = new Worker(script, {type : 'string'});
}
// Terminate half of the workers early.
for (let i = 0; i < workers.length; i++) {
if ((i & 1) == 1) workers[i].terminate();
}
// Get messages from some workers.
for (let i = 0; i < workers.length; i++) {
let msg = workers[i].getMessage();
assertTrue(msg === undefined || msg === 42);
// terminate all workers.
workers[i].terminate();
}
}
(function RunTest() {
print(`running ${kNumBatches} batches...`);
let time = performance.now();
for (let i = 0; i < kNumBatches; i++) {
let before = performance.now();
RunWorkerBatch(kBatchSize);
let time = performance.now() - before;
print(`batch ${i+1}, Δ = ${(time).toFixed(3)} ms`);
}
})();

View File

@ -0,0 +1,55 @@
// Copyright 2019 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.
// Flags: --expose-gc --stress-runs=1
const kBatchSize = 10;
const kNumBatches = 10;
function RunWorkerBatch(count) {
let script = `onmessage = function({data:msg}) {
if (msg.array) {
msg.array[0] = 99;
postMessage({array : msg.array});
}
}`;
// Launch workers.
let workers = new Array(count);
for (let i = 0; i < count; i++) {
workers[i] = new Worker(script, {type : 'string'});
}
// Send messages.
for (let i = 0; i < workers.length; i++) {
let array = new Int32Array([55, -77]);
workers[i].postMessage({array : array});
// terminate half of the workers early.
if ((i & 1) == 1) workers[i].terminate();
}
// Wait for replies.
for (let i = 0; i < workers.length; i++) {
let msg = workers[i].getMessage();
if (msg !== undefined && msg.array) {
assertInstanceof(msg.array, Int32Array);
assertEquals(99, msg.array[0]);
assertEquals(-77, msg.array[1]);
}
// terminate all workers.
workers[i].terminate();
}
}
(function RunTest() {
print(`running ${kNumBatches} batches...`);
let time = performance.now();
for (let i = 0; i < kNumBatches; i++) {
let before = performance.now();
RunWorkerBatch(kBatchSize);
gc();
let time = performance.now() - before;
print(`batch ${i+1}, Δ = ${(time).toFixed(3)} ms`);
}
})();

View File

@ -0,0 +1,47 @@
// Copyright 2019 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.
// Flags: --expose-gc --stress-runs=1
let script = `onmessage =
function({data:msg}) {
if (msg.depth > 0) {
print("spawn");
let w = new Worker(msg.script, {type : "string"});
w.postMessage({script: msg.script, depth: msg.depth - 1});
let m = w.getMessage();
w.terminate();
postMessage(m);
} else {
postMessage(-99);
}
}`;
function RunWorker(depth) {
let w = new Worker(script, {type : "string"});
let array = new Int32Array([55, -77]);
w.postMessage({script: script, depth: depth});
let msg = w.getMessage();
print(msg);
w.terminate();
}
function RunTest(depth, iterations) {
let time = performance.now();
for (let i = 0; i < iterations; i++) {
let now = performance.now();
print(`iteration ${i}, Δ = ${(now - time).toFixed(3)} ms`);
RunWorker(depth);
gc();
time = now;
}
}
// TODO(9524): increase the workload of this test. Runs out of threads
// on too many platforms.
RunTest(1, 1);
RunTest(2, 2);
RunTest(5, 3);
RunTest(9, 2);

View File

@ -0,0 +1,58 @@
// Copyright 2019 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.
// Flags: --stress-runs=1
const kBatchSize = 10;
const kNumBatches = 10;
function RunWorkerBatch(count) {
let script = `onmessage = function({data:msg}) {
if (msg.array) {
msg.array[0] = 99;
postMessage({array : msg.array});
}
}`;
// Launch workers.
let workers = new Array(count);
for (let i = 0; i < count; i++) {
workers[i] = new Worker(script, {type : 'string'});
}
// Send messages.
for (let i = 0; i < workers.length; i++) {
let array = new Int32Array([55, -77]);
workers[i].postMessage({array : array});
// terminate half of the workers early.
if ((i & 1) == 1) {
workers[i].terminate();
// A second terminate should have no effect.
workers[i].terminate();
}
}
// Wait for replies.
for (let i = 0; i < workers.length; i++) {
let msg = workers[i].getMessage();
if (msg !== undefined && msg.array) {
assertInstanceof(msg.array, Int32Array);
assertEquals(99, msg.array[0]);
assertEquals(-77, msg.array[1]);
}
// terminate all workers.
workers[i].terminate();
}
}
(function RunTest() {
print(`running ${kNumBatches} batches...`);
let time = performance.now();
for (let i = 0; i < kNumBatches; i++) {
let before = performance.now();
RunWorkerBatch(kBatchSize);
let time = performance.now() - before;
print(`batch ${i+1}, Δ = ${(time).toFixed(3)} ms`);
}
})();

View File

@ -0,0 +1,40 @@
// Copyright 2015 the V8 project authors. All rights reserved.
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following
// disclaimer in the documentation and/or other materials provided
// with the distribution.
// * Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
if (this.Worker) {
var workerScript =
`var w = new Worker('postMessage(42)', {type: 'string'});
onmessage = function({data:parentMsg}) {
w.postMessage(parentMsg);
var childMsg = w.getMessage();
postMessage(childMsg);
};`;
var w = new Worker(workerScript, {type: 'string'});
w.postMessage(9);
assertEquals(42, w.getMessage());
}

197
deps/v8/test/mjsunit/d8/d8-worker.js vendored Normal file
View File

@ -0,0 +1,197 @@
// Copyright 2015 the V8 project authors. All rights reserved.
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following
// disclaimer in the documentation and/or other materials provided
// with the distribution.
// * Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// Test the Worker API of d8. This test only makes sense with d8. A Worker
// spawns a new OS thread and isolate, and runs it concurrently with the
// current running thread.
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({data: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' + JSON.stringify(m));
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;
case 10:
if (JSON.stringify(m) !== '{"foo":{},"err":{}}')
throw new Error('Object ' + JSON.stringify(m));
break;
case 11:
if (m.message != "message")
throw new Error('Error ' + JSON.stringify(m));
break;
}
if (c == 12) {
postMessage('DONE');
}
};`;
if (this.Worker) {
function createArrayBuffer(byteLength) {
var ab = new ArrayBuffer(byteLength);
var t = new Uint32Array(ab);
for (var i = 0; i < byteLength / 4; ++i)
t[i] = i;
return ab;
}
assertThrows(function() {
// Second arg must be 'options' object
new Worker(workerScript, 123);
});
assertThrows(function() {
new Worker('test/mjsunit/d8/d8-worker.js', {type: 'invalid'});
});
assertThrows(function() {
// worker type defaults to 'classic' which tries to load from file
new Worker(workerScript);
});
var w = new Worker(workerScript, {type: 'string'});
assertEquals("Starting worker", w.getMessage());
w.postMessage(undefined);
w.postMessage(null);
w.postMessage(true);
w.postMessage(false);
w.postMessage(100);
w.postMessage("hi");
w.postMessage([4, true, "bye"]);
w.postMessage({a: 1, b: 2.5, c: "three"});
// Test bad get in transfer list.
var transferList = [undefined];
Object.defineProperty(transferList, '0', {
get: function() {
throw 'unexpected!';
}
});
assertThrows(function() {
w.postMessage([], transferList);
});
// Test console.log in transfer list.
(function() {
var val = [undefined];
Object.defineProperty(val, '0', {get: () => console.log()});
assertThrows(function() {
w.postMessage(val, [val]);
});
})();
// Clone ArrayBuffer
var ab1 = createArrayBuffer(16);
w.postMessage(ab1);
assertEquals(16, ab1.byteLength); // ArrayBuffer should not be detached.
// Transfer ArrayBuffer
var ab2 = createArrayBuffer(32);
w.postMessage(ab2, [ab2]);
assertEquals(0, ab2.byteLength); // ArrayBuffer should be detached.
// Attempting to transfer the same ArrayBuffer twice should throw.
assertThrows(function() {
var ab3 = createArrayBuffer(4);
w.postMessage(ab3, [ab3, ab3]);
});
assertEquals("undefined", typeof foo);
// Transfer Error
const err = new Error();
w.postMessage({ foo: err, err })
// Transfer single Error
w.postMessage(new Error("message"))
// Read a message from the worker.
assertEquals("DONE", w.getMessage());
w.terminate();
// Make sure that the main thread doesn't block forever in getMessage() if
// the worker dies without posting a message.
var w2 = new Worker('', {type: 'string'});
var msg = w2.getMessage();
assertEquals(undefined, msg);
// Test close (should send termination to worker isolate).
var close_worker = new Worker(
"postMessage('one'); close(); while(true) { postMessage('two'); }",
{type: "string"})
assertEquals("one", close_worker.getMessage());
}

View File

@ -0,0 +1,8 @@
// Copyright 2017 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.
// Flags: --enable-tracing --trace-path=test/mjsunit/d8/v8_trace.json
// Just test that running d8 with --enable-tracing does not crash in a normal
// execution without exceptions or calls to natives.

View File

@ -0,0 +1,8 @@
// Copyright 2025 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.
//
// Flags: --flush-denormals
assertFalse(Number.MIN_VALUE * 2 > 0);
assertEquals(Number.MIN_VALUE * 2, 0);

View File

@ -0,0 +1,10 @@
// Copyright 2025 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.
assertTrue(Number.MIN_VALUE * 2 > 0);
d8.test.setFlushDenormals(true);
assertFalse(Number.MIN_VALUE * 2 > 0);
assertEquals(Number.MIN_VALUE * 2, 0);
d8.test.setFlushDenormals(false);
assertTrue(Number.MIN_VALUE * 2 > 0);

View File

@ -0,0 +1,43 @@
// Copyright 2025 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.
assertTrue(Number.MIN_VALUE * 2 > 0);
let flushed = new Worker(function() {
postMessage(Number.MIN_VALUE * 2 > 0);
postMessage(Number.MIN_VALUE * 2 == 0);
}, {
type: "function",
flushDenormals: true
});
assertFalse(flushed.getMessage());
assertTrue(flushed.getMessage());
let nonFlushed = new Worker(function() {
postMessage(Number.MIN_VALUE * 2 > 0);
}, {
type: "function",
flushDenormals: false
});
assertTrue(nonFlushed.getMessage());
let defaultFlush = new Worker(function() {
postMessage(Number.MIN_VALUE * 2 > 0);
}, {
type: "function"
});
assertTrue(defaultFlush.getMessage());
d8.test.setFlushDenormals(true);
let defaultFlushWithFlush = new Worker(function() {
postMessage(Number.MIN_VALUE * 2 > 0);
postMessage(Number.MIN_VALUE * 2 == 0);
}, {
type: "function"
});
assertFalse(defaultFlushWithFlush.getMessage());
assertTrue(defaultFlushWithFlush.getMessage());
d8.test.setFlushDenormals(false);

View File

@ -0,0 +1,16 @@
// Copyright 2024 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.
import { a, b } from "data:text/javascript,export let a = 'b'; export let b = 'a';";
assertEquals('b', a);
assertEquals('a', b);
import x from "data:text/javascript,export default 7";
assertEquals(7, x);
import * as y from "data:text/javascript,export function q() { return 42; }";
assertEquals(42, y.q());
let z = await import("data:text/javascript,export const z = 5");
assertEquals(5, z.z);

View File

@ -0,0 +1,23 @@
// 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.
const mark = performance.mark("a mark");
assertEquals("mark", mark.entryType);
assertEquals("a mark", mark.name);
assertTrue(typeof mark.startTime == "number");
assertEquals(0, mark.duration);
const measure = performance.measure("a measure")
assertEquals("measure", measure.entryType);
assertEquals("a measure", measure.name);
assertEquals(0, measure.startTime);
assertTrue(typeof mark.duration == "number");
assertTrue(mark.startTime <= measure.duration);
const range_measure = performance.measure("a range measure", mark)
assertEquals("measure", range_measure.entryType);
assertEquals("a range measure", range_measure.name);
assertEquals(mark.startTime, range_measure.startTime);
assertTrue(typeof range_measure.duration == "number");
assertTrue(0 <= range_measure.duration);

View File

@ -0,0 +1,14 @@
// Copyright 2024 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.
function func() {
this.postMessage(true);
while (true) {
import('data:text/javascript,export function v4(){}');
}
}
const worker = new Worker(func, {
type: "function"
});
worker.getMessage();