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