js/src/tests/ecma_5/strict/10.4.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/10.4.2.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,55 @@
     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 +/* Direct calls to eval should inherit the strictness of the calling code. */
    1.12 +assertEq(testLenientAndStrict("eval('010')",
    1.13 +                              completesNormally,
    1.14 +                              raisesException(SyntaxError)),
    1.15 +         true);
    1.16 +
    1.17 +/*
    1.18 + * Directives in the eval code itself should always override a direct
    1.19 + * caller's strictness.
    1.20 + */
    1.21 +assertEq(testLenientAndStrict("eval('\"use strict\"; 010')",
    1.22 +                              raisesException(SyntaxError),
    1.23 +                              raisesException(SyntaxError)),
    1.24 +         true);
    1.25 +
    1.26 +/* Code passed to indirect calls to eval should never be strict. */
    1.27 +assertEq(testLenientAndStrict("var evil=eval; evil('010')",
    1.28 +                              completesNormally,
    1.29 +                              completesNormally),
    1.30 +         true);
    1.31 +
    1.32 +/*
    1.33 + * Code passed to the Function constructor never inherits the caller's
    1.34 + * strictness.
    1.35 + */
    1.36 +assertEq(completesNormally("Function('010')"),
    1.37 +         true);
    1.38 +assertEq(raisesException(SyntaxError)("Function('\"use strict\"; 010')"),
    1.39 +         true);
    1.40 +
    1.41 +/*
    1.42 + * If 'eval' causes a frame's primitive |this| to become wrapped, the frame should see the same
    1.43 + * wrapper object as the eval code.
    1.44 + */
    1.45 +var call_this, eval_this;
    1.46 +function f(code) {
    1.47 +  /*
    1.48 +   * At this point, a primitive |this| has not yet been wrapped. A
    1.49 +   * reference to |this| from the eval call should wrap it, and the wrapper
    1.50 +   * should be stored where the call frame can see it.
    1.51 +   */
    1.52 +  eval(code);
    1.53 +  call_this = this; 
    1.54 +}
    1.55 +f.call(true, 'eval_this = this');
    1.56 +assertEq(call_this, eval_this);
    1.57 +
    1.58 +reportCompare(true, true);

mercurial