mirror of
https://github.com/denoland/deno.git
synced 2024-11-23 15:16:54 -05:00
7c2e7c6608
Provides a concrete state type that can be dynamically added. This is necessary for op crates. * renames BasicState to OpState * async ops take `Rc<RefCell<OpState>>` * sync ops take `&mut OpState` * removes `OpRegistry`, `OpRouter` traits * `get_error_class_fn` moved to OpState * ResourceTable moved to OpState
31 lines
824 B
Rust
31 lines
824 B
Rust
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
|
|
|
|
use std::sync::Arc;
|
|
use std::sync::Mutex;
|
|
|
|
pub fn init(
|
|
rt: &mut deno_core::JsRuntime,
|
|
response: Arc<Mutex<Option<String>>>,
|
|
) {
|
|
let custom_assets = std::collections::HashMap::new();
|
|
// TODO(ry) use None.
|
|
// TODO(bartlomieju): is this op even required?
|
|
rt.register_op(
|
|
"op_fetch_asset",
|
|
crate::op_fetch_asset::op_fetch_asset(custom_assets),
|
|
);
|
|
|
|
super::reg_json_sync(
|
|
rt,
|
|
"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!({}))
|
|
},
|
|
);
|
|
}
|