neon

Module object

Source
Expand description

Traits for working with JavaScript objects.

This module defines the Object trait, which is implemented by all object types in the JavaScript type hierarchy. This trait provides key operations in the semantics of JavaScript objects, such as getting and setting an object’s properties.

§Property Keys

Object properties are accessed by a property key, which in JavaScript can be a string or symbol. (Neon does not yet have support for symbols.) For convenience, the PropertyKey trait allows Neon programs to use various Rust string types, as well as numeric types, as keys when accessing object properties, converting the keys to strings as necessary:

fn set_and_check<'cx>(
    cx: &mut Cx<'cx>,
    obj: Handle<'cx, JsObject>
) -> JsResult<'cx, JsValue> {
    // set property "17" with integer shorthand
    obj.prop(cx, 17).set("hello")?;
    // get property "17" with string shorthand
    // returns the same value ("hello!")
    obj.prop(cx, "17").get()
}

Structs§

Traits§

  • The trait of all object types.
  • A property key in a JavaScript object.