summaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
authorAaron O'Mullan <aaron.omullan@gmail.com>2022-03-16 00:33:46 +0100
committerGitHub <noreply@github.com>2022-03-16 00:33:46 +0100
commitbd481bf095f920a419ea55543f911e087f98f36f (patch)
treeb4f97aabfd3734770c5367b1253511a02d86af87 /core
parent672f66dde1f7ec87282d37e10cac2cdd36e5f181 (diff)
feat(ops): optional OpState (#13954)
Diffstat (limited to 'core')
-rw-r--r--core/examples/hello_world.rs5
-rw-r--r--core/ops_builtin.rs8
-rw-r--r--core/runtime.rs14
3 files changed, 9 insertions, 18 deletions
diff --git a/core/examples/hello_world.rs b/core/examples/hello_world.rs
index d5d7af94d..e551efa55 100644
--- a/core/examples/hello_world.rs
+++ b/core/examples/hello_world.rs
@@ -14,10 +14,7 @@ use deno_core::RuntimeOptions;
use deno_core::*;
#[op]
-fn op_sum(
- _state: &mut OpState,
- nums: Vec<f64>,
-) -> Result<f64, deno_core::error::AnyError> {
+fn op_sum(nums: Vec<f64>) -> Result<f64, deno_core::error::AnyError> {
// Sum inputs
let sum = nums.iter().fold(0.0, |a, v| a + v);
// return as a Result<f64, AnyError>
diff --git a/core/ops_builtin.rs b/core/ops_builtin.rs
index 92f77f954..d8729688e 100644
--- a/core/ops_builtin.rs
+++ b/core/ops_builtin.rs
@@ -54,7 +54,7 @@ pub fn op_resources(
}
#[op]
-pub fn op_void_sync(_state: &mut OpState) -> Result<(), Error> {
+pub fn op_void_sync() -> Result<(), Error> {
Ok(())
}
@@ -101,11 +101,7 @@ pub fn op_metrics(
/// Builtin utility to print to stdout/stderr
#[op]
-pub fn op_print(
- _state: &mut OpState,
- msg: String,
- is_err: bool,
-) -> Result<(), Error> {
+pub fn op_print(msg: String, is_err: bool) -> Result<(), Error> {
if is_err {
stderr().write_all(msg.as_bytes())?;
stderr().flush().unwrap();
diff --git a/core/runtime.rs b/core/runtime.rs
index 17840a2d0..8ec3dfb08 100644
--- a/core/runtime.rs
+++ b/core/runtime.rs
@@ -2088,7 +2088,7 @@ pub mod tests {
#[test]
fn test_error_builder() {
#[op]
- fn op_err(_: &mut OpState) -> Result<(), Error> {
+ fn op_err() -> Result<(), Error> {
Err(custom_error("DOMExceptionOperationError", "abc"))
}
@@ -2533,9 +2533,7 @@ assertEquals(1, notify_return_value);
#[tokio::test]
async fn test_set_macrotask_callback_set_next_tick_callback() {
#[op]
- async fn op_async_sleep(
- _op_state: Rc<RefCell<OpState>>,
- ) -> Result<(), Error> {
+ async fn op_async_sleep() -> Result<(), Error> {
// Future must be Poll::Pending on first call
tokio::time::sleep(std::time::Duration::from_millis(1)).await;
Ok(())
@@ -2610,13 +2608,13 @@ assertEquals(1, notify_return_value);
static NEXT_TICK: AtomicUsize = AtomicUsize::new(0);
#[op]
- fn op_macrotask(_: &mut OpState) -> Result<(), AnyError> {
+ fn op_macrotask() -> Result<(), AnyError> {
MACROTASK.fetch_add(1, Ordering::Relaxed);
Ok(())
}
#[op]
- fn op_next_tick(_: &mut OpState) -> Result<(), AnyError> {
+ fn op_next_tick() -> Result<(), AnyError> {
NEXT_TICK.fetch_add(1, Ordering::Relaxed);
Ok(())
}
@@ -2747,13 +2745,13 @@ assertEquals(1, notify_return_value);
static UNCAUGHT_EXCEPTION: AtomicUsize = AtomicUsize::new(0);
#[op]
- fn op_promise_reject(_: &mut OpState) -> Result<(), AnyError> {
+ fn op_promise_reject() -> Result<(), AnyError> {
PROMISE_REJECT.fetch_add(1, Ordering::Relaxed);
Ok(())
}
#[op]
- fn op_uncaught_exception(_: &mut OpState) -> Result<(), AnyError> {
+ fn op_uncaught_exception() -> Result<(), AnyError> {
UNCAUGHT_EXCEPTION.fetch_add(1, Ordering::Relaxed);
Ok(())
}