[quickjs-devel] Re: Iterate over JSValue/Object

  • From: Alexander Rodin <rodin.alexander@xxxxxxxxx>
  • To: quickjs-devel@xxxxxxxxxxxxx
  • Date: Mon, 19 Aug 2019 15:12:05 +0300

Hi Serghei,

How it can be iterated an JSValue of type Object? I need to parse on C-host 
an 
object/array received from js.

You can use `JS_GetOwnPropertyNames` and `JS_GetPropertyInternal` to iterate 
over object properties.

See 
https://github.com/theduke/quickjs-rs/blob/4a87e54c66e2d4225be69c258f044f396d2f8ac1/src/bindings.rs#L239-L288
 
<https://github.com/theduke/quickjs-rs/blob/4a87e54c66e2d4225be69c258f044f396d2f8ac1/src/bindings.rs#L239-L288>
 for an example of iterating over an object and 
https://github.com/theduke/quickjs-rs/blob/4a87e54c66e2d4225be69c258f044f396d2f8ac1/src/bindings.rs#L202-L237
 
<https://github.com/theduke/quickjs-rs/blob/4a87e54c66e2d4225be69c258f044f396d2f8ac1/src/bindings.rs#L202-L237>
 for an example of iterating over an array. Although it is not C, but Rust, the 
idea should still be clear if you look at `unsafe` blocks.

Best regards,
Alexander

Other related posts: