File tree Expand file tree Collapse file tree 3 files changed +43
-23
lines changed Expand file tree Collapse file tree 3 files changed +43
-23
lines changed Original file line number Diff line number Diff line change @@ -169,30 +169,33 @@ const py_proxy_handler = {
169169            return  null ; 
170170        } 
171171
172-         if  ( prop  ===  Symbol . iterator )  { 
173-             // Get the Python object iterator, and return a JavaScript generator. 
174-             const  iter_ref  =  Module . ccall ( 
175-                 "proxy_c_to_js_get_iter" , 
176-                 "number" , 
177-                 [ "number" ] , 
178-                 [ target . _ref ] , 
179-             ) ; 
180-             return  function *  ( )  { 
181-                 const  value  =  Module . _malloc ( 3  *  4 ) ; 
182-                 while  ( true )  { 
183-                     const  valid  =  Module . ccall ( 
184-                         "proxy_c_to_js_iternext" , 
185-                         "number" , 
186-                         [ "number" ,  "pointer" ] , 
187-                         [ iter_ref ,  value ] , 
188-                     ) ; 
189-                     if  ( ! valid )  { 
190-                         break ; 
172+         if  ( typeof  prop  !==  "string" )  { 
173+             if  ( prop  ===  Symbol . iterator )  { 
174+                 // Get the Python object iterator, and return a JavaScript generator. 
175+                 const  iter_ref  =  Module . ccall ( 
176+                     "proxy_c_to_js_get_iter" , 
177+                     "number" , 
178+                     [ "number" ] , 
179+                     [ target . _ref ] , 
180+                 ) ; 
181+                 return  function *  ( )  { 
182+                     const  value  =  Module . _malloc ( 3  *  4 ) ; 
183+                     while  ( true )  { 
184+                         const  valid  =  Module . ccall ( 
185+                             "proxy_c_to_js_iternext" , 
186+                             "number" , 
187+                             [ "number" ,  "pointer" ] , 
188+                             [ iter_ref ,  value ] , 
189+                         ) ; 
190+                         if  ( ! valid )  { 
191+                             break ; 
192+                         } 
193+                         yield  proxy_convert_mp_to_js_obj_jsside ( value ) ; 
191194                    } 
192-                     yield   proxy_convert_mp_to_js_obj_jsside ( value ) ; 
193-                 } 
194-                  Module . _free ( value ) ; 
195-             } ; 
195+                     Module . _free ( value ) ; 
196+                 } ; 
197+             } 
198+             return   null ; 
196199        } 
197200
198201        const  value  =  Module . _malloc ( 3  *  4 ) ; 
Original file line number Diff line number Diff line change 1+ // Test `<py-obj> get <attr>` on the JavaScript side, which tests PyProxy.get. 
2+ 
3+ const  mp  =  await  ( await  import ( process . argv [ 2 ] ) ) . loadMicroPython ( ) ; 
4+ 
5+ mp . runPython ( ` 
6+ x = {"a": 1} 
7+ ` ) ; 
8+ 
9+ const  x  =  mp . globals . get ( "x" ) ; 
10+ console . log ( x . a  ===  1 ) ; 
11+ console . log ( x . b  ===  undefined ) ; 
12+ console . log ( typeof  x [ Symbol . iterator ]  ===  "function" ) ; 
13+ console . log ( Object . prototype . toString . call ( x )  ===  "[object Object]" ) ; 
Original file line number Diff line number Diff line change 1+ true
2+ true
3+ true
4+ true
    
 
   
 
     
   
   
          
     
  
    
     
 
    
      
     
 
     
    You can’t perform that action at this time.
  
 
    
  
     
    
      
        
     
 
       
      
     
   
 
    
    
  
 
  
 
     
    
0 commit comments