diff options
author | Aaron O'Mullan <aaron.omullan@gmail.com> | 2021-04-06 05:17:00 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-04-05 23:17:00 -0400 |
commit | 91e80ada8a323a6526f760d41f2ebc481814e843 (patch) | |
tree | 9eed0f428d921f561e0ded092d6cda14a381d2ca | |
parent | d849c87eb16a4bebee1a09c171dbdae6a4924a55 (diff) |
core: remove serde_json-isms in op_close() and op_resources() (#10026)
Core no longer uses `serde_json` now, besides re-exporting it or in the module specifier tests
-rw-r--r-- | core/core.js | 4 | ||||
-rw-r--r-- | core/ops.rs | 27 |
2 files changed, 13 insertions, 18 deletions
diff --git a/core/core.js b/core/core.js index f94ec8139..40a8270e3 100644 --- a/core/core.js +++ b/core/core.js @@ -105,11 +105,11 @@ } function resources() { - return jsonOpSync("op_resources"); + return Object.fromEntries(jsonOpSync("op_resources")); } function close(rid) { - jsonOpSync("op_close", { rid }); + jsonOpSync("op_close", rid); } Object.assign(window.Deno.core, { diff --git a/core/ops.rs b/core/ops.rs index 1a2a2ebc7..caf984e00 100644 --- a/core/ops.rs +++ b/core/ops.rs @@ -4,6 +4,7 @@ use crate::error::bad_resource_id; use crate::error::type_error; use crate::error::AnyError; use crate::gotham_state::GothamState; +use crate::resources::ResourceId; use crate::resources::ResourceTable; use crate::runtime::GetErrorClassFn; use crate::ZeroCopyBuf; @@ -12,10 +13,7 @@ use indexmap::IndexMap; use rusty_v8 as v8; use serde::de::DeserializeOwned; use serde::Serialize; -use serde_json::json; -use serde_json::Value; use std::cell::RefCell; -use std::collections::HashMap; use std::iter::once; use std::ops::Deref; use std::ops::DerefMut; @@ -189,15 +187,15 @@ impl Default for OpTable { /// This op must be wrapped in `json_op_sync`. pub fn op_resources( state: &mut OpState, - _args: Value, + _args: (), _zero_copy: Option<ZeroCopyBuf>, -) -> Result<Value, AnyError> { - let serialized_resources: HashMap<u32, String> = state +) -> Result<Vec<(ResourceId, String)>, AnyError> { + let serialized_resources = state .resource_table .names() .map(|(rid, name)| (rid, name.to_string())) .collect(); - Ok(json!(serialized_resources)) + Ok(serialized_resources) } /// Remove a resource from the resource table. @@ -205,20 +203,17 @@ pub fn op_resources( /// This op must be wrapped in `json_op_sync`. pub fn op_close( state: &mut OpState, - args: Value, + rid: Option<ResourceId>, _zero_copy: Option<ZeroCopyBuf>, -) -> Result<Value, AnyError> { - let rid = args - .get("rid") - .and_then(Value::as_u64) - .ok_or_else(|| type_error("missing or invalid `rid`"))?; - +) -> Result<(), AnyError> { + // TODO(@AaronO): drop Option after improving type-strictness balance in serde_v8 + let rid = rid.ok_or_else(|| type_error("missing or invalid `rid`"))?; state .resource_table - .close(rid as u32) + .close(rid) .ok_or_else(bad_resource_id)?; - Ok(json!({})) + Ok(()) } #[cfg(test)] |