blob: 9a43ed95d0abf8348a10db833d45baf5f9fd61ee [file] [log] [blame]
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<script src="../../http/tests/inspector/resources/inspector-test.js"></script>
<script src="resources/remote-object-utilities.js"></script>
<script>
function test()
{
let steps = [
// Special:
// Null / undefined
{expression: `null`},
{expression: `undefined`},
// Symbol
{expression: `Symbol()`},
{expression: `Symbol("test")`},
// Primatives:
// Boolean
{expression: `true`},
{expression: `false`},
// Number
{expression: `0`},
{expression: `-0`},
{expression: `1`},
{expression: `-1`},
{expression: `1.234`},
{expression: `-1.234`},
{expression: `1e3`},
{expression: `Number.MAX_VALUE`},
{expression: `Number.MIN_VALUE`},
{expression: `NaN`},
{expression: `Infinity`},
{expression: `-Infinity`},
// Strings
{expression: `''`},
{expression: `'"'`}, // a single quoted string
{expression: `"'"`}, // a double quoted string
{expression: "`template`"}, // a template string
{expression: `"string"`},
{expression: `"Unicodeā€¦"`},
{expression: `"I wish I had something to put here."`},
// Function
{expression: `(function(){})`},
{expression: `function foo(){}; foo`},
{expression: `function myFunction(a, b) { console.log(a, b); }; myFunction`},
{expression: `function myTarget(a, b) { console.log(a, b); }; myTarget.bind(null)`}, // bound function
{expression: `Array.prototype.push`}, // native (ECMAScript)
{expression: `window.setTimeout`}, // native (DOM)
{expression: `Object.getOwnPropertyDescriptor({ get getter() { return 1 } }, "getter").get`}, // getter
{expression: `Object.getOwnPropertyDescriptor({ set setter(v) { console.log(v); } }, "setter").set`}, // setter
// Objects:
// Date
{expression: `new Date(99)`, browserOnly: true},
{expression: `new Date(1421903245871)`, browserOnly: true},
// Regexp
{expression: `/ /`},
{expression: `/(?:)/`},
{expression: `/^r(e)g[e]{1,}x+/`},
{expression: `/^r(e)g[e]{1,}x+/ig`},
{expression: `new RegExp("")`},
{expression: `new RegExp("test", "i")`},
// Array
{expression: `[]`},
{expression: `[0, -0, 1, 2]`},
{expression: `[[1],[2],[3]]`},
{expression: `[true, 1, 1.234, "string", /regex/]`},
{expression: `[[null]]`},
{expression: `[[undefined]]`},
{expression: `[{a:1}, {b:2}, {c:2}]`},
{expression: `[[{a:1}, {b:2}, {c:2}]]`},
{expression: `arr = []; arr[0] = arr; arr`}, // cyclic
{expression: `arr = []; arr.length = 100; arr`}, // 100 empty elements
{expression: `arr = []; arr.length = 100; arr.fill(1)`}, // 100 full elements
{expression: `arr = []; arr.length = 100; arr[10] = 1; arr`}, // sparse
// Array-like (Arguments, TypedArrays)
{expression: `a = null; (function() { a = arguments; })(1, "2", /3/); a`},
{expression: `new Int32Array(new ArrayBuffer(16))`},
{expression: `new Uint8ClampedArray(12)`},
{expression: `var intArray = new Int32Array(new ArrayBuffer(16)); for (var i = 0; i < intArray.length; ++i) intArray[i] = i; intArray`},
{expression: `var buffer = new ArrayBuffer(10000000); var int8View = new Int8Array(buffer); int8View`}, // 10000000 elements.
// Object
{expression: `({})`},
{expression: `({a: 1})`},
{expression: `({a: 1, b: 0, c: -0})`},
{expression: `({a: 1, b: \"string\", c: /regex/, d: Symbol("sym")})`},
{expression: `o = {a:1}; o.b = o; o`}, // cyclic
{expression: `({a:function a(){}, b:function b(){}, get getter(){}, set setter(v){}})`},
{expression: `function Foo() {}; new Foo`},
{expression: `var Foo2 = function() {}; new Foo2`},
{expression: `var namespace = {}; namespace.Foo3 = function() {}; new namespace.Foo3`},
{expression: `function Bar() { this._x = 5 }; Bar.prototype = {constructor: Bar, get x() {return this._x;}}; new Bar`},
{expression: `function Bar2() { this._x = 5 }; Bar.prototype = {get x() {return this._x;}}; new Bar2`},
{expression: `new ArrayBuffer(16)`},
{expression: `new DataView(new ArrayBuffer(16))`},
{expression: `obj = {}; obj["prop"] = 1; obj[Symbol()] = 2; obj[Symbol("sym")] = 3; obj[Symbol("sym")] = 4; obj[Symbol.iterator] = Symbol(); obj`}, // Symbol properties
// Error
{expression: `error = null; try { [].x.x; } catch (e) { error = e; }; error`},
{expression: `error = null; try { eval("if()"); } catch (e) { error = e; }; error`},
{expression: `error = null; try { document.createTextNode("").splitText(100); } catch (e) { error = e; }; error`},
// Map / WeakMap
{expression: `new Map`},
{expression: `map = new Map; map.set(1, 2); map.set("key", "value"); map`},
{expression: `map = new Map; map.set({a:1}, {b:2}); map.set(document.body, [1,2]); map`},
{expression: `map = new Map; for (var i = 0; i <= 100; i++) map.set(i, i); map`},
{expression: `map = new Map; map.set(map, map); map`},
{expression: `map = new WeakMap; strongKey = {id:1}; map.set(strongKey, [1,2]); map`},
// Set / WeakSet
{expression: `new Set`},
{expression: `set = new Set; set.add(1); set.add(2); set.add("key"); set`},
{expression: `set = new Set; set.add({a:1}); set.add(document.body); set.add([1,2]); set`},
{expression: `set = new Set; for (var i = 0; i <= 100; i++) set.add(i); set`},
{expression: `set = new Set; set.add(set); set`},
{expression: `set = new WeakSet; strongKey = {id:1}; set.add(strongKey); set`},
// Iterators
{expression: `"a"[Symbol.iterator]()`},
{expression: `"long string"[Symbol.iterator]()`},
{expression: `[][Symbol.iterator]()`},
{expression: `[1][Symbol.iterator]()`},
{expression: `[1, "two", 3, "four", 5, "size"][Symbol.iterator]()`},
{expression: `[1, "two", 3, "four", 5, "size"].keys()`},
{expression: `[1, "two", 3, "four", 5, "size"].entries()`},
{expression: `map = new Map; map.set(1, 2); map.set("key", "value"); map.values()`},
{expression: `map.keys()`},
{expression: `map.entries()`},
{expression: `set = new Set; for (var i = 0; i <= 100; i++) set.add(i); set.values()`},
{expression: `map.entries()`},
{expression: `x = undefined; (function() { x = arguments; })(1, "two"); x[Symbol.iterator]()`},
{expression: `iter = [1, 2][Symbol.iterator](); iter["return"] = function(){}; iter`},
// Promise
{expression: `new Promise(function(){})`},
{expression: `Promise.reject()`},
{expression: `Promise.reject("result")`},
{expression: `Promise.resolve()`},
{expression: `Promise.resolve({result:1})`},
// Proxy
{expression: `new Proxy({x:1, y:1}, {handler: true})`},
{expression: `new Proxy(new Proxy({foo:1, bar:1}, {}), {})`},
// Classes
{expression: `Person = class Person { constructor(name){} get fullName(){} methodName(p1, p2){} }; Person`}, // Constructor => class type
{expression: `Person.prototype.methodName`}, // Method => just a function type
{expression: `new Person`}, // Instance, not lossless, it's prototype may have interesting methods to show
{expression: `Alpha = class A { methodA(){} }; Beta = class B extends Alpha { methodB(){} }; Beta`},
{expression: `[Beta]`},
// Improveable:
// Sealed / Frozen objects.
{expression: `Object.seal({})`},
{expression: `Object.freeze({})`},
];
if (!window.WI) {
window.steps = steps;
return;
}
runSteps(steps);
}
</script>
</head>
<body onload="runTest(); runInBrowserTest();"></body>
</html>