Attached patches to shell.cc. On Friday, December 28, 2018 at 12:15:48 PM UTC-8, Jane Chen wrote: > > Embedding v8 6.7, open to upgrade if necessary. > > I modified v8 shell.cc to experiment with the new Module API and am trying > to figure out how to handle error conditions while resolving a module. > > If the resolve callback calls v8::Isolate::throwException, I get: > > # > # Fatal error in ../../src/api.cc, line 2325 > # Check failed: self->status() >= i::Module::kInstantiated (0 vs. 3). > # > > Thread #1 [v8_shell] 3310 [core: 2] (Suspended : Signal : SIGILL:Illegal > instruction) > v8::base::OS::Abort() at > /space/projects/v8upgrade6.7/v8/v8/src/base/platform/platform-posix.cc:381 > 0x7ffff7fa9f49 > V8_Fatal() at /space/projects/v8upgrade6.7/v8/v8/src/base/logging.cc:170 > 0x7ffff7f9e7b4 > v8::base::(anonymous namespace)::DefaultDcheckHandler at > /space/projects/v8upgrade6.7/v8/v8/src/base/logging.cc:56 0x7ffff7f9e7d5 > v8::internal::Isolate::scheduled_exception() at > /space/projects/v8upgrade6.7/v8/v8/src/isolate-inl.h:68 0x7ffff73c4bd8 > v8::internal::Isolate::PromoteScheduledException() at > /space/projects/v8upgrade6.7/v8/v8/src/isolate.cc:1,636 0x7ffff73c4bd8 > v8::internal::Module::PrepareInstantiate() at > /space/projects/v8upgrade6.7/v8/v8/src/objects/module.cc:475 0x7ffff74c20ae > v8::internal::Module::Instantiate() at > /space/projects/v8upgrade6.7/v8/v8/src/objects/module.cc:434 0x7ffff74c3fcb > v8::Module::InstantiateModule() at > /space/projects/v8upgrade6.7/v8/v8/src/api.cc:2,309 0x7ffff6d0f08c > ExecuteString() at > /space/projects/v8upgrade6.7/v8/v8/samples/shell.cc:367 0x555555557435 > RunShell() at /space/projects/v8upgrade6.7/v8/v8/samples/shell.cc:324 > 0x555555557a6e > > If resolve callback returns a module not containing the imported functions: > > V8 version 6.7.288.52 [sample shell] > > import { square, diag } from 'lib'; > (shell):1: SyntaxError: The requested module 'lib' does not provide an > export named 'square' > import { square, diag } from 'lib'; > ^^^^^^ > SyntaxError: The requested module 'lib' does not provide an export named > 'square' > > # > # Fatal error in ../../src/api.cc, line 2325 > # Check failed: self->status() >= i::Module::kInstantiated (0 vs. 3). > # > > Thread #1 [v8_shell] 7277 [core: 17] (Suspended : Signal : SIGILL:Illegal > instruction) > v8::base::OS::Abort() at > /space/projects/v8upgrade6.7/v8/v8/src/base/platform/platform-posix.cc:381 > 0x7ffff7fa9f49 > V8_Fatal() at /space/projects/v8upgrade6.7/v8/v8/src/base/logging.cc:170 > 0x7ffff7f9e7b4 > v8::Module::Evaluate() at > /space/projects/v8upgrade6.7/v8/v8/src/api.cc:2,325 0x7ffff6d0f611 > ExecuteString() at > /space/projects/v8upgrade6.7/v8/v8/samples/shell.cc:380 0x5555555575df > RunShell() at /space/projects/v8upgrade6.7/v8/v8/samples/shell.cc:324 > 0x555555557bfe > main() at /space/projects/v8upgrade6.7/v8/v8/samples/shell.cc:89 > 0x55555555676e > > How is ResolveCallback supposed to handle these error conditions to avoid > v8 crashes? > > If I upgrade to the latest stable v8 version, is it going to help? > > Thanks a lot in advance! >
-- -- v8-users mailing list v8-users@googlegroups.com http://groups.google.com/group/v8-users --- You received this message because you are subscribed to the Google Groups "v8-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to v8-users+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
diff --git a/samples/shell.cc b/samples/shell.cc index 81b028720c..cc52401a97 100644 --- a/samples/shell.cc +++ b/samples/shell.cc @@ -332,6 +332,26 @@ void RunShell(v8::Local<v8::Context> context, v8::Platform* platform) { fprintf(stderr, "\n"); } +v8::MaybeLocal<v8::Module> resolveCallback(v8::Local<v8::Context> context, + v8::Local<v8::String> specifier, + v8::Local<v8::Module> referrer) +{ + v8::Isolate* isolate = context->GetIsolate(); + v8::MaybeLocal<v8::String> v8str = v8::String::NewFromUtf8(isolate, + "'module not found'"); + v8::ScriptOrigin origin(v8str.ToLocalChecked(),v8::Local<v8::Integer>(), + v8::Local<v8::Integer>(),v8::Local<v8::Boolean>(), + v8::Local<v8::Integer>(),v8::Local<v8::Value>(),v8::Local<v8::Boolean>(), + v8::Local<v8::Boolean>(),v8::Boolean::New(isolate,true)); + v8::ScriptCompiler::Source src(v8str.ToLocalChecked(),origin); + v8::MaybeLocal<v8::Module> script = + v8::ScriptCompiler::CompileModule(isolate,&src); + v8::Local<v8::Module> module = script.ToLocalChecked(); + if (module->InstantiateModule(context,resolveCallback).IsNothing()) + isolate->ThrowException(v8str.ToLocalChecked()); + return module; +} + // Executes a string within the current v8 context. bool ExecuteString(v8::Isolate* isolate, v8::Local<v8::String> source, @@ -339,17 +359,25 @@ bool ExecuteString(v8::Isolate* isolate, v8::Local<v8::String> source, bool report_exceptions) { v8::HandleScope handle_scope(isolate); v8::TryCatch try_catch(isolate); - v8::ScriptOrigin origin(name); + v8::ScriptOrigin origin(name,v8::Local<v8::Integer>(), + v8::Local<v8::Integer>(),v8::Local<v8::Boolean>(), + v8::Local<v8::Integer>(),v8::Local<v8::Value>(),v8::Local<v8::Boolean>(), + v8::Local<v8::Boolean>(),v8::Boolean::New(isolate,true)); v8::Local<v8::Context> context(isolate->GetCurrentContext()); - v8::Local<v8::Script> script; - if (!v8::Script::Compile(context, source, &origin).ToLocal(&script)) { + v8::ScriptCompiler::Source src(source,origin); + v8::MaybeLocal<v8::Module> script = + v8::ScriptCompiler::CompileModule(isolate,&src); + if (script.IsEmpty() || try_catch.HasCaught()) { // Print errors that happened during compilation. if (report_exceptions) ReportException(isolate, &try_catch); return false; } else { v8::Local<v8::Value> result; - if (!script->Run(context).ToLocal(&result)) { + v8::Local<v8::Module> module = script.ToLocalChecked(); + if (module->InstantiateModule(context,resolveCallback).IsNothing()) + ReportException(isolate, &try_catch); + if (!module->Evaluate(context).ToLocal(&result)) { assert(try_catch.HasCaught()); // Print errors that happened during execution. if (report_exceptions) diff --git a/test/cctest/compiler/graph-builder-tester.h b/test/cctest/compiler/graph-builder-tester.h index 2edf6c27e6..5643d4d10b 100644 --- a/test/cctest/compiler/graph-builder-tester.h +++ b/test/cctest/compiler/graph-builder-tester.h @@ -164,9 +164,6 @@ class GraphBuilderTester : public HandleAndZoneScope, Node* ChangeUint32ToTagged(Node* a) { return NewNode(simplified()->ChangeUint32ToTagged(), a); } - Node* ChangeFloat64ToTagged(Node* a) { - return NewNode(simplified()->ChangeFloat64ToTagged(), a); - } Node* ChangeTaggedToBit(Node* a) { return NewNode(simplified()->ChangeTaggedToBit(), a); }
diff --git a/samples/shell.cc b/samples/shell.cc index 81b028720c..8d5f082575 100644 --- a/samples/shell.cc +++ b/samples/shell.cc @@ -332,6 +332,17 @@ void RunShell(v8::Local<v8::Context> context, v8::Platform* platform) { fprintf(stderr, "\n"); } +v8::MaybeLocal<v8::Module> resolveCallback(v8::Local<v8::Context> context, + v8::Local<v8::String> specifier, + v8::Local<v8::Module> referrer) +{ + v8::Isolate* isolate = context->GetIsolate(); + v8::MaybeLocal<v8::String> v8str = v8::String::NewFromUtf8(isolate, + "module not found"); + isolate->ThrowException(v8str.ToLocalChecked()); + return v8::MaybeLocal<v8::Module>(); +} + // Executes a string within the current v8 context. bool ExecuteString(v8::Isolate* isolate, v8::Local<v8::String> source, @@ -339,17 +350,25 @@ bool ExecuteString(v8::Isolate* isolate, v8::Local<v8::String> source, bool report_exceptions) { v8::HandleScope handle_scope(isolate); v8::TryCatch try_catch(isolate); - v8::ScriptOrigin origin(name); + v8::ScriptOrigin origin(name,v8::Local<v8::Integer>(), + v8::Local<v8::Integer>(),v8::Local<v8::Boolean>(), + v8::Local<v8::Integer>(),v8::Local<v8::Value>(),v8::Local<v8::Boolean>(), + v8::Local<v8::Boolean>(),v8::Boolean::New(isolate,true)); v8::Local<v8::Context> context(isolate->GetCurrentContext()); - v8::Local<v8::Script> script; - if (!v8::Script::Compile(context, source, &origin).ToLocal(&script)) { + v8::ScriptCompiler::Source src(source,origin); + v8::MaybeLocal<v8::Module> script = + v8::ScriptCompiler::CompileModule(isolate,&src); + if (script.IsEmpty() || try_catch.HasCaught()) { // Print errors that happened during compilation. if (report_exceptions) ReportException(isolate, &try_catch); return false; } else { v8::Local<v8::Value> result; - if (!script->Run(context).ToLocal(&result)) { + v8::Local<v8::Module> module = script.ToLocalChecked(); + if (module->InstantiateModule(context,resolveCallback).IsNothing()) + ReportException(isolate, &try_catch); + if (!module->Evaluate(context).ToLocal(&result)) { assert(try_catch.HasCaught()); // Print errors that happened during execution. if (report_exceptions) diff --git a/test/cctest/compiler/graph-builder-tester.h b/test/cctest/compiler/graph-builder-tester.h index 2edf6c27e6..5643d4d10b 100644 --- a/test/cctest/compiler/graph-builder-tester.h +++ b/test/cctest/compiler/graph-builder-tester.h @@ -164,9 +164,6 @@ class GraphBuilderTester : public HandleAndZoneScope, Node* ChangeUint32ToTagged(Node* a) { return NewNode(simplified()->ChangeUint32ToTagged(), a); } - Node* ChangeFloat64ToTagged(Node* a) { - return NewNode(simplified()->ChangeFloat64ToTagged(), a); - } Node* ChangeTaggedToBit(Node* a) { return NewNode(simplified()->ChangeTaggedToBit(), a); }