summaryrefslogtreecommitdiff
path: root/core/runtime.rs
diff options
context:
space:
mode:
Diffstat (limited to 'core/runtime.rs')
-rw-r--r--core/runtime.rs35
1 files changed, 35 insertions, 0 deletions
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();
+ }
}