Skip to content

Commit

Permalink
wip: add test plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
afinch7 committed Nov 18, 2019
1 parent 87f9a8c commit 4cdeeb2
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 0 deletions.
7 changes: 7 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ members = [
"core",
"tools/hyper_hello",
"deno_typescript",
"cli/tests/test_native_plugin"
]
13 changes: 13 additions & 0 deletions cli/tests/test_native_plugin/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[package]
name = "test_native_plugin"
version = "0.1.0"
authors = ["afinch7 <andyfinch7@gmail.com>"]
edition = "2018"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[lib]
crate-type = ["cdylib"]

[dependencies]
deno = { path = "../../../core" }
6 changes: 6 additions & 0 deletions cli/tests/test_native_plugin/mod.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
const plugin = Deno.openPlugin(
"./../../../target/debug/libtest_native_plugin.so"
);
const op_test_io_async = plugin.ops.op_test_io_async;

console.log(op_test_io_async);
26 changes: 26 additions & 0 deletions cli/tests/test_native_plugin/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
use deno::CoreOp;
use deno::Op;
use deno::PluginInitContext;
use deno::{Buf, PinnedBuf};

#[macro_use]
extern crate deno;

fn init(context: &mut dyn PluginInitContext) {
context.register_op("test_io_sync", Box::new(op_test_io_sync));
}
init_fn!(init);

pub fn op_test_io_sync(data: &[u8], zero_copy: Option<PinnedBuf>) -> CoreOp {
if let Some(buf) = zero_copy {
let data_str = std::str::from_utf8(&data[..]).unwrap();
let buf_str = std::str::from_utf8(&buf[..]).unwrap();
println!(
"Hello from native bindings. data: {} | zero_copy: {}",
data_str, buf_str
);
}
let result = b"test";
let result_box: Buf = Box::new(*result);
Op::Sync(result_box)
}
1 change: 1 addition & 0 deletions cli/worker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ impl Worker {
ops::files::init(&mut i, &state);
ops::fs::init(&mut i, &state);
ops::io::init(&mut i, &state);
ops::native_plugins::init(&mut i, &state, isolate.clone());
ops::net::init(&mut i, &state);
ops::tls::init(&mut i, &state);
ops::os::init(&mut i, &state);
Expand Down

0 comments on commit 4cdeeb2

Please sign in to comment.