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

View File

@ -0,0 +1,41 @@
// Copyright 2023 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: --no-enable-one-shot-optimization
Debug = debug.Debug
var exception = null;
var array = [1,2,3];
function listener(event, exec_state, event_data, data) {
if (event != Debug.DebugEvent.Break) return;
try {
function success(expectation, source) {
var result = exec_state.frame(0).evaluate(source, true).value();
if (expectation !== undefined) assertEquals(expectation, result);
}
function fail(source) {
assertThrows(() => exec_state.frame(0).evaluate(source, true),
EvalError);
}
fail(`array.fill(1)`);
success([1, 1, 1], `[1, 2, 3].fill(1)`);
} catch (e) {
exception = e;
print(e, e.stack);
};
};
// Add the debug event listener.
Debug.setListener(listener);
function f() {
debugger;
};
f();
assertNull(exception);

View File

@ -0,0 +1,65 @@
// 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.
// Test that asynchronous features do not work with
// side-effect free debug-evaluate.
Debug = debug.Debug
var exception = null;
function* generator() {
yield 1;
}
async function async() {
return 1;
}
var g = generator();
var p = new Promise(() => {});
function listener(event, exec_state, event_data, data) {
if (event != Debug.DebugEvent.Break) return;
try {
function fail(source) {
assertThrows(() => exec_state.frame(0).evaluate(source, true),
EvalError);
}
fail("new Promise()");
fail("generator()");
fail("g.next()");
fail("Promise.resolve()");
fail("Promise.reject()");
fail("p.then(() => {})");
fail("p.catch(() => {})");
fail("p.finally(() => {})");
fail("Promise.all([p, p])");
fail("Promise.race([p, p])");
fail("(async function() { await 1; })()");
// Calling (but not awaiting) non-side-effecting async functions
// should be fine.
function succeed(source) {
exec_state.frame(0).evaluate(source, true);
}
succeed("async()");
succeed("(async function() {})()");
} catch (e) {
exception = e;
print(e, e.stack);
};
};
// Add the debug event listener.
Debug.setListener(listener);
function f() {
debugger;
};
f();
assertNull(exception);

View File

@ -0,0 +1,145 @@
// 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.
Debug = debug.Debug
var exception = null;
var date = new Date();
var map = new Map().set("a", "b").set("c", "d");
var set = new Set([1, 2]);
var weak_key = [];
var weak_map = new WeakMap().set(weak_key, "a").set({}, "b");
var weak_set = new WeakSet([weak_key, {}]);
var add = function (a, b) { return a + b; };
var number_value = 13;
function get_number() {
return typeof(number_value);
};
function listener(event, exec_state, event_data, data) {
if (event != Debug.DebugEvent.Break) return;
try {
function success(expectation, source) {
var result = exec_state.frame(0).evaluate(source, true).value();
if (expectation !== undefined) assertEquals(expectation, result);
}
function fail(source) {
assertThrows(() => exec_state.frame(0).evaluate(source, true),
EvalError);
}
// Test Function-related functions.
success("func", `(function func(){}).prototype.constructor.name`);
success("[object Object]", `(function func(){}).prototype.toString()`);
success(12, `add.bind(null, 10)(2)`);
success(3, `add.call(null, 1, 2)`);
success(3, `add.apply(null, [1, 2])`);
// Test Date.prototype functions.
success(undefined, `Date()`);
success(undefined, `new Date()`);
success(undefined, `Date.now()`);
success(undefined, `Date.parse(1)`);
for (f of Object.getOwnPropertyNames(Date.prototype)) {
if (typeof Date.prototype[f] === "function") {
if (f.startsWith("set")) {
fail(`date.${f}(5);`, true);
} else if (f.startsWith("toLocale") && typeof Intl === "undefined") {
continue;
} else {
success(undefined, `date.${f}();`);
}
}
}
// Test Boolean.
success(true, `Boolean(1)`);
success(new Boolean(true), `new Boolean(1)`);
success("true", `true.toString()`);
success(true, `true.valueOf()`);
// Test global functions.
success(1, `parseInt("1")`);
success(1.3, `parseFloat("1.3")`);
success("abc", `decodeURI("abc")`);
success("abc", `encodeURI("abc")`);
success("abc", `decodeURIComponent("abc")`);
success("abc", `encodeURIComponent("abc")`);
success("abc", `escape("abc")`);
success("abc", `unescape("abc")`);
success(true, `isFinite(0)`);
success(true, `isNaN(0/0)`);
success("object", `typeof date`);
success("number", `get_number()`);
// Test Map functions.
success(undefined, `new Map()`);
success("[object Map]", `map.toString()`);
success("b", `map.get("a")`);
success(true, `map.get("x") === undefined`);
success(undefined, `map.entries()`);
success(undefined, `map.keys()`);
success(undefined, `map.values()`);
success(undefined, `map.forEach(()=>1)`);
success(true, `map.has("c")`);
success(2, `map.size`);
success(undefined, `new Map([[1, 2]])`);
fail(`map.delete("a")`);
fail(`map.clear()`);
fail(`map.set("x", "y")`);
// Test Set functions.
success(undefined, `new Set()`);
success("[object Set]", `set.toString()`);
success(undefined, `set.entries()`);
success(undefined, `set.keys()`);
success(undefined, `set.values()`);
success(undefined, `set.forEach(()=>1)`);
success(true, `set.has(1)`);
success(2, `set.size`);
success(1, `new Set([1]).size`);
fail(`set.add(2)`);
fail(`set.delete(1)`);
fail(`set.clear()`);
// Test WeakMap functions.
success(undefined, `new WeakMap()`);
success("[object WeakMap]", `weak_map.toString()`);
success("a", `weak_map.get(weak_key)`);
success(true, `weak_map.get([]) === undefined`);
success(true, `weak_map.has(weak_key)`);
fail(`new WeakMap([[[], {}]])`);
fail(`weak_map.delete("a")`);
fail(`weak_map.set("x", "y")`);
// Test WeakSet functions.
success(undefined, `new WeakSet()`);
success("[object WeakSet]", `weak_set.toString()`);
success(true, `weak_set.has(weak_key)`);
fail(`new WeakSet([[], {}])`);
fail(`weak_set.add([])`);
fail(`weak_set.delete("a")`);
// Test BigInt functions.
success(10n, `BigInt('10')`);
success(10n, `BigInt.asIntN(10, 10n)`);
success(10n, `BigInt.asUintN(10, 10n)`);
success("10", `10n.toString()`);
success(10n, `10n.valueOf()`);
} catch (e) {
exception = e;
print(e, e.stack);
};
};
// Add the debug event listener.
Debug.setListener(listener);
function f() {
debugger;
};
f();
assertNull(exception);

