@@ -153,14 +153,21 @@ EM_JS(void, js_reflect_construct, (int f_ref, uint32_t n_args, uint32_t * args,
153
153
proxy_convert_js_to_mp_obj_jsside (ret , out );
154
154
});
155
155
156
- EM_JS (int , js_get_len , (int f_ref ), {
157
- return proxy_js_ref [f_ref ].length ;
156
+ EM_JS (void , js_get_iter , (int f_ref , uint32_t * out ), {
157
+ const f = proxy_js_ref [f_ref ];
158
+ const ret = f [Symbol .iterator ]();
159
+ proxy_convert_js_to_mp_obj_jsside (ret , out );
158
160
});
159
161
160
- EM_JS (void , js_subscr_int , (int f_ref , int idx , uint32_t * out ), {
162
+ EM_JS (bool , js_iter_next , (int f_ref , uint32_t * out ), {
161
163
const f = proxy_js_ref [f_ref ];
162
- const ret = f [idx ];
163
- proxy_convert_js_to_mp_obj_jsside (ret , out );
164
+ const ret = f .next ();
165
+ if (ret .done ) {
166
+ return false;
167
+ } else {
168
+ proxy_convert_js_to_mp_obj_jsside (ret .value , out );
169
+ return true;
170
+ }
164
171
});
165
172
166
173
EM_JS (void , js_subscr_load , (int f_ref , uint32_t * index_ref , uint32_t * out ), {
@@ -320,17 +327,13 @@ void mp_obj_jsproxy_attr(mp_obj_t self_in, qstr attr, mp_obj_t *dest) {
320
327
typedef struct _jsproxy_it_t {
321
328
mp_obj_base_t base ;
322
329
mp_fun_1_t iternext ;
323
- mp_obj_jsproxy_t * obj ;
324
- uint16_t cur ;
325
- uint16_t len ;
330
+ mp_obj_jsproxy_t * iter ;
326
331
} jsproxy_it_t ;
327
332
328
333
static mp_obj_t jsproxy_it_iternext (mp_obj_t self_in ) {
329
334
jsproxy_it_t * self = MP_OBJ_TO_PTR (self_in );
330
- if (self -> cur < self -> len ) {
331
- uint32_t out [3 ];
332
- js_subscr_int (self -> obj -> ref , self -> cur , out );
333
- self -> cur += 1 ;
335
+ uint32_t out [3 ];
336
+ if (js_iter_next (self -> iter -> ref , out )) {
334
337
return proxy_convert_js_to_mp_obj_cside (out );
335
338
} else {
336
339
return MP_OBJ_STOP_ITERATION ;
@@ -343,9 +346,9 @@ static mp_obj_t jsproxy_new_it(mp_obj_t self_in, mp_obj_iter_buf_t *iter_buf) {
343
346
jsproxy_it_t * o = (jsproxy_it_t * )iter_buf ;
344
347
o -> base .type = & mp_type_polymorph_iter ;
345
348
o -> iternext = jsproxy_it_iternext ;
346
- o -> obj = self ;
347
- o -> cur = 0 ;
348
- o -> len = js_get_len ( self -> ref );
349
+ uint32_t out [ 3 ] ;
350
+ js_get_iter ( self -> ref , out ) ;
351
+ o -> iter = proxy_convert_js_to_mp_obj_cside ( out );
349
352
return MP_OBJ_FROM_PTR (o );
350
353
}
351
354
0 commit comments