Skip to content

Commit 9d35205

Browse files
update to quickjs_runtime 0.16
1 parent be697f9 commit 9d35205

File tree

7 files changed

+22
-20
lines changed

7 files changed

+22
-20
lines changed

Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,12 @@ cache = ["lru"]
4747

4848

4949
[dependencies]
50-
quickjs_runtime = { version = "0.15" }
50+
quickjs_runtime = { version = "0.16" }
5151
#quickjs_runtime = { path = '../quickjs_es_runtime', features = ["typescript", "default"]}
5252
#quickjs_runtime = { git = 'https://github.com/HiRoFa/quickjs_es_runtime', features = ["typescript", "default"]}
5353
#libquickjs-sys = {package="hirofa-quickjs-sys", path='../quickjs-sys', features=["quickjs-ng"]}
5454
#libquickjs-sys = {package="hirofa-quickjs-sys", git='https://github.com/HiRoFa/quickjs-sys', features=["bellard"]}
55-
libquickjs-sys = { package = "hirofa-quickjs-sys", version = "0.10", features = ["bellard"], default-features = false }
55+
libquickjs-sys = { package = "hirofa-quickjs-sys", version = "0.11", features = ["bellard"], default-features = false }
5656
hirofa_utils = "0.7"
5757
#hirofa_utils = {git = "https://github.com/HiRoFa/utils"}
5858
#hirofa_utils = { path = '../utils'}

src/features/js_fetch/proxies.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,8 @@ fn impl_response(realm: &QuickJsRealmAdapter) -> Result<(), JsError> {
9797
return Err(JsError::new_str("getHeader expects a single String arg"));
9898
}
9999

