summaryrefslogtreecommitdiff
path: root/cli/ops/resources.rs
diff options
context:
space:
mode:
authorBert Belder <bertbelder@gmail.com>2020-09-06 02:34:02 +0200
committerGitHub <noreply@github.com>2020-09-06 02:34:02 +0200
commitc821e8f2f1fb8ad5e9eb00854277cafc8c80b2f5 (patch)
treec429a3c2707a4047fb512443a8468b7e15e5730d /cli/ops/resources.rs
parent849431eb1d112d1f79f4a327830dc1a5bf22dd47 (diff)
Move JSON ops to deno_core (#7336)
Diffstat (limited to 'cli/ops/resources.rs')
-rw-r--r--cli/ops/resources.rs26
1 files changed, 13 insertions, 13 deletions
diff --git a/cli/ops/resources.rs b/cli/ops/resources.rs
index 0493aeed3..d7c2fd142 100644
--- a/cli/ops/resources.rs
+++ b/cli/ops/resources.rs
@@ -1,33 +1,31 @@
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
-use super::dispatch_json::{Deserialize, Value};
+
use crate::state::State;
-use deno_core::CoreIsolate;
use deno_core::ErrBox;
-use deno_core::ResourceTable;
+use deno_core::OpRegistry;
use deno_core::ZeroCopyBuf;
+use serde_derive::Deserialize;
+use serde_json::Value;
use std::rc::Rc;
-pub fn init(i: &mut CoreIsolate, s: &Rc<State>) {
- let t = &CoreIsolate::state(i).borrow().resource_table.clone();
-
- i.register_op("op_resources", s.stateful_json_op_sync(t, op_resources));
- i.register_op("op_close", s.stateful_json_op_sync(t, op_close));
+pub fn init(s: &Rc<State>) {
+ s.register_op_json_sync("op_resources", op_resources);
+ s.register_op_json_sync("op_close", op_close);
}
fn op_resources(
- _state: &State,
- resource_table: &mut ResourceTable,
+ state: &State,
_args: Value,
_zero_copy: &mut [ZeroCopyBuf],
) -> Result<Value, ErrBox> {
+ let resource_table = state.resource_table.borrow();
let serialized_resources = resource_table.entries();
Ok(json!(serialized_resources))
}
/// op_close removes a resource from the resource table.
fn op_close(
- _state: &State,
- resource_table: &mut ResourceTable,
+ state: &State,
args: Value,
_zero_copy: &mut [ZeroCopyBuf],
) -> Result<Value, ErrBox> {
@@ -36,7 +34,9 @@ fn op_close(
rid: i32,
}
let args: CloseArgs = serde_json::from_value(args)?;
- resource_table
+ state
+ .resource_table
+ .borrow_mut()
.close(args.rid as u32)
.ok_or_else(ErrBox::bad_resource_id)?;
Ok(json!({}))