Skip to content
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

example: prototype op crate #3031

Closed
wants to merge 14 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
prototype op_hello
ry committed Sep 26, 2019
commit 282b175e9402b7270a00fa7d286fbed31e6c9b04
13 changes: 13 additions & 0 deletions op_hello/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[package]
name = "op_hello"
version = "0.1.0"
authors = ["Ryan Dahl <[email protected]>"]
edition = "2018"

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

[dependencies]
deno = "0.19.0"

[dev-dependencies]
deno_typescript = "0.19.0"
5 changes: 5 additions & 0 deletions op_hello/src/hello.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
const OP_HELLO = Deno.ops.add("hello");

export function hello() {
Deno.send(OP_HELLO);
}
24 changes: 24 additions & 0 deletions op_hello/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
extern crate deno;
use deno::*;

pub fn init(&mut isolate: Isolate) {
isolate.register_op("hello", op_hello);
}

fn op_hello(_control_buf: &[u8], _zero_copy_buf: Option<PinnedBuf>) -> CoreOp {
println!("Hello world");
CoreOp::Sync(Box::new([]))
}

#[test]
fn basic_test() {
match op_hello() {
CoreOp::Sync(buf) => {
assert_eq!(buf.len(), 0);
}
CoreOp::Async(_) => {
unreachable!()
}
}
}