diff --git a/test/language/comments/hashbang/use-strict.js b/test/language/comments/hashbang/use-strict.js index 541c115cd9..962614c0bb 100644 --- a/test/language/comments/hashbang/use-strict.js +++ b/test/language/comments/hashbang/use-strict.js @@ -10,7 +10,7 @@ description: > info: | HashbangComment:: #! SingleLineCommentChars[opt] -flags: [raw, noStrict] +flags: [raw] features: [hashbang] ---*/ diff --git a/test/language/directive-prologue/10.1.1-2gs.js b/test/language/directive-prologue/10.1.1-2gs.js index 260dbb03fa..df4b4bcce6 100644 --- a/test/language/directive-prologue/10.1.1-2gs.js +++ b/test/language/directive-prologue/10.1.1-2gs.js @@ -13,5 +13,5 @@ flags: [raw] ---*/ "use strict" -throw new Error("This code should not execute"); +throw "Test262: This statement should not be evaluated."; var public = 1; diff --git a/test/language/directive-prologue/10.1.1-5gs.js b/test/language/directive-prologue/10.1.1-5gs.js index 1e216a68ca..f3f8e2acf1 100644 --- a/test/language/directive-prologue/10.1.1-5gs.js +++ b/test/language/directive-prologue/10.1.1-5gs.js @@ -13,5 +13,5 @@ flags: [raw] ---*/ "use strict"; -throw new Error("This code should not execute"); +throw "Test262: This statement should not be evaluated."; var public = 1; diff --git a/test/language/directive-prologue/10.1.1-8gs.js b/test/language/directive-prologue/10.1.1-8gs.js index 68b3b6500d..33f979ef05 100644 --- a/test/language/directive-prologue/10.1.1-8gs.js +++ b/test/language/directive-prologue/10.1.1-8gs.js @@ -14,5 +14,5 @@ flags: [raw] "use strict"; "use strict"; -throw new Error("This code should not execute"); +throw "Test262: This statement should not be evaluated."; var public = 1; diff --git a/test/language/directive-prologue/14.1-4gs.js b/test/language/directive-prologue/14.1-4gs.js index 7b8a942179..d401a5192f 100644 --- a/test/language/directive-prologue/14.1-4gs.js +++ b/test/language/directive-prologue/14.1-4gs.js @@ -13,5 +13,5 @@ flags: [raw] ---*/ "use strict"; -throw new Error("This code should not execute"); +throw "Test262: This statement should not be evaluated."; eval = 42; diff --git a/test/language/directive-prologue/14.1-5gs.js b/test/language/directive-prologue/14.1-5gs.js index 5837a1fde8..e1f2977e7a 100644 --- a/test/language/directive-prologue/14.1-5gs.js +++ b/test/language/directive-prologue/14.1-5gs.js @@ -15,5 +15,5 @@ flags: [raw] "a"; "use strict"; "c"; -throw new Error("This code should not execute"); +throw "Test262: This statement should not be evaluated."; eval = 42; diff --git a/test/language/directive-prologue/func-decl-inside-func-decl-parse.js b/test/language/directive-prologue/func-decl-inside-func-decl-parse.js index d540118e43..ab240cd754 100644 --- a/test/language/directive-prologue/func-decl-inside-func-decl-parse.js +++ b/test/language/directive-prologue/func-decl-inside-func-decl-parse.js @@ -9,11 +9,13 @@ description: > is strict function code if FunctionDeclaration is contained in use strict negative: - phase: early + phase: parse type: SyntaxError flags: [noStrict] ---*/ +$DONOTEVALUATE(); + function testcase() { "use strict"; function fun() { diff --git a/test/language/directive-prologue/func-decl-no-semi-parse.js b/test/language/directive-prologue/func-decl-no-semi-parse.js index 9135ff4b91..be56d0d140 100644 --- a/test/language/directive-prologue/func-decl-no-semi-parse.js +++ b/test/language/directive-prologue/func-decl-no-semi-parse.js @@ -8,11 +8,13 @@ description: > Strict Mode - Use Strict Directive Prologue is ''use strict'' which lost the last character ';' negative: - phase: early + phase: parse type: SyntaxError flags: [noStrict] ---*/ +$DONOTEVALUATE(); + function fun() { "use strict" var static; diff --git a/test/language/directive-prologue/func-decl-parse.js b/test/language/directive-prologue/func-decl-parse.js index 2740f3546e..6d347d6447 100644 --- a/test/language/directive-prologue/func-decl-parse.js +++ b/test/language/directive-prologue/func-decl-parse.js @@ -8,11 +8,13 @@ description: > Strict Mode - Function code of a FunctionDeclaration contains Use Strict Directive which appears at the start of the block negative: - phase: early + phase: parse type: SyntaxError flags: [noStrict] ---*/ +$DONOTEVALUATE(); + function fun() { "use strict"; var static; diff --git a/test/language/directive-prologue/func-expr-inside-func-decl-parse.js b/test/language/directive-prologue/func-expr-inside-func-decl-parse.js index 22e48b2a1f..e24e978f02 100644 --- a/test/language/directive-prologue/func-expr-inside-func-decl-parse.js +++ b/test/language/directive-prologue/func-expr-inside-func-decl-parse.js @@ -9,11 +9,13 @@ description: > is strict function code if FunctionExpression is contained in use strict negative: - phase: early + phase: parse type: SyntaxError flags: [noStrict] ---*/ +$DONOTEVALUATE(); + function testcase() { "use strict"; var static; diff --git a/test/language/directive-prologue/func-expr-no-semi-parse.js b/test/language/directive-prologue/func-expr-no-semi-parse.js index 404e1ac308..0d901f9dc6 100644 --- a/test/language/directive-prologue/func-expr-no-semi-parse.js +++ b/test/language/directive-prologue/func-expr-no-semi-parse.js @@ -8,11 +8,13 @@ description: > Strict Mode - Use Strict Directive Prologue is ''use strict'' which lost the last character ';' negative: - phase: early + phase: parse type: SyntaxError flags: [noStrict] ---*/ +$DONOTEVALUATE(); + (function() { "use strict" diff --git a/test/language/directive-prologue/func-expr-parse.js b/test/language/directive-prologue/func-expr-parse.js index b1239d2d49..e27c32dd73 100644 --- a/test/language/directive-prologue/func-expr-parse.js +++ b/test/language/directive-prologue/func-expr-parse.js @@ -8,11 +8,13 @@ description: > Strict Mode - Function code of a FunctionExpression contains Use Strict Directive which appears at the start of the block negative: - phase: early + phase: parse type: SyntaxError flags: [noStrict] ---*/ +$DONOTEVALUATE(); + (function() { "use strict"; diff --git a/test/language/expressions/import.meta/syntax/goal-script.js b/test/language/expressions/import.meta/syntax/goal-script.js index d2a1125c7e..882cd4785c 100644 --- a/test/language/expressions/import.meta/syntax/goal-script.js +++ b/test/language/expressions/import.meta/syntax/goal-script.js @@ -8,7 +8,7 @@ description: > info: | It is an early Syntax Error if Module is not the syntactic goal symbol. negative: - phase: early + phase: parse type: SyntaxError features: [import.meta] ---*/ diff --git a/test/language/expressions/import.meta/syntax/invalid-assignment-target-array-destructuring-expr.js b/test/language/expressions/import.meta/syntax/invalid-assignment-target-array-destructuring-expr.js index 1d7b0c1e50..65c9dc4b27 100644 --- a/test/language/expressions/import.meta/syntax/invalid-assignment-target-array-destructuring-expr.js +++ b/test/language/expressions/import.meta/syntax/invalid-assignment-target-array-destructuring-expr.js @@ -21,7 +21,7 @@ info: | and AssignmentTargetType(LeftHandSideExpression) is not simple. flags: [module] negative: - phase: early + phase: parse type: SyntaxError features: [import.meta, destructuring-assignment] ---*/ diff --git a/test/language/expressions/import.meta/syntax/invalid-assignment-target-array-rest-destructuring-expr.js b/test/language/expressions/import.meta/syntax/invalid-assignment-target-array-rest-destructuring-expr.js index 77a73fbd77..2bd4f477cb 100644 --- a/test/language/expressions/import.meta/syntax/invalid-assignment-target-array-rest-destructuring-expr.js +++ b/test/language/expressions/import.meta/syntax/invalid-assignment-target-array-rest-destructuring-expr.js @@ -21,7 +21,7 @@ info: | and AssignmentTargetType(LeftHandSideExpression) is not simple. flags: [module] negative: - phase: early + phase: parse type: SyntaxError features: [import.meta, destructuring-assignment] ---*/ diff --git a/test/language/expressions/import.meta/syntax/invalid-assignment-target-assignment-expr.js b/test/language/expressions/import.meta/syntax/invalid-assignment-target-assignment-expr.js index e51d624743..19b7408859 100644 --- a/test/language/expressions/import.meta/syntax/invalid-assignment-target-assignment-expr.js +++ b/test/language/expressions/import.meta/syntax/invalid-assignment-target-assignment-expr.js @@ -21,7 +21,7 @@ info: | ArrayLiteral and AssignmentTargetType of LeftHandSideExpression is invalid. flags: [module] negative: - phase: early + phase: parse type: ReferenceError features: [import.meta] ---*/ diff --git a/test/language/expressions/import.meta/syntax/invalid-assignment-target-for-await-of-loop.js b/test/language/expressions/import.meta/syntax/invalid-assignment-target-for-await-of-loop.js index 12907c55e0..a5c28cb3ad 100644 --- a/test/language/expressions/import.meta/syntax/invalid-assignment-target-for-await-of-loop.js +++ b/test/language/expressions/import.meta/syntax/invalid-assignment-target-for-await-of-loop.js @@ -20,7 +20,7 @@ info: | It is a Syntax Error if AssignmentTargetType of LeftHandSideExpression is not simple. flags: [module] negative: - phase: early + phase: parse type: SyntaxError features: [import.meta, async-iteration] ---*/ diff --git a/test/language/expressions/import.meta/syntax/invalid-assignment-target-for-in-loop.js b/test/language/expressions/import.meta/syntax/invalid-assignment-target-for-in-loop.js index 0088b1fb3d..84367470f0 100644 --- a/test/language/expressions/import.meta/syntax/invalid-assignment-target-for-in-loop.js +++ b/test/language/expressions/import.meta/syntax/invalid-assignment-target-for-in-loop.js @@ -20,7 +20,7 @@ info: | It is a Syntax Error if AssignmentTargetType of LeftHandSideExpression is not simple. flags: [module] negative: - phase: early + phase: parse type: SyntaxError features: [import.meta] ---*/ diff --git a/test/language/expressions/import.meta/syntax/invalid-assignment-target-for-of-loop.js b/test/language/expressions/import.meta/syntax/invalid-assignment-target-for-of-loop.js index 4b828f76b9..c7b3ea2595 100644 --- a/test/language/expressions/import.meta/syntax/invalid-assignment-target-for-of-loop.js +++ b/test/language/expressions/import.meta/syntax/invalid-assignment-target-for-of-loop.js @@ -20,7 +20,7 @@ info: | It is a Syntax Error if AssignmentTargetType of LeftHandSideExpression is not simple. flags: [module] negative: - phase: early + phase: parse type: SyntaxError features: [import.meta] ---*/ diff --git a/test/language/expressions/import.meta/syntax/invalid-assignment-target-object-destructuring-expr.js b/test/language/expressions/import.meta/syntax/invalid-assignment-target-object-destructuring-expr.js index dd18008d87..1c6bc2101b 100644 --- a/test/language/expressions/import.meta/syntax/invalid-assignment-target-object-destructuring-expr.js +++ b/test/language/expressions/import.meta/syntax/invalid-assignment-target-object-destructuring-expr.js @@ -21,7 +21,7 @@ info: | and AssignmentTargetType(LeftHandSideExpression) is not simple. flags: [module] negative: - phase: early + phase: parse type: SyntaxError features: [import.meta, destructuring-assignment] ---*/ diff --git a/test/language/expressions/import.meta/syntax/invalid-assignment-target-object-rest-destructuring-expr.js b/test/language/expressions/import.meta/syntax/invalid-assignment-target-object-rest-destructuring-expr.js index 65aa86c9a0..b4fde0ec8d 100644 --- a/test/language/expressions/import.meta/syntax/invalid-assignment-target-object-rest-destructuring-expr.js +++ b/test/language/expressions/import.meta/syntax/invalid-assignment-target-object-rest-destructuring-expr.js @@ -21,7 +21,7 @@ info: | and AssignmentTargetType(LeftHandSideExpression) is not simple. flags: [module] negative: - phase: early + phase: parse type: SyntaxError features: [import.meta, destructuring-assignment, object-rest] ---*/ diff --git a/test/language/expressions/import.meta/syntax/invalid-assignment-target-update-expr.js b/test/language/expressions/import.meta/syntax/invalid-assignment-target-update-expr.js index 0b7d4642d0..5d50f62d09 100644 --- a/test/language/expressions/import.meta/syntax/invalid-assignment-target-update-expr.js +++ b/test/language/expressions/import.meta/syntax/invalid-assignment-target-update-expr.js @@ -22,7 +22,7 @@ info: | It is an early Reference Error if AssignmentTargetType of LeftHandSideExpression is invalid. flags: [module] negative: - phase: early + phase: parse type: ReferenceError features: [import.meta] ---*/ diff --git a/tools/lint/lib/checks/flags.py b/tools/lint/lib/checks/flags.py new file mode 100644 index 0000000000..4b5f1595d7 --- /dev/null +++ b/tools/lint/lib/checks/flags.py @@ -0,0 +1,36 @@ +from ..check import Check + +class CheckFlags(Check): + '''Ensure tests don't contain any contradicting or redundant flag combinations.''' + ID = 'FLAGS' + + def run(self, name, meta, source): + if meta is None or meta.get('flags') is None: + return + + flags = meta['flags'] + + onlyStrict = 'onlyStrict' in flags + noStrict = 'noStrict' in flags + module = 'module' in flags + raw = 'raw' in flags + canBlockIsFalse = 'CanBlockIsFalse' in flags + canBlockIsTrue = 'CanBlockIsTrue' in flags + + if onlyStrict and noStrict: + return '"onlyStrict" and "noStrict" flags are mutually exclusive' + + if canBlockIsFalse and canBlockIsTrue: + return '"CanBlockIsFalse" and "CanBlockIsTrue" flags are mutually exclusive' + + if raw and onlyStrict: + return 'Raw tests cannot prepend a "use strict" directive' + + if raw and noStrict: + return '"raw" flag implies no "use strict" directive should be prepended' + + if module and onlyStrict: + return 'Module tests cannot be run in non-strict mode' + + if module and noStrict: + return '"module" flag implies the test is run in strict mode' diff --git a/tools/lint/lib/checks/negative.py b/tools/lint/lib/checks/negative.py old mode 100755 new mode 100644 index 4357aa4d32..2b9d6c08a0 --- a/tools/lint/lib/checks/negative.py +++ b/tools/lint/lib/checks/negative.py @@ -27,6 +27,9 @@ class CheckNegative(Check): if not 'phase' in negative: return '"negative" must specify a "phase" field' + if negative["phase"] not in ["parse", "resolution", "runtime"]: + return '"phase" must be one of ["parse", "resolution", "runtime"]' + if negative["phase"] in ["parse", "resolution"]: if meta.get('flags') and 'raw' in meta['flags']: if not _THROW_STMT_LEGACY.search(source): diff --git a/tools/lint/lint.py b/tools/lint/lint.py index 07d99e90eb..cac68bf25a 100755 --- a/tools/lint/lint.py +++ b/tools/lint/lint.py @@ -38,6 +38,7 @@ from lib.checks.license import CheckLicense from lib.checks.negative import CheckNegative from lib.checks.filename import CheckFileName from lib.checks.nopadding import CheckNoPadding +from lib.checks.flags import CheckFlags from lib.eprint import eprint import lib.frontmatter import lib.exceptions @@ -59,7 +60,8 @@ checks = [ CheckHarness(), CheckLicense(), CheckNegative(), - CheckNoPadding() + CheckNoPadding(), + CheckFlags(), ] def lint(file_names): diff --git a/tools/lint/test/fixtures/flags_canblock_true_and_false.js b/tools/lint/test/fixtures/flags_canblock_true_and_false.js new file mode 100644 index 0000000000..0b6313d83e --- /dev/null +++ b/tools/lint/test/fixtures/flags_canblock_true_and_false.js @@ -0,0 +1,9 @@ +FLAGS +^ expected errors | v input +// Copyright (C) 2019 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-assignment-operators-static-semantics-early-errors +description: Minimal test +flags: [CanBlockIsFalse, CanBlockIsTrue] +---*/ diff --git a/tools/lint/test/fixtures/flags_module_and_noStrict.js b/tools/lint/test/fixtures/flags_module_and_noStrict.js new file mode 100644 index 0000000000..bbe048d70c --- /dev/null +++ b/tools/lint/test/fixtures/flags_module_and_noStrict.js @@ -0,0 +1,9 @@ +FLAGS +^ expected errors | v input +// Copyright (C) 2019 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-assignment-operators-static-semantics-early-errors +description: Minimal test +flags: [module, noStrict] +---*/ diff --git a/tools/lint/test/fixtures/flags_module_and_onlyStrict.js b/tools/lint/test/fixtures/flags_module_and_onlyStrict.js new file mode 100644 index 0000000000..7cc869d424 --- /dev/null +++ b/tools/lint/test/fixtures/flags_module_and_onlyStrict.js @@ -0,0 +1,9 @@ +FLAGS +^ expected errors | v input +// Copyright (C) 2019 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-assignment-operators-static-semantics-early-errors +description: Minimal test +flags: [module, onlyStrict] +---*/ diff --git a/tools/lint/test/fixtures/flags_onlyStrict_and_noStrict.js b/tools/lint/test/fixtures/flags_onlyStrict_and_noStrict.js new file mode 100644 index 0000000000..177d4084b7 --- /dev/null +++ b/tools/lint/test/fixtures/flags_onlyStrict_and_noStrict.js @@ -0,0 +1,9 @@ +FLAGS +^ expected errors | v input +// Copyright (C) 2019 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-assignment-operators-static-semantics-early-errors +description: Minimal test +flags: [onlyStrict, noStrict] +---*/ diff --git a/tools/lint/test/fixtures/flags_raw_and_noStrict.js b/tools/lint/test/fixtures/flags_raw_and_noStrict.js new file mode 100644 index 0000000000..280ffaf161 --- /dev/null +++ b/tools/lint/test/fixtures/flags_raw_and_noStrict.js @@ -0,0 +1,9 @@ +FLAGS +^ expected errors | v input +// Copyright (C) 2019 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-assignment-operators-static-semantics-early-errors +description: Minimal test +flags: [raw, noStrict] +---*/ diff --git a/tools/lint/test/fixtures/flags_raw_and_onlyStrict.js b/tools/lint/test/fixtures/flags_raw_and_onlyStrict.js new file mode 100644 index 0000000000..49300911e0 --- /dev/null +++ b/tools/lint/test/fixtures/flags_raw_and_onlyStrict.js @@ -0,0 +1,9 @@ +FLAGS +^ expected errors | v input +// Copyright (C) 2019 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-assignment-operators-static-semantics-early-errors +description: Minimal test +flags: [raw, onlyStrict] +---*/ diff --git a/tools/lint/test/fixtures/negative_invalid_phase.js b/tools/lint/test/fixtures/negative_invalid_phase.js new file mode 100644 index 0000000000..e960a59a33 --- /dev/null +++ b/tools/lint/test/fixtures/negative_invalid_phase.js @@ -0,0 +1,16 @@ +NEGATIVE +^ expected errors | v input +// Copyright (C) 2019 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-assignment-operators-static-semantics-early-errors +description: Minimal test +negative: + type: SyntaxError + phase: early +flags: [raw] +---*/ + +$DONOTEVALUATE(); + +!!!