diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 381de565..d9611790 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -101,7 +101,7 @@ jobs: # https://docs.github.com/en/actions/learn-github-actions/contexts#context-availability strategy: matrix: - msrv: [1.65.0] # 1.65.0 introduced GAT stabilization + msrv: [1.81.0] # 'home' crate requires 1.81.0 name: ubuntu / ${{ matrix.msrv }} steps: - uses: actions/checkout@v4 @@ -112,7 +112,7 @@ jobs: with: toolchain: ${{ matrix.msrv }} - name: cargo +${{ matrix.msrv }} check - run: cargo check + run: cargo +${{ matrix.msrv }} check --features full-async,bindgen coverage: runs-on: ubuntu-latest diff --git a/.gitignore b/.gitignore index d0967c52..1136c009 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,4 @@ target .ccls-cache -Cargo.lock .gdb_history +Cargo.lock diff --git a/Cargo.toml b/Cargo.toml index 6f0f6926..30f46721 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -3,7 +3,7 @@ name = "rquickjs" version = "0.8.1" authors = ["Mees Delzenne ", "K. "] edition = "2021" -rust-version = "1.65" +rust-version = "1.81" license = "MIT" readme = "README.md" description = "High level bindings to the QuickJS JavaScript engine" diff --git a/core/src/runtime/raw.rs b/core/src/runtime/raw.rs index da6ca9ab..2c9bacc2 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 { - 0 != unsafe { qjs::JS_IsJobPending(self.rt.as_ptr()) } + (unsafe { qjs::JS_IsJobPending(self.rt.as_ptr()) } as i32) != 0 } pub fn execute_pending_job(&mut self) -> StdResult { diff --git a/core/src/runtime/userdata.rs b/core/src/runtime/userdata.rs index 34283299..56667caa 100644 --- a/core/src/runtime/userdata.rs +++ b/core/src/runtime/userdata.rs @@ -10,9 +10,9 @@ use std::{ use crate::JsLifetime; -unsafe fn to_static<'js, T: JsLifetime<'js>>(this: T) -> T::Changed<'static> +unsafe fn to_static<'js, T>(this: T) -> T::Changed<'static> where - T: Sized, + T: JsLifetime<'js> + Sized, { assert_eq!( std::mem::size_of::(), @@ -40,9 +40,9 @@ where ) } -unsafe fn from_static_box<'js, T: JsLifetime<'js>>(this: Box>) -> Box +unsafe fn from_static_box<'js, T>(this: Box>) -> Box where - T: Sized, + T: JsLifetime<'js> + Sized, { assert_eq!( std::mem::size_of::(), @@ -58,9 +58,9 @@ where Box::from_raw(Box::into_raw(this) as *mut T) } -unsafe fn from_static_ref<'a, 'js, T: JsLifetime<'js>>(this: &'a T::Changed<'static>) -> &'a T +unsafe fn from_static_ref<'a, 'js, T>(this: &'a T::Changed<'static>) -> &'a T where - T: Sized, + T: JsLifetime<'js> + Sized, { std::mem::transmute(this) } diff --git a/core/src/value.rs b/core/src/value.rs index 5f332bc7..0a94ea22 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 { - 0 != unsafe { qjs::JS_IsFunction(self.ctx.as_ptr(), self.value) } + (unsafe { qjs::JS_IsFunction(self.ctx.as_ptr(), self.value) } as i32) != 0 } /// Check if the value is a constructor function #[inline] pub fn is_constructor(&self) -> bool { - 0 != unsafe { qjs::JS_IsConstructor(self.ctx.as_ptr(), self.value) } + (unsafe { qjs::JS_IsConstructor(self.ctx.as_ptr(), self.value) } as i32) != 0 } /// 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 { - 0 != unsafe { qjs::JS_IsError(self.ctx.as_ptr(), self.value) } + (unsafe { qjs::JS_IsError(self.ctx.as_ptr(), self.value) } as i32) != 0 } /// Reference as value diff --git a/core/src/value/array_buffer.rs b/core/src/value/array_buffer.rs index 0a6f77ab..0dfc9006 100644 --- a/core/src/value/array_buffer.rs +++ b/core/src/value/array_buffer.rs @@ -67,7 +67,7 @@ impl<'js> ArrayBuffer<'js> { size as _, Some(drop_raw::), capacity as _, - 0, + false, ); ctx.handle_exception(val).inspect_err(|_| { // don't forget to free data when error occurred diff --git a/core/src/value/function.rs b/core/src/value/function.rs index 20a7662b..a78b2f5a 100644 --- a/core/src/value/function.rs +++ b/core/src/value/function.rs @@ -161,8 +161,7 @@ impl<'js> Function<'js> { /// Returns whether this function is an constructor. pub fn is_constructor(&self) -> bool { - let res = unsafe { qjs::JS_IsConstructor(self.ctx().as_ptr(), self.0.as_js_value()) }; - res != 0 + ((unsafe { qjs::JS_IsConstructor(self.ctx().as_ptr(), self.0.as_js_value()) }) as i32) != 0 } /// Set whether this function is a constructor or not. @@ -171,7 +170,7 @@ impl<'js> Function<'js> { qjs::JS_SetConstructorBit( self.ctx().as_ptr(), self.0.as_js_value(), - is_constructor as i32, + is_constructor.into(), ) }; } diff --git a/core/src/value/typed_array.rs b/core/src/value/typed_array.rs index ae20ad92..1c584800 100644 --- a/core/src/value/typed_array.rs +++ b/core/src/value/typed_array.rs @@ -324,7 +324,13 @@ impl<'js, T> IntoJs<'js> for TypedArray<'js, T> { impl<'js> Object<'js> { pub fn is_typed_array(&self) -> bool { let array_type = unsafe { qjs::JS_GetTypedArrayType(self.value) }; - T::ARRAY_TYPE == array_type.try_into().unwrap() + if array_type < 0 { + return false; + } + if let Ok(array_type) = TryInto::::try_into(array_type) { + return array_type == T::ARRAY_TYPE; + } + return false; } /// Interpret as [`TypedArray`] @@ -436,4 +442,23 @@ mod test { assert_eq!(val.as_bytes().unwrap(), &res) }); } + + #[test] + fn is_typed_array() { + test_with(|ctx| { + let val: Value = ctx + .eval( + r#" + new Uint32Array([0xCAFEDEAD, 0xFEEDBEAD]) + "#, + ) + .unwrap(); + let obj = val.into_object().unwrap(); + assert!(obj.is_typed_array::()); + assert!(!obj.is_typed_array::()); + + let obj = Object::new(ctx).unwrap(); + assert!(!obj.is_typed_array::()); + }); + } } diff --git a/sys/quickjs b/sys/quickjs index 8bcc0706..ab48ede9 160000 --- a/sys/quickjs +++ b/sys/quickjs @@ -1 +1 @@ -Subproject commit 8bcc070658c04c6bca0e6469d488c00697a1d680 +Subproject commit ab48ede9ea7f793e43d77228b52bcc2e23199aa4 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( diff --git a/sys/src/inlines/common.rs b/sys/src/inlines/common.rs index 70876d53..c8ffbcdd 100644 --- a/sys/src/inlines/common.rs +++ b/sys/src/inlines/common.rs @@ -32,7 +32,6 @@ pub unsafe fn JS_IsBigInt(v: JSValue) -> bool { tag == JS_TAG_BIG_INT } - #[inline] pub unsafe fn JS_IsBool(v: JSValue) -> bool { let tag = JS_VALUE_GET_TAG(v); @@ -83,7 +82,7 @@ pub unsafe fn JS_IsObject(v: JSValue) -> bool { #[inline] pub unsafe fn JS_ToCString(ctx: *mut JSContext, val: JSValue) -> *const c_char { - JS_ToCStringLen2(ctx, ptr::null_mut(), val, 0) + JS_ToCStringLen2(ctx, ptr::null_mut(), val, (false).into()) } #[inline] pub unsafe fn JS_ToCStringLen( @@ -91,7 +90,7 @@ pub unsafe fn JS_ToCStringLen( plen: *mut usize, val: JSValue, ) -> *const c_char { - JS_ToCStringLen2(ctx, plen as _, val, 0) + JS_ToCStringLen2(ctx, plen as _, val, (false).into()) } #[inline]