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

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/js/src/tests/ecma_5/strict/8.7.2.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,56 @@
     1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     1.5 +
     1.6 +/*
     1.7 + * Any copyright is dedicated to the Public Domain.
     1.8 + * http://creativecommons.org/licenses/publicdomain/
     1.9 + */
    1.10 +
    1.11 +/*
    1.12 + * These tests depend on the fact that testLenientAndStrict tries the
    1.13 + * strict case first; otherwise, the non-strict evaluation creates the
    1.14 + * variable. Ugh. Ideally, we would use evalcx, but that's not
    1.15 + * available in the browser.
    1.16 + */
    1.17 +
    1.18 +/* Assigning to an undeclared variable should fail in strict mode. */
    1.19 +assertEq(testLenientAndStrict('undeclared=1',
    1.20 +                              completesNormally,
    1.21 +                              raisesException(ReferenceError)),
    1.22 +         true);
    1.23 +
    1.24 +/*
    1.25 + * Assigning to a var-declared variable should be okay in strict and
    1.26 + * lenient modes.
    1.27 + */
    1.28 +assertEq(testLenientAndStrict('var var_declared; var_declared=1',
    1.29 +                              completesNormally,
    1.30 +                              completesNormally),
    1.31 +         true);
    1.32 +
    1.33 +/*
    1.34 + * We mustn't report errors until the code is actually run; the variable
    1.35 + * could be created in the mean time.
    1.36 + */
    1.37 +assertEq(testLenientAndStrict('undeclared_at_compiletime=1',
    1.38 +                              parsesSuccessfully,
    1.39 +                              parsesSuccessfully),
    1.40 +         true);
    1.41 +
    1.42 +function obj() {
    1.43 +  var o = { x: 1, y: 1 };
    1.44 +  Object.defineProperty(o, 'x', { writable: false });
    1.45 +  return o;
    1.46 +}
    1.47 +
    1.48 +/* Put EXPR in a strict mode code context with 'with' bindings in scope. */
    1.49 +function in_strict_with(expr) {
    1.50 +  return "with(obj()) { (function () { 'use strict'; " + expr + " })(); }";
    1.51 +}
    1.52 +
    1.53 +assertEq(raisesException(TypeError)(in_strict_with('x = 2; y = 2;')), true);
    1.54 +assertEq(raisesException(TypeError)(in_strict_with('x++;')), true);
    1.55 +assertEq(raisesException(TypeError)(in_strict_with('++x;')), true);
    1.56 +assertEq(raisesException(TypeError)(in_strict_with('x--;')), true);
    1.57 +assertEq(raisesException(TypeError)(in_strict_with('--x;')), true);
    1.58 +
    1.59 +reportCompare(true, true);

mercurial