diff --git a/deno2/deno.cc b/deno2/deno.cc index 0c9bbd9185..e158a0e9a3 100644 --- a/deno2/deno.cc +++ b/deno2/deno.cc @@ -109,8 +109,8 @@ void Print(const v8::FunctionCallbackInfo& args) { fflush(stdout); } -// Sets the recv callback. -void Recv(const v8::FunctionCallbackInfo& args) { +// Sets the sub callback. +void Sub(const v8::FunctionCallbackInfo& args) { v8::Isolate* isolate = args.GetIsolate(); Deno* d = reinterpret_cast(isolate->GetData(0)); assert(d->isolate == isolate); @@ -121,11 +121,11 @@ void Recv(const v8::FunctionCallbackInfo& args) { assert(v->IsFunction()); v8::Local func = v8::Local::Cast(v); - d->recv.Reset(isolate, func); + d->sub.Reset(isolate, func); } // Called from JavaScript, routes message to golang. -void Send(const v8::FunctionCallbackInfo& args) { +void Pub(const v8::FunctionCallbackInfo& args) { v8::Isolate* isolate = args.GetIsolate(); Deno* d = static_cast(isolate->GetData(0)); assert(d->isolate == isolate); @@ -213,13 +213,13 @@ v8::StartupData MakeSnapshot(v8::StartupData* prev_natives_blob, CHECK( global->Set(context, deno::v8_str("deno_print"), print_val).FromJust()); - auto recv_tmpl = v8::FunctionTemplate::New(isolate, Recv); - auto recv_val = recv_tmpl->GetFunction(context).ToLocalChecked(); - CHECK(global->Set(context, deno::v8_str("deno_recv"), recv_val).FromJust()); + auto sub_tmpl = v8::FunctionTemplate::New(isolate, Sub); + auto sub_val = sub_tmpl->GetFunction(context).ToLocalChecked(); + CHECK(global->Set(context, deno::v8_str("deno_sub"), sub_val).FromJust()); - auto send_tmpl = v8::FunctionTemplate::New(isolate, Send); - auto send_val = send_tmpl->GetFunction(context).ToLocalChecked(); - CHECK(global->Set(context, deno::v8_str("deno_send"), send_val).FromJust()); + auto pub_tmpl = v8::FunctionTemplate::New(isolate, Pub); + auto pub_val = pub_tmpl->GetFunction(context).ToLocalChecked(); + CHECK(global->Set(context, deno::v8_str("deno_pub"), pub_val).FromJust()); bool r = Load(context, js_filename, js_source); assert(r); @@ -274,10 +274,10 @@ bool deno_load(Deno* d, const char* name_s, const char* source_s) { return deno::Load(context, name_s, source_s); } -// Routes message to the javascript callback set with deno_recv(). +// Routes message to the javascript callback set with deno_sub(). // False return value indicates error. Check deno_last_exception() for exception // text. Caller owns buf. -bool deno_send(Deno* d, deno_buf buf) { +bool deno_pub(Deno* d, deno_buf buf) { v8::Locker locker(d->isolate); v8::Isolate::Scope isolate_scope(d->isolate); v8::HandleScope handle_scope(d->isolate); @@ -287,9 +287,9 @@ bool deno_send(Deno* d, deno_buf buf) { v8::TryCatch try_catch(d->isolate); - auto recv = d->recv.Get(d->isolate); - if (recv.IsEmpty()) { - d->last_exception = "deno_recv has not been called."; + auto sub = d->sub.Get(d->isolate); + if (sub.IsEmpty()) { + d->last_exception = "deno_sub has not been called."; return false; } @@ -302,7 +302,7 @@ bool deno_send(Deno* d, deno_buf buf) { assert(!args[0].IsEmpty()); assert(!try_catch.HasCaught()); - recv->Call(context->Global(), 1, args); + sub->Call(context->Global(), 1, args); if (try_catch.HasCaught()) { deno::HandleException(context, try_catch.Exception()); diff --git a/deno2/deno_internal.h b/deno2/deno_internal.h index 8472f4264f..52c1770f69 100644 --- a/deno2/deno_internal.h +++ b/deno2/deno_internal.h @@ -12,9 +12,9 @@ extern "C" { struct deno_s { v8::Isolate* isolate; std::string last_exception; - v8::Persistent recv; + v8::Persistent sub; v8::Persistent context; - deno_recv_cb cb; + deno_sub_cb cb; void* data; }; } @@ -22,13 +22,13 @@ struct deno_s { namespace deno { void Print(const v8::FunctionCallbackInfo& args); -void Recv(const v8::FunctionCallbackInfo& args); -void Send(const v8::FunctionCallbackInfo& args); +void Sub(const v8::FunctionCallbackInfo& args); +void Pub(const v8::FunctionCallbackInfo& args); static intptr_t external_references[] = {reinterpret_cast(Print), - reinterpret_cast(Recv), - reinterpret_cast(Send), 0}; + reinterpret_cast(Sub), + reinterpret_cast(Pub), 0}; -Deno* NewFromSnapshot(void* data, deno_recv_cb cb); +Deno* NewFromSnapshot(void* data, deno_sub_cb cb); v8::StartupData MakeSnapshot(v8::StartupData* prev_natives_blob, v8::StartupData* prev_snapshot_blob, diff --git a/deno2/from_snapshot.cc b/deno2/from_snapshot.cc index 3c15cdc77d..adb404bf0e 100644 --- a/deno2/from_snapshot.cc +++ b/deno2/from_snapshot.cc @@ -21,7 +21,7 @@ namespace deno { #include "snapshot_deno.cc" #endif -Deno* NewFromSnapshot(void* data, deno_recv_cb cb) { +Deno* NewFromSnapshot(void* data, deno_sub_cb cb) { auto natives_blob = *StartupBlob_natives(); auto snapshot_blob = *StartupBlob_snapshot(); @@ -52,7 +52,7 @@ Deno* NewFromSnapshot(void* data, deno_recv_cb cb) { } // namespace deno extern "C" { -Deno* deno_new(void* data, deno_recv_cb cb) { +Deno* deno_new(void* data, deno_sub_cb cb) { return deno::NewFromSnapshot(data, cb); } } diff --git a/deno2/include/deno.h b/deno2/include/deno.h index f67a7cf51d..c6bc82e265 100644 --- a/deno2/include/deno.h +++ b/deno2/include/deno.h @@ -18,14 +18,14 @@ struct deno_s; typedef struct deno_s Deno; // The callback from V8 when data is sent. -typedef deno_buf (*deno_recv_cb)(Deno* d, deno_buf buf); +typedef deno_buf (*deno_sub_cb)(Deno* d, deno_buf buf); void deno_init(); const char* deno_v8_version(); void deno_set_flags(int* argc, char** argv); // Constructor -Deno* deno_new(void* data, deno_recv_cb cb); +Deno* deno_new(void* data, deno_sub_cb cb); // Returns false on error. // Get error text with deno_last_exception(). @@ -33,7 +33,7 @@ bool deno_load(Deno* d, const char* name_s, const char* source_s); // Returns false on error. // Get error text with deno_last_exception(). -bool deno_send(Deno* d, deno_buf buf); +bool deno_pub(Deno* d, deno_buf buf); const char* deno_last_exception(Deno* d); diff --git a/deno2/js/mock_runtime.js b/deno2/js/mock_runtime.js index cdb6031e31..b3ec7f0348 100644 --- a/deno2/js/mock_runtime.js +++ b/deno2/js/mock_runtime.js @@ -10,8 +10,8 @@ function assert(cond) { if (!cond) throw Error("mock_runtime.js assert failed"); } -function recvabc() { - deno_recv((msg) => { +function subabc() { + deno_sub((msg) => { assert(msg instanceof ArrayBuffer); assert(msg.byteLength === 3); }); diff --git a/deno2/mock_runtime_test.cc b/deno2/mock_runtime_test.cc index 22b5962753..1d8a654574 100644 --- a/deno2/mock_runtime_test.cc +++ b/deno2/mock_runtime_test.cc @@ -27,25 +27,25 @@ deno_buf strbuf(const char* str) { return deno_buf{d, strlen(str)}; } -TEST(MockRuntimeTest, SendSuccess) { +TEST(MockRuntimeTest, PubSuccess) { Deno* d = deno_new(NULL, NULL); - EXPECT_TRUE(deno_load(d, "a.js", "recvabc();")); - EXPECT_TRUE(deno_send(d, strbuf("abc"))); + EXPECT_TRUE(deno_load(d, "a.js", "subabc();")); + EXPECT_TRUE(deno_pub(d, strbuf("abc"))); deno_dispose(d); } -TEST(MockRuntimeTest, SendByteLength) { +TEST(MockRuntimeTest, PubByteLength) { Deno* d = deno_new(NULL, NULL); - EXPECT_TRUE(deno_load(d, "a.js", "recvabc();")); - // We send the wrong sized message, it should throw. - EXPECT_FALSE(deno_send(d, strbuf("abcd"))); + EXPECT_TRUE(deno_load(d, "a.js", "subabc();")); + // We pub the wrong sized message, it should throw. + EXPECT_FALSE(deno_pub(d, strbuf("abcd"))); deno_dispose(d); } -TEST(MockRuntimeTest, SendNoCallback) { +TEST(MockRuntimeTest, PubNoCallback) { Deno* d = deno_new(NULL, NULL); - // We didn't call deno_recv(), sending should fail. - EXPECT_FALSE(deno_send(d, strbuf("abc"))); + // We didn't call deno_sub(), pubing should fail. + EXPECT_FALSE(deno_pub(d, strbuf("abc"))); deno_dispose(d); }