1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
4 * Any copyright is dedicated to the Public Domain.
5 * http://creativecommons.org/licenses/publicdomain/
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.
15 /* Assigning to an undeclared variable should fail in strict mode. */
16 assertEq(testLenientAndStrict('undeclared=1',
18 raisesException(ReferenceError)),
22 * Assigning to a var-declared variable should be okay in strict and
25 assertEq(testLenientAndStrict('var var_declared; var_declared=1',
31 * We mustn't report errors until the code is actually run; the variable
32 * could be created in the mean time.
34 assertEq(testLenientAndStrict('undeclared_at_compiletime=1',
40 var o = { x: 1, y: 1 };
41 Object.defineProperty(o, 'x', { writable: false });
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 + " })(); }";
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);
56 reportCompare(true, true);
58 var successfullyParsed = true;