Debian Codegraph @

tests/auto/qml/ecmascripttests/test262/test/language/expressions/call/tco-cross-realm-fun-call.js

raw
1 // Copyright (C) 2017 André Bargull. All rights reserved.
2 // This code is governed by the BSD license found in the LICENSE file.
3
4 /*---
5 esid: sec-function-calls-runtime-semantics-evaluation
6 description: >
7 Check TypeError is thrown from correct realm with tco-call to class constructor from [[Call]] invocation.
8 info: |
9 12.3.4.3 Runtime Semantics: EvaluateDirectCall( func, thisValue, arguments, tailPosition )
10 ...
11 4. If tailPosition is true, perform PrepareForTailCall().
12 5. Let result be Call(func, thisValue, argList).
13 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.
14 7. Assert: If result is not an abrupt completion, then Type(result) is an ECMAScript language type.
15 8. Return result.
16
17 9.2.1 [[Call]] ( thisArgument, argumentsList)
18 ...
19 2. If F.[[FunctionKind]] is "classConstructor", throw a TypeError exception.
20 3. Let callerContext be the running execution context.
21 4. Let calleeContext be PrepareForOrdinaryCall(F, undefined).
22 5. Assert: calleeContext is now the running execution context.
23 ...
24
25 features: [tail-call-optimization, class]
26 ---*/
27
28 // - The class constructor call is in a valid tail-call position, which means PrepareForTailCall is performed.
29 // - The function call returns from `otherRealm` and proceeds the tail-call in this realm.
30 // - Calling the class constructor throws a TypeError from the current realm, that means this realm and not `otherRealm`.
31 var code = "'use strict'; (function() { return (class {})(); });";
32
33 var otherRealm = $262.createRealm();
34 var tco = otherRealm.evalScript(code);
35
36 assert.throws(TypeError, function() {
37 tco();
38 });