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

Side by Side Diff: src/collection.js

Issue 21924007: Make new Harmony constructors subclassing-friendly (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: CR feedback Created 7 years, 4 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
« no previous file with comments | « src/arraybuffer.js ('k') | src/messages.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 26 matching lines...) Expand all
37 var $WeakSet = global.WeakSet; 37 var $WeakSet = global.WeakSet;
38 38
39 // Global sentinel to be used instead of undefined keys, which are not 39 // Global sentinel to be used instead of undefined keys, which are not
40 // supported internally but required for Harmony sets and maps. 40 // supported internally but required for Harmony sets and maps.
41 var undefined_sentinel = {}; 41 var undefined_sentinel = {};
42 42
43 // ------------------------------------------------------------------- 43 // -------------------------------------------------------------------
44 // Harmony Set 44 // Harmony Set
45 45
46 function SetConstructor() { 46 function SetConstructor() {
47 if (%_IsConstructCall()) { 47 %SetInitialize(this);
48 %SetInitialize(this);
49 } else {
50 throw MakeTypeError('constructor_not_function', ['Set']);
51 }
52 } 48 }
53 49
54 50
55 function SetAdd(key) { 51 function SetAdd(key) {
56 if (!IS_SET(this)) { 52 if (!IS_SET(this)) {
57 throw MakeTypeError('incompatible_method_receiver', 53 throw MakeTypeError('incompatible_method_receiver',
58 ['Set.prototype.add', this]); 54 ['Set.prototype.add', this]);
59 } 55 }
60 if (IS_UNDEFINED(key)) { 56 if (IS_UNDEFINED(key)) {
61 key = undefined_sentinel; 57 key = undefined_sentinel;
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
101 return %SetGetSize(this); 97 return %SetGetSize(this);
102 } 98 }
103 99
104 100
105 function SetClear() { 101 function SetClear() {
106 if (!IS_SET(this)) { 102 if (!IS_SET(this)) {
107 throw MakeTypeError('incompatible_method_receiver', 103 throw MakeTypeError('incompatible_method_receiver',
108 ['Set.prototype.clear', this]); 104 ['Set.prototype.clear', this]);
109 } 105 }
110 // Replace the internal table with a new empty table. 106 // Replace the internal table with a new empty table.
111 %SetInitialize(this); 107 %SetClear(this);
112 } 108 }
113 109
114 110
115 // ------------------------------------------------------------------- 111 // -------------------------------------------------------------------
116 112
117 function SetUpSet() { 113 function SetUpSet() {
118 %CheckIsBootstrapping(); 114 %CheckIsBootstrapping();
119 115
120 %SetCode($Set, SetConstructor); 116 %SetCode($Set, SetConstructor);
121 %FunctionSetPrototype($Set, new $Object()); 117 %FunctionSetPrototype($Set, new $Object());
122 %SetProperty($Set.prototype, "constructor", $Set, DONT_ENUM); 118 %SetProperty($Set.prototype, "constructor", $Set, DONT_ENUM);
123 119
124 // Set up the non-enumerable functions on the Set prototype object. 120 // Set up the non-enumerable functions on the Set prototype object.
125 InstallGetter($Set.prototype, "size", SetGetSize); 121 InstallGetter($Set.prototype, "size", SetGetSize);
126 InstallFunctions($Set.prototype, DONT_ENUM, $Array( 122 InstallFunctions($Set.prototype, DONT_ENUM, $Array(
127 "add", SetAdd, 123 "add", SetAdd,
128 "has", SetHas, 124 "has", SetHas,
129 "delete", SetDelete, 125 "delete", SetDelete,
130 "clear", SetClear 126 "clear", SetClear
131 )); 127 ));
132 } 128 }
133 129
134 SetUpSet(); 130 SetUpSet();
135 131
136 132
137 // ------------------------------------------------------------------- 133 // -------------------------------------------------------------------
138 // Harmony Map 134 // Harmony Map
139 135
140 function MapConstructor() { 136 function MapConstructor() {
141 if (%_IsConstructCall()) { 137 %MapInitialize(this);
142 %MapInitialize(this);
143 } else {
144 throw MakeTypeError('constructor_not_function', ['Map']);
145 }
146 } 138 }
147 139
148 140
149 function MapGet(key) { 141 function MapGet(key) {
150 if (!IS_MAP(this)) { 142 if (!IS_MAP(this)) {
151 throw MakeTypeError('incompatible_method_receiver', 143 throw MakeTypeError('incompatible_method_receiver',
152 ['Map.prototype.get', this]); 144 ['Map.prototype.get', this]);
153 } 145 }
154 if (IS_UNDEFINED(key)) { 146 if (IS_UNDEFINED(key)) {
155 key = undefined_sentinel; 147 key = undefined_sentinel;
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
202 return %MapGetSize(this); 194 return %MapGetSize(this);
203 } 195 }
204 196
205 197
206 function MapClear() { 198 function MapClear() {
207 if (!IS_MAP(this)) { 199 if (!IS_MAP(this)) {
208 throw MakeTypeError('incompatible_method_receiver', 200 throw MakeTypeError('incompatible_method_receiver',
209 ['Map.prototype.clear', this]); 201 ['Map.prototype.clear', this]);
210 } 202 }
211 // Replace the internal table with a new empty table. 203 // Replace the internal table with a new empty table.
212 %MapInitialize(this); 204 %MapClear(this);
213 } 205 }
214 206
215 207
216 // ------------------------------------------------------------------- 208 // -------------------------------------------------------------------
217 209
218 function SetUpMap() { 210 function SetUpMap() {
219 %CheckIsBootstrapping(); 211 %CheckIsBootstrapping();
220 212
221 %SetCode($Map, MapConstructor); 213 %SetCode($Map, MapConstructor);
222 %FunctionSetPrototype($Map, new $Object()); 214 %FunctionSetPrototype($Map, new $Object());
(...skipping 10 matching lines...) Expand all
233 )); 225 ));
234 } 226 }
235 227
236 SetUpMap(); 228 SetUpMap();
237 229
238 230
239 // ------------------------------------------------------------------- 231 // -------------------------------------------------------------------
240 // Harmony WeakMap 232 // Harmony WeakMap
241 233
242 function WeakMapConstructor() { 234 function WeakMapConstructor() {
243 if (%_IsConstructCall()) { 235 %WeakMapInitialize(this);
244 %WeakCollectionInitialize(this);
245 } else {
246 throw MakeTypeError('constructor_not_function', ['WeakMap']);
247 }
248 } 236 }
249 237
250 238
251 function WeakMapGet(key) { 239 function WeakMapGet(key) {
252 if (!IS_WEAKMAP(this)) { 240 if (!IS_WEAKMAP(this)) {
253 throw MakeTypeError('incompatible_method_receiver', 241 throw MakeTypeError('incompatible_method_receiver',
254 ['WeakMap.prototype.get', this]); 242 ['WeakMap.prototype.get', this]);
255 } 243 }
256 if (!(IS_SPEC_OBJECT(key) || IS_SYMBOL(key))) { 244 if (!(IS_SPEC_OBJECT(key) || IS_SYMBOL(key))) {
257 throw %MakeTypeError('invalid_weakmap_key', [this, key]); 245 throw %MakeTypeError('invalid_weakmap_key', [this, key]);
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
295 return %WeakCollectionDelete(this, key); 283 return %WeakCollectionDelete(this, key);
296 } 284 }
297 285
298 286
299 function WeakMapClear() { 287 function WeakMapClear() {
300 if (!IS_WEAKMAP(this)) { 288 if (!IS_WEAKMAP(this)) {
301 throw MakeTypeError('incompatible_method_receiver', 289 throw MakeTypeError('incompatible_method_receiver',
302 ['WeakMap.prototype.clear', this]); 290 ['WeakMap.prototype.clear', this]);
303 } 291 }
304 // Replace the internal table with a new empty table. 292 // Replace the internal table with a new empty table.
305 %WeakCollectionInitialize(this); 293 %WeakCollectionClear(this);
306 } 294 }
307 295
308 296
309 // ------------------------------------------------------------------- 297 // -------------------------------------------------------------------
310 298
311 function SetUpWeakMap() { 299 function SetUpWeakMap() {
312 %CheckIsBootstrapping(); 300 %CheckIsBootstrapping();
313 301
314 %SetCode($WeakMap, WeakMapConstructor); 302 %SetCode($WeakMap, WeakMapConstructor);
315 %FunctionSetPrototype($WeakMap, new $Object()); 303 %FunctionSetPrototype($WeakMap, new $Object());
316 %SetProperty($WeakMap.prototype, "constructor", $WeakMap, DONT_ENUM); 304 %SetProperty($WeakMap.prototype, "constructor", $WeakMap, DONT_ENUM);
317 305
318 // Set up the non-enumerable functions on the WeakMap prototype object. 306 // Set up the non-enumerable functions on the WeakMap prototype object.
319 InstallFunctions($WeakMap.prototype, DONT_ENUM, $Array( 307 InstallFunctions($WeakMap.prototype, DONT_ENUM, $Array(
320 "get", WeakMapGet, 308 "get", WeakMapGet,
321 "set", WeakMapSet, 309 "set", WeakMapSet,
322 "has", WeakMapHas, 310 "has", WeakMapHas,
323 "delete", WeakMapDelete, 311 "delete", WeakMapDelete,
324 "clear", WeakMapClear 312 "clear", WeakMapClear
325 )); 313 ));
326 } 314 }
327 315
328 SetUpWeakMap(); 316 SetUpWeakMap();
329 317
330 318
331 // ------------------------------------------------------------------- 319 // -------------------------------------------------------------------
332 // Harmony WeakSet 320 // Harmony WeakSet
333 321
334 function WeakSetConstructor() { 322 function WeakSetConstructor() {
335 if (%_IsConstructCall()) { 323 %WeakSetInitialize(this);
336 %WeakCollectionInitialize(this);
337 } else {
338 throw MakeTypeError('constructor_not_function', ['WeakSet']);
339 }
340 } 324 }
341 325
342 326
343 function WeakSetAdd(value) { 327 function WeakSetAdd(value) {
344 if (!IS_WEAKSET(this)) { 328 if (!IS_WEAKSET(this)) {
345 throw MakeTypeError('incompatible_method_receiver', 329 throw MakeTypeError('incompatible_method_receiver',
346 ['WeakSet.prototype.add', this]); 330 ['WeakSet.prototype.add', this]);
347 } 331 }
348 if (!(IS_SPEC_OBJECT(value) || IS_SYMBOL(value))) { 332 if (!(IS_SPEC_OBJECT(value) || IS_SYMBOL(value))) {
349 throw %MakeTypeError('invalid_weakset_value', [this, value]); 333 throw %MakeTypeError('invalid_weakset_value', [this, value]);
(...skipping 25 matching lines...) Expand all
375 return %WeakCollectionDelete(this, value); 359 return %WeakCollectionDelete(this, value);
376 } 360 }
377 361
378 362
379 function WeakSetClear() { 363 function WeakSetClear() {
380 if (!IS_WEAKSET(this)) { 364 if (!IS_WEAKSET(this)) {
381 throw MakeTypeError('incompatible_method_receiver', 365 throw MakeTypeError('incompatible_method_receiver',
382 ['WeakSet.prototype.clear', this]); 366 ['WeakSet.prototype.clear', this]);
383 } 367 }
384 // Replace the internal table with a new empty table. 368 // Replace the internal table with a new empty table.
385 %WeakCollectionInitialize(this); 369 %WeakCollectionClear(this);
386 } 370 }
387 371
388 372
389 // ------------------------------------------------------------------- 373 // -------------------------------------------------------------------
390 374
391 function SetUpWeakSet() { 375 function SetUpWeakSet() {
392 %CheckIsBootstrapping(); 376 %CheckIsBootstrapping();
393 377
394 %SetCode($WeakSet, WeakSetConstructor); 378 %SetCode($WeakSet, WeakSetConstructor);
395 %FunctionSetPrototype($WeakSet, new $Object()); 379 %FunctionSetPrototype($WeakSet, new $Object());
396 %SetProperty($WeakSet.prototype, "constructor", $WeakSet, DONT_ENUM); 380 %SetProperty($WeakSet.prototype, "constructor", $WeakSet, DONT_ENUM);
397 381
398 // Set up the non-enumerable functions on the WeakSet prototype object. 382 // Set up the non-enumerable functions on the WeakSet prototype object.
399 InstallFunctions($WeakSet.prototype, DONT_ENUM, $Array( 383 InstallFunctions($WeakSet.prototype, DONT_ENUM, $Array(
400 "add", WeakSetAdd, 384 "add", WeakSetAdd,
401 "has", WeakSetHas, 385 "has", WeakSetHas,
402 "delete", WeakSetDelete, 386 "delete", WeakSetDelete,
403 "clear", WeakSetClear 387 "clear", WeakSetClear
404 )); 388 ));
405 } 389 }
406 390
407 SetUpWeakSet(); 391 SetUpWeakSet();
OLDNEW
« no previous file with comments | « src/arraybuffer.js ('k') | src/messages.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698