summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRyan Dahl <ry@tinyclouds.org>2018-06-11 19:18:53 +0200
committerRyan Dahl <ry@tinyclouds.org>2018-06-11 19:19:34 +0200
commit2443f7efee9c04f9331743a5e7ca5c71396f2004 (patch)
tree3f530649b1e41ceed21c4c26902e4b6672b589de
parent9590c87c623ba9654f332e26ba10370915e7ade9 (diff)
Use pub/sub instead of send/recv
-rw-r--r--deno2/deno.cc32
-rw-r--r--deno2/deno_internal.h14
-rw-r--r--deno2/from_snapshot.cc4
-rw-r--r--deno2/include/deno.h6
-rw-r--r--deno2/js/mock_runtime.js4
-rw-r--r--deno2/mock_runtime_test.cc20
6 files changed, 40 insertions, 40 deletions
diff --git a/deno2/deno.cc b/deno2/deno.cc
index 0c9bbd918..e158a0e9a 100644
--- a/deno2/deno.cc
+++ b/deno2/deno.cc
@@ -109,8 +109,8 @@ void Print(const v8::FunctionCallbackInfo<v8::Value>& args) {
fflush(stdout);
}
-// Sets the recv callback.
-void Recv(const v8::FunctionCallbackInfo<v8::Value>& args) {
+// Sets the sub callback.
+void Sub(const v8::FunctionCallbackInfo<v8::Value>& args) {
v8::Isolate* isolate = args.GetIsolate();
Deno* d = reinterpret_cast<Deno*>(isolate->GetData(0));
assert(d->isolate == isolate);
@@ -121,11 +121,11 @@ void Recv(const v8::FunctionCallbackInfo<v8::Value>& args) {
assert(v->IsFunction());
v8::Local<v8::Function> func = v8::Local<v8::Function>::Cast(v);
- d->recv.Reset(isolate, func);
+ d->sub.Reset(isolate, func);
}
// Called from JavaScript, routes message to golang.
-void Send(const v8::FunctionCallbackInfo<v8::Value>& args) {
+void Pub(const v8::FunctionCallbackInfo<v8::Value>& args) {
v8::Isolate* isolate = args.GetIsolate();
Deno* d = static_cast<Deno*>(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 8472f4264..52c1770f6 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<v8::Function> recv;
+ v8::Persistent<v8::Function> sub;
v8::Persistent<v8::Context> 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<v8::Value>& args);
-void Recv(const v8::FunctionCallbackInfo<v8::Value>& args);
-void Send(const v8::FunctionCallbackInfo<v8::Value>& args);
+void Sub(const v8::FunctionCallbackInfo<v8::Value>& args);
+void Pub(const v8::FunctionCallbackInfo<v8::Value>& args);
static intptr_t external_references[] = {reinterpret_cast<intptr_t>(Print),
- reinterpret_cast<intptr_t>(Recv),
- reinterpret_cast<intptr_t>(Send), 0};
+ reinterpret_cast<intptr_t>(Sub),
+ reinterpret_cast<intptr_t>(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 3c15cdc77..adb404bf0 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 f67a7cf51..c6bc82e26 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 cdb6031e3..b3ec7f034 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 22b596275..1d8a65457 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);
}