Skip to content

Commit

Permalink
Fix conversions
Browse files Browse the repository at this point in the history
  • Loading branch information
richarddavison committed Jan 22, 2025
1 parent fa53748 commit 9d1dfb3
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 47 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 {
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<bool, *mut qjs::JSContext> {
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 {
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.
Expand All @@ -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
Expand Down
8 changes: 6 additions & 2 deletions core/src/value/function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
)
};
}

Expand Down
91 changes: 50 additions & 41 deletions sys/src/bindings/aarch64-apple-darwin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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]
Expand Down Expand Up @@ -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;
Expand All @@ -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);
Expand Down Expand Up @@ -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" {
Expand All @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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" {
Expand All @@ -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;
Expand Down Expand Up @@ -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" {
Expand Down Expand Up @@ -1899,21 +1908,21 @@ 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<
unsafe extern "C" fn(
ctx: *mut JSContext,
promise: JSValue,
reason: JSValue,
is_handled: ::std::os::raw::c_int,
is_handled: bool,
opaque: *mut ::std::os::raw::c_void,
),
>;
Expand All @@ -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);
Expand Down Expand Up @@ -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(
Expand Down

0 comments on commit 9d1dfb3

Please sign in to comment.