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

Side by Side Diff: src/collection.js

Issue 10658014: Fix Harmony Maps and WeakMaps for undefined values. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Adapted unit test case. Created 8 years, 6 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 2011 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
11 // with the distribution. 11 // with the distribution.
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
122 122
123 123
124 function MapHas(key) { 124 function MapHas(key) {
125 if (!IS_MAP(this)) { 125 if (!IS_MAP(this)) {
126 throw MakeTypeError('incompatible_method_receiver', 126 throw MakeTypeError('incompatible_method_receiver',
127 ['Map.prototype.has', this]); 127 ['Map.prototype.has', this]);
128 } 128 }
129 if (IS_UNDEFINED(key)) { 129 if (IS_UNDEFINED(key)) {
130 key = undefined_sentinel; 130 key = undefined_sentinel;
131 } 131 }
132 return !IS_UNDEFINED(%MapGet(this, key)); 132 return %MapHas(this, key);
133 } 133 }
134 134
135 135
136 function MapDelete(key) { 136 function MapDelete(key) {
137 if (!IS_MAP(this)) { 137 if (!IS_MAP(this)) {
138 throw MakeTypeError('incompatible_method_receiver', 138 throw MakeTypeError('incompatible_method_receiver',
139 ['Map.prototype.delete', this]); 139 ['Map.prototype.delete', this]);
140 } 140 }
141 if (IS_UNDEFINED(key)) { 141 if (IS_UNDEFINED(key)) {
142 key = undefined_sentinel; 142 key = undefined_sentinel;
143 } 143 }
144 if (!IS_UNDEFINED(%MapGet(this, key))) { 144 return %MapDelete(this, key);
145 %MapSet(this, key, void 0);
146 return true;
147 } else {
148 return false;
149 }
150 } 145 }
151 146
152 147
153 function WeakMapConstructor() { 148 function WeakMapConstructor() {
154 if (%_IsConstructCall()) { 149 if (%_IsConstructCall()) {
155 %WeakMapInitialize(this); 150 %WeakMapInitialize(this);
156 } else { 151 } else {
157 return new $WeakMap(); 152 return new $WeakMap();
158 } 153 }
159 } 154 }
(...skipping 24 matching lines...) Expand all
184 179
185 180
186 function WeakMapHas(key) { 181 function WeakMapHas(key) {
187 if (!IS_WEAKMAP(this)) { 182 if (!IS_WEAKMAP(this)) {
188 throw MakeTypeError('incompatible_method_receiver', 183 throw MakeTypeError('incompatible_method_receiver',
189 ['WeakMap.prototype.has', this]); 184 ['WeakMap.prototype.has', this]);
190 } 185 }
191 if (!IS_SPEC_OBJECT(key)) { 186 if (!IS_SPEC_OBJECT(key)) {
192 throw %MakeTypeError('invalid_weakmap_key', [this, key]); 187 throw %MakeTypeError('invalid_weakmap_key', [this, key]);
193 } 188 }
194 return !IS_UNDEFINED(%WeakMapGet(this, key)); 189 return %WeakMapHas(this, key);
195 } 190 }
196 191
197 192
198 function WeakMapDelete(key) { 193 function WeakMapDelete(key) {
199 if (!IS_WEAKMAP(this)) { 194 if (!IS_WEAKMAP(this)) {
200 throw MakeTypeError('incompatible_method_receiver', 195 throw MakeTypeError('incompatible_method_receiver',
201 ['WeakMap.prototype.delete', this]); 196 ['WeakMap.prototype.delete', this]);
202 } 197 }
203 if (!IS_SPEC_OBJECT(key)) { 198 if (!IS_SPEC_OBJECT(key)) {
204 throw %MakeTypeError('invalid_weakmap_key', [this, key]); 199 throw %MakeTypeError('invalid_weakmap_key', [this, key]);
205 } 200 }
206 if (!IS_UNDEFINED(%WeakMapGet(this, key))) { 201 return %WeakMapDelete(this, key);
207 %WeakMapSet(this, key, void 0);
208 return true;
209 } else {
210 return false;
211 }
212 } 202 }
213 203
214 // ------------------------------------------------------------------- 204 // -------------------------------------------------------------------
215 205
216 (function () { 206 (function () {
217 %CheckIsBootstrapping(); 207 %CheckIsBootstrapping();
218 208
219 // Set up the Set and Map constructor function. 209 // Set up the Set and Map constructor function.
220 %SetCode($Set, SetConstructor); 210 %SetCode($Set, SetConstructor);
221 %SetCode($Map, MapConstructor); 211 %SetCode($Map, MapConstructor);
(...skipping 24 matching lines...) Expand all
246 %SetProperty($WeakMap.prototype, "constructor", $WeakMap, DONT_ENUM); 236 %SetProperty($WeakMap.prototype, "constructor", $WeakMap, DONT_ENUM);
247 237
248 // Set up the non-enumerable functions on the WeakMap prototype object. 238 // Set up the non-enumerable functions on the WeakMap prototype object.
249 InstallFunctions($WeakMap.prototype, DONT_ENUM, $Array( 239 InstallFunctions($WeakMap.prototype, DONT_ENUM, $Array(
250 "get", WeakMapGet, 240 "get", WeakMapGet,
251 "set", WeakMapSet, 241 "set", WeakMapSet,
252 "has", WeakMapHas, 242 "has", WeakMapHas,
253 "delete", WeakMapDelete 243 "delete", WeakMapDelete
254 )); 244 ));
255 })(); 245 })();
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