Skip to main content

Module cdefs

Module cdefs 

Source
Expand description

The C structs whose bytes C fills in and we read.

JSClassDef and JSCFunctionListEntry are built by the caller’s compiler as static data, then handed to us by pointer. Nothing about them is negotiated at runtime: a field at the wrong offset is a silent misread, so every one of these is asserted against the number gcc printed for offsetof on this platform (tests/abi.rs).

Measured on x86-64 Linux with the reference quickjs.h:

JSCFunctionListEntry 32 bytes: name 0, prop_flags 8, def_type 9, magic 10, u 16
  u.func.length 16, u.func.cproto 17, u.func.cfunc 24
  u.getset.get 16, u.getset.set 24, u.str/i32/i64/f64 16
JSClassDef 40 bytes: class_name 0, finalizer 8, gc_mark 16, call 24, exotic 32

§Why JSCFunctionType is a union of function pointers

The reference spells one union for fourteen calling conventions and casts through it. We only ever read the pointer out and call it with the convention the surrounding cproto/def_type names, which is what the reference’s own JS_SetPropertyFunctionList does too — so the union stays opaque here and JSCFunctionType::as_ptr is the one accessor.

Modules§

prop
JS_PROP_*: the attribute bits a JSCFunctionListEntry::prop_flags carries.

Structs§

FunctionEntry
The u.func half of JSCFunctionListEntry: a function plus its arity and convention.
GetSetEntry
The u.getset half: a getter and a setter, either of which may be null.
JSCFunctionListEntry
JSCFunctionListEntry: one row of a static table a C module hands us.
JSCFunctionType
JSCFunctionType: the union of every JSCFunction* pointer type.
JSClassDef
JSClassDef: what JS_NewClass is handed.
JSClassExoticMethods
JSClassExoticMethods: the traps a class may override.
JSMallocFunctions
JSMallocFunctions: a custom allocator for JS_NewRuntime2.
JSMemoryUsage
JSMemoryUsage: the shape JS_ComputeMemoryUsage fills in.
JSPrintValueOptions
JSPrintValueOptions: how JS_PrintValue renders a value.
JSPropertyDescriptor
JSPropertyDescriptor: one complete property, as JS_GetOwnProperty reports it.
JSPropertyEnum
JSPropertyEnum: one entry of JS_GetOwnPropertyNames’ answer.
JsModuleDef
JSModuleDef: a C module’s definition, as JS_NewCModule answers it.

Enums§

CFunctionEnum
JSCFunctionEnum: which calling convention a JSCFunctionType holds.

Constants§

JS_CALL_FLAG_CONSTRUCTOR
JS_CALL_FLAG_CONSTRUCTOR: the flag JSClassCall receives on a new call.
JS_DEF_ALIAS
JS_DEF_ALIAS.
JS_DEF_CFUNC
JS_DEF_CFUNC: a function, with u.func filled in.
JS_DEF_CGETSET
JS_DEF_CGETSET: a getter/setter pair with no magic.
JS_DEF_CGETSET_MAGIC
JS_DEF_CGETSET_MAGIC: a getter/setter pair that also receives magic.
JS_DEF_OBJECT
JS_DEF_OBJECT: a nested function-list table.
JS_DEF_PROP_ATOM
JS_DEF_PROP_ATOM.
JS_DEF_PROP_BOOL
JS_DEF_PROP_BOOL.
JS_DEF_PROP_DOUBLE
JS_DEF_PROP_DOUBLE.
JS_DEF_PROP_INT32
JS_DEF_PROP_INT32.
JS_DEF_PROP_INT64
JS_DEF_PROP_INT64.
JS_DEF_PROP_STRING
JS_DEF_PROP_STRING.
JS_DEF_PROP_UNDEFINED
JS_DEF_PROP_UNDEFINED.

Type Aliases§

Bool
JS_BOOL.
CFunctionData
JSCFunctionData: (ctx, this_val, argc, argv, magic, func_data).
ClassCall
JSClassCall: (ctx, func_obj, this_val, argc, argv, flags).
ClassFinalizer
JSClassFinalizer: void (*)(JSRuntime *rt, JSValue val).
ClassGCMark
JSClassGCMark: void (*)(JSRuntime *rt, JSValueConst val, JS_MarkFunc *mark_func).
ClassId
JSClassID: a uint32_t. 0 is JS_INVALID_CLASS_ID.
InterruptHandler
JSInterruptHandler: return non-zero to abort the running script.
JobFunc
JSJobFunc: a job the host enqueued with JS_EnqueueJob.
ModuleCheckAttrs
JSModuleCheckSupportedImportAttributes: refuse an attribute set the host cannot honour.
ModuleInitFunc
JSModuleInitFunc: fills a module’s exports in.
ModuleLoaderFunc
JSModuleLoaderFunc: load the module a normalised key names.
ModuleLoaderFunc2
JSModuleLoaderFunc2: the same, plus the import attributes.
ModuleNormalizeFunc
JSModuleNormalizeFunc: turn (base_name, name) into the module’s key.
PrintValueWrite
JSPrintValueWrite: receives the rendered text in chunks.
PromiseRejectionTracker
JSHostPromiseRejectionTracker.
RawFunction
JSCFunction: the plain (ctx, this_val, argc, argv) shape.

Unions§

FunctionListUnion
The u union of JSCFunctionListEntry.