1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/js/src/tests/js1_8_5/extensions/findReferences-01.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,54 @@ 1.4 +// Any copyright is dedicated to the Public Domain. 1.5 +// http://creativecommons.org/licenses/publicdomain/ 1.6 +// Contributor: Jim Blandy 1.7 + 1.8 +if (typeof findReferences == "function") { 1.9 + function C() {} 1.10 + var o = new C; 1.11 + o.x = {}; // via ordinary property 1.12 + o[42] = {}; // via numeric property 1.13 + o[123456789] = {}; // via ridiculous numeric property 1.14 + o.myself = o; // self-references should be reported 1.15 + o.alsoMyself = o; // multiple self-references should all be reported 1.16 + 1.17 + assertEq(referencesVia(o, 'type; type_proto', C.prototype), true); 1.18 + assertEq(referencesVia(o, 'shape; base; parent', this), true); 1.19 + assertEq(referencesVia(o, 'x', o.x), true); 1.20 + assertEq(referencesVia(o, 'objectElements[42]', o[42]), true); 1.21 + assertEq(referencesVia(o, '123456789', o[123456789]), true); 1.22 + assertEq(referencesVia(o, 'myself', o), true); 1.23 + assertEq(referencesVia(o, 'alsoMyself', o), true); 1.24 + 1.25 + function g() { return 42; } 1.26 + function s(v) { } 1.27 + var p = Object.defineProperty({}, 'a', { get:g, set:s }); 1.28 + assertEq(referencesVia(p, 'shape; base; getter', g), true); 1.29 + assertEq(referencesVia(p, 'shape; base; setter', s), true); 1.30 + 1.31 + // If there are multiple objects with the same shape referring to a getter 1.32 + // or setter, findReferences should get all of them, even though the shape 1.33 + // gets 'marked' the first time we visit it. 1.34 + var q = Object.defineProperty({}, 'a', { get:g, set:s }); 1.35 + assertEq(referencesVia(p, 'shape; base; getter', g), true); 1.36 + assertEq(referencesVia(q, 'shape; base; getter', g), true); 1.37 + 1.38 + // If we extend each object's shape chain, both should still be able to 1.39 + // reach the getter, even though the two shapes are each traversed twice. 1.40 + p.b = 9; 1.41 + q.b = 9; 1.42 + assertEq(referencesVia(p, 'shape; parent; base; getter', g), true); 1.43 + assertEq(referencesVia(q, 'shape; parent; base; getter', g), true); 1.44 + 1.45 + // These are really just ordinary own property references. 1.46 + assertEq(referencesVia(C, 'prototype', Object.getPrototypeOf(o)), true); 1.47 + assertEq(referencesVia(Object.getPrototypeOf(o), 'constructor', C), true); 1.48 + 1.49 + // Dense arrays should work, too. 1.50 + a = []; 1.51 + a[1] = o; 1.52 + assertEq(referencesVia(a, 'objectElements[1]', o), true); 1.53 + 1.54 + reportCompare(true, true); 1.55 +} else { 1.56 + reportCompare(true, true, "test skipped: findReferences is not a function"); 1.57 +}