View File

@ -0,0 +1,289 @@
// 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: --js-staging
Debug = debug.Debug
var exception = null;
var object = {"foo": "bar"};
var object_with_symbol_key = {[Symbol("a")]: 1};
var object_with_callbacks = { toString: () => "string", valueOf: () => 3};
var symbol_for_a = Symbol.for("a");
var typed_array = new Uint8Array([1, 2, 3]);
var array_buffer = new ArrayBuffer(3);
var data_view = new DataView(new ArrayBuffer(8), 0, 8);
var array = [1,2,3];
var pure_function = function(x) { return x * x; };
var unpure_function = function(x) { array.push(x); };
var stack = new DisposableStack();
var regexp = /\d/g;
var async_stack = new AsyncDisposableStack();
function listener(event, exec_state, event_data, data) {
if (event != Debug.DebugEvent.Break) return;
try {
function success(expectation, source) {
var result = exec_state.frame(0).evaluate(source, true).value();
if (expectation !== undefined) assertEquals(expectation, result);
}
function fail(source) {
assertThrows(() => exec_state.frame(0).evaluate(source, true),
EvalError);
}
// Test some Object functions.
success({}, `new Object()`);
success({p : 3}, `Object.create({}, { p: { value: 3 } })`);
success("[[\"a\",1],[\"b\",2]]",
`JSON.stringify(Object.entries({a:1, b:2}))`);
success({value: 1, writable: true, enumerable: true, configurable: true},
`Object.getOwnPropertyDescriptor({a: 1}, "a")`);
success("{\"a\":{\"value\":1,\"writable\":true," +
"\"enumerable\":true,\"configurable\":true}}",
`JSON.stringify(Object.getOwnPropertyDescriptors({a: 1}))`);
success(["a"], `Object.getOwnPropertyNames({a: 1})`);
success(undefined, `Object.getOwnPropertySymbols(object_with_symbol_key)`);
success({}, `Object.getPrototypeOf(Object.create({}))`);
success(true, `Object.is(Object, Object)`);
success(true, `Object.isExtensible({})`);
success(false, `Object.isFrozen({})`);
success(false, `Object.isSealed({})`);
success([1, 2], `Object.values({a:1, b:2})`);
success(["a", 1, "b", 2], `Object.entries({a:1, b:2}).flat()`);
success(["a", "b"], `Object.keys({a:1, b:2})`);
success(
'{"1":[1],"2":[2]}', `JSON.stringify(Object.groupBy([1,2], x => x))`);
fail(`Object.assign({}, {})`);
fail(`Object.defineProperties({}, [{p:{value:3}}])`);
fail(`Object.defineProperty({}, {p:{value:3}})`);
fail(`Object.freeze({})`);
fail(`Object.preventExtensions({})`);
fail(`Object.seal({})`);
fail(`Object.setPrototypeOf({}, {})`);
// Test some Object.prototype functions.
success(true, `({a:1}).hasOwnProperty("a")`);
success(true, `Object.prototype.isPrototypeOf({})`);
success(true, `({a:1}).propertyIsEnumerable("a")`);
success("[object Object]", `({a:1}).toString()`);
success("[object Object]", `({a:1}).toLocaleString()`);
success("string", `(object_with_callbacks).toString()`);
success(3, `(object_with_callbacks).valueOf()`);
// Test Array functions.
success(true, `Array.isArray([1, 2, 3])`);
success([], `new Array()`);
success([undefined, undefined], `new Array(2)`);
success([1, 2], `new Array(1, 2)`);
success([1, 2, 3], `Array.from([1, 2, 3])`);
success(3, `Array.from([1, 2, 3]).pop()`);
success([1, 2, 3], `Array.of(1, 2, 3)`);
success(3, `Array.of(1, 2, 3).pop()`);
var function_param = [
"flatMap", "forEach", "every", "some", "reduce", "reduceRight", "find",
"filter", "map", "findIndex", "findLast", "findLastIndex", "group",
"groupToMap"
];
var fails = ["pop", "push", "reverse", "shift", "unshift", "splice",
"sort", "copyWithin", "fill"];
for (f of Object.getOwnPropertyNames(Array.prototype)) {
if (typeof Array.prototype[f] === "function") {
if (fails.includes(f)) {
if (function_param.includes(f)) {
fail(`array.${f}(()=>{});`);
} else {
fail(`array.${f}();`);
}
} else if (function_param.includes(f)) {
exec_state.frame(0).evaluate(`array.${f}(()=>{});`, true);
} else {
exec_state.frame(0).evaluate(`array.${f}();`, true);
}
}
}
// Test ArrayBuffer functions.
success(3, `array_buffer.byteLength`);
success(2, `array_buffer.slice(1, 3).byteLength`);
success(true, `ArrayBuffer.isView(typed_array)`);
// Test DataView functions.
success(undefined, `new DataView(array_buffer, 1, 2)`);
success(undefined, `data_view.buffer`);
success(undefined, `data_view.byteLength`);
success(undefined, `data_view.byteOffset`);
for (f of Object.getOwnPropertyNames(DataView.prototype)) {
if (typeof data_view[f] === 'function') {
if (f.startsWith('getBig')) {
success(0n, `data_view.${f}()`);
} else if (f.startsWith('get')) {
success(0, `data_view.${f}()`);
}
}
}
// Test TypedArray functions.
success({}, `new Uint8Array()`);
success({0: 0, 1: 0}, `new Uint8Array(2)`);
success({0: 1, 1: 2, 2: 3}, `new Uint8Array(typed_array)`);
success(true, `!!typed_array.buffer`);
success(0, `typed_array.byteOffset`);
success(3, `typed_array.byteLength`);
success({0: 1, 1: 2}, `Uint8Array.of(1, 2)`);
function_param = [
"forEach", "every", "some", "reduce", "reduceRight", "find", "filter",
"map", "findIndex", "findLast", "findLastIndex",
];
fails = ["reverse", "sort", "copyWithin", "fill", "set"];
var typed_proto_proto = Object.getPrototypeOf(Object.getPrototypeOf(new Uint8Array()));
for (f of Object.getOwnPropertyNames(typed_proto_proto)) {
if (typeof typed_array[f] === "function" && f !== "constructor") {
if (fails.includes(f)) {
if (function_param.includes(f)) {
fail(`typed_array.${f}(()=>{});`);
} else {
fail(`typed_array.${f}();`);
}
} else if (function_param.includes(f)) {
exec_state.frame(0).evaluate(`typed_array.${f}(()=>{});`, true);
} else {
exec_state.frame(0).evaluate(`typed_array.${f}();`, true);
}
}
}
// Test Math functions.
for (f of Object.getOwnPropertyNames(Math)) {
if (f !== "random" && typeof Math[f] === "function") {
var result = exec_state.frame(0).evaluate(
`Math.${f}(0.5, -0.5);`, true).value();
assertEquals(Math[f](0.5, -0.5), result);
}
}
fail("Math.random();");
// Test Number functions.
success(new Number(0), `new Number()`);
for (f of Object.getOwnPropertyNames(Number)) {
if (typeof Number[f] === "function") {
success(Number[f](0.5), `Number.${f}(0.5);`);
}
}
for (f of Object.getOwnPropertyNames(Number.prototype)) {
if (typeof Number.prototype[f] === "function") {
if (f == "toLocaleString" && typeof Intl === "undefined") continue;
success(Number(0.5)[f](5), `Number(0.5).${f}(5);`);
}
}
// Test String functions.
for (f of Object.getOwnPropertyNames(String.prototype)) {
if (typeof String.prototype[f] === "function") {
// Do not expect locale-specific or regexp-related functions to work.
// {Lower,Upper}Case (Locale-specific or not) do not work either
// if Intl is enabled.
if (f.indexOf("locale") >= 0) continue;
if (f.indexOf("Locale") >= 0) continue;
switch (f) {
case "match":
case "split":
case "matchAll":
case "normalize":
case "search":
case "toLowerCase":
case "toUpperCase":
continue;
}
success("abcd"[f](2), `"abcd".${f}(2);`);
}
}
success(new String(), `new String()`);
success(" ", "String.fromCodePoint(0x20)");
success(" ", "String.fromCharCode(0x20)");
success("abcd", "'abCd'.toLocaleLowerCase()");
success("ABCD", "'abcd'.toLocaleUpperCase()");
success("abcd", "'abCd'.toLowerCase()");
success("ABCD", "'abcd'.toUpperCase()");
success("a", "'abcd'.match('a')[0]");
success("a", "'abcd'.match(/a/)[0]");
fail("'1234'.match(regexp)");
success("[object RegExp String Iterator]", "'abcd'.matchAll('a').toString()");
success("[object RegExp String Iterator]", "'abcd'.matchAll(/a/g).toString()");
fail("'1234'.matchAll(regexp)");
success("ebcd", "'abcd'.replace('a', 'e')");
success("ebcd", "'abcd'.replace(/a/, 'e')");
fail("'135'.replace(regexp, 'e')");
success("ebcd", "'abcd'.replaceAll('a', 'e')");
success("ebcd", "'abcd'.replaceAll(/a/g, 'e')");
fail("'135'.replaceAll(regexp, 'e')");
success(1, "'abcd'.search('b')");
success(1, "'abcd'.search(/b/)");
fail("'12a34b'.search(regexp)");
success(["a", "cd"], "'abcd'.split('b')");
success(["a", "cd"], "'abcd'.split(/b/)");
fail("'12a34b'.split(regexp)");
success(-1, "'abcd'.localeCompare('abce')");
success('abcd', "'abcd'.normalize('NFC')");
// Test RegExp functions.
fail(`/a/.compile()`);
success('a', `/a/.exec('abc')[0]`);
success(true, `/a/.test('abc')`);
fail(`/a/.toString()`);
// Test JSON functions.
success('{"abc":[1,2]}', "JSON.stringify(JSON.parse('{\"abc\":[1,2]}'))");
// Test Symbol functions.
success(undefined, `Symbol("a")`);
fail(`Symbol.for("a")`); // Symbol.for can be observed via Symbol.keyFor.
success("a", `Symbol.keyFor(symbol_for_a)`);
success("Symbol(a)", `symbol_for_a.valueOf().toString()`);
success("Symbol(a)", `symbol_for_a[Symbol.toPrimitive]().toString()`);
// Test Reflect functions.
success(4, `Reflect.apply(pure_function, undefined, [2])`);
fail(`Reflect.apply(unpure_function, undefined, [2])`);
success("foo", `Reflect.construct(String, ["foo"]).toString()`);
fail(`Reflect.construct(unpure_function, ["foo"])`);
success("bar", `Reflect.getOwnPropertyDescriptor(object, "foo").value`);
success(true, `Reflect.getPrototypeOf(object) === Object.prototype`);
success(true, `Reflect.has(object, "foo")`);
success(true, `Reflect.isExtensible(object)`);
success("foo", `Reflect.ownKeys(object)[0]`);
fail(`Reflect.defineProperty(object, "baz", {})`);
fail(`Reflect.deleteProperty(object, "foo")`);
fail(`Reflect.preventExtensions(object)`);
fail(`Reflect.set(object, "great", "expectations")`);
fail(`Reflect.setPrototypeOf(object, Array.prototype)`);
// Test some Map functions
success('[1]', `JSON.stringify(Map.groupBy([1,2], x => x).get(1))`);
// Test DisposableStack functions.
success({}, `new DisposableStack()`);
success(false, `stack.disposed`);
// Test AsyncDisposableStack functions.
success({}, `new AsyncDisposableStack()`);
success(false, `async_stack.disposed`);
} catch (e) {
exception = e;
print(e, e.stack);
};
};
// Add the debug event listener.
Debug.setListener(listener);
function f() {
debugger;
};
f();
assertNull(exception);

