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

Side by Side Diff: src/collection.js

Issue 11409002: ES6: Add support for Set and Map clear method (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 8 years, 1 month 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 | « no previous file | test/mjsunit/harmony/collections.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 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
90 90
91 function SetGetSize() { 91 function SetGetSize() {
92 if (!IS_SET(this)) { 92 if (!IS_SET(this)) {
93 throw MakeTypeError('incompatible_method_receiver', 93 throw MakeTypeError('incompatible_method_receiver',
94 ['Set.prototype.size', this]); 94 ['Set.prototype.size', this]);
95 } 95 }
96 return %SetGetSize(this); 96 return %SetGetSize(this);
97 } 97 }
98 98
99 99
100 function SetClear() {
101 if (!IS_SET(this)) {
102 throw MakeTypeError('incompatible_method_receiver',
103 ['Set.prototype.clear', this]);
104 }
105 // Replace the internal table with a new empty table.
106 %SetInitialize(this);
arv (Not doing code reviews) 2012/11/08 21:16:28 I first added a %SetClear before I realized that i
Michael Starzinger 2012/11/09 08:56:12 That's fine, I prefer it the way it is as well. Th
107 }
108
109
100 function MapConstructor() { 110 function MapConstructor() {
101 if (%_IsConstructCall()) { 111 if (%_IsConstructCall()) {
102 %MapInitialize(this); 112 %MapInitialize(this);
103 } else { 113 } else {
104 return new $Map(); 114 return new $Map();
105 } 115 }
106 } 116 }
107 117
108 118
109 function MapGet(key) { 119 function MapGet(key) {
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
156 166
157 function MapGetSize() { 167 function MapGetSize() {
158 if (!IS_MAP(this)) { 168 if (!IS_MAP(this)) {
159 throw MakeTypeError('incompatible_method_receiver', 169 throw MakeTypeError('incompatible_method_receiver',
160 ['Map.prototype.size', this]); 170 ['Map.prototype.size', this]);
161 } 171 }
162 return %MapGetSize(this); 172 return %MapGetSize(this);
163 } 173 }
164 174
165 175
176 function MapClear() {
177 if (!IS_MAP(this)) {
178 throw MakeTypeError('incompatible_method_receiver',
179 ['Map.prototype.clear', this]);
180 }
181 // Replace the internal table with a new empty table.
182 %MapInitialize(this);
183 }
184
185
166 function WeakMapConstructor() { 186 function WeakMapConstructor() {
167 if (%_IsConstructCall()) { 187 if (%_IsConstructCall()) {
168 %WeakMapInitialize(this); 188 %WeakMapInitialize(this);
169 } else { 189 } else {
170 return new $WeakMap(); 190 return new $WeakMap();
171 } 191 }
172 } 192 }
173 193
174 194
175 function WeakMapGet(key) { 195 function WeakMapGet(key) {
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
230 250
231 // Set up the constructor property on the Set and Map prototype object. 251 // Set up the constructor property on the Set and Map prototype object.
232 %SetProperty($Set.prototype, "constructor", $Set, DONT_ENUM); 252 %SetProperty($Set.prototype, "constructor", $Set, DONT_ENUM);
233 %SetProperty($Map.prototype, "constructor", $Map, DONT_ENUM); 253 %SetProperty($Map.prototype, "constructor", $Map, DONT_ENUM);
234 254
235 // Set up the non-enumerable functions on the Set prototype object. 255 // Set up the non-enumerable functions on the Set prototype object.
236 InstallGetter($Set.prototype, "size", SetGetSize); 256 InstallGetter($Set.prototype, "size", SetGetSize);
237 InstallFunctions($Set.prototype, DONT_ENUM, $Array( 257 InstallFunctions($Set.prototype, DONT_ENUM, $Array(
238 "add", SetAdd, 258 "add", SetAdd,
239 "has", SetHas, 259 "has", SetHas,
240 "delete", SetDelete 260 "delete", SetDelete,
261 "clear", SetClear
241 )); 262 ));
242 263
243 // Set up the non-enumerable functions on the Map prototype object. 264 // Set up the non-enumerable functions on the Map prototype object.
244 InstallGetter($Map.prototype, "size", MapGetSize); 265 InstallGetter($Map.prototype, "size", MapGetSize);
245 InstallFunctions($Map.prototype, DONT_ENUM, $Array( 266 InstallFunctions($Map.prototype, DONT_ENUM, $Array(
246 "get", MapGet, 267 "get", MapGet,
247 "set", MapSet, 268 "set", MapSet,
248 "has", MapHas, 269 "has", MapHas,
249 "delete", MapDelete 270 "delete", MapDelete,
271 "clear", MapClear
250 )); 272 ));
251 273
252 // Set up the WeakMap constructor function. 274 // Set up the WeakMap constructor function.
253 %SetCode($WeakMap, WeakMapConstructor); 275 %SetCode($WeakMap, WeakMapConstructor);
254 276
255 // Set up the constructor property on the WeakMap prototype object. 277 // Set up the constructor property on the WeakMap prototype object.
256 %SetProperty($WeakMap.prototype, "constructor", $WeakMap, DONT_ENUM); 278 %SetProperty($WeakMap.prototype, "constructor", $WeakMap, DONT_ENUM);
257 279
258 // Set up the non-enumerable functions on the WeakMap prototype object. 280 // Set up the non-enumerable functions on the WeakMap prototype object.
259 InstallFunctions($WeakMap.prototype, DONT_ENUM, $Array( 281 InstallFunctions($WeakMap.prototype, DONT_ENUM, $Array(
260 "get", WeakMapGet, 282 "get", WeakMapGet,
261 "set", WeakMapSet, 283 "set", WeakMapSet,
262 "has", WeakMapHas, 284 "has", WeakMapHas,
263 "delete", WeakMapDelete 285 "delete", WeakMapDelete
264 )); 286 ));
265 })(); 287 })();
OLDNEW
« no previous file with comments | « no previous file | test/mjsunit/harmony/collections.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698