summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRyan Dahl <ry@tinyclouds.org>2018-07-06 16:26:34 -0400
committerRyan Dahl <ry@tinyclouds.org>2018-07-06 18:25:09 -0400
commita2dde56c5961f451b9042c1f651af372c4984034 (patch)
tree06aaf64e257d9d6bd1f6f16eca2b02aab971c04b
parent9778eceaf5922b1e051859a68b2e02a2f1b1ee8b (diff)
Remove channel parameter from deno_send/recv.
-rw-r--r--Roadmap.md7
-rw-r--r--js/deno.d.ts4
-rw-r--r--js/main.ts2
-rw-r--r--js/mock_runtime.js14
-rw-r--r--src/binding.cc20
-rw-r--r--src/deno.h4
-rw-r--r--src/main.cc6
-rw-r--r--src/mock_runtime_test.cc15
8 files changed, 29 insertions, 43 deletions
diff --git a/Roadmap.md b/Roadmap.md
index 560ed3ffb..69af482e0 100644
--- a/Roadmap.md
+++ b/Roadmap.md
@@ -107,8 +107,7 @@ typedef struct {
size_t len;
} deno_buf;
-typedef void (*deno_sub_cb)(Deno* d, const char* channel,
- deno_buf bufs[], size_t nbufs)
+typedef void (*deno_sub_cb)(Deno* d, deno_buf bufs[], size_t nbufs)
void deno_set_callback(Deno* deno, deno_sub_cb cb);
// Executes javascript source code.
@@ -139,10 +138,10 @@ There are three layers of API to consider:
### L1
```typescript
-function send(channel: string, ...ab: ArrayBuffer[]): ArrayBuffer[] | null;
+function send(...ab: ArrayBuffer[]): ArrayBuffer[] | null;
```
Used to make calls outside of V8. Send an ArrayBuffer and synchronously receive
-an ArrayBuffer back. The channel parameter specifies the purpose of the message.
+an ArrayBuffer back.
```typescript
function poll(): ArrayBuffer[];
diff --git a/js/deno.d.ts b/js/deno.d.ts
index 748ee32ce..f554135bc 100644
--- a/js/deno.d.ts
+++ b/js/deno.d.ts
@@ -1,10 +1,10 @@
// Copyright 2018 Ryan Dahl <ry@tinyclouds.org>
// All rights reserved. MIT License.
-type MessageCallback = (channel: string, msg: ArrayBuffer) => void;
+type MessageCallback = (msg: ArrayBuffer) => void;
interface Deno {
recv(cb: MessageCallback): void;
- send(channel: string, msg: ArrayBuffer): null | ArrayBuffer;
+ send(msg: ArrayBuffer): null | ArrayBuffer;
print(x: string): void;
}
diff --git a/js/main.ts b/js/main.ts
index 6ba38f669..01c3ab9fb 100644
--- a/js/main.ts
+++ b/js/main.ts
@@ -27,7 +27,7 @@ window["denoMain"] = () => {
// First we send an empty "Start" message to let the privlaged side know we
// are ready. The response should be a "StartRes" message containing the CLI
// argv and other info.
- const res = deno.send("start", startMsg());
+ const res = deno.send(startMsg());
// TODO(ry) Remove this conditional once main.rs gets up to speed.
if (res == null) {
diff --git a/js/mock_runtime.js b/js/mock_runtime.js
index 666cabf45..66a34657e 100644
--- a/js/mock_runtime.js
+++ b/js/mock_runtime.js
@@ -28,15 +28,13 @@ global.TypedArraySnapshots = () => {
};
global.SendSuccess = () => {
- deno.recv((channel, msg) => {
- assert(channel === "SendSuccess");
+ deno.recv(msg => {
deno.print("SendSuccess: ok");
});
};
global.SendByteLength = () => {
- deno.recv((channel, msg) => {
- assert(channel === "SendByteLength");
+ deno.recv(msg => {
assert(msg instanceof ArrayBuffer);
assert(msg.byteLength === 3);
});
@@ -45,16 +43,16 @@ global.SendByteLength = () => {
global.RecvReturnEmpty = () => {
const ui8 = new Uint8Array("abc".split("").map(c => c.charCodeAt(0)));
const ab = typedArrayToArrayBuffer(ui8);
- let r = deno.send("RecvReturnEmpty", ab);
+ let r = deno.send(ab);
assert(r == null);
- r = deno.send("RecvReturnEmpty", ab);
+ r = deno.send(ab);
assert(r == null);
};
global.RecvReturnBar = () => {
const ui8 = new Uint8Array("abc".split("").map(c => c.charCodeAt(0)));
const ab = typedArrayToArrayBuffer(ui8);
- const r = deno.send("RecvReturnBar", ab);
+ const r = deno.send(ab);
assert(r instanceof ArrayBuffer);
assert(r.byteLength === 3);
const rui8 = new Uint8Array(r);
@@ -84,7 +82,7 @@ global.ErrorHandling = () => {
assert(line === 3);
assert(col === 1);
assert(error instanceof Error);
- deno.send("ErrorHandling", typedArrayToArrayBuffer(new Uint8Array([42])));
+ deno.send(typedArrayToArrayBuffer(new Uint8Array([42])));
};
eval("\n\n notdefined()\n//# sourceURL=helloworld.js");
};
diff --git a/src/binding.cc b/src/binding.cc
index 0bbcf8b94..50b029b90 100644
--- a/src/binding.cc
+++ b/src/binding.cc
@@ -167,15 +167,9 @@ void Send(const v8::FunctionCallbackInfo<v8::Value>& args) {
v8::Locker locker(d->isolate);
v8::EscapableHandleScope handle_scope(isolate);
- CHECK_EQ(args.Length(), 2);
- v8::Local<v8::Value> channel_v = args[0];
- CHECK(channel_v->IsString());
- v8::String::Utf8Value channel_vstr(isolate, channel_v);
- const char* channel = *channel_vstr;
-
- v8::Local<v8::Value> ab_v = args[1];
+ CHECK_EQ(args.Length(), 1);
+ v8::Local<v8::Value> ab_v = args[0];
CHECK(ab_v->IsArrayBuffer());
-
auto ab = v8::Local<v8::ArrayBuffer>::Cast(ab_v);
auto contents = ab->GetContents();
@@ -187,7 +181,7 @@ void Send(const v8::FunctionCallbackInfo<v8::Value>& args) {
DCHECK_EQ(d->currentArgs, nullptr);
d->currentArgs = &args;
- d->cb(d, channel, buf);
+ d->cb(d, buf);
d->currentArgs = nullptr;
}
@@ -293,7 +287,7 @@ int deno_execute(Deno* d, const char* js_filename, const char* js_source) {
return deno::Execute(context, js_filename, js_source) ? 1 : 0;
}
-int deno_send(Deno* d, const char* channel, deno_buf buf) {
+int deno_send(Deno* d, deno_buf buf) {
v8::Locker locker(d->isolate);
v8::Isolate::Scope isolate_scope(d->isolate);
v8::HandleScope handle_scope(d->isolate);
@@ -313,10 +307,8 @@ int deno_send(Deno* d, const char* channel, deno_buf buf) {
auto ab = v8::ArrayBuffer::New(d->isolate, buf.len);
memcpy(ab->GetContents().Data(), buf.data, buf.len);
- v8::Local<v8::Value> args[2];
- args[0] = deno::v8_str(channel);
- args[1] = ab;
-
+ v8::Local<v8::Value> args[1];
+ args[0] = ab;
recv->Call(context->Global(), 1, args);
if (try_catch.HasCaught()) {
diff --git a/src/deno.h b/src/deno.h
index 605a76456..fd2b4766a 100644
--- a/src/deno.h
+++ b/src/deno.h
@@ -20,7 +20,7 @@ typedef struct deno_s Deno;
// A callback to receive a message from deno.send javascript call.
// buf is valid only for the lifetime of the call.
-typedef void (*deno_recv_cb)(Deno* d, const char* channel, deno_buf buf);
+typedef void (*deno_recv_cb)(Deno* d, deno_buf buf);
void deno_init();
const char* deno_v8_version();
@@ -37,7 +37,7 @@ int deno_execute(Deno* d, const char* js_filename, const char* js_source);
// Routes message to the javascript callback set with deno.recv(). A false
// return value indicates error. Check deno_last_exception() for exception text.
// 0 = fail, 1 = success
-int deno_send(Deno* d, const char* channel, deno_buf buf);
+int deno_send(Deno* d, deno_buf buf);
// Call this inside a deno_recv_cb to respond synchronously to messages.
// If this is not called during the life time of a deno_recv_cb callback
diff --git a/src/main.cc b/src/main.cc
index 9dee442df..78c86ee15 100644
--- a/src/main.cc
+++ b/src/main.cc
@@ -53,7 +53,7 @@ void HandleCodeFetch(Deno* d, const CodeFetch* msg) {
handle_code_fetch(module_specifier, containing_file);
}
-void MessagesFromJS(Deno* d, const char* channel, deno_buf buf) {
+void MessagesFromJS(Deno* d, deno_buf buf) {
auto data = reinterpret_cast<const uint8_t*>(buf.data);
flatbuffers::Verifier verifier(data, buf.len);
DCHECK(verifier.VerifyBuffer<Base>());
@@ -61,8 +61,8 @@ void MessagesFromJS(Deno* d, const char* channel, deno_buf buf) {
auto base = flatbuffers::GetRoot<Base>(buf.data);
auto msg_type = base->msg_type();
const char* msg_type_name = EnumNamesAny()[msg_type];
- printf("MessagesFromJS channel %s, msg_type = %d, msg_type_name = %s\n",
- channel, msg_type, msg_type_name);
+ printf("MessagesFromJS msg_type = %d, msg_type_name = %s\n", msg_type,
+ msg_type_name);
switch (msg_type) {
case Any_Start:
HandleStart(d);
diff --git a/src/mock_runtime_test.cc b/src/mock_runtime_test.cc
index d3d9df2a6..67b097e8d 100644
--- a/src/mock_runtime_test.cc
+++ b/src/mock_runtime_test.cc
@@ -28,7 +28,7 @@ deno_buf strbuf(const char* str) { return deno_buf{str, strlen(str)}; }
TEST(MockRuntimeTest, SendSuccess) {
Deno* d = deno_new(nullptr, nullptr);
EXPECT_TRUE(deno_execute(d, "a.js", "SendSuccess()"));
- EXPECT_TRUE(deno_send(d, "SendSuccess", strbuf("abc")));
+ EXPECT_TRUE(deno_send(d, strbuf("abc")));
deno_delete(d);
}
@@ -36,22 +36,21 @@ TEST(MockRuntimeTest, SendByteLength) {
Deno* d = deno_new(nullptr, nullptr);
EXPECT_TRUE(deno_execute(d, "a.js", "SendByteLength()"));
// We pub the wrong sized message, it should throw.
- EXPECT_FALSE(deno_send(d, "SendByteLength", strbuf("abcd")));
+ EXPECT_FALSE(deno_send(d, strbuf("abcd")));
deno_delete(d);
}
TEST(MockRuntimeTest, SendNoCallback) {
Deno* d = deno_new(nullptr, nullptr);
// We didn't call deno.recv() in JS, should fail.
- EXPECT_FALSE(deno_send(d, "SendNoCallback", strbuf("abc")));
+ EXPECT_FALSE(deno_send(d, strbuf("abc")));
deno_delete(d);
}
TEST(MockRuntimeTest, RecvReturnEmpty) {
static int count = 0;
- Deno* d = deno_new(nullptr, [](auto _, auto channel, auto buf) {
+ Deno* d = deno_new(nullptr, [](auto _, auto buf) {
count++;
- EXPECT_STREQ(channel, "RecvReturnEmpty");
EXPECT_EQ(static_cast<size_t>(3), buf.len);
EXPECT_EQ(buf.data[0], 'a');
EXPECT_EQ(buf.data[1], 'b');
@@ -64,9 +63,8 @@ TEST(MockRuntimeTest, RecvReturnEmpty) {
TEST(MockRuntimeTest, RecvReturnBar) {
static int count = 0;
- Deno* d = deno_new(nullptr, [](auto deno, auto channel, auto buf) {
+ Deno* d = deno_new(nullptr, [](auto deno, auto buf) {
count++;
- EXPECT_STREQ(channel, "RecvReturnBar");
EXPECT_EQ(static_cast<size_t>(3), buf.len);
EXPECT_EQ(buf.data[0], 'a');
EXPECT_EQ(buf.data[1], 'b');
@@ -98,9 +96,8 @@ TEST(MockRuntimeTest, SnapshotBug) {
TEST(MockRuntimeTest, ErrorHandling) {
static int count = 0;
- Deno* d = deno_new(nullptr, [](auto deno, auto channel, auto buf) {
+ Deno* d = deno_new(nullptr, [](auto deno, auto buf) {
count++;
- EXPECT_STREQ(channel, "ErrorHandling");
EXPECT_EQ(static_cast<size_t>(1), buf.len);
EXPECT_EQ(buf.data[0], 42);
});