Skip to main content

quickjs/
cdefs.rs

1//! The C structs whose bytes C fills in and we read.
2//!
3//! `JSClassDef` and `JSCFunctionListEntry` are built by the *caller*'s compiler as static
4//! data, then handed to us by pointer. Nothing about them is negotiated at runtime: a field
5//! at the wrong offset is a silent misread, so every one of these is asserted against the
6//! number `gcc` printed for `offsetof` on this platform (`tests/abi.rs`).
7//!
8//! Measured on x86-64 Linux with the reference `quickjs.h`:
9//!
10//! ```text
11//! JSCFunctionListEntry 32 bytes: name 0, prop_flags 8, def_type 9, magic 10, u 16
12//!   u.func.length 16, u.func.cproto 17, u.func.cfunc 24
13//!   u.getset.get 16, u.getset.set 24, u.str/i32/i64/f64 16
14//! JSClassDef 40 bytes: class_name 0, finalizer 8, gc_mark 16, call 24, exotic 32
15//! ```
16//!
17//! # Why `JSCFunctionType` is a union of function pointers
18//!
19//! The reference spells one union for fourteen calling conventions and casts through it. We
20//! only ever *read* the pointer out and call it with the convention the surrounding
21//! `cproto`/`def_type` names, which is what the reference's own `JS_SetPropertyFunctionList`
22//! does too — so the union stays opaque here and [`JSCFunctionType::as_ptr`] is the one
23//! accessor.
24
25use core::ffi::{c_char, c_int, c_void};
26
27use crate::jsvalue::JsValue;
28
29/// `JS_CALL_FLAG_CONSTRUCTOR`: the flag `JSClassCall` receives on a `new` call.
30pub const JS_CALL_FLAG_CONSTRUCTOR: c_int = 1 << 0;
31
32/// `JSClassID`: a `uint32_t`. `0` is `JS_INVALID_CLASS_ID`.
33pub type ClassId = u32;
34
35/// `JS_BOOL`.
36pub type Bool = c_int;
37
38/// `JS_PROP_*`: the attribute bits a `JSCFunctionListEntry::prop_flags` carries.
39pub mod prop {
40    /// `JS_PROP_CONFIGURABLE`.
41    pub const CONFIGURABLE: u8 = 1 << 0;
42    /// `JS_PROP_WRITABLE`.
43    pub const WRITABLE: u8 = 1 << 1;
44    /// `JS_PROP_ENUMERABLE`.
45    pub const ENUMERABLE: u8 = 1 << 2;
46    /// `JS_PROP_HAS_VALUE`, `JS_PROP_HAS_GET`, … — the "this descriptor field is present"
47    /// bits. `JS_SetPropertyFunctionList` never sets them; they exist here so the shared
48    /// constants are all in one place.
49    pub const HAS_GET: u8 = 1 << 5;
50    /// `JS_PROP_HAS_SET`.
51    pub const HAS_SET: u8 = 1 << 6;
52    /// `JS_PROP_C_W_E`, the default for a method.
53    pub const C_W_E: u8 = CONFIGURABLE | WRITABLE | ENUMERABLE;
54}
55
56/// `JSCFunctionEnum`: which calling convention a `JSCFunctionType` holds.
57///
58/// Only the ones a `JSCFunctionListEntry` can name are listed; the reference's remaining
59/// values (`f_f`, `f_f_f`, `iterator_next`, …) are `JS_CFUNC_SPECIAL_DEF`'s business and
60/// arrive with the built-in classes that want them.
61#[derive(Clone, Copy, PartialEq, Eq, Debug)]
62#[repr(i32)]
63pub enum CFunctionEnum {
64    /// `JS_CFUNC_generic`: `(ctx, this_val, argc, argv)`.
65    Generic = 0,
66    /// `JS_CFUNC_generic_magic`: the same plus a trailing `magic`.
67    GenericMagic = 1,
68    /// `JS_CFUNC_constructor`: `(ctx, new_target, argc, argv)`, and `new` is allowed.
69    Constructor = 2,
70    /// `JS_CFUNC_constructor_magic`.
71    ConstructorMagic = 3,
72    /// `JS_CFUNC_constructor_or_func`: `(ctx, this_val, argc, argv)` either way.
73    ConstructorOrFunc = 4,
74    /// `JS_CFUNC_constructor_or_func_magic`.
75    ConstructorOrFuncMagic = 5,
76    /// `JS_CFUNC_constructor_or_func_flags`: `(ctx, func_obj, this_val, argc, argv, flags)`.
77    ConstructorOrFuncFlags = 6,
78    /// `JS_CFUNC_f_f`.
79    FF = 7,
80    /// `JS_CFUNC_f_f_f`.
81    FFF = 8,
82    /// `JS_CFUNC_getter`: `(ctx, this_val)`.
83    Getter = 9,
84    /// `JS_CFUNC_setter`: `(ctx, this_val, val)`.
85    Setter = 10,
86    /// `JS_CFUNC_getter_magic`.
87    GetterMagic = 11,
88    /// `JS_CFUNC_setter_magic`.
89    SetterMagic = 12,
90    /// `JS_CFUNC_iterator_next`.
91    IteratorNext = 13,
92}
93
94impl CFunctionEnum {
95    /// The enum value as C would have written it, or `None` for a value this layer does not
96    /// implement — which is a `TypeError` for the caller rather than a guess at a calling
97    /// convention.
98    pub fn from_raw(raw: u8) -> Option<CFunctionEnum> {
99        Some(match raw {
100            0 => CFunctionEnum::Generic,
101            1 => CFunctionEnum::GenericMagic,
102            2 => CFunctionEnum::Constructor,
103            3 => CFunctionEnum::ConstructorMagic,
104            4 => CFunctionEnum::ConstructorOrFunc,
105            5 => CFunctionEnum::ConstructorOrFuncMagic,
106            6 => CFunctionEnum::ConstructorOrFuncFlags,
107            7 => CFunctionEnum::FF,
108            8 => CFunctionEnum::FFF,
109            9 => CFunctionEnum::Getter,
110            10 => CFunctionEnum::Setter,
111            11 => CFunctionEnum::GetterMagic,
112            12 => CFunctionEnum::SetterMagic,
113            13 => CFunctionEnum::IteratorNext,
114            _ => return None,
115        })
116    }
117
118    /// Whether `new` is allowed on a function with this convention.
119    pub fn is_constructor(self) -> bool {
120        matches!(
121            self,
122            CFunctionEnum::Constructor
123                | CFunctionEnum::ConstructorMagic
124                | CFunctionEnum::ConstructorOrFunc
125                | CFunctionEnum::ConstructorOrFuncMagic
126                | CFunctionEnum::ConstructorOrFuncFlags
127        )
128    }
129}
130
131/// `JSCFunctionType`: the union of every `JSCFunction*` pointer type.
132///
133/// Kept as one pointer here, because the union is only ever read through the accessor the
134/// surrounding `cproto` selects. Reading any variant is a pointer load; which *signature*
135/// to call it with is decided by the enum, not by the union.
136#[derive(Clone, Copy)]
137#[repr(C)]
138pub struct JSCFunctionType {
139    /// The pointer, sign- and type-erased.
140    pub pointer: *const c_void,
141}
142
143impl JSCFunctionType {
144    /// The same pointer with no type. Callers transmute it to the signature `cproto` names.
145    pub fn as_ptr(self) -> *const c_void {
146        self.pointer
147    }
148
149    /// Whether the union holds nothing.
150    pub fn is_null(self) -> bool {
151        self.pointer.is_null()
152    }
153}
154
155// `JS_DEF_*`: what a `JSCFunctionListEntry` defines.
156/// `JS_DEF_CFUNC`: a function, with `u.func` filled in.
157pub const JS_DEF_CFUNC: u8 = 0;
158/// `JS_DEF_CGETSET`: a getter/setter pair with no `magic`.
159pub const JS_DEF_CGETSET: u8 = 1;
160/// `JS_DEF_CGETSET_MAGIC`: a getter/setter pair that also receives `magic`.
161pub const JS_DEF_CGETSET_MAGIC: u8 = 2;
162/// `JS_DEF_PROP_STRING`.
163pub const JS_DEF_PROP_STRING: u8 = 3;
164/// `JS_DEF_PROP_INT32`.
165pub const JS_DEF_PROP_INT32: u8 = 4;
166/// `JS_DEF_PROP_INT64`.
167pub const JS_DEF_PROP_INT64: u8 = 5;
168/// `JS_DEF_PROP_DOUBLE`.
169pub const JS_DEF_PROP_DOUBLE: u8 = 6;
170/// `JS_DEF_PROP_UNDEFINED`.
171pub const JS_DEF_PROP_UNDEFINED: u8 = 7;
172/// `JS_DEF_OBJECT`: a nested function-list table.
173pub const JS_DEF_OBJECT: u8 = 8;
174/// `JS_DEF_ALIAS`.
175pub const JS_DEF_ALIAS: u8 = 9;
176/// `JS_DEF_PROP_ATOM`.
177pub const JS_DEF_PROP_ATOM: u8 = 10;
178/// `JS_DEF_PROP_BOOL`.
179pub const JS_DEF_PROP_BOOL: u8 = 11;
180
181/// The `u.func` half of [`JSCFunctionListEntry`]: a function plus its arity and convention.
182#[derive(Clone, Copy)]
183#[repr(C)]
184pub struct FunctionEntry {
185    /// `length`.
186    pub length: u8,
187    /// A [`CFunctionEnum`] value.
188    pub cproto: u8,
189    /// Six bytes of padding, which C inserted to align `cfunc` to 8.
190    ///
191    /// Written out rather than left to `repr(C)` because the *next* field is a union: a
192    /// struct ending in a union has the union's alignment, and the compiler would place
193    /// `cfunc` at 8 anyway — but a field that is not spelled is a field whose offset is not
194    /// asserted, and this file's whole premise is that every offset is asserted.
195    pub _padding: [u8; 6],
196    /// The body.
197    pub cfunc: JSCFunctionType,
198}
199
200/// The `u.getset` half: a getter and a setter, either of which may be null.
201#[derive(Clone, Copy)]
202#[repr(C)]
203pub struct GetSetEntry {
204    /// `u.getset.get`.
205    pub get: JSCFunctionType,
206    /// `u.getset.set`.
207    pub set: JSCFunctionType,
208}
209
210/// The `u` union of [`JSCFunctionListEntry`].
211///
212/// A union in C; a struct here, because we read exactly one arm per entry and the arms all
213/// start at offset 0 — with the exception of `func`, whose `cfunc` is at 8 rather than 0.
214/// Modelling it as a struct of overlapping fields would need `unsafe` reads of a union for
215/// no gain: the field we want is chosen by `def_type`, which is checked before anything is
216/// read.
217#[derive(Clone, Copy)]
218#[repr(C)]
219pub union FunctionListUnion {
220    /// `u.func`.
221    pub func: core::mem::ManuallyDrop<FunctionEntry>,
222    /// `u.getset`.
223    pub getset: core::mem::ManuallyDrop<GetSetEntry>,
224    /// `u.alias.name`.
225    pub alias_name: *const c_char,
226    /// `u.alias.base`.
227    pub alias_base: c_int,
228    /// `u.prop_list.tab`.
229    pub prop_list_tab: *const JSCFunctionListEntry,
230    /// `u.prop_list.len`.
231    pub prop_list_len: c_int,
232    /// `u.str`.
233    pub str_: *const c_char,
234    /// `u.i32`, and also `u.alias.base`/`u.prop_list.len`'s storage.
235    pub i32: i32,
236    /// `u.i64`.
237    pub i64: i64,
238    /// `u.f64`.
239    pub f64: f64,
240    /// The raw eight bytes, for the cases where the arm is a pair of 4-byte words.
241    pub raw: u64,
242}
243
244/// `JSCFunctionListEntry`: one row of a static table a C module hands us.
245///
246/// 32 bytes, `u` at 16. C builds these with `JS_CFUNC_DEF` and friends, so the layout is
247/// fixed by the *caller's* compiler and we only read it.
248#[repr(C)]
249pub struct JSCFunctionListEntry {
250    /// The property name.
251    pub name: *const c_char,
252    /// `JS_PROP_*` attribute bits.
253    pub prop_flags: u8,
254    /// One of the `JS_DEF_*` values.
255    pub def_type: u8,
256    /// The `magic` integer the definition carries.
257    pub magic: i16,
258    /// Four bytes C inserted to align the union to 8.
259    pub _padding: [u8; 4],
260    /// The payload, whose arm `def_type` selects.
261    pub u: FunctionListUnion,
262}
263
264/// `JSClassFinalizer`: `void (*)(JSRuntime *rt, JSValue val)`.
265pub type ClassFinalizer = Option<unsafe extern "C" fn(*mut c_void, JsValue)>;
266
267/// `JSClassGCMark`: `void (*)(JSRuntime *rt, JSValueConst val, JS_MarkFunc *mark_func)`.
268pub type ClassGCMark = Option<unsafe extern "C" fn(*mut c_void, JsValue, *mut c_void)>;
269
270/// `JSClassCall`: `(ctx, func_obj, this_val, argc, argv, flags)`.
271pub type ClassCall = Option<
272    unsafe extern "C" fn(*mut c_void, JsValue, JsValue, c_int, *const JsValue, c_int) -> JsValue,
273>;
274
275/// `JSClassExoticMethods`: the traps a class may override.
276///
277/// Read field by field with null checks — a module that only wants `get_own_property` leaves
278/// the rest zero, which is what `point.c`'s empty `JSClassDef` relies on.
279#[repr(C)]
280pub struct JSClassExoticMethods {
281    /// `[[GetOwnProperty]]`.
282    pub get_own_property: Option<
283        unsafe extern "C" fn(*mut c_void, *mut JsValue, JsValue, c_int, *const JsValue) -> c_int,
284    >,
285    /// `[[DefineOwnProperty]]`.
286    pub define_own_property: Option<
287        unsafe extern "C" fn(
288            *mut c_void,
289            JsValue,
290            c_int,
291            *const JsValue,
292            JsValue,
293            *mut c_int,
294        ) -> c_int,
295    >,
296    /// `[[HasProperty]]`.
297    pub has_property:
298        Option<unsafe extern "C" fn(*mut c_void, JsValue, c_int, *const JsValue) -> c_int>,
299    /// `[[Delete]]`.
300    pub delete_property:
301        Option<unsafe extern "C" fn(*mut c_void, JsValue, c_int, *const JsValue) -> c_int>,
302    /// `[[GetPrototypeOf]]`.
303    pub get_prototype: Option<unsafe extern "C" fn(*mut c_void, JsValue) -> JsValue>,
304    /// `[[SetPrototypeOf]]`.
305    pub set_prototype: Option<unsafe extern "C" fn(*mut c_void, JsValue, JsValue) -> c_int>,
306    /// `[[IsExtensible]]`.
307    pub is_extensible: Option<unsafe extern "C" fn(*mut c_void, JsValue) -> c_int>,
308    /// `[[PreventExtensions]]`.
309    pub prevent_extensions: Option<unsafe extern "C" fn(*mut c_void, JsValue) -> c_int>,
310}
311
312/// `JSClassDef`: what `JS_NewClass` is handed.
313///
314/// 40 bytes: `class_name` 0, `finalizer` 8, `gc_mark` 16, `call` 24, `exotic` 32.
315#[repr(C)]
316pub struct JSClassDef {
317    /// The class name, for diagnostics.
318    pub class_name: *const c_char,
319    /// Run once when an instance is released.
320    pub finalizer: ClassFinalizer,
321    /// `gc_mark`, for a payload that points at other JavaScript values.
322    pub gc_mark: ClassGCMark,
323    /// `call`, non-null when instances are callable.
324    pub call: ClassCall,
325    /// The exotic traps.
326    pub exotic: *const JSClassExoticMethods,
327}
328
329/// `JSModuleInitFunc`: fills a module's exports in.
330pub type ModuleInitFunc =
331    Option<unsafe extern "C" fn(*mut crate::runtime::JsContext, *mut JsModuleDef) -> c_int>;
332
333/// `JSCFunctionData`: `(ctx, this_val, argc, argv, magic, func_data)`.
334pub type CFunctionData = Option<
335    unsafe extern "C" fn(
336        *mut crate::runtime::JsContext,
337        JsValue,
338        c_int,
339        *const JsValue,
340        c_int,
341        *mut JsValue,
342    ) -> JsValue,
343>;
344
345/// `JSCFunction`: the plain `(ctx, this_val, argc, argv)` shape.
346pub type RawFunction = *const c_void;
347
348/// `JSInterruptHandler`: return non-zero to abort the running script.
349pub type InterruptHandler =
350    Option<unsafe extern "C" fn(*mut crate::runtime::JsRuntime, *mut c_void) -> c_int>;
351
352/// `JSModuleNormalizeFunc`: turn `(base_name, name)` into the module's key.
353pub type ModuleNormalizeFunc = Option<
354    unsafe extern "C" fn(
355        *mut crate::runtime::JsContext,
356        *const c_char,
357        *const c_char,
358        *mut c_void,
359    ) -> *mut c_char,
360>;
361
362/// `JSModuleLoaderFunc`: load the module a normalised key names.
363pub type ModuleLoaderFunc = Option<
364    unsafe extern "C" fn(*mut crate::runtime::JsContext, *const c_char, *mut c_void) -> JsValue,
365>;
366
367/// `JSModuleLoaderFunc2`: the same, plus the import attributes.
368pub type ModuleLoaderFunc2 = Option<
369    unsafe extern "C" fn(
370        *mut crate::runtime::JsContext,
371        *const c_char,
372        *mut crate::runtime::JsContext,
373        *const c_char,
374        *mut c_void,
375    ) -> JsValue,
376>;
377
378/// `JSModuleCheckSupportedImportAttributes`: refuse an attribute set the host cannot honour.
379pub type ModuleCheckAttrs = Option<
380    unsafe extern "C" fn(
381        *mut crate::runtime::JsContext,
382        *mut crate::runtime::JsContext,
383        *mut c_void,
384    ) -> c_int,
385>;
386
387/// `JSJobFunc`: a job the host enqueued with `JS_EnqueueJob`.
388pub type JobFunc =
389    Option<unsafe extern "C" fn(*mut crate::runtime::JsContext, c_int, *const JsValue) -> JsValue>;
390
391/// `JSHostPromiseRejectionTracker`.
392pub type PromiseRejectionTracker = Option<
393    unsafe extern "C" fn(*mut crate::runtime::JsContext, JsValue, JsValue, c_int, *mut c_void),
394>;
395
396/// `JSMallocFunctions`: a custom allocator for `JS_NewRuntime2`.
397#[repr(C)]
398pub struct JSMallocFunctions {
399    /// `js_malloc`.
400    pub js_malloc: Option<unsafe extern "C" fn(*mut c_void, usize) -> *mut c_void>,
401    /// `js_free`.
402    pub js_free: Option<unsafe extern "C" fn(*mut c_void, *mut c_void)>,
403    /// `js_realloc`.
404    pub js_realloc: Option<unsafe extern "C" fn(*mut c_void, *mut c_void, usize) -> *mut c_void>,
405    /// `js_malloc_usable_size`.
406    pub js_malloc_usable_size: Option<unsafe extern "C" fn(*const c_void) -> usize>,
407}
408
409/// `JSPropertyEnum`: one entry of `JS_GetOwnPropertyNames`' answer.
410///
411/// 8 bytes, exactly as the header lays it out: `is_enumerable` is a `JS_BOOL` (4 bytes) and
412/// `atom` follows at offset 4.
413#[repr(C)]
414pub struct JSPropertyEnum {
415    /// Whether the property is enumerable, filled in when `JS_GPN_SET_ENUM` was asked for.
416    pub is_enumerable: crate::cdefs::Bool,
417    /// The property's atom.
418    pub atom: crate::atoms::Atom,
419}
420
421/// `JSPropertyDescriptor`: one complete property, as `JS_GetOwnProperty` reports it.
422///
423/// 32 bytes: `flags` at 0, then three `JSValue`s at 8/16/24.
424#[repr(C)]
425pub struct JSPropertyDescriptor {
426    /// `JS_PROP_*`: the attributes, plus `JS_PROP_GETSET` for an accessor.
427    pub flags: c_int,
428    /// The value, for a data property.
429    pub value: JsValue,
430    /// The getter, for an accessor.
431    pub getter: JsValue,
432    /// The setter, for an accessor.
433    pub setter: JsValue,
434}
435
436/// `JSPrintValueOptions`: how `JS_PrintValue` renders a value.
437#[repr(C)]
438pub struct JSPrintValueOptions {
439    /// `show_hidden`: `bool` in the header's bitfield, and this layer reads it as a byte.
440    pub show_hidden: u8,
441    /// `raw_dump`.
442    pub raw_dump: u8,
443    /// `max_depth`, 0 for no limit.
444    pub max_depth: u32,
445    /// `max_string_length`, 0 for no limit.
446    pub max_string_length: u32,
447    /// `max_item_count`, 0 for no limit.
448    pub max_item_count: u32,
449}
450
451/// `JSPrintValueWrite`: receives the rendered text in chunks.
452pub type PrintValueWrite = Option<unsafe extern "C" fn(*mut c_void, *const c_char, usize)>;
453
454/// `JSMemoryUsage`: the shape `JS_ComputeMemoryUsage` fills in.
455///
456/// Field-for-field with the header so that a C program reading `s->malloc_count` reads the
457/// number we wrote there. Every field is `int64_t` in the reference; the `size_t`-valued
458/// ones are widened on the way out.
459#[repr(C)]
460#[derive(Default, Clone, Copy)]
461pub struct JSMemoryUsage {
462    /// Bytes the allocator holds.
463    pub malloc_size: i64,
464    /// Allocations outstanding.
465    pub malloc_count: i64,
466    /// Bytes the allocator can still hand out (0 when unlimited).
467    pub memory_used_size: i64,
468    /// Times the allocator was asked for memory.
469    pub malloc_limit: i64,
470    /// Bytes the allocator has borrowed from the system.
471    pub memory_used_count: i64,
472    /// Atoms interned.
473    pub atom_count: i64,
474    /// Bytes those atoms occupy.
475    pub atom_size: i64,
476    /// Strings.
477    pub str_count: i64,
478    /// Bytes those strings occupy.
479    pub str_size: i64,
480    /// Objects.
481    pub obj_count: i64,
482    /// Bytes those objects occupy.
483    pub obj_size: i64,
484    /// Properties.
485    pub prop_count: i64,
486    /// Bytes those properties occupy.
487    pub prop_size: i64,
488    /// Shapes (hidden classes).
489    pub shape_count: i64,
490    /// Bytes those shapes occupy.
491    pub shape_size: i64,
492    /// JavaScript functions.
493    pub js_func_count: i64,
494    /// Bytes of bytecode.
495    pub js_func_size: i64,
496    /// Bytecode instructions.
497    pub js_func_code_size: i64,
498    /// Bytecode instructions, as a running total.
499    pub js_func_pc2line_count: i64,
500    /// Bytes of the pc-to-line table.
501    pub js_func_pc2line_size: i64,
502    /// C functions.
503    pub c_func_count: i64,
504    /// Arrays.
505    pub array_count: i64,
506    /// Arrays stored as element vectors.
507    pub fast_array_count: i64,
508    /// Elements in those.
509    pub fast_array_elements: i64,
510    /// Binary objects.
511    pub binary_object_count: i64,
512    /// Bytes they occupy.
513    pub binary_object_size: i64,
514}
515
516/// `JSModuleDef`: a C module's definition, as `JS_NewCModule` answers it.
517///
518/// The C side only passes it back, so the fields are ours — but it has to be a real
519/// allocation with a stable address, because `JS_AddModuleExport` is called with the same
520/// pointer the init function was given. It is `repr(C)` for the same reason: nothing on the
521/// C side looks inside, and a plain Rust layout is all it needs.
522#[repr(C)]
523pub struct JsModuleDef {
524    /// The module name, as `JS_NewCModule` received it.
525    pub name: String,
526    /// The exports added with `JS_AddModuleExport`/`JS_AddModuleExportList`.
527    pub declared: Vec<String>,
528    /// The values set with `JS_SetModuleExport`.
529    ///
530    /// Engine values, not `JSValue`s: `JS_SetModuleExport` consumes the reference it is
531    /// given (as the C API says it does), so what is kept is the engine's own handle. That
532    /// keeps the module definition out of the reference-counting business entirely, and a
533    /// definition therefore needs no `Drop`.
534    pub values: Vec<(String, engine::Value)>,
535    /// The function that fills the exports in, run when the module is instantiated.
536    pub init: ModuleInitFunc,
537    /// `JS_SetModulePrivateValue`'s value, which a host uses to reach its own data from a
538    /// module's callbacks.
539    pub private: Option<engine::Value>,
540}
541
542const _: () = {
543    use core::mem::{align_of, offset_of, size_of};
544    assert!(size_of::<JSCFunctionListEntry>() == 32);
545    assert!(offset_of!(JSCFunctionListEntry, name) == 0);
546    assert!(offset_of!(JSCFunctionListEntry, prop_flags) == 8);
547    assert!(offset_of!(JSCFunctionListEntry, def_type) == 9);
548    assert!(offset_of!(JSCFunctionListEntry, magic) == 10);
549    assert!(offset_of!(JSCFunctionListEntry, u) == 16);
550    assert!(offset_of!(FunctionEntry, length) == 0);
551    assert!(offset_of!(FunctionEntry, cproto) == 1);
552    assert!(offset_of!(FunctionEntry, cfunc) == 8);
553    assert!(align_of::<JSCFunctionListEntry>() == 8);
554    assert!(size_of::<JSClassDef>() == 40);
555    assert!(offset_of!(JSClassDef, class_name) == 0);
556    assert!(offset_of!(JSClassDef, finalizer) == 8);
557    assert!(offset_of!(JSClassDef, gc_mark) == 16);
558    assert!(offset_of!(JSClassDef, call) == 24);
559    assert!(offset_of!(JSClassDef, exotic) == 32);
560    assert!(size_of::<JSCFunctionType>() == 8);
561    assert!(size_of::<ClassId>() == 4);
562};