| OLD | NEW |
| 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 (function(global, utils) { | 5 (function(global, utils) { |
| 6 | 6 |
| 7 "use strict"; | 7 "use strict"; |
| 8 | 8 |
| 9 %CheckIsBootstrapping(); | 9 %CheckIsBootstrapping(); |
| 10 | 10 |
| 11 // ------------------------------------------------------------------- |
| 12 // Imports |
| 13 |
| 14 var GetExistingHash; |
| 15 var GetHash; |
| 11 var GlobalObject = global.Object; | 16 var GlobalObject = global.Object; |
| 12 var GlobalWeakMap = global.WeakMap; | 17 var GlobalWeakMap = global.WeakMap; |
| 13 var GlobalWeakSet = global.WeakSet; | 18 var GlobalWeakSet = global.WeakSet; |
| 14 var toStringTagSymbol = utils.ImportNow("to_string_tag_symbol"); | 19 var toStringTagSymbol = utils.ImportNow("to_string_tag_symbol"); |
| 15 | 20 |
| 21 utils.Import(function(from) { |
| 22 GetExistingHash = from.GetExistingHash; |
| 23 GetHash = from.GetHash; |
| 24 }); |
| 25 |
| 16 // ------------------------------------------------------------------- | 26 // ------------------------------------------------------------------- |
| 17 // Harmony WeakMap | 27 // Harmony WeakMap |
| 18 | 28 |
| 19 function WeakMapConstructor(iterable) { | 29 function WeakMapConstructor(iterable) { |
| 20 if (!%_IsConstructCall()) { | 30 if (!%_IsConstructCall()) { |
| 21 throw MakeTypeError(kConstructorNotFunction, "WeakMap"); | 31 throw MakeTypeError(kConstructorNotFunction, "WeakMap"); |
| 22 } | 32 } |
| 23 | 33 |
| 24 %WeakCollectionInitialize(this); | 34 %WeakCollectionInitialize(this); |
| 25 | 35 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 37 } | 47 } |
| 38 } | 48 } |
| 39 | 49 |
| 40 | 50 |
| 41 function WeakMapGet(key) { | 51 function WeakMapGet(key) { |
| 42 if (!IS_WEAKMAP(this)) { | 52 if (!IS_WEAKMAP(this)) { |
| 43 throw MakeTypeError(kIncompatibleMethodReceiver, | 53 throw MakeTypeError(kIncompatibleMethodReceiver, |
| 44 'WeakMap.prototype.get', this); | 54 'WeakMap.prototype.get', this); |
| 45 } | 55 } |
| 46 if (!IS_SPEC_OBJECT(key)) return UNDEFINED; | 56 if (!IS_SPEC_OBJECT(key)) return UNDEFINED; |
| 47 var hash = $getExistingHash(key); | 57 var hash = GetExistingHash(key); |
| 48 if (IS_UNDEFINED(hash)) return UNDEFINED; | 58 if (IS_UNDEFINED(hash)) return UNDEFINED; |
| 49 return %WeakCollectionGet(this, key, hash); | 59 return %WeakCollectionGet(this, key, hash); |
| 50 } | 60 } |
| 51 | 61 |
| 52 | 62 |
| 53 function WeakMapSet(key, value) { | 63 function WeakMapSet(key, value) { |
| 54 if (!IS_WEAKMAP(this)) { | 64 if (!IS_WEAKMAP(this)) { |
| 55 throw MakeTypeError(kIncompatibleMethodReceiver, | 65 throw MakeTypeError(kIncompatibleMethodReceiver, |
| 56 'WeakMap.prototype.set', this); | 66 'WeakMap.prototype.set', this); |
| 57 } | 67 } |
| 58 if (!IS_SPEC_OBJECT(key)) throw MakeTypeError(kInvalidWeakMapKey); | 68 if (!IS_SPEC_OBJECT(key)) throw MakeTypeError(kInvalidWeakMapKey); |
| 59 return %WeakCollectionSet(this, key, value, $getHash(key)); | 69 return %WeakCollectionSet(this, key, value, GetHash(key)); |
| 60 } | 70 } |
| 61 | 71 |
| 62 | 72 |
| 63 function WeakMapHas(key) { | 73 function WeakMapHas(key) { |
| 64 if (!IS_WEAKMAP(this)) { | 74 if (!IS_WEAKMAP(this)) { |
| 65 throw MakeTypeError(kIncompatibleMethodReceiver, | 75 throw MakeTypeError(kIncompatibleMethodReceiver, |
| 66 'WeakMap.prototype.has', this); | 76 'WeakMap.prototype.has', this); |
| 67 } | 77 } |
| 68 if (!IS_SPEC_OBJECT(key)) return false; | 78 if (!IS_SPEC_OBJECT(key)) return false; |
| 69 var hash = $getExistingHash(key); | 79 var hash = GetExistingHash(key); |
| 70 if (IS_UNDEFINED(hash)) return false; | 80 if (IS_UNDEFINED(hash)) return false; |
| 71 return %WeakCollectionHas(this, key, hash); | 81 return %WeakCollectionHas(this, key, hash); |
| 72 } | 82 } |
| 73 | 83 |
| 74 | 84 |
| 75 function WeakMapDelete(key) { | 85 function WeakMapDelete(key) { |
| 76 if (!IS_WEAKMAP(this)) { | 86 if (!IS_WEAKMAP(this)) { |
| 77 throw MakeTypeError(kIncompatibleMethodReceiver, | 87 throw MakeTypeError(kIncompatibleMethodReceiver, |
| 78 'WeakMap.prototype.delete', this); | 88 'WeakMap.prototype.delete', this); |
| 79 } | 89 } |
| 80 if (!IS_SPEC_OBJECT(key)) return false; | 90 if (!IS_SPEC_OBJECT(key)) return false; |
| 81 var hash = $getExistingHash(key); | 91 var hash = GetExistingHash(key); |
| 82 if (IS_UNDEFINED(hash)) return false; | 92 if (IS_UNDEFINED(hash)) return false; |
| 83 return %WeakCollectionDelete(this, key, hash); | 93 return %WeakCollectionDelete(this, key, hash); |
| 84 } | 94 } |
| 85 | 95 |
| 86 | 96 |
| 87 // ------------------------------------------------------------------- | 97 // ------------------------------------------------------------------- |
| 88 | 98 |
| 89 %SetCode(GlobalWeakMap, WeakMapConstructor); | 99 %SetCode(GlobalWeakMap, WeakMapConstructor); |
| 90 %FunctionSetLength(GlobalWeakMap, 0); | 100 %FunctionSetLength(GlobalWeakMap, 0); |
| 91 %FunctionSetPrototype(GlobalWeakMap, new GlobalObject()); | 101 %FunctionSetPrototype(GlobalWeakMap, new GlobalObject()); |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 123 } | 133 } |
| 124 } | 134 } |
| 125 | 135 |
| 126 | 136 |
| 127 function WeakSetAdd(value) { | 137 function WeakSetAdd(value) { |
| 128 if (!IS_WEAKSET(this)) { | 138 if (!IS_WEAKSET(this)) { |
| 129 throw MakeTypeError(kIncompatibleMethodReceiver, | 139 throw MakeTypeError(kIncompatibleMethodReceiver, |
| 130 'WeakSet.prototype.add', this); | 140 'WeakSet.prototype.add', this); |
| 131 } | 141 } |
| 132 if (!IS_SPEC_OBJECT(value)) throw MakeTypeError(kInvalidWeakSetValue); | 142 if (!IS_SPEC_OBJECT(value)) throw MakeTypeError(kInvalidWeakSetValue); |
| 133 return %WeakCollectionSet(this, value, true, $getHash(value)); | 143 return %WeakCollectionSet(this, value, true, GetHash(value)); |
| 134 } | 144 } |
| 135 | 145 |
| 136 | 146 |
| 137 function WeakSetHas(value) { | 147 function WeakSetHas(value) { |
| 138 if (!IS_WEAKSET(this)) { | 148 if (!IS_WEAKSET(this)) { |
| 139 throw MakeTypeError(kIncompatibleMethodReceiver, | 149 throw MakeTypeError(kIncompatibleMethodReceiver, |
| 140 'WeakSet.prototype.has', this); | 150 'WeakSet.prototype.has', this); |
| 141 } | 151 } |
| 142 if (!IS_SPEC_OBJECT(value)) return false; | 152 if (!IS_SPEC_OBJECT(value)) return false; |
| 143 var hash = $getExistingHash(value); | 153 var hash = GetExistingHash(value); |
| 144 if (IS_UNDEFINED(hash)) return false; | 154 if (IS_UNDEFINED(hash)) return false; |
| 145 return %WeakCollectionHas(this, value, hash); | 155 return %WeakCollectionHas(this, value, hash); |
| 146 } | 156 } |
| 147 | 157 |
| 148 | 158 |
| 149 function WeakSetDelete(value) { | 159 function WeakSetDelete(value) { |
| 150 if (!IS_WEAKSET(this)) { | 160 if (!IS_WEAKSET(this)) { |
| 151 throw MakeTypeError(kIncompatibleMethodReceiver, | 161 throw MakeTypeError(kIncompatibleMethodReceiver, |
| 152 'WeakSet.prototype.delete', this); | 162 'WeakSet.prototype.delete', this); |
| 153 } | 163 } |
| 154 if (!IS_SPEC_OBJECT(value)) return false; | 164 if (!IS_SPEC_OBJECT(value)) return false; |
| 155 var hash = $getExistingHash(value); | 165 var hash = GetExistingHash(value); |
| 156 if (IS_UNDEFINED(hash)) return false; | 166 if (IS_UNDEFINED(hash)) return false; |
| 157 return %WeakCollectionDelete(this, value, hash); | 167 return %WeakCollectionDelete(this, value, hash); |
| 158 } | 168 } |
| 159 | 169 |
| 160 | 170 |
| 161 // ------------------------------------------------------------------- | 171 // ------------------------------------------------------------------- |
| 162 | 172 |
| 163 %SetCode(GlobalWeakSet, WeakSetConstructor); | 173 %SetCode(GlobalWeakSet, WeakSetConstructor); |
| 164 %FunctionSetLength(GlobalWeakSet, 0); | 174 %FunctionSetLength(GlobalWeakSet, 0); |
| 165 %FunctionSetPrototype(GlobalWeakSet, new GlobalObject()); | 175 %FunctionSetPrototype(GlobalWeakSet, new GlobalObject()); |
| 166 %AddNamedProperty(GlobalWeakSet.prototype, "constructor", GlobalWeakSet, | 176 %AddNamedProperty(GlobalWeakSet.prototype, "constructor", GlobalWeakSet, |
| 167 DONT_ENUM); | 177 DONT_ENUM); |
| 168 %AddNamedProperty(GlobalWeakSet.prototype, toStringTagSymbol, "WeakSet", | 178 %AddNamedProperty(GlobalWeakSet.prototype, toStringTagSymbol, "WeakSet", |
| 169 DONT_ENUM | READ_ONLY); | 179 DONT_ENUM | READ_ONLY); |
| 170 | 180 |
| 171 // Set up the non-enumerable functions on the WeakSet prototype object. | 181 // Set up the non-enumerable functions on the WeakSet prototype object. |
| 172 utils.InstallFunctions(GlobalWeakSet.prototype, DONT_ENUM, [ | 182 utils.InstallFunctions(GlobalWeakSet.prototype, DONT_ENUM, [ |
| 173 "add", WeakSetAdd, | 183 "add", WeakSetAdd, |
| 174 "has", WeakSetHas, | 184 "has", WeakSetHas, |
| 175 "delete", WeakSetDelete | 185 "delete", WeakSetDelete |
| 176 ]); | 186 ]); |
| 177 | 187 |
| 178 }) | 188 }) |
| OLD | NEW |