Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | // After returning from an implicit toString call, the calling frame's onStep |
michael@0 | 2 | // hook fires. |
michael@0 | 3 | |
michael@0 | 4 | var g = newGlobal(); |
michael@0 | 5 | g.eval("var originalX = {toString: function () { debugger; log += 'x'; return 1; }};\n"); |
michael@0 | 6 | |
michael@0 | 7 | var dbg = Debugger(g); |
michael@0 | 8 | dbg.onDebuggerStatement = function (frame) { |
michael@0 | 9 | g.log += 'd'; |
michael@0 | 10 | frame.older.onStep = function () { |
michael@0 | 11 | if (!g.log.match(/[sy]$/)) |
michael@0 | 12 | g.log += 's'; |
michael@0 | 13 | }; |
michael@0 | 14 | }; |
michael@0 | 15 | |
michael@0 | 16 | // expr is an expression that will trigger an implicit toString call. |
michael@0 | 17 | function check(expr) { |
michael@0 | 18 | g.log = ''; |
michael@0 | 19 | g.x = g.originalX; |
michael@0 | 20 | g.eval(expr + ";\n" + |
michael@0 | 21 | "log += 'y';\n"); |
michael@0 | 22 | assertEq(g.log, 'dxsy'); |
michael@0 | 23 | } |
michael@0 | 24 | |
michael@0 | 25 | check("'' + x"); |
michael@0 | 26 | check("0 + x"); |
michael@0 | 27 | check("0 - x"); |
michael@0 | 28 | check("0 * x"); |
michael@0 | 29 | check("0 / x"); |
michael@0 | 30 | check("0 % x"); |
michael@0 | 31 | check("+x"); |
michael@0 | 32 | check("x in {}"); |
michael@0 | 33 | check("x++"); |
michael@0 | 34 | check("++x"); |
michael@0 | 35 | check("x--"); |
michael@0 | 36 | check("--x"); |
michael@0 | 37 | check("x < 0"); |
michael@0 | 38 | check("x > 0"); |
michael@0 | 39 | check("x >= 0"); |
michael@0 | 40 | check("x <= 0"); |
michael@0 | 41 | check("x == 0"); |
michael@0 | 42 | check("x != 0"); |
michael@0 | 43 | check("x & 1"); |
michael@0 | 44 | check("x | 1"); |
michael@0 | 45 | check("x ^ 1"); |
michael@0 | 46 | check("~x"); |
michael@0 | 47 | check("x << 1"); |
michael@0 | 48 | check("x >> 1"); |
michael@0 | 49 | check("x >>> 1"); |
michael@0 | 50 | |
michael@0 | 51 | g.eval("function lastStep() { throw StopIteration; }"); |
michael@0 | 52 | g.eval("function emptyIterator() { debugger; log += 'x'; return { next: lastStep }; }"); |
michael@0 | 53 | g.eval("var customEmptyIterator = { __iterator__: emptyIterator };"); |
michael@0 | 54 | g.log = ''; |
michael@0 | 55 | g.eval("for (i in customEmptyIterator);\n" + |
michael@0 | 56 | "log += 'y';\n"); |
michael@0 | 57 | assertEq(g.log, 'dxsy'); |
michael@0 | 58 | |
michael@0 | 59 | g.eval("var getter = { get x() { debugger; return log += 'x'; } }"); |
michael@0 | 60 | check("getter.x"); |
michael@0 | 61 | |
michael@0 | 62 | g.eval("var setter = { set x(v) { debugger; return log += 'x'; } }"); |
michael@0 | 63 | check("setter.x = 1"); |
michael@0 | 64 | |
michael@0 | 65 | g.eval("Object.defineProperty(this, 'thisgetter', { get: function() { debugger; log += 'x'; }});"); |
michael@0 | 66 | check("thisgetter"); |