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 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
106 } | 106 } |
107 return %SetGetSize(this); | 107 return %SetGetSize(this); |
108 } | 108 } |
109 | 109 |
110 | 110 |
111 function SetClear() { | 111 function SetClear() { |
112 if (!IS_SET(this)) { | 112 if (!IS_SET(this)) { |
113 throw MakeTypeError('incompatible_method_receiver', | 113 throw MakeTypeError('incompatible_method_receiver', |
114 ['Set.prototype.clear', this]); | 114 ['Set.prototype.clear', this]); |
115 } | 115 } |
116 // Replace the internal table with a new empty table. | 116 %SetClear(this); |
117 %SetInitialize(this); | |
118 } | 117 } |
119 | 118 |
120 | 119 |
| 120 function SetForEach(f, receiver) { |
| 121 if (!IS_SET(this)) { |
| 122 throw MakeTypeError('incompatible_method_receiver', |
| 123 ['Set.prototype.forEach', this]); |
| 124 } |
| 125 |
| 126 if (!IS_SPEC_FUNCTION(f)) { |
| 127 throw MakeTypeError('called_non_callable', [f]); |
| 128 } |
| 129 |
| 130 var iterator = %SetCreateIterator(this, ITERATOR_KIND_VALUES); |
| 131 var entry; |
| 132 try { |
| 133 while (!(entry = %SetIteratorNext(iterator)).done) { |
| 134 %_CallFunction(receiver, entry.value, entry.value, this, f); |
| 135 } |
| 136 } finally { |
| 137 %SetIteratorClose(iterator); |
| 138 } |
| 139 } |
| 140 |
| 141 |
121 // ------------------------------------------------------------------- | 142 // ------------------------------------------------------------------- |
122 | 143 |
123 function SetUpSet() { | 144 function SetUpSet() { |
124 %CheckIsBootstrapping(); | 145 %CheckIsBootstrapping(); |
125 | 146 |
126 %SetCode($Set, SetConstructor); | 147 %SetCode($Set, SetConstructor); |
127 %FunctionSetPrototype($Set, new $Object()); | 148 %FunctionSetPrototype($Set, new $Object()); |
128 %SetProperty($Set.prototype, "constructor", $Set, DONT_ENUM); | 149 %SetProperty($Set.prototype, "constructor", $Set, DONT_ENUM); |
129 | 150 |
| 151 %FunctionSetLength(SetForEach, 1); |
| 152 |
130 // Set up the non-enumerable functions on the Set prototype object. | 153 // Set up the non-enumerable functions on the Set prototype object. |
131 InstallGetter($Set.prototype, "size", SetGetSize); | 154 InstallGetter($Set.prototype, "size", SetGetSize); |
132 InstallFunctions($Set.prototype, DONT_ENUM, $Array( | 155 InstallFunctions($Set.prototype, DONT_ENUM, $Array( |
133 "add", SetAdd, | 156 "add", SetAdd, |
134 "has", SetHas, | 157 "has", SetHas, |
135 "delete", SetDelete, | 158 "delete", SetDelete, |
136 "clear", SetClear | 159 "clear", SetClear, |
| 160 "forEach", SetForEach |
137 )); | 161 )); |
138 } | 162 } |
139 | 163 |
140 SetUpSet(); | 164 SetUpSet(); |
141 | 165 |
142 | 166 |
143 // ------------------------------------------------------------------- | 167 // ------------------------------------------------------------------- |
144 // Harmony Map | 168 // Harmony Map |
145 | 169 |
146 function MapConstructor() { | 170 function MapConstructor() { |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
195 } | 219 } |
196 return %MapGetSize(this); | 220 return %MapGetSize(this); |
197 } | 221 } |
198 | 222 |
199 | 223 |
200 function MapClear() { | 224 function MapClear() { |
201 if (!IS_MAP(this)) { | 225 if (!IS_MAP(this)) { |
202 throw MakeTypeError('incompatible_method_receiver', | 226 throw MakeTypeError('incompatible_method_receiver', |
203 ['Map.prototype.clear', this]); | 227 ['Map.prototype.clear', this]); |
204 } | 228 } |
205 // Replace the internal table with a new empty table. | 229 %MapClear(this); |
206 %MapInitialize(this); | |
207 } | 230 } |
208 | 231 |
209 | 232 |
| 233 function MapForEach(f, receiver) { |
| 234 if (!IS_MAP(this)) { |
| 235 throw MakeTypeError('incompatible_method_receiver', |
| 236 ['Map.prototype.forEach', this]); |
| 237 } |
| 238 |
| 239 if (!IS_SPEC_FUNCTION(f)) { |
| 240 throw MakeTypeError('called_non_callable', [f]); |
| 241 } |
| 242 |
| 243 var iterator = %MapCreateIterator(this, ITERATOR_KIND_ENTRIES); |
| 244 var entry; |
| 245 try { |
| 246 while (!(entry = %MapIteratorNext(iterator)).done) { |
| 247 %_CallFunction(receiver, entry.value[1], entry.value[0], this, f); |
| 248 } |
| 249 } finally { |
| 250 %MapIteratorClose(iterator); |
| 251 } |
| 252 } |
| 253 |
| 254 |
210 // ------------------------------------------------------------------- | 255 // ------------------------------------------------------------------- |
211 | 256 |
212 function SetUpMap() { | 257 function SetUpMap() { |
213 %CheckIsBootstrapping(); | 258 %CheckIsBootstrapping(); |
214 | 259 |
215 %SetCode($Map, MapConstructor); | 260 %SetCode($Map, MapConstructor); |
216 %FunctionSetPrototype($Map, new $Object()); | 261 %FunctionSetPrototype($Map, new $Object()); |
217 %SetProperty($Map.prototype, "constructor", $Map, DONT_ENUM); | 262 %SetProperty($Map.prototype, "constructor", $Map, DONT_ENUM); |
218 | 263 |
| 264 %FunctionSetLength(MapForEach, 1); |
| 265 |
219 // Set up the non-enumerable functions on the Map prototype object. | 266 // Set up the non-enumerable functions on the Map prototype object. |
220 InstallGetter($Map.prototype, "size", MapGetSize); | 267 InstallGetter($Map.prototype, "size", MapGetSize); |
221 InstallFunctions($Map.prototype, DONT_ENUM, $Array( | 268 InstallFunctions($Map.prototype, DONT_ENUM, $Array( |
222 "get", MapGet, | 269 "get", MapGet, |
223 "set", MapSet, | 270 "set", MapSet, |
224 "has", MapHas, | 271 "has", MapHas, |
225 "delete", MapDelete, | 272 "delete", MapDelete, |
226 "clear", MapClear | 273 "clear", MapClear, |
| 274 "forEach", MapForEach |
227 )); | 275 )); |
228 } | 276 } |
229 | 277 |
230 SetUpMap(); | 278 SetUpMap(); |
OLD | NEW |