mirror of
https://github.com/tc39/test262.git
synced 2025-07-27 07:54:41 +02:00
Update for new eval
restrictions on super
(#781)
A recent change to the specification [1] introduces parse-time errors for certain usages of `super` within eval code. Modify all tests that are affected by this change: - Update the test bodies to accurately enforce the new semantics - Rename files to better reflect the section of the specification that they enforce - Update test meta-data - Change the `esid` meta-data to reflect the location of the relevant specification text - Remove the `es6id` meta-data as the behavior is no longer relatable to that specification - Introduce the `features` meta-data in cases where the test file's new location no longer reflects all required language features [1] "Normative: Clarify rules around super inside eval" https://github.com/tc39/ecma262/pull/685
This commit is contained in:
parent
71e573f7da
commit
720c3cc8cc
@ -1,16 +1,33 @@
|
|||||||
// Copyright (C) 2016 the V8 project authors. All rights reserved.
|
// Copyright (C) 2016 the V8 project authors. All rights reserved.
|
||||||
// This code is governed by the BSD license found in the LICENSE file.
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
/*---
|
/*---
|
||||||
esid: sec-scripts-static-semantics-early-errors
|
esid: sec-performeval
|
||||||
es6id: 15.1.1
|
|
||||||
description: >
|
description: >
|
||||||
A direct eval in the functon code of a non-ArrowFunction may contain
|
A direct eval in the functon code of a non-ArrowFunction may not contain
|
||||||
SuperCall
|
SuperCall
|
||||||
info: |
|
info: |
|
||||||
- It is a Syntax Error if StatementList Contains super unless the source code
|
[...]
|
||||||
containing super is eval code that is being processed by a direct eval that
|
4. Let inMethod be false.
|
||||||
is contained in function code that is not the function code of an
|
5. Let inConstructor be false.
|
||||||
ArrowFunction.
|
6. If thisEnvRec has a [[HomeObject]] field, then
|
||||||
|
a. Let inMethod be true.
|
||||||
|
b. If thisEnvRec.[[FunctionObject]] has a [[Construct]] field, let
|
||||||
|
inConstructor be true.
|
||||||
|
7. Let script be the ECMAScript code that is the result of parsing x,
|
||||||
|
interpreted as UTF-16 encoded Unicode text as described in 6.1.4, for the
|
||||||
|
goal symbol Script. If inMethod is false, additional early error rules
|
||||||
|
from 18.2.1.1.1 are applied. If inConstructor is false, additional early
|
||||||
|
error rules from 18.2.1.1.2 are applied. If the parse fails, throw a
|
||||||
|
SyntaxError exception. If any early errors are detected, throw a
|
||||||
|
SyntaxError or a ReferenceError exception, depending on the type of the
|
||||||
|
error (but see also clause 16). Parsing and early error detection may be
|
||||||
|
interweaved in an implementation dependent manner.
|
||||||
|
|
||||||
|
18.2.1.1.1 Additional Early Error Rules for Eval Outside Methods
|
||||||
|
|
||||||
|
ScriptBody : StatementList
|
||||||
|
|
||||||
|
- It is a Syntax Error if StatementList contains super.
|
||||||
features: [super]
|
features: [super]
|
||||||
---*/
|
---*/
|
||||||
|
|
||||||
@ -19,8 +36,8 @@ function f() {
|
|||||||
eval('executed = true; super();');
|
eval('executed = true; super();');
|
||||||
}
|
}
|
||||||
|
|
||||||
assert.throws(ReferenceError, function() {
|
assert.throws(SyntaxError, function() {
|
||||||
f();
|
f();
|
||||||
});
|
});
|
||||||
|
|
||||||
assert.sameValue(executed, true);
|
assert.sameValue(executed, false);
|
||||||
|
49
test/language/eval-code/direct/super-call-method.js
Normal file
49
test/language/eval-code/direct/super-call-method.js
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
// Copyright (C) 2016 the V8 project authors. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
/*---
|
||||||
|
esid: sec-performeval
|
||||||
|
description: >
|
||||||
|
SuperCall may may only occur in eval code for direct eval within a
|
||||||
|
constructor method
|
||||||
|
info: |
|
||||||
|
[...]
|
||||||
|
4. Let inMethod be false.
|
||||||
|
5. Let inConstructor be false.
|
||||||
|
6. If thisEnvRec has a [[HomeObject]] field, then
|
||||||
|
a. Let inMethod be true.
|
||||||
|
b. If thisEnvRec.[[FunctionObject]] has a [[Construct]] field, let
|
||||||
|
inConstructor be true.
|
||||||
|
7. Let script be the ECMAScript code that is the result of parsing x,
|
||||||
|
interpreted as UTF-16 encoded Unicode text as described in 6.1.4, for the
|
||||||
|
goal symbol Script. If inMethod is false, additional early error rules
|
||||||
|
from 18.2.1.1.1 are applied. If inConstructor is false, additional early
|
||||||
|
error rules from 18.2.1.1.2 are applied. If the parse fails, throw a
|
||||||
|
SyntaxError exception. If any early errors are detected, throw a
|
||||||
|
SyntaxError or a ReferenceError exception, depending on the type of the
|
||||||
|
error (but see also clause 16). Parsing and early error detection may be
|
||||||
|
interweaved in an implementation dependent manner.
|
||||||
|
|
||||||
|
18.2.1.1.1 Additional Early Error Rules for Eval Outside Methods
|
||||||
|
|
||||||
|
ScriptBody : StatementList
|
||||||
|
|
||||||
|
- It is a Syntax Error if StatementList contains super.
|
||||||
|
features: [super]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
var evaluatedArg = false;
|
||||||
|
var obj = {
|
||||||
|
method() {
|
||||||
|
// Early errors restricting the usage of SuperCall necessitate the use of
|
||||||
|
// `eval`.
|
||||||
|
eval('super(evaluatedArg = true);');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
assert.throws(SyntaxError, function() {
|
||||||
|
obj.method();
|
||||||
|
});
|
||||||
|
|
||||||
|
assert.sameValue(
|
||||||
|
evaluatedArg, false, 'did not perform ArgumentsListEvaluation'
|
||||||
|
);
|
47
test/language/eval-code/direct/super-prop-dot-no-home.js
Normal file
47
test/language/eval-code/direct/super-prop-dot-no-home.js
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
// Copyright (C) 2016 the V8 project authors. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
/*---
|
||||||
|
esid: sec-performeval
|
||||||
|
description: >
|
||||||
|
SuperProperty may may only occur in eval code for direct eval within a method
|
||||||
|
info: |
|
||||||
|
[...]
|
||||||
|
4. Let inMethod be false.
|
||||||
|
5. Let inConstructor be false.
|
||||||
|
6. If thisEnvRec has a [[HomeObject]] field, then
|
||||||
|
a. Let inMethod be true.
|
||||||
|
b. If thisEnvRec.[[FunctionObject]] has a [[Construct]] field, let
|
||||||
|
inConstructor be true.
|
||||||
|
7. Let script be the ECMAScript code that is the result of parsing x,
|
||||||
|
interpreted as UTF-16 encoded Unicode text as described in 6.1.4, for the
|
||||||
|
goal symbol Script. If inMethod is false, additional early error rules
|
||||||
|
from 18.2.1.1.1 are applied. If inConstructor is false, additional early
|
||||||
|
error rules from 18.2.1.1.2 are applied. If the parse fails, throw a
|
||||||
|
SyntaxError exception. If any early errors are detected, throw a
|
||||||
|
SyntaxError or a ReferenceError exception, depending on the type of the
|
||||||
|
error (but see also clause 16). Parsing and early error detection may be
|
||||||
|
interweaved in an implementation dependent manner.
|
||||||
|
|
||||||
|
18.2.1.1.1 Additional Early Error Rules for Eval Outside Methods
|
||||||
|
|
||||||
|
ScriptBody : StatementList
|
||||||
|
|
||||||
|
- It is a Syntax Error if StatementList contains super.
|
||||||
|
features: [super]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
var caught;
|
||||||
|
function f() {
|
||||||
|
// Early errors restricting the usage of SuperProperty necessitate the use of
|
||||||
|
// `eval`.
|
||||||
|
try {
|
||||||
|
eval('super.x;');
|
||||||
|
} catch (err) {
|
||||||
|
caught = err;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
f();
|
||||||
|
|
||||||
|
assert.sameValue(typeof caught, 'object');
|
||||||
|
assert.sameValue(caught.constructor, SyntaxError);
|
@ -0,0 +1,46 @@
|
|||||||
|
// Copyright (C) 2016 the V8 project authors. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
/*---
|
||||||
|
esid: sec-performeval
|
||||||
|
description: >
|
||||||
|
Expression is not evaluated prior to verification of "super" binding
|
||||||
|
info: |
|
||||||
|
[...]
|
||||||
|
4. Let inMethod be false.
|
||||||
|
5. Let inConstructor be false.
|
||||||
|
6. If thisEnvRec has a [[HomeObject]] field, then
|
||||||
|
a. Let inMethod be true.
|
||||||
|
b. If thisEnvRec.[[FunctionObject]] has a [[Construct]] field, let
|
||||||
|
inConstructor be true.
|
||||||
|
7. Let script be the ECMAScript code that is the result of parsing x,
|
||||||
|
interpreted as UTF-16 encoded Unicode text as described in 6.1.4, for the
|
||||||
|
goal symbol Script. If inMethod is false, additional early error rules
|
||||||
|
from 18.2.1.1.1 are applied. If inConstructor is false, additional early
|
||||||
|
error rules from 18.2.1.1.2 are applied. If the parse fails, throw a
|
||||||
|
SyntaxError exception. If any early errors are detected, throw a
|
||||||
|
SyntaxError or a ReferenceError exception, depending on the type of the
|
||||||
|
error (but see also clause 16). Parsing and early error detection may be
|
||||||
|
interweaved in an implementation dependent manner.
|
||||||
|
|
||||||
|
18.2.1.1.1 Additional Early Error Rules for Eval Outside Methods
|
||||||
|
|
||||||
|
ScriptBody : StatementList
|
||||||
|
|
||||||
|
- It is a Syntax Error if StatementList contains super.
|
||||||
|
features: [super]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
var evaluated = false;
|
||||||
|
function f() {
|
||||||
|
// Early errors restricting the usage of SuperProperty necessitate the use of
|
||||||
|
// `eval`.
|
||||||
|
try {
|
||||||
|
eval('super[evaluated = true];');
|
||||||
|
// Evaluation of SuperProperty is expected to fail in this context, but that
|
||||||
|
// behavior is tested elsewhere, so the error is discarded.
|
||||||
|
} catch (_) {}
|
||||||
|
}
|
||||||
|
|
||||||
|
f();
|
||||||
|
|
||||||
|
assert.sameValue(evaluated, false);
|
47
test/language/eval-code/direct/super-prop-expr-no-home.js
Normal file
47
test/language/eval-code/direct/super-prop-expr-no-home.js
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
// Copyright (C) 2016 the V8 project authors. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
/*---
|
||||||
|
esid: sec-performeval
|
||||||
|
description: >
|
||||||
|
SuperProperty may may only occur in eval code for direct eval within a method
|
||||||
|
info: |
|
||||||
|
[...]
|
||||||
|
4. Let inMethod be false.
|
||||||
|
5. Let inConstructor be false.
|
||||||
|
6. If thisEnvRec has a [[HomeObject]] field, then
|
||||||
|
a. Let inMethod be true.
|
||||||
|
b. If thisEnvRec.[[FunctionObject]] has a [[Construct]] field, let
|
||||||
|
inConstructor be true.
|
||||||
|
7. Let script be the ECMAScript code that is the result of parsing x,
|
||||||
|
interpreted as UTF-16 encoded Unicode text as described in 6.1.4, for the
|
||||||
|
goal symbol Script. If inMethod is false, additional early error rules
|
||||||
|
from 18.2.1.1.1 are applied. If inConstructor is false, additional early
|
||||||
|
error rules from 18.2.1.1.2 are applied. If the parse fails, throw a
|
||||||
|
SyntaxError exception. If any early errors are detected, throw a
|
||||||
|
SyntaxError or a ReferenceError exception, depending on the type of the
|
||||||
|
error (but see also clause 16). Parsing and early error detection may be
|
||||||
|
interweaved in an implementation dependent manner.
|
||||||
|
|
||||||
|
18.2.1.1.1 Additional Early Error Rules for Eval Outside Methods
|
||||||
|
|
||||||
|
ScriptBody : StatementList
|
||||||
|
|
||||||
|
- It is a Syntax Error if StatementList contains super.
|
||||||
|
features: [super]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
var caught;
|
||||||
|
function f() {
|
||||||
|
// Early errors restricting the usage of SuperProperty necessitate the use of
|
||||||
|
// `eval`.
|
||||||
|
try {
|
||||||
|
eval('super["x"];');
|
||||||
|
} catch (err) {
|
||||||
|
caught = err;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
f();
|
||||||
|
|
||||||
|
assert.sameValue(typeof caught, 'object');
|
||||||
|
assert.sameValue(caught.constructor, SyntaxError);
|
@ -1,25 +0,0 @@
|
|||||||
// Copyright (C) 2016 the V8 project authors. All rights reserved.
|
|
||||||
// This code is governed by the BSD license found in the LICENSE file.
|
|
||||||
/*---
|
|
||||||
esid: sec-super-keyword
|
|
||||||
es6id: 12.3.5
|
|
||||||
description: SuperCall requires that NewTarget is defined
|
|
||||||
info: |
|
|
||||||
1. Let newTarget be GetNewTarget().
|
|
||||||
2. If newTarget is undefined, throw a ReferenceError exception.
|
|
||||||
---*/
|
|
||||||
|
|
||||||
var evaluatedArg = false;
|
|
||||||
function f() {
|
|
||||||
// Early errors restricting the usage of SuperCall necessitate the use of
|
|
||||||
// `eval`.
|
|
||||||
eval('super(evaluatedArg = true);');
|
|
||||||
}
|
|
||||||
|
|
||||||
assert.throws(ReferenceError, function() {
|
|
||||||
f();
|
|
||||||
});
|
|
||||||
|
|
||||||
assert.sameValue(
|
|
||||||
evaluatedArg, false, 'did not perform ArgumentsListEvaluation'
|
|
||||||
);
|
|
@ -1,33 +0,0 @@
|
|||||||
// Copyright (C) 2016 the V8 project authors. All rights reserved.
|
|
||||||
// This code is governed by the BSD license found in the LICENSE file.
|
|
||||||
/*---
|
|
||||||
esid: sec-super-keyword
|
|
||||||
es6id: 12.3.5
|
|
||||||
description: ReferenceError is thrown when environment has no "super" binding
|
|
||||||
info: |
|
|
||||||
1. Let propertyKey be StringValue of IdentifierName.
|
|
||||||
2. If the code matched by the syntactic production that is being evaluated is
|
|
||||||
strict mode code, let strict be true, else let strict be false.
|
|
||||||
3. Return ? MakeSuperPropertyReference(propertyKey, strict).
|
|
||||||
|
|
||||||
12.3.5.3 Runtime Semantics: MakeSuperPropertyReference
|
|
||||||
|
|
||||||
1. Let env be GetThisEnvironment( ).
|
|
||||||
2. If env.HasSuperBinding() is false, throw a ReferenceError exception.
|
|
||||||
---*/
|
|
||||||
|
|
||||||
var caught;
|
|
||||||
function f() {
|
|
||||||
// Early errors restricting the usage of SuperProperty necessitate the use of
|
|
||||||
// `eval`.
|
|
||||||
try {
|
|
||||||
eval('super.x;');
|
|
||||||
} catch (err) {
|
|
||||||
caught = err;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
f();
|
|
||||||
|
|
||||||
assert.sameValue(typeof caught, 'object');
|
|
||||||
assert.sameValue(caught.constructor, ReferenceError);
|
|
@ -1,24 +0,0 @@
|
|||||||
// Copyright (C) 2016 the V8 project authors. All rights reserved.
|
|
||||||
// This code is governed by the BSD license found in the LICENSE file.
|
|
||||||
/*---
|
|
||||||
esid: sec-super-keyword
|
|
||||||
es6id: 12.3.5
|
|
||||||
description: Expression is evaluated prior to verification of "super" binding
|
|
||||||
info: |
|
|
||||||
1. Let propertyNameReference be the result of evaluating Expression.
|
|
||||||
---*/
|
|
||||||
|
|
||||||
var evaluated = false;
|
|
||||||
function f() {
|
|
||||||
// Early errors restricting the usage of SuperProperty necessitate the use of
|
|
||||||
// `eval`.
|
|
||||||
try {
|
|
||||||
eval('super[evaluated = true];');
|
|
||||||
// Evaluation of SuperProperty is expected to fail in this context, but that
|
|
||||||
// behavior is tested elsewhere, so the error is discarded.
|
|
||||||
} catch (_) {}
|
|
||||||
}
|
|
||||||
|
|
||||||
f();
|
|
||||||
|
|
||||||
assert.sameValue(evaluated, true);
|
|
@ -1,33 +0,0 @@
|
|||||||
// Copyright (C) 2016 the V8 project authors. All rights reserved.
|
|
||||||
// This code is governed by the BSD license found in the LICENSE file.
|
|
||||||
/*---
|
|
||||||
esid: sec-super-keyword
|
|
||||||
es6id: 12.3.5
|
|
||||||
description: ReferenceError is thrown when environment has no "super" binding
|
|
||||||
info: |
|
|
||||||
[...]
|
|
||||||
4. If the code matched by the syntactic production that is being evaluated is
|
|
||||||
strict mode code, let strict be true, else let strict be false.
|
|
||||||
5. Return ? MakeSuperPropertyReference(propertyKey, strict).
|
|
||||||
|
|
||||||
12.3.5.3 Runtime Semantics: MakeSuperPropertyReference
|
|
||||||
|
|
||||||
1. Let env be GetThisEnvironment( ).
|
|
||||||
2. If env.HasSuperBinding() is false, throw a ReferenceError exception.
|
|
||||||
---*/
|
|
||||||
|
|
||||||
var caught;
|
|
||||||
function f() {
|
|
||||||
// Early errors restricting the usage of SuperProperty necessitate the use of
|
|
||||||
// `eval`.
|
|
||||||
try {
|
|
||||||
eval('super["x"];');
|
|
||||||
} catch (err) {
|
|
||||||
caught = err;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
f();
|
|
||||||
|
|
||||||
assert.sameValue(typeof caught, 'object');
|
|
||||||
assert.sameValue(caught.constructor, ReferenceError);
|
|
Loading…
x
Reference in New Issue
Block a user