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

Side by Side Diff: src/collection.js

Issue 19678023: ES6: Implement WeakSet (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Reitveld is acting up Created 7 years, 5 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
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 16 matching lines...) Expand all
27 27
28 "use strict"; 28 "use strict";
29 29
30 // This file relies on the fact that the following declaration has been made 30 // This file relies on the fact that the following declaration has been made
31 // in runtime.js: 31 // in runtime.js:
32 // var $Array = global.Array; 32 // var $Array = global.Array;
33 33
34 var $Set = global.Set; 34 var $Set = global.Set;
35 var $Map = global.Map; 35 var $Map = global.Map;
36 var $WeakMap = global.WeakMap; 36 var $WeakMap = global.WeakMap;
37 var $WeakSet = global.WeakSet;
37 38
38 // 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
39 // supported internally but required for Harmony sets and maps. 40 // supported internally but required for Harmony sets and maps.
40 var undefined_sentinel = {}; 41 var undefined_sentinel = {};
41 42
42 // ------------------------------------------------------------------- 43 // -------------------------------------------------------------------
43 // Harmony Set 44 // Harmony Set
44 45
45 function SetConstructor() { 46 function SetConstructor() {
46 if (%_IsConstructCall()) { 47 if (%_IsConstructCall()) {
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after
233 } 234 }
234 235
235 SetUpMap(); 236 SetUpMap();
236 237
237 238
238 // ------------------------------------------------------------------- 239 // -------------------------------------------------------------------
239 // Harmony WeakMap 240 // Harmony WeakMap
240 241
241 function WeakMapConstructor() { 242 function WeakMapConstructor() {
242 if (%_IsConstructCall()) { 243 if (%_IsConstructCall()) {
243 %WeakMapInitialize(this); 244 %WeakCollectionInitialize(this);
244 } else { 245 } else {
245 return new $WeakMap(); 246 return new $WeakMap();
246 } 247 }
247 } 248 }
248 249
249 250
250 function WeakMapGet(key) { 251 function WeakMapGet(key) {
251 if (!IS_WEAKMAP(this)) { 252 if (!IS_WEAKMAP(this)) {
252 throw MakeTypeError('incompatible_method_receiver', 253 throw MakeTypeError('incompatible_method_receiver',
253 ['WeakMap.prototype.get', this]); 254 ['WeakMap.prototype.get', this]);
254 } 255 }
255 if (!(IS_SPEC_OBJECT(key) || IS_SYMBOL(key))) { 256 if (!(IS_SPEC_OBJECT(key) || IS_SYMBOL(key))) {
256 throw %MakeTypeError('invalid_weakmap_key', [this, key]); 257 throw %MakeTypeError('invalid_weakmap_key', [this, key]);
257 } 258 }
258 return %WeakMapGet(this, key); 259 return %WeakCollectionGet(this, key);
259 } 260 }
260 261
261 262
262 function WeakMapSet(key, value) { 263 function WeakMapSet(key, value) {
263 if (!IS_WEAKMAP(this)) { 264 if (!IS_WEAKMAP(this)) {
264 throw MakeTypeError('incompatible_method_receiver', 265 throw MakeTypeError('incompatible_method_receiver',
265 ['WeakMap.prototype.set', this]); 266 ['WeakMap.prototype.set', this]);
266 } 267 }
267 if (!(IS_SPEC_OBJECT(key) || IS_SYMBOL(key))) { 268 if (!(IS_SPEC_OBJECT(key) || IS_SYMBOL(key))) {
268 throw %MakeTypeError('invalid_weakmap_key', [this, key]); 269 throw %MakeTypeError('invalid_weakmap_key', [this, key]);
269 } 270 }
270 return %WeakMapSet(this, key, value); 271 return %WeakCollectionSet(this, key, value);
271 } 272 }
272 273
273 274
274 function WeakMapHas(key) { 275 function WeakMapHas(key) {
275 if (!IS_WEAKMAP(this)) { 276 if (!IS_WEAKMAP(this)) {
276 throw MakeTypeError('incompatible_method_receiver', 277 throw MakeTypeError('incompatible_method_receiver',
277 ['WeakMap.prototype.has', this]); 278 ['WeakMap.prototype.has', this]);
278 } 279 }
279 if (!(IS_SPEC_OBJECT(key) || IS_SYMBOL(key))) { 280 if (!(IS_SPEC_OBJECT(key) || IS_SYMBOL(key))) {
280 throw %MakeTypeError('invalid_weakmap_key', [this, key]); 281 throw %MakeTypeError('invalid_weakmap_key', [this, key]);
281 } 282 }
282 return %WeakMapHas(this, key); 283 return %WeakCollectionHas(this, key);
283 } 284 }
284 285
285 286
286 function WeakMapDelete(key) { 287 function WeakMapDelete(key) {
287 if (!IS_WEAKMAP(this)) { 288 if (!IS_WEAKMAP(this)) {
288 throw MakeTypeError('incompatible_method_receiver', 289 throw MakeTypeError('incompatible_method_receiver',
289 ['WeakMap.prototype.delete', this]); 290 ['WeakMap.prototype.delete', this]);
290 } 291 }
291 if (!(IS_SPEC_OBJECT(key) || IS_SYMBOL(key))) { 292 if (!(IS_SPEC_OBJECT(key) || IS_SYMBOL(key))) {
292 throw %MakeTypeError('invalid_weakmap_key', [this, key]); 293 throw %MakeTypeError('invalid_weakmap_key', [this, key]);
293 } 294 }
294 return %WeakMapDelete(this, key); 295 return %WeakCollectionDelete(this, key);
295 } 296 }
296 297
297 298
298 function WeakMapClear() { 299 function WeakMapClear() {
299 if (!IS_WEAKMAP(this)) { 300 if (!IS_WEAKMAP(this)) {
300 throw MakeTypeError('incompatible_method_receiver', 301 throw MakeTypeError('incompatible_method_receiver',
301 ['WeakMap.prototype.clear', this]); 302 ['WeakMap.prototype.clear', this]);
302 } 303 }
303 // Replace the internal table with a new empty table. 304 // Replace the internal table with a new empty table.
304 %WeakMapInitialize(this); 305 %WeakCollectionInitialize(this);
305 } 306 }
306 307
307 308
308 // ------------------------------------------------------------------- 309 // -------------------------------------------------------------------
309 310
310 function SetUpWeakMap() { 311 function SetUpWeakMap() {
311 %CheckIsBootstrapping(); 312 %CheckIsBootstrapping();
312 313
313 %SetCode($WeakMap, WeakMapConstructor); 314 %SetCode($WeakMap, WeakMapConstructor);
314 %FunctionSetPrototype($WeakMap, new $Object()); 315 %FunctionSetPrototype($WeakMap, new $Object());
315 %SetProperty($WeakMap.prototype, "constructor", $WeakMap, DONT_ENUM); 316 %SetProperty($WeakMap.prototype, "constructor", $WeakMap, DONT_ENUM);
316 317
317 // Set up the non-enumerable functions on the WeakMap prototype object. 318 // Set up the non-enumerable functions on the WeakMap prototype object.
318 InstallFunctions($WeakMap.prototype, DONT_ENUM, $Array( 319 InstallFunctions($WeakMap.prototype, DONT_ENUM, $Array(
319 "get", WeakMapGet, 320 "get", WeakMapGet,
320 "set", WeakMapSet, 321 "set", WeakMapSet,
321 "has", WeakMapHas, 322 "has", WeakMapHas,
322 "delete", WeakMapDelete, 323 "delete", WeakMapDelete,
323 "clear", WeakMapClear 324 "clear", WeakMapClear
324 )); 325 ));
325 } 326 }
326 327
327 SetUpWeakMap(); 328 SetUpWeakMap();
329
330
331 // -------------------------------------------------------------------
332 // Harmony WeakSet
333
334 function WeakSetConstructor() {
335 if (%_IsConstructCall()) {
336 %WeakCollectionInitialize(this);
337 } else {
338 return new $WeakSet();
339 }
340 }
341
342
343 function WeakSetAdd(value) {
344 if (!IS_WEAKSET(this)) {
345 throw MakeTypeError('incompatible_method_receiver',
346 ['WeakSet.prototype.add', this]);
347 }
348 if (!(IS_SPEC_OBJECT(value) || IS_SYMBOL(value))) {
349 throw %MakeTypeError('invalid_weakset_value', [this, value]);
350 }
351 return %WeakCollectionSet(this, value, true);
352 }
353
354
355 function WeakSetHas(value) {
356 if (!IS_WEAKSET(this)) {
357 throw MakeTypeError('incompatible_method_receiver',
358 ['WeakSet.prototype.has', this]);
359 }
360 if (!(IS_SPEC_OBJECT(value) || IS_SYMBOL(value))) {
361 throw %MakeTypeError('invalid_weakset_value', [this, value]);
362 }
363 return %WeakCollectionHas(this, value);
364 }
365
366
367 function WeakSetDelete(value) {
368 if (!IS_WEAKSET(this)) {
369 throw MakeTypeError('incompatible_method_receiver',
370 ['WeakSet.prototype.delete', this]);
371 }
372 if (!(IS_SPEC_OBJECT(value) || IS_SYMBOL(value))) {
373 throw %MakeTypeError('invalid_weakset_value', [this, value]);
374 }
375 return %WeakCollectionDelete(this, value);
376 }
377
378
379 function WeakSetClear() {
380 if (!IS_WEAKSET(this)) {
381 throw MakeTypeError('incompatible_method_receiver',
382 ['WeakSet.prototype.clear', this]);
383 }
384 // Replace the internal table with a new empty table.
385 %WeakCollectionInitialize(this);
386 }
387
388
389 // -------------------------------------------------------------------
390
391 function SetUpWeakSet() {
392 %CheckIsBootstrapping();
393
394 %SetCode($WeakSet, WeakSetConstructor);
395 %FunctionSetPrototype($WeakSet, new $Object());
396 %SetProperty($WeakSet.prototype, "constructor", $WeakSet, DONT_ENUM);
397
398 // Set up the non-enumerable functions on the WeakSet prototype object.
399 InstallFunctions($WeakSet.prototype, DONT_ENUM, $Array(
400 "add", WeakSetAdd,
401 "has", WeakSetHas,
402 "delete", WeakSetDelete,
403 "clear", WeakSetClear
404 ));
405 }
406
407 SetUpWeakSet();
OLDNEW
« no previous file with comments | « src/bootstrapper.cc ('k') | src/heap.h » ('j') | src/objects-printer.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698