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.
This commit is contained in:
Mike Pennisi 2019-03-31 22:09:37 -04:00
parent 255338141b
commit 9b396d0b0b
10 changed files with 97 additions and 101 deletions

View File

@ -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) {};\
}\
");
});

View File

@ -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) {};\
}\
}\
");
});

View File

@ -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) {};\
}\
}\
");
});

View File

@ -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) {}; \
}\
");
});

View File

@ -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 ({}) {}

View File

@ -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) {};
}
}

View File

@ -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) {};
}
}

View File

@ -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) {};
}

View File

@ -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) {};
};

View File

@ -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){} } };