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_
FreeC ⚠String JS_FreeCString: release a string fromJS_ToCStringLen2.- JS_
GetClassID ⚠ JS_GetClassID: the class an object belongs to, orJS_INVALID_CLASS_ID.- JS_
GetClass ⚠Proto JS_GetClassProto: the prototype installed forclass_id, as a new reference.- JS_
GetGlobal ⚠Object - The global object (
JS_GetGlobalObject). - JS_
GetOpaque ⚠ JS_GetOpaque: the payload ofobjwhen it is an instance ofclass_id.- JS_
GetOpaque2 ⚠ JS_GetOpaque2:JS_GetOpaque, raising aTypeErrorinstead of answering null.- JS_
GetProperty ⚠Str JS_GetPropertyStr: read a property by name, answering a new reference.- JS_
GetRuntime ⚠ JS_GetRuntime: the runtime a context belongs to.- JS_
IsRegistered ⚠Class JS_IsRegisteredClass.- JS_
NewC ⚠Function2 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 inheritingObject.prototype.- JS_
NewObject ⚠Class JS_NewObjectClass: an instance ofclass_idwith the prototype installed for it.- JS_
NewObject ⚠Proto Class JS_NewObjectProtoClass: an instance ofclass_idwhose prototype isproto.- JS_
SetClass ⚠Proto JS_SetClassProto: the prototypeJS_NewObjectClassuses forclass_id.- JS_
SetConstructor ⚠ JS_SetConstructor: makefunc_obj.prototypeandproto.constructorpoint at each other.- JS_
SetOpaque ⚠ JS_SetOpaque: attach a payload pointer to a host-class instance.- JS_
SetProperty ⚠Function List JS_SetPropertyFunctionList: install a static table of definitions.- JS_
SetProperty ⚠Str JS_SetPropertyStr: write a property by name, answering-1on failure.- JS_
Throw ⚠Range Error JS_ThrowRangeError: raise aRangeErrorwith the given message.- JS_
ToBool ⚠ JS_ToBool: the truthiness of a value, or-1for an exception.- JS_
ToCString ⚠Len2 JS_ToCStringLen2: the value as a NUL-terminated UTF-8 string, allocated bycrate::js_mallocz’s allocator soJS_FreeCStringcan release it.- JS_
ToFloat64 ⚠ JS_ToFloat64:ToNumber, or-1with a pending exception.- JS_
ToIndex ⚠ JS_ToIndex: a valid array index, or aRangeError.
Type Aliases§
- RawFunction
- The shape of every C function the API installs, as a raw pointer.