summaryrefslogtreecommitdiff
path: root/libdeno
diff options
context:
space:
mode:
Diffstat (limited to 'libdeno')
-rw-r--r--libdeno/binding.cc22
-rw-r--r--libdeno/internal.h5
-rw-r--r--libdeno/modules.cc54
-rw-r--r--libdeno/modules_test.cc151
4 files changed, 1 insertions, 231 deletions
diff --git a/libdeno/binding.cc b/libdeno/binding.cc
index 7346956fd..c291852da 100644
--- a/libdeno/binding.cc
+++ b/libdeno/binding.cc
@@ -289,14 +289,6 @@ void Send(const v8::FunctionCallbackInfo<v8::Value>& args) {
}
}
-v8::Local<v8::Object> DenoIsolate::GetBuiltinModules() {
- v8::EscapableHandleScope handle_scope(isolate_);
- if (builtin_modules_.IsEmpty()) {
- builtin_modules_.Reset(isolate_, v8::Object::New(isolate_));
- }
- return handle_scope.Escape(builtin_modules_.Get(isolate_));
-}
-
v8::ScriptOrigin ModuleOrigin(v8::Isolate* isolate,
v8::Local<v8::Value> resource_name) {
return v8::ScriptOrigin(resource_name, v8::Local<v8::Integer>(),
@@ -350,15 +342,6 @@ deno_mod DenoIsolate::RegisterModule(bool main, const char* name,
return id;
}
-void BuiltinModules(v8::Local<v8::Name> property,
- const v8::PropertyCallbackInfo<v8::Value>& info) {
- v8::Isolate* isolate = info.GetIsolate();
- DenoIsolate* d = DenoIsolate::FromIsolate(isolate);
- DCHECK_EQ(d->isolate_, isolate);
- v8::Locker locker(d->isolate_);
- info.GetReturnValue().Set(d->GetBuiltinModules());
-}
-
void Shared(v8::Local<v8::Name> property,
const v8::PropertyCallbackInfo<v8::Value>& info) {
v8::Isolate* isolate = info.GetIsolate();
@@ -530,11 +513,6 @@ void InitializeContext(v8::Isolate* isolate, v8::Local<v8::Context> context) {
CHECK(deno_val->SetAccessor(context, deno::v8_str("shared"), Shared)
.FromJust());
-
- CHECK(
- deno_val
- ->SetAccessor(context, deno::v8_str("builtinModules"), BuiltinModules)
- .FromJust());
}
void MessageCallback(v8::Local<v8::Message> message,
diff --git a/libdeno/internal.h b/libdeno/internal.h
index 563043085..71cf731b6 100644
--- a/libdeno/internal.h
+++ b/libdeno/internal.h
@@ -67,7 +67,6 @@ class DenoIsolate {
void AddIsolate(v8::Isolate* isolate);
deno_mod RegisterModule(bool main, const char* name, const char* source);
- v8::Local<v8::Object> GetBuiltinModules();
void ClearModules();
ModuleInfo* GetModuleInfo(deno_mod id) {
@@ -109,7 +108,6 @@ class DenoIsolate {
size_t next_zero_copy_id_;
void* user_data_;
- v8::Persistent<v8::Object> builtin_modules_;
std::map<deno_mod, ModuleInfo> mods_;
std::map<std::string, deno_mod> mods_by_name_;
deno_resolve_cb resolve_cb_;
@@ -159,8 +157,6 @@ void EvalContext(const v8::FunctionCallbackInfo<v8::Value>& args);
void ErrorToJSON(const v8::FunctionCallbackInfo<v8::Value>& args);
void Shared(v8::Local<v8::Name> property,
const v8::PropertyCallbackInfo<v8::Value>& info);
-void BuiltinModules(v8::Local<v8::Name> property,
- const v8::PropertyCallbackInfo<v8::Value>& info);
void MessageCallback(v8::Local<v8::Message> message, v8::Local<v8::Value> data);
static intptr_t external_references[] = {
reinterpret_cast<intptr_t>(Print),
@@ -169,7 +165,6 @@ static intptr_t external_references[] = {
reinterpret_cast<intptr_t>(EvalContext),
reinterpret_cast<intptr_t>(ErrorToJSON),
reinterpret_cast<intptr_t>(Shared),
- reinterpret_cast<intptr_t>(BuiltinModules),
reinterpret_cast<intptr_t>(MessageCallback),
0};
diff --git a/libdeno/modules.cc b/libdeno/modules.cc
index d8b2f48d1..0b408aec8 100644
--- a/libdeno/modules.cc
+++ b/libdeno/modules.cc
@@ -19,42 +19,6 @@ using v8::ScriptOrigin;
using v8::String;
using v8::Value;
-std::string BuiltinModuleSrc(Local<Context> context, Local<String> specifier) {
- auto* isolate = context->GetIsolate();
- DenoIsolate* d = DenoIsolate::FromIsolate(isolate);
- v8::Isolate::Scope isolate_scope(isolate);
- v8::EscapableHandleScope handle_scope(isolate);
- v8::Context::Scope context_scope(context);
-
- v8::String::Utf8Value specifier_utf8val(isolate, specifier);
- const char* specifier_cstr = *specifier_utf8val;
-
- auto builtin_modules = d->GetBuiltinModules();
- auto val = builtin_modules->Get(context, specifier).ToLocalChecked();
- CHECK(val->IsObject());
- auto obj = val->ToObject(isolate);
-
- // In order to export obj as a module, we must iterate over its properties
- // and export them each individually.
- // TODO(ry) Find a better way to do this.
- std::string src = "let globalEval = eval\nlet g = globalEval('this');\n";
- auto names = obj->GetOwnPropertyNames(context).ToLocalChecked();
- for (uint32_t i = 0; i < names->Length(); i++) {
- auto name = names->Get(context, i).ToLocalChecked();
- v8::String::Utf8Value name_utf8val(isolate, name);
- const char* name_cstr = *name_utf8val;
- // TODO(ry) use format string.
- src.append("export const ");
- src.append(name_cstr);
- src.append(" = g.libdeno.builtinModules.");
- src.append(specifier_cstr);
- src.append(".");
- src.append(name_cstr);
- src.append(";\n");
- }
- return src;
-}
-
v8::MaybeLocal<v8::Module> ResolveCallback(Local<Context> context,
Local<String> specifier,
Local<Module> referrer) {
@@ -66,8 +30,6 @@ v8::MaybeLocal<v8::Module> ResolveCallback(Local<Context> context,
v8::EscapableHandleScope handle_scope(isolate);
- auto builtin_modules = d->GetBuiltinModules();
-
deno_mod referrer_id = referrer->GetIdentityHash();
auto* referrer_info = d->GetModuleInfo(referrer_id);
CHECK_NOT_NULL(referrer_info);
@@ -79,21 +41,7 @@ v8::MaybeLocal<v8::Module> ResolveCallback(Local<Context> context,
v8::String::Utf8Value req_utf8(isolate, req);
std::string req_str(*req_utf8);
- deno_mod id = 0;
- {
- bool has_builtin = builtin_modules->Has(context, specifier).ToChecked();
- if (has_builtin) {
- auto it = d->mods_by_name_.find(req_str.c_str());
- if (it != d->mods_by_name_.end()) {
- id = it->second;
- } else {
- std::string src = BuiltinModuleSrc(context, specifier);
- id = d->RegisterModule(false, req_str.c_str(), src.c_str());
- }
- } else {
- id = d->resolve_cb_(d->user_data_, req_str.c_str(), referrer_id);
- }
- }
+ deno_mod id = d->resolve_cb_(d->user_data_, req_str.c_str(), referrer_id);
// Note: id might be zero, in which case GetModuleInfo will return
// nullptr.
diff --git a/libdeno/modules_test.cc b/libdeno/modules_test.cc
index cb800e89a..357c48641 100644
--- a/libdeno/modules_test.cc
+++ b/libdeno/modules_test.cc
@@ -64,157 +64,6 @@ TEST(ModulesTest, Resolution) {
deno_delete(d);
}
-TEST(ModulesTest, BuiltinModules) {
- exec_count = 0; // Reset
- Deno* d = deno_new(deno_config{0, empty, empty, recv_cb});
- EXPECT_EQ(0, exec_count);
-
- deno_execute(d, d, "setup.js",
- "libdeno.builtinModules['deno'] = { foo: 'bar' };");
- EXPECT_EQ(nullptr, deno_last_exception(d));
-
- static deno_mod a =
- deno_mod_new(d, true, "a.js",
- "import { b } from 'b.js'\n"
- "import * as deno from 'deno'\n"
- "if (b() != 'b') throw Error('b');\n"
- "if (deno.foo != 'bar') throw Error('foo');\n"
- "libdeno.send(new Uint8Array([4]));");
- EXPECT_NE(a, 0);
- EXPECT_EQ(nullptr, deno_last_exception(d));
-
- const char* b_src = "export function b() { return 'b' }";
- static deno_mod b = deno_mod_new(d, false, "b.js", b_src);
- EXPECT_NE(b, 0);
- EXPECT_EQ(nullptr, deno_last_exception(d));
-
- EXPECT_EQ(0, exec_count);
-
- EXPECT_EQ(2u, deno_mod_imports_len(d, a));
- EXPECT_EQ(0u, deno_mod_imports_len(d, b));
-
- EXPECT_STREQ("b.js", deno_mod_imports_get(d, a, 0));
- EXPECT_STREQ("deno", deno_mod_imports_get(d, a, 1));
- EXPECT_EQ(nullptr, deno_mod_imports_get(d, a, 2));
- EXPECT_EQ(nullptr, deno_mod_imports_get(d, b, 0));
-
- static int resolve_count = 0;
- auto resolve_cb = [](void* user_data, const char* specifier,
- deno_mod referrer) {
- EXPECT_EQ(referrer, a);
- EXPECT_STREQ(specifier, "b.js");
- resolve_count++;
- return b;
- };
-
- deno_mod_instantiate(d, d, b, resolve_cb);
- EXPECT_EQ(nullptr, deno_last_exception(d));
- EXPECT_EQ(0, resolve_count);
- EXPECT_EQ(0, exec_count);
-
- deno_mod_instantiate(d, d, a, resolve_cb);
- EXPECT_EQ(nullptr, deno_last_exception(d));
- EXPECT_EQ(1, resolve_count);
- EXPECT_EQ(0, exec_count);
-
- deno_mod_evaluate(d, d, a);
- EXPECT_EQ(nullptr, deno_last_exception(d));
- EXPECT_EQ(1, resolve_count);
- EXPECT_EQ(1, exec_count);
-
- deno_delete(d);
-}
-
-TEST(ModulesTest, BuiltinModules2) {
- exec_count = 0; // Reset
- Deno* d = deno_new(deno_config{0, empty, empty, recv_cb});
- EXPECT_EQ(0, exec_count);
-
- deno_execute(d, d, "setup.js",
- "libdeno.builtinModules['builtin1'] = { foo: 'bar' }; \n"
- "libdeno.builtinModules['builtin2'] = { hello: 'world' }; \n");
- EXPECT_EQ(nullptr, deno_last_exception(d));
-
- static deno_mod a =
- deno_mod_new(d, true, "a.js",
- "import * as b1 from 'builtin1'\n"
- "import * as b2 from 'builtin2'\n"
- "if (b1.foo != 'bar') throw Error('bad1');\n"
- "if (b2.hello != 'world') throw Error('bad2');\n"
- "libdeno.send(new Uint8Array([4]));");
- EXPECT_NE(a, 0);
- EXPECT_EQ(nullptr, deno_last_exception(d));
-
- EXPECT_EQ(2u, deno_mod_imports_len(d, a));
- EXPECT_STREQ("builtin1", deno_mod_imports_get(d, a, 0));
- EXPECT_STREQ("builtin2", deno_mod_imports_get(d, a, 1));
-
- deno_mod_instantiate(d, d, a, nullptr);
- EXPECT_EQ(nullptr, deno_last_exception(d));
- EXPECT_EQ(0, exec_count);
-
- deno_mod_evaluate(d, d, a);
- EXPECT_EQ(nullptr, deno_last_exception(d));
- EXPECT_EQ(1, exec_count);
-
- deno_delete(d);
-}
-
-TEST(ModulesTest, BuiltinModules3) {
- exec_count = 0; // Reset
- Deno* d = deno_new(deno_config{0, empty, empty, recv_cb});
- EXPECT_EQ(0, exec_count);
-
- deno_execute(d, d, "setup.js",
- "libdeno.builtinModules['builtin'] = { foo: 'bar' };");
- EXPECT_EQ(nullptr, deno_last_exception(d));
-
- static deno_mod a =
- deno_mod_new(d, true, "a.js",
- "import * as b1 from 'builtin'\n"
- "import * as b2 from 'b.js'\n"
- "if (b1.foo != 'bar') throw Error('bad1');\n"
- "if (b2.bar() != 'bar') throw Error('bad2');\n"
- "libdeno.send(new Uint8Array([4]));");
- EXPECT_NE(a, 0);
- EXPECT_EQ(nullptr, deno_last_exception(d));
-
- EXPECT_EQ(2u, deno_mod_imports_len(d, a));
- EXPECT_STREQ("builtin", deno_mod_imports_get(d, a, 0));
- EXPECT_STREQ("b.js", deno_mod_imports_get(d, a, 1));
-
- static deno_mod b = deno_mod_new(d, false, "b.js",
- "import { foo } from 'builtin';\n"
- "export function bar() { return foo }\n");
- EXPECT_NE(b, 0);
- EXPECT_EQ(nullptr, deno_last_exception(d));
-
- static int resolve_count = 0;
- auto resolve_cb = [](void* user_data, const char* specifier,
- deno_mod referrer) {
- EXPECT_EQ(referrer, a);
- EXPECT_STREQ(specifier, "b.js");
- resolve_count++;
- return b;
- };
-
- deno_mod_instantiate(d, d, a, resolve_cb);
- EXPECT_EQ(nullptr, deno_last_exception(d));
- EXPECT_EQ(1, resolve_count);
- EXPECT_EQ(0, exec_count);
-
- deno_mod_instantiate(d, d, b, resolve_cb);
- EXPECT_EQ(nullptr, deno_last_exception(d));
- EXPECT_EQ(1, resolve_count);
- EXPECT_EQ(0, exec_count);
-
- deno_mod_evaluate(d, d, a);
- EXPECT_EQ(nullptr, deno_last_exception(d));
- EXPECT_EQ(1, exec_count);
-
- deno_delete(d);
-}
-
TEST(ModulesTest, ResolutionError) {
exec_count = 0; // Reset
Deno* d = deno_new(deno_config{0, empty, empty, recv_cb});