| OLD | NEW |
| 1 // Copyright 2017 the V8 project authors. All rights reserved. | 1 // Copyright 2017 the V8 project authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 // Flags: --ignition --turbo | 5 // Flags: --ignition --turbo |
| 6 | 6 |
| 7 Debug = debug.Debug | 7 Debug = debug.Debug |
| 8 | 8 |
| 9 var exception = null; | 9 var exception = null; |
| 10 var object_with_symbol_key = {[Symbol("a")]: 1}; |
| 11 var object_with_callbacks = { toString: () => "string", valueOf: () => 3}; |
| 12 var symbol_for_a = Symbol.for("a"); |
| 10 | 13 |
| 11 function listener(event, exec_state, event_data, data) { | 14 function listener(event, exec_state, event_data, data) { |
| 12 if (event != Debug.DebugEvent.Break) return; | 15 if (event != Debug.DebugEvent.Break) return; |
| 13 try { | 16 try { |
| 14 function success(expectation, source) { | 17 function success(expectation, source) { |
| 15 assertEquals(expectation, | 18 var result = exec_state.frame(0).evaluate(source, true).value(); |
| 16 exec_state.frame(0).evaluate(source, true).value()); | 19 if (expectation !== undefined) assertEquals(expectation, result); |
| 17 } | 20 } |
| 18 function fail(source) { | 21 function fail(source) { |
| 19 assertThrows(() => exec_state.frame(0).evaluate(source, true), | 22 assertThrows(() => exec_state.frame(0).evaluate(source, true), |
| 20 EvalError); | 23 EvalError); |
| 21 } | 24 } |
| 22 | 25 |
| 26 // Test some Object functions. |
| 27 success({p : 3}, `Object.create({}, { p: { value: 3 } })`); |
| 28 success("[[\"a\",1],[\"b\",2]]", |
| 29 `JSON.stringify(Object.entries({a:1, b:2}))`); |
| 30 success({value: 1, writable: true, enumerable: true, configurable: true}, |
| 31 `Object.getOwnPropertyDescriptor({a: 1}, "a")`); |
| 32 success("{\"a\":{\"value\":1,\"writable\":true," + |
| 33 "\"enumerable\":true,\"configurable\":true}}", |
| 34 `JSON.stringify(Object.getOwnPropertyDescriptors({a: 1}))`); |
| 35 success(["a"], `Object.getOwnPropertyNames({a: 1})`); |
| 36 success(undefined, `Object.getOwnPropertySymbols(object_with_symbol_key)`); |
| 37 success({}, `Object.getPrototypeOf(Object.create({}))`); |
| 38 success(true, `Object.is(Object, Object)`); |
| 39 success(true, `Object.isExtensible({})`); |
| 40 success(false, `Object.isFrozen({})`); |
| 41 success(false, `Object.isSealed({})`); |
| 42 success([1, 2], `Object.values({a:1, b:2})`); |
| 43 |
| 44 fail(`Object.assign({}, {})`); |
| 45 fail(`Object.defineProperties({}, [{p:{value:3}}])`); |
| 46 fail(`Object.defineProperty({}, {p:{value:3}})`); |
| 47 fail(`Object.freeze({})`); |
| 48 fail(`Object.preventExtensions({})`); |
| 49 fail(`Object.seal({})`); |
| 50 fail(`Object.setPrototypeOf({}, {})`); |
| 51 |
| 52 // Test some Object.prototype functions. |
| 53 success(true, `({a:1}).hasOwnProperty("a")`); |
| 54 success(true, `Object.prototype.isPrototypeOf({})`); |
| 55 success(true, `({a:1}).propertyIsEnumerable("a")`); |
| 56 success("[object Object]", `({a:1}).toString()`); |
| 57 success("string", `(object_with_callbacks).toString()`); |
| 58 success(3, `(object_with_callbacks).valueOf()`); |
| 59 |
| 23 // Test Array functions. | 60 // Test Array functions. |
| 24 var function_param = [ | 61 var function_param = [ |
| 25 "forEach", "every", "some", "reduce", "reduceRight", "find", "filter", | 62 "forEach", "every", "some", "reduce", "reduceRight", "find", "filter", |
| 26 "map", "findIndex" | 63 "map", "findIndex" |
| 27 ]; | 64 ]; |
| 28 var fails = ["toString", "join", "toLocaleString", "pop", "push", | 65 var fails = ["toString", "join", "toLocaleString", "pop", "push", |
| 29 "reverse", "shift", "unshift", "slice", "splice", "sort", "filter", | 66 "reverse", "shift", "unshift", "slice", "splice", "sort", "filter", |
| 30 "map", "copyWithin", "fill", "concat"]; | 67 "map", "copyWithin", "fill", "concat"]; |
| 31 for (f of Object.getOwnPropertyNames(Array.prototype)) { | 68 for (f of Object.getOwnPropertyNames(Array.prototype)) { |
| 32 if (typeof Array.prototype[f] === "function") { | 69 if (typeof Array.prototype[f] === "function") { |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 90 fail("'abcd'.toUpperCase()"); | 127 fail("'abcd'.toUpperCase()"); |
| 91 fail("'abCd'.toLocaleLowerCase()"); | 128 fail("'abCd'.toLocaleLowerCase()"); |
| 92 fail("'abcd'.toLocaleUpperCase()"); | 129 fail("'abcd'.toLocaleUpperCase()"); |
| 93 fail("'abcd'.match(/a/)"); | 130 fail("'abcd'.match(/a/)"); |
| 94 fail("'abcd'.replace(/a/)"); | 131 fail("'abcd'.replace(/a/)"); |
| 95 fail("'abcd'.search(/a/)"); | 132 fail("'abcd'.search(/a/)"); |
| 96 fail("'abcd'.split(/a/)"); | 133 fail("'abcd'.split(/a/)"); |
| 97 | 134 |
| 98 // Test JSON functions. | 135 // Test JSON functions. |
| 99 success('{"abc":[1,2]}', "JSON.stringify(JSON.parse('{\"abc\":[1,2]}'))"); | 136 success('{"abc":[1,2]}', "JSON.stringify(JSON.parse('{\"abc\":[1,2]}'))"); |
| 137 |
| 138 // Test Symbol functions. |
| 139 success(undefined, `Symbol("a")`); |
| 140 fail(`Symbol.for("a")`); // Symbol.for can be observed via Symbol.keyFor. |
| 141 success("a", `Symbol.keyFor(symbol_for_a)`); |
| 142 success("Symbol(a)", `symbol_for_a.valueOf().toString()`); |
| 143 success("Symbol(a)", `symbol_for_a[Symbol.toPrimitive]().toString()`); |
| 100 } catch (e) { | 144 } catch (e) { |
| 101 exception = e; | 145 exception = e; |
| 102 print(e, e.stack); | 146 print(e, e.stack); |
| 103 }; | 147 }; |
| 104 }; | 148 }; |
| 105 | 149 |
| 106 // Add the debug event listener. | 150 // Add the debug event listener. |
| 107 Debug.setListener(listener); | 151 Debug.setListener(listener); |
| 108 | 152 |
| 109 function f() { | 153 function f() { |
| 110 debugger; | 154 debugger; |
| 111 }; | 155 }; |
| 112 | 156 |
| 113 f(); | 157 f(); |
| 114 | 158 |
| 115 assertNull(exception); | 159 assertNull(exception); |
| OLD | NEW |