Commit 825dd8a9 authored by yangguo's avatar yangguo Committed by Commit bot

[debug-wrappers] remove mirror tests.

Debug mirrors will no longer be supported in the near future.
It will now only be tested by being used by the v8-inspector.

R=jgruber@chromium.org
BUG=v8:5530

Review-Url: https://codereview.chromium.org/2566103002
Cr-Commit-Position: refs/heads/master@{#41686}
parent 5f874d4f
// Copyright 2014 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: --expose-debug-as debug
var handle1 = debug.MakeMirror(123).handle();
assertEquals("number", debug.LookupMirror(handle1).type());
debug.ToggleMirrorCache(false);
var handle2 = debug.MakeMirror(123).handle();
assertEquals(undefined, handle2);
assertThrows(function() { debug.LookupMirror(handle2) });
debug.ToggleMirrorCache(true);
var handle3 = debug.MakeMirror(123).handle();
assertEquals("number", debug.LookupMirror(handle3).type());
// Copyright 2014 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-debug-as debug
// Test the mirror object for functions.
function *generator(f) {
"use strict";
yield;
f();
yield;
}
function MirrorRefCache(json_refs) {
var tmp = eval('(' + json_refs + ')');
this.refs_ = [];
for (var i = 0; i < tmp.length; i++) {
this.refs_[tmp[i].handle] = tmp[i];
}
}
MirrorRefCache.prototype.lookup = function(handle) {
return this.refs_[handle];
}
function TestGeneratorMirror(g, status, line, column, receiver) {
// Create mirror and JSON representation.
var mirror = debug.MakeMirror(g);
var serializer = debug.MakeMirrorSerializer();
var json = JSON.stringify(serializer.serializeValue(mirror));
var refs = new MirrorRefCache(
JSON.stringify(serializer.serializeReferencedObjects()));
// Check the mirror hierachy.
assertTrue(mirror instanceof debug.Mirror);
assertTrue(mirror instanceof debug.ValueMirror);
assertTrue(mirror instanceof debug.ObjectMirror);
assertTrue(mirror instanceof debug.GeneratorMirror);
// Check the mirror properties.
assertTrue(mirror.isGenerator());
assertEquals('generator', mirror.type());
assertFalse(mirror.isPrimitive());
assertEquals('Generator', mirror.className());
assertEquals(receiver, mirror.receiver().value());
assertEquals(generator, mirror.func().value());
assertEquals(status, mirror.status());
// Note that line numbers are 0-based, not 1-based.
var loc = mirror.sourceLocation();
if (status === 'suspended') {
assertTrue(!!loc);
assertEquals(line, loc.line);
assertEquals(column, loc.column);
} else {
assertEquals(undefined, loc);
}
TestInternalProperties(mirror, status, receiver);
}
function TestInternalProperties(mirror, status, receiver) {
var properties = mirror.internalProperties();
assertEquals(3, properties.length);
assertEquals("[[GeneratorStatus]]", properties[0].name());
assertEquals(status, properties[0].value().value());
assertEquals("[[GeneratorFunction]]", properties[1].name());
assertEquals(generator, properties[1].value().value());
assertEquals("[[GeneratorReceiver]]", properties[2].name());
assertEquals(receiver, properties[2].value().value());
}
var iter = generator(function() {
var mirror = debug.MakeMirror(iter);
assertEquals('running', mirror.status());
assertEquals(undefined, mirror.sourceLocation());
TestInternalProperties(mirror, 'running');
});
TestGeneratorMirror(iter, 'suspended', 7, 19);
iter.next();
TestGeneratorMirror(iter, 'suspended', 9, 2);
iter.next();
TestGeneratorMirror(iter, 'suspended', 11, 2);
iter.next();
TestGeneratorMirror(iter, 'closed');
// Test generator with receiver.
var obj = {foo: 42};
var iter2 = generator.call(obj, function() {
var mirror = debug.MakeMirror(iter2);
assertEquals('running', mirror.status());
assertEquals(undefined, mirror.sourceLocation());
TestInternalProperties(mirror, 'running', obj);
});
TestGeneratorMirror(iter2, 'suspended', 7, 19, obj);
iter2.next();
TestGeneratorMirror(iter2, 'suspended', 9, 2, obj);
iter2.next();
TestGeneratorMirror(iter2, 'suspended', 11, 2, obj);
iter2.next();
TestGeneratorMirror(iter2, 'closed', 0, 0, obj);
// Copyright 2014 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-debug-as debug --expose-gc
function testMapMirror(mirror) {
// Create JSON representation.
var serializer = debug.MakeMirrorSerializer();
var json = JSON.stringify(serializer.serializeValue(mirror));
// Check the mirror hierachy.
assertTrue(mirror instanceof debug.Mirror);
assertTrue(mirror instanceof debug.ValueMirror);
assertTrue(mirror instanceof debug.ObjectMirror);
assertTrue(mirror instanceof debug.MapMirror);
assertTrue(mirror.isMap());
// Parse JSON representation and check.
var fromJSON = eval('(' + json + ')');
assertEquals('map', fromJSON.type);
}
function testSetMirror(mirror) {
// Create JSON representation.
var serializer = debug.MakeMirrorSerializer();
var json = JSON.stringify(serializer.serializeValue(mirror));
// Check the mirror hierachy.
assertTrue(mirror instanceof debug.Mirror);
assertTrue(mirror instanceof debug.ValueMirror);
assertTrue(mirror instanceof debug.ObjectMirror);
assertTrue(mirror instanceof debug.SetMirror);
assertTrue(mirror.isSet());
// Parse JSON representation and check.
var fromJSON = eval('(' + json + ')');
assertEquals('set', fromJSON.type);
}
var o1 = new Object();
var o2 = new Object();
var o3 = new Object();
// Test the mirror object for Maps
var map = new Map();
map.set(o1, 11);
map.set(o2, 22);
map.delete(o1);
var mapMirror = debug.MakeMirror(map);
testMapMirror(mapMirror);
var entries = mapMirror.entries();
assertEquals(1, entries.length);
assertSame(o2, entries[0].key);
assertEquals(22, entries[0].value);
map.set(o1, 33);
map.set(o3, o2);
map.delete(o2);
map.set(undefined, 44);
entries = mapMirror.entries();
assertEquals(3, entries.length);
assertSame(o1, entries[0].key);
assertEquals(33, entries[0].value);
assertSame(o3, entries[1].key);
assertSame(o2, entries[1].value);
assertEquals(undefined, entries[2].key);
assertEquals(44, entries[2].value);
assertEquals(3, mapMirror.entries(0).length);
assertEquals(1, mapMirror.entries(1).length);
assertEquals(2, mapMirror.entries(2).length);
// Test the mirror object for Sets
var set = new Set();
set.add(o1);
set.add(o2);
set.delete(o1);
set.add(undefined);
var setMirror = debug.MakeMirror(set);
testSetMirror(setMirror);
var values = setMirror.values();
assertEquals(2, values.length);
assertEquals(1, setMirror.values(1).length);
assertSame(o2, values[0]);
assertEquals(undefined, values[1]);
function initWeakMap(weakMap) {
weakMap.set(o1, 11);
weakMap.set(new Object(), 22);
weakMap.set(o3, 33);
weakMap.set(new Object(), 44);
var weakMapMirror = debug.MakeMirror(weakMap);
testMapMirror(weakMapMirror);
weakMap.set(new Object(), 55);
assertTrue(weakMapMirror.entries().length <= 5);
return weakMapMirror;
}
// Test the mirror object for WeakMaps
var weakMap = new WeakMap();
var weakMapMirror = initWeakMap(weakMap);
gc();
function testWeakMapEntries(weakMapMirror) {
var entries = weakMapMirror.entries();
assertEquals(2, entries.length);
assertEquals(2, weakMapMirror.entries(0).length);
assertEquals(1, weakMapMirror.entries(1).length);
var found = 0;
for (var i = 0; i < entries.length; i++) {
if (Object.is(entries[i].key, o1)) {
assertEquals(11, entries[i].value);
found++;
}
if (Object.is(entries[i].key, o3)) {
assertEquals(33, entries[i].value);
found++;
}
}
assertEquals(2, found);
}
testWeakMapEntries(weakMapMirror);
function initWeakSet(weakSet) {
weakSet.add(o1);
weakSet.add(new Object());
weakSet.add(o2);
weakSet.add(new Object());
weakSet.add(new Object());
weakSet.add(o3);
weakSet.delete(o2);
var weakSetMirror = debug.MakeMirror(weakSet);
testSetMirror(weakSetMirror);
assertTrue(weakSetMirror.values().length <= 5);
return weakSetMirror;
}
// Test the mirror object for WeakSets
var weakSet = new WeakSet();
var weakSetMirror = initWeakSet(weakSet);
gc();
function testWeakSetValues(weakSetMirror) {
var values = weakSetMirror.values();
assertEquals(2, values.length);
assertEquals(2, weakSetMirror.values(0).length);
assertEquals(1, weakSetMirror.values(1).length);
var found = 0;
for (var i = 0; i < values.length; i++) {
if (Object.is(values[i], o1)) {
found++;
}
if (Object.is(values[i], o3)) {
found++;
}
}
assertEquals(2, found);
}
testWeakSetValues(weakSetMirror);
// Copyright 2014 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-debug-as debug
// Test the mirror object for collection iterators.
function testIteratorMirror(iter, offset, expected, opt_limit) {
while (offset-- > 0) iter.next();
var mirror = debug.MakeMirror(iter);
assertTrue(mirror.isIterator());
var preview = mirror.preview(opt_limit);
assertArrayEquals(expected, preview);
// Check that iterator has not changed after taking preview.
var values = [];
for (var i of iter) {
if (opt_limit && values.length >= opt_limit) break;
values.push(i);
}
assertArrayEquals(expected, values);
}
function testIteratorInternalProperties(iter, offset, kind, index, has_more) {
while (offset-- > 0) iter.next();
var mirror = debug.MakeMirror(iter);
assertTrue(mirror.isIterator());
var properties = mirror.internalProperties();
assertEquals(3, properties.length);
assertEquals("[[IteratorHasMore]]", properties[0].name());
assertEquals(has_more, properties[0].value().value());
assertEquals("[[IteratorIndex]]", properties[1].name());
assertEquals(index, properties[1].value().value());
assertEquals("[[IteratorKind]]", properties[2].name());
assertEquals(kind, properties[2].value().value());
}
var o1 = { foo: 1 };
var o2 = { foo: 2 };
var map = new Map();
map.set(41, 42);
map.set(o1, o2);
testIteratorMirror(map.keys(), 0, [41, o1]);
testIteratorMirror(map.values(), 0, [42, o2]);
testIteratorMirror(map.entries(), 0, [[41, 42], [o1, o2]]);
testIteratorMirror(map.keys(), 1, [o1]);
testIteratorMirror(map.values(), 1, [o2]);
testIteratorMirror(map.entries(), 1, [[o1, o2]]);
testIteratorMirror(map.keys(), 2, []);
testIteratorMirror(map.values(), 2, []);
testIteratorMirror(map.entries(), 2, []);
// Test with maximum limit.
testIteratorMirror(map.keys(), 0, [41], 1);
testIteratorMirror(map.values(), 0, [42], 1);
testIteratorMirror(map.entries(), 0, [[41, 42]], 1);
testIteratorInternalProperties(map.keys(), 0, "keys", 0, true);
testIteratorInternalProperties(map.values(), 1, "values", 1, true);
testIteratorInternalProperties(map.entries(), 2, "entries", 2, false);
testIteratorInternalProperties(map.keys(), 3, "keys", 2, false);
var set = new Set();
set.add(41);
set.add(42);
set.add(o1);
set.add(o2);
testIteratorMirror(set.keys(), 0, [41, 42, o1, o2]);
testIteratorMirror(set.values(), 0, [41, 42, o1, o2]);
testIteratorMirror(set.entries(), 0, [[41, 41], [42, 42], [o1, o1], [o2, o2]]);
testIteratorMirror(set.keys(), 1, [42, o1, o2]);
testIteratorMirror(set.values(), 1, [42, o1, o2]);
testIteratorMirror(set.entries(), 1, [[42, 42], [o1, o1], [o2, o2]]);
testIteratorMirror(set.keys(), 3, [o2]);
testIteratorMirror(set.values(), 3, [o2]);
testIteratorMirror(set.entries(), 3, [[o2, o2]]);
testIteratorMirror(set.keys(), 5, []);
testIteratorMirror(set.values(), 5, []);
testIteratorMirror(set.entries(), 5, []);
// Test with maximum limit.
testIteratorMirror(set.keys(), 1, [42, o1], 2);
testIteratorMirror(set.values(), 1, [42, o1], 2);
testIteratorMirror(set.entries(), 1, [[42, 42], [o1, o1]], 2);
testIteratorInternalProperties(set.keys(), 0, "values", 0, true);
testIteratorInternalProperties(set.values(), 1, "values", 1, true);
testIteratorInternalProperties(set.entries(), 2, "entries", 2, true);
testIteratorInternalProperties(set.keys(), 3, "values", 3, true);
testIteratorInternalProperties(set.values(), 4, "values", 4, false);
testIteratorInternalProperties(set.entries(), 5, "entries", 4, false);
// Copyright 2014 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-debug-as debug
// Test the mirror object for promises.
function MirrorRefCache(json_refs) {
var tmp = eval('(' + json_refs + ')');
this.refs_ = [];
for (var i = 0; i < tmp.length; i++) {
this.refs_[tmp[i].handle] = tmp[i];
}
}
MirrorRefCache.prototype.lookup = function(handle) {
return this.refs_[handle];
}
function testPromiseMirror(promise, status, value) {
// Create mirror and JSON representation.
var mirror = debug.MakeMirror(promise);
var serializer = debug.MakeMirrorSerializer();
var json = JSON.stringify(serializer.serializeValue(mirror));
var refs = new MirrorRefCache(
JSON.stringify(serializer.serializeReferencedObjects()));
// Check the mirror hierachy.
assertTrue(mirror instanceof debug.Mirror);
assertTrue(mirror instanceof debug.ValueMirror);
assertTrue(mirror instanceof debug.ObjectMirror);
assertTrue(mirror instanceof debug.PromiseMirror);
// Check the mirror properties.
assertEquals(status, mirror.status());
assertTrue(mirror.isPromise());
assertEquals('promise', mirror.type());
assertFalse(mirror.isPrimitive());
assertEquals("Object", mirror.className());
assertEquals("#<Promise>", mirror.toText());
assertSame(promise, mirror.value());
assertTrue(mirror.promiseValue() instanceof debug.Mirror);
assertEquals(value, mirror.promiseValue().value());
// Parse JSON representation and check.
var fromJSON = eval('(' + json + ')');
assertEquals('promise', fromJSON.type);
assertEquals('Object', fromJSON.className);
assertEquals('function', refs.lookup(fromJSON.constructorFunction.ref).type);
assertEquals('Promise', refs.lookup(fromJSON.constructorFunction.ref).name);
assertEquals(status, fromJSON.status);
assertEquals(value, refs.lookup(fromJSON.promiseValue.ref).value);
}
// Test a number of different promises.
var resolved = new Promise(function(resolve, reject) { resolve() });
var rejected = new Promise(function(resolve, reject) { reject() });
var pending = new Promise(function(resolve, reject) {});
testPromiseMirror(resolved, "resolved", undefined);
testPromiseMirror(rejected, "rejected", undefined);
testPromiseMirror(pending, "pending", undefined);
var resolvedv = new Promise(function(resolve, reject) { resolve('resolve') });
var rejectedv = new Promise(function(resolve, reject) { reject('reject') });
var thrownv = new Promise(function(resolve, reject) { throw 'throw' });
testPromiseMirror(resolvedv, "resolved", 'resolve');
testPromiseMirror(rejectedv, "rejected", 'reject');
testPromiseMirror(thrownv, "rejected", 'throw');
// Test internal properties of different promises.
var m1 = debug.MakeMirror(new Promise(
function(resolve, reject) { resolve(1) }));
var ip = m1.internalProperties();
assertEquals(2, ip.length);
assertEquals("[[PromiseStatus]]", ip[0].name());
assertEquals("[[PromiseValue]]", ip[1].name());
assertEquals("resolved", ip[0].value().value());
assertEquals(1, ip[1].value().value());
var m2 = debug.MakeMirror(new Promise(function(resolve, reject) { reject(2) }));
ip = m2.internalProperties();
assertEquals("rejected", ip[0].value().value());
assertEquals(2, ip[1].value().value());
var m3 = debug.MakeMirror(new Promise(function(resolve, reject) { }));
ip = m3.internalProperties();
assertEquals("pending", ip[0].value().value());
assertEquals("undefined", typeof(ip[1].value().value()));
// Copyright 2014 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-debug-as debug
// Test the mirror object for symbols.
function testSymbolMirror(symbol, description) {
// Create mirror and JSON representation.
var mirror = debug.MakeMirror(symbol);
var serializer = debug.MakeMirrorSerializer();
var json = JSON.stringify(serializer.serializeValue(mirror));
// Check the mirror hierachy.
assertTrue(mirror instanceof debug.Mirror);
assertTrue(mirror instanceof debug.ValueMirror);
assertTrue(mirror instanceof debug.SymbolMirror);
// Check the mirror properties.
assertTrue(mirror.isSymbol());
assertEquals(description, mirror.description());
assertEquals('symbol', mirror.type());
assertTrue(mirror.isPrimitive());
var description_text = description === undefined ? "" : description;
assertEquals('Symbol(' + description_text + ')', mirror.toText());
assertSame(symbol, mirror.value());
// Parse JSON representation and check.
var fromJSON = eval('(' + json + ')');
assertEquals('symbol', fromJSON.type);
assertEquals(description, fromJSON.description);
}
// Test a number of different symbols.
testSymbolMirror(Symbol("a"), "a");
testSymbolMirror(Symbol(12), "12");
testSymbolMirror(Symbol.for("b"), "b");
testSymbolMirror(Symbol(), undefined);
// Copyright 2016 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-debug-as debug --harmony-async-await --allow-natives-syntax
// Test the mirror object for promises.
var AsyncFunction = (async function() {}).constructor;
function MirrorRefCache(json_refs) {
var tmp = eval('(' + json_refs + ')');
this.refs_ = [];
for (var i = 0; i < tmp.length; i++) {
this.refs_[tmp[i].handle] = tmp[i];
}
}
MirrorRefCache.prototype.lookup = function(handle) {
return this.refs_[handle];
}
function testPromiseMirror(promise, status, value) {
// Create mirror and JSON representation.
var mirror = debug.MakeMirror(promise);
var serializer = debug.MakeMirrorSerializer();
var json = JSON.stringify(serializer.serializeValue(mirror));
var refs = new MirrorRefCache(
JSON.stringify(serializer.serializeReferencedObjects()));
// Check the mirror hierachy.
assertTrue(mirror instanceof debug.Mirror);
assertTrue(mirror instanceof debug.ValueMirror);
assertTrue(mirror instanceof debug.ObjectMirror);
assertTrue(mirror instanceof debug.PromiseMirror);
// Check the mirror properties.
assertEquals(status, mirror.status());
assertTrue(mirror.isPromise());
assertEquals('promise', mirror.type());
assertFalse(mirror.isPrimitive());
assertEquals("Object", mirror.className());
assertEquals("#<Promise>", mirror.toText());
assertSame(promise, mirror.value());
assertTrue(mirror.promiseValue() instanceof debug.Mirror);
assertEquals(value, mirror.promiseValue().value());
// Parse JSON representation and check.
var fromJSON = eval('(' + json + ')');
assertEquals('promise', fromJSON.type);
assertEquals('Object', fromJSON.className);
assertEquals('function', refs.lookup(fromJSON.constructorFunction.ref).type);
assertEquals('Promise', refs.lookup(fromJSON.constructorFunction.ref).name);
assertEquals(status, fromJSON.status);
assertEquals(value, refs.lookup(fromJSON.promiseValue.ref).value);
}
// Test a number of different promises.
var resolved = (async function() {})();
var rejected = (async function() { throw undefined; })();
var pending = (async function() { await 1; })();
testPromiseMirror(resolved, "resolved", undefined);
testPromiseMirror(rejected, "rejected", undefined);
testPromiseMirror(pending, "pending", undefined);
var resolvedv = (async function() { return "resolve"; })();
var rejectedv = (async function() { return Promise.reject("reject"); })();
var thrownv = (async function() { throw "throw"; })();
testPromiseMirror(resolvedv, "resolved", 'resolve');
testPromiseMirror(rejectedv, "rejected", 'reject');
testPromiseMirror(thrownv, "rejected", 'throw');
// Test internal properties of different promises.
var m1 = debug.MakeMirror((async function() { return 1; })());
var ip = m1.internalProperties();
assertEquals(2, ip.length);
assertEquals("[[PromiseStatus]]", ip[0].name());
assertEquals("[[PromiseValue]]", ip[1].name());
assertEquals("resolved", ip[0].value().value());
assertEquals(1, ip[1].value().value());
var m2 = debug.MakeMirror((async function() { throw 2; })());
ip = m2.internalProperties();
assertEquals("rejected", ip[0].value().value());
assertEquals(2, ip[1].value().value());
var m3 = debug.MakeMirror((async function() { await 1; })());
ip = m3.internalProperties();
assertEquals("pending", ip[0].value().value());
assertEquals("undefined", typeof(ip[1].value().value()));
%RunMicrotasks();
// Copyright 2016 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-debug-as debug --harmony-async-await --allow-natives-syntax
// Test the mirror object for functions.
var AsyncFunction = (async function() {}).constructor;
function MirrorRefCache(json_refs) {
var tmp = eval('(' + json_refs + ')');
this.refs_ = [];
for (var i = 0; i < tmp.length; i++) {
this.refs_[tmp[i].handle] = tmp[i];
}
}
MirrorRefCache.prototype.lookup = function(handle) {
return this.refs_[handle];
}
function testFunctionMirror(f) {
// Create mirror and JSON representation.
var mirror = debug.MakeMirror(f);
var serializer = debug.MakeMirrorSerializer();
var json = JSON.stringify(serializer.serializeValue(mirror));
var refs = new MirrorRefCache(
JSON.stringify(serializer.serializeReferencedObjects()));
// Check the mirror hierachy.
assertTrue(mirror instanceof debug.Mirror);
assertTrue(mirror instanceof debug.ValueMirror);
assertTrue(mirror instanceof debug.ObjectMirror);
assertTrue(mirror instanceof debug.FunctionMirror);
// Check the mirror properties.
assertTrue(mirror.isFunction());
assertEquals('function', mirror.type());
assertFalse(mirror.isPrimitive());
assertEquals("Function", mirror.className());
assertEquals(f.name, mirror.name());
assertTrue(mirror.resolved());
assertEquals(f.toString(), mirror.source());
assertTrue(mirror.constructorFunction() instanceof debug.ObjectMirror);
assertTrue(mirror.protoObject() instanceof debug.Mirror);
assertTrue(mirror.prototypeObject() instanceof debug.Mirror);
// Test text representation
assertEquals(f.toString(), mirror.toText());
// Parse JSON representation and check.
var fromJSON = eval('(' + json + ')');
assertEquals('function', fromJSON.type);
assertEquals('Function', fromJSON.className);
assertEquals('function', refs.lookup(fromJSON.constructorFunction.ref).type);
assertEquals('AsyncFunction',
refs.lookup(fromJSON.constructorFunction.ref).name);
assertTrue(fromJSON.resolved);
assertEquals(f.name, fromJSON.name);
assertEquals(f.toString(), fromJSON.source);
// Check the formatted text (regress 1142074).
assertEquals(f.toString(), fromJSON.text);
}
// Test a number of different functions.
testFunctionMirror(async function(){});
testFunctionMirror(AsyncFunction());
testFunctionMirror(new AsyncFunction());
testFunctionMirror(async() => {});
testFunctionMirror(async function a(){return 1;});
testFunctionMirror(({ async foo() {} }).foo);
testFunctionMirror((async function(){}).bind({}), "Object");
%RunMicrotasks();
// Copyright 2008 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: --expose-debug-as debug
// Test the mirror object for objects
function MirrorRefCache(json_refs) {
var tmp = eval('(' + json_refs + ')');
this.refs_ = [];
for (var i = 0; i < tmp.length; i++) {
this.refs_[tmp[i].handle] = tmp[i];
}
}
MirrorRefCache.prototype.lookup = function(handle) {
return this.refs_[handle];
}
function testArrayMirror(a, names) {
// Create mirror and JSON representation.
var mirror = debug.MakeMirror(a);
var serializer = debug.MakeMirrorSerializer();
var json = JSON.stringify(serializer.serializeValue(mirror));
var refs = new MirrorRefCache(
JSON.stringify(serializer.serializeReferencedObjects()));
// Check the mirror hierachy.
assertTrue(mirror instanceof debug.Mirror, 'Unexpected mirror hierachy');
assertTrue(mirror instanceof debug.ValueMirror, 'Unexpected mirror hierachy');
assertTrue(mirror instanceof debug.ObjectMirror, 'Unexpected mirror hierachy');
assertTrue(mirror instanceof debug.ArrayMirror, 'Unexpected mirror hierachy');
// Check the mirror properties.
assertTrue(mirror.isArray(), 'Unexpected mirror');
assertEquals('object', mirror.type(), 'Unexpected mirror type');
assertFalse(mirror.isPrimitive(), 'Unexpected primitive mirror');
assertEquals('Array', mirror.className(), 'Unexpected mirror class name');
assertTrue(mirror.constructorFunction() instanceof debug.ObjectMirror, 'Unexpected mirror hierachy');
assertEquals('Array', mirror.constructorFunction().name(), 'Unexpected constructor function name');
assertTrue(mirror.protoObject() instanceof debug.Mirror, 'Unexpected mirror hierachy');
assertTrue(mirror.prototypeObject() instanceof debug.Mirror, 'Unexpected mirror hierachy');
assertEquals(mirror.length(), a.length, "Length mismatch");
var indexedProperties = mirror.indexedPropertiesFromRange();
assertEquals(indexedProperties.length, a.length);
for (var i = 0; i < indexedProperties.length; i++) {
assertTrue(indexedProperties[i] instanceof debug.Mirror, 'Unexpected mirror hierachy');
assertTrue(indexedProperties[i] instanceof debug.PropertyMirror, 'Unexpected mirror hierachy');
}
// Parse JSON representation and check.
var fromJSON = eval('(' + json + ')');
assertEquals('object', fromJSON.type, 'Unexpected mirror type in JSON');
assertEquals('Array', fromJSON.className, 'Unexpected mirror class name in JSON');
assertEquals(mirror.constructorFunction().handle(), fromJSON.constructorFunction.ref, 'Unexpected constructor function handle in JSON');
assertEquals('function', refs.lookup(fromJSON.constructorFunction.ref).type, 'Unexpected constructor function type in JSON');
assertEquals('Array', refs.lookup(fromJSON.constructorFunction.ref).name, 'Unexpected constructor function name in JSON');
assertEquals(void 0, fromJSON.namedInterceptor, 'No named interceptor expected in JSON');
assertEquals(void 0, fromJSON.indexedInterceptor, 'No indexed interceptor expected in JSON');
// Check that the serialization contains all indexed properties and the length property.
var length_found = false;
for (var i = 0; i < fromJSON.properties.length; i++) {
if (fromJSON.properties[i].name == 'length') {
length_found = true;
assertEquals('number', refs.lookup(fromJSON.properties[i].ref).type, "Unexpected type of the length property");
assertEquals(a.length, refs.lookup(fromJSON.properties[i].ref).value, "Length mismatch in parsed JSON");
} else {
var index = parseInt(fromJSON.properties[i].name);
print(index);
if (!isNaN(index)) {
print(index);
// This test assumes that the order of the indexeed properties is in the
// same order in the serialization as returned from
// indexedPropertiesFromRange()
assertEquals(indexedProperties[index].name(), index);
assertEquals(indexedProperties[index].value().type(), refs.lookup(fromJSON.properties[i].ref).type, 'Unexpected serialized type');
}
}
}
assertTrue(length_found, 'Property length not found');
// Check that the serialization contains all names properties.
if (names) {
for (var i = 0; i < names.length; i++) {
var found = false;
for (var j = 0; j < fromJSON.properties.length; j++) {
if (names[i] == fromJSON.properties[j].name) {
found = true;
}
}
assertTrue(found, names[i])
}
}
}
// Test a number of different arrays.
testArrayMirror([]);
testArrayMirror([1]);
testArrayMirror([1,2]);
testArrayMirror(["a", function(){}, [1,2], 2, /[ab]/]);
a=[1];
a[100]=7;
testArrayMirror(a);
a=[1,2,3];
a.x=2.2;
a.y=function(){return null;}
testArrayMirror(a, ['x','y']);
var a = []; a.push(a);
testArrayMirror(a);
// Copyright 2008 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: --expose-debug-as debug
// Test the mirror object for boolean values
function testBooleanMirror(b) {
// Create mirror and JSON representation.
var mirror = debug.MakeMirror(b);
var serializer = debug.MakeMirrorSerializer();
var json = JSON.stringify(serializer.serializeValue(mirror));
// Check the mirror hierachy.
assertTrue(mirror instanceof debug.Mirror);
assertTrue(mirror instanceof debug.ValueMirror);
assertTrue(mirror instanceof debug.BooleanMirror);
// Check the mirror properties.
assertTrue(mirror.isBoolean());
assertEquals('boolean', mirror.type());
assertTrue(mirror.isPrimitive());
// Test text representation
assertEquals(b ? 'true' : 'false', mirror.toText());
// Parse JSON representation and check.
var fromJSON = eval('(' + json + ')');
assertEquals('boolean', fromJSON.type, json);
assertEquals(b, fromJSON.value, json);
}
// Test all boolean values.
testBooleanMirror(true);
testBooleanMirror(false);
// Copyright 2008 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: --expose-debug-as debug
// Test the mirror object for boolean values
function testDateMirror(d, iso8601) {
// Create mirror and JSON representation.
var mirror = debug.MakeMirror(d);
var serializer = debug.MakeMirrorSerializer();
var json = JSON.stringify(serializer.serializeValue(mirror));
// Check the mirror hierachy.
assertTrue(mirror instanceof debug.Mirror);
assertTrue(mirror instanceof debug.ValueMirror);
assertTrue(mirror instanceof debug.ObjectMirror);
assertTrue(mirror instanceof debug.DateMirror);
// Check the mirror properties.
assertTrue(mirror.isDate());
assertEquals('object', mirror.type());
assertFalse(mirror.isPrimitive());
// Test text representation
assertEquals(iso8601, mirror.toText());
// Parse JSON representation and check.
var fromJSON = eval('(' + json + ')');
assertEquals('object', fromJSON.type);
assertEquals('Date', fromJSON.className);
assertEquals(iso8601, fromJSON.value);
}
// Test Date values.
testDateMirror(new Date(Date.parse("Dec 25, 1995 1:30 UTC")),
"1995-12-25T01:30:00.000Z");
d = new Date();
d.setUTCFullYear(1967);
d.setUTCMonth(0); // January.
d.setUTCDate(17);
d.setUTCHours(9);
d.setUTCMinutes(22);
d.setUTCSeconds(59);
d.setUTCMilliseconds(0);
testDateMirror(d, "1967-01-17T09:22:59.000Z");
d.setUTCMilliseconds(1);
testDateMirror(d, "1967-01-17T09:22:59.001Z");
d.setUTCSeconds(12);
testDateMirror(d, "1967-01-17T09:22:12.001Z");
d.setUTCSeconds(36);
testDateMirror(d, "1967-01-17T09:22:36.001Z");
d.setUTCMilliseconds(136);
testDateMirror(d, "1967-01-17T09:22:36.136Z");
// Copyright 2008 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: --expose-debug-as debug
// Test the mirror object for regular error objects
function MirrorRefCache(json_refs) {
var tmp = eval('(' + json_refs + ')');
this.refs_ = [];
for (var i = 0; i < tmp.length; i++) {
this.refs_[tmp[i].handle] = tmp[i];
}
}
MirrorRefCache.prototype.lookup = function(handle) {
return this.refs_[handle];
}
function testErrorMirror(e) {
// Create mirror and JSON representation.
var mirror = debug.MakeMirror(e);
var serializer = debug.MakeMirrorSerializer();
var json = JSON.stringify(serializer.serializeValue(mirror));
var refs = new MirrorRefCache(
JSON.stringify(serializer.serializeReferencedObjects()));
// Check the mirror hierachy.
assertTrue(mirror instanceof debug.Mirror);
assertTrue(mirror instanceof debug.ValueMirror);
assertTrue(mirror instanceof debug.ObjectMirror);
assertTrue(mirror instanceof debug.ErrorMirror);
// Check the mirror properties.
assertTrue(mirror.isError());
assertEquals('error', mirror.type());
assertFalse(mirror.isPrimitive());
assertEquals(mirror.message(), e.message, 'source');
// Parse JSON representation and check.
var fromJSON = eval('(' + json + ')');
assertEquals('error', fromJSON.type);
assertEquals('Error', fromJSON.className);
if (e.message) {
var found_message = false;
for (var i in fromJSON.properties) {
var p = fromJSON.properties[i];
print(p.name);
if (p.name == 'message') {
assertEquals(e.message, refs.lookup(p.ref).value);
found_message = true;
}
}
assertTrue(found_message, 'Property message not found');
}
// Check the formatted text (regress 1231579).
assertEquals(fromJSON.text, e.toString(), 'toString');
}
// Test Date values.
testErrorMirror(new Error());
testErrorMirror(new Error('This does not work'));
testErrorMirror(new Error(123+456));
testErrorMirror(new EvalError('EvalError'));
testErrorMirror(new RangeError('RangeError'));
testErrorMirror(new ReferenceError('ReferenceError'));
testErrorMirror(new SyntaxError('SyntaxError'));
testErrorMirror(new TypeError('TypeError'));
testErrorMirror(new URIError('URIError'));
// Copyright 2008 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: --expose-debug-as debug
// Test the mirror object for functions.
function MirrorRefCache(json_refs) {
var tmp = eval('(' + json_refs + ')');
this.refs_ = [];
for (var i = 0; i < tmp.length; i++) {
this.refs_[tmp[i].handle] = tmp[i];
}
}
MirrorRefCache.prototype.lookup = function(handle) {
return this.refs_[handle];
}
function testFunctionMirror(f) {
// Create mirror and JSON representation.
var mirror = debug.MakeMirror(f);
var serializer = debug.MakeMirrorSerializer();
var json = JSON.stringify(serializer.serializeValue(mirror));
var refs = new MirrorRefCache(
JSON.stringify(serializer.serializeReferencedObjects()));
// Check the mirror hierachy.
assertTrue(mirror instanceof debug.Mirror);
assertTrue(mirror instanceof debug.ValueMirror);
assertTrue(mirror instanceof debug.ObjectMirror);
assertTrue(mirror instanceof debug.FunctionMirror);
// Check the mirror properties.
assertTrue(mirror.isFunction());
assertEquals('function', mirror.type());
assertFalse(mirror.isPrimitive());
assertEquals("Function", mirror.className());
assertEquals(f.name, mirror.name());
assertTrue(mirror.resolved());
assertEquals(f.toString(), mirror.source());
assertTrue(mirror.constructorFunction() instanceof debug.ObjectMirror);
assertTrue(mirror.protoObject() instanceof debug.Mirror);
assertTrue(mirror.prototypeObject() instanceof debug.Mirror);
// Test text representation
assertEquals(f.toString(), mirror.toText());
// Parse JSON representation and check.
var fromJSON = eval('(' + json + ')');
assertEquals('function', fromJSON.type);
assertEquals('Function', fromJSON.className);
assertEquals('function', refs.lookup(fromJSON.constructorFunction.ref).type);
assertEquals('Function', refs.lookup(fromJSON.constructorFunction.ref).name);
assertTrue(fromJSON.resolved);
assertEquals(f.name, fromJSON.name);
assertEquals(f.toString(), fromJSON.source);
// Check the formatted text (regress 1142074).
assertEquals(f.toString(), fromJSON.text);
}
// Test a number of different functions.
testFunctionMirror(function(){});
testFunctionMirror(function a(){return 1;});
testFunctionMirror(Math.sin);
testFunctionMirror((function(){}).bind({}), "Object");
// Copyright 2008 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: --expose-debug-as debug
// Test the mirror object for null
// Create mirror and JSON representation.
var mirror = debug.MakeMirror(null);
var serializer = debug.MakeMirrorSerializer();
var json = JSON.stringify(serializer.serializeValue(mirror));
// Check the mirror hierachy.
assertTrue(mirror instanceof debug.Mirror);
assertTrue(mirror instanceof debug.NullMirror);
// Check the mirror properties.
assertTrue(mirror.isNull());
assertEquals('null', mirror.type());
assertTrue(mirror.isPrimitive());
// Test text representation
assertEquals('null', mirror.toText());
// Parse JSON representation and check.
var fromJSON = eval('(' + json + ')');
assertEquals('null', fromJSON.type);
// Copyright 2008 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: --expose-debug-as debug
// Test the mirror object for number values
function testNumberMirror(n) {
// Create mirror and JSON representation.
var mirror = debug.MakeMirror(n);
var serializer = debug.MakeMirrorSerializer();
var json = JSON.stringify(serializer.serializeValue(mirror));
// Check the mirror hierachy.
assertTrue(mirror instanceof debug.Mirror);
assertTrue(mirror instanceof debug.ValueMirror);
assertTrue(mirror instanceof debug.NumberMirror);
// Check the mirror properties.
assertTrue(mirror.isNumber());
assertEquals('number', mirror.type());
assertTrue(mirror.isPrimitive());
// Test text representation
assertEquals(String(n), mirror.toText());
// Parse JSON representation and check.
var fromJSON = eval('(' + json + ')');
assertEquals('number', fromJSON.type);
if (isFinite(n)) {
assertEquals(n, fromJSON.value);
} else {
// NaN and Infinity values are encoded as strings.
assertTrue(typeof fromJSON.value == 'string');
if (n === Infinity) {
assertEquals('Infinity', fromJSON.value);
} else if (n === -Infinity) {
assertEquals('-Infinity', fromJSON.value);
} else {
assertEquals('NaN', fromJSON.value);
}
}
}
// Test a number of different numbers.
testNumberMirror(-7);
testNumberMirror(-6.5);
testNumberMirror(0);
testNumberMirror(42);
testNumberMirror(100.0002);
testNumberMirror(Infinity);
testNumberMirror(-Infinity);
testNumberMirror(NaN);
This diff is collapsed.
// Copyright 2008 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: --expose-debug-as debug
// Test the mirror object for regular expression values
var dont_enum = debug.PropertyAttribute.DontEnum;
var dont_delete = debug.PropertyAttribute.DontDelete;
var expected_prototype_attributes = {
'source': dont_enum,
'global': dont_enum,
'ignoreCase': dont_enum,
'multiline': dont_enum,
'unicode' : dont_enum,
};
function MirrorRefCache(json_refs) {
var tmp = eval('(' + json_refs + ')');
this.refs_ = [];
for (var i = 0; i < tmp.length; i++) {
this.refs_[tmp[i].handle] = tmp[i];
}
}
MirrorRefCache.prototype.lookup = function(handle) {
return this.refs_[handle];
}
function testRegExpMirror(r) {
// Create mirror and JSON representation.
var mirror = debug.MakeMirror(r);
var serializer = debug.MakeMirrorSerializer();
var json = JSON.stringify(serializer.serializeValue(mirror));
var refs = new MirrorRefCache(
JSON.stringify(serializer.serializeReferencedObjects()));
// Check the mirror hierachy.
assertTrue(mirror instanceof debug.Mirror);
assertTrue(mirror instanceof debug.ValueMirror);
assertTrue(mirror instanceof debug.ObjectMirror);
assertTrue(mirror instanceof debug.RegExpMirror);
// Check the mirror properties.
assertTrue(mirror.isRegExp());
assertEquals('regexp', mirror.type());
assertFalse(mirror.isPrimitive());
assertEquals(dont_enum | dont_delete,
mirror.property('lastIndex').attributes());
var proto_mirror = mirror.protoObject();
for (var p in expected_prototype_attributes) {
assertEquals(expected_prototype_attributes[p],
proto_mirror.property(p).attributes(),
p + ' attributes');
}
// Test text representation
assertEquals('/' + r.source + '/', mirror.toText());
// Parse JSON representation and check.
var fromJSON = eval('(' + json + ')');
assertEquals('regexp', fromJSON.type);
assertEquals('RegExp', fromJSON.className);
assertEquals('lastIndex', fromJSON.properties[0].name);
assertEquals(dont_enum | dont_delete, fromJSON.properties[0].attributes);
assertEquals(mirror.property('lastIndex').propertyType(),
fromJSON.properties[0].propertyType);
assertEquals(mirror.property('lastIndex').value().value(),
refs.lookup(fromJSON.properties[0].ref).value);
}
// Test Date values.
testRegExpMirror(/x/);
testRegExpMirror(/[abc]/);
testRegExpMirror(/[\r\n]/g);
testRegExpMirror(/a*b/gmi);
testRegExpMirror(/(\u{0066}|\u{0062})oo/u);
// Copyright 2008 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: --expose-debug-as debug --allow-natives-syntax
// Test the mirror object for scripts.
function testScriptMirror(f, file_name, file_lines, type, compilation_type,
source, eval_from_line) {
// Create mirror and JSON representation.
var mirror = debug.MakeMirror(f).script();
var serializer = debug.MakeMirrorSerializer();
var json = JSON.stringify(serializer.serializeValue(mirror));
// Check the mirror hierachy.
assertTrue(mirror instanceof debug.Mirror);
assertFalse(mirror instanceof debug.ValueMirror);
assertTrue(mirror instanceof debug.ScriptMirror);
// Check the mirror properties.
assertTrue(mirror.isScript());
assertEquals('script', mirror.type());
var name = mirror.name();
if (name) {
assertEquals(file_name, name.substring(name.length - file_name.length));
} else {
assertTrue(file_name === null);
}
assertEquals(0, mirror.lineOffset());
assertEquals(0, mirror.columnOffset());
if (file_lines > 0) {
assertEquals(file_lines, mirror.lineCount());
}
assertEquals(type, mirror.scriptType());
assertEquals(compilation_type, mirror.compilationType(), "compilation type");
if (source) {
assertEquals(source, mirror.source());
}
if (eval_from_line) {
assertEquals(eval_from_line, mirror.evalFromLocation().line);
}
// Parse JSON representation and check.
var fromJSON = JSON.parse(json);
assertEquals('script', fromJSON.type);
name = fromJSON.name;
if (name) {
assertEquals(file_name, name.substring(name.length - file_name.length));
} else {
assertTrue(file_name === null);
}
assertEquals(0, fromJSON.lineOffset);
assertEquals(0, fromJSON.columnOffset);
if (file_lines > 0) {
assertEquals(file_lines, fromJSON.lineCount);
}
assertEquals(type, fromJSON.scriptType);
assertEquals(compilation_type, fromJSON.compilationType);
}
// Test the script mirror for different functions.
testScriptMirror(function(){}, 'mirror-script.js', 89, 2, 0);
testScriptMirror(eval('(function(){})'), null, 1, 2, 1, '(function(){})', 86);
testScriptMirror(eval('(function(){\n })'), null, 2, 2, 1, '(function(){\n })', 87);
// Copyright 2008 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: --expose-debug-as debug
// Test the mirror object for string values
const kMaxProtocolStringLength = 80; // Constant from mirror-delay.js
function testStringMirror(s) {
// Create mirror and JSON representation.
var mirror = debug.MakeMirror(s);
var serializer = debug.MakeMirrorSerializer();
var json = JSON.stringify(serializer.serializeValue(mirror));
// Check the mirror hierachy.
assertTrue(mirror instanceof debug.Mirror);
assertTrue(mirror instanceof debug.ValueMirror);
assertTrue(mirror instanceof debug.StringMirror);
// Check the mirror properties.
assertTrue(mirror.isString());
assertEquals('string', mirror.type());
assertTrue(mirror.isPrimitive());
// Test text representation
if (s.length <= kMaxProtocolStringLength) {
assertEquals(s, mirror.toText());
} else {
assertEquals(s.substring(0, kMaxProtocolStringLength),
mirror.toText().substring(0, kMaxProtocolStringLength));
}
// Parse JSON representation and check.
var fromJSON = eval('(' + json + ')');
assertEquals('string', fromJSON.type);
if (s.length <= kMaxProtocolStringLength) {
assertEquals(s, fromJSON.value);
} else {
assertEquals(s.substring(0, kMaxProtocolStringLength),
fromJSON.value.substring(0, kMaxProtocolStringLength));
assertEquals(fromJSON.fromIndex, 0);
assertEquals(fromJSON.toIndex, kMaxProtocolStringLength);
}
}
// Test a number of different strings.
testStringMirror('');
testStringMirror('abcdABCD');
testStringMirror('1234');
testStringMirror('"');
testStringMirror('"""');
testStringMirror("'");
testStringMirror("'''");
testStringMirror("'\"'");
testStringMirror('\\');
testStringMirror('\b\t\n\f\r');
testStringMirror('\u0001\u0002\u001E\u001F');
testStringMirror('"a":1,"b":2');
var s = "1234567890"
s = s + s + s + s + s + s + s + s;
assertEquals(kMaxProtocolStringLength, s.length);
testStringMirror(s);
s = s + 'X';
testStringMirror(s);
// Copyright 2008 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: --expose-debug-as debug
// Test the mirror object for undefined
// Create mirror and JSON representation.
var mirror = debug.MakeMirror(void 0);
var serializer = debug.MakeMirrorSerializer();
var json = JSON.stringify(serializer.serializeValue(mirror));
// Check the mirror hierachy.
assertTrue(mirror instanceof debug.Mirror);
assertTrue(mirror instanceof debug.UndefinedMirror);
// Check the mirror properties.
assertTrue(mirror.isUndefined());
assertEquals('undefined', mirror.type());
assertTrue(mirror.isPrimitive());
// Test text representation
assertEquals('undefined', mirror.toText());
// Parse JSON representation and check.
var fromJSON = eval('(' + json + ')');
assertEquals('undefined', fromJSON.type);
// Copyright 2008 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: --expose-debug-as debug
// Test the mirror object for unresolved functions.
function MirrorRefCache(json_refs) {
var tmp = eval('(' + json_refs + ')');
this.refs_ = [];
for (var i = 0; i < tmp.length; i++) {
this.refs_[tmp[i].handle] = tmp[i];
}
}
MirrorRefCache.prototype.lookup = function(handle) {
return this.refs_[handle];
}
var mirror = new debug.UnresolvedFunctionMirror("f");
var serializer = debug.MakeMirrorSerializer();
var json = JSON.stringify(serializer.serializeValue(mirror));
var refs = new MirrorRefCache(
JSON.stringify(serializer.serializeReferencedObjects()));
// Check the mirror hierachy for unresolved functions.
assertTrue(mirror instanceof debug.Mirror);
assertTrue(mirror instanceof debug.ValueMirror);
assertTrue(mirror instanceof debug.ObjectMirror);
assertTrue(mirror instanceof debug.FunctionMirror);
// Check the mirror properties for unresolved functions.
assertTrue(mirror.isUnresolvedFunction());
assertEquals('function', mirror.type());
assertFalse(mirror.isPrimitive());
assertEquals("Function", mirror.className());
assertEquals("f", mirror.name());
assertEquals('undefined', typeof mirror.inferredName());
assertFalse(mirror.resolved());
assertEquals(void 0, mirror.source());
assertEquals('undefined', mirror.constructorFunction().type());
assertEquals('undefined', mirror.protoObject().type());
assertEquals('undefined', mirror.prototypeObject().type());
// Parse JSON representation of unresolved functions and check.
var fromJSON = eval('(' + json + ')');
assertEquals('function', fromJSON.type, 'Unexpected mirror type in JSON');
assertEquals('Function', fromJSON.className, 'Unexpected mirror class name in JSON');
assertEquals(mirror.constructorFunction().handle(), fromJSON.constructorFunction.ref, 'Unexpected constructor function handle in JSON');
assertEquals('undefined', refs.lookup(fromJSON.constructorFunction.ref).type, 'Unexpected constructor function type in JSON');
assertEquals(mirror.protoObject().handle(), fromJSON.protoObject.ref, 'Unexpected proto object handle in JSON');
assertEquals('undefined', refs.lookup(fromJSON.protoObject.ref).type, 'Unexpected proto object type in JSON');
assertEquals(mirror.prototypeObject().handle(), fromJSON.prototypeObject.ref, 'Unexpected prototype object handle in JSON');
assertEquals('undefined', refs.lookup(fromJSON.prototypeObject.ref).type, 'Unexpected prototype object type in JSON');
assertFalse(fromJSON.resolved);
assertEquals("f", fromJSON.name);
assertFalse('inferredName' in fromJSON);
assertEquals(void 0, fromJSON.source);
// Copyright 2016 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-debug-as debug
var mirror = debug.MakeMirror(new Proxy({}, {}));
// As long as we have no special mirror for proxies, we use an object mirror.
assertEquals("object", mirror.type());
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment