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

Side by Side Diff: src/collection.js

Issue 299703004: Use SameValueZero for Map and Set (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 6 years, 7 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 | src/objects.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 // 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
11 var $Set = global.Set; 11 var $Set = global.Set;
12 var $Map = global.Map; 12 var $Map = global.Map;
13 13
14 // Global sentinel to be used instead of undefined keys, which are not
15 // supported internally but required for Harmony sets and maps.
16 var undefined_sentinel = {};
17
18
19 // Map and Set uses SameValueZero which means that +0 and -0 should be treated
20 // as the same value.
21 function NormalizeKey(key) {
22 if (IS_UNDEFINED(key)) {
23 return undefined_sentinel;
24 }
25
26 if (key === 0) {
27 return 0;
28 }
29
30 return key;
31 }
32
33 14
34 // ------------------------------------------------------------------- 15 // -------------------------------------------------------------------
35 // Harmony Set 16 // Harmony Set
36 17
37 function SetConstructor() { 18 function SetConstructor() {
38 if (%_IsConstructCall()) { 19 if (%_IsConstructCall()) {
39 %SetInitialize(this); 20 %SetInitialize(this);
40 } else { 21 } else {
41 throw MakeTypeError('constructor_not_function', ['Set']); 22 throw MakeTypeError('constructor_not_function', ['Set']);
42 } 23 }
43 } 24 }
44 25
45 26
46 function SetAddJS(key) { 27 function SetAddJS(key) {
47 if (!IS_SET(this)) { 28 if (!IS_SET(this)) {
48 throw MakeTypeError('incompatible_method_receiver', 29 throw MakeTypeError('incompatible_method_receiver',
49 ['Set.prototype.add', this]); 30 ['Set.prototype.add', this]);
50 } 31 }
51 return %SetAdd(this, NormalizeKey(key)); 32 return %SetAdd(this, key);
52 } 33 }
53 34
54 35
55 function SetHasJS(key) { 36 function SetHasJS(key) {
56 if (!IS_SET(this)) { 37 if (!IS_SET(this)) {
57 throw MakeTypeError('incompatible_method_receiver', 38 throw MakeTypeError('incompatible_method_receiver',
58 ['Set.prototype.has', this]); 39 ['Set.prototype.has', this]);
59 } 40 }
60 return %SetHas(this, NormalizeKey(key)); 41 return %SetHas(this, key);
61 } 42 }
62 43
63 44
64 function SetDeleteJS(key) { 45 function SetDeleteJS(key) {
65 if (!IS_SET(this)) { 46 if (!IS_SET(this)) {
66 throw MakeTypeError('incompatible_method_receiver', 47 throw MakeTypeError('incompatible_method_receiver',
67 ['Set.prototype.delete', this]); 48 ['Set.prototype.delete', this]);
68 } 49 }
69 key = NormalizeKey(key);
70 if (%SetHas(this, key)) { 50 if (%SetHas(this, key)) {
71 %SetDelete(this, key); 51 %SetDelete(this, key);
72 return true; 52 return true;
73 } else { 53 } else {
74 return false; 54 return false;
75 } 55 }
76 } 56 }
77 57
78 58
79 function SetGetSizeJS() { 59 function SetGetSizeJS() {
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
147 throw MakeTypeError('constructor_not_function', ['Map']); 127 throw MakeTypeError('constructor_not_function', ['Map']);
148 } 128 }
149 } 129 }
150 130
151 131
152 function MapGetJS(key) { 132 function MapGetJS(key) {
153 if (!IS_MAP(this)) { 133 if (!IS_MAP(this)) {
154 throw MakeTypeError('incompatible_method_receiver', 134 throw MakeTypeError('incompatible_method_receiver',
155 ['Map.prototype.get', this]); 135 ['Map.prototype.get', this]);
156 } 136 }
157 return %MapGet(this, NormalizeKey(key)); 137 return %MapGet(this, key);
158 } 138 }
159 139
160 140
161 function MapSetJS(key, value) { 141 function MapSetJS(key, value) {
162 if (!IS_MAP(this)) { 142 if (!IS_MAP(this)) {
163 throw MakeTypeError('incompatible_method_receiver', 143 throw MakeTypeError('incompatible_method_receiver',
164 ['Map.prototype.set', this]); 144 ['Map.prototype.set', this]);
165 } 145 }
166 return %MapSet(this, NormalizeKey(key), value); 146 return %MapSet(this, key, value);
167 } 147 }
168 148
169 149
170 function MapHasJS(key) { 150 function MapHasJS(key) {
171 if (!IS_MAP(this)) { 151 if (!IS_MAP(this)) {
172 throw MakeTypeError('incompatible_method_receiver', 152 throw MakeTypeError('incompatible_method_receiver',
173 ['Map.prototype.has', this]); 153 ['Map.prototype.has', this]);
174 } 154 }
175 return %MapHas(this, NormalizeKey(key)); 155 return %MapHas(this, key);
176 } 156 }
177 157
178 158
179 function MapDeleteJS(key) { 159 function MapDeleteJS(key) {
180 if (!IS_MAP(this)) { 160 if (!IS_MAP(this)) {
181 throw MakeTypeError('incompatible_method_receiver', 161 throw MakeTypeError('incompatible_method_receiver',
182 ['Map.prototype.delete', this]); 162 ['Map.prototype.delete', this]);
183 } 163 }
184 return %MapDelete(this, NormalizeKey(key)); 164 return %MapDelete(this, key);
185 } 165 }
186 166
187 167
188 function MapGetSizeJS() { 168 function MapGetSizeJS() {
189 if (!IS_MAP(this)) { 169 if (!IS_MAP(this)) {
190 throw MakeTypeError('incompatible_method_receiver', 170 throw MakeTypeError('incompatible_method_receiver',
191 ['Map.prototype.size', this]); 171 ['Map.prototype.size', this]);
192 } 172 }
193 return %MapGetSize(this); 173 return %MapGetSize(this);
194 } 174 }
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
238 "get", MapGetJS, 218 "get", MapGetJS,
239 "set", MapSetJS, 219 "set", MapSetJS,
240 "has", MapHasJS, 220 "has", MapHasJS,
241 "delete", MapDeleteJS, 221 "delete", MapDeleteJS,
242 "clear", MapClearJS, 222 "clear", MapClearJS,
243 "forEach", MapForEach 223 "forEach", MapForEach
244 )); 224 ));
245 } 225 }
246 226
247 SetUpMap(); 227 SetUpMap();
OLDNEW
« no previous file with comments | « no previous file | src/objects.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698