@@ -6,14 +6,10 @@ use std::hash::Hasher;
6
6
7
7
use ahash:: AHasher ;
8
8
9
- use crate :: ecmascript:: abstract_operations:: operations_on_iterator_objects:: {
10
- get_iterator, if_abrupt_close_iterator, iterator_close, iterator_step_value,
11
- } ;
12
- use crate :: ecmascript:: abstract_operations:: operations_on_objects:: {
13
- call_function, get, get_method, try_get,
14
- } ;
9
+ use crate :: ecmascript:: abstract_operations:: operations_on_objects:: { get, get_method, try_get} ;
15
10
use crate :: ecmascript:: abstract_operations:: testing_and_comparison:: is_callable;
16
11
use crate :: ecmascript:: builtins:: array:: ArrayHeap ;
12
+ use crate :: ecmascript:: builtins:: keyed_collections:: map_objects:: map_constructor:: add_entries_from_iterable;
17
13
use crate :: ecmascript:: builtins:: keyed_collections:: map_objects:: map_prototype:: canonicalize_keyed_collection_key;
18
14
use crate :: ecmascript:: builtins:: ordinary:: ordinary_create_from_constructor;
19
15
use crate :: ecmascript:: builtins:: weak_map:: data:: WeakMapData ;
@@ -263,68 +259,12 @@ pub fn add_entries_from_iterable_weak_map_constructor<'a>(
263
259
}
264
260
}
265
261
266
- add_entries_from_iterable ( agent, target. unbind ( ) , iterable, adder. unbind ( ) , gc)
267
- }
268
-
269
- /// ### [24.1.1.2 AddEntriesFromIterable ( target, iterable, adder )](https://tc39.es/ecma262/#sec-add-entries-from-iterable)
270
- ///
271
- /// The abstract operation AddEntriesFromIterable takes arguments target (an
272
- /// Object), iterable (an ECMAScript language value, but not undefined or
273
- /// null), and adder (a function object) and returns either a normal completion
274
- /// containing an ECMAScript language value or a throw completion. adder will
275
- /// be invoked, with target as the receiver.
276
- ///
277
- /// > NOTE: The parameter iterable is expected to be an object that implements
278
- /// > an @@iterator method that returns an iterator object that produces a two
279
- /// > element array-like object whose first element is a value that will be used
280
- /// > as a WeakMap key and whose second element is the value to associate with that
281
- /// > key.
282
- pub ( crate ) fn add_entries_from_iterable < ' a > (
283
- agent : & mut Agent ,
284
- target : WeakMap ,
285
- iterable : Value ,
286
- adder : Function ,
287
- mut gc : GcScope < ' a , ' _ > ,
288
- ) -> JsResult < WeakMap < ' a > > {
289
- let target = target. bind ( gc. nogc ( ) ) . scope ( agent, gc. nogc ( ) ) ;
290
- let adder = adder. bind ( gc. nogc ( ) ) . scope ( agent, gc. nogc ( ) ) ;
291
- // 1. Let iteratorRecord be ? GetIterator(iterable, SYNC).
292
- let mut iterator_record = get_iterator ( agent, iterable, false , gc. reborrow ( ) ) ?;
293
- // 2. Repeat,
294
- loop {
295
- // a. Let next be ? IteratorStepValue(iteratorRecord).
296
- let next = iterator_step_value ( agent, & mut iterator_record, gc. reborrow ( ) ) ?;
297
- // b. If next is DONE, return target.
298
- let Some ( next) = next else {
299
- return Ok ( target. get ( agent) . bind ( gc. into_nogc ( ) ) ) ;
300
- } ;
301
- // c. If next is not an Object, then
302
- let Ok ( next) = Object :: try_from ( next) else {
303
- // i. Let error be ThrowCompletion(a newly created TypeError object).
304
- let error = agent. throw_exception_with_static_message (
305
- ExceptionType :: TypeError ,
306
- "Invalid iterator next return value" ,
307
- gc. nogc ( ) ,
308
- ) ;
309
- // ii. Return ? IteratorClose(iteratorRecord, error).
310
- return iterator_close ( agent, & iterator_record, Err ( error) , gc. reborrow ( ) ) ;
311
- } ;
312
- // d. Let k be Completion(Get(next, "0")).
313
- let k = get ( agent, next, 0 . into ( ) , gc. reborrow ( ) ) ;
314
- // e. IfAbruptCloseIterator(k, iteratorRecord).
315
- let k = if_abrupt_close_iterator ( agent, k, & iterator_record, gc. reborrow ( ) ) ?;
316
- // f. Let v be Completion(Get(next, "1")).
317
- let v = get ( agent, next, 1 . into ( ) , gc. reborrow ( ) ) ;
318
- // g. IfAbruptCloseIterator(v, iteratorRecord).
319
- let v = if_abrupt_close_iterator ( agent, v, & iterator_record, gc. reborrow ( ) ) ?;
320
- // h. Let status be Completion(Call(adder, target, « k, v »)).
321
- let status = call_function (
322
- agent,
323
- adder. get ( agent) ,
324
- target. get ( agent) . into_value ( ) ,
325
- Some ( ArgumentsList ( & [ k, v] ) ) ,
326
- gc. reborrow ( ) ,
327
- ) ;
328
- let _ = if_abrupt_close_iterator ( agent, status, & iterator_record, gc. reborrow ( ) ) ?;
329
- }
262
+ Ok ( WeakMap :: try_from ( add_entries_from_iterable (
263
+ agent,
264
+ target. into_object ( ) . unbind ( ) ,
265
+ iterable,
266
+ adder. unbind ( ) ,
267
+ gc,
268
+ ) ?)
269
+ . unwrap ( ) )
330
270
}
0 commit comments