js/src/tests/ecma_5/strict/directive-prologue-01.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/directive-prologue-01.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,78 @@
     1.4 +// Any copyright is dedicated to the Public Domain.
     1.5 +// http://creativecommons.org/licenses/publicdomain/
     1.6 +
     1.7 +//-----------------------------------------------------------------------------
     1.8 +var BUGNUMBER = 601262;
     1.9 +var summary =
    1.10 +  "A string literal containing an octal escape before a strict mode " +
    1.11 +  "directive should be a syntax error";
    1.12 +
    1.13 +print(BUGNUMBER + ": " + summary);
    1.14 +
    1.15 +/**************
    1.16 + * BEGIN TEST *
    1.17 + **************/
    1.18 +
    1.19 +try
    1.20 +{
    1.21 +  eval(" '\\145'; 'use strict'; ");
    1.22 +  throw new Error("no error thrown for eval");
    1.23 +}
    1.24 +catch (e)
    1.25 +{
    1.26 +  assertEq(e instanceof SyntaxError, true,
    1.27 +           "wrong error for octal-escape before strict directive in eval");
    1.28 +}
    1.29 +
    1.30 +try
    1.31 +{
    1.32 +  Function(" '\\145'; 'use strict'; ");
    1.33 +  throw new Error("no error thrown for Function");
    1.34 +}
    1.35 +catch (e)
    1.36 +{
    1.37 +  assertEq(e instanceof SyntaxError, true,
    1.38 +           "wrong error for octal-escape before strict directive in Function");
    1.39 +}
    1.40 +
    1.41 +try
    1.42 +{
    1.43 +  eval(" function f(){ '\\145'; 'use strict'; } ");
    1.44 +  throw new Error("no error thrown for eval of function");
    1.45 +}
    1.46 +catch (e)
    1.47 +{
    1.48 +  assertEq(e instanceof SyntaxError, true,
    1.49 +           "wrong error for octal-escape before strict directive in eval of " +
    1.50 +           "function");
    1.51 +}
    1.52 +
    1.53 +try
    1.54 +{
    1.55 +  Function(" function f(){ '\\145'; 'use strict'; } ");
    1.56 +  throw new Error("no error thrown for eval of function");
    1.57 +}
    1.58 +catch (e)
    1.59 +{
    1.60 +  assertEq(e instanceof SyntaxError, true,
    1.61 +           "wrong error for octal-escape before strict directive in eval of " +
    1.62 +           "function");
    1.63 +}
    1.64 +
    1.65 +eval("function notAnError1() { 5; '\\145'; function g() { 'use strict'; } }");
    1.66 +
    1.67 +Function("function notAnError2() { 5; '\\145'; function g() { 'use strict'; } }");
    1.68 +
    1.69 +function notAnError3()
    1.70 +{
    1.71 +  5;
    1.72 +  "\145";
    1.73 +  function g() { "use strict"; }
    1.74 +}
    1.75 +
    1.76 +/******************************************************************************/
    1.77 +
    1.78 +if (typeof reportCompare === "function")
    1.79 +  reportCompare(true, true);
    1.80 +
    1.81 +print("All tests passed!");

mercurial