blob: b7b33001c481975735a2d62a5f665b876849bbbc (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
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");
|