js/src/tests/ecma_5/strict/8.7.2.js

changeset 0
6474c204b198
equal deleted inserted replaced
-1:000000000000 0:af737d676207
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 /*
9 * These tests depend on the fact that testLenientAndStrict tries the
10 * strict case first; otherwise, the non-strict evaluation creates the
11 * variable. Ugh. Ideally, we would use evalcx, but that's not
12 * available in the browser.
13 */
14
15 /* Assigning to an undeclared variable should fail in strict mode. */
16 assertEq(testLenientAndStrict('undeclared=1',
17 completesNormally,
18 raisesException(ReferenceError)),
19 true);
20
21 /*
22 * Assigning to a var-declared variable should be okay in strict and
23 * lenient modes.
24 */
25 assertEq(testLenientAndStrict('var var_declared; var_declared=1',
26 completesNormally,
27 completesNormally),
28 true);
29
30 /*
31 * We mustn't report errors until the code is actually run; the variable
32 * could be created in the mean time.
33 */
34 assertEq(testLenientAndStrict('undeclared_at_compiletime=1',
35 parsesSuccessfully,
36 parsesSuccessfully),
37 true);
38
39 function obj() {
40 var o = { x: 1, y: 1 };
41 Object.defineProperty(o, 'x', { writable: false });
42 return o;
43 }
44
45 /* Put EXPR in a strict mode code context with 'with' bindings in scope. */
46 function in_strict_with(expr) {
47 return "with(obj()) { (function () { 'use strict'; " + expr + " })(); }";
48 }
49
50 assertEq(raisesException(TypeError)(in_strict_with('x = 2; y = 2;')), true);
51 assertEq(raisesException(TypeError)(in_strict_with('x++;')), true);
52 assertEq(raisesException(TypeError)(in_strict_with('++x;')), true);
53 assertEq(raisesException(TypeError)(in_strict_with('x--;')), true);
54 assertEq(raisesException(TypeError)(in_strict_with('--x;')), true);
55
56 reportCompare(true, true);

mercurial