diff options
author | Jan Haller <bromeon@gmail.com> | 2020-11-06 02:26:14 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-11-06 12:26:14 +1100 |
commit | 6162807a7e8971524c9d8df746916be83d81b649 (patch) | |
tree | 61615feab63ec21682f8fcb2a11ae5f6df392396 /core/runtime.rs | |
parent | 5f7c80986fd9cff6a65d4e419fc2972abe992ccf (diff) |
docs(core): document several concepts around JsRuntime and ops (#7897)
Diffstat (limited to 'core/runtime.rs')
-rw-r--r-- | core/runtime.rs | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/core/runtime.rs b/core/runtime.rs index 0fa465bf2..9766f71fa 100644 --- a/core/runtime.rs +++ b/core/runtime.rs @@ -191,6 +191,7 @@ pub struct RuntimeOptions { } impl JsRuntime { + /// Only constructor, configuration is done through `options`. pub fn new(mut options: RuntimeOptions) -> Self { static DENO_INIT: Once = Once::new(); DENO_INIT.call_once(|| { @@ -320,6 +321,8 @@ impl JsRuntime { } } + /// Returns the runtime's op state, which can be used to maintain ops + /// and access resources between op calls. pub fn op_state(&mut self) -> Rc<RefCell<OpState>> { let state_rc = Self::state(self.v8_isolate()); let state = state_rc.borrow(); @@ -328,6 +331,9 @@ impl JsRuntime { /// Executes traditional JavaScript code (traditional = not ES modules) /// + /// The execution takes place on the current global context, so it is possible + /// to maintain local JS state and invoke this method multiple times. + /// /// `AnyError` can be downcast to a type that exposes additional information /// about the V8 exception. By default this type is `JsError`, however it may /// be a different type if `RuntimeOptions::js_error_create_fn` has been set. @@ -391,6 +397,15 @@ impl JsRuntime { snapshot } + /// Registers an op that can be called from JavaScript. + /// + /// The _op_ mechanism allows to expose Rust functions to the JS runtime, + /// which can be called using the provided `name`. + /// + /// This function provides byte-level bindings. To pass data via JSON, the + /// following functions can be passed as an argument for `op_fn`: + /// * [json_op_sync()](fn.json_op_sync.html) + /// * [json_op_async()](fn.json_op_async.html) pub fn register_op<F>(&mut self, name: &str, op_fn: F) -> OpId where F: Fn(Rc<RefCell<OpState>>, BufVec) -> Op + 'static, |