-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use gotham-like state for ops (#7385)
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
- Loading branch information
Showing
44 changed files
with
1,573 additions
and
1,345 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,31 @@ | ||
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license. | ||
|
||
use crate::state::State; | ||
use deno_core::OpRegistry; | ||
use std::rc::Rc; | ||
use std::sync::Arc; | ||
use std::sync::Mutex; | ||
|
||
pub fn init(s: &Rc<State>, response: Arc<Mutex<Option<String>>>) { | ||
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? | ||
s.register_op( | ||
rt.register_op( | ||
"op_fetch_asset", | ||
crate::op_fetch_asset::op_fetch_asset(custom_assets), | ||
); | ||
|
||
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!({})) | ||
}); | ||
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!({})) | ||
}, | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.