Skip to content

Commit

Permalink
deps: cherry-pick 0c35b72 from upstream V8
Browse files Browse the repository at this point in the history
Original commit message:

    [api,modules] Allow GetModuleNamespace on unevaluated modules.

    Bug: v8:7217
    Cq-Include-Trybots: master.tryserver.chromium.linux:linux_chromium_rel_ng
    Change-Id: I97b067254355eb91e12b92eba92631cbc3ce8000
    Reviewed-on: https://chromium-review.googlesource.com/839280
    Commit-Queue: Georg Neis <neis@chromium.org>
    Reviewed-by: Adam Klein <adamk@chromium.org>
    Cr-Commit-Position: refs/heads/master@{#50395}

PR-URL: #18038
Refs: v8/v8@0c35b72
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Tiancheng "Timothy" Gu <timothygu99@gmail.com>
  • Loading branch information
devsnek authored and codebytere committed Aug 3, 2018
1 parent 6297592 commit 1875ab3
Show file tree
Hide file tree
Showing 3 changed files with 114 additions and 4 deletions.
2 changes: 1 addition & 1 deletion deps/v8/include/v8-version.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#define V8_MAJOR_VERSION 6
#define V8_MINOR_VERSION 2
#define V8_BUILD_NUMBER 414
#define V8_PATCH_LEVEL 62
#define V8_PATCH_LEVEL 63

// Use 1 for candidates and 0 otherwise.
// (Boolean macro values are not supported by all preprocessors.)
Expand Down
5 changes: 2 additions & 3 deletions deps/v8/src/api.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2212,9 +2212,8 @@ Location Module::GetModuleRequestLocation(int i) const {

Local<Value> Module::GetModuleNamespace() {
Utils::ApiCheck(
GetStatus() == kEvaluated, "v8::Module::GetModuleNamespace",
"v8::Module::GetModuleNamespace can only be used on a module with "
"status kEvaluated");
GetStatus() >= kInstantiated, "v8::Module::GetModuleNamespace",
"v8::Module::GetModuleNamespace must be used on an instantiated module");
i::Handle<i::Module> self = Utils::OpenHandle(this);
i::Handle<i::JSModuleNamespace> module_namespace =
i::Module::GetModuleNamespace(self);
Expand Down
111 changes: 111 additions & 0 deletions deps/v8/test/cctest/test-modules.cc
Original file line number Diff line number Diff line change
Expand Up @@ -281,4 +281,115 @@ TEST(ModuleEvaluationCompletion2) {
CHECK(!try_catch.HasCaught());
}

TEST(ModuleNamespace) {
Isolate* isolate = CcTest::isolate();
HandleScope scope(isolate);
LocalContext env;
v8::TryCatch try_catch(isolate);

Local<v8::Object> ReferenceError =
CompileRun("ReferenceError")->ToObject(env.local()).ToLocalChecked();

Local<String> source_text = v8_str(
"import {a, b} from 'export var a = 1; export let b = 2';"
"export function geta() {return a};"
"export function getb() {return b};"
"export let radio = 3;"
"export var gaga = 4;");
ScriptOrigin origin = ModuleOrigin(v8_str("file.js"), CcTest::isolate());
ScriptCompiler::Source source(source_text, origin);
Local<Module> module =
ScriptCompiler::CompileModule(isolate, &source).ToLocalChecked();
CHECK_EQ(Module::kUninstantiated, module->GetStatus());
CHECK(module
->InstantiateModule(env.local(),
CompileSpecifierAsModuleResolveCallback)
.FromJust());
CHECK_EQ(Module::kInstantiated, module->GetStatus());
Local<Value> ns = module->GetModuleNamespace();
CHECK_EQ(Module::kInstantiated, module->GetStatus());
Local<v8::Object> nsobj = ns->ToObject(env.local()).ToLocalChecked();

// a, b
CHECK(nsobj->Get(env.local(), v8_str("a")).ToLocalChecked()->IsUndefined());
CHECK(nsobj->Get(env.local(), v8_str("b")).ToLocalChecked()->IsUndefined());

// geta
{
auto geta = nsobj->Get(env.local(), v8_str("geta")).ToLocalChecked();
auto a = geta.As<v8::Function>()
->Call(env.local(), geta, 0, nullptr)
.ToLocalChecked();
CHECK(a->IsUndefined());
}

// getb
{
v8::TryCatch inner_try_catch(isolate);
auto getb = nsobj->Get(env.local(), v8_str("getb")).ToLocalChecked();
CHECK(
getb.As<v8::Function>()->Call(env.local(), getb, 0, nullptr).IsEmpty());
CHECK(inner_try_catch.HasCaught());
CHECK(inner_try_catch.Exception()
->InstanceOf(env.local(), ReferenceError)
.FromJust());
}

// radio
{
v8::TryCatch inner_try_catch(isolate);
// https://bugs.chromium.org/p/v8/issues/detail?id=7235
// CHECK(nsobj->Get(env.local(), v8_str("radio")).IsEmpty());
CHECK(nsobj->Get(env.local(), v8_str("radio"))
.ToLocalChecked()
->IsUndefined());
CHECK(inner_try_catch.HasCaught());
CHECK(inner_try_catch.Exception()
->InstanceOf(env.local(), ReferenceError)
.FromJust());
}

// gaga
{
auto gaga = nsobj->Get(env.local(), v8_str("gaga")).ToLocalChecked();
CHECK(gaga->IsUndefined());
}

CHECK(!try_catch.HasCaught());
CHECK_EQ(Module::kInstantiated, module->GetStatus());
module->Evaluate(env.local()).ToLocalChecked();
CHECK_EQ(Module::kEvaluated, module->GetStatus());

// geta
{
auto geta = nsobj->Get(env.local(), v8_str("geta")).ToLocalChecked();
auto a = geta.As<v8::Function>()
->Call(env.local(), geta, 0, nullptr)
.ToLocalChecked();
CHECK_EQ(1, a->Int32Value(env.local()).FromJust());
}

// getb
{
auto getb = nsobj->Get(env.local(), v8_str("getb")).ToLocalChecked();
auto b = getb.As<v8::Function>()
->Call(env.local(), getb, 0, nullptr)
.ToLocalChecked();
CHECK_EQ(2, b->Int32Value(env.local()).FromJust());
}

// radio
{
auto radio = nsobj->Get(env.local(), v8_str("radio")).ToLocalChecked();
CHECK_EQ(3, radio->Int32Value(env.local()).FromJust());
}

// gaga
{
auto gaga = nsobj->Get(env.local(), v8_str("gaga")).ToLocalChecked();
CHECK_EQ(4, gaga->Int32Value(env.local()).FromJust());
}

CHECK(!try_catch.HasCaught());
}
} // anonymous namespace

0 comments on commit 1875ab3

Please sign in to comment.