Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into blockless
Browse files Browse the repository at this point in the history
# Conflicts:
#       Cargo.lock
  • Loading branch information
uditdc committed Mar 20, 2024
2 parents 615fee1 + 0a32f86 commit 8d35f47
Show file tree
Hide file tree
Showing 16 changed files with 543 additions and 424 deletions.
447 changes: 242 additions & 205 deletions Cargo.lock

Large diffs are not rendered by default.

12 changes: 6 additions & 6 deletions crates/cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,16 @@ wizer = { workspace = true }
structopt = "0.3"
anyhow = { workspace = true }
brotli = "3.4.0"
wasmprinter = { version = "0.2.78", optional = true }
wasmprinter = { version = "0.201.0", optional = true }
wasmtime = { workspace = true }
wasmtime-wasi = { workspace = true }
wasi-common = { workspace = true }
walrus = "0.20.3"
swc_core = { version = "0.89.7", features = ["common_sourcemap", "ecma_ast", "ecma_parser"] }
wit-parser = "0.13.1"
swc_core = { version = "0.90.14", features = ["common_sourcemap", "ecma_ast", "ecma_parser"] }
wit-parser = "0.201.0"
convert_case = "0.6.0"
wasm-opt = "0.116.0"
tempfile = "3.9.0"
tempfile = "3.10.1"

[dev-dependencies]
serde_json = "1.0"
Expand All @@ -37,10 +37,10 @@ lazy_static = "1.4"
serde = { version = "1.0", default-features = false, features = ["derive"] }
criterion = "0.5"
num-format = "0.4.4"
wasmparser = "0.121.0"
wasmparser = "0.201.0"

[build-dependencies]
anyhow = "1.0.79"
anyhow = "1.0.80"
wizer = { workspace = true }

[[bench]]
Expand Down
2 changes: 1 addition & 1 deletion crates/javy/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ categories = ["wasm"]

[dependencies]
anyhow = { workspace = true }
quickjs-wasm-rs = { version = "3.0.1-alpha.1", path = "../quickjs-wasm-rs" }
quickjs-wasm-rs = { version = "3.1.0-alpha.1", path = "../quickjs-wasm-rs" }
serde_json = { version = "1.0", optional = true }
serde-transcode = { version = "1.1", optional = true }
rmp-serde = { version = "^1.1", optional = true }
Expand Down
2 changes: 2 additions & 0 deletions crates/quickjs-wasm-rs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## Unreleased

- Add a new `expose-sys` feature that exposes unstable escape hatch functions to the underlying `quickjs_wasm_sys` crate.

## [3.0.0] - 2024-01-31

### Changed
Expand Down
6 changes: 5 additions & 1 deletion crates/quickjs-wasm-rs/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "quickjs-wasm-rs"
version = "3.0.1-alpha.1"
version = "3.1.0-alpha.1"
authors.workspace = true
edition.workspace = true
license.workspace = true
Expand All @@ -18,3 +18,7 @@ once_cell = "1.19"
[dev-dependencies]
quickcheck = "1"
serde_bytes = "0.11.14"

[features]
# Re-exports the quickjs-wasm-sys module and exposes additional, unstable APIs.
export-sys = []
24 changes: 24 additions & 0 deletions crates/quickjs-wasm-rs/src/js_binding/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,30 @@ impl JSContextRef {
JSValueRef::new(self, raw)
}

/// Returns the raw pointer to the underlying [quickjs_wasm_sys::JSContext].
///
/// # Safety
/// While calling this function is safe, using it’s return value has to be
/// done with a sufficitenly deep understanding of QuickJS and [quickjs_wasm_sys].
///
/// This function is not part of the crate’s semver API contract.
#[cfg(feature = "export-sys")]
pub unsafe fn as_raw(&self) -> *mut JSContext {
self.inner
}

/// Creates a `JSContextRef` from a pointer to a [quickjs_wasm_sys::JSContext].
///
/// # Safety
/// The caller has to ensure that the returned `JSContextRef` is the only one
/// used throughout its lifetime.
///
/// This function is not part of the crate’s semver API contract.
#[cfg(feature = "export-sys")]
pub unsafe fn from_raw(inner: *mut JSContext) -> JSContextRef {
JSContextRef { inner }
}

/// Compiles JavaScript to QuickJS bytecode with an ECMAScript module scope.
///
/// # Arguments
Expand Down
19 changes: 19 additions & 0 deletions crates/quickjs-wasm-rs/src/js_binding/value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,25 @@ impl<'a> JSValueRef<'a> {
Self { context, value }
}

/// Creates a new `JSValueRef` from a `u64`, which is QuickJS’s internal representation.
///
/// # Safety
/// The caller has to ensure that the given value is valid and belongs to the context.
///
/// This function is not part of the crate’s semver API contract.
#[cfg(feature = "export-sys")]
pub unsafe fn from_raw(context: &'a JSContextRef, value: JSValueRaw) -> Self {
JSValueRef::new_unchecked(context, value)
}

