Update rquickjs dependency (#3942)

This commit is contained in:
Mees Delzenne 2024-05-08 13:00:54 +02:00 committed by GitHub
parent b9f02d146d
commit 061ad8c712
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
20 changed files with 63 additions and 135 deletions

41
Cargo.lock generated
View file

@ -473,7 +473,7 @@ version = "1.9.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "10b3e585719c2358d2660232671ca8ca4ddb4be4ce8a1842d6c2dc8685303316"
dependencies = [
"async-lock 3.3.0",
"async-lock",
"async-task",
"concurrent-queue",
"fastrand 2.0.2",
@ -481,15 +481,6 @@ dependencies = [
"slab",
]
[[package]]
name = "async-lock"
version = "2.8.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "287272293e9d8c41773cec55e365490fe034813a2f172f502d6ddcf75b2f582b"
dependencies = [
"event-listener 2.5.3",
]
[[package]]
name = "async-lock"
version = "3.3.0"
@ -873,17 +864,17 @@ dependencies = [
[[package]]
name = "bindgen"
version = "0.66.1"
version = "0.69.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f2b84e06fc203107bfbad243f4aba2af864eb7db3b1cf46ea0a023b0b433d2a7"
checksum = "a00dc851838a2120612785d195287475a3ac45514741da670b735818822129a0"
dependencies = [
"bitflags 2.5.0",
"cexpr",
"clang-sys",
"itertools 0.11.0",
"lazy_static",
"lazycell",
"log",
"peeking_take_while",
"prettyplease",
"proc-macro2",
"quote",
@ -4541,9 +4532,9 @@ dependencies = [
[[package]]
name = "reblessive"
version = "0.3.3"
version = "0.3.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ffb68fbdf0b0509dcff7c86244a6e2408968c6153c7e50c4eb14a7be598b83a7"
checksum = "4149deda5bd21e0f6ccaa2f907cd542541521dead5861bc51bebdf2af4acaf2a"
[[package]]
name = "redox_syscall"
@ -4968,9 +4959,9 @@ dependencies = [
[[package]]
name = "rquickjs"
version = "0.5.1"
version = "0.6.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ad7f63201fa6f2ff8173e4758ea552549d687d8f63003361a8b5c50f7c446ded"
checksum = "9cbd33e0b668aea0ab238b9164523aca929096f9f40834700d71d91dd4888882"
dependencies = [
"rquickjs-core",
"rquickjs-macro",
@ -4978,20 +4969,20 @@ dependencies = [
[[package]]
name = "rquickjs-core"
version = "0.5.1"
version = "0.6.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cad00eeddc0f88af54ee202c8385fb214fe0423897c056a7df8369fb482e3695"
checksum = "2e9129d69b7b8f7ee8ad1da5b12c7f4a8a8acd45f2e6dd9cb2ee1bc5a1f2fa3d"
dependencies = [
"async-lock 2.8.0",
"async-lock",
"relative-path",
"rquickjs-sys",
]
[[package]]
name = "rquickjs-macro"
version = "0.5.1"
version = "0.6.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f27b39e889cc951e3e5f6b74012f943e642fa0fac51a8552948751f19a9b62f8"
checksum = "c7d2ecaf7c9eda262e02a91e9541989a9dd18984d17d0d97f99f33b464318057"
dependencies = [
"convert_case 0.6.0",
"fnv",
@ -5007,11 +4998,11 @@ dependencies = [
[[package]]
name = "rquickjs-sys"
version = "0.5.1"
version = "0.6.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "120dbbc3296de9b96de8890091635d46f3506cd38b4e8f21800c386c035d64fa"
checksum = "bf6f2288d8e7fbb5130f62cf720451641e99d55f6fde9db86aa2914ecb553fd2"
dependencies = [
"bindgen 0.66.1",
"bindgen 0.69.4",
"cc",
]

View file

@ -89,7 +89,7 @@ geo-types = { version = "0.7.12", features = ["arbitrary"] }
hex = { version = "0.4.3" }
indxdb = { version = "0.4.0", optional = true }
ipnet = "2.9.0"
js = { version = "0.5.1", package = "rquickjs", features = [
js = { version = "0.6.2", package = "rquickjs", features = [
"array-buffer",
"bindgen",
"classes",
@ -115,7 +115,7 @@ pin-project-lite = "0.2.13"
quick_cache = "0.5.1"
radix_trie = { version = "0.2.1", features = ["serde"] }
rand = "0.8.5"
reblessive = { version = "0.3.3", features = ["tree"] }
reblessive = { version = "0.3.5", features = ["tree"] }
regex = "1.10.2"
regex-syntax = { version = "0.8.2", optional = true, features = ["arbitrary"] }
reqwest = { version = "0.11.22", default-features = false, features = [

View file

@ -147,7 +147,7 @@ impl<'js> FromJs<'js> for Body {
})
}
};
if let Some(x) = Class::<Blob>::from_object(object.clone()) {
if let Some(x) = Class::<Blob>::from_object(object) {
let borrow = x.borrow();
return Ok(Body::buffer(BodyKind::Blob(borrow.mime.clone()), borrow.data.clone()));
}

View file

@ -26,7 +26,7 @@ fn append_blob_part<'js>(
const LINE_ENDING: &[u8] = b"\n";
if let Some(object) = value.as_object() {
if let Some(x) = Class::<Blob>::from_object(object.clone()) {
if let Some(x) = Class::<Blob>::from_object(object) {
data.extend_from_slice(&x.borrow().data);
return Ok(());
}
@ -210,7 +210,7 @@ mod test {
const NATIVE_LINE_ENDING: &str = "\n";
ctx.globals().set("NATIVE_LINE_ENDING",NATIVE_LINE_ENDING).unwrap();
ctx.eval::<Promise<()>,_>(r#"(async () => {
ctx.eval::<Promise,_>(r#"(async () => {
let blob = new Blob();
assert.eq(blob.size,0);
assert.eq(blob.type,"");
@ -233,7 +233,7 @@ mod test {
assert.mustThrow(() => new Blob("text"));
assert.mustThrow(() => new Blob(["text"], {endings: "invalid value"}));
})()
"#).catch(&ctx).unwrap().await.catch(&ctx).unwrap();
"#).catch(&ctx).unwrap().into_future::<()>().await.catch(&ctx).unwrap();
})
.await
}

View file

@ -28,9 +28,7 @@ impl<'js> FormDataValue<'js> {
filename: Opt<Coerced<String<'js>>>,
error: &'static str,
) -> Result<Self> {
if let Some(blob) =
value.as_object().and_then(|value| Class::<Blob>::from_object(value.clone()))
{
if let Some(blob) = value.as_object().and_then(Class::<Blob>::from_object) {
let filename = filename.into_inner().map(|x| x.0);
Ok(FormDataValue::Blob {

View file

@ -343,7 +343,7 @@ impl<'js> FromJs<'js> for RequestInit<'js> {
}
let headers = if let Some(hdrs) = object.get::<_, Option<Object>>("headers")? {
if let Some(cls) = Class::<Headers>::from_object(hdrs.clone()) {
if let Some(cls) = Class::<Headers>::from_object(&hdrs) {
cls
} else {
Class::instance(ctx.clone(), Headers::new_inner(ctx, hdrs.into_value())?)?
@ -418,7 +418,7 @@ impl<'js> Request<'js> {
url,
init,
})
} else if let Some(request) = input.into_object().and_then(Class::<Self>::from_object) {
} else if let Some(request) = input.as_object().and_then(Class::<Self>::from_object) {
// existing request object, just return it
request.try_borrow()?.clone_js(ctx.clone())
} else {
@ -551,7 +551,7 @@ mod test {
#[tokio::test]
async fn basic_request_use() {
create_test_context!(ctx => {
ctx.eval::<Promise<()>,_>(r#"
ctx.eval::<Promise,_>(r#"
(async () => {
assert.mustThrow(() => {
new Request("invalid url")
@ -621,7 +621,7 @@ mod test {
assert.seq(await req_2.text(),"some text");
})()
"#).catch(&ctx).unwrap().await.catch(&ctx).unwrap();
"#).catch(&ctx).unwrap().into_future::<()>().await.catch(&ctx).unwrap();
})
.await;
}

View file

@ -308,7 +308,7 @@ mod test {
#[tokio::test]
async fn basic_response_use() {
create_test_context!(ctx => {
ctx.eval::<Promise<()>,_>(r#"
ctx.eval::<Promise,_>(r#"
(async () => {
let resp = new Response();
assert(resp.bodyUsed);
@ -369,7 +369,7 @@ mod test {
})()
"#).catch(&ctx).unwrap().await.catch(&ctx).unwrap();
"#).catch(&ctx).unwrap().into_future::<()>().await.catch(&ctx).unwrap();
})
.await;
}

View file

@ -13,14 +13,9 @@ use crate::err::Error;
use crate::sql::value::Value;
use js::async_with;
use js::object::Property;
use js::prelude::Promise;
use js::prelude::Rest;
use js::prelude::This;
use js::prelude::*;
use js::CatchResultExt;
use js::Class;
use js::Ctx;
use js::Function;
use js::Module;
use js::{Class, Ctx, Function, Module, Promise};
/// Insert query data into the context,
///
@ -95,10 +90,11 @@ pub async fn run(
// function. For the entire duration of which context, opt, txn and doc are valid.
unsafe{ create_query_data(context,opt,txn,doc,&ctx) }?;
// Register the surrealdb module as a global object
let (module,promise) = Module::evaluate_def::<modules::surrealdb::Package, _>(ctx.clone(), "surrealdb")?;
promise.finish::<()>()?;
global.set(
"surrealdb",
Module::evaluate_def::<modules::surrealdb::Package, _>(ctx.clone(), "surrealdb")?
.get::<_, js::Value>("default")?,
module.get::<_, js::Value>("default")?,
)?;
fetch::register(&ctx)?;
let console = globals::console::console(&ctx)?;
@ -106,14 +102,16 @@ pub async fn run(
global.set("console",console)?;
// Register the special SurrealDB types as classes
classes::init(&ctx)?;
// Attempt to compile the script
let res = ctx.clone().compile("script", src)?;
let (module,promise) = Module::declare(ctx.clone(),"script", src)?.eval()?;
promise.into_future::<()>().await?;
// Attempt to fetch the main export
let fnc = res.get::<_, Function>("default")?;
let fnc = module.get::<_, Function>("default")?;
// Extract the doc if any
let doc = doc.map(|v|v.doc.as_ref());
// Execute the main function
let promise: Promise<Value> = fnc.call((This(doc), Rest(arg)))?;
let promise = fnc.call::<_,Promise>((This(doc), Rest(arg)))?.into_future::<Value>();
promise.await
}.await;

View file

@ -46,7 +46,7 @@ macro_rules! impl_module_def {
};
($pkg: ident, $path: literal, $($name: literal => $action: tt $($wrapper: ident)?),*) => {
impl js::module::ModuleDef for Package {
fn declare(decls: &mut js::module::Declarations) -> js::Result<()> {
fn declare(decls: &js::module::Declarations) -> js::Result<()> {
decls.declare("default")?;
$(
decls.declare($name)?;
@ -54,7 +54,7 @@ macro_rules! impl_module_def {
Ok(())
}
fn evaluate<'js>(ctx: &js::Ctx<'js>, exports: &mut js::module::Exports<'js>) -> js::Result<()> {
fn evaluate<'js>(ctx: &js::Ctx<'js>, exports: &js::module::Exports<'js>) -> js::Result<()> {
let default = js::Object::new(ctx.clone())?;
$(
let value = crate::fnc::script::modules::impl_module_def!(ctx, $path, $name, $action, $($wrapper)?);

View file

@ -18,13 +18,13 @@ pub fn platform() -> &'static str {
pub struct Package;
impl ModuleDef for Package {
fn declare(declare: &mut Declarations) -> Result<()> {
fn declare(declare: &Declarations) -> Result<()> {
declare.declare("arch")?;
declare.declare("platform")?;
Ok(())
}
fn evaluate<'js>(_ctx: &js::Ctx<'js>, exports: &mut Exports<'js>) -> Result<()> {
fn evaluate<'js>(_ctx: &js::Ctx<'js>, exports: &Exports<'js>) -> Result<()> {
exports.export("arch", js_arch)?;
exports.export("platform", js_platform)?;
Ok(())

View file

@ -9,7 +9,7 @@ mod uuid;
pub struct Package;
impl js::module::ModuleDef for Package {
fn declare(decls: &mut js::module::Declarations) -> js::Result<()> {
fn declare(decls: &js::module::Declarations) -> js::Result<()> {
decls.declare("default")?;
decls.declare("bool")?;
decls.declare("enum")?;
@ -22,7 +22,7 @@ impl js::module::ModuleDef for Package {
decls.declare("uuid")?;
Ok(())
}
fn evaluate<'js>(ctx: &js::Ctx<'js>, exports: &mut js::module::Exports<'js>) -> js::Result<()> {
fn evaluate<'js>(ctx: &js::Ctx<'js>, exports: &js::module::Exports<'js>) -> js::Result<()> {
let default = js::Function::new(ctx.clone(), |ctx: Ctx<'js>, args: Rest<Value>| {
run(ctx, "rand", args.0)
})?

View file

@ -7,13 +7,13 @@ use crate::sql::value::Value;
pub struct Package;
impl js::module::ModuleDef for Package {
fn declare(decls: &mut js::module::Declarations) -> js::Result<()> {
fn declare(decls: &js::module::Declarations) -> js::Result<()> {
decls.declare("default")?;
decls.declare("v4")?;
decls.declare("v7")?;
Ok(())
}
fn evaluate<'js>(ctx: &js::Ctx<'js>, exports: &mut js::module::Exports<'js>) -> js::Result<()> {
fn evaluate<'js>(ctx: &js::Ctx<'js>, exports: &js::module::Exports<'js>) -> js::Result<()> {
let default = js::Function::new(ctx.clone(), |ctx: Ctx<'js>, args: Rest<Value>| {
run(ctx, "rand::uuid", args.0)
})?

View file

@ -28,7 +28,7 @@ async fn value(ctx: Ctx<'_>, value: Coerced<String>) -> Result<SurValue> {
}
impl ModuleDef for Package {
fn declare(decls: &mut js::module::Declarations) -> js::Result<()> {
fn declare(decls: &js::module::Declarations) -> js::Result<()> {
decls.declare("default")?;
decls.declare("functions")?;
decls.declare("version")?;
@ -38,7 +38,7 @@ impl ModuleDef for Package {
Ok(())
}
fn evaluate<'js>(ctx: &js::Ctx<'js>, exports: &mut js::module::Exports<'js>) -> js::Result<()> {
fn evaluate<'js>(ctx: &js::Ctx<'js>, exports: &js::module::Exports<'js>) -> js::Result<()> {
let default = js::Object::new(ctx.clone())?;
let package = pkg::<functions::Package>(ctx, "functions")?;
exports.export("functions", package.clone())?;
@ -69,5 +69,7 @@ fn pkg<'js, D>(ctx: &Ctx<'js>, name: &str) -> Result<Value<'js>>
where
D: ModuleDef,
{
Module::evaluate_def::<D, _>(ctx.clone(), name)?.get::<_, js::Value>("default")
let (m, promise) = Module::evaluate_def::<D, _>(ctx.clone(), name)?;
promise.finish()?;
m.get::<_, js::Value>("default")
}

View file

@ -110,7 +110,7 @@ tokio-util = { version = "0.7.10", optional = true, features = ["compat"] }
tracing = "0.1.40"
trice = { version = "0.4.0", optional = true }
url = "2.5.0"
reblessive = { version = "0.3.3", features = ["tree"] }
reblessive = { version = "0.3.5", features = ["tree"] }
[dev-dependencies]
criterion = { version = "0.5.1", features = ["async_tokio"] }

View file

@ -137,10 +137,10 @@ where
}
false => {
let mut table = Table::default();
table.0 = record_id.tb.clone();
table.0.clone_from(&record_id.tb);
content.resource = Ok(table.into());
let mut ident = Ident::default();
ident.0 = "id".to_owned();
"id".clone_into(&mut ident.0);
let id = Part::Field(ident);
data.put(&[id], record_id.into());
content.content = data;

View file

@ -76,7 +76,7 @@ where
}
// Build the query and execute it
let mut query = sql::Query::default();
query.0 .0 = statements.clone();
query.0 .0.clone_from(&statements);
let param = Param::query(query, self.bindings?);
let mut conn = Client::new(Method::Query);
let mut response = conn.execute_query(router, param).await?;

View file

@ -216,7 +216,7 @@ impl<R> IntoResource<Vec<R>> for &str {
fn into_resource(self) -> Result<Resource> {
blacklist_colon(self)?;
let mut table = Table::default();
table.0 = self.to_owned();
self.clone_into(&mut table.0);
Ok(Resource::Table(table))
}
}

View file

@ -1,60 +0,0 @@
use surrealdb::sql::Array;
use surrealdb::sql::Value;
pub trait Take {
fn needs_one(self) -> Result<Value, ()>;
fn needs_two(self) -> Result<(Value, Value), ()>;
fn needs_one_or_two(self) -> Result<(Value, Value), ()>;
fn needs_one_two_or_three(self) -> Result<(Value, Value, Value), ()>;
}
impl Take for Array {
/// Convert the array to one argument
fn needs_one(self) -> Result<Value, ()> {
if self.len() != 1 {
return Err(());
}
let mut x = self.into_iter();
match x.next() {
Some(a) => Ok(a),
None => Ok(Value::None),
}
}
/// Convert the array to two arguments
fn needs_two(self) -> Result<(Value, Value), ()> {
if self.len() != 2 {
return Err(());
}
let mut x = self.into_iter();
match (x.next(), x.next()) {
(Some(a), Some(b)) => Ok((a, b)),
(Some(a), None) => Ok((a, Value::None)),
(_, _) => Ok((Value::None, Value::None)),
}
}
/// Convert the array to two arguments
fn needs_one_or_two(self) -> Result<(Value, Value), ()> {
if self.is_empty() && self.len() > 2 {
return Err(());
}
let mut x = self.into_iter();
match (x.next(), x.next()) {
(Some(a), Some(b)) => Ok((a, b)),
(Some(a), None) => Ok((a, Value::None)),
(_, _) => Ok((Value::None, Value::None)),
}
}
/// Convert the array to three arguments
fn needs_one_two_or_three(self) -> Result<(Value, Value, Value), ()> {
if self.is_empty() && self.len() > 3 {
return Err(());
}
let mut x = self.into_iter();
match (x.next(), x.next(), x.next()) {
(Some(a), Some(b), Some(c)) => Ok((a, b, c)),
(Some(a), Some(b), None) => Ok((a, b, Value::None)),
(Some(a), None, None) => Ok((a, Value::None, Value::None)),
(_, _, _) => Ok((Value::None, Value::None, Value::None)),
}
}
}

View file

@ -1,4 +1,3 @@
pub mod args;
pub mod connection;
pub mod failure;
pub mod format;

View file

@ -1360,7 +1360,7 @@ version = "0.11.3"
criteria = "safe-to-run"
[[exemptions.reblessive]]
version = "0.3.3"
version = "0.3.5"
criteria = "safe-to-deploy"
[[exemptions.redox_syscall]]
@ -1476,19 +1476,19 @@ version = "0.21.0"
criteria = "safe-to-deploy"
[[exemptions.rquickjs]]
version = "0.5.1"
version = "0.6.2"
criteria = "safe-to-deploy"
[[exemptions.rquickjs-core]]
version = "0.5.1"
version = "0.6.2"
criteria = "safe-to-deploy"
[[exemptions.rquickjs-macro]]
version = "0.5.1"
version = "0.6.2"
criteria = "safe-to-deploy"
[[exemptions.rquickjs-sys]]
version = "0.5.1"
version = "0.6.2"
criteria = "safe-to-deploy"
[[exemptions.rsa]]