From b449964d1a8d87d53350c0f9adcf1227e6fd3eef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartek=20Iwa=C5=84czuk?= Date: Thu, 23 Jul 2020 15:29:36 +0200 Subject: refactor: remove more compiler runtime code (#6841) --- cli/ops/compiler.rs | 52 +++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 51 insertions(+), 1 deletion(-) (limited to 'cli/ops/compiler.rs') diff --git a/cli/ops/compiler.rs b/cli/ops/compiler.rs index 9e56ef436..5af2f5eb0 100644 --- a/cli/ops/compiler.rs +++ b/cli/ops/compiler.rs @@ -1,8 +1,20 @@ // Copyright 2018-2020 the Deno authors. All rights reserved. MIT license. +use super::dispatch_json::{JsonOp, Value}; +use crate::op_error::OpError; +use crate::ops::json_op; +use crate::ops::JsonOpDispatcher; use crate::state::State; use deno_core::CoreIsolate; +use deno_core::CoreIsolateState; +use deno_core::ZeroCopyBuf; +use std::sync::Arc; +use std::sync::Mutex; -pub fn init(i: &mut CoreIsolate, _s: &State) { +pub fn init( + i: &mut CoreIsolate, + _s: &State, + response: Arc>>, +) { let custom_assets = std::collections::HashMap::new(); // TODO(ry) use None. // TODO(bartlomieju): is this op even required? @@ -10,4 +22,42 @@ pub fn init(i: &mut CoreIsolate, _s: &State) { "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( + response: Arc>>, + dispatcher: D, +) -> impl JsonOpDispatcher +where + D: Fn( + Arc>>, + Value, + &mut [ZeroCopyBuf], + ) -> Result, +{ + move |_isolate_state: &mut CoreIsolateState, + args: Value, + zero_copy: &mut [ZeroCopyBuf]| + -> Result { + dispatcher(response.clone(), args, zero_copy) + } +} + +fn op_compiler_respond( + response: Arc>>, + args: Value, + _zero_copy: &mut [ZeroCopyBuf], +) -> Result { + 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!({}))) } -- cgit v1.2.3