summaryrefslogtreecommitdiff
path: root/cli/ops/compiler.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/compiler.rs
parent849431eb1d112d1f79f4a327830dc1a5bf22dd47 (diff)
Move JSON ops to deno_core (#7336)
Diffstat (limited to 'cli/ops/compiler.rs')
-rw-r--r--cli/ops/compiler.rs66
1 files changed, 13 insertions, 53 deletions
diff --git a/cli/ops/compiler.rs b/cli/ops/compiler.rs
index c35043e2d..0b8379fa3 100644
--- a/cli/ops/compiler.rs
+++ b/cli/ops/compiler.rs
@@ -1,67 +1,27 @@
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
-use super::dispatch_json::{JsonOp, Value};
-use crate::ops::json_op;
+
use crate::state::State;
-use deno_core::CoreIsolate;
-use deno_core::CoreIsolateState;
-use deno_core::ErrBox;
-use deno_core::ZeroCopyBuf;
+use deno_core::OpRegistry;
use std::rc::Rc;
use std::sync::Arc;
use std::sync::Mutex;
-pub fn init(
- i: &mut CoreIsolate,
- _s: &Rc<State>,
- response: Arc<Mutex<Option<String>>>,
-) {
+pub fn init(s: &Rc<State>, response: Arc<Mutex<Option<String>>>) {
let custom_assets = std::collections::HashMap::new();
// TODO(ry) use None.
// TODO(bartlomieju): is this op even required?
- i.register_op(
+ s.register_op(
"op_fetch_asset",
crate::op_fetch_asset::op_fetch_asset(custom_assets),
);
- i.register_op(
- "op_compiler_respond",
- json_op(compiler_op(response, op_compiler_respond)),
- );
-}
-
-pub fn compiler_op<D>(
- response: Arc<Mutex<Option<String>>>,
- dispatcher: D,
-) -> impl Fn(
- &mut deno_core::CoreIsolateState,
- Value,
- &mut [ZeroCopyBuf],
-) -> Result<JsonOp, ErrBox>
-where
- D: Fn(
- Arc<Mutex<Option<String>>>,
- Value,
- &mut [ZeroCopyBuf],
- ) -> Result<JsonOp, ErrBox>,
-{
- move |_isolate_state: &mut CoreIsolateState,
- args: Value,
- zero_copy: &mut [ZeroCopyBuf]|
- -> Result<JsonOp, ErrBox> {
- dispatcher(response.clone(), args, zero_copy)
- }
-}
-
-fn op_compiler_respond(
- response: Arc<Mutex<Option<String>>>,
- args: Value,
- _zero_copy: &mut [ZeroCopyBuf],
-) -> Result<JsonOp, ErrBox> {
- let mut r = response.lock().unwrap();
- assert!(
- r.is_none(),
- "op_compiler_respond found unexpected existing compiler output"
- );
- *r = Some(args.to_string());
- Ok(JsonOp::Sync(json!({})))
+ s.register_op_json_sync("op_compiler_respond", move |_state, args, _bufs| {
+ let mut response_slot = response.lock().unwrap();
+ let replaced_value = response_slot.replace(args.to_string());
+ assert!(
+ replaced_value.is_none(),
+ "op_compiler_respond found unexpected existing compiler output",
+ );
+ Ok(json!({}))
+ });
}