View File

@ -0,0 +1,109 @@
// 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.
Debug = debug.Debug
var exception = null;
var o = { p : 1 };
var successes = [
[45,
`(function() {
var sum = 0;
for (var i = 0; i < 10; i++) sum += i;
return sum;
})()`
],
["0012",
`(function() {
var sum = 0;
for (var i in [1, 2, 3]) sum += i;
return sum;
})()`
],
[15,
`(function() {
var sum = 1;
while (sum < 12) sum += sum + 1;
return sum;
})()`
],
[15,
`(function() {
var sum = 1;
do { sum += sum + 1; } while (sum < 12);
return sum;
})()`
],
["023",
`(function() {
var sum = "";
for (var i = 0; i < 4; i++) {
switch (i) {
case 0:
case 1:
if (i == 0) sum += i;
break;
default:
case 3:
sum += i;
break;
}
}
return sum;
})()`
],
["oups",
`(function() {
try {
if (Math.sin(1) < 1) throw new Error("oups");
} catch (e) {
return e.message;
}
})()`
],
[6,
`(function() { // Iterator.prototype.next performs stores.
var sum = 0;
for (let i of [1, 2, 3]) sum += i;
return sum;
})()`
]
];
var fails = [
`(function() { // Store to scope object.
with (o) {
p = 2;
}
})()`,
];
function listener(event, exec_state, event_data, data) {
if (event != Debug.DebugEvent.Break) return;
try {
successes.forEach(function ([expectation, source]) {
assertEquals(expectation,
exec_state.frame(0).evaluate(source, true).value());
});
fails.forEach(function (test) {
assertThrows(() => exec_state.frame(0).evaluate(test, true), EvalError);
});
} catch (e) {
exception = e;
print(e, e.stack);
};
};
// Add the debug event listener.
Debug.setListener(listener);
function f() {
debugger;
};
f();
assertNull(exception);

