Skip to main content

Module objects

Module objects 

Source
Expand description

Objects, properties and C functions: the JS_NewObject family.

Everything here is a translation, not an implementation: the engine already has objects, property tables, accessors and host functions (docs/m15-plan.md §5, S1). What this module adds is the C API’s shapes — a JSCFunctionListEntry table, a JS_CFUNC_* calling convention, JS_SetConstructor’s two reciprocal properties.

§The one real decision: who owns the returned value

A function that answers JSValue answers a new reference: the caller owns it and is responsible for JS_FreeValue. That is why JS_NewObject boxes its answer with a count of one and why a C function’s return value is released by the trampoline once the engine value has been cloned out. argv is the opposite — borrowed, never freed by us — which is the asymmetry crate::convert is built around.

Functions§

JS_FreeCString⚠
JS_FreeCString: release a string from JS_ToCStringLen2.
JS_GetClassID⚠
JS_GetClassID: the class an object belongs to, or JS_INVALID_CLASS_ID.
JS_GetClassProto⚠
JS_GetClassProto: the prototype installed for class_id, as a new reference.
JS_GetGlobalObject⚠
The global object (JS_GetGlobalObject).
JS_GetOpaque⚠
JS_GetOpaque: the payload of obj when it is an instance of class_id.
JS_GetOpaque2⚠
JS_GetOpaque2: JS_GetOpaque, raising a TypeError instead of answering null.
JS_GetPropertyStr⚠
JS_GetPropertyStr: read a property by name, answering a new reference.
JS_GetRuntime⚠
JS_GetRuntime: the runtime a context belongs to.
JS_IsRegisteredClass⚠
JS_IsRegisteredClass.
JS_NewCFunction2⚠
JS_NewCFunction2: wrap a C function pointer as a JavaScript function.
JS_NewClass⚠
JS_NewClass: register a class with the runtime.
JS_NewClassID⚠
JS_NewClassID: allocate an id, storing it in *pclass_id.
JS_NewObject⚠
JS_NewObject: an ordinary object inheriting Object.prototype.
JS_NewObjectClass⚠
JS_NewObjectClass: an instance of class_id with the prototype installed for it.
JS_NewObjectProtoClass⚠
JS_NewObjectProtoClass: an instance of class_id whose prototype is proto.
JS_SetClassProto⚠
JS_SetClassProto: the prototype JS_NewObjectClass uses for class_id.
JS_SetConstructor⚠
JS_SetConstructor: make func_obj.prototype and proto.constructor point at each other.
JS_SetOpaque⚠
JS_SetOpaque: attach a payload pointer to a host-class instance.
JS_SetPropertyFunctionList⚠
JS_SetPropertyFunctionList: install a static table of definitions.
JS_SetPropertyStr⚠
JS_SetPropertyStr: write a property by name, answering -1 on failure.
JS_ThrowRangeError⚠
JS_ThrowRangeError: raise a RangeError with the given message.
JS_ToBool⚠
JS_ToBool: the truthiness of a value, or -1 for an exception.
JS_ToCStringLen2⚠
JS_ToCStringLen2: the value as a NUL-terminated UTF-8 string, allocated by crate::js_mallocz’s allocator so JS_FreeCString can release it.
JS_ToFloat64⚠
JS_ToFloat64: ToNumber, or -1 with a pending exception.
JS_ToIndex⚠
JS_ToIndex: a valid array index, or a RangeError.

Type Aliases§

RawFunction
The shape of every C function the API installs, as a raw pointer.