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 "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 $WeakMap = global.WeakMap; | 11 var $WeakMap = global.WeakMap; |
12 var $WeakSet = global.WeakSet; | 12 var $WeakSet = global.WeakSet; |
13 | 13 |
14 | 14 |
15 // ------------------------------------------------------------------- | 15 // ------------------------------------------------------------------- |
16 // Harmony WeakMap | 16 // Harmony WeakMap |
17 | 17 |
18 function WeakMapConstructor() { | 18 function WeakMapConstructor(iterable) { |
19 if (%_IsConstructCall()) { | 19 if (!%_IsConstructCall()) { |
20 %WeakCollectionInitialize(this); | |
21 } else { | |
22 throw MakeTypeError('constructor_not_function', ['WeakMap']); | 20 throw MakeTypeError('constructor_not_function', ['WeakMap']); |
23 } | 21 } |
| 22 |
| 23 var iter, adder; |
| 24 |
| 25 if (!IS_NULL_OR_UNDEFINED(iterable)) { |
| 26 iter = GetIterator(iterable); |
| 27 adder = this.set; |
| 28 if (!IS_SPEC_FUNCTION(adder)) { |
| 29 throw MakeTypeError('property_not_function', ['set', this]); |
| 30 } |
| 31 } |
| 32 |
| 33 %WeakCollectionInitialize(this); |
| 34 |
| 35 if (IS_UNDEFINED(iter)) return; |
| 36 |
| 37 var next, done, nextItem; |
| 38 while (!(next = iter.next()).done) { |
| 39 if (!IS_SPEC_OBJECT(next)) { |
| 40 throw MakeTypeError('iterator_result_not_an_object', [next]); |
| 41 } |
| 42 nextItem = next.value; |
| 43 if (!IS_SPEC_OBJECT(nextItem)) { |
| 44 throw MakeTypeError('iterator_value_not_an_object', [nextItem]); |
| 45 } |
| 46 %_CallFunction(this, nextItem[0], nextItem[1], adder); |
| 47 } |
24 } | 48 } |
25 | 49 |
26 | 50 |
27 function WeakMapGet(key) { | 51 function WeakMapGet(key) { |
28 if (!IS_WEAKMAP(this)) { | 52 if (!IS_WEAKMAP(this)) { |
29 throw MakeTypeError('incompatible_method_receiver', | 53 throw MakeTypeError('incompatible_method_receiver', |
30 ['WeakMap.prototype.get', this]); | 54 ['WeakMap.prototype.get', this]); |
31 } | 55 } |
32 if (!(IS_SPEC_OBJECT(key) || IS_SYMBOL(key))) { | 56 if (!(IS_SPEC_OBJECT(key) || IS_SYMBOL(key))) { |
33 throw %MakeTypeError('invalid_weakmap_key', [this, key]); | 57 throw %MakeTypeError('invalid_weakmap_key', [this, key]); |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
100 "clear", WeakMapClear | 124 "clear", WeakMapClear |
101 )); | 125 )); |
102 } | 126 } |
103 | 127 |
104 SetUpWeakMap(); | 128 SetUpWeakMap(); |
105 | 129 |
106 | 130 |
107 // ------------------------------------------------------------------- | 131 // ------------------------------------------------------------------- |
108 // Harmony WeakSet | 132 // Harmony WeakSet |
109 | 133 |
110 function WeakSetConstructor() { | 134 function WeakSetConstructor(iterable) { |
111 if (%_IsConstructCall()) { | 135 if (!%_IsConstructCall()) { |
112 %WeakCollectionInitialize(this); | |
113 } else { | |
114 throw MakeTypeError('constructor_not_function', ['WeakSet']); | 136 throw MakeTypeError('constructor_not_function', ['WeakSet']); |
115 } | 137 } |
| 138 |
| 139 var iter, adder; |
| 140 |
| 141 if (!IS_NULL_OR_UNDEFINED(iterable)) { |
| 142 iter = GetIterator(iterable); |
| 143 adder = this.add; |
| 144 if (!IS_SPEC_FUNCTION(adder)) { |
| 145 throw MakeTypeError('property_not_function', ['add', this]); |
| 146 } |
| 147 } |
| 148 |
| 149 %WeakCollectionInitialize(this); |
| 150 |
| 151 if (IS_UNDEFINED(iter)) return; |
| 152 |
| 153 var next, done; |
| 154 while (!(next = iter.next()).done) { |
| 155 if (!IS_SPEC_OBJECT(next)) { |
| 156 throw MakeTypeError('iterator_result_not_an_object', [next]); |
| 157 } |
| 158 %_CallFunction(this, next.value, adder); |
| 159 } |
116 } | 160 } |
117 | 161 |
118 | 162 |
119 function WeakSetAdd(value) { | 163 function WeakSetAdd(value) { |
120 if (!IS_WEAKSET(this)) { | 164 if (!IS_WEAKSET(this)) { |
121 throw MakeTypeError('incompatible_method_receiver', | 165 throw MakeTypeError('incompatible_method_receiver', |
122 ['WeakSet.prototype.add', this]); | 166 ['WeakSet.prototype.add', this]); |
123 } | 167 } |
124 if (!(IS_SPEC_OBJECT(value) || IS_SYMBOL(value))) { | 168 if (!(IS_SPEC_OBJECT(value) || IS_SYMBOL(value))) { |
125 throw %MakeTypeError('invalid_weakset_value', [this, value]); | 169 throw %MakeTypeError('invalid_weakset_value', [this, value]); |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
174 // Set up the non-enumerable functions on the WeakSet prototype object. | 218 // Set up the non-enumerable functions on the WeakSet prototype object. |
175 InstallFunctions($WeakSet.prototype, DONT_ENUM, $Array( | 219 InstallFunctions($WeakSet.prototype, DONT_ENUM, $Array( |
176 "add", WeakSetAdd, | 220 "add", WeakSetAdd, |
177 "has", WeakSetHas, | 221 "has", WeakSetHas, |
178 "delete", WeakSetDelete, | 222 "delete", WeakSetDelete, |
179 "clear", WeakSetClear | 223 "clear", WeakSetClear |
180 )); | 224 )); |
181 } | 225 } |
182 | 226 |
183 SetUpWeakSet(); | 227 SetUpWeakSet(); |
OLD | NEW |