View File

@ -0,0 +1,67 @@
// 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.
// Test that declaring local variables in IIFEs works with
// side-effect free debug-evaluate.
Debug = debug.Debug
var exception = null;
function listener(event, exec_state, event_data, data) {
if (event != Debug.DebugEvent.Break) return;
try {
function success(expectation, source) {
assertEquals(expectation,
exec_state.frame(0).evaluate(source, true).value());
}
function fail(source) {
assertThrows(() => exec_state.frame(0).evaluate(source, true),
EvalError);
}
// Declaring 'a' sets a property to the global object.
fail("var a = 3");
exec_state.frame(0).evaluate("var a = 2", false);
assertEquals(2, a);
// Wrapping into an IIFE would be fine, since 'a' is local.
success(100,
`(function(x) {
var a = 0;
for (var i = 0; i < x; i++) {
a += x;
}
return a;
})(10);`);
success(100,
`(x => {
let a = 0;
for (var i = 0; i < x; i++) {
a += x;
}
return a;
})(10);`);
// Not using 'var' to declare would make the access go to global object.
fail( `(function(x) {
a = 0;
for (var i = 0; i < x; i++) {
a += x;
}
return a;
})(10);`);
} catch (e) {
exception = e;
print(e, e.stack);
};
};
// Add the debug event listener.
Debug.setListener(listener);
function f() {
debugger;
};
f();
assertNull(exception);

