js/src/jit-test/tests/debug/Debugger-findScripts-12.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 // Debugger.prototype.findScripts can filter by global, url, and line number.
michael@0 2
michael@0 3 // Two scripts, with different functions at the same line numbers.
michael@0 4 var url1 = scriptdir + 'Debugger-findScripts-12-script1';
michael@0 5 var url2 = scriptdir + 'Debugger-findScripts-12-script2';
michael@0 6
michael@0 7 // Three globals: two with code, one with nothing.
michael@0 8 var g1 = newGlobal();
michael@0 9 g1.toSource = function () "[global g1]";
michael@0 10 g1.load(url1);
michael@0 11 g1.load(url2);
michael@0 12 var g2 = newGlobal();
michael@0 13 g2.toSource = function () "[global g2]";
michael@0 14 g2.load(url1);
michael@0 15 g2.load(url2);
michael@0 16 var g3 = newGlobal();
michael@0 17
michael@0 18 var dbg = new Debugger(g1, g2, g3);
michael@0 19
michael@0 20 function script(func) {
michael@0 21 var gw = dbg.addDebuggee(func.global);
michael@0 22 var script = gw.makeDebuggeeValue(func).script;
michael@0 23 script.toString = function ()
michael@0 24 "[Debugger.Script for " + func.name + " in " + uneval(func.global) + "]";
michael@0 25 return script;
michael@0 26 }
michael@0 27
michael@0 28 // The function scripts we know of. There may be random eval scripts involved, but
michael@0 29 // we don't care about those.
michael@0 30 var allScripts = ([g1.f, g1.f(), g1.g, g1.h, g1.h(), g1.i,
michael@0 31 g2.f, g2.f(), g2.g, g2.h, g2.h(), g2.i].map(script));
michael@0 32
michael@0 33 // Search for scripts using |query|, expecting no members of allScripts
michael@0 34 // except those given in |expected| in the result. If |expected| is
michael@0 35 // omitted, expect no members of allScripts at all.
michael@0 36 function queryExpectOnly(query, expected) {
michael@0 37 print();
michael@0 38 print("queryExpectOnly(" + uneval(query) + ")");
michael@0 39 var scripts = dbg.findScripts(query);
michael@0 40 var present = allScripts.filter(function (s) { return scripts.indexOf(s) != -1; });
michael@0 41 if (expected) {
michael@0 42 expected = expected.map(script);
michael@0 43 expected.forEach(function (s) {
michael@0 44 if (present.indexOf(s) == -1)
michael@0 45 assertEq(s + " not present", "is present");
michael@0 46 });
michael@0 47 present.forEach(function (s) {
michael@0 48 if (expected.indexOf(s) == -1)
michael@0 49 assertEq(s + " is present", "not present");
michael@0 50 });
michael@0 51 } else {
michael@0 52 assertEq(present.length, 0);
michael@0 53 }
michael@0 54 }
michael@0 55
michael@0 56 // We have twelve functions: two globals, each with two urls, each
michael@0 57 // defining three functions. Show that all the different combinations of
michael@0 58 // query parameters select what they should.
michael@0 59
michael@0 60 // There are gaps in the pattern:
michael@0 61 // - You can only filter by line if you're also filtering by url.
michael@0 62 // - You can't ask for only the innermost scripts unless you're filtering by line.
michael@0 63
michael@0 64 // Filtering by global, url, and line produces one function, or two
michael@0 65 // where they are nested.
michael@0 66 queryExpectOnly({ global:g1, url:url1, line: 6 }, [g1.f ]);
michael@0 67 queryExpectOnly({ global:g1, url:url1, line: 8 }, [g1.f, g1.f()]);
michael@0 68 queryExpectOnly({ global:g1, url:url1, line: 15 }, [g1.g ]);
michael@0 69 queryExpectOnly({ global:g1, url:url2, line: 6 }, [g1.h ]);
michael@0 70 queryExpectOnly({ global:g1, url:url2, line: 8 }, [g1.h, g1.h()]);
michael@0 71 queryExpectOnly({ global:g1, url:url2, line: 15 }, [g1.i ]);
michael@0 72 queryExpectOnly({ global:g2, url:url1, line: 6 }, [g2.f ]);
michael@0 73 queryExpectOnly({ global:g2, url:url1, line: 8 }, [g2.f, g2.f()]);
michael@0 74 queryExpectOnly({ global:g2, url:url1, line: 15 }, [g2.g ]);
michael@0 75 queryExpectOnly({ global:g2, url:url2, line: 6 }, [g2.h ]);
michael@0 76 queryExpectOnly({ global:g2, url:url2, line: 8 }, [g2.h, g2.h()]);
michael@0 77 queryExpectOnly({ global:g2, url:url2, line: 15 }, [g2.i ]);
michael@0 78
michael@0 79 // Filtering by global, url, and line, and requesting only the innermost
michael@0 80 // function at each point, should produce only one function.
michael@0 81 queryExpectOnly({ global:g1, url:url1, line: 6, innermost: true }, [g1.f ]);
michael@0 82 queryExpectOnly({ global:g1, url:url1, line: 8, innermost: true }, [g1.f()]);
michael@0 83 queryExpectOnly({ global:g1, url:url1, line: 15, innermost: true }, [g1.g ]);
michael@0 84 queryExpectOnly({ global:g1, url:url2, line: 6, innermost: true }, [g1.h ]);
michael@0 85 queryExpectOnly({ global:g1, url:url2, line: 8, innermost: true }, [g1.h()]);
michael@0 86 queryExpectOnly({ global:g1, url:url2, line: 15, innermost: true }, [g1.i ]);
michael@0 87 queryExpectOnly({ global:g2, url:url1, line: 6, innermost: true }, [g2.f ]);
michael@0 88 queryExpectOnly({ global:g2, url:url1, line: 8, innermost: true }, [g2.f()]);
michael@0 89 queryExpectOnly({ global:g2, url:url1, line: 15, innermost: true }, [g2.g ]);
michael@0 90 queryExpectOnly({ global:g2, url:url2, line: 6, innermost: true }, [g2.h ]);
michael@0 91 queryExpectOnly({ global:g2, url:url2, line: 8, innermost: true }, [g2.h()]);
michael@0 92 queryExpectOnly({ global:g2, url:url2, line: 15, innermost: true }, [g2.i ]);
michael@0 93
michael@0 94 // Filtering by url and global should produce sets of three scripts.
michael@0 95 queryExpectOnly({ global:g1, url:url1 }, [g1.f, g1.f(), g1.g]);
michael@0 96 queryExpectOnly({ global:g1, url:url2 }, [g1.h, g1.h(), g1.i]);
michael@0 97 queryExpectOnly({ global:g2, url:url1 }, [g2.f, g2.f(), g2.g]);
michael@0 98 queryExpectOnly({ global:g2, url:url2 }, [g2.h, g2.h(), g2.i]);
michael@0 99
michael@0 100 // Filtering by url and line, innermost-only, should produce sets of two scripts,
michael@0 101 // or four where there are nested functions.
michael@0 102 queryExpectOnly({ url:url1, line: 6 }, [g1.f, g2.f ]);
michael@0 103 queryExpectOnly({ url:url1, line: 8 }, [g1.f, g1.f(), g2.f, g2.f()]);
michael@0 104 queryExpectOnly({ url:url1, line:15 }, [g1.g, g2.g ]);
michael@0 105 queryExpectOnly({ url:url2, line: 6 }, [g1.h, g2.h ]);
michael@0 106 queryExpectOnly({ url:url2, line: 8 }, [g1.h, g1.h(), g2.h, g2.h()]);
michael@0 107 queryExpectOnly({ url:url2, line:15 }, [g1.i, g2.i ]);
michael@0 108
michael@0 109 // Filtering by url and line, and requesting only the innermost scripts,
michael@0 110 // should always produce pairs of scripts.
michael@0 111 queryExpectOnly({ url:url1, line: 6, innermost: true }, [g1.f, g2.f ]);
michael@0 112 queryExpectOnly({ url:url1, line: 8, innermost: true }, [g1.f(), g2.f()]);
michael@0 113 queryExpectOnly({ url:url1, line:15, innermost: true }, [g1.g, g2.g ]);
michael@0 114 queryExpectOnly({ url:url2, line: 6, innermost: true }, [g1.h, g2.h ]);
michael@0 115 queryExpectOnly({ url:url2, line: 8, innermost: true }, [g1.h(), g2.h()]);
michael@0 116 queryExpectOnly({ url:url2, line:15, innermost: true }, [g1.i, g2.i ]);
michael@0 117
michael@0 118 // Filtering by global only should produce sets of six scripts.
michael@0 119 queryExpectOnly({ global:g1 }, [g1.f, g1.f(), g1.g, g1.h, g1.h(), g1.i]);
michael@0 120 queryExpectOnly({ global:g2 }, [g2.f, g2.f(), g2.g, g2.h, g2.h(), g2.i]);
michael@0 121
michael@0 122 // Filtering by url should produce sets of six scripts.
michael@0 123 queryExpectOnly({ url:url1 }, [g1.f, g1.f(), g1.g, g2.f, g2.f(), g2.g]);
michael@0 124 queryExpectOnly({ url:url2 }, [g1.h, g1.h(), g1.i, g2.h, g2.h(), g2.i]);
michael@0 125
michael@0 126 // Filtering by no axes should produce all twelve scripts.
michael@0 127 queryExpectOnly({}, [g1.f, g1.f(), g1.g, g1.h, g1.h(), g1.i,
michael@0 128 g2.f, g2.f(), g2.g, g2.h, g2.h(), g2.i]);

mercurial