Add libdeno.builtinModules (#1463)

This is needed to support builtin modules like

    import { open } from "deno"
This commit is contained in:
Ryan Dahl 2019-01-06 16:32:21 -05:00 committed by GitHub
parent f37d67e809
commit 1b7938e3aa
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 100 additions and 3 deletions

View file

@ -306,3 +306,28 @@ TEST(LibDenoTest, ModuleSnapshot) {
delete[] test_snapshot.data_ptr;
}
TEST(LibDenoTest, BuiltinModules) {
static int count = 0;
auto resolve_cb = [](void* user_data, const char* specifier,
const char* referrer) {
EXPECT_STREQ(specifier, "b.js");
EXPECT_STREQ(referrer, "c.js");
count++;
auto d = reinterpret_cast<Deno*>(user_data);
deno_resolve_ok(d, "b.js", mod_b);
};
Deno* d = deno_new(deno_config{0, empty, empty, nullptr, resolve_cb});
EXPECT_TRUE(deno_execute(
d, d, "setup.js", "libdeno.builtinModules['deno'] = { foo: 'bar' }; \n"));
EXPECT_EQ(count, 0);
EXPECT_TRUE(
deno_execute_mod(d, d, "c.js",
"import { retb } from 'b.js'\n"
"import * as deno from 'deno'\n"
"if (retb() != 'b') throw Error('retb');\n"
// " libdeno.print('deno ' + JSON.stringify(deno));\n"
"if (deno.foo != 'bar') throw Error('foo');\n"));
EXPECT_EQ(count, 1);
deno_delete(d);
}