Skip to content

Commit 2a6f743

Browse files
committed
feat: upgrade quickjs-ng to v0.9.0 and fix compatibility
1 parent d108327 commit 2a6f743

File tree

6 files changed

+33
-32
lines changed

6 files changed

+33
-32
lines changed

examples/catch_promise_rejection.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ unsafe extern "C" fn host_promise_rejection_tracker(
5151
ctx: *mut JSContext,
5252
_promise: RawJSValue,
5353
reason: RawJSValue,
54-
is_handled: c_int,
54+
is_handled: bool,
5555
_opaque: *mut c_void,
5656
) {
5757
let reason = OwnedJsValue::own(ctx, &reason);

libquickjs-sys/embed/extensions.c

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ JSValue JS_Ext_NewBool(JSContext *ctx, uint8_t val)
6262
return JS_NewBool(ctx, val);
6363
}
6464

65-
JS_BOOL JS_Ext_IsNan(JSValue v)
65+
bool JS_Ext_IsNan(JSValue v)
6666
{
6767
return JS_VALUE_IS_NAN(v);
6868
}
@@ -92,12 +92,12 @@ int JS_Ext_GetNormTag(JSValue v)
9292
return JS_VALUE_GET_NORM_TAG(v);
9393
}
9494

95-
JS_BOOL JS_Ext_IsNumber(JSValue v)
95+
bool JS_Ext_IsNumber(JSValue v)
9696
{
9797
return JS_IsNumber(v);
9898
}
9999

100-
JS_BOOL JS_Ext_IsBigInt(JSContext *ctx, JSValue v)
100+
bool JS_Ext_IsBigInt(JSContext *ctx, JSValue v)
101101
{
102102
return JS_IsBigInt(ctx, v);
103103
}
@@ -110,42 +110,42 @@ JS_BOOL JS_Ext_IsBigInt(JSContext *ctx, JSValue v)
110110
// return JS_IsBigDecimal(v);
111111
// }
112112

113-
JS_BOOL JS_Ext_IsBool(JSValue v)
113+
bool JS_Ext_IsBool(JSValue v)
114114
{
115115
return JS_IsBool(v);
116116
}
117117

118-
JS_BOOL JS_Ext_IsNull(JSValue v)
118+
bool JS_Ext_IsNull(JSValue v)
119119
{
120120
return JS_IsNull(v);
121121
}
122122

123-
JS_BOOL JS_Ext_IsUndefined(JSValue v)
123+
bool JS_Ext_IsUndefined(JSValue v)
124124
{
125125
return JS_IsUndefined(v);
126126
}
127127

128-
JS_BOOL JS_Ext_IsException(JSValue v)
128+
bool JS_Ext_IsException(JSValue v)
129129
{
130130
return JS_IsException(v);
131131
}
132132

133-
JS_BOOL JS_Ext_IsUninitialized(JSValue v)
133+
bool JS_Ext_IsUninitialized(JSValue v)
134134
{
135135
return JS_IsUninitialized(v);
136136
}
137137

138-
JS_BOOL JS_Ext_IsString(JSValue v)
138+
bool JS_Ext_IsString(JSValue v)
139139
{
140140
return JS_IsString(v);
141141
}
142142

143-
JS_BOOL JS_Ext_IsSymbol(JSValue v)
143+
bool JS_Ext_IsSymbol(JSValue v)
144144
{
145145
return JS_IsSymbol(v);
146146
}
147147

148-
JS_BOOL JS_Ext_IsObject(JSValue v)
148+
bool JS_Ext_IsObject(JSValue v)
149149
{
150150
return JS_IsObject(v);
151151
}
@@ -173,7 +173,7 @@ JSValue JS_Ext_NewCFunctionMagic(JSContext *ctx,
173173
return JS_NewCFunctionMagic(ctx, func, name, length, cproto, magic);
174174
}
175175