View File

@ -0,0 +1,97 @@
// 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.
Debug = debug.Debug
var exception = null;
var date = new Date();
var T = true;
var F = false;
var one = 1;
var two = 2;
var string = "s";
var array = [1, 2, 3];
function max(...rest) {
return Math.max(...rest);
}
function def(a = 1) {
return a;
}
function d1([a, b = 'b']) {
return a + b;
}
function d2({ x: c, y, z = 'z' } = {x: 'x', y: 'y' }) {
return c + y + z;
}
function listener(event, exec_state, event_data, data) {
if (event != Debug.DebugEvent.Break) return;
try {
function success(expectation, source) {
var result = exec_state.frame(0).evaluate(source, true).value();
if (expectation !== undefined) assertEquals(expectation, result);
}
function fail(source) {
assertThrows(() => exec_state.frame(0).evaluate(source, true),
EvalError);
}
success(false, `Object == {}`);
success(false, `Object === {}`);
success(true, `Object != {}`);
success(true, `Object !== {}`);
success(true, `'s' == string`);
success(true, `'s' === string`);
success(true, `1 < Math.cos(0) * 2`);
success(false, `1 < string`);
success(true, `'a' < string`);
success("s", `string[0]`);
success(0, `[0][0]`);
success(1, `T^F`);
success(0, `T&F`);
success(1, `T|F`);
success(false, `T&&F`);
success(true, `T||F`);
success(false, `T?F:T`);
success(false, `!T`);
success(1, `+one`);
success(-1, `-one`);
success(-2, `~one`);
success(4, `one << two`);
success(1, `two >> one`);
success(1, `two >>> one`);
success(3, `two + one`);
success(2, `two * one`);
success(0.5, `one / two`);
success(0, `(one / two) | 0`);
success(1, `one ** two`);
success(NaN, `string * two`);
success("s2", `string + two`);
success("s2", `string + two`);
success([1,2,3], `[...array]`);
success(3, `max(...array)`);
success({s:1}, `({[string]:1})`);
fail(`[a, b] = [1, 2]`);
success(2, `def(2)`);
success(1, `def()`);
success('ab', `d1(['a'])`);
success("XYz", `d2({x:'X', y:'Y'})`);
} catch (e) {
exception = e;
print(e, e.stack);
};
};
// Add the debug event listener.
Debug.setListener(listener);
function f() {
debugger;
};
f();
assertNull(exception);

