From 9d1dfb3b440e93c19d5afd3f2720970356bc4794 Mon Sep 17 00:00:00 2001 From: Richard Davison Date: Wed, 22 Jan 2025 10:29:59 +0100 Subject: [PATCH] Fix conversions --- core/src/runtime/raw.rs | 2 +- core/src/value.rs | 6 +- core/src/value/function.rs | 8 ++- sys/src/bindings/aarch64-apple-darwin.rs | 91 +++++++++++++----------- 4 files changed, 60 insertions(+), 47 deletions(-) diff --git a/core/src/runtime/raw.rs b/core/src/runtime/raw.rs index 22be1b89..de5f7c3a 100644 --- a/core/src/runtime/raw.rs +++ b/core/src/runtime/raw.rs @@ -210,7 +210,7 @@ impl RawRuntime { } pub fn is_job_pending(&self) -> bool { - unsafe { qjs::JS_IsJobPending(self.rt.as_ptr()) } + (unsafe { qjs::JS_IsJobPending(self.rt.as_ptr()) }).into() } pub fn execute_pending_job(&mut self) -> StdResult { diff --git a/core/src/value.rs b/core/src/value.rs index 9a31c5ca..e7be548a 100644 --- a/core/src/value.rs +++ b/core/src/value.rs @@ -352,13 +352,13 @@ impl<'js> Value<'js> { /// Check if the value is a function #[inline] pub fn is_function(&self) -> bool { - unsafe { qjs::JS_IsFunction(self.ctx.as_ptr(), self.value) } + (unsafe { qjs::JS_IsFunction(self.ctx.as_ptr(), self.value) }).into() } /// Check if the value is a constructor function #[inline] pub fn is_constructor(&self) -> bool { - unsafe { qjs::JS_IsConstructor(self.ctx.as_ptr(), self.value) } + (unsafe { qjs::JS_IsConstructor(self.ctx.as_ptr(), self.value) }).into() } /// Check if the value is a promise. @@ -376,7 +376,7 @@ impl<'js> Value<'js> { /// Check if the value is an error #[inline] pub fn is_error(&self) -> bool { - unsafe { qjs::JS_IsError(self.ctx.as_ptr(), self.value) } + (unsafe { qjs::JS_IsError(self.ctx.as_ptr(), self.value) }).into() } /// Reference as value diff --git a/core/src/value/function.rs b/core/src/value/function.rs index d332e74d..bb456422 100644 --- a/core/src/value/function.rs +++ b/core/src/value/function.rs @@ -161,13 +161,17 @@ impl<'js> Function<'js> { /// Returns whether this function is an constructor. pub fn is_constructor(&self) -> bool { - unsafe { qjs::JS_IsConstructor(self.ctx().as_ptr(), self.0.as_js_value()) } + (unsafe { qjs::JS_IsConstructor(self.ctx().as_ptr(), self.0.as_js_value()) }).into() } /// Set whether this function is a constructor or not. pub fn set_constructor(&self, is_constructor: bool) { unsafe { - qjs::JS_SetConstructorBit(self.ctx().as_ptr(), self.0.as_js_value(), is_constructor) + qjs::JS_SetConstructorBit( + self.ctx().as_ptr(), + self.0.as_js_value(), + is_constructor.into(), + ) }; } diff --git a/sys/src/bindings/aarch64-apple-darwin.rs b/sys/src/bindings/aarch64-apple-darwin.rs index f02f35b5..29585bfe 100644 --- a/sys/src/bindings/aarch64-apple-darwin.rs +++ b/sys/src/bindings/aarch64-apple-darwin.rs @@ -34,6 +34,25 @@ pub const JS_EVAL_FLAG_UNUSED: u32 = 16; pub const JS_EVAL_FLAG_COMPILE_ONLY: u32 = 32; pub const JS_EVAL_FLAG_BACKTRACE_BARRIER: u32 = 64; pub const JS_EVAL_FLAG_ASYNC: u32 = 128; +pub const JS_DUMP_BYTECODE_FINAL: u32 = 1; +pub const JS_DUMP_BYTECODE_PASS2: u32 = 2; +pub const JS_DUMP_BYTECODE_PASS1: u32 = 4; +pub const JS_DUMP_BYTECODE_HEX: u32 = 16; +pub const JS_DUMP_BYTECODE_PC2LINE: u32 = 32; +pub const JS_DUMP_BYTECODE_STACK: u32 = 64; +pub const JS_DUMP_BYTECODE_STEP: u32 = 128; +pub const JS_DUMP_READ_OBJECT: u32 = 256; +pub const JS_DUMP_FREE: u32 = 512; +pub const JS_DUMP_GC: u32 = 1024; +pub const JS_DUMP_GC_FREE: u32 = 2048; +pub const JS_DUMP_MODULE_RESOLVE: u32 = 4096; +pub const JS_DUMP_PROMISE: u32 = 8192; +pub const JS_DUMP_LEAKS: u32 = 16384; +pub const JS_DUMP_ATOM_LEAKS: u32 = 32768; +pub const JS_DUMP_MEM: u32 = 65536; +pub const JS_DUMP_OBJECTS: u32 = 131072; +pub const JS_DUMP_ATOMS: u32 = 262144; +pub const JS_DUMP_SHAPES: u32 = 524288; pub const JS_ATOM_NULL: u32 = 0; pub const JS_CALL_FLAG_CONSTRUCTOR: u32 = 1; pub const JS_INVALID_CLASS_ID: u32 = 0; @@ -336,6 +355,9 @@ extern "C" { extern "C" { pub fn JS_SetDumpFlags(rt: *mut JSRuntime, flags: u64); } +extern "C" { + pub fn JS_GetDumpFlags(rt: *mut JSRuntime) -> u64; +} extern "C" { pub fn JS_GetGCThreshold(rt: *mut JSRuntime) -> size_t; } @@ -379,7 +401,7 @@ extern "C" { pub fn JS_RunGC(rt: *mut JSRuntime); } extern "C" { - pub fn JS_IsLiveObject(rt: *mut JSRuntime, obj: JSValue) -> ::std::os::raw::c_int; + pub fn JS_IsLiveObject(rt: *mut JSRuntime, obj: JSValue) -> bool; } extern "C" { pub fn JS_NewContext(rt: *mut JSRuntime) -> *mut JSContext; @@ -454,22 +476,13 @@ extern "C" { pub fn JS_IsEqual(ctx: *mut JSContext, op1: JSValue, op2: JSValue) -> ::std::os::raw::c_int; } extern "C" { - pub fn JS_IsStrictEqual( - ctx: *mut JSContext, - op1: JSValue, - op2: JSValue, - ) -> ::std::os::raw::c_int; + pub fn JS_IsStrictEqual(ctx: *mut JSContext, op1: JSValue, op2: JSValue) -> bool; } extern "C" { - pub fn JS_IsSameValue(ctx: *mut JSContext, op1: JSValue, op2: JSValue) - -> ::std::os::raw::c_int; + pub fn JS_IsSameValue(ctx: *mut JSContext, op1: JSValue, op2: JSValue) -> bool; } extern "C" { - pub fn JS_IsSameValueZero( - ctx: *mut JSContext, - op1: JSValue, - op2: JSValue, - ) -> ::std::os::raw::c_int; + pub fn JS_IsSameValueZero(ctx: *mut JSContext, op1: JSValue, op2: JSValue) -> bool; } extern "C" { pub fn js_string_codePointRange( @@ -901,7 +914,7 @@ extern "C" { #[repr(C)] #[derive(Debug, Copy, Clone)] pub struct JSPropertyEnum { - pub is_enumerable: ::std::os::raw::c_int, + pub is_enumerable: bool, pub atom: JSAtom, } #[test] @@ -1253,7 +1266,7 @@ extern "C" { ) -> ::std::os::raw::c_int; } extern "C" { - pub fn JS_IsRegisteredClass(rt: *mut JSRuntime, class_id: JSClassID) -> ::std::os::raw::c_int; + pub fn JS_IsRegisteredClass(rt: *mut JSRuntime, class_id: JSClassID) -> bool; } extern "C" { pub fn JS_NewNumber(ctx: *mut JSContext, d: f64) -> JSValue; @@ -1271,13 +1284,13 @@ extern "C" { pub fn JS_GetException(ctx: *mut JSContext) -> JSValue; } extern "C" { - pub fn JS_HasException(ctx: *mut JSContext) -> ::std::os::raw::c_int; + pub fn JS_HasException(ctx: *mut JSContext) -> bool; } extern "C" { - pub fn JS_IsError(ctx: *mut JSContext, val: JSValue) -> ::std::os::raw::c_int; + pub fn JS_IsError(ctx: *mut JSContext, val: JSValue) -> bool; } extern "C" { - pub fn JS_IsUncatchableError(ctx: *mut JSContext, val: JSValue) -> ::std::os::raw::c_int; + pub fn JS_IsUncatchableError(ctx: *mut JSContext, val: JSValue) -> bool; } extern "C" { pub fn JS_SetUncatchableError(ctx: *mut JSContext, val: JSValue); @@ -1409,7 +1422,7 @@ extern "C" { ctx: *mut JSContext, plen: *mut size_t, val1: JSValue, - cesu8: ::std::os::raw::c_int, + cesu8: bool, ) -> *const ::std::os::raw::c_char; } extern "C" { @@ -1435,23 +1448,22 @@ extern "C" { pub fn JS_ToObject(ctx: *mut JSContext, val: JSValue) -> JSValue; } extern "C" { - pub fn JS_IsFunction(ctx: *mut JSContext, val: JSValue) -> ::std::os::raw::c_int; + pub fn JS_ToObjectString(ctx: *mut JSContext, val: JSValue) -> JSValue; } extern "C" { - pub fn JS_IsConstructor(ctx: *mut JSContext, val: JSValue) -> ::std::os::raw::c_int; + pub fn JS_IsFunction(ctx: *mut JSContext, val: JSValue) -> bool; } extern "C" { - pub fn JS_SetConstructorBit( - ctx: *mut JSContext, - func_obj: JSValue, - val: ::std::os::raw::c_int, - ) -> ::std::os::raw::c_int; + pub fn JS_IsConstructor(ctx: *mut JSContext, val: JSValue) -> bool; +} +extern "C" { + pub fn JS_SetConstructorBit(ctx: *mut JSContext, func_obj: JSValue, val: bool) -> bool; } extern "C" { - pub fn JS_IsRegExp(val: JSValue) -> ::std::os::raw::c_int; + pub fn JS_IsRegExp(val: JSValue) -> bool; } extern "C" { - pub fn JS_IsMap(val: JSValue) -> ::std::os::raw::c_int; + pub fn JS_IsMap(val: JSValue) -> bool; } extern "C" { pub fn JS_NewArray(ctx: *mut JSContext) -> JSValue; @@ -1463,7 +1475,7 @@ extern "C" { pub fn JS_NewDate(ctx: *mut JSContext, epoch_ms: f64) -> JSValue; } extern "C" { - pub fn JS_IsDate(v: JSValue) -> ::std::os::raw::c_int; + pub fn JS_IsDate(v: JSValue) -> bool; } extern "C" { pub fn JS_GetProperty(ctx: *mut JSContext, this_obj: JSValue, prop: JSAtom) -> JSValue; @@ -1613,10 +1625,7 @@ extern "C" { ) -> JSValue; } extern "C" { - pub fn JS_DetectModule( - input: *const ::std::os::raw::c_char, - input_len: size_t, - ) -> ::std::os::raw::c_int; + pub fn JS_DetectModule(input: *const ::std::os::raw::c_char, input_len: size_t) -> bool; } extern "C" { pub fn JS_Eval( @@ -1742,7 +1751,7 @@ extern "C" { len: size_t, free_func: JSFreeArrayBufferDataFunc, opaque: *mut ::std::os::raw::c_void, - is_shared: ::std::os::raw::c_int, + is_shared: bool, ) -> JSValue; } extern "C" { @@ -1755,7 +1764,7 @@ extern "C" { pub fn JS_GetArrayBuffer(ctx: *mut JSContext, psize: *mut size_t, obj: JSValue) -> *mut u8; } extern "C" { - pub fn JS_IsArrayBuffer(obj: JSValue) -> ::std::os::raw::c_int; + pub fn JS_IsArrayBuffer(obj: JSValue) -> bool; } extern "C" { pub fn JS_GetUint8Array(ctx: *mut JSContext, psize: *mut size_t, obj: JSValue) -> *mut u8; @@ -1797,7 +1806,7 @@ extern "C" { len: size_t, free_func: JSFreeArrayBufferDataFunc, opaque: *mut ::std::os::raw::c_void, - is_shared: ::std::os::raw::c_int, + is_shared: bool, ) -> JSValue; } extern "C" { @@ -1899,13 +1908,13 @@ extern "C" { pub fn JS_PromiseResult(ctx: *mut JSContext, promise: JSValue) -> JSValue; } extern "C" { - pub fn JS_IsPromise(val: JSValue) -> ::std::os::raw::c_int; + pub fn JS_IsPromise(val: JSValue) -> bool; } extern "C" { pub fn JS_NewSymbol( ctx: *mut JSContext, description: *const ::std::os::raw::c_char, - is_global: ::std::os::raw::c_int, + is_global: bool, ) -> JSValue; } pub type JSHostPromiseRejectionTracker = ::std::option::Option< @@ -1913,7 +1922,7 @@ pub type JSHostPromiseRejectionTracker = ::std::option::Option< ctx: *mut JSContext, promise: JSValue, reason: JSValue, - is_handled: ::std::os::raw::c_int, + is_handled: bool, opaque: *mut ::std::os::raw::c_void, ), >; @@ -1938,7 +1947,7 @@ extern "C" { ); } extern "C" { - pub fn JS_SetCanBlock(rt: *mut JSRuntime, can_block: ::std::os::raw::c_int); + pub fn JS_SetCanBlock(rt: *mut JSRuntime, can_block: bool); } extern "C" { pub fn JS_SetIsHTMLDDA(ctx: *mut JSContext, obj: JSValue); @@ -1996,7 +2005,7 @@ extern "C" { ) -> ::std::os::raw::c_int; } extern "C" { - pub fn JS_IsJobPending(rt: *mut JSRuntime) -> ::std::os::raw::c_int; + pub fn JS_IsJobPending(rt: *mut JSRuntime) -> bool; } extern "C" { pub fn JS_ExecutePendingJob(