1use core::ffi::{c_int, c_void};
14
15use engine::Value;
16use engine::interp::Hint;
17
18use crate::atoms::Atom;
19use crate::cdefs::{Bool, CFunctionEnum, JSClassDef};
20use crate::conversions::{arg, c_text};
21use crate::jsvalue::{self, JsValue};
22
23use crate::runtime::{self, JsContext, JsRuntime};
24use crate::value_helpers::jsvalue_of;
25
26pub(crate) unsafe fn decode_args(argc: c_int, argv: *const JsValue) -> Vec<Value> {
36 if argc <= 0 || argv.is_null() {
37 return Vec::new();
38 }
39 let values = unsafe { core::slice::from_raw_parts(argv, argc as usize) };
41 values
42 .iter()
43 .map(|value| unsafe { arg(*value) }.unwrap_or(Value::Undefined))
44 .collect()
45}
46
47#[unsafe(no_mangle)]
57pub unsafe extern "C" fn JS_Call(
58 ctx: *mut JsContext,
59 func_obj: JsValue,
60 this_obj: JsValue,
61 argc: c_int,
62 argv: *const JsValue,
63) -> JsValue {
64 let Some(context) = (unsafe { ctx.as_ref() }) else {
65 return jsvalue::EXCEPTION;
66 };
67 let Some(callee) = (unsafe { arg(func_obj) }) else {
68 return runtime::throw_error(context, "TypeError", "not a function");
69 };
70 let this = unsafe { arg(this_obj) }.unwrap_or(Value::Undefined);
71 let args = unsafe { decode_args(argc, argv) };
73 let result = context.with_current_interp(|interp| interp.call_value(callee, this, args));
74 runtime::result_value(context, result)
75}
76
77#[unsafe(no_mangle)]
86pub unsafe extern "C" fn JS_Invoke(
87 ctx: *mut JsContext,
88 this_val: JsValue,
89 atom: Atom,
90 argc: c_int,
91 argv: *const JsValue,
92) -> JsValue {
93 let Some(context) = (unsafe { ctx.as_ref() }) else {
94 return jsvalue::EXCEPTION;
95 };
96 let Some(receiver) = (unsafe { arg(this_val) }) else {
97 return runtime::throw_error(context, "TypeError", "not a value");
98 };
99 let Some(key) = crate::properties::atom_text(context, atom) else {
100 return runtime::throw_error(context, "TypeError", "invalid atom");
101 };
102 let args = unsafe { decode_args(argc, argv) };
104 let result = context.with_current_interp(|interp| {
105 let method = interp.read_field(&receiver, &key)?;
106 interp.call_value(method, receiver, args)
107 });
108 runtime::result_value(context, result)
109}
110
111#[unsafe(no_mangle)]
117pub unsafe extern "C" fn JS_CallConstructor(
118 ctx: *mut JsContext,
119 func_obj: JsValue,
120 argc: c_int,
121 argv: *const JsValue,
122) -> JsValue {
123 let Some(context) = (unsafe { ctx.as_ref() }) else {
124 return jsvalue::EXCEPTION;
125 };
126 let Some(callee) = (unsafe { arg(func_obj) }) else {
127 return runtime::throw_error(context, "TypeError", "not a constructor");
128 };
129 let args = unsafe { decode_args(argc, argv) };
131 let result =
132 context.with_current_interp(|interp| interp.construct(callee.clone(), callee, args));
133 runtime::result_value(context, result)
134}
135
136#[unsafe(no_mangle)]
142pub unsafe extern "C" fn JS_CallConstructor2(
143 ctx: *mut JsContext,
144 func_obj: JsValue,
145 new_target: JsValue,
146 argc: c_int,
147 argv: *const JsValue,
148) -> JsValue {
149 let Some(context) = (unsafe { ctx.as_ref() }) else {
150 return jsvalue::EXCEPTION;
151 };
152 let Some(callee) = (unsafe { arg(func_obj) }) else {
153 return runtime::throw_error(context, "TypeError", "not a constructor");
154 };
155 let new_target = unsafe { arg(new_target) }.unwrap_or_else(|| callee.clone());
156 let args = unsafe { decode_args(argc, argv) };
158 let result = context.with_current_interp(|interp| interp.construct(callee, new_target, args));
159 runtime::result_value(context, result)
160}
161
162#[unsafe(no_mangle)]
171pub unsafe extern "C" fn JS_NewCFunctionData(
172 ctx: *mut JsContext,
173 func: crate::cdefs::CFunctionData,
174 length: c_int,
175 magic: c_int,
176 data_len: c_int,
177 data: *const JsValue,
178) -> JsValue {
179 let Some(context) = (unsafe { ctx.as_ref() }) else {
180 return jsvalue::EXCEPTION;
181 };
182 let Some(func) = func else {
183 return runtime::throw_error(context, "TypeError", "null function");
184 };
185 let captured = unsafe { decode_args(data_len, data) };
187 context.with_current_interp(|interp| {
188 let arity = u32::try_from(length).unwrap_or(0);
189 let body: engine::object::HostFn = Box::new(move |interp, this, args| {
190 let mut all: Vec<Value> = args.to_vec();
193 all.extend(captured.iter().cloned());
194 let this_value = jsvalue_of(this);
195 let arguments: Vec<JsValue> = all.iter().map(|v| jsvalue_of(v.clone())).collect();
196 let argc = c_int::try_from(arguments.len()).unwrap_or(c_int::MAX);
197 let context = runtime::current_context();
198 let answer = unsafe {
200 let call: unsafe extern "C" fn(
201 *mut JsContext,
202 JsValue,
203 c_int,
204 *const JsValue,
205 c_int,
206 *mut JsValue,
207 ) -> JsValue = func;
208 let data_out = arguments.as_ptr().add(args.len()) as *mut JsValue;
212 call(
213 context
214 .map(|c| c as *const JsContext as *mut JsContext)
215 .unwrap_or(std::ptr::null_mut()),
216 this_value,
217 argc,
218 arguments.as_ptr(),
219 magic,
220 data_out,
221 )
222 };
223 let _ = interp;
224 match unsafe { arg(answer) } {
225 Some(value) => {
226 unsafe { runtime::release(answer) };
228 Ok(value)
229 }
230 None => Err(engine::Signal::Throw(
231 context
232 .map(|context| context.take_pending().unwrap_or(Value::Undefined))
233 .unwrap_or(Value::Undefined),
234 )),
235 }
236 });
237 jsvalue_of(Value::Object(interp.new_host_function(
238 "C function data".to_string(),
239 arity,
240 body,
241 )))
242 })
243}
244
245#[unsafe(no_mangle)]
255pub unsafe extern "C" fn JS_IsFunction(_ctx: *mut JsContext, val: JsValue) -> Bool {
256 match unsafe { arg(val) } {
257 Some(Value::Object(object)) => c_int::from(object.is_callable()),
258 _ => 0,
259 }
260}
261
262#[unsafe(no_mangle)]
268pub unsafe extern "C" fn JS_IsConstructor(_ctx: *mut JsContext, val: JsValue) -> Bool {
269 match unsafe { arg(val) } {
270 Some(Value::Object(object)) => c_int::from(object.is_constructor()),
271 _ => 0,
272 }
273}
274
275#[unsafe(no_mangle)]
287pub unsafe extern "C" fn JS_IsCFunction(
288 _ctx: *mut JsContext,
289 val: JsValue,
290 func: *const c_void,
291 magic: c_int,
292) -> Bool {
293 let _ = (func, magic);
294 match unsafe { arg(val) } {
295 Some(Value::Object(object)) => {
302 c_int::from(object.is_callable() && object.is_native_function())
303 }
304 _ => 0,
305 }
306}
307
308#[unsafe(no_mangle)]
314pub unsafe extern "C" fn JS_IsError(ctx: *mut JsContext, val: JsValue) -> Bool {
315 let Some(context) = (unsafe { ctx.as_ref() }) else {
316 return 0;
317 };
318 let Some(Value::Object(object)) = (unsafe { arg(val) }) else {
319 return 0;
320 };
321 let is_error = context.with_current_interp(|interp| {
324 interp
325 .internal_get(&object, "_class")
326 .is_some_and(|tag| tag.to_js_string().ends_with("Error"))
327 });
328 c_int::from(is_error)
329}
330
331#[unsafe(no_mangle)]
340pub unsafe extern "C" fn JS_IsArray(ctx: *mut JsContext, val: JsValue) -> c_int {
341 let Some(context) = (unsafe { ctx.as_ref() }) else {
342 return -1;
343 };
344 let Some(value) = (unsafe { arg(val) }) else {
345 runtime::throw_error(context, "TypeError", "not a value");
346 return -1;
347 };
348 let answer = context.with_current_interp(|interp| {
349 interp.is_array_value(&value)
351 });
352 c_int::from(answer)
353}
354
355#[unsafe(no_mangle)]
361pub unsafe extern "C" fn JS_IsArrayBuffer(obj: JsValue) -> Bool {
362 match unsafe { arg(obj) } {
363 Some(Value::Object(object)) => c_int::from(object.array_buffer_storage().is_some()),
364 _ => 0,
365 }
366}
367
368#[unsafe(no_mangle)]
374pub unsafe extern "C" fn JS_IsInstanceOf(ctx: *mut JsContext, val: JsValue, obj: JsValue) -> c_int {
375 let Some(context) = (unsafe { ctx.as_ref() }) else {
376 return -1;
377 };
378 let Some(value) = (unsafe { arg(val) }) else {
379 runtime::throw_error(context, "TypeError", "not a value");
380 return -1;
381 };
382 let Some(target) = (unsafe { arg(obj) }) else {
383 runtime::throw_error(context, "TypeError", "not a value");
384 return -1;
385 };
386 let result = context.with_current_interp(|interp| {
387 let answer = interp.instance_of_operator(&value, &target)?;
388 Ok(c_int::from(answer))
389 });
390 match result {
391 Ok(answer) => answer,
392 Err(signal) => {
393 let _ = runtime::result_value(context, Err(signal));
394 -1
395 }
396 }
397}
398
399#[unsafe(no_mangle)]
405pub unsafe extern "C" fn JS_OrdinaryIsInstanceOf(
406 ctx: *mut JsContext,
407 val: JsValue,
408 obj: JsValue,
409) -> c_int {
410 let Some(context) = (unsafe { ctx.as_ref() }) else {
411 return -1;
412 };
413 let Some(value) = (unsafe { arg(val) }) else {
414 return runtime::throw_error(context, "TypeError", "not a value").int_answer(context);
415 };
416 let Some(target) = (unsafe { arg(obj) }) else {
417 return runtime::throw_error(context, "TypeError", "not a value").int_answer(context);
418 };
419 let result = context.with_current_interp(|interp| {
420 let answer = interp.ordinary_instance_of(&value, &target)?;
421 Ok(c_int::from(answer))
422 });
423 match result {
424 Ok(answer) => answer,
425 Err(signal) => {
426 let _ = runtime::result_value(context, Err(signal));
427 -1
428 }
429 }
430}
431
432#[unsafe(no_mangle)]
441pub unsafe extern "C" fn JS_IsImmutableArrayBuffer(_obj: JsValue) -> c_int {
442 0
443}
444
445#[unsafe(no_mangle)]
451pub unsafe extern "C" fn JS_SetImmutableArrayBuffer(_obj: JsValue, _immutable: Bool) -> c_int {
452 -1
455}
456
457#[unsafe(no_mangle)]
467pub unsafe extern "C" fn JS_IsLiveObject(_rt: *mut JsRuntime, obj: JsValue) -> Bool {
468 c_int::from(unsafe { arg(obj) }.is_some())
469}
470
471#[unsafe(no_mangle)]
481pub unsafe extern "C" fn JS_IsJobPending(rt: *mut JsRuntime) -> Bool {
482 let Some(runtime) = (unsafe { rt.as_ref() }) else {
483 return 0;
484 };
485 for context in runtime.live_contexts() {
486 let Some(context) = (unsafe { context.as_ref() }) else {
488 continue;
489 };
490 if context.with_current_interp(|interp| interp.has_pending_timers_or_jobs()) {
491 return 1;
492 }
493 }
494 0
495}
496
497#[unsafe(no_mangle)]
507pub unsafe extern "C" fn JS_EnqueueJob(
508 ctx: *mut JsContext,
509 job_func: crate::cdefs::JobFunc,
510 argc: c_int,
511 argv: *const JsValue,
512) -> c_int {
513 let Some(context) = (unsafe { ctx.as_ref() }) else {
514 return -1;
515 };
516 let Some(job_func) = job_func else {
517 runtime::throw_error(context, "TypeError", "null job");
518 return -1;
519 };
520 let args = unsafe { decode_args(argc, argv) };
522 let result = context.with_current_interp(|interp| {
523 let context_pointer = context as *const JsContext as usize;
526 let body: engine::object::HostFn = Box::new(move |_interp, _this, _args| {
527 let this_value = jsvalue::UNDEFINED;
528 let arguments: Vec<JsValue> = args.iter().map(|v| jsvalue_of(v.clone())).collect();
529 let argc = c_int::try_from(arguments.len()).unwrap_or(c_int::MAX);
530 let answer = unsafe {
532 let call: unsafe extern "C" fn(*mut JsContext, c_int, *const JsValue) -> JsValue =
533 job_func;
534 call(context_pointer as *mut JsContext, argc, arguments.as_ptr())
535 };
536 let _ = this_value;
537 match unsafe { arg(answer) } {
538 Some(value) => {
539 unsafe { runtime::release(answer) };
541 Ok(value)
542 }
543 None => Ok(Value::Undefined),
544 }
545 });
546 let function = interp.new_host_function("job", 0, body);
547 interp.enqueue_job_function(Value::Object(function))?;
548 Ok(Value::Undefined)
549 });
550 match result {
551 Ok(_) => 0,
552 Err(signal) => {
553 let _ = runtime::result_value(context, Err(signal));
554 -1
555 }
556 }
557}
558
559#[unsafe(no_mangle)]
565pub unsafe extern "C" fn JS_ExecutePendingJob(
566 rt: *mut JsRuntime,
567 pctx: *mut *mut JsContext,
568) -> c_int {
569 let Some(runtime) = (unsafe { rt.as_ref() }) else {
570 return -1;
571 };
572 let contexts: Vec<*mut JsContext> = runtime.live_contexts();
573 for context in contexts {
574 let Some(context_ref) = (unsafe { context.as_ref() }) else {
576 continue;
577 };
578 let pending = context_ref.with_current_interp(|interp| interp.has_pending_timers_or_jobs());
581 if !pending {
582 continue;
583 }
584 let ran = context_ref.with_current_interp(|interp| interp.drain_jobs().is_ok());
585 if ran {
586 if !pctx.is_null() {
587 unsafe { *pctx = context };
589 }
590 return 1;
591 }
592 }
593 0
594}
595
596trait IntAnswer {
602 fn int_answer(self, context: &JsContext) -> c_int;
604}
605
606impl IntAnswer for JsValue {
607 fn int_answer(self, _context: &JsContext) -> c_int {
608 -1
609 }
610}
611
612#[unsafe(no_mangle)]
618pub unsafe extern "C" fn JS_CreateFromConstructor(
619 ctx: *mut JsContext,
620 ctor: JsValue,
621 _class_id: c_int,
622) -> JsValue {
623 let Some(context) = (unsafe { ctx.as_ref() }) else {
624 return jsvalue::EXCEPTION;
625 };
626 let Some(callee) = (unsafe { arg(ctor) }) else {
627 return runtime::throw_error(context, "TypeError", "not a constructor");
628 };
629 let result = context.with_current_interp(|interp| {
630 let object = match &callee {
631 Value::Object(object) => object.clone(),
632 _ => {
633 return Err(engine::Signal::Throw(
634 interp.make_error("TypeError", "not a constructor"),
635 ));
636 }
637 };
638 let proto = interp.prototype_of(&object);
639 Ok(Value::Object(interp.new_object(Some(proto))))
640 });
641 runtime::result_value(context, result)
642}
643
644#[unsafe(no_mangle)]
656pub unsafe extern "C" fn JS_NewCConstructor(
657 ctx: *mut JsContext,
658 class_id: c_int,
659 name: *const core::ffi::c_char,
660 func: crate::cdefs::RawFunction,
661 length: c_int,
662 cproto: c_int,
663 magic: c_int,
664 parent_ctor: JsValue,
665 ctor_fields: *const crate::cdefs::JSCFunctionListEntry,
666 n_ctor_fields: c_int,
667 proto_fields: *const crate::cdefs::JSCFunctionListEntry,
668 n_proto_fields: c_int,
669 _flags: c_int,
670) -> JsValue {
671 let Some(context) = (unsafe { ctx.as_ref() }) else {
672 return jsvalue::EXCEPTION;
673 };
674 let class_name = unsafe { c_text(name) };
676 let constructor =
679 unsafe { crate::objects::JS_NewCFunction2(ctx, func, name, length, cproto, magic) };
680 if constructor.is_exception() {
681 return constructor;
682 }
683 let prototype = context.with_current_interp(|interp| {
684 let parent = if parent_ctor.is_null() {
685 None
686 } else {
687 match unsafe { arg(parent_ctor) } {
688 Some(Value::Object(object)) => Some(object),
689 _ => None,
690 }
691 };
692 let proto = interp.new_object(parent);
693 jsvalue_of(Value::Object(proto))
694 });
695 if !ctor_fields.is_null() && n_ctor_fields > 0 {
697 unsafe {
699 crate::objects::JS_SetPropertyFunctionList(
700 ctx,
701 constructor,
702 ctor_fields,
703 n_ctor_fields,
704 );
705 }
706 }
707 if !proto_fields.is_null() && n_proto_fields > 0 {
708 unsafe {
710 crate::objects::JS_SetPropertyFunctionList(
711 ctx,
712 prototype,
713 proto_fields,
714 n_proto_fields,
715 );
716 }
717 }
718 unsafe {
720 crate::objects::JS_SetConstructor(ctx, constructor, prototype);
721 }
722 let _ = (class_id, class_name, CFunctionEnum::from_raw(cproto as u8));
723 constructor
724}
725
726#[unsafe(no_mangle)]
732pub unsafe extern "C" fn JS_GetIterator(
733 ctx: *mut JsContext,
734 obj: JsValue,
735 is_async: Bool,
736) -> JsValue {
737 let Some(context) = (unsafe { ctx.as_ref() }) else {
738 return jsvalue::EXCEPTION;
739 };
740 let Some(value) = (unsafe { arg(obj) }) else {
741 return runtime::throw_error(context, "TypeError", "not a value");
742 };
743 let result = context.with_current_interp(|interp| {
744 let key = interp.realm.well_known_key(if is_async != 0 {
746 engine::interp::WellKnown::AsyncIterator
747 } else {
748 engine::interp::WellKnown::Iterator
749 });
750 let method = interp.read_field_key(&value, &key)?;
751 interp.call_value(method, value, Vec::new())
752 });
753 runtime::result_value(context, result)
754}
755
756#[unsafe(no_mangle)]
762pub unsafe extern "C" fn JS_IteratorNext(
763 ctx: *mut JsContext,
764 enum_obj: JsValue,
765 method: JsValue,
766 pdone: *mut Bool,
767) -> JsValue {
768 let Some(context) = (unsafe { ctx.as_ref() }) else {
769 return jsvalue::EXCEPTION;
770 };
771 let Some(iterator) = (unsafe { arg(enum_obj) }) else {
772 return runtime::throw_error(context, "TypeError", "not a value");
773 };
774 let step = unsafe { arg(method) }.unwrap_or(Value::Undefined);
775 let result = context.with_current_interp(|interp| {
776 let step = if matches!(step, Value::Undefined) {
777 interp.read_field(&iterator, "next")?
778 } else {
779 step
780 };
781 let answer = interp.call_value(step, iterator, Vec::new())?;
782 let done = interp.read_field(&answer, "done")?.to_boolean();
784 if !pdone.is_null() {
785 unsafe { *pdone = c_int::from(done) };
787 }
788 interp.read_field(&answer, "value")
789 });
790 runtime::result_value(context, result)
791}
792
793#[unsafe(no_mangle)]
799pub unsafe extern "C" fn JS_IteratorClose(
800 ctx: *mut JsContext,
801 enum_obj: JsValue,
802 is_exception_pending: Bool,
803) -> c_int {
804 let Some(context) = (unsafe { ctx.as_ref() }) else {
805 return -1;
806 };
807 let Some(iterator) = (unsafe { arg(enum_obj) }) else {
808 runtime::throw_error(context, "TypeError", "not a value");
809 return -1;
810 };
811 let result = context.with_current_interp(|interp| {
812 let value = interp.read_field(&iterator, "return")?;
813 if matches!(value, Value::Undefined | Value::Null) {
816 return Ok(());
817 }
818 match interp.call_value(value, iterator, Vec::new()) {
819 Ok(_) => Ok(()),
820 Err(_) if is_exception_pending != 0 => Ok(()),
824 Err(signal) => Err(signal),
825 }
826 });
827 match result {
828 Ok(()) => 0,
829 Err(signal) => {
830 let _ = runtime::result_value(context, Err(signal));
831 -1
832 }
833 }
834}
835
836#[unsafe(no_mangle)]
842pub unsafe extern "C" fn JS_NewPromiseCapability(
843 ctx: *mut JsContext,
844 resolving_funcs: *mut JsValue,
845) -> JsValue {
846 let Some(context) = (unsafe { ctx.as_ref() }) else {
847 return jsvalue::EXCEPTION;
848 };
849 context.with_current_interp(|interp| {
850 let (promise, resolve, reject) = interp.new_promise_capability();
851 if !resolving_funcs.is_null() {
852 unsafe {
854 resolving_funcs.write(jsvalue_of(resolve));
855 resolving_funcs.add(1).write(jsvalue_of(reject));
856 }
857 }
858 jsvalue_of(Value::Object(promise))
859 })
860}
861
862#[unsafe(no_mangle)]
871pub unsafe extern "C" fn JS_PromiseState(ctx: *mut JsContext, promise: JsValue) -> c_int {
872 let Some(context) = (unsafe { ctx.as_ref() }) else {
873 return 2;
874 };
875 let Some(Value::Object(object)) = (unsafe { arg(promise) }) else {
876 return 2;
877 };
878 context.with_current_interp(|interp| match interp.promise_state(&object) {
879 Some(state) => {
880 let state = state.borrow();
881 match &state.status {
882 engine::object::PromiseStatus::Pending => 0,
883 engine::object::PromiseStatus::Fulfilled(_) => 1,
884 engine::object::PromiseStatus::Rejected(_) => 2,
885 }
886 }
887 None => 2,
888 })
889}
890
891#[unsafe(no_mangle)]
897pub unsafe extern "C" fn JS_PromiseResult(ctx: *mut JsContext, promise: JsValue) -> JsValue {
898 let Some(context) = (unsafe { ctx.as_ref() }) else {
899 return jsvalue::EXCEPTION;
900 };
901 let Some(Value::Object(object)) = (unsafe { arg(promise) }) else {
902 return runtime::throw_error(context, "TypeError", "not a promise");
903 };
904 let result = context.with_current_interp(|interp| match interp.promise_state(&object) {
905 Some(state) => {
906 let state = state.borrow();
907 match &state.status {
908 engine::object::PromiseStatus::Pending => Ok(Value::Undefined),
909 engine::object::PromiseStatus::Fulfilled(value)
910 | engine::object::PromiseStatus::Rejected(value) => Ok(value.clone()),
911 }
912 }
913 None => Err(engine::Signal::Throw(
914 interp.make_error("TypeError", "not a promise"),
915 )),
916 });
917 runtime::result_value(context, result)
918}
919
920#[unsafe(no_mangle)]
931pub unsafe extern "C" fn JS_SetHostPromiseRejectionTracker(
932 _rt: *mut JsRuntime,
933 _cb: *const c_void,
934 _opaque: *mut c_void,
935) {
936}
937
938#[unsafe(no_mangle)]
944pub unsafe extern "C" fn JS_EvalFunction(ctx: *mut JsContext, fun_obj: JsValue) -> JsValue {
945 let Some(context) = (unsafe { ctx.as_ref() }) else {
946 return jsvalue::EXCEPTION;
947 };
948 let Some(callee) = (unsafe { arg(fun_obj) }) else {
949 return runtime::throw_error(context, "TypeError", "not a function");
950 };
951 let result = context.with_current_interp(|interp| {
952 interp.call_value(callee, Value::Undefined, Vec::new())
957 });
958 runtime::result_value(context, result)
959}
960
961#[unsafe(no_mangle)]
969pub unsafe extern "C" fn JS_GetAnyOpaque(obj: JsValue, class_id: *mut u32) -> *mut c_void {
970 match unsafe { arg(obj) } {
971 Some(Value::Object(object)) => {
972 let id: u32 = object.host_class_id().map(|id| id.get()).unwrap_or(0);
973 if !class_id.is_null() {
974 unsafe { *class_id = id };
976 }
977 object
978 .host_opaque()
979 .map(|opaque| opaque.as_ptr())
980 .unwrap_or(std::ptr::null_mut())
981 .cast()
982 }
983 _ => {
984 if !class_id.is_null() {
985 unsafe { *class_id = 0 };
987 }
988 std::ptr::null_mut()
989 }
990 }
991}
992
993const _: Option<JSClassDef> = None;
996
997const _: Option<Hint> = None;