2023-01-02 16:00:42 -05:00
|
|
|
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
|
2021-08-31 07:08:16 -04:00
|
|
|
//! This example shows you how to define ops in Rust and then call them from
|
|
|
|
//! JavaScript.
|
|
|
|
|
|
|
|
use deno_core::Extension;
|
|
|
|
use deno_core::JsRuntime;
|
|
|
|
use deno_core::RuntimeOptions;
|
|
|
|
|
|
|
|
fn main() {
|
2023-01-08 17:48:46 -05:00
|
|
|
let my_ext = Extension::builder("my_ext")
|
2022-03-15 18:43:17 -04:00
|
|
|
.middleware(|op| match op.name {
|
2022-03-22 11:39:58 -04:00
|
|
|
"op_print" => op.disable(),
|
2022-03-15 18:43:17 -04:00
|
|
|
_ => op,
|
2021-08-31 07:08:16 -04:00
|
|
|
})
|
|
|
|
.build();
|
|
|
|
|
|
|
|
// Initialize a runtime instance
|
|
|
|
let mut runtime = JsRuntime::new(RuntimeOptions {
|
|
|
|
extensions: vec![my_ext],
|
|
|
|
..Default::default()
|
|
|
|
});
|
|
|
|
|
|
|
|
// Deno.core.print() will now be a NOP
|
|
|
|
runtime
|
2023-04-04 08:46:31 -04:00
|
|
|
.execute_script_static("<usage>", r#"Deno.core.print("I'm broken")"#)
|
2021-08-31 07:08:16 -04:00
|
|
|
.unwrap();
|
|
|
|
}
|