-
Notifications
You must be signed in to change notification settings - Fork 5.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
deno_runtime extension_with_ops example fails to find registered op #22600
Comments
We've started moving away from
|
Thanks @mmastrac, I tried updating the main.js file above to import {
op_hello,
} from "ext:core/ops";
op_hello("World"); And get this error:
Is this what you meant? |
I found a hack/workaround. Things work if I move the import code from
use std::path::Path;
use std::rc::Rc;
use deno_core::error::AnyError;
use deno_core::op2;
use deno_core::FsModuleLoader;
use deno_core::ModuleSpecifier;
use deno_runtime::BootstrapOptions;
use deno_runtime::permissions::PermissionsContainer;
use deno_runtime::worker::MainWorker;
use deno_runtime::worker::WorkerOptions;
deno_core::extension!(hello_runtime, ops = [op_hello]);
#[op2(fast)]
fn op_hello(#[string] text: &str) {
println!("Hello {}!", text);
}
#[tokio::main]
async fn main() -> Result<(), AnyError> {
let js_path = Path::new(env!("CARGO_MANIFEST_DIR"))
.join("src/main.js");
let main_module = ModuleSpecifier::from_file_path(js_path).unwrap();
// main_module.as_str()
let mut worker = MainWorker::bootstrap_from_options(
main_module.clone(),
PermissionsContainer::allow_all(),
WorkerOptions {
module_loader: Rc::new(FsModuleLoader),
extensions: vec![hello_runtime::init_ops()],
bootstrap: BootstrapOptions {
enable_testing_features: true,
..Default::default()
},
..Default::default()
},
);
worker.execute_main_module(&main_module).await?;
worker.run_event_loop(false).await?;
let script_code = r#"
var op_hello;
import("ext:core/ops").then((imported) => {{
op_hello = imported.op_hello;
}})
"#.to_string();
worker.execute_script("ext:<anon>", script_code.into())?;
worker.run_event_loop(false).await?;
let script_code = r#"
op_hello("World");
"#.to_string();
worker.execute_script("ext:<anon>", script_code.into())?;
worker.run_event_loop(false).await?;
Ok(())
}
I think this is enough for our current usecase, but I'd be interested to know if there's a better way to do this. Thanks! |
Ideally you should add some ES modules to your extension, and from those modules re-export the op functions you need. There's an example here -- we need to update this example to the modern style when we have some time (or if you'd like to PR something for it, happy to review it!) https://github.com/denoland/deno_core/blob/main/testing/checkin/runtime/async.ts |
Thanks @mmastrac, I'd be happy to contribute a PR if I figure out how to make this work. When I follow the const { op_hello } = Deno.core.ensureFastOps();
op_hello("Hello") I get an error that |
@mmastrac
but I can't find it anywhere. |
@jonmmease |
Hi @AuTsing, I only worked around it as I described in #22600 (comment), where everything is evaluated from Rust using |
@jonmmease Its a challenge. |
@jonmmease In your case, just make the following modifications.
I think this would be work. |
I'm fixing up the extension example in #22906 -- please let me know if that helps with understanding the op registration. |
) Better example to close #22600 --------- Signed-off-by: Matt Mastracci <matthew@mastracci.com>
Thanks @mmastrac, that's a clear example. |
) Better example to close #22600 --------- Signed-off-by: Matt Mastracci <matthew@mastracci.com>
…oland#22906) Better example to close denoland#22600 --------- Signed-off-by: Matt Mastracci <matthew@mastracci.com>
Thanks @mmastrac, that's very helpful! |
Context
Hi, I'm the maintainer of vl-convert, which is a crate that embeds
deno_runtime
anddeno_core
. When updating from the crate versions associated with Deno 1.38.4 to those associated with Deno 1.41.0, I found that the custom Rust ops that we register are no longer found from within the JavaScript runtime. After investigating a bit more, I'm seeing the same behavior in theextension_with_ops
example as well.I don't know if this is a bug, or if there has been a change in how ops should be registered which isn't reflected in the example, or something else.
Thanks for taking the time to take a look at this!
Setup
Extract the
extension_with_ops
example into a standalone cargo project.Cargo.toml
src/main.rs
(Note modification ofmain.js
path compared to example).src/main.js
Issue
When running this example with
cargo run
, the following panic is displayed.This is the same error I'm seeing when updating vl-convert
The text was updated successfully, but these errors were encountered: