Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(598)

Side by Side Diff: test/mjsunit/harmony/classes.js

Issue 631433002: Classes runtime (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright 2014 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: --harmony
6
7 'use strict';
8
9 (function TestBasics() {
10 var C = class C {}
11 assertEquals(typeof C, 'function');
12 assertEquals(C.__proto__, Function.prototype);
13 assertEquals(Object.prototype, Object.getPrototypeOf(C.prototype));
14 assertEquals(Function.prototype, Object.getPrototypeOf(C));
15 assertEquals('C', C.name);
16
17 class D {}
18 assertEquals(typeof D, 'function');
19 assertEquals(D.__proto__, Function.prototype);
20 assertEquals(Object.prototype, Object.getPrototypeOf(D.prototype));
21 assertEquals(Function.prototype, Object.getPrototypeOf(D));
22 assertEquals('D', D.name);
23
24 var E = class {}
25 assertEquals('', E.name);
26 })();
27
28
29 (function TestBasicsExtends() {
30 class C extends null {}
31 assertEquals(typeof C, 'function');
32 assertEquals(C.__proto__, Function.prototype);
33 assertEquals(null, Object.getPrototypeOf(C.prototype));
34
35 class D extends C {}
36 assertEquals(typeof D, 'function');
37 assertEquals(D.__proto__, C);
38 assertEquals(C.prototype, Object.getPrototypeOf(D.prototype));
39 })();
40
41
42 (function TestSideEffectInExtends() {
43 var calls = 0;
44 class C {}
45 class D extends (calls++, C) {}
46 assertEquals(1, calls);
47 assertEquals(typeof D, 'function');
48 assertEquals(D.__proto__, C);
49 assertEquals(C.prototype, Object.getPrototypeOf(D.prototype));
50 })();
51
52
53 (function TestInvalidExtends() {
54 assertThrows(function() {
55 class C extends 42 {}
56 }, TypeError);
57
58 assertThrows(function() {
59 // Function but its .prototype is not null or a function.
60 class C extends Math.abs {}
61 }, TypeError);
62
63 assertThrows(function() {
64 Math.abs.prototype = 42;
65 class C extends Math.abs {}
66 }, TypeError);
67 delete Math.abs.prototype;
68 })();
69
70
71 (function TestConstructorProperty() {
72 class C {}
73 assertEquals(C, C.prototype.constructor);
74 var descr = Object.getOwnPropertyDescriptor(C.prototype, 'constructor');
75 assertTrue(descr.configurable);
76 assertFalse(descr.enumerable);
77 assertTrue(descr.writable);
78 })();
79
80
81 (function TestPrototypeProperty() {
82 class C {}
83 var descr = Object.getOwnPropertyDescriptor(C, 'prototype');
84 assertFalse(descr.configurable);
85 assertFalse(descr.enumerable);
86 assertFalse(descr.writable);
87 })();
88
89
90 (function TestConstructor() {
91 var count = 0;
92 class C {
93 constructor() {
94 assertEquals(Object.getPrototypeOf(this), C.prototype);
95 count++;
96 }
97 }
98 assertEquals(C, C.prototype.constructor);
99 var descr = Object.getOwnPropertyDescriptor(C.prototype, 'constructor');
100 assertTrue(descr.configurable);
101 assertFalse(descr.enumerable);
102 assertTrue(descr.writable);
103
104 var c = new C();
105 assertEquals(1, count);
106 assertEquals(Object.getPrototypeOf(c), C.prototype);
107 })();
108
109
110 (function TestImplicitConstructor() {
111 class C {}
112 var c = new C();
113 assertEquals(Object.getPrototypeOf(c), C.prototype);
114 })();
115
116
117 (function TestConstructorStrict() {
118 class C {
119 constructor() {
120 assertThrows(function() {
121 nonExistingBinding = 42;
122 }, ReferenceError);
123 }
124 }
125 new C();
126 })();
127
128
129 (function TestSuperInConstructor() {
130 var calls = 0;
131 class B {}
132 B.prototype.x = 42;
133
134 class C extends B {
135 constructor() {
136 calls++;
137 assertEquals(42, super.x);
138 }
139 }
140
141 new C;
142 assertEquals(1, calls);
143 })();
144
145
146 /* TODO(arv): Implement
147 (function TestNameBindingInConstructor() {
148 class C {
149 constructor() {
150 assertThrows(function() {
151 C = 42;
152 }, ReferenceError);
153 }
154 }
155 new C();
156 })();
157 */
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698