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

Side by Side Diff: src/collection.js

Issue 11360089: ES6: Adding support for size to Set and Map (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 | src/runtime.h » ('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 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
81 } 81 }
82 if (%SetHas(this, key)) { 82 if (%SetHas(this, key)) {
83 %SetDelete(this, key); 83 %SetDelete(this, key);
84 return true; 84 return true;
85 } else { 85 } else {
86 return false; 86 return false;
87 } 87 }
88 } 88 }
89 89
90 90
91 function SetGetSize() {
92 if (!IS_SET(this)) {
93 throw MakeTypeError('incompatible_method_receiver',
94 ['Set.prototype.size', this]);
95 }
96 return %SetGetSize(this);
97 }
98
99
91 function MapConstructor() { 100 function MapConstructor() {
92 if (%_IsConstructCall()) { 101 if (%_IsConstructCall()) {
93 %MapInitialize(this); 102 %MapInitialize(this);
94 } else { 103 } else {
95 return new $Map(); 104 return new $Map();
96 } 105 }
97 } 106 }
98 107
99 108
100 function MapGet(key) { 109 function MapGet(key) {
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
138 throw MakeTypeError('incompatible_method_receiver', 147 throw MakeTypeError('incompatible_method_receiver',
139 ['Map.prototype.delete', this]); 148 ['Map.prototype.delete', this]);
140 } 149 }
141 if (IS_UNDEFINED(key)) { 150 if (IS_UNDEFINED(key)) {
142 key = undefined_sentinel; 151 key = undefined_sentinel;
143 } 152 }
144 return %MapDelete(this, key); 153 return %MapDelete(this, key);
145 } 154 }
146 155
147 156
157 function MapGetSize() {
158 if (!IS_MAP(this)) {
159 throw MakeTypeError('incompatible_method_receiver',
160 ['Map.prototype.size', this]);
161 }
162 return %MapGetSize(this);
163 }
164
165
148 function WeakMapConstructor() { 166 function WeakMapConstructor() {
149 if (%_IsConstructCall()) { 167 if (%_IsConstructCall()) {
150 %WeakMapInitialize(this); 168 %WeakMapInitialize(this);
151 } else { 169 } else {
152 return new $WeakMap(); 170 return new $WeakMap();
153 } 171 }
154 } 172 }
155 173
156 174
157 function WeakMapGet(key) { 175 function WeakMapGet(key) {
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
208 226
209 // Set up the Set and Map constructor function. 227 // Set up the Set and Map constructor function.
210 %SetCode($Set, SetConstructor); 228 %SetCode($Set, SetConstructor);
211 %SetCode($Map, MapConstructor); 229 %SetCode($Map, MapConstructor);
212 230
213 // Set up the constructor property on the Set and Map prototype object. 231 // Set up the constructor property on the Set and Map prototype object.
214 %SetProperty($Set.prototype, "constructor", $Set, DONT_ENUM); 232 %SetProperty($Set.prototype, "constructor", $Set, DONT_ENUM);
215 %SetProperty($Map.prototype, "constructor", $Map, DONT_ENUM); 233 %SetProperty($Map.prototype, "constructor", $Map, DONT_ENUM);
216 234
217 // Set up the non-enumerable functions on the Set prototype object. 235 // Set up the non-enumerable functions on the Set prototype object.
236 InstallGetter($Set.prototype, "size", SetGetSize);
218 InstallFunctions($Set.prototype, DONT_ENUM, $Array( 237 InstallFunctions($Set.prototype, DONT_ENUM, $Array(
219 "add", SetAdd, 238 "add", SetAdd,
220 "has", SetHas, 239 "has", SetHas,
221 "delete", SetDelete 240 "delete", SetDelete
222 )); 241 ));
223 242
224 // Set up the non-enumerable functions on the Map prototype object. 243 // Set up the non-enumerable functions on the Map prototype object.
244 InstallGetter($Map.prototype, "size", MapGetSize);
225 InstallFunctions($Map.prototype, DONT_ENUM, $Array( 245 InstallFunctions($Map.prototype, DONT_ENUM, $Array(
226 "get", MapGet, 246 "get", MapGet,
227 "set", MapSet, 247 "set", MapSet,
228 "has", MapHas, 248 "has", MapHas,
229 "delete", MapDelete 249 "delete", MapDelete
230 )); 250 ));
231 251
232 // Set up the WeakMap constructor function. 252 // Set up the WeakMap constructor function.
233 %SetCode($WeakMap, WeakMapConstructor); 253 %SetCode($WeakMap, WeakMapConstructor);
234 254
235 // Set up the constructor property on the WeakMap prototype object. 255 // Set up the constructor property on the WeakMap prototype object.
236 %SetProperty($WeakMap.prototype, "constructor", $WeakMap, DONT_ENUM); 256 %SetProperty($WeakMap.prototype, "constructor", $WeakMap, DONT_ENUM);
237 257
238 // Set up the non-enumerable functions on the WeakMap prototype object. 258 // Set up the non-enumerable functions on the WeakMap prototype object.
239 InstallFunctions($WeakMap.prototype, DONT_ENUM, $Array( 259 InstallFunctions($WeakMap.prototype, DONT_ENUM, $Array(
240 "get", WeakMapGet, 260 "get", WeakMapGet,
241 "set", WeakMapSet, 261 "set", WeakMapSet,
242 "has", WeakMapHas, 262 "has", WeakMapHas,
243 "delete", WeakMapDelete 263 "delete", WeakMapDelete
244 )); 264 ));
245 })(); 265 })();
OLDNEW
« no previous file with comments | « no previous file | src/runtime.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698