Skip to content

Commit

Permalink
prep 0.13
Browse files Browse the repository at this point in the history
  • Loading branch information
andrieshiemstra committed Mar 8, 2024
1 parent 2d83b88 commit 60896f8
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 21 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# 0.13.0

* support quickjs-ng (v 0.3.0) as feature, it compiles, some test cases fail (bigint) but should be a nice first step

# 0.12.1

* bugfix: console.log("a:%s", undefined); would fail
Expand Down
7 changes: 4 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "quickjs_runtime"
version = "0.12.1"
version = "0.13.0"
authors = ["Andries Hiemstra <info@hirofa.com>"]
edition = "2021"
description = "Wrapper API and utils for the QuickJS JavaScript engine with support for Promise, Modules, Async/await"
Expand Down Expand Up @@ -30,9 +30,9 @@ hirofa_utils = "0.7"
#hirofa_utils = {git="https://github.com/HiRoFa/utils"}
backtrace = "0.3.67"

libquickjs-sys = {package="hirofa-quickjs-sys", git='https://github.com/HiRoFa/quickjs-sys'}
#libquickjs-sys = {package="hirofa-quickjs-sys", git='https://github.com/HiRoFa/quickjs-sys'}
#libquickjs-sys = {package="hirofa-quickjs-sys", path='../quickjs-sys'}
#libquickjs-sys = {package="hirofa-quickjs-sys", version="0.2.0", features=["bellard"]}
libquickjs-sys = {package="hirofa-quickjs-sys", version="0.3.0", default-features=false}
lazy_static = "1.4.0"
log = "0.4"
num_cpus = "1"
Expand All @@ -43,6 +43,7 @@ tokio = {version = "1", features = ["rt-multi-thread", "rt", "bytes", "fs", "io-
serde_json = "1.0"
serde = {version="1.0", features=["derive"]}
string_cache = "0.8"
flume = {version="0.10", features=["async"]}

#swc
# like the good people at denoland said
Expand Down
3 changes: 1 addition & 2 deletions src/typescript/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,6 @@ pub fn fix_stack_trace(stack_trace: &str, maps: &HashMap<String, String>) -> Str

#[cfg(test)]
pub mod tests {
use crate::builder::QuickJsRuntimeBuilder;
use crate::facades::tests::init_test_rt;
use crate::jsutils::{JsValueType, Script};
use crate::typescript::{parse_stack_trace, serialize_stack};
Expand Down Expand Up @@ -457,7 +456,7 @@ pub mod tests {

assert_eq!(
serialize_stack(&a).as_str(),
r#" at func (file.ts:88)
r#" at func (file.ts:88:12)
at doWriteTransactioned (gcsproject:///gcs_objectstore/ObjectStore.ts:170)
"#
);
Expand Down
35 changes: 19 additions & 16 deletions src/values.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ use crate::reflection::JsProxyInstanceId;
use futures::executor::block_on;
use futures::Future;
use hirofa_utils::debug_mutex::DebugMutex;
use hirofa_utils::resolvable_future::ResolvableFuture;
use serde::Serialize;
use serde_json::Value;
use std::collections::HashMap;
Expand Down Expand Up @@ -210,11 +209,10 @@ impl CachedJsPromiseRef {
pub async fn get_promise_result(
&self,
) -> Result<Result<JsValueFacade, JsValueFacade>, JsError> {
let fut: ResolvableFuture<Result<Result<JsValueFacade, JsValueFacade>, JsError>> =
ResolvableFuture::new();
let resolver = fut.get_resolver();
let resolver1 = resolver.clone();
let resolver2 = resolver.clone();
let (tx, rx) = flume::bounded(1);

let tx1 = tx.clone();
let tx2 = tx.clone();

self.cached_object.with_obj_void(move |realm, obj| {
let res = || {
Expand All @@ -224,8 +222,8 @@ impl CachedJsPromiseRef {
//
let resolution = &args[0];
let send_res = match realm.to_js_value_facade(resolution) {
Ok(vf) => resolver1.resolve(Ok(Ok(vf))),
Err(conv_err) => resolver1.resolve(Err(conv_err)),
Ok(vf) => tx1.send(Ok(Ok(vf))),
Err(conv_err) => tx1.send(Err(conv_err)),
};
send_res
.map_err(|e| JsError::new_string(format!("could not send: {e}")))?;
Expand All @@ -239,8 +237,8 @@ impl CachedJsPromiseRef {
//
let rejection = &args[0];
let send_res = match realm.to_js_value_facade(rejection) {
Ok(vf) => resolver2.resolve(Ok(Err(vf))),
Err(conv_err) => resolver2.resolve(Err(conv_err)),
Ok(vf) => tx2.send(Ok(Err(vf))),
Err(conv_err) => tx2.send(Err(conv_err)),
};
send_res
.map_err(|e| JsError::new_string(format!("could not send: {e}")))?;
Expand All @@ -254,16 +252,21 @@ impl CachedJsPromiseRef {
};
match res() {
Ok(_) => {}
Err(e) => match resolver.resolve(Err(e)) {
Ok(_) => {}
Err(e) => {
log::error!("failed to resolve 47643: {}", e);
Err(e) => {
log::error!("failed to add promise reactions {}", e);
match tx.send(Err(e)) {
Ok(_) => {}
Err(e) => {
log::error!("failed to resolve 47643: {}", e);
}
}
},
}
}
});

fut.await
rx.recv_async()
.await
.map_err(|e| JsError::new_string(format!("{e}")))?
}
}

Expand Down

0 comments on commit 60896f8

Please sign in to comment.