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