mirror of
https://github.com/tc39/test262.git
synced 2025-07-26 07:25:15 +02:00
Add tests for TCO with eval and cross-realm cases
This commit is contained in:
parent
d231b90ea8
commit
f4151fdbc0
@ -0,0 +1,39 @@
|
|||||||
|
// Copyright (C) 2017 André Bargull. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
|
||||||
|
/*---
|
||||||
|
id: sec-function-calls-runtime-semantics-evaluation
|
||||||
|
info: >
|
||||||
|
Check TypeError is thrown from correct realm with tco-call to class constructor from derived
|
||||||
|
class [[Construct]] invocation.
|
||||||
|
description: |
|
||||||
|
12.3.4.3 Runtime Semantics: EvaluateDirectCall( func, thisValue, arguments, tailPosition )
|
||||||
|
...
|
||||||
|
4. If tailPosition is true, perform PrepareForTailCall().
|
||||||
|
5. Let result be Call(func, thisValue, argList).
|
||||||
|
6. Assert: If tailPosition is true, the above call will not return here, but instead evaluation will continue as if the following return has already occurred.
|
||||||
|
7. Assert: If result is not an abrupt completion, then Type(result) is an ECMAScript language type.
|
||||||
|
8. Return result.
|
||||||
|
|
||||||
|
9.2.1 [[Call]] ( thisArgument, argumentsList)
|
||||||
|
...
|
||||||
|
2. If F.[[FunctionKind]] is "classConstructor", throw a TypeError exception.
|
||||||
|
3. Let callerContext be the running execution context.
|
||||||
|
4. Let calleeContext be PrepareForOrdinaryCall(F, undefined).
|
||||||
|
5. Assert: calleeContext is now the running execution context.
|
||||||
|
...
|
||||||
|
|
||||||
|
features: [tail-call-optimization, class]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
// - The class constructor call is in a valid tail-call position, which means PrepareForTailCall is performed.
|
||||||
|
// - The function call returns from `otherRealm` and proceeds the tail-call in this realm.
|
||||||
|
// - Calling the class constructor throws a TypeError from the current realm, that means this realm and not `otherRealm`.
|
||||||
|
var code = "(class { constructor() { return (class {})(); } });";
|
||||||
|
|
||||||
|
var otherRealm = $262.createRealm();
|
||||||
|
var tco = otherRealm.evalScript(code);
|
||||||
|
|
||||||
|
assert.throws(TypeError, function() {
|
||||||
|
new tco();
|
||||||
|
});
|
@ -0,0 +1,39 @@
|
|||||||
|
// Copyright (C) 2017 André Bargull. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
|
||||||
|
/*---
|
||||||
|
id: sec-function-calls-runtime-semantics-evaluation
|
||||||
|
info: >
|
||||||
|
Check TypeError is thrown from correct realm with tco-call to class constructor from
|
||||||
|
class [[Construct]] invocation.
|
||||||
|
description: |
|
||||||
|
12.3.4.3 Runtime Semantics: EvaluateDirectCall( func, thisValue, arguments, tailPosition )
|
||||||
|
...
|
||||||
|
4. If tailPosition is true, perform PrepareForTailCall().
|
||||||
|
5. Let result be Call(func, thisValue, argList).
|
||||||
|
6. Assert: If tailPosition is true, the above call will not return here, but instead evaluation will continue as if the following return has already occurred.
|
||||||
|
7. Assert: If result is not an abrupt completion, then Type(result) is an ECMAScript language type.
|
||||||
|
8. Return result.
|
||||||
|
|
||||||
|
9.2.1 [[Call]] ( thisArgument, argumentsList)
|
||||||
|
...
|
||||||
|
2. If F.[[FunctionKind]] is "classConstructor", throw a TypeError exception.
|
||||||
|
3. Let callerContext be the running execution context.
|
||||||
|
4. Let calleeContext be PrepareForOrdinaryCall(F, undefined).
|
||||||
|
5. Assert: calleeContext is now the running execution context.
|
||||||
|
...
|
||||||
|
|
||||||
|
features: [tail-call-optimization, class]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
// - The class constructor call is in a valid tail-call position, which means PrepareForTailCall is performed.
|
||||||
|
// - The function call returns from `otherRealm` and proceeds the tail-call in this realm.
|
||||||
|
// - Calling the class constructor throws a TypeError from the current realm, that means this realm and not `otherRealm`.
|
||||||
|
var code = "(class extends Object { constructor() { return (class {})(); } });";
|
||||||
|
|
||||||
|
var otherRealm = $262.createRealm();
|
||||||
|
var tco = otherRealm.evalScript(code);
|
||||||
|
|
||||||
|
assert.throws(TypeError, function() {
|
||||||
|
new tco();
|
||||||
|
});
|
38
test/language/expressions/call/tco-cross-realm-fun-call.js
Normal file
38
test/language/expressions/call/tco-cross-realm-fun-call.js
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
// Copyright (C) 2017 André Bargull. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
|
||||||
|
/*---
|
||||||
|
id: sec-function-calls-runtime-semantics-evaluation
|
||||||
|
info: >
|
||||||
|
Check TypeError is thrown from correct realm with tco-call to class constructor from [[Call]] invocation.
|
||||||
|
description: |
|
||||||
|
12.3.4.3 Runtime Semantics: EvaluateDirectCall( func, thisValue, arguments, tailPosition )
|
||||||
|
...
|
||||||
|
4. If tailPosition is true, perform PrepareForTailCall().
|
||||||
|
5. Let result be Call(func, thisValue, argList).
|
||||||
|
6. Assert: If tailPosition is true, the above call will not return here, but instead evaluation will continue as if the following return has already occurred.
|
||||||
|
7. Assert: If result is not an abrupt completion, then Type(result) is an ECMAScript language type.
|
||||||
|
8. Return result.
|
||||||
|
|
||||||
|
9.2.1 [[Call]] ( thisArgument, argumentsList)
|
||||||
|
...
|
||||||
|
2. If F.[[FunctionKind]] is "classConstructor", throw a TypeError exception.
|
||||||
|
3. Let callerContext be the running execution context.
|
||||||
|
4. Let calleeContext be PrepareForOrdinaryCall(F, undefined).
|
||||||
|
5. Assert: calleeContext is now the running execution context.
|
||||||
|
...
|
||||||
|
|
||||||
|
features: [tail-call-optimization, class]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
// - The class constructor call is in a valid tail-call position, which means PrepareForTailCall is performed.
|
||||||
|
// - The function call returns from `otherRealm` and proceeds the tail-call in this realm.
|
||||||
|
// - Calling the class constructor throws a TypeError from the current realm, that means this realm and not `otherRealm`.
|
||||||
|
var code = "'use strict'; (function() { return (class {})(); });";
|
||||||
|
|
||||||
|
var otherRealm = $262.createRealm();
|
||||||
|
var tco = otherRealm.evalScript(code);
|
||||||
|
|
||||||
|
assert.throws(TypeError, function() {
|
||||||
|
tco();
|
||||||
|
});
|
@ -0,0 +1,38 @@
|
|||||||
|
// Copyright (C) 2017 André Bargull. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
|
||||||
|
/*---
|
||||||
|
id: sec-function-calls-runtime-semantics-evaluation
|
||||||
|
info: >
|
||||||
|
Check TypeError is thrown from correct realm with tco-call to class constructor from [[Construct]] invocation.
|
||||||
|
description: |
|
||||||
|
12.3.4.3 Runtime Semantics: EvaluateDirectCall( func, thisValue, arguments, tailPosition )
|
||||||
|
...
|
||||||
|
4. If tailPosition is true, perform PrepareForTailCall().
|
||||||
|
5. Let result be Call(func, thisValue, argList).
|
||||||
|
6. Assert: If tailPosition is true, the above call will not return here, but instead evaluation will continue as if the following return has already occurred.
|
||||||
|
7. Assert: If result is not an abrupt completion, then Type(result) is an ECMAScript language type.
|
||||||
|
8. Return result.
|
||||||
|
|
||||||
|
9.2.1 [[Call]] ( thisArgument, argumentsList)
|
||||||
|
...
|
||||||
|
2. If F.[[FunctionKind]] is "classConstructor", throw a TypeError exception.
|
||||||
|
3. Let callerContext be the running execution context.
|
||||||
|
4. Let calleeContext be PrepareForOrdinaryCall(F, undefined).
|
||||||
|
5. Assert: calleeContext is now the running execution context.
|
||||||
|
...
|
||||||
|
|
||||||
|
features: [tail-call-optimization, class]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
// - The class constructor call is in a valid tail-call position, which means PrepareForTailCall is performed.
|
||||||
|
// - The function call returns from `otherRealm` and proceeds the tail-call in this realm.
|
||||||
|
// - Calling the class constructor throws a TypeError from the current realm, that means this realm and not `otherRealm`.
|
||||||
|
var code = "'use strict'; (function() { return (class {})(); });";
|
||||||
|
|
||||||
|
var otherRealm = $262.createRealm();
|
||||||
|
var tco = otherRealm.evalScript(code);
|
||||||
|
|
||||||
|
assert.throws(TypeError, function() {
|
||||||
|
new tco();
|
||||||
|
});
|
@ -0,0 +1,44 @@
|
|||||||
|
// Copyright (C) 2017 André Bargull. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
|
||||||
|
/*---
|
||||||
|
id: sec-function-calls-runtime-semantics-evaluation
|
||||||
|
info: >
|
||||||
|
Tail-call with identifier named "eval" in function environment, local "eval" binding dynamically added.
|
||||||
|
description: |
|
||||||
|
12.3.4.1 Runtime Semantics: Evaluation
|
||||||
|
...
|
||||||
|
6. If Type(ref) is Reference and IsPropertyReference(ref) is false and
|
||||||
|
GetReferencedName(ref) is "eval", then
|
||||||
|
a. If SameValue(func, %eval%) is true, then
|
||||||
|
...
|
||||||
|
...
|
||||||
|
9. Return ? EvaluateCall(func, ref, arguments, tailCall).
|
||||||
|
|
||||||
|
12.3.4.2 Runtime Semantics: EvaluateCall( func, ref, arguments, tailPosition )
|
||||||
|
...
|
||||||
|
7. If tailPosition is true, perform PrepareForTailCall().
|
||||||
|
8. Let result be Call(func, thisValue, argList).
|
||||||
|
...
|
||||||
|
|
||||||
|
flags: [noStrict]
|
||||||
|
features: [tail-call-optimization]
|
||||||
|
includes: [tcoHelper.js]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
var callCount = 0;
|
||||||
|
|
||||||
|
(function() {
|
||||||
|
function f(n) {
|
||||||
|
"use strict";
|
||||||
|
if (n === 0) {
|
||||||
|
callCount += 1
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
return eval(n - 1);
|
||||||
|
}
|
||||||
|
eval("var eval = f;");
|
||||||
|
f($MAX_ITERATIONS);
|
||||||
|
})();
|
||||||
|
|
||||||
|
assert.sameValue(callCount, 1);
|
44
test/language/expressions/call/tco-non-eval-function.js
Normal file
44
test/language/expressions/call/tco-non-eval-function.js
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
// Copyright (C) 2017 André Bargull. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
|
||||||
|
/*---
|
||||||
|
id: sec-function-calls-runtime-semantics-evaluation
|
||||||
|
info: >
|
||||||
|
Tail-call with identifier named "eval" in function environment.
|
||||||
|
description: |
|
||||||
|
12.3.4.1 Runtime Semantics: Evaluation
|
||||||
|
...
|
||||||
|
6. If Type(ref) is Reference and IsPropertyReference(ref) is false and
|
||||||
|
GetReferencedName(ref) is "eval", then
|
||||||
|
a. If SameValue(func, %eval%) is true, then
|
||||||
|
...
|
||||||
|
...
|
||||||
|
9. Return ? EvaluateCall(func, ref, arguments, tailCall).
|
||||||
|
|
||||||
|
12.3.4.2 Runtime Semantics: EvaluateCall( func, ref, arguments, tailPosition )
|
||||||
|
...
|
||||||
|
7. If tailPosition is true, perform PrepareForTailCall().
|
||||||
|
8. Let result be Call(func, thisValue, argList).
|
||||||
|
...
|
||||||
|
|
||||||
|
flags: [noStrict]
|
||||||
|
features: [tail-call-optimization]
|
||||||
|
includes: [tcoHelper.js]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
var callCount = 0;
|
||||||
|
|
||||||
|
(function() {
|
||||||
|
function f(n) {
|
||||||
|
"use strict";
|
||||||
|
if (n === 0) {
|
||||||
|
callCount += 1
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
return eval(n - 1);
|
||||||
|
}
|
||||||
|
var eval = f;
|
||||||
|
f($MAX_ITERATIONS);
|
||||||
|
})();
|
||||||
|
|
||||||
|
assert.sameValue(callCount, 1);
|
43
test/language/expressions/call/tco-non-eval-global.js
Normal file
43
test/language/expressions/call/tco-non-eval-global.js
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
// Copyright (C) 2017 André Bargull. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
|
||||||
|
/*---
|
||||||
|
id: sec-function-calls-runtime-semantics-evaluation
|
||||||
|
info: >
|
||||||
|
Tail-call with identifier named "eval" in global environment.
|
||||||
|
description: |
|
||||||
|
12.3.4.1 Runtime Semantics: Evaluation
|
||||||
|
...
|
||||||
|
6. If Type(ref) is Reference and IsPropertyReference(ref) is false and
|
||||||
|
GetReferencedName(ref) is "eval", then
|
||||||
|
a. If SameValue(func, %eval%) is true, then
|
||||||
|
...
|
||||||
|
...
|
||||||
|
9. Return ? EvaluateCall(func, ref, arguments, tailCall).
|
||||||
|
|
||||||
|
12.3.4.2 Runtime Semantics: EvaluateCall( func, ref, arguments, tailPosition )
|
||||||
|
...
|
||||||
|
7. If tailPosition is true, perform PrepareForTailCall().
|
||||||
|
8. Let result be Call(func, thisValue, argList).
|
||||||
|
...
|
||||||
|
|
||||||
|
flags: [noStrict]
|
||||||
|
features: [tail-call-optimization]
|
||||||
|
includes: [tcoHelper.js]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
var callCount = 0;
|
||||||
|
|
||||||
|
function f(n) {
|
||||||
|
"use strict";
|
||||||
|
if (n === 0) {
|
||||||
|
callCount += 1
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
return eval(n - 1);
|
||||||
|
}
|
||||||
|
eval = f;
|
||||||
|
|
||||||
|
f($MAX_ITERATIONS);
|
||||||
|
|
||||||
|
assert.sameValue(callCount, 1);
|
46
test/language/expressions/call/tco-non-eval-with.js
Normal file
46
test/language/expressions/call/tco-non-eval-with.js
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
// Copyright (C) 2017 André Bargull. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
|
||||||
|
/*---
|
||||||
|
id: sec-function-calls-runtime-semantics-evaluation
|
||||||
|
info: >
|
||||||
|
Tail-call with identifier named "eval" in object environment.
|
||||||
|
description: |
|
||||||
|
12.3.4.1 Runtime Semantics: Evaluation
|
||||||
|
...
|
||||||
|
6. If Type(ref) is Reference and IsPropertyReference(ref) is false and
|
||||||
|
GetReferencedName(ref) is "eval", then
|
||||||
|
a. If SameValue(func, %eval%) is true, then
|
||||||
|
...
|
||||||
|
...
|
||||||
|
9. Return ? EvaluateCall(func, ref, arguments, tailCall).
|
||||||
|
|
||||||
|
12.3.4.2 Runtime Semantics: EvaluateCall( func, ref, arguments, tailPosition )
|
||||||
|
...
|
||||||
|
7. If tailPosition is true, perform PrepareForTailCall().
|
||||||
|
8. Let result be Call(func, thisValue, argList).
|
||||||
|
...
|
||||||
|
|
||||||
|
flags: [noStrict]
|
||||||
|
features: [tail-call-optimization]
|
||||||
|
includes: [tcoHelper.js]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
var callCount = 0;
|
||||||
|
|
||||||
|
var f, scope = {};
|
||||||
|
with (scope) {
|
||||||
|
f = function (n) {
|
||||||
|
"use strict";
|
||||||
|
if (n === 0) {
|
||||||
|
callCount += 1
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
return eval(n - 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
scope.eval = f;
|
||||||
|
|
||||||
|
f($MAX_ITERATIONS);
|
||||||
|
|
||||||
|
assert.sameValue(callCount, 1);
|
Loading…
x
Reference in New Issue
Block a user