| OLD | NEW |
| 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 22 matching lines...) Expand all Loading... |
| 33 | 33 |
| 34 var $Set = global.Set; | 34 var $Set = global.Set; |
| 35 var $Map = global.Map; | 35 var $Map = global.Map; |
| 36 var $WeakMap = global.WeakMap; | 36 var $WeakMap = global.WeakMap; |
| 37 var $WeakSet = global.WeakSet; | 37 var $WeakSet = global.WeakSet; |
| 38 | 38 |
| 39 // Global sentinel to be used instead of undefined keys, which are not | 39 // Global sentinel to be used instead of undefined keys, which are not |
| 40 // supported internally but required for Harmony sets and maps. | 40 // supported internally but required for Harmony sets and maps. |
| 41 var undefined_sentinel = {}; | 41 var undefined_sentinel = {}; |
| 42 | 42 |
| 43 |
| 44 // Map and Set uses SameValueZero which means that +0 and -0 should be treated |
| 45 // as the same value. |
| 46 function NormalizeKey(key) { |
| 47 if (IS_UNDEFINED(key)) { |
| 48 return undefined_sentinel; |
| 49 } |
| 50 |
| 51 if (key === 0) { |
| 52 return 0; |
| 53 } |
| 54 |
| 55 return key; |
| 56 } |
| 57 |
| 58 |
| 43 // ------------------------------------------------------------------- | 59 // ------------------------------------------------------------------- |
| 44 // Harmony Set | 60 // Harmony Set |
| 45 | 61 |
| 46 function SetConstructor() { | 62 function SetConstructor() { |
| 47 if (%_IsConstructCall()) { | 63 if (%_IsConstructCall()) { |
| 48 %SetInitialize(this); | 64 %SetInitialize(this); |
| 49 } else { | 65 } else { |
| 50 throw MakeTypeError('constructor_not_function', ['Set']); | 66 throw MakeTypeError('constructor_not_function', ['Set']); |
| 51 } | 67 } |
| 52 } | 68 } |
| 53 | 69 |
| 54 | 70 |
| 55 function SetAdd(key) { | 71 function SetAdd(key) { |
| 56 if (!IS_SET(this)) { | 72 if (!IS_SET(this)) { |
| 57 throw MakeTypeError('incompatible_method_receiver', | 73 throw MakeTypeError('incompatible_method_receiver', |
| 58 ['Set.prototype.add', this]); | 74 ['Set.prototype.add', this]); |
| 59 } | 75 } |
| 60 if (IS_UNDEFINED(key)) { | 76 return %SetAdd(this, NormalizeKey(key)); |
| 61 key = undefined_sentinel; | |
| 62 } | |
| 63 return %SetAdd(this, key); | |
| 64 } | 77 } |
| 65 | 78 |
| 66 | 79 |
| 67 function SetHas(key) { | 80 function SetHas(key) { |
| 68 if (!IS_SET(this)) { | 81 if (!IS_SET(this)) { |
| 69 throw MakeTypeError('incompatible_method_receiver', | 82 throw MakeTypeError('incompatible_method_receiver', |
| 70 ['Set.prototype.has', this]); | 83 ['Set.prototype.has', this]); |
| 71 } | 84 } |
| 72 if (IS_UNDEFINED(key)) { | 85 return %SetHas(this, NormalizeKey(key)); |
| 73 key = undefined_sentinel; | |
| 74 } | |
| 75 return %SetHas(this, key); | |
| 76 } | 86 } |
| 77 | 87 |
| 78 | 88 |
| 79 function SetDelete(key) { | 89 function SetDelete(key) { |
| 80 if (!IS_SET(this)) { | 90 if (!IS_SET(this)) { |
| 81 throw MakeTypeError('incompatible_method_receiver', | 91 throw MakeTypeError('incompatible_method_receiver', |
| 82 ['Set.prototype.delete', this]); | 92 ['Set.prototype.delete', this]); |
| 83 } | 93 } |
| 84 if (IS_UNDEFINED(key)) { | 94 key = NormalizeKey(key); |
| 85 key = undefined_sentinel; | |
| 86 } | |
| 87 if (%SetHas(this, key)) { | 95 if (%SetHas(this, key)) { |
| 88 %SetDelete(this, key); | 96 %SetDelete(this, key); |
| 89 return true; | 97 return true; |
| 90 } else { | 98 } else { |
| 91 return false; | 99 return false; |
| 92 } | 100 } |
| 93 } | 101 } |
| 94 | 102 |
| 95 | 103 |
| 96 function SetGetSize() { | 104 function SetGetSize() { |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 144 throw MakeTypeError('constructor_not_function', ['Map']); | 152 throw MakeTypeError('constructor_not_function', ['Map']); |
| 145 } | 153 } |
| 146 } | 154 } |
| 147 | 155 |
| 148 | 156 |
| 149 function MapGet(key) { | 157 function MapGet(key) { |
| 150 if (!IS_MAP(this)) { | 158 if (!IS_MAP(this)) { |
| 151 throw MakeTypeError('incompatible_method_receiver', | 159 throw MakeTypeError('incompatible_method_receiver', |
| 152 ['Map.prototype.get', this]); | 160 ['Map.prototype.get', this]); |
| 153 } | 161 } |
| 154 if (IS_UNDEFINED(key)) { | 162 return %MapGet(this, NormalizeKey(key)); |
| 155 key = undefined_sentinel; | |
| 156 } | |
| 157 return %MapGet(this, key); | |
| 158 } | 163 } |
| 159 | 164 |
| 160 | 165 |
| 161 function MapSet(key, value) { | 166 function MapSet(key, value) { |
| 162 if (!IS_MAP(this)) { | 167 if (!IS_MAP(this)) { |
| 163 throw MakeTypeError('incompatible_method_receiver', | 168 throw MakeTypeError('incompatible_method_receiver', |
| 164 ['Map.prototype.set', this]); | 169 ['Map.prototype.set', this]); |
| 165 } | 170 } |
| 166 if (IS_UNDEFINED(key)) { | 171 return %MapSet(this, NormalizeKey(key), value); |
| 167 key = undefined_sentinel; | |
| 168 } | |
| 169 return %MapSet(this, key, value); | |
| 170 } | 172 } |
| 171 | 173 |
| 172 | 174 |
| 173 function MapHas(key) { | 175 function MapHas(key) { |
| 174 if (!IS_MAP(this)) { | 176 if (!IS_MAP(this)) { |
| 175 throw MakeTypeError('incompatible_method_receiver', | 177 throw MakeTypeError('incompatible_method_receiver', |
| 176 ['Map.prototype.has', this]); | 178 ['Map.prototype.has', this]); |
| 177 } | 179 } |
| 178 if (IS_UNDEFINED(key)) { | 180 return %MapHas(this, NormalizeKey(key)); |
| 179 key = undefined_sentinel; | |
| 180 } | |
| 181 return %MapHas(this, key); | |
| 182 } | 181 } |
| 183 | 182 |
| 184 | 183 |
| 185 function MapDelete(key) { | 184 function MapDelete(key) { |
| 186 if (!IS_MAP(this)) { | 185 if (!IS_MAP(this)) { |
| 187 throw MakeTypeError('incompatible_method_receiver', | 186 throw MakeTypeError('incompatible_method_receiver', |
| 188 ['Map.prototype.delete', this]); | 187 ['Map.prototype.delete', this]); |
| 189 } | 188 } |
| 190 if (IS_UNDEFINED(key)) { | 189 return %MapDelete(this, NormalizeKey(key)); |
| 191 key = undefined_sentinel; | |
| 192 } | |
| 193 return %MapDelete(this, key); | |
| 194 } | 190 } |
| 195 | 191 |
| 196 | 192 |
| 197 function MapGetSize() { | 193 function MapGetSize() { |
| 198 if (!IS_MAP(this)) { | 194 if (!IS_MAP(this)) { |
| 199 throw MakeTypeError('incompatible_method_receiver', | 195 throw MakeTypeError('incompatible_method_receiver', |
| 200 ['Map.prototype.size', this]); | 196 ['Map.prototype.size', this]); |
| 201 } | 197 } |
| 202 return %MapGetSize(this); | 198 return %MapGetSize(this); |
| 203 } | 199 } |
| (...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 398 // Set up the non-enumerable functions on the WeakSet prototype object. | 394 // Set up the non-enumerable functions on the WeakSet prototype object. |
| 399 InstallFunctions($WeakSet.prototype, DONT_ENUM, $Array( | 395 InstallFunctions($WeakSet.prototype, DONT_ENUM, $Array( |
| 400 "add", WeakSetAdd, | 396 "add", WeakSetAdd, |
| 401 "has", WeakSetHas, | 397 "has", WeakSetHas, |
| 402 "delete", WeakSetDelete, | 398 "delete", WeakSetDelete, |
| 403 "clear", WeakSetClear | 399 "clear", WeakSetClear |
| 404 )); | 400 )); |
| 405 } | 401 } |
| 406 | 402 |
| 407 SetUpWeakSet(); | 403 SetUpWeakSet(); |
| OLD | NEW |