2017-01-16 06:57:54 +00:00
|
|
|
// 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.
|
|
|
|
|
2017-07-13 12:27:47 +00:00
|
|
|
// Flags: --no-stress-fullcodegen
|
2017-01-16 06:57:54 +00:00
|
|
|
|
|
|
|
Debug = debug.Debug
|
|
|
|
|
|
|
|
var exception = null;
|
2017-03-16 17:10:34 +00:00
|
|
|
var object_with_symbol_key = {[Symbol("a")]: 1};
|
|
|
|
var object_with_callbacks = { toString: () => "string", valueOf: () => 3};
|
|
|
|
var symbol_for_a = Symbol.for("a");
|
2017-01-16 06:57:54 +00:00
|
|
|
|
|
|
|
function listener(event, exec_state, event_data, data) {
|
|
|
|
if (event != Debug.DebugEvent.Break) return;
|
|
|
|
try {
|
|
|
|
function success(expectation, source) {
|
2017-03-16 17:10:34 +00:00
|
|
|
var result = exec_state.frame(0).evaluate(source, true).value();
|
|
|
|
if (expectation !== undefined) assertEquals(expectation, result);
|
2017-01-16 06:57:54 +00:00
|
|
|
}
|
|
|
|
function fail(source) {
|
2017-02-10 17:06:22 +00:00
|
|
|
assertThrows(() => exec_state.frame(0).evaluate(source, true),
|
|
|
|
EvalError);
|
2017-01-16 06:57:54 +00:00
|
|
|
}
|
|
|
|
|
2017-03-16 17:10:34 +00:00
|
|
|
// Test some Object functions.
|
2017-03-17 11:57:33 +00:00
|
|
|
success({}, `new Object()`);
|
2017-03-16 17:10:34 +00:00
|
|
|
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})`);
|
|
|
|
|
|
|
|
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("string", `(object_with_callbacks).toString()`);
|
|
|
|
success(3, `(object_with_callbacks).valueOf()`);
|
|
|
|
|
2017-02-22 13:29:40 +00:00
|
|
|
// Test Array functions.
|
2017-03-17 11:57:33 +00:00
|
|
|
success([], `new Array()`);
|
2017-02-22 13:29:40 +00:00
|
|
|
var function_param = [
|
|
|
|
"forEach", "every", "some", "reduce", "reduceRight", "find", "filter",
|
|
|
|
"map", "findIndex"
|
|
|
|
];
|
|
|
|
var fails = ["toString", "join", "toLocaleString", "pop", "push",
|
|
|
|
"reverse", "shift", "unshift", "slice", "splice", "sort", "filter",
|
|
|
|
"map", "copyWithin", "fill", "concat"];
|
|
|
|
for (f of Object.getOwnPropertyNames(Array.prototype)) {
|
|
|
|
if (typeof Array.prototype[f] === "function") {
|
|
|
|
if (fails.includes(f)) {
|
|
|
|
if (function_param.includes(f)) {
|
|
|
|
fail(`[1, 2, 3].${f}(()=>{});`);
|
|
|
|
} else {
|
|
|
|
fail(`[1, 2, 3].${f}();`);
|
|
|
|
}
|
|
|
|
} else if (function_param.includes(f)) {
|
|
|
|
exec_state.frame(0).evaluate(`[1, 2, 3].${f}(()=>{});`, true);
|
|
|
|
} else {
|
|
|
|
exec_state.frame(0).evaluate(`[1, 2, 3].${f}();`, true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-01-16 06:57:54 +00:00
|
|
|
// Test Math functions.
|
|
|
|
for (f of Object.getOwnPropertyNames(Math)) {
|
|
|
|
if (typeof Math[f] === "function") {
|
|
|
|
var result = exec_state.frame(0).evaluate(
|
2017-02-22 13:29:40 +00:00
|
|
|
`Math.${f}(0.5, -0.5);`, true).value();
|
2017-01-16 06:57:54 +00:00
|
|
|
if (f != "random") assertEquals(Math[f](0.5, -0.5), result);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Test Number functions.
|
2017-03-17 11:57:33 +00:00
|
|
|
success(new Number(0), `new Number()`);
|
2017-01-16 06:57:54 +00:00
|
|
|
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") continue;
|
|
|
|
success(Number(0.5)[f](5), `Number(0.5).${f}(5);`);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Test String functions.
|
2017-03-17 11:57:33 +00:00
|
|
|
success(new String(), `new String()`);
|
2017-01-16 06:57:54 +00:00
|
|
|
success(" ", "String.fromCodePoint(0x20)");
|
|
|
|
success(" ", "String.fromCharCode(0x20)");
|
|
|
|
for (f of Object.getOwnPropertyNames(String.prototype)) {
|
|
|
|
if (typeof String.prototype[f] === "function") {
|
|
|
|
// Do not expect locale-specific or regexp-related functions to work.
|
2017-03-17 07:18:07 +00:00
|
|
|
// {Lower,Upper}Case (Locale-specific or not) do not work either
|
|
|
|
// if Intl is enabled.
|
2017-01-16 06:57:54 +00:00
|
|
|
if (f.indexOf("locale") >= 0) continue;
|
2017-03-17 07:18:07 +00:00
|
|
|
if (f.indexOf("Locale") >= 0) continue;
|
|
|
|
if (typeof Intl !== 'undefined') {
|
|
|
|
if (f == "toUpperCase") continue;
|
|
|
|
if (f == "toLowerCase") continue;
|
|
|
|
}
|
2017-01-16 06:57:54 +00:00
|
|
|
if (f == "normalize") continue;
|
|
|
|
if (f == "match") continue;
|
|
|
|
if (f == "search") continue;
|
2017-02-02 11:31:01 +00:00
|
|
|
if (f == "split" || f == "replace") {
|
|
|
|
fail(`'abcd'.${f}(2)`);
|
|
|
|
continue;
|
|
|
|
}
|
2017-01-16 06:57:54 +00:00
|
|
|
success("abcd"[f](2), `"abcd".${f}(2);`);
|
|
|
|
}
|
|
|
|
}
|
2017-01-19 21:45:12 +00:00
|
|
|
fail("'abCd'.toLocaleLowerCase()");
|
|
|
|
fail("'abcd'.toLocaleUpperCase()");
|
2017-03-17 07:18:07 +00:00
|
|
|
if (typeof Intl !== 'undefined') {
|
|
|
|
fail("'abCd'.toLowerCase()");
|
|
|
|
fail("'abcd'.toUpperCase()");
|
|
|
|
}
|
2017-01-16 06:57:54 +00:00
|
|
|
fail("'abcd'.match(/a/)");
|
|
|
|
fail("'abcd'.replace(/a/)");
|
|
|
|
fail("'abcd'.search(/a/)");
|
|
|
|
fail("'abcd'.split(/a/)");
|
|
|
|
|
|
|
|
// Test JSON functions.
|
|
|
|
success('{"abc":[1,2]}', "JSON.stringify(JSON.parse('{\"abc\":[1,2]}'))");
|
2017-03-16 17:10:34 +00:00
|
|
|
|
|
|
|
// 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()`);
|
2017-01-16 06:57:54 +00:00
|
|
|
} catch (e) {
|
|
|
|
exception = e;
|
|
|
|
print(e, e.stack);
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
// Add the debug event listener.
|
|
|
|
Debug.setListener(listener);
|
|
|
|
|
|
|
|
function f() {
|
|
|
|
debugger;
|
|
|
|
};
|
|
|
|
|
|
|
|
f();
|
|
|
|
|
|
|
|
assertNull(exception);
|