/// Returns QuickJS’s internal representation. Note that the value is implicitly tied to the context it came from.
///
/// # Safety
/// The function is safe to call, but not part of the crate’s semver API contract.
#[cfg(feature = "export-sys")]
pub unsafe fn as_raw(&self) -> JSValueRaw {
self.value
}
pub(super) fn eval_function(&self) -> Result<Self> {
Self::new(self.context, unsafe {
JS_EvalFunction(self.context.inner, self.value)
Expand Down
3 changes: 3 additions & 0 deletions crates/quickjs-wasm-rs/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@ mod js_binding;
mod js_value;
mod serialize;

#[cfg(feature = "export-sys")]
pub use quickjs_wasm_sys;

pub use crate::js_binding::context::JSContextRef;
pub use crate::js_binding::error::JSError;
pub use crate::js_binding::exception::Exception;
Expand Down
2 changes: 2 additions & 0 deletions crates/quickjs-wasm-sys/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## Unreleased changes

- Expose `JS_DupValue` via `JS_DupValueExt`.

## [1.2.0] - 2024-01-31

- Changed: Updated to 2023-12-09 release of QuickJS.
Expand Down
4 changes: 2 additions & 2 deletions crates/quickjs-wasm-sys/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ categories = ["external-ffi-bindings"]

[build-dependencies]
cc = "1.0"
bindgen = "0.69.2"
bindgen = "0.69.4"
walkdir = "2"
anyhow.workspace = true
tokio = { version = "1.35", default-features = false, features = ["rt", "macros"] }
tokio = { version = "1.36", default-features = false, features = ["rt", "macros"] }
http-body-util = "0.1.0"
hyper = "1.1"
hyper-tls = "0.6.0"
Expand Down
29 changes: 20 additions & 9 deletions crates/quickjs-wasm-sys/extensions/value.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
#include "../quickjs/quickjs.h"
#include "../quickjs/libbf.h"
#include "../quickjs/quickjs.h"

// Quick JS API Extensions.
// These are wrapper functions on top of QuickJS API and exist because either
// QuickJS doesn't expose a native way to achieve the desired behavior or
// because the functions are marked inline, and in which case, bindgen can't
// generate Rust bindings out-of-the box.
// https://github.com/rust-lang/rust-bindgen/discussions/2405

// The definitions in this file are paired with their respective `extern "C"`
// declaration in `extensions/value.rs`.

JSValue JS_NewBool_Ext(JSContext *ctx, JS_BOOL val) {
return JS_MKVAL(JS_TAG_BOOL, (val != 0));
Expand All @@ -21,18 +31,20 @@ JSValue JS_NewFloat64_Ext(JSContext *ctx, double d) {
return JS_NewFloat64(ctx, d);
}

JS_BOOL JS_IsFloat64_Ext(int tag) {
return JS_TAG_IS_FLOAT64(tag);
JSValue JS_DupValueExt(JSContext *ctx, JSValueConst v) {
return JS_DupValue(ctx, v);
}

JS_BOOL JS_IsArrayBuffer_Ext(JSContext* ctx, JSValue val) {
size_t len;
return JS_GetArrayBuffer(ctx, &len, val) != 0;
JS_BOOL JS_IsFloat64_Ext(int tag) { return JS_TAG_IS_FLOAT64(tag); }

JS_BOOL JS_IsArrayBuffer_Ext(JSContext *ctx, JSValue val) {
size_t len;
return JS_GetArrayBuffer(ctx, &len, val) != 0;
}

typedef struct JSBigFloat {
JSRefCountHeader header; /* must come first, 32-bit */
bf_t num;
JSRefCountHeader header; /* must come first, 32-bit */
bf_t num;
} JSBigFloat;

JS_BOOL JS_BigIntSigned(JSContext *ctx, JSValue val) {
Expand Down Expand Up @@ -72,7 +84,6 @@ int JS_BigIntToUint64(JSContext *ctx, uint64_t *pres, JSValueConst val) {
return JS_BigIntToUint64Free(ctx, pres, JS_DupValue(ctx, val));
}


const JSValue ext_js_null = JS_NULL;
const JSValue ext_js_undefined = JS_UNDEFINED;
const JSValue ext_js_false = JS_FALSE;
Expand Down
1 change: 1 addition & 0 deletions crates/quickjs-wasm-sys/src/extensions/value.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
extern "C" {
pub fn JS_DupValueExt(ctx: *mut JSContext, v: JSValue) -> JSValue;
pub fn JS_NewBool_Ext(ctx: *mut JSContext, bool: i32) -> JSValue;
pub fn JS_NewInt32_Ext(ctx: *mut JSContext, val: i32) -> JSValue;
pub fn JS_NewUint32_Ext(ctx: *mut JSContext, val: u32) -> JSValue;
Expand Down
Loading

0 comments on commit 8d35f47

Please sign in to comment.