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 | /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
michael@0 | 2 | |
michael@0 | 3 | /* |
michael@0 | 4 | * Any copyright is dedicated to the Public Domain. |
michael@0 | 5 | * http://creativecommons.org/licenses/publicdomain/ |
michael@0 | 6 | */ |
michael@0 | 7 | |
michael@0 | 8 | /* Direct calls to eval should inherit the strictness of the calling code. */ |
michael@0 | 9 | assertEq(testLenientAndStrict("eval('010')", |
michael@0 | 10 | completesNormally, |
michael@0 | 11 | raisesException(SyntaxError)), |
michael@0 | 12 | true); |
michael@0 | 13 | |
michael@0 | 14 | /* |
michael@0 | 15 | * Directives in the eval code itself should always override a direct |
michael@0 | 16 | * caller's strictness. |
michael@0 | 17 | */ |
michael@0 | 18 | assertEq(testLenientAndStrict("eval('\"use strict\"; 010')", |
michael@0 | 19 | raisesException(SyntaxError), |
michael@0 | 20 | raisesException(SyntaxError)), |
michael@0 | 21 | true); |
michael@0 | 22 | |
michael@0 | 23 | /* Code passed to indirect calls to eval should never be strict. */ |
michael@0 | 24 | assertEq(testLenientAndStrict("var evil=eval; evil('010')", |
michael@0 | 25 | completesNormally, |
michael@0 | 26 | completesNormally), |
michael@0 | 27 | true); |
michael@0 | 28 | |
michael@0 | 29 | /* |
michael@0 | 30 | * Code passed to the Function constructor never inherits the caller's |
michael@0 | 31 | * strictness. |
michael@0 | 32 | */ |
michael@0 | 33 | assertEq(completesNormally("Function('010')"), |
michael@0 | 34 | true); |
michael@0 | 35 | assertEq(raisesException(SyntaxError)("Function('\"use strict\"; 010')"), |
michael@0 | 36 | true); |
michael@0 | 37 | |
michael@0 | 38 | /* |
michael@0 | 39 | * If 'eval' causes a frame's primitive |this| to become wrapped, the frame should see the same |
michael@0 | 40 | * wrapper object as the eval code. |
michael@0 | 41 | */ |
michael@0 | 42 | var call_this, eval_this; |
michael@0 | 43 | function f(code) { |
michael@0 | 44 | /* |
michael@0 | 45 | * At this point, a primitive |this| has not yet been wrapped. A |
michael@0 | 46 | * reference to |this| from the eval call should wrap it, and the wrapper |
michael@0 | 47 | * should be stored where the call frame can see it. |
michael@0 | 48 | */ |
michael@0 | 49 | eval(code); |
michael@0 | 50 | call_this = this; |
michael@0 | 51 | } |
michael@0 | 52 | f.call(true, 'eval_this = this'); |
michael@0 | 53 | assertEq(call_this, eval_this); |
michael@0 | 54 | |
michael@0 | 55 | reportCompare(true, true); |