• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1// Copyright 2015 the V8 project authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5// Flags: --strong-mode --allow-natives-syntax
6
7'use strict';
8
9function assertWeakClassWeakInstances(x) {
10  assertFalse(%IsStrong(x));
11  assertFalse(%IsStrong(x.prototype));
12  assertFalse(%IsStrong(new x));
13}
14
15function assertWeakClassStrongInstances(x) {
16  assertFalse(%IsStrong(x));
17  assertFalse(%IsStrong(x.prototype));
18  assertTrue(%IsStrong(new x));
19}
20
21function assertStrongClassWeakInstances(x) {
22  assertTrue(%IsStrong(x));
23  assertTrue(%IsStrong(x.prototype));
24  assertFalse(%IsStrong(new x));
25}
26
27function assertStrongClassStrongInstances(x) {
28  assertTrue(%IsStrong(x));
29  assertTrue(%IsStrong(x.prototype));
30  assertTrue(%IsStrong(new x));
31}
32
33function getWeakClass() {
34  return (class {});
35}
36
37function getWeakClassExtends(x) {
38  return (class extends x {});
39}
40
41function getStrongClass() {
42  "use strong";
43  return (class {});
44}
45
46function getStrongClassExtends(x) {
47  "use strong";
48  return (class extends x {});
49}
50
51(function SimpleWeakClassLiterals() {
52  class C {};
53  class D extends C {};
54  class E extends Object {};
55
56  assertWeakClassWeakInstances(C);
57  assertWeakClassWeakInstances(D);
58  assertWeakClassWeakInstances(E);
59
60  assertWeakClassWeakInstances(class {});
61  assertWeakClassWeakInstances(class extends Object {});
62  assertWeakClassWeakInstances(class extends C {});
63  assertWeakClassWeakInstances(class extends class {} {});
64})();
65
66(function SimpleStrongClassLiterals() {
67  'use strong';
68  class C {};
69  class D extends C {};
70
71  assertStrongClassStrongInstances(C);
72  assertStrongClassStrongInstances(D);
73
74  assertStrongClassStrongInstances(class {});
75  assertStrongClassStrongInstances(class extends C {});
76  assertStrongClassStrongInstances(class extends class {} {});
77})();
78
79(function MixedWeakClassLiterals() {
80  class C extends getStrongClass() {};
81  class D extends getStrongClassExtends((class {})) {};
82  class E extends getStrongClassExtends(C) {};
83
84  assertWeakClassStrongInstances(C);
85  assertWeakClassStrongInstances(class extends getStrongClass() {});
86
87  assertWeakClassWeakInstances(D);
88  assertWeakClassWeakInstances(
89    class extends getStrongClassExtends((class {})) {});
90
91  assertWeakClassStrongInstances(E);
92  assertWeakClassStrongInstances(
93    class extends getStrongClassExtends(class extends getStrongClass() {}) {});
94})();
95
96(function MixedStrongClassLiterals() {
97  'use strong';
98  class C extends getWeakClass() {};
99  class D extends getWeakClassExtends((class {})) {};
100  class E extends getWeakClassExtends(C) {};
101  class F extends Object {};
102
103  assertStrongClassWeakInstances(C);
104  assertStrongClassWeakInstances(class extends getWeakClass() {});
105
106  assertStrongClassStrongInstances(D);
107  assertStrongClassStrongInstances(
108    class extends getWeakClassExtends((class {})) {});
109
110  assertStrongClassWeakInstances(E);
111  assertStrongClassWeakInstances(
112    class extends getWeakClassExtends(class extends getWeakClass() {}) {});
113
114  assertStrongClassWeakInstances(F);
115  assertStrongClassWeakInstances(class extends Object {});
116})();
117
118(function WeakMonkeyPatchedClassLiterals() {
119  class C {};
120  assertWeakClassWeakInstances(C);
121  C.__proto__ = getStrongClass();
122  // C's default constructor doesn't call super.
123  assertWeakClassWeakInstances(C);
124
125  class D extends Object {};
126  assertWeakClassWeakInstances(D);
127  D.__proto__ = getStrongClass();
128  // D is a derived class, so its default constructor calls super.
129  assertWeakClassStrongInstances(D);
130
131  class E extends (class {}) {};
132  E.__proto__ = C;
133  assertWeakClassWeakInstances(E);
134
135  class F extends (class {}) {};
136  F.__proto__ = D;
137  assertWeakClassStrongInstances(F);
138
139  class G extends getStrongClass() {};
140  G.__proto__ = getWeakClass();
141  assertWeakClassWeakInstances(G);
142})();
143
144(function StrongMonkeyPatchedClassLiterals() {
145  let C = getStrongClassExtends(getWeakClassExtends(getStrongClass()));
146  let D = getStrongClassExtends(getWeakClassExtends(getWeakClass()));
147
148  assertStrongClassStrongInstances(C);
149  C.__proto__.__proto__ = getWeakClass();
150  assertStrongClassWeakInstances(C);
151  C.__proto__.__proto__ = getStrongClass();
152  assertStrongClassStrongInstances(C);
153
154  assertStrongClassWeakInstances(D);
155  D.__proto__.__proto__ = getStrongClass();
156  assertStrongClassStrongInstances(D);
157  D.__proto__.__proto__ = getWeakClass();
158  assertStrongClassWeakInstances(D);
159})();
160