pub fn set_property2_q(
    q_ctx: &QuickJsRealmAdapter,
    obj_ref: &JSValueRef,
    prop_name: &str,
    prop_ref: &JSValueRef,
    flags: i32
) -> Result<(), JsError>
Expand description

set a property with specific flags set_property applies the default flag JS_PROP_C_W_E (Configurable, Writable, Enumerable) flags you can use here are

  • q::JS_PROP_CONFIGURABLE
  • q::JS_PROP_WRITABLE
  • q::JS_PROP_ENUMERABLE
  • q::JS_PROP_C_W_E
  • q::JS_PROP_LENGTH
  • q::JS_PROP_TMASK
  • q::JS_PROP_NORMAL
  • q::JS_PROP_GETSET
  • q::JS_PROP_VARREF
  • q::JS_PROP_AUTOINIT

Example

use quickjs_runtime::builder::QuickJsRuntimeBuilder;
use quickjs_runtime::quickjs_utils::objects::{create_object_q, set_property2_q};
use quickjs_runtime::quickjs_utils::primitives::from_i32;
use libquickjs_sys as q;
let rt = QuickJsRuntimeBuilder::new().build();
rt.exe_rt_task_in_event_loop(|q_js_rt| {
   let q_ctx = q_js_rt.get_main_context();
   let obj = create_object_q(q_ctx).ok().unwrap();
   let prop = from_i32(785);
   // not enumerable
   set_property2_q(q_ctx, &obj, "someProp", &prop, (q::JS_PROP_CONFIGURABLE | q::JS_PROP_WRITABLE) as i32).ok().unwrap();
})