michael@0: /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: michael@0: /* michael@0: * Any copyright is dedicated to the Public Domain. michael@0: * http://creativecommons.org/licenses/publicdomain/ michael@0: */ michael@0: michael@0: /* michael@0: * These tests depend on the fact that testLenientAndStrict tries the michael@0: * strict case first; otherwise, the non-strict evaluation creates the michael@0: * variable. Ugh. Ideally, we would use evalcx, but that's not michael@0: * available in the browser. michael@0: */ michael@0: michael@0: /* Assigning to an undeclared variable should fail in strict mode. */ michael@0: assertEq(testLenientAndStrict('undeclared=1', michael@0: completesNormally, michael@0: raisesException(ReferenceError)), michael@0: true); michael@0: michael@0: /* michael@0: * Assigning to a var-declared variable should be okay in strict and michael@0: * lenient modes. michael@0: */ michael@0: assertEq(testLenientAndStrict('var var_declared; var_declared=1', michael@0: completesNormally, michael@0: completesNormally), michael@0: true); michael@0: michael@0: /* michael@0: * We mustn't report errors until the code is actually run; the variable michael@0: * could be created in the mean time. michael@0: */ michael@0: assertEq(testLenientAndStrict('undeclared_at_compiletime=1', michael@0: parsesSuccessfully, michael@0: parsesSuccessfully), michael@0: true); michael@0: michael@0: function obj() { michael@0: var o = { x: 1, y: 1 }; michael@0: Object.defineProperty(o, 'x', { writable: false }); michael@0: return o; michael@0: } michael@0: michael@0: /* Put EXPR in a strict mode code context with 'with' bindings in scope. */ michael@0: function in_strict_with(expr) { michael@0: return "with(obj()) { (function () { 'use strict'; " + expr + " })(); }"; michael@0: } michael@0: michael@0: assertEq(raisesException(TypeError)(in_strict_with('x = 2; y = 2;')), true); michael@0: assertEq(raisesException(TypeError)(in_strict_with('x++;')), true); michael@0: assertEq(raisesException(TypeError)(in_strict_with('++x;')), true); michael@0: assertEq(raisesException(TypeError)(in_strict_with('x--;')), true); michael@0: assertEq(raisesException(TypeError)(in_strict_with('--x;')), true); michael@0: michael@0: reportCompare(true, true);