2020-01-02 15:13:47 -05:00
|
|
|
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
|
2019-08-14 11:03:02 -04:00
|
|
|
|
2019-10-01 18:51:05 -04:00
|
|
|
pub mod errors;
|
2020-01-21 11:50:06 -05:00
|
|
|
pub mod runtime_compiler;
|
2020-09-10 09:57:45 -04:00
|
|
|
|
2020-09-14 12:48:57 -04:00
|
|
|
use deno_core::error::AnyError;
|
2020-09-10 09:57:45 -04:00
|
|
|
use deno_core::json_op_async;
|
|
|
|
use deno_core::json_op_sync;
|
2020-09-21 12:36:37 -04:00
|
|
|
use deno_core::serde_json::Value;
|
2020-09-10 09:57:45 -04:00
|
|
|
use deno_core::BufVec;
|
|
|
|
use deno_core::JsRuntime;
|
|
|
|
use deno_core::OpState;
|
|
|
|
use deno_core::ZeroCopyBuf;
|
2020-12-13 13:45:53 -05:00
|
|
|
use deno_runtime::metrics::metrics_op;
|
2020-09-10 09:57:45 -04:00
|
|
|
use std::cell::RefCell;
|
|
|
|
use std::future::Future;
|
|
|
|
use std::rc::Rc;
|
|
|
|
|
|
|
|
pub fn reg_json_async<F, R>(rt: &mut JsRuntime, name: &'static str, op_fn: F)
|
|
|
|
where
|
|
|
|
F: Fn(Rc<RefCell<OpState>>, Value, BufVec) -> R + 'static,
|
2020-09-14 12:48:57 -04:00
|
|
|
R: Future<Output = Result<Value, AnyError>> + 'static,
|
2020-09-10 09:57:45 -04:00
|
|
|
{
|
|
|
|
rt.register_op(name, metrics_op(json_op_async(op_fn)));
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn reg_json_sync<F>(rt: &mut JsRuntime, name: &'static str, op_fn: F)
|
|
|
|
where
|
2020-09-14 12:48:57 -04:00
|
|
|
F: Fn(&mut OpState, Value, &mut [ZeroCopyBuf]) -> Result<Value, AnyError>
|
2020-09-10 09:57:45 -04:00
|
|
|
+ 'static,
|
|
|
|
{
|
|
|
|
rt.register_op(name, metrics_op(json_op_sync(op_fn)));
|
|
|
|
}
|