js/src/jit-test/tests/debug/Environment-find-06.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 // Environment.prototype.find finds bindings that are function arguments, 'let'
michael@0 2 // bindings, or FunctionExpression names.
michael@0 3
michael@0 4 var g = newGlobal();
michael@0 5 g.eval("function h() { debugger; }");
michael@0 6
michael@0 7 var dbg = new Debugger(g);
michael@0 8
michael@0 9 function test1(code) {
michael@0 10 var hits = 0;
michael@0 11 dbg.onDebuggerStatement = function (frame) {
michael@0 12 var env = frame.older.environment.find('X');
michael@0 13 assertEq(env.names().indexOf('X') !== -1, true);
michael@0 14 assertEq(env.type, 'declarative');
michael@0 15 assertEq(env.parent !== null, true);
michael@0 16 hits++;
michael@0 17 };
michael@0 18 g.eval(code);
michael@0 19 assertEq(hits, 1);
michael@0 20 }
michael@0 21
michael@0 22 var manyNames = '';
michael@0 23 for (var i = 0; i < 2048; i++)
michael@0 24 manyNames += 'x' + i + ', ';
michael@0 25 manyNames += 'X';
michael@0 26
michael@0 27 function test2(code) {
michael@0 28 print(code + " : one");
michael@0 29 test1(code.replace('@@', 'X'));
michael@0 30 print(code + " : many");
michael@0 31 test1(code.replace('@@', manyNames));
michael@0 32 }
michael@0 33
michael@0 34 test2('function f(@@) { h(); } f(1);');
michael@0 35 test2('function f(@@) { h(); } f();');
michael@0 36 test2('function f(@@) { return function g() { h(X); }; } f(1)();');
michael@0 37 test2('function f(@@) { return function g() { h(X); }; } f()();');
michael@0 38
michael@0 39 test2(' { let @@ = 0; h(); }');
michael@0 40 test2('function f(a, b, c) { let @@ = 0; h(); } f(1, 2, 3);');
michael@0 41 test2(' { let @@ = 0; { let y = 0; h(); } }');
michael@0 42 test2('function f() { let @@ = 0; { let y = 0; h(); } } f();');
michael@0 43 test2(' { for (let @@ = 0; X < 1; X++) h(); }');
michael@0 44 test2('function f() { for (let @@ = 0; X < 1; X++) h(); } f();');
michael@0 45 test2(' { (let (@@ = 0) let (y = 2, z = 3) h()); }');
michael@0 46 test2('function f() { return (let (@@ = 0) let (y = 2, z = 3) h()); } f();');
michael@0 47
michael@0 48 test1('(function X() { h(); })();');
michael@0 49 test1('(function X(a, b, c) { h(); })(1, 2, 3);');

mercurial