summaryrefslogtreecommitdiffstats
path: root/js/src/tests/test262/language/statements/class/subclass/default-constructor-2.js
blob: e5a984401dedb4d7430e75b792e88e34714ea69f (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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
// Copyright (C) 2014 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 14.5
description: >
    class default constructor 2
---*/
class Base1 { }
assert.throws(TypeError, function() { Base1(); });

class Subclass1 extends Base1 { }

assert.throws(TypeError, function() { Subclass1(); });

var s1 = new Subclass1();
assert.sameValue(
  Subclass1.prototype,
  Object.getPrototypeOf(s1),
  "The value of `Subclass1.prototype` is `Object.getPrototypeOf(s1)`, after executing `var s1 = new Subclass1();`"
);

class Base2 {
  constructor(x, y) {
    this.x = x;
    this.y = y;
  }
}

class Subclass2 extends Base2 {};

var s2 = new Subclass2(1, 2);

assert.sameValue(
  Subclass2.prototype,
  Object.getPrototypeOf(s2),
  "The value of `Subclass2.prototype` is `Object.getPrototypeOf(s2)`, after executing `var s2 = new Subclass2(1, 2);`"
);
assert.sameValue(s2.x, 1, "The value of `s2.x` is `1`");
assert.sameValue(s2.y, 2, "The value of `s2.y` is `2`");

var f = Subclass2.bind({}, 3, 4);
var s2prime = new f();
assert.sameValue(
  Subclass2.prototype,
  Object.getPrototypeOf(s2prime),
  "The value of `Subclass2.prototype` is `Object.getPrototypeOf(s2prime)`"
);
assert.sameValue(s2prime.x, 3, "The value of `s2prime.x` is `3`");
assert.sameValue(s2prime.y, 4, "The value of `s2prime.y` is `4`");


var obj = {};
class Base3 {
  constructor() {
    return obj;
  }
}

class Subclass3 extends Base3 {};

var s3 = new Subclass3();
assert.sameValue(s3, obj, "The value of `s3` is `obj`");


reportCompare(0, 0);