File: tco-cross-realm-class-derived-construct.js

package info (click to toggle)
qtdeclarative-opensource-src 5.15.8%2Bdfsg-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 259,256 kB
  • sloc: javascript: 512,396; cpp: 495,775; xml: 8,892; python: 3,304; ansic: 2,764; sh: 206; makefile: 62; php: 27
file content (39 lines) | stat: -rw-r--r-- 1,766 bytes parent folder | download | duplicates (11)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
// Copyright (C) 2017 André Bargull. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
esid: sec-function-calls-runtime-semantics-evaluation
description: >
  Check TypeError is thrown from correct realm with tco-call to class constructor from
  class [[Construct]] invocation.
info: |
  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();
});