1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-11-24 15:19:26 -05:00

Rename deno_load to deno_execute.

This commit is contained in:
Ryan Dahl 2018-06-11 20:49:57 +02:00
parent 482fc3a2ce
commit 56c3ac464e
3 changed files with 15 additions and 15 deletions

View file

@ -153,8 +153,8 @@ void Pub(const v8::FunctionCallbackInfo<v8::Value>& args) {
} }
} }
bool Load(v8::Local<v8::Context> context, const char* name_s, bool Execute(v8::Local<v8::Context> context, const char* js_filename,
const char* source_s) { const char* js_source) {
auto* isolate = context->GetIsolate(); auto* isolate = context->GetIsolate();
v8::Isolate::Scope isolate_scope(isolate); v8::Isolate::Scope isolate_scope(isolate);
v8::HandleScope handle_scope(isolate); v8::HandleScope handle_scope(isolate);
@ -163,8 +163,8 @@ bool Load(v8::Local<v8::Context> context, const char* name_s,
v8::TryCatch try_catch(isolate); v8::TryCatch try_catch(isolate);
auto name = v8_str(name_s); auto name = v8_str(js_filename);
auto source = v8_str(source_s); auto source = v8_str(js_source);
v8::ScriptOrigin origin(name); v8::ScriptOrigin origin(name);
@ -217,7 +217,7 @@ v8::StartupData MakeSnapshot(v8::StartupData* prev_natives_blob,
auto pub_val = pub_tmpl->GetFunction(context).ToLocalChecked(); auto pub_val = pub_tmpl->GetFunction(context).ToLocalChecked();
CHECK(global->Set(context, deno::v8_str("deno_pub"), pub_val).FromJust()); CHECK(global->Set(context, deno::v8_str("deno_pub"), pub_val).FromJust());
bool r = Load(context, js_filename, js_source); bool r = Execute(context, js_filename, js_source);
assert(r); assert(r);
creator->SetDefaultContext(context); creator->SetDefaultContext(context);
@ -261,13 +261,13 @@ void deno_set_flags(int* argc, char** argv) {
const char* deno_last_exception(Deno* d) { return d->last_exception.c_str(); } const char* deno_last_exception(Deno* d) { return d->last_exception.c_str(); }
bool deno_load(Deno* d, const char* name_s, const char* source_s) { bool deno_execute(Deno* d, const char* js_filename, const char* js_source) {
auto* isolate = d->isolate; auto* isolate = d->isolate;
v8::Locker locker(isolate); v8::Locker locker(isolate);
v8::Isolate::Scope isolate_scope(isolate); v8::Isolate::Scope isolate_scope(isolate);
v8::HandleScope handle_scope(isolate); v8::HandleScope handle_scope(isolate);
auto context = d->context.Get(d->isolate); auto context = d->context.Get(d->isolate);
return deno::Load(context, name_s, source_s); return deno::Execute(context, js_filename, js_source);
} }
// Routes message to the javascript callback set with deno_sub(). // Routes message to the javascript callback set with deno_sub().

View file

@ -29,7 +29,7 @@ Deno* deno_new(void* data, deno_sub_cb cb);
// Returns false on error. // Returns false on error.
// Get error text with deno_last_exception(). // Get error text with deno_last_exception().
bool deno_load(Deno* d, const char* name_s, const char* source_s); bool deno_execute(Deno* d, const char* js_filename, const char* js_source);
// Returns false on error. // Returns false on error.
// Get error text with deno_last_exception(). // Get error text with deno_last_exception().

View file

@ -6,19 +6,19 @@
TEST(MockRuntimeTest, InitializesCorrectly) { TEST(MockRuntimeTest, InitializesCorrectly) {
Deno* d = deno_new(NULL, NULL); Deno* d = deno_new(NULL, NULL);
EXPECT_TRUE(deno_load(d, "a.js", "1 + 2")); EXPECT_TRUE(deno_execute(d, "a.js", "1 + 2"));
deno_dispose(d); deno_dispose(d);
} }
TEST(MockRuntimeTest, CanCallFoo) { TEST(MockRuntimeTest, CanCallFoo) {
Deno* d = deno_new(NULL, NULL); Deno* d = deno_new(NULL, NULL);
EXPECT_TRUE(deno_load(d, "a.js", "if (foo() != 'foo') throw Error();")); EXPECT_TRUE(deno_execute(d, "a.js", "if (foo() != 'foo') throw Error();"));
deno_dispose(d); deno_dispose(d);
} }
TEST(MockRuntimeTest, ErrorsCorrectly) { TEST(MockRuntimeTest, ErrorsCorrectly) {
Deno* d = deno_new(NULL, NULL); Deno* d = deno_new(NULL, NULL);
EXPECT_FALSE(deno_load(d, "a.js", "throw Error()")); EXPECT_FALSE(deno_execute(d, "a.js", "throw Error()"));
deno_dispose(d); deno_dispose(d);
} }
@ -29,14 +29,14 @@ deno_buf strbuf(const char* str) {
TEST(MockRuntimeTest, PubSuccess) { TEST(MockRuntimeTest, PubSuccess) {
Deno* d = deno_new(NULL, NULL); Deno* d = deno_new(NULL, NULL);
EXPECT_TRUE(deno_load(d, "a.js", "subabc();")); EXPECT_TRUE(deno_execute(d, "a.js", "subabc();"));
EXPECT_TRUE(deno_pub(d, strbuf("abc"))); EXPECT_TRUE(deno_pub(d, strbuf("abc")));
deno_dispose(d); deno_dispose(d);
} }
TEST(MockRuntimeTest, PubByteLength) { TEST(MockRuntimeTest, PubByteLength) {
Deno* d = deno_new(NULL, NULL); Deno* d = deno_new(NULL, NULL);
EXPECT_TRUE(deno_load(d, "a.js", "subabc();")); EXPECT_TRUE(deno_execute(d, "a.js", "subabc();"));
// We pub the wrong sized message, it should throw. // We pub the wrong sized message, it should throw.
EXPECT_FALSE(deno_pub(d, strbuf("abcd"))); EXPECT_FALSE(deno_pub(d, strbuf("abcd")));
deno_dispose(d); deno_dispose(d);
@ -61,7 +61,7 @@ TEST(MockRuntimeTest, SubReturnEmpty) {
EXPECT_EQ(data[2], 'c'); EXPECT_EQ(data[2], 'c');
return deno_buf{nullptr, 0}; return deno_buf{nullptr, 0};
}); });
EXPECT_TRUE(deno_load(d, "a.js", "pubReturnEmpty()")); EXPECT_TRUE(deno_execute(d, "a.js", "pubReturnEmpty()"));
EXPECT_EQ(count, 2); EXPECT_EQ(count, 2);
deno_dispose(d); deno_dispose(d);
} }
@ -78,7 +78,7 @@ TEST(MockRuntimeTest, SubReturnBar) {
EXPECT_EQ(data[2], 'c'); EXPECT_EQ(data[2], 'c');
return strbuf("bar"); return strbuf("bar");
}); });
EXPECT_TRUE(deno_load(d, "a.js", "pubReturnBar()")); EXPECT_TRUE(deno_execute(d, "a.js", "pubReturnBar()"));
EXPECT_EQ(count, 1); EXPECT_EQ(count, 1);
deno_dispose(d); deno_dispose(d);
} }