View File

@ -0,0 +1,28 @@
// 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.
Debug = debug.Debug;
/(\w)(\w)(\w)(\w)(\w)(\w)(\w)(\w)(\w)(\w)/.exec(">>>abcdefghij<<<");
assertRegExp();
Debug.evaluateGlobal(`/(\\w)(\\w)(\\w)(\\w)(\\w)(\\w)(\\w)(\\w)(\\w)(\\w)/.exec(">>>hklmnoprst<<<")`, true);
assertRegExp();
function assertRegExp() {
assertEquals("a", RegExp.$1);
assertEquals("b", RegExp.$2);
assertEquals("c", RegExp.$3);
assertEquals("d", RegExp.$4);
assertEquals("e", RegExp.$5);
assertEquals("f", RegExp.$6);
assertEquals("g", RegExp.$7);
assertEquals("h", RegExp.$8);
assertEquals("i", RegExp.$9);
assertEquals("abcdefghij", RegExp.lastMatch);
assertEquals("j", RegExp.lastParen);
assertEquals(">>>", RegExp.leftContext);
assertEquals("<<<", RegExp.rightContext);
assertEquals(">>>abcdefghij<<<", RegExp.input);
}

View File

@ -0,0 +1,327 @@
// 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: --js-staging
Debug = debug.Debug;
// StaCurrentContextSlot
success(10, `(function(){
const x = 10;
function f1() {return x;}
return x;
})()`);
// SetNamedProperty
var a = {name: 'foo'};
function set_name(a) {
a.name = 'bar';
return a.name;
}
fail(`set_name(a)`);
success('bar', `set_name({name: 'foo'})`);
// DefineNamedOwnProperty
var name_value = 'value';
function create_object_literal() {
var obj = {name: name_value};
return obj.name;
};
success('value', `create_object_literal()`);
// SetKeyedProperty
var arrayValue = 1;
function create_array_literal() {
return [arrayValue];
}
var b = { 1: 2 };
success([arrayValue], `create_array_literal()`)
fail(`b[1] ^= 2`);
// StaInArrayLiteral
function return_array_use_spread(a) {
return [...a];
}
success([1], `return_array_use_spread([1])`);
// CallAccessorSetter
var array = [1,2,3];
fail(`array.length = 2`);
success(2, `[1,2,3].length = 2`);
// DefineKeyedOwnPropertyInLiteral
function return_literal_with_data_property(a) {
return {[a] : 1};
}
success({foo: 1}, `return_literal_with_data_property('foo')`);
// Set builtins with temporary objects
var set = new Set([1,2]);
fail(`set.add(3).size`);
success(1, `new Set().add(1).size`);
success(0, `(() => { const s = new Set([1]); s.delete(1); return s.size; })()`);
fail(`set.delete(1)`);
success(0, `(() => { const s = new Set([1]); s.clear(); return s.size; })()`);
fail(`set.clear()`);
// new set
success(3, `(() => {
let s = 0;
for (const a of new Set([1,2]))
s += a;
return s;
})()`);
// existing set
success(3, `(() => {
let s = 0;
for (const a of set)
s += a;
return s;
})()`);
// existing iterator
var setIterator = set.entries();
fail(`(() => {
let s = 0;
for (const a of setIterator)
s += a;
return s;
})()`);
// Array builtins with temporary objects
success([1,1,1], '[1,2,3].fill(1)');
fail(`array.fill(1)`);
success([1], `(() => { const a = []; a.push(1); return a; })()`);
fail(`array.push(1)`);
success([1], `(() => { const a = [1,2]; a.pop(); return a; })()`);
fail(`array.pop()`);
success([3,2,1], `[1,2,3].reverse()`);
fail(`array.reverse()`);
success([1,2,3], `[2,1,3].sort()`);
fail(`array.sort()`);
success([2,3], `[1,2,3].splice(1,2)`);
fail(`array.splice(1,2)`);
success([1,2], `(() => { const a = [2]; a.unshift(1); return a; })()`);
fail(`array.unshift(1)`);
success(1, `[1,2].shift()`);
fail(`array.shift()`);
// new array
success(6, `(() => {
let s = 0;
for (const a of [1,2,3])
s += a;
return s;
})()`);
// existing array
success(6, `(() => {
let s = 0;
for (const a of array)
s += a;
return s;
})()`);
// existing iterator
var arrayIterator = array.entries();
fail(`(() => {
let s = 0;
for (const a of arrayIterator)
s += a;
return s;
})()`);
success(6, `array.reduce((a,b) => a + b, 0)`);
// Map builtins with temporary objects
var map = new Map([[1,2]]);
fail(`map.set(3, 4).size`);
success(1, `new Map().set(1, 2).size`);
success(0, `(() => {
const m = new Map([[1, 2]]);
m.delete(1);
return m.size;
})()`);
fail(`map.delete(1)`);
success(0, `(() => {
const m = new Map([[1, 2]]);
m.clear();
return m.size;
})()`);
fail(`map.clear()`);
// new set
success(2, `(() => {
let s = 0;
for (const [a, b] of new Map([[1,2]]))
s += b;
return s;
})()`);
// existing set
success(2, `(() => {
let s = 0;
for (const [a,b] of map)
s += b;
return s;
})()`);
// existing iterator
var mapIterator = map.entries();
fail(`(() => {
let s = 0;
for (const [a,b] of mapIterator)
s += a;
return s;
})()`);
// Regexps
var regExp = /a/;
success(true, `/a/.test('a')`);
fail(`/a/.test({toString: () => {map.clear(); return 'a';}})`)
fail(`regExp.test('a')`);
// DisposableStack use().
let disposable_stack = new DisposableStack();
fail(`(() => {
const disposable = {
value: 1,
[Symbol.dispose]() {
return 43;
}
};
disposable_stack.use(disposable);
})()`);
success(42, `(() => {
let stack = new DisposableStack();
const disposable = {
value: 1,
[Symbol.dispose]() {
return 43;
}
};
stack.use(disposable);
return 42;
})()`)
// DisposableStack dispose().
fail(`disposable_stack.dispose()`);
success(42, `(() => {
let stack = new DisposableStack();
stack.dispose();
return 42;
})()`);
// DisposableStack adopt().
fail(`disposable_stack.adopt(42, function(v) {return v})`);
success(42, `(() => {
let stack = new DisposableStack();
stack.adopt(42, function(v) {return v});
return 42;
})()`);
// DisposableStack defer().
fail(`disposable_stack.defer(() => console.log(42))`);
success(42, `(() => {
let stack = new DisposableStack();
stack.defer(() => console.log(42));
return 42;
})()`);
// DisposableStack move().
fail(`let new_disposable_stack = disposable_stack.move()`);
success(42, `(() => {
let stack = new DisposableStack();
const disposable = {
value: 1,
[Symbol.dispose]() {
return 43;
}
};
stack.use(disposable);
let new_disposable_stack = stack.move()
return 42;
})()`);
// AsyncDisposableStack use().
let async_disposable_stack = new AsyncDisposableStack();
fail(`(() => {
const async_disposable = {
value: 1,
[Symbol.asyncDispose]() {
return 43;
}
};
async_disposable_stack.use(async_disposable);
})()`);
success(42, `(() => {
let stack = new AsyncDisposableStack();
const async_disposable = {
value: 1,
[Symbol.asyncDispose]() {
return 43;
}
};
stack.use(async_disposable);
return 42;
})()`)
// AsyncDisposableStack disposeAsync().
fail(`async_disposable_stack.disposeAsync()`);
success(42, `(() => {
let stack = new AsyncDisposableStack();
stack.disposeAsync();
return 42;
})()`);
// AsyncDisposableStack adopt().
fail(`async_disposable_stack.adopt(42, function(v) {return v})`);
success(42, `(() => {
let stack = new AsyncDisposableStack();
stack.adopt(42, function(v) {return v});
return 42;
})()`);
// AsyncDisposableStack defer().
fail(`async_disposable_stack.defer(() => console.log(42))`);
success(42, `(() => {
let stack = new AsyncDisposableStack();
stack.defer(() => console.log(42));
return 42;
})()`);
// AsyncDisposableStack move().
fail(`let new_async_Sdisposable_stack = async_disposable_stack.move()`);
success(42, `(() => {
let stack = new AsyncDisposableStack();
const async_disposable = {
value: 1,
[Symbol.asyncDispose]() {
return 43;
}
};
stack.use(async_disposable);
let new_async_disposable_stack = stack.move()
return 42;
})()`);
function success(expectation, source) {
const result = Debug.evaluateGlobal(source, true).value();
if (expectation !== undefined) assertEquals(expectation, result);
}
function fail(source) {
assertThrows(() => Debug.evaluateGlobal(source, true),
EvalError);
}

