Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(431)

Unified Diff: test/cctest/test-modules.cc

Issue 2827733002: [modules] Allow resolve-callback to signal failure. (Closed)
Patch Set: Cleanup. Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/objects.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/cctest/test-modules.cc
diff --git a/test/cctest/test-modules.cc b/test/cctest/test-modules.cc
index 9e8bf100d575252b85439fce7d9674f3dfa53a69..f63a04d0118d3b0c67eb66a9ae1074a56fe8ed25 100644
--- a/test/cctest/test-modules.cc
+++ b/test/cctest/test-modules.cc
@@ -27,9 +27,11 @@ ScriptOrigin ModuleOrigin(Local<v8::Value> resource_name, Isolate* isolate) {
return origin;
}
-MaybeLocal<Module> AlwaysEmptyResolveCallback(Local<Context> context,
- Local<String> specifier,
- Local<Module> referrer) {
+MaybeLocal<Module> FailAlwaysResolveCallback(Local<Context> context,
+ Local<String> specifier,
+ Local<Module> referrer) {
+ Isolate* isolate = context->GetIsolate();
+ isolate->ThrowException(v8_str("boom"));
return MaybeLocal<Module>();
}
@@ -37,18 +39,22 @@ static int g_count = 0;
MaybeLocal<Module> FailOnSecondCallResolveCallback(Local<Context> context,
Local<String> specifier,
Local<Module> referrer) {
- if (g_count++ > 0) return MaybeLocal<Module>();
+ Isolate* isolate = CcTest::isolate();
+ if (g_count++ > 0) {
+ isolate->ThrowException(v8_str("booom"));
+ return MaybeLocal<Module>();
+ }
Local<String> source_text = v8_str("");
- ScriptOrigin origin = ModuleOrigin(v8_str("module.js"), CcTest::isolate());
+ ScriptOrigin origin = ModuleOrigin(v8_str("module.js"), isolate);
ScriptCompiler::Source source(source_text, origin);
- return ScriptCompiler::CompileModule(CcTest::isolate(), &source)
- .ToLocalChecked();
+ return ScriptCompiler::CompileModule(isolate, &source).ToLocalChecked();
}
TEST(ModuleInstantiationFailures) {
Isolate* isolate = CcTest::isolate();
HandleScope scope(isolate);
LocalContext env;
+ v8::TryCatch try_catch(isolate);
Local<String> source_text = v8_str(
"import './foo.js';"
@@ -62,14 +68,26 @@ TEST(ModuleInstantiationFailures) {
CHECK(v8_str("./bar.js")->StrictEquals(module->GetModuleRequest(1)));
// Instantiation should fail.
- CHECK(!module->Instantiate(env.local(), AlwaysEmptyResolveCallback));
+ {
+ v8::TryCatch inner_try_catch(isolate);
+ CHECK(!module->Instantiate(env.local(), FailAlwaysResolveCallback));
+ CHECK(inner_try_catch.HasCaught());
+ CHECK(inner_try_catch.Exception()->StrictEquals(v8_str("boom")));
+ }
// Start over again...
module = ScriptCompiler::CompileModule(isolate, &source).ToLocalChecked();
// Instantiation should fail if a sub-module fails to resolve.
g_count = 0;
- CHECK(!module->Instantiate(env.local(), FailOnSecondCallResolveCallback));
+ {
+ v8::TryCatch inner_try_catch(isolate);
+ CHECK(!module->Instantiate(env.local(), FailOnSecondCallResolveCallback));
+ CHECK(inner_try_catch.HasCaught());
+ CHECK(inner_try_catch.Exception()->StrictEquals(v8_str("booom")));
+ }
+
+ CHECK(!try_catch.HasCaught());
}
static MaybeLocal<Module> CompileSpecifierAsModuleResolveCallback(
@@ -84,6 +102,7 @@ TEST(ModuleEvaluation) {
Isolate* isolate = CcTest::isolate();
HandleScope scope(isolate);
LocalContext env;
+ v8::TryCatch try_catch(isolate);
Local<String> source_text = v8_str(
"import 'Object.expando = 5';"
@@ -96,12 +115,15 @@ TEST(ModuleEvaluation) {
CompileSpecifierAsModuleResolveCallback));
CHECK(!module->Evaluate(env.local()).IsEmpty());
ExpectInt32("Object.expando", 10);
+
+ CHECK(!try_catch.HasCaught());
}
TEST(ModuleEvaluationCompletion1) {
Isolate* isolate = CcTest::isolate();
HandleScope scope(isolate);
LocalContext env;
+ v8::TryCatch try_catch(isolate);
const char* sources[] = {
"",
@@ -133,12 +155,15 @@ TEST(ModuleEvaluationCompletion1) {
CompileSpecifierAsModuleResolveCallback));
CHECK(module->Evaluate(env.local()).ToLocalChecked()->IsUndefined());
}
+
+ CHECK(!try_catch.HasCaught());
}
TEST(ModuleEvaluationCompletion2) {
Isolate* isolate = CcTest::isolate();
HandleScope scope(isolate);
LocalContext env;
+ v8::TryCatch try_catch(isolate);
const char* sources[] = {
"'gaga'; ",
@@ -171,6 +196,8 @@ TEST(ModuleEvaluationCompletion2) {
.ToLocalChecked()
->StrictEquals(v8_str("gaga")));
}
+
+ CHECK(!try_catch.HasCaught());
}
} // anonymous namespace
« no previous file with comments | « src/objects.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698