diff options
author | Aaron O'Mullan <aaron.omullan@gmail.com> | 2022-04-02 00:09:21 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-04-02 00:09:21 +0200 |
commit | 25b6b2ed66c001143811efb8b65407b4803e65c4 (patch) | |
tree | 98a629f164f341409f3096df009c4ba93f2613c0 /core | |
parent | 1535fdd94902207bb3a563834700594bb6e8add9 (diff) |
feat(ops): #[op(unstable)] (#14124)
Diffstat (limited to 'core')
-rw-r--r-- | core/extensions.rs | 1 | ||||
-rw-r--r-- | core/runtime.rs | 35 |
2 files changed, 36 insertions, 0 deletions
diff --git a/core/extensions.rs b/core/extensions.rs index 10de66dd2..94453a6e2 100644 --- a/core/extensions.rs +++ b/core/extensions.rs @@ -16,6 +16,7 @@ pub struct OpDecl { pub v8_fn_ptr: OpFnRef, pub enabled: bool, pub is_async: bool, // TODO(@AaronO): enum sync/async/fast ? + pub is_unstable: bool, } impl OpDecl { diff --git a/core/runtime.rs b/core/runtime.rs index fd884a709..bea9908ed 100644 --- a/core/runtime.rs +++ b/core/runtime.rs @@ -3050,4 +3050,39 @@ assertEquals(1, notify_return_value); let scope = &mut runtime.handle_scope(); assert!(r.open(scope).is_undefined()); } + + #[test] + fn test_op_unstable_disabling() { + #[op] + fn op_foo() -> Result<i64, anyhow::Error> { + Ok(42) + } + + #[op(unstable)] + fn op_bar() -> Result<i64, anyhow::Error> { + Ok(42) + } + + let ext = Extension::builder() + .ops(vec![op_foo::decl(), op_bar::decl()]) + .middleware(|op| if op.is_unstable { op.disable() } else { op }) + .build(); + let mut runtime = JsRuntime::new(RuntimeOptions { + extensions: vec![ext], + ..Default::default() + }); + runtime + .execute_script( + "test.js", + r#" + if (Deno.core.opSync('op_foo') !== 42) { + throw new Error("Exptected op_foo() === 42"); + } + if (Deno.core.opSync('op_bar') !== undefined) { + throw new Error("Expected op_bar to be disabled") + } + "#, + ) + .unwrap(); + } } |