View File

@ -0,0 +1,131 @@
// 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.
Debug = debug.Debug
var exception = null;
let a = 1;
var object = { property : 2,
get getter() { return 3; }
};
var string0 = new String("string");
var string1 = { toString() { return "x"; } };
var string2 = { toString() { print("x"); return "x"; } };
var array = [4, 5];
var error = new Error();
function simple_return(x) { return x; }
function set_a() { a = 2; }
function get_a() { return a; }
var bound = get_a.bind(0);
function return_arg0() { return return_arg0.arguments[0]; }
function return_caller_name() { return return_caller_name.caller.name; }
var global_eval = eval;
function listener(event, exec_state, event_data, data) {
if (event != Debug.DebugEvent.Break) return;
try {
function success(expectation, source) {
assertEquals(expectation,
exec_state.frame(0).evaluate(source, true).value());
}
function fail(source) {
assertThrows(() => exec_state.frame(0).evaluate(source, true),
EvalError);
}
// Simple test.
success(3, "1 + 2");
// Dymanic load.
success(array, "array");
// Context load.
success(1, "a");
// Global and named property load.
success(2, "object.property");
// Load via read-only getter.
success(3, "object.getter");
// Implicit call to read-only toString.
success("xy", "string1 + 'y'");
// Keyed property load.
success(5, "array[1]");
// Call to read-only function.
success(1, "get_a()");
success(1, "bound()");
success({}, "new get_a()");
// Call to read-only function within try-catch.
success(1, "try { get_a() } catch (e) {}");
// Call to C++ built-in.
success(Math.sin(2), "Math.sin(2)");
// Call to allowlisted get accessors.
success(3, "'abc'.length");
success(2, "array.length");
success(1, "'x'.length");
success(0, "set_a.length");
success("set_a", "set_a.name");
success(0, "bound.length");
success("bound get_a", "bound.name");
success(1, "return_arg0(1)");
success("f", "(function f() { return return_caller_name() })()");
// Non-evaluated call.
// Constructed literals.
success([1], "[1]");
success({x: 1}, "({x: 1})");
success([1], "[a]");
success({x: 1}, "({x: a})");
// Test that template literal evaluation fails.
fail("simple_return`1`");
// Test that non-read-only code fails.
fail("exception = 1");
// Test that calling a non-read-only function fails.
fail("set_a()");
fail("new set_a()");
// Test that implicit call to a non-read-only function fails.
fail("string2 + 'y'");
// Test that try-catch does not catch the EvalError.
fail("try { set_a() } catch (e) {}");
// Test that call to set accessor fails.
fail("array.length = 4");
fail("set_a.name = 'set_b'");
fail("set_a.length = 1");
fail("bound.name = 'bound'");
fail("bound.length = 1");
fail("set_a.prototype = null");
// Test that call to non-allowlisted get accessor fails.
fail("error.stack");
// Call to set accessors with receiver check.
success(1, "[].length = 1");
success(1, "'x'.length = 1");
fail("string0.length = 1");
success(1, "(new String('abc')).length = 1");
success("g", "(function(){}).name = 'g'");
success(1, "(function(){}).length = 1");
success("g", "get_a.bind(0).name = 'g'");
success(1, "get_a.bind(0).length = 1");
success(null, "(function(){}).prototype = null");
fail("(new Error()).stack.length > 1");
fail("(new Error()).stack = 'a'");
// Eval is not allowed.
fail("eval('Math.sin(1)')");
fail("eval('exception = 1')");
fail("global_eval('1')");
success(1, "(() => { var a = 1; return a++; })()")
} catch (e) {
exception = e;
print(e, e.stack);
};
};
// Add the debug event listener.
Debug.setListener(listener);
function f() {
debugger;
};
f();
assertNull(exception);
assertEquals(1, a);