summaryrefslogtreecommitdiffstats
path: root/js/src/tests/ecma_5/extensions/misplaced-inconsistent-directive.js
diff options
context:
space:
mode:
authorMatt A. Tobin <mattatobin@localhost.localdomain>2018-02-02 04:16:08 -0500
committerMatt A. Tobin <mattatobin@localhost.localdomain>2018-02-02 04:16:08 -0500
commit5f8de423f190bbb79a62f804151bc24824fa32d8 (patch)
tree10027f336435511475e392454359edea8e25895d /js/src/tests/ecma_5/extensions/misplaced-inconsistent-directive.js
parent49ee0794b5d912db1f95dce6eb52d781dc210db5 (diff)
downloadUXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.gz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.lz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.xz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.zip
Add m-esr52 at 52.6.0
Diffstat (limited to 'js/src/tests/ecma_5/extensions/misplaced-inconsistent-directive.js')
-rw-r--r--js/src/tests/ecma_5/extensions/misplaced-inconsistent-directive.js74
1 files changed, 74 insertions, 0 deletions
diff --git a/js/src/tests/ecma_5/extensions/misplaced-inconsistent-directive.js b/js/src/tests/ecma_5/extensions/misplaced-inconsistent-directive.js
new file mode 100644
index 000000000..b7b33001c
--- /dev/null
+++ b/js/src/tests/ecma_5/extensions/misplaced-inconsistent-directive.js
@@ -0,0 +1,74 @@
+// |reftest| skip-if(!xulRuntime.shell) -- needs evaluate()
+/*
+ * Any copyright is dedicated to the Public Domain.
+ * http://creativecommons.org/licenses/publicdomain/
+ * Contributor:
+ * Jeff Walden <jwalden+code@mit.edu>
+ */
+
+//-----------------------------------------------------------------------------
+var BUGNUMBER = 1046964;
+var summary =
+ "Misplaced directives (e.g. 'use strict') should trigger warnings if they " +
+ "contradict the actually-used semantics";
+
+print(BUGNUMBER + ": " + summary);
+
+/**************
+ * BEGIN TEST *
+ **************/
+
+options("strict");
+options("werror");
+
+function evaluateNoRval(code)
+{
+ evaluate(code, { isRunOnce: true, noScriptRval: true });
+}
+
+function expectSyntaxError(code)
+{
+ try
+ {
+ evaluateNoRval(code);
+ throw new Error("didn't throw");
+ }
+ catch (e)
+ {
+ assertEq(e instanceof SyntaxError, true,
+ "should have thrown a SyntaxError, instead got:\n" +
+ " " + e + "\n" +
+ "when evaluating:\n" +
+ " " + code);
+ }
+}
+
+expectSyntaxError("function f1() {} 'use strict'; function f2() {}");
+expectSyntaxError("function f3() { var x; 'use strict'; }");
+
+if (isAsmJSCompilationAvailable())
+ expectSyntaxError("function f4() {} 'use asm'; function f5() {}");
+expectSyntaxError("function f6() { var x; 'use strict'; }");
+if (isAsmJSCompilationAvailable())
+ expectSyntaxError("'use asm'; function f7() {}");
+
+// No errors expected -- useless non-directives, but not contrary to used
+// semantics.
+evaluateNoRval("'use strict'; function f8() {} 'use strict'; function f9() {}");
+evaluateNoRval("'use strict'; function f10() { var z; 'use strict' }");
+
+if (isAsmJSCompilationAvailable()) {
+ try {
+ evaluateNoRval("function f11() { 'use asm'; return {}; }");
+ } catch(e) {
+ if (!e.toString().includes("Successfully compiled asm.js code"))
+ throw e;
+ }
+}
+
+/******************************************************************************/
+
+if (typeof reportCompare === "function")
+ reportCompare(true, true);
+
+print("Tests complete");