Function script::dom::bindings::import::module::jsapi::JS::ToJSONMaybeSafely

source ·
pub unsafe extern "C" fn ToJSONMaybeSafely(
    cx: *mut JSContext,
    input: Handle<*mut JSObject>,
    callback: Option<unsafe extern "C" fn(_: *const u16, _: u32, _: *mut c_void) -> bool>,
    data: *mut c_void,
) -> bool
Expand description

An API akin to JS_Stringify but with the goal of not having observable side-effects when the stringification is performed. This means it does not allow a replacer or a custom space and has the following constraints on its input:

  1. The input must be a plain object or array, not an abitrary value.
  2. Every value in the graph reached by the algorithm starting with this object must be one of the following: null, undefined, a string (NOT a string object!), a boolean, a finite number (i.e. no NaN or Infinity or -Infinity), a plain object with no accessor properties, or an Array with no holes.

The actual behavior differs from JS_Stringify only in asserting the above and NOT attempting to get the “toJSON” property from things, since that could clearly have side-effects.