| OLD | NEW |
| 1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 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 29 matching lines...) Expand all Loading... |
| 40 function SetConstructor() { | 40 function SetConstructor() { |
| 41 if (%_IsConstructCall()) { | 41 if (%_IsConstructCall()) { |
| 42 %SetInitialize(this); | 42 %SetInitialize(this); |
| 43 } else { | 43 } else { |
| 44 return new $Set(); | 44 return new $Set(); |
| 45 } | 45 } |
| 46 } | 46 } |
| 47 | 47 |
| 48 | 48 |
| 49 function SetAdd(key) { | 49 function SetAdd(key) { |
| 50 if (!IS_SET(this)) { |
| 51 throw MakeTypeError('incompatible_method_receiver', |
| 52 ['Set.prototype.add', this]); |
| 53 } |
| 50 if (IS_UNDEFINED(key)) { | 54 if (IS_UNDEFINED(key)) { |
| 51 key = undefined_sentinel; | 55 key = undefined_sentinel; |
| 52 } | 56 } |
| 53 return %SetAdd(this, key); | 57 return %SetAdd(this, key); |
| 54 } | 58 } |
| 55 | 59 |
| 56 | 60 |
| 57 function SetHas(key) { | 61 function SetHas(key) { |
| 62 if (!IS_SET(this)) { |
| 63 throw MakeTypeError('incompatible_method_receiver', |
| 64 ['Set.prototype.has', this]); |
| 65 } |
| 58 if (IS_UNDEFINED(key)) { | 66 if (IS_UNDEFINED(key)) { |
| 59 key = undefined_sentinel; | 67 key = undefined_sentinel; |
| 60 } | 68 } |
| 61 return %SetHas(this, key); | 69 return %SetHas(this, key); |
| 62 } | 70 } |
| 63 | 71 |
| 64 | 72 |
| 65 function SetDelete(key) { | 73 function SetDelete(key) { |
| 74 if (!IS_SET(this)) { |
| 75 throw MakeTypeError('incompatible_method_receiver', |
| 76 ['Set.prototype.delete', this]); |
| 77 } |
| 66 if (IS_UNDEFINED(key)) { | 78 if (IS_UNDEFINED(key)) { |
| 67 key = undefined_sentinel; | 79 key = undefined_sentinel; |
| 68 } | 80 } |
| 69 return %SetDelete(this, key); | 81 return %SetDelete(this, key); |
| 70 } | 82 } |
| 71 | 83 |
| 72 | 84 |
| 73 function MapConstructor() { | 85 function MapConstructor() { |
| 74 if (%_IsConstructCall()) { | 86 if (%_IsConstructCall()) { |
| 75 %MapInitialize(this); | 87 %MapInitialize(this); |
| 76 } else { | 88 } else { |
| 77 return new $Map(); | 89 return new $Map(); |
| 78 } | 90 } |
| 79 } | 91 } |
| 80 | 92 |
| 81 | 93 |
| 82 function MapGet(key) { | 94 function MapGet(key) { |
| 95 if (!IS_MAP(this)) { |
| 96 throw MakeTypeError('incompatible_method_receiver', |
| 97 ['Map.prototype.get', this]); |
| 98 } |
| 83 if (IS_UNDEFINED(key)) { | 99 if (IS_UNDEFINED(key)) { |
| 84 key = undefined_sentinel; | 100 key = undefined_sentinel; |
| 85 } | 101 } |
| 86 return %MapGet(this, key); | 102 return %MapGet(this, key); |
| 87 } | 103 } |
| 88 | 104 |
| 89 | 105 |
| 90 function MapSet(key, value) { | 106 function MapSet(key, value) { |
| 107 if (!IS_MAP(this)) { |
| 108 throw MakeTypeError('incompatible_method_receiver', |
| 109 ['Map.prototype.set', this]); |
| 110 } |
| 91 if (IS_UNDEFINED(key)) { | 111 if (IS_UNDEFINED(key)) { |
| 92 key = undefined_sentinel; | 112 key = undefined_sentinel; |
| 93 } | 113 } |
| 94 return %MapSet(this, key, value); | 114 return %MapSet(this, key, value); |
| 95 } | 115 } |
| 96 | 116 |
| 97 | 117 |
| 98 function MapHas(key) { | 118 function MapHas(key) { |
| 119 if (!IS_MAP(this)) { |
| 120 throw MakeTypeError('incompatible_method_receiver', |
| 121 ['Map.prototype.has', this]); |
| 122 } |
| 99 if (IS_UNDEFINED(key)) { | 123 if (IS_UNDEFINED(key)) { |
| 100 key = undefined_sentinel; | 124 key = undefined_sentinel; |
| 101 } | 125 } |
| 102 return !IS_UNDEFINED(%MapGet(this, key)); | 126 return !IS_UNDEFINED(%MapGet(this, key)); |
| 103 } | 127 } |
| 104 | 128 |
| 105 | 129 |
| 106 function MapDelete(key) { | 130 function MapDelete(key) { |
| 131 if (!IS_MAP(this)) { |
| 132 throw MakeTypeError('incompatible_method_receiver', |
| 133 ['Map.prototype.delete', this]); |
| 134 } |
| 107 if (IS_UNDEFINED(key)) { | 135 if (IS_UNDEFINED(key)) { |
| 108 key = undefined_sentinel; | 136 key = undefined_sentinel; |
| 109 } | 137 } |
| 110 if (!IS_UNDEFINED(%MapGet(this, key))) { | 138 if (!IS_UNDEFINED(%MapGet(this, key))) { |
| 111 %MapSet(this, key, void 0); | 139 %MapSet(this, key, void 0); |
| 112 return true; | 140 return true; |
| 113 } else { | 141 } else { |
| 114 return false; | 142 return false; |
| 115 } | 143 } |
| 116 } | 144 } |
| 117 | 145 |
| 118 | 146 |
| 119 function WeakMapConstructor() { | 147 function WeakMapConstructor() { |
| 120 if (%_IsConstructCall()) { | 148 if (%_IsConstructCall()) { |
| 121 %WeakMapInitialize(this); | 149 %WeakMapInitialize(this); |
| 122 } else { | 150 } else { |
| 123 return new $WeakMap(); | 151 return new $WeakMap(); |
| 124 } | 152 } |
| 125 } | 153 } |
| 126 | 154 |
| 127 | 155 |
| 128 function WeakMapGet(key) { | 156 function WeakMapGet(key) { |
| 157 if (!IS_WEAKMAP(this)) { |
| 158 throw MakeTypeError('incompatible_method_receiver', |
| 159 ['WeakMap.prototype.get', this]); |
| 160 } |
| 129 if (!IS_SPEC_OBJECT(key)) { | 161 if (!IS_SPEC_OBJECT(key)) { |
| 130 throw %MakeTypeError('invalid_weakmap_key', [this, key]); | 162 throw %MakeTypeError('invalid_weakmap_key', [this, key]); |
| 131 } | 163 } |
| 132 return %WeakMapGet(this, key); | 164 return %WeakMapGet(this, key); |
| 133 } | 165 } |
| 134 | 166 |
| 135 | 167 |
| 136 function WeakMapSet(key, value) { | 168 function WeakMapSet(key, value) { |
| 169 if (!IS_WEAKMAP(this)) { |
| 170 throw MakeTypeError('incompatible_method_receiver', |
| 171 ['WeakMap.prototype.set', this]); |
| 172 } |
| 137 if (!IS_SPEC_OBJECT(key)) { | 173 if (!IS_SPEC_OBJECT(key)) { |
| 138 throw %MakeTypeError('invalid_weakmap_key', [this, key]); | 174 throw %MakeTypeError('invalid_weakmap_key', [this, key]); |
| 139 } | 175 } |
| 140 return %WeakMapSet(this, key, value); | 176 return %WeakMapSet(this, key, value); |
| 141 } | 177 } |
| 142 | 178 |
| 143 | 179 |
| 144 function WeakMapHas(key) { | 180 function WeakMapHas(key) { |
| 181 if (!IS_WEAKMAP(this)) { |
| 182 throw MakeTypeError('incompatible_method_receiver', |
| 183 ['WeakMap.prototype.has', this]); |
| 184 } |
| 145 if (!IS_SPEC_OBJECT(key)) { | 185 if (!IS_SPEC_OBJECT(key)) { |
| 146 throw %MakeTypeError('invalid_weakmap_key', [this, key]); | 186 throw %MakeTypeError('invalid_weakmap_key', [this, key]); |
| 147 } | 187 } |
| 148 return !IS_UNDEFINED(%WeakMapGet(this, key)); | 188 return !IS_UNDEFINED(%WeakMapGet(this, key)); |
| 149 } | 189 } |
| 150 | 190 |
| 151 | 191 |
| 152 function WeakMapDelete(key) { | 192 function WeakMapDelete(key) { |
| 193 if (!IS_WEAKMAP(this)) { |
| 194 throw MakeTypeError('incompatible_method_receiver', |
| 195 ['WeakMap.prototype.delete', this]); |
| 196 } |
| 153 if (!IS_SPEC_OBJECT(key)) { | 197 if (!IS_SPEC_OBJECT(key)) { |
| 154 throw %MakeTypeError('invalid_weakmap_key', [this, key]); | 198 throw %MakeTypeError('invalid_weakmap_key', [this, key]); |
| 155 } | 199 } |
| 156 if (!IS_UNDEFINED(%WeakMapGet(this, key))) { | 200 if (!IS_UNDEFINED(%WeakMapGet(this, key))) { |
| 157 %WeakMapSet(this, key, void 0); | 201 %WeakMapSet(this, key, void 0); |
| 158 return true; | 202 return true; |
| 159 } else { | 203 } else { |
| 160 return false; | 204 return false; |
| 161 } | 205 } |
| 162 } | 206 } |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 196 %SetProperty($WeakMap.prototype, "constructor", $WeakMap, DONT_ENUM); | 240 %SetProperty($WeakMap.prototype, "constructor", $WeakMap, DONT_ENUM); |
| 197 | 241 |
| 198 // Set up the non-enumerable functions on the WeakMap prototype object. | 242 // Set up the non-enumerable functions on the WeakMap prototype object. |
| 199 InstallFunctions($WeakMap.prototype, DONT_ENUM, $Array( | 243 InstallFunctions($WeakMap.prototype, DONT_ENUM, $Array( |
| 200 "get", WeakMapGet, | 244 "get", WeakMapGet, |
| 201 "set", WeakMapSet, | 245 "set", WeakMapSet, |
| 202 "has", WeakMapHas, | 246 "has", WeakMapHas, |
| 203 "delete", WeakMapDelete | 247 "delete", WeakMapDelete |
| 204 )); | 248 )); |
| 205 })(); | 249 })(); |
| OLD | NEW |