176-
JS_BOOL JS_Ext_IsPromise(JSContext *ctx, JSValue val)
176+
bool JS_Ext_IsPromise(JSContext *ctx, JSValue val)
177177
{
178178
void *p = JS_GetOpaque(val, JS_CLASS_PROMISE);
179179
return p != NULL;

libquickjs-sys/embed/extensions.h

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22,23 +22,23 @@ extern "C"
2222
JSValue JS_Ext_NewInt32(JSContext *ctx, int32_t val);
2323
JSValue JS_Ext_NewBool(JSContext *ctx, uint8_t val);
2424

25-
JS_BOOL JS_Ext_IsNan(JSValue v);
25+
bool JS_Ext_IsNan(JSValue v);
2626
double JS_Ext_GetFloat64(JSValue v);
2727
int JS_Ext_GetInt(JSValue v);
2828
int JS_Ext_GetBool(JSValue v);
2929
void *JS_Ext_GetPtr(JSValue v);
3030
int JS_Ext_GetNormTag(JSValue v);
3131

32-
JS_BOOL JS_Ext_IsNumber(JSValue v);
33-
JS_BOOL JS_Ext_IsBigInt(JSContext *ctx, JSValue v);
34-
JS_BOOL JS_Ext_IsBool(JSValue v);
35-
JS_BOOL JS_Ext_IsNull(JSValue v);
36-
JS_BOOL JS_Ext_IsUndefined(JSValue v);
37-
JS_BOOL JS_Ext_IsException(JSValue v);
38-
JS_BOOL JS_Ext_IsUninitialized(JSValue v);
39-
JS_BOOL JS_Ext_IsString(JSValue v);
40-
JS_BOOL JS_Ext_IsSymbol(JSValue v);
41-
JS_BOOL JS_Ext_IsObject(JSValue v);
32+
bool JS_Ext_IsNumber(JSValue v);
33+
bool JS_Ext_IsBigInt(JSContext *ctx, JSValue v);
34+
bool JS_Ext_IsBool(JSValue v);
35+
bool JS_Ext_IsNull(JSValue v);
36+
bool JS_Ext_IsUndefined(JSValue v);
37+
bool JS_Ext_IsException(JSValue v);
38+
bool JS_Ext_IsUninitialized(JSValue v);
39+
bool JS_Ext_IsString(JSValue v);
40+
bool JS_Ext_IsSymbol(JSValue v);
41+
bool JS_Ext_IsObject(JSValue v);
4242

4343
int JS_Ext_ToUint32(JSContext *ctx, uint32_t *pres, JSValue val);
4444
JSValue JS_Ext_NewCFunction(JSContext *ctx,
@@ -51,7 +51,7 @@ extern "C"
5151
int length,
5252
JSCFunctionEnum cproto,
5353
int magic);
54-
JS_BOOL JS_Ext_IsPromise(JSContext *ctx, JSValue val);
54+
bool JS_Ext_IsPromise(JSContext *ctx, JSValue val);
5555

5656
JSValue JS_Ext_PromiseResolve(JSContext *ctx, JSValue value);
5757
JSValue JS_Ext_PromiseReject(JSContext *ctx, JSValue value);

src/utils.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ pub(crate) fn deserialize_borrowed_str(
1616

1717
match tag {
1818
q::JS_TAG_STRING => {
19-
let ptr = unsafe { q::JS_ToCStringLen2(context, std::ptr::null_mut(), *r, 0) };
19+
let ptr = unsafe { q::JS_ToCStringLen2(context, std::ptr::null_mut(), *r, false) };
2020

2121
if ptr.is_null() {
2222
return Err(ValueError::Internal(
@@ -300,7 +300,7 @@ use crate::ExecutionError;
300300

301301
/// Get the last exception from the runtime, and if present, convert it to a ExceptionError.
302302
pub(crate) fn get_exception(context: *mut q::JSContext) -> Option<ExecutionError> {
303-
if unsafe { q::JS_HasException(context) } == 0 {
303+
if unsafe { !q::JS_HasException(context) } {
304304
return None;
305305
}
306306

src/value/value.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -147,19 +147,19 @@ impl OwnedJsValue {
147147
/// Check if this value is a Javascript array.
148148
#[inline]
149149
pub fn is_array(&self) -> bool {
150-
unsafe { q::JS_IsArray(self.context, self.value) == 1 }
150+
unsafe { q::JS_IsArray(self.value) }
151151
}
152152

153153
/// Check if this value is a Javascript function.
154154
#[inline]
155155
pub fn is_function(&self) -> bool {
156-
unsafe { q::JS_IsFunction(self.context, self.value) == 1 }
156+
unsafe { q::JS_IsFunction(self.context, self.value) }
157157
}
158158

159159
/// Check if this value is a Javascript promise.
160160
#[inline]
161161
pub fn is_promise(&self) -> bool {
162-
unsafe { q::JS_Ext_IsPromise(self.context, self.value) == 1 }
162+
unsafe { q::JS_Ext_IsPromise(self.context, self.value) }
163163
}
164164

165165
/// Check if this value is a Javascript module.
@@ -213,7 +213,8 @@ impl OwnedJsValue {
213213
/// Convert this value into a string
214214
pub fn to_string(&self) -> Result<String, ValueError> {
215215
self.check_tag(JsTag::String)?;
216-
let ptr = unsafe { q::JS_ToCStringLen2(self.context, std::ptr::null_mut(), self.value, 0) };
216+
let ptr =
217+
unsafe { q::JS_ToCStringLen2(self.context, std::ptr::null_mut(), self.value, false) };
217218

218219
if ptr.is_null() {
219220
return Err(ValueError::Internal(

0 commit comments

Comments
 (0)