Function mozjs::jsapi::JS_InitClass

source ·
pub unsafe extern "C" fn JS_InitClass(
    cx: *mut JSContext,
    obj: Handle<*mut JSObject>,
    protoClass: *const JSClass,
    protoProto: Handle<*mut JSObject>,
    name: *const i8,
    constructor: Option<unsafe extern "C" fn(_: *mut JSContext, _: u32, _: *mut Value) -> bool>,
    nargs: u32,
    ps: *const JSPropertySpec,
    fs: *const JSFunctionSpec,
    static_ps: *const JSPropertySpec,
    static_fs: *const JSFunctionSpec
) -> *mut JSObject
Expand description

Defines a builtin constructor and prototype. Returns the prototype object.

  • Defines a property named name on obj, with its value set to a newly-created JS function that invokes the constructor JSNative. The length of the function is nargs.

  • Creates a prototype object with proto protoProto and class protoClass. If protoProto is nullptr, Object.prototype will be used instead. If protoClass is nullptr, the prototype object will be a plain JS object.

  • The ps and fs properties/functions will be defined on the prototype object.

  • The static_ps and static_fs properties/functions will be defined on the constructor.