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 1083083004: Reland "Migrate error messages, part 2." (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: fix for layout test Created 5 years, 8 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
« no previous file with comments | « src/arraybuffer.js ('k') | src/collection-iterator.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 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 (function() { 5 (function() {
6 6
7 "use strict"; 7 "use strict";
8 8
9 %CheckIsBootstrapping(); 9 %CheckIsBootstrapping();
10 10
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
92 function SetConstructor(iterable) { 92 function SetConstructor(iterable) {
93 if (!%_IsConstructCall()) { 93 if (!%_IsConstructCall()) {
94 throw MakeTypeError('constructor_not_function', ['Set']); 94 throw MakeTypeError('constructor_not_function', ['Set']);
95 } 95 }
96 96
97 %_SetInitialize(this); 97 %_SetInitialize(this);
98 98
99 if (!IS_NULL_OR_UNDEFINED(iterable)) { 99 if (!IS_NULL_OR_UNDEFINED(iterable)) {
100 var adder = this.add; 100 var adder = this.add;
101 if (!IS_SPEC_FUNCTION(adder)) { 101 if (!IS_SPEC_FUNCTION(adder)) {
102 throw MakeTypeError(kPropertyNotFunction, ['add', this]); 102 throw MakeTypeError(kPropertyNotFunction, 'add', this);
103 } 103 }
104 104
105 for (var value of iterable) { 105 for (var value of iterable) {
106 %_CallFunction(this, value, adder); 106 %_CallFunction(this, value, adder);
107 } 107 }
108 } 108 }
109 } 109 }
110 110
111 111
112 function SetAdd(key) { 112 function SetAdd(key) {
113 if (!IS_SET(this)) { 113 if (!IS_SET(this)) {
114 throw MakeTypeError('incompatible_method_receiver', 114 throw MakeTypeError(kIncompatibleMethodReceiver, 'Set.prototype.add', this);
115 ['Set.prototype.add', this]);
116 } 115 }
117 // Normalize -0 to +0 as required by the spec. 116 // Normalize -0 to +0 as required by the spec.
118 // Even though we use SameValueZero as the comparison for the keys we don't 117 // Even though we use SameValueZero as the comparison for the keys we don't
119 // want to ever store -0 as the key since the key is directly exposed when 118 // want to ever store -0 as the key since the key is directly exposed when
120 // doing iteration. 119 // doing iteration.
121 if (key === 0) { 120 if (key === 0) {
122 key = 0; 121 key = 0;
123 } 122 }
124 var table = %_JSCollectionGetTable(this); 123 var table = %_JSCollectionGetTable(this);
125 var numBuckets = ORDERED_HASH_TABLE_BUCKET_COUNT(table); 124 var numBuckets = ORDERED_HASH_TABLE_BUCKET_COUNT(table);
(...skipping 19 matching lines...) Expand all
145 ORDERED_HASH_TABLE_SET_BUCKET_AT(table, bucket, entry); 144 ORDERED_HASH_TABLE_SET_BUCKET_AT(table, bucket, entry);
146 ORDERED_HASH_TABLE_SET_ELEMENT_COUNT(table, nof + 1); 145 ORDERED_HASH_TABLE_SET_ELEMENT_COUNT(table, nof + 1);
147 FIXED_ARRAY_SET(table, index, key); 146 FIXED_ARRAY_SET(table, index, key);
148 FIXED_ARRAY_SET_SMI(table, index + 1, chainEntry); 147 FIXED_ARRAY_SET_SMI(table, index + 1, chainEntry);
149 return this; 148 return this;
150 } 149 }
151 150
152 151
153 function SetHas(key) { 152 function SetHas(key) {
154 if (!IS_SET(this)) { 153 if (!IS_SET(this)) {
155 throw MakeTypeError('incompatible_method_receiver', 154 throw MakeTypeError(kIncompatibleMethodReceiver, 'Set.prototype.has', this);
156 ['Set.prototype.has', this]);
157 } 155 }
158 var table = %_JSCollectionGetTable(this); 156 var table = %_JSCollectionGetTable(this);
159 var numBuckets = ORDERED_HASH_TABLE_BUCKET_COUNT(table); 157 var numBuckets = ORDERED_HASH_TABLE_BUCKET_COUNT(table);
160 var hash = GetHash(key); 158 var hash = GetHash(key);
161 return SetFindEntry(table, numBuckets, key, hash) !== NOT_FOUND; 159 return SetFindEntry(table, numBuckets, key, hash) !== NOT_FOUND;
162 } 160 }
163 161
164 162
165 function SetDelete(key) { 163 function SetDelete(key) {
166 if (!IS_SET(this)) { 164 if (!IS_SET(this)) {
167 throw MakeTypeError('incompatible_method_receiver', 165 throw MakeTypeError(kIncompatibleMethodReceiver,
168 ['Set.prototype.delete', this]); 166 'Set.prototype.delete', this);
169 } 167 }
170 var table = %_JSCollectionGetTable(this); 168 var table = %_JSCollectionGetTable(this);
171 var numBuckets = ORDERED_HASH_TABLE_BUCKET_COUNT(table); 169 var numBuckets = ORDERED_HASH_TABLE_BUCKET_COUNT(table);
172 var hash = GetHash(key); 170 var hash = GetHash(key);
173 var entry = SetFindEntry(table, numBuckets, key, hash); 171 var entry = SetFindEntry(table, numBuckets, key, hash);
174 if (entry === NOT_FOUND) return false; 172 if (entry === NOT_FOUND) return false;
175 173
176 var nof = ORDERED_HASH_TABLE_ELEMENT_COUNT(table) - 1; 174 var nof = ORDERED_HASH_TABLE_ELEMENT_COUNT(table) - 1;
177 var nod = ORDERED_HASH_TABLE_DELETED_COUNT(table) + 1; 175 var nod = ORDERED_HASH_TABLE_DELETED_COUNT(table) + 1;
178 var index = ORDERED_HASH_SET_ENTRY_TO_INDEX(entry, numBuckets); 176 var index = ORDERED_HASH_SET_ENTRY_TO_INDEX(entry, numBuckets);
179 FIXED_ARRAY_SET(table, index, %_TheHole()); 177 FIXED_ARRAY_SET(table, index, %_TheHole());
180 ORDERED_HASH_TABLE_SET_ELEMENT_COUNT(table, nof); 178 ORDERED_HASH_TABLE_SET_ELEMENT_COUNT(table, nof);
181 ORDERED_HASH_TABLE_SET_DELETED_COUNT(table, nod); 179 ORDERED_HASH_TABLE_SET_DELETED_COUNT(table, nod);
182 if (nof < (numBuckets >>> 1)) %SetShrink(this); 180 if (nof < (numBuckets >>> 1)) %SetShrink(this);
183 return true; 181 return true;
184 } 182 }
185 183
186 184
187 function SetGetSize() { 185 function SetGetSize() {
188 if (!IS_SET(this)) { 186 if (!IS_SET(this)) {
189 throw MakeTypeError('incompatible_method_receiver', 187 throw MakeTypeError(kIncompatibleMethodReceiver,
190 ['Set.prototype.size', this]); 188 'Set.prototype.size', this);
191 } 189 }
192 var table = %_JSCollectionGetTable(this); 190 var table = %_JSCollectionGetTable(this);
193 return ORDERED_HASH_TABLE_ELEMENT_COUNT(table); 191 return ORDERED_HASH_TABLE_ELEMENT_COUNT(table);
194 } 192 }
195 193
196 194
197 function SetClearJS() { 195 function SetClearJS() {
198 if (!IS_SET(this)) { 196 if (!IS_SET(this)) {
199 throw MakeTypeError('incompatible_method_receiver', 197 throw MakeTypeError(kIncompatibleMethodReceiver,
200 ['Set.prototype.clear', this]); 198 'Set.prototype.clear', this);
201 } 199 }
202 %_SetClear(this); 200 %_SetClear(this);
203 } 201 }
204 202
205 203
206 function SetForEach(f, receiver) { 204 function SetForEach(f, receiver) {
207 if (!IS_SET(this)) { 205 if (!IS_SET(this)) {
208 throw MakeTypeError('incompatible_method_receiver', 206 throw MakeTypeError(kIncompatibleMethodReceiver,
209 ['Set.prototype.forEach', this]); 207 'Set.prototype.forEach', this);
210 } 208 }
211 209
212 if (!IS_SPEC_FUNCTION(f)) { 210 if (!IS_SPEC_FUNCTION(f)) throw MakeTypeError(kCalledNonCallable, f);
213 throw MakeTypeError('called_non_callable', [f]);
214 }
215 var needs_wrapper = false; 211 var needs_wrapper = false;
216 if (IS_NULL_OR_UNDEFINED(receiver)) { 212 if (IS_NULL_OR_UNDEFINED(receiver)) {
217 receiver = %GetDefaultReceiver(f) || receiver; 213 receiver = %GetDefaultReceiver(f) || receiver;
218 } else { 214 } else {
219 needs_wrapper = SHOULD_CREATE_WRAPPER(f, receiver); 215 needs_wrapper = SHOULD_CREATE_WRAPPER(f, receiver);
220 } 216 }
221 217
222 var iterator = new SetIterator(this, ITERATOR_KIND_VALUES); 218 var iterator = new SetIterator(this, ITERATOR_KIND_VALUES);
223 var key; 219 var key;
224 var stepping = DEBUG_IS_ACTIVE && %DebugCallbackSupportsStepping(f); 220 var stepping = DEBUG_IS_ACTIVE && %DebugCallbackSupportsStepping(f);
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
259 function MapConstructor(iterable) { 255 function MapConstructor(iterable) {
260 if (!%_IsConstructCall()) { 256 if (!%_IsConstructCall()) {
261 throw MakeTypeError('constructor_not_function', ['Map']); 257 throw MakeTypeError('constructor_not_function', ['Map']);
262 } 258 }
263 259
264 %_MapInitialize(this); 260 %_MapInitialize(this);
265 261
266 if (!IS_NULL_OR_UNDEFINED(iterable)) { 262 if (!IS_NULL_OR_UNDEFINED(iterable)) {
267 var adder = this.set; 263 var adder = this.set;
268 if (!IS_SPEC_FUNCTION(adder)) { 264 if (!IS_SPEC_FUNCTION(adder)) {
269 throw MakeTypeError(kPropertyNotFunction, ['set', this]); 265 throw MakeTypeError(kPropertyNotFunction, 'set', this);
270 } 266 }
271 267
272 for (var nextItem of iterable) { 268 for (var nextItem of iterable) {
273 if (!IS_SPEC_OBJECT(nextItem)) { 269 if (!IS_SPEC_OBJECT(nextItem)) {
274 throw MakeTypeError('iterator_value_not_an_object', [nextItem]); 270 throw MakeTypeError('iterator_value_not_an_object', [nextItem]);
275 } 271 }
276 %_CallFunction(this, nextItem[0], nextItem[1], adder); 272 %_CallFunction(this, nextItem[0], nextItem[1], adder);
277 } 273 }
278 } 274 }
279 } 275 }
280 276
281 277
282 function MapGet(key) { 278 function MapGet(key) {
283 if (!IS_MAP(this)) { 279 if (!IS_MAP(this)) {
284 throw MakeTypeError('incompatible_method_receiver', 280 throw MakeTypeError(kIncompatibleMethodReceiver,
285 ['Map.prototype.get', this]); 281 'Map.prototype.get', this);
286 } 282 }
287 var table = %_JSCollectionGetTable(this); 283 var table = %_JSCollectionGetTable(this);
288 var numBuckets = ORDERED_HASH_TABLE_BUCKET_COUNT(table); 284 var numBuckets = ORDERED_HASH_TABLE_BUCKET_COUNT(table);
289 var hash = GetHash(key); 285 var hash = GetHash(key);
290 var entry = MapFindEntry(table, numBuckets, key, hash); 286 var entry = MapFindEntry(table, numBuckets, key, hash);
291 if (entry === NOT_FOUND) return UNDEFINED; 287 if (entry === NOT_FOUND) return UNDEFINED;
292 return ORDERED_HASH_MAP_VALUE_AT(table, entry, numBuckets); 288 return ORDERED_HASH_MAP_VALUE_AT(table, entry, numBuckets);
293 } 289 }
294 290
295 291
296 function MapSet(key, value) { 292 function MapSet(key, value) {
297 if (!IS_MAP(this)) { 293 if (!IS_MAP(this)) {
298 throw MakeTypeError('incompatible_method_receiver', 294 throw MakeTypeError(kIncompatibleMethodReceiver,
299 ['Map.prototype.set', this]); 295 'Map.prototype.set', this);
300 } 296 }
301 // Normalize -0 to +0 as required by the spec. 297 // Normalize -0 to +0 as required by the spec.
302 // Even though we use SameValueZero as the comparison for the keys we don't 298 // Even though we use SameValueZero as the comparison for the keys we don't
303 // want to ever store -0 as the key since the key is directly exposed when 299 // want to ever store -0 as the key since the key is directly exposed when
304 // doing iteration. 300 // doing iteration.
305 if (key === 0) { 301 if (key === 0) {
306 key = 0; 302 key = 0;
307 } 303 }
308 304
309 var table = %_JSCollectionGetTable(this); 305 var table = %_JSCollectionGetTable(this);
(...skipping 26 matching lines...) Expand all
336 ORDERED_HASH_TABLE_SET_ELEMENT_COUNT(table, nof + 1); 332 ORDERED_HASH_TABLE_SET_ELEMENT_COUNT(table, nof + 1);
337 FIXED_ARRAY_SET(table, index, key); 333 FIXED_ARRAY_SET(table, index, key);
338 FIXED_ARRAY_SET(table, index + 1, value); 334 FIXED_ARRAY_SET(table, index + 1, value);
339 FIXED_ARRAY_SET(table, index + 2, chainEntry); 335 FIXED_ARRAY_SET(table, index + 2, chainEntry);
340 return this; 336 return this;
341 } 337 }
342 338
343 339
344 function MapHas(key) { 340 function MapHas(key) {
345 if (!IS_MAP(this)) { 341 if (!IS_MAP(this)) {
346 throw MakeTypeError('incompatible_method_receiver', 342 throw MakeTypeError(kIncompatibleMethodReceiver,
347 ['Map.prototype.has', this]); 343 'Map.prototype.has', this);
348 } 344 }
349 var table = %_JSCollectionGetTable(this); 345 var table = %_JSCollectionGetTable(this);
350 var numBuckets = ORDERED_HASH_TABLE_BUCKET_COUNT(table); 346 var numBuckets = ORDERED_HASH_TABLE_BUCKET_COUNT(table);
351 var hash = GetHash(key); 347 var hash = GetHash(key);
352 return MapFindEntry(table, numBuckets, key, hash) !== NOT_FOUND; 348 return MapFindEntry(table, numBuckets, key, hash) !== NOT_FOUND;
353 } 349 }
354 350
355 351
356 function MapDelete(key) { 352 function MapDelete(key) {
357 if (!IS_MAP(this)) { 353 if (!IS_MAP(this)) {
358 throw MakeTypeError('incompatible_method_receiver', 354 throw MakeTypeError(kIncompatibleMethodReceiver,
359 ['Map.prototype.delete', this]); 355 'Map.prototype.delete', this);
360 } 356 }
361 var table = %_JSCollectionGetTable(this); 357 var table = %_JSCollectionGetTable(this);
362 var numBuckets = ORDERED_HASH_TABLE_BUCKET_COUNT(table); 358 var numBuckets = ORDERED_HASH_TABLE_BUCKET_COUNT(table);
363 var hash = GetHash(key); 359 var hash = GetHash(key);
364 var entry = MapFindEntry(table, numBuckets, key, hash); 360 var entry = MapFindEntry(table, numBuckets, key, hash);
365 if (entry === NOT_FOUND) return false; 361 if (entry === NOT_FOUND) return false;
366 362
367 var nof = ORDERED_HASH_TABLE_ELEMENT_COUNT(table) - 1; 363 var nof = ORDERED_HASH_TABLE_ELEMENT_COUNT(table) - 1;
368 var nod = ORDERED_HASH_TABLE_DELETED_COUNT(table) + 1; 364 var nod = ORDERED_HASH_TABLE_DELETED_COUNT(table) + 1;
369 var index = ORDERED_HASH_MAP_ENTRY_TO_INDEX(entry, numBuckets); 365 var index = ORDERED_HASH_MAP_ENTRY_TO_INDEX(entry, numBuckets);
370 FIXED_ARRAY_SET(table, index, %_TheHole()); 366 FIXED_ARRAY_SET(table, index, %_TheHole());
371 FIXED_ARRAY_SET(table, index + 1, %_TheHole()); 367 FIXED_ARRAY_SET(table, index + 1, %_TheHole());
372 ORDERED_HASH_TABLE_SET_ELEMENT_COUNT(table, nof); 368 ORDERED_HASH_TABLE_SET_ELEMENT_COUNT(table, nof);
373 ORDERED_HASH_TABLE_SET_DELETED_COUNT(table, nod); 369 ORDERED_HASH_TABLE_SET_DELETED_COUNT(table, nod);
374 if (nof < (numBuckets >>> 1)) %MapShrink(this); 370 if (nof < (numBuckets >>> 1)) %MapShrink(this);
375 return true; 371 return true;
376 } 372 }
377 373
378 374
379 function MapGetSize() { 375 function MapGetSize() {
380 if (!IS_MAP(this)) { 376 if (!IS_MAP(this)) {
381 throw MakeTypeError('incompatible_method_receiver', 377 throw MakeTypeError(kIncompatibleMethodReceiver,
382 ['Map.prototype.size', this]); 378 'Map.prototype.size', this);
383 } 379 }
384 var table = %_JSCollectionGetTable(this); 380 var table = %_JSCollectionGetTable(this);
385 return ORDERED_HASH_TABLE_ELEMENT_COUNT(table); 381 return ORDERED_HASH_TABLE_ELEMENT_COUNT(table);
386 } 382 }
387 383
388 384
389 function MapClearJS() { 385 function MapClearJS() {
390 if (!IS_MAP(this)) { 386 if (!IS_MAP(this)) {
391 throw MakeTypeError('incompatible_method_receiver', 387 throw MakeTypeError(kIncompatibleMethodReceiver,
392 ['Map.prototype.clear', this]); 388 'Map.prototype.clear', this);
393 } 389 }
394 %_MapClear(this); 390 %_MapClear(this);
395 } 391 }
396 392
397 393
398 function MapForEach(f, receiver) { 394 function MapForEach(f, receiver) {
399 if (!IS_MAP(this)) { 395 if (!IS_MAP(this)) {
400 throw MakeTypeError('incompatible_method_receiver', 396 throw MakeTypeError(kIncompatibleMethodReceiver,
401 ['Map.prototype.forEach', this]); 397 'Map.prototype.forEach', this);
402 } 398 }
403 399
404 if (!IS_SPEC_FUNCTION(f)) { 400 if (!IS_SPEC_FUNCTION(f)) throw MakeTypeError(kCalledNonCallable, f);
405 throw MakeTypeError('called_non_callable', [f]);
406 }
407 var needs_wrapper = false; 401 var needs_wrapper = false;
408 if (IS_NULL_OR_UNDEFINED(receiver)) { 402 if (IS_NULL_OR_UNDEFINED(receiver)) {
409 receiver = %GetDefaultReceiver(f) || receiver; 403 receiver = %GetDefaultReceiver(f) || receiver;
410 } else { 404 } else {
411 needs_wrapper = SHOULD_CREATE_WRAPPER(f, receiver); 405 needs_wrapper = SHOULD_CREATE_WRAPPER(f, receiver);
412 } 406 }
413 407
414 var iterator = new MapIterator(this, ITERATOR_KIND_ENTRIES); 408 var iterator = new MapIterator(this, ITERATOR_KIND_ENTRIES);
415 var stepping = DEBUG_IS_ACTIVE && %DebugCallbackSupportsStepping(f); 409 var stepping = DEBUG_IS_ACTIVE && %DebugCallbackSupportsStepping(f);
416 var value_array = [UNDEFINED, UNDEFINED]; 410 var value_array = [UNDEFINED, UNDEFINED];
(...skipping 20 matching lines...) Expand all
437 InstallFunctions(GlobalMap.prototype, DONT_ENUM, [ 431 InstallFunctions(GlobalMap.prototype, DONT_ENUM, [
438 "get", MapGet, 432 "get", MapGet,
439 "set", MapSet, 433 "set", MapSet,
440 "has", MapHas, 434 "has", MapHas,
441 "delete", MapDelete, 435 "delete", MapDelete,
442 "clear", MapClearJS, 436 "clear", MapClearJS,
443 "forEach", MapForEach 437 "forEach", MapForEach
444 ]); 438 ]);
445 439
446 })(); 440 })();
OLDNEW
« no previous file with comments | « src/arraybuffer.js ('k') | src/collection-iterator.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698