100-
let name = args[0].to_str()?;
101-
if let Some(headers) = response.headers.get(name) {
100+
let name = args[0].to_string()?;
101+
if let Some(headers) = response.headers.get(name.as_str()) {
102102
if !headers.is_empty() {
103103
return realm.create_string(headers.first().unwrap());
104104
}

src/modules/db/sqlx/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1218,9 +1218,9 @@ fn prep_query_and_args(
12181218
args: Vec<QuickJsValueAdapter>,
12191219
protocol: Protocol,
12201220
) -> Result<(String, Vec<JsValueFacade>), JsError> {
1221-
let query = args[0].to_str()?;
1221+
let query = args[0].to_string()?;
12221222

1223-
let parsed_query = parse_query(protocol, query);
1223+
let parsed_query = parse_query(protocol, query.as_str());
12241224

12251225
// param names in correct order
12261226

src/modules/encoding/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ pub(crate) fn create_base64_proxy(_realm: &QuickJsRealmAdapter) -> JsProxy {
167167
if args.is_empty() || !args[0].is_string() {
168168
Err(JsError::new_str("decode expects a single string arg"))
169169
} else {
170-
let s = args[0].to_str()?;
170+
let s = args[0].to_string()?;
171171
let engine = base64::engine::general_purpose::STANDARD_NO_PAD;
172172
let decoded = engine.decode(s.trim_end_matches('=')).map_err(|e| {
173173
JsError::new_string(format!("could not decode base64({s}): {e}"))

src/modules/htmldom/mod.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -846,15 +846,15 @@ fn init_node_proxy(realm: &QuickJsRealmAdapter) -> Result<QuickJsValueAdapter, J
846846
return Err(JsError::new_str("getAttribute expects one string arg"));
847847
}
848848

849-
let local_name = args[0].to_str()?;
849+
let local_name = args[0].to_string()?;
850850

851851
with_node(id, |node| {
852852
//
853853
match node.as_element() {
854854
None => Err(JsError::new_str("not an Element")),
855855
Some(element) => {
856856
let attrs = &mut *element.attributes.borrow_mut();
857-
match attrs.get(local_name) {
857+
match attrs.get(local_name.as_str()) {
858858
None => realm.create_null(),
859859
Some(attr) => realm.create_string(attr),
860860
}
@@ -910,11 +910,11 @@ fn init_node_proxy(realm: &QuickJsRealmAdapter) -> Result<QuickJsValueAdapter, J
910910
return Err(JsError::new_str("querySelector expects one string arg"));
911911
}
912912

913-
let selectors = args[0].to_str()?;
913+
let selectors = args[0].to_string()?;
914914

915915
let res = with_node(id, |node| {
916916
//
917-
let result = node.select_first(selectors);
917+
let result = node.select_first(selectors.as_str());
918918
match result {
919919
Ok(ndr) => Some(ndr.as_node().clone()),
920920
Err(_) => None,
@@ -1185,12 +1185,12 @@ fn init_node_proxy(realm: &QuickJsRealmAdapter) -> Result<QuickJsValueAdapter, J
11851185
));
11861186
}
11871187

1188-
let id_attr = args[0].to_str()?;
1188+
let id_attr = args[0].to_string()?;
11891189

11901190
let res = with_node(id, |node| match node.as_document() {
11911191
None => Err(JsError::new_str("not a Document")),
11921192
Some(_document) => {
1193-
let node_res = node.select_first(format!("#{id_attr}").as_str());
1193+
let node_res = node.select_first(id_attr.as_str());
11941194
Ok(node_res)
11951195
}
11961196
});

src/modules/jwt/mod.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,8 @@ fn create(
122122
} else {
123123
let alg_header = realm.get_object_property(&args[0], "alg")?;
124124
let alg = if alg_header.is_string() {
125-
JwtAlgo::from_str(alg_header.to_str()?)?
125+
let string = alg_header.to_string()?;
126+
JwtAlgo::from_str(string.as_str())?
126127
} else {
127128
JwtAlgo::EdDSA
128129
};

src/modules/util/cache/mod.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -85,13 +85,13 @@ impl CacheRegion {
8585
pub fn remove(&mut self, key: &str) -> Option<CacheEntry> {
8686
self.lru_cache.pop(key)
8787
}
88-
pub fn put(&mut self, key: &str, val: JsValueFacade) {
88+
pub fn put(&mut self, key: String, val: JsValueFacade) {
8989
let ce = CacheEntry {
9090
val,
9191
created: Instant::now(),
9292
last_used: Instant::now(),
9393
};
94-
self.lru_cache.put(key.to_string(), ce);
94+
self.lru_cache.put(key, ce);
9595
}
9696
fn invalidate_stale(&mut self) {
9797
let min_last_used = Instant::now().sub(self.max_idle);
@@ -238,7 +238,7 @@ impl NativeModuleLoader for CacheModuleLoader {
238238

239239
fn cache_add(
240240
realm: &QuickJsRealmAdapter,
241-
key: &str,
241+
key: String,
242242
value: &QuickJsValueAdapter,
243243
region: &mut CacheRegion,
244244
) -> Result<(), JsError> {
@@ -293,8 +293,9 @@ fn init_region_proxy(realm: &QuickJsRealmAdapter) -> Result<(), JsError> {
293293
"cache_add_func",
294294
move |realm, _this, args| {
295295
// cache args 0
296+
let key_clone = key.clone();
296297
with_cache_region(&instance_id, |cache_region2| {
297-
cache_add(realm, &key, &args[0], cache_region2)
298+
cache_add(realm, key_clone, &args[0], cache_region2)
298299
})?;
299300

300301
realm.create_null()
@@ -303,7 +304,7 @@ fn init_region_proxy(realm: &QuickJsRealmAdapter) -> Result<(), JsError> {
303304
)?;
304305
realm.add_promise_reactions(&init_result, Some(then), None, None)?;
305306
} else {
306-
cache_add(realm, &key, &init_result, cache_region)?;
307+
cache_add(realm, key, &init_result, cache_region)?;
307308
}
308309
Ok(init_result)
309310
}
@@ -322,7 +323,7 @@ fn init_region_proxy(realm: &QuickJsRealmAdapter) -> Result<(), JsError> {
322323
));
323324
}
324325

325-
let key = args[0].to_str()?;
326+
let key = args[0].to_string()?;
326327
let val = realm.to_js_value_facade(&args[1])?;
327328

328329
with_cache_region(instance_id, move |cache_region| {

0 commit comments

Comments
 (0)