summaryrefslogtreecommitdiff
path: root/core/ops.rs
diff options
context:
space:
mode:
authorAaron O'Mullan <aaron.omullan@gmail.com>2021-04-06 05:17:00 +0200
committerGitHub <noreply@github.com>2021-04-05 23:17:00 -0400
commit91e80ada8a323a6526f760d41f2ebc481814e843 (patch)
tree9eed0f428d921f561e0ded092d6cda14a381d2ca /core/ops.rs
parentd849c87eb16a4bebee1a09c171dbdae6a4924a55 (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
Diffstat (limited to 'core/ops.rs')
-rw-r--r--core/ops.rs27
1 files changed, 11 insertions, 16 deletions
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)]