summaryrefslogtreecommitdiffstats
path: root/js/src/tests/test262/language/expressions/super/call-proto-not-ctor.js
blob: d7728be750bff0b1ee2b22a3996b46362d7623e6 (plain)
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
40
41
42
43
// 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
description: SuperCall should evaluate Arguments prior to checking IsConstructor
info: |
  SuperCall : `super` Arguments

  [...]
  3. Let _func_ be ! GetSuperConstructor().
  4. Let _argList_ be ? ArgumentListEvaluation of |Arguments|.
  5. If IsConstructor(_func_) is *false*, throw a *TypeError* exception.
  [...]
features: [class]
---*/

var evaluatedArg = false;
var caught;
class C extends Object {
  constructor() {
    try {
      super(evaluatedArg = true);
    } catch (err) {
      caught = err;
    }
  }
}

Object.setPrototypeOf(C, parseInt);

// When the "construct" invocation completes and the "this" value is
// uninitialized, the specification dictates that a ReferenceError must be
// thrown. That behavior is tested elsewhere, so the error is ignored (if it is
// produced at all).
try {
  new C();
} catch (_) {}

assert.sameValue(typeof caught, 'object');
assert.sameValue(caught.constructor, TypeError);
assert(evaluatedArg, 'performs ArgumentsListEvaluation');

reportCompare(0, 0);