2020-01-02 15:13:47 -05:00
|
|
|
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
|
2020-07-23 09:29:36 -04:00
|
|
|
use super::dispatch_json::{JsonOp, Value};
|
|
|
|
use crate::op_error::OpError;
|
|
|
|
use crate::ops::json_op;
|
2020-02-08 14:34:31 -05:00
|
|
|
use crate::state::State;
|
2020-04-23 05:51:07 -04:00
|
|
|
use deno_core::CoreIsolate;
|
2020-07-23 09:29:36 -04:00
|
|
|
use deno_core::CoreIsolateState;
|
|
|
|
use deno_core::ZeroCopyBuf;
|
2020-08-18 12:30:13 -04:00
|
|
|
use std::rc::Rc;
|
2020-07-23 09:29:36 -04:00
|
|
|
use std::sync::Arc;
|
|
|
|
use std::sync::Mutex;
|
2019-08-26 08:50:21 -04:00
|
|
|
|
2020-07-23 09:29:36 -04:00
|
|
|
pub fn init(
|
|
|
|
i: &mut CoreIsolate,
|
2020-08-18 12:30:13 -04:00
|
|
|
_s: &Rc<State>,
|
2020-07-23 09:29:36 -04:00
|
|
|
response: Arc<Mutex<Option<String>>>,
|
|
|
|
) {
|
2020-05-18 06:59:29 -04:00
|
|
|
let custom_assets = std::collections::HashMap::new();
|
|
|
|
// TODO(ry) use None.
|
|
|
|
// TODO(bartlomieju): is this op even required?
|
2019-10-11 14:41:54 -04:00
|
|
|
i.register_op(
|
2020-02-25 09:14:27 -05:00
|
|
|
"op_fetch_asset",
|
2020-07-20 19:49:57 -04:00
|
|
|
crate::op_fetch_asset::op_fetch_asset(custom_assets),
|
2020-02-19 00:34:11 -05:00
|
|
|
);
|
2020-07-23 09:29:36 -04:00
|
|
|
|
|
|
|
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,
|
2020-08-12 10:44:58 -04:00
|
|
|
) -> impl Fn(
|
|
|
|
&mut deno_core::CoreIsolateState,
|
|
|
|
Value,
|
|
|
|
&mut [ZeroCopyBuf],
|
|
|
|
) -> Result<JsonOp, OpError>
|
2020-07-23 09:29:36 -04:00
|
|
|
where
|
|
|
|
D: Fn(
|
|
|
|
Arc<Mutex<Option<String>>>,
|
|
|
|
Value,
|
|
|
|
&mut [ZeroCopyBuf],
|
|
|
|
) -> Result<JsonOp, OpError>,
|
|
|
|
{
|
|
|
|
move |_isolate_state: &mut CoreIsolateState,
|
|
|
|
args: Value,
|
|
|
|
zero_copy: &mut [ZeroCopyBuf]|
|
|
|
|
-> Result<JsonOp, OpError> {
|
|
|
|
dispatcher(response.clone(), args, zero_copy)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn op_compiler_respond(
|
|
|
|
response: Arc<Mutex<Option<String>>>,
|
|
|
|
args: Value,
|
|
|
|
_zero_copy: &mut [ZeroCopyBuf],
|
|
|
|
) -> Result<JsonOp, OpError> {
|
|
|
|
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!({})))
|
2019-10-11 14:41:54 -04:00
|
|
|
}
|