Skip to content

Commit

Permalink
Fix binding issue
Browse files Browse the repository at this point in the history
  • Loading branch information
richarddavison committed Jan 21, 2025
1 parent 0473e65 commit 1cc3eb3
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 21 deletions.
2 changes: 1 addition & 1 deletion core/src/runtime/raw.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()) }
}

pub fn execute_pending_job(&mut self) -> StdResult<bool, *mut qjs::JSContext> {
Expand Down
12 changes: 6 additions & 6 deletions core/src/runtime/userdata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<T>(),
Expand Down Expand Up @@ -40,9 +40,9 @@ where
)
}

unsafe fn from_static_box<'js, T: JsLifetime<'js>>(this: Box<T::Changed<'static>>) -> Box<T>
unsafe fn from_static_box<'js, T>(this: Box<T::Changed<'static>>) -> Box<T>
where
T: Sized,
T: JsLifetime<'js> + Sized,
{
assert_eq!(
std::mem::size_of::<T>(),
Expand All @@ -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)
}
Expand Down
6 changes: 3 additions & 3 deletions core/src/value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) }
}

/// 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) }
}

/// Check if the value is a promise.
Expand All @@ -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) }
}

/// Reference as value
Expand Down
2 changes: 1 addition & 1 deletion core/src/value/array_buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ impl<'js> ArrayBuffer<'js> {
size as _,
Some(drop_raw::<T>),
capacity as _,
0,
false,
);
ctx.handle_exception(val).inspect_err(|_| {
// don't forget to free data when error occurred
Expand Down
9 changes: 2 additions & 7 deletions core/src/value/function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,18 +161,13 @@ 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()) }
}

/// 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 as i32,
)
qjs::JS_SetConstructorBit(self.ctx().as_ptr(), self.0.as_js_value(), is_constructor)
};
}

Expand Down
5 changes: 2 additions & 3 deletions sys/src/inlines/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -83,15 +82,15 @@ 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)
}
#[inline]
pub unsafe fn JS_ToCStringLen(
ctx: *mut JSContext,
plen: *mut usize,
val: JSValue,
) -> *const c_char {
JS_ToCStringLen2(ctx, plen as _, val, 0)
JS_ToCStringLen2(ctx, plen as _, val, false)
}

#[inline]
Expand Down

0 comments on commit 1cc3eb3

Please sign in to comment.