Debian Codegraph @

tests/auto/qml/ecmascripttests/test262/test/language/expressions/call/tco-cross-realm-class-derived-construct.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
8 class [[Construct]] invocation.
9 info: |
10 12.3.4.3 Runtime Semantics: EvaluateDirectCall( func, thisValue, arguments, tailPosition )
11 ...
12 4. If tailPosition is true, perform PrepareForTailCall().
13 5. Let result be Call(func, thisValue, argList).
14 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.
15 7. Assert: If result is not an abrupt completion, then Type(result) is an ECMAScript language type.
16 8. Return result.
17
18 9.2.1 [[Call]] ( thisArgument, argumentsList)
19 ...
20 2. If F.[[FunctionKind]] is "classConstructor", throw a TypeError exception.
21 3. Let callerContext be the running execution context.
22 4. Let calleeContext be PrepareForOrdinaryCall(F, undefined).
23 5. Assert: calleeContext is now the running execution context.
24 ...
25
26 features: [tail-call-optimization, class]
27 ---*/
28
29 // - The class constructor call is in a valid tail-call position, which means PrepareForTailCall is performed.
30 // - The function call returns from `otherRealm` and proceeds the tail-call in this realm.
31 // - Calling the class constructor throws a TypeError from the current realm, that means this realm and not `otherRealm`.
32 var code = "(class extends Object { constructor() { return (class {})(); } });";
33
34 var otherRealm = $262.createRealm();
35 var tco = otherRealm.evalScript(code);
36
37 assert.throws(TypeError, function() {
38 new tco();
39 });