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

Side by Side Diff: src/collection.js

Issue 478683002: ES6: Make sure we do not store -0 as the key in Map/Set (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 6 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 | « no previous file | test/mjsunit/es6/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 // 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 "use strict"; 5 "use strict";
6 6
7 // This file relies on the fact that the following declaration has been made 7 // This file relies on the fact that the following declaration has been made
8 // in runtime.js: 8 // in runtime.js:
9 // var $Array = global.Array; 9 // var $Array = global.Array;
10 10
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
42 %_CallFunction(this, next.value, adder); 42 %_CallFunction(this, next.value, adder);
43 } 43 }
44 } 44 }
45 45
46 46
47 function SetAddJS(key) { 47 function SetAddJS(key) {
48 if (!IS_SET(this)) { 48 if (!IS_SET(this)) {
49 throw MakeTypeError('incompatible_method_receiver', 49 throw MakeTypeError('incompatible_method_receiver',
50 ['Set.prototype.add', this]); 50 ['Set.prototype.add', this]);
51 } 51 }
52 // Normalize -0 to +0 as required by the spec.
53 // Even though we use SameValueZero as the comparison for the keys we don't
54 // want to ever store -0 as the key since the key is directly exposed when
55 // doing iteration.
56 if (key === 0) {
57 key = 0;
58 }
52 return %SetAdd(this, key); 59 return %SetAdd(this, key);
53 } 60 }
54 61
55 62
56 function SetHasJS(key) { 63 function SetHasJS(key) {
57 if (!IS_SET(this)) { 64 if (!IS_SET(this)) {
58 throw MakeTypeError('incompatible_method_receiver', 65 throw MakeTypeError('incompatible_method_receiver',
59 ['Set.prototype.has', this]); 66 ['Set.prototype.has', this]);
60 } 67 }
61 return %SetHas(this, key); 68 return %SetHas(this, key);
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
179 } 186 }
180 return %MapGet(this, key); 187 return %MapGet(this, key);
181 } 188 }
182 189
183 190
184 function MapSetJS(key, value) { 191 function MapSetJS(key, value) {
185 if (!IS_MAP(this)) { 192 if (!IS_MAP(this)) {
186 throw MakeTypeError('incompatible_method_receiver', 193 throw MakeTypeError('incompatible_method_receiver',
187 ['Map.prototype.set', this]); 194 ['Map.prototype.set', this]);
188 } 195 }
196 // Normalize -0 to +0 as required by the spec.
197 // Even though we use SameValueZero as the comparison for the keys we don't
198 // want to ever store -0 as the key since the key is directly exposed when
199 // doing iteration.
200 if (key === 0) {
201 key = 0;
202 }
189 return %MapSet(this, key, value); 203 return %MapSet(this, key, value);
190 } 204 }
191 205
192 206
193 function MapHasJS(key) { 207 function MapHasJS(key) {
194 if (!IS_MAP(this)) { 208 if (!IS_MAP(this)) {
195 throw MakeTypeError('incompatible_method_receiver', 209 throw MakeTypeError('incompatible_method_receiver',
196 ['Map.prototype.has', this]); 210 ['Map.prototype.has', this]);
197 } 211 }
198 return %MapHas(this, key); 212 return %MapHas(this, key);
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
263 "get", MapGetJS, 277 "get", MapGetJS,
264 "set", MapSetJS, 278 "set", MapSetJS,
265 "has", MapHasJS, 279 "has", MapHasJS,
266 "delete", MapDeleteJS, 280 "delete", MapDeleteJS,
267 "clear", MapClearJS, 281 "clear", MapClearJS,
268 "forEach", MapForEach 282 "forEach", MapForEach
269 )); 283 ));
270 } 284 }
271 285
272 SetUpMap(); 286 SetUpMap();
OLDNEW
« no previous file with comments | « no previous file | test/mjsunit/es6/collections.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698