From 9b396d0b0b31aeb5616c72fe759b08e43b636464 Mon Sep 17 00:00:00 2001 From: Mike Pennisi Date: Sun, 31 Mar 2019 22:09:37 -0400 Subject: [PATCH] Refactor `with` statement tests for parsers The tests for the parsing of the `with` statement were expressed using eval. This made the tests more complex than necessary and also prevented the tests from providing value to ECMAScript parsers. Remove the use of eval and instead express the expectations with literal source text. Rename the files to make each test's purpose more clear. --- test/language/statements/with/12.10.1-1-s.js | 21 ---------------- test/language/statements/with/12.10.1-2-s.js | 25 ------------------- test/language/statements/with/12.10.1-3-s.js | 25 ------------------- test/language/statements/with/12.10.1-7-s.js | 20 --------------- .../with/{12.10.1-11-s.js => stict-script.js} | 12 +++++---- .../with/strict-fn-decl-nested-1.js | 23 +++++++++++++++++ .../with/strict-fn-decl-nested-2.js | 22 ++++++++++++++++ .../statements/with/strict-fn-decl.js | 19 ++++++++++++++ .../statements/with/strict-fn-expr.js | 19 ++++++++++++++ .../{12.10.1-14-s.js => strict-fn-method.js} | 12 +++++---- 10 files changed, 97 insertions(+), 101 deletions(-) delete mode 100644 test/language/statements/with/12.10.1-1-s.js delete mode 100644 test/language/statements/with/12.10.1-2-s.js delete mode 100644 test/language/statements/with/12.10.1-3-s.js delete mode 100644 test/language/statements/with/12.10.1-7-s.js rename test/language/statements/with/{12.10.1-11-s.js => stict-script.js} (52%) create mode 100644 test/language/statements/with/strict-fn-decl-nested-1.js create mode 100644 test/language/statements/with/strict-fn-decl-nested-2.js create mode 100644 test/language/statements/with/strict-fn-decl.js create mode 100644 test/language/statements/with/strict-fn-expr.js rename test/language/statements/with/{12.10.1-14-s.js => strict-fn-method.js} (50%) diff --git a/test/language/statements/with/12.10.1-1-s.js b/test/language/statements/with/12.10.1-1-s.js deleted file mode 100644 index 1407711469..0000000000 --- a/test/language/statements/with/12.10.1-1-s.js +++ /dev/null @@ -1,21 +0,0 @@ -// Copyright (c) 2012 Ecma International. All rights reserved. -// This code is governed by the BSD license found in the LICENSE file. - -/*--- -es5id: 12.10.1-1-s -description: with statement in strict mode throws SyntaxError (strict function) -flags: [noStrict] ----*/ - - -assert.throws(SyntaxError, function() { - // wrapping it in eval since this needs to be a syntax error. The - // exception thrown must be a SyntaxError exception. - eval("\ - function f() {\ - \'use strict\';\ - var o = {}; \ - with (o) {};\ - }\ - "); -}); diff --git a/test/language/statements/with/12.10.1-2-s.js b/test/language/statements/with/12.10.1-2-s.js deleted file mode 100644 index 639f81413f..0000000000 --- a/test/language/statements/with/12.10.1-2-s.js +++ /dev/null @@ -1,25 +0,0 @@ -// Copyright (c) 2012 Ecma International. All rights reserved. -// This code is governed by the BSD license found in the LICENSE file. - -/*--- -es5id: 12.10.1-2-s -description: > - with statement in strict mode throws SyntaxError (nested function - where container is strict) -flags: [noStrict] ----*/ - - -assert.throws(SyntaxError, function() { - // wrapping it in eval since this needs to be a syntax error. The - // exception thrown must be a SyntaxError exception. - eval("\ - function foo() {\ - \'use strict\'; \ - function f() {\ - var o = {}; \ - with (o) {};\ - }\ - }\ - "); -}); diff --git a/test/language/statements/with/12.10.1-3-s.js b/test/language/statements/with/12.10.1-3-s.js deleted file mode 100644 index 922d035960..0000000000 --- a/test/language/statements/with/12.10.1-3-s.js +++ /dev/null @@ -1,25 +0,0 @@ -// Copyright (c) 2012 Ecma International. All rights reserved. -// This code is governed by the BSD license found in the LICENSE file. - -/*--- -es5id: 12.10.1-3-s -description: > - with statement in strict mode throws SyntaxError (nested strict - function) -flags: [noStrict] ----*/ - - -assert.throws(SyntaxError, function() { - // wrapping it in eval since this needs to be a syntax error. The - // exception thrown must be a SyntaxError exception. - eval("\ - function foo() {\ - function f() {\ - \'use strict\'; \ - var o = {}; \ - with (o) {};\ - }\ - }\ - "); -}); diff --git a/test/language/statements/with/12.10.1-7-s.js b/test/language/statements/with/12.10.1-7-s.js deleted file mode 100644 index 35d562653d..0000000000 --- a/test/language/statements/with/12.10.1-7-s.js +++ /dev/null @@ -1,20 +0,0 @@ -// Copyright (c) 2012 Ecma International. All rights reserved. -// This code is governed by the BSD license found in the LICENSE file. - -/*--- -es5id: 12.10.1-7-s -description: > - with statement in strict mode throws SyntaxError (function - expression, where the container function is directly evaled from - strict code) -flags: [onlyStrict] ----*/ - - -assert.throws(SyntaxError, function() { - eval("var f = function () {\ - var o = {}; \ - with (o) {}; \ - }\ - "); -}); diff --git a/test/language/statements/with/12.10.1-11-s.js b/test/language/statements/with/stict-script.js similarity index 52% rename from test/language/statements/with/12.10.1-11-s.js rename to test/language/statements/with/stict-script.js index 1b4e2e1f3e..9514530c03 100644 --- a/test/language/statements/with/12.10.1-11-s.js +++ b/test/language/statements/with/stict-script.js @@ -4,12 +4,14 @@ /*--- es5id: 12.10.1-11-s description: > - Strict Mode - SyntaxError is thrown when using WithStatement in - strict mode code + Strict Mode - SyntaxError is thrown when using WithStatement in strict mode + code +negative: + phase: parse + type: SyntaxError flags: [onlyStrict] ---*/ +$DONOTEVALUATE(); -assert.throws(SyntaxError, function() { - eval("with ({}) { throw new Error();}"); -}); +with ({}) {} diff --git a/test/language/statements/with/strict-fn-decl-nested-1.js b/test/language/statements/with/strict-fn-decl-nested-1.js new file mode 100644 index 0000000000..374c997828 --- /dev/null +++ b/test/language/statements/with/strict-fn-decl-nested-1.js @@ -0,0 +1,23 @@ +// Copyright (c) 2012 Ecma International. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +es5id: 12.10.1-2-s +description: > + with statement in strict mode throws SyntaxError (nested function where + container is strict) +negative: + phase: parse + type: SyntaxError +flags: [noStrict] +---*/ + +$DONOTEVALUATE(); + +function foo() { + 'use strict'; + function f() { + var o = {}; + with (o) {}; + } +} diff --git a/test/language/statements/with/strict-fn-decl-nested-2.js b/test/language/statements/with/strict-fn-decl-nested-2.js new file mode 100644 index 0000000000..447d0db42c --- /dev/null +++ b/test/language/statements/with/strict-fn-decl-nested-2.js @@ -0,0 +1,22 @@ +// Copyright (c) 2012 Ecma International. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +es5id: 12.10.1-3-s +description: > + with statement in strict mode throws SyntaxError (nested strict function) +negative: + phase: parse + type: SyntaxError +flags: [noStrict] +---*/ + +$DONOTEVALUATE(); + +function foo() { + function f() { + 'use strict'; + var o = {}; + with (o) {}; + } +} diff --git a/test/language/statements/with/strict-fn-decl.js b/test/language/statements/with/strict-fn-decl.js new file mode 100644 index 0000000000..b39477b21c --- /dev/null +++ b/test/language/statements/with/strict-fn-decl.js @@ -0,0 +1,19 @@ +// Copyright (c) 2012 Ecma International. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +es5id: 12.10.1-1-s +description: with statement in strict mode throws SyntaxError (strict function) +flags: [noStrict] +negative: + phase: parse + type: SyntaxError +---*/ + +$DONOTEVALUATE(); + +function f() { + 'use strict'; + var o = {}; + with (o) {}; +} diff --git a/test/language/statements/with/strict-fn-expr.js b/test/language/statements/with/strict-fn-expr.js new file mode 100644 index 0000000000..ad7d86d238 --- /dev/null +++ b/test/language/statements/with/strict-fn-expr.js @@ -0,0 +1,19 @@ +// Copyright (c) 2012 Ecma International. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +es5id: 12.10.1-7-s +description: > + with statement in strict mode throws SyntaxError (function expression) +negative: + phase: parse + type: SyntaxError +flags: [onlyStrict] +---*/ + +$DONOTEVALUATE(); + +var f = function () { + var o = {}; + with (o) {}; +}; diff --git a/test/language/statements/with/12.10.1-14-s.js b/test/language/statements/with/strict-fn-method.js similarity index 50% rename from test/language/statements/with/12.10.1-14-s.js rename to test/language/statements/with/strict-fn-method.js index 8c825e74b8..1eac303a73 100644 --- a/test/language/statements/with/12.10.1-14-s.js +++ b/test/language/statements/with/strict-fn-method.js @@ -4,12 +4,14 @@ /*--- es5id: 12.10.1-14-s description: > - Strict Mode - SyntaxError is thrown when the getter of a literal - object utilizes WithStatement + Strict Mode - SyntaxError is thrown when the getter of a literal object + utilizes WithStatement +negative: + phase: parse + type: SyntaxError flags: [onlyStrict] ---*/ +$DONOTEVALUATE(); -assert.throws(SyntaxError, function() { - eval("var obj = { get(a) { with(a){} } }; "); -}); +var obj = { get(a) { with(a){} } };