diff options
author | Ryan Dahl <ry@tinyclouds.org> | 2018-07-06 16:26:34 -0400 |
---|---|---|
committer | Ryan Dahl <ry@tinyclouds.org> | 2018-07-06 18:25:09 -0400 |
commit | a2dde56c5961f451b9042c1f651af372c4984034 (patch) | |
tree | 06aaf64e257d9d6bd1f6f16eca2b02aab971c04b /src | |
parent | 9778eceaf5922b1e051859a68b2e02a2f1b1ee8b (diff) |
Remove channel parameter from deno_send/recv.
Diffstat (limited to 'src')
-rw-r--r-- | src/binding.cc | 20 | ||||
-rw-r--r-- | src/deno.h | 4 | ||||
-rw-r--r-- | src/main.cc | 6 | ||||
-rw-r--r-- | src/mock_runtime_test.cc | 15 |
4 files changed, 17 insertions, 28 deletions
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); }); |