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(iterable) { | 18 function WeakMapConstructor(iterable) { |
19 if (!%_IsConstructCall()) { | 19 if (!%_IsConstructCall()) { |
20 throw MakeTypeError('constructor_not_function', ['WeakMap']); | 20 throw MakeTypeError('constructor_not_function', ['WeakMap']); |
21 } | 21 } |
22 | 22 |
23 var iter, adder; | |
24 | |
25 if (!IS_NULL_OR_UNDEFINED(iterable)) { | |
26 adder = this.set; | |
27 if (!IS_SPEC_FUNCTION(adder)) { | |
28 throw MakeTypeError('property_not_function', ['set', this]); | |
29 } | |
30 iter = GetIterator(iterable); | |
31 } | |
32 | |
33 %WeakCollectionInitialize(this); | 23 %WeakCollectionInitialize(this); |
34 | 24 |
35 if (IS_UNDEFINED(iter)) return; | 25 if (!IS_NULL_OR_UNDEFINED(iterable)) { |
36 | 26 var adder = this.set; |
37 var next, done, nextItem; | 27 if (!IS_SPEC_FUNCTION(adder)) { |
38 while (!(next = iter.next()).done) { | 28 throw MakeTypeError('property_not_function', ['set', this]); |
39 if (!IS_SPEC_OBJECT(next)) { | |
40 throw MakeTypeError('iterator_result_not_an_object', [next]); | |
41 } | 29 } |
42 nextItem = next.value; | 30 for (var nextItem of iterable) { |
43 if (!IS_SPEC_OBJECT(nextItem)) { | 31 if (!IS_SPEC_OBJECT(nextItem)) { |
44 throw MakeTypeError('iterator_value_not_an_object', [nextItem]); | 32 throw MakeTypeError('iterator_value_not_an_object', [nextItem]); |
| 33 } |
| 34 %_CallFunction(this, nextItem[0], nextItem[1], adder); |
45 } | 35 } |
46 %_CallFunction(this, nextItem[0], nextItem[1], adder); | |
47 } | 36 } |
48 } | 37 } |
49 | 38 |
50 | 39 |
51 function WeakMapGet(key) { | 40 function WeakMapGet(key) { |
52 if (!IS_WEAKMAP(this)) { | 41 if (!IS_WEAKMAP(this)) { |
53 throw MakeTypeError('incompatible_method_receiver', | 42 throw MakeTypeError('incompatible_method_receiver', |
54 ['WeakMap.prototype.get', this]); | 43 ['WeakMap.prototype.get', this]); |
55 } | 44 } |
56 if (!(IS_SPEC_OBJECT(key) || IS_SYMBOL(key))) { | 45 if (!(IS_SPEC_OBJECT(key) || IS_SYMBOL(key))) { |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
120 | 109 |
121 | 110 |
122 // ------------------------------------------------------------------- | 111 // ------------------------------------------------------------------- |
123 // Harmony WeakSet | 112 // Harmony WeakSet |
124 | 113 |
125 function WeakSetConstructor(iterable) { | 114 function WeakSetConstructor(iterable) { |
126 if (!%_IsConstructCall()) { | 115 if (!%_IsConstructCall()) { |
127 throw MakeTypeError('constructor_not_function', ['WeakSet']); | 116 throw MakeTypeError('constructor_not_function', ['WeakSet']); |
128 } | 117 } |
129 | 118 |
130 var iter, adder; | |
131 | |
132 if (!IS_NULL_OR_UNDEFINED(iterable)) { | |
133 adder = this.add; | |
134 if (!IS_SPEC_FUNCTION(adder)) { | |
135 throw MakeTypeError('property_not_function', ['add', this]); | |
136 } | |
137 iter = GetIterator(iterable); | |
138 } | |
139 | |
140 %WeakCollectionInitialize(this); | 119 %WeakCollectionInitialize(this); |
141 | 120 |
142 if (IS_UNDEFINED(iter)) return; | 121 if (!IS_NULL_OR_UNDEFINED(iterable)) { |
143 | 122 var adder = this.add; |
144 var next, done; | 123 if (!IS_SPEC_FUNCTION(adder)) { |
145 while (!(next = iter.next()).done) { | 124 throw MakeTypeError('property_not_function', ['add', this]); |
146 if (!IS_SPEC_OBJECT(next)) { | |
147 throw MakeTypeError('iterator_result_not_an_object', [next]); | |
148 } | 125 } |
149 %_CallFunction(this, next.value, adder); | 126 for (var value of iterable) { |
| 127 %_CallFunction(this, value, adder); |
| 128 } |
150 } | 129 } |
151 } | 130 } |
152 | 131 |
153 | 132 |
154 function WeakSetAdd(value) { | 133 function WeakSetAdd(value) { |
155 if (!IS_WEAKSET(this)) { | 134 if (!IS_WEAKSET(this)) { |
156 throw MakeTypeError('incompatible_method_receiver', | 135 throw MakeTypeError('incompatible_method_receiver', |
157 ['WeakSet.prototype.add', this]); | 136 ['WeakSet.prototype.add', this]); |
158 } | 137 } |
159 if (!(IS_SPEC_OBJECT(value) || IS_SYMBOL(value))) { | 138 if (!(IS_SPEC_OBJECT(value) || IS_SYMBOL(value))) { |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
200 | 179 |
201 // Set up the non-enumerable functions on the WeakSet prototype object. | 180 // Set up the non-enumerable functions on the WeakSet prototype object. |
202 InstallFunctions($WeakSet.prototype, DONT_ENUM, $Array( | 181 InstallFunctions($WeakSet.prototype, DONT_ENUM, $Array( |
203 "add", WeakSetAdd, | 182 "add", WeakSetAdd, |
204 "has", WeakSetHas, | 183 "has", WeakSetHas, |
205 "delete", WeakSetDelete | 184 "delete", WeakSetDelete |
206 )); | 185 )); |
207 } | 186 } |
208 | 187 |
209 SetUpWeakSet(); | 188 SetUpWeakSet(); |
OLD | NEW |