Commit d8a5506c authored by Georg Neis's avatar Georg Neis Committed by Commit Bot

[modules] Include module specifier in instantiation error messages.

Bug: chromium:780819
Change-Id: I07c5ff3cf955edb087a175ea2d71a35e0f520ec3
Reviewed-on: https://chromium-review.googlesource.com/813839
Commit-Queue: Georg Neis <neis@chromium.org>
Reviewed-by: 's avatarAdam Klein <adamk@chromium.org>
Cr-Commit-Position: refs/heads/master@{#49953}
parent 060f868e
...@@ -308,7 +308,7 @@ class ErrorUtils : public AllStatic { ...@@ -308,7 +308,7 @@ class ErrorUtils : public AllStatic {
T(ConstructorNotFunction, "Constructor % requires 'new'") \ T(ConstructorNotFunction, "Constructor % requires 'new'") \
T(ConstructorNotReceiver, "The .constructor property is not an object") \ T(ConstructorNotReceiver, "The .constructor property is not an object") \
T(CurrencyCode, "Currency code is required with currency style.") \ T(CurrencyCode, "Currency code is required with currency style.") \
T(CyclicModuleDependency, "Detected cycle while resolving name '%'") \ T(CyclicModuleDependency, "Detected cycle while resolving name '%' in '%'") \
T(DataViewNotArrayBuffer, \ T(DataViewNotArrayBuffer, \
"First argument to DataView constructor must be an ArrayBuffer") \ "First argument to DataView constructor must be an ArrayBuffer") \
T(DateType, "this is not a Date object.") \ T(DateType, "this is not a Date object.") \
...@@ -564,7 +564,7 @@ class ErrorUtils : public AllStatic { ...@@ -564,7 +564,7 @@ class ErrorUtils : public AllStatic {
T(ValueOutOfRange, "Value % out of range for % options property %") \ T(ValueOutOfRange, "Value % out of range for % options property %") \
/* SyntaxError */ \ /* SyntaxError */ \
T(AmbiguousExport, \ T(AmbiguousExport, \
"The requested module contains conflicting star exports for name '%'") \ "The requested module '%' contains conflicting star exports for name '%'") \
T(BadGetterArity, "Getter must not have any formal parameters.") \ T(BadGetterArity, "Getter must not have any formal parameters.") \
T(BadSetterArity, "Setter must have exactly one formal parameter.") \ T(BadSetterArity, "Setter must have exactly one formal parameter.") \
T(BigIntInvalidString, "Invalid BigInt string") \ T(BigIntInvalidString, "Invalid BigInt string") \
...@@ -699,7 +699,7 @@ class ErrorUtils : public AllStatic { ...@@ -699,7 +699,7 @@ class ErrorUtils : public AllStatic {
"Lexical declaration cannot appear in a single-statement context") \ "Lexical declaration cannot appear in a single-statement context") \
T(UnknownLabel, "Undefined label '%'") \ T(UnknownLabel, "Undefined label '%'") \
T(UnresolvableExport, \ T(UnresolvableExport, \
"The requested module does not provide an export named '%'") \ "The requested module '%' does not provide an export named '%'") \
T(UnterminatedArgList, "missing ) after argument list") \ T(UnterminatedArgList, "missing ) after argument list") \
T(UnterminatedRegExp, "Invalid regular expression: missing /") \ T(UnterminatedRegExp, "Invalid regular expression: missing /") \
T(UnterminatedTemplate, "Unterminated template literal") \ T(UnterminatedTemplate, "Unterminated template literal") \
......
...@@ -244,8 +244,11 @@ MaybeHandle<Cell> Module::ResolveImport(Handle<Module> module, ...@@ -244,8 +244,11 @@ MaybeHandle<Cell> Module::ResolveImport(Handle<Module> module,
Isolate* isolate = module->GetIsolate(); Isolate* isolate = module->GetIsolate();
Handle<Module> requested_module( Handle<Module> requested_module(
Module::cast(module->requested_modules()->get(module_request)), isolate); Module::cast(module->requested_modules()->get(module_request)), isolate);
MaybeHandle<Cell> result = Module::ResolveExport(requested_module, name, loc, Handle<String> specifier(
must_resolve, resolve_set); String::cast(module->info()->module_requests()->get(module_request)),
isolate);
MaybeHandle<Cell> result = Module::ResolveExport(
requested_module, specifier, name, loc, must_resolve, resolve_set);
if (isolate->has_pending_exception()) { if (isolate->has_pending_exception()) {
DCHECK(result.is_null()); DCHECK(result.is_null());
if (must_resolve) module->RecordError(); if (must_resolve) module->RecordError();
...@@ -258,7 +261,8 @@ MaybeHandle<Cell> Module::ResolveImport(Handle<Module> module, ...@@ -258,7 +261,8 @@ MaybeHandle<Cell> Module::ResolveImport(Handle<Module> module,
} }
MaybeHandle<Cell> Module::ResolveExport(Handle<Module> module, MaybeHandle<Cell> Module::ResolveExport(Handle<Module> module,
Handle<String> name, Handle<String> module_specifier,
Handle<String> export_name,
MessageLocation loc, bool must_resolve, MessageLocation loc, bool must_resolve,
Module::ResolveSet* resolve_set) { Module::ResolveSet* resolve_set) {
DCHECK_NE(module->status(), kErrored); DCHECK_NE(module->status(), kErrored);
...@@ -266,7 +270,7 @@ MaybeHandle<Cell> Module::ResolveExport(Handle<Module> module, ...@@ -266,7 +270,7 @@ MaybeHandle<Cell> Module::ResolveExport(Handle<Module> module,
DCHECK_GE(module->status(), kPreInstantiating); DCHECK_GE(module->status(), kPreInstantiating);
Isolate* isolate = module->GetIsolate(); Isolate* isolate = module->GetIsolate();
Handle<Object> object(module->exports()->Lookup(name), isolate); Handle<Object> object(module->exports()->Lookup(export_name), isolate);
if (object->IsCell()) { if (object->IsCell()) {
// Already resolved (e.g. because it's a local export). // Already resolved (e.g. because it's a local export).
return Handle<Cell>::cast(object); return Handle<Cell>::cast(object);
...@@ -282,17 +286,18 @@ MaybeHandle<Cell> Module::ResolveExport(Handle<Module> module, ...@@ -282,17 +286,18 @@ MaybeHandle<Cell> Module::ResolveExport(Handle<Module> module,
Zone* zone = resolve_set->zone(); Zone* zone = resolve_set->zone();
name_set = name_set =
new (zone->New(sizeof(UnorderedStringSet))) UnorderedStringSet(zone); new (zone->New(sizeof(UnorderedStringSet))) UnorderedStringSet(zone);
} else if (name_set->count(name)) { } else if (name_set->count(export_name)) {
// Cycle detected. // Cycle detected.
if (must_resolve) { if (must_resolve) {
return isolate->Throw<Cell>( return isolate->Throw<Cell>(
isolate->factory()->NewSyntaxError( isolate->factory()->NewSyntaxError(
MessageTemplate::kCyclicModuleDependency, name), MessageTemplate::kCyclicModuleDependency, export_name,
module_specifier),
&loc); &loc);
} }
return MaybeHandle<Cell>(); return MaybeHandle<Cell>();
} }
name_set->insert(name); name_set->insert(export_name);
} }
if (object->IsModuleInfoEntry()) { if (object->IsModuleInfoEntry()) {
...@@ -313,23 +318,24 @@ MaybeHandle<Cell> Module::ResolveExport(Handle<Module> module, ...@@ -313,23 +318,24 @@ MaybeHandle<Cell> Module::ResolveExport(Handle<Module> module,
// The export table may have changed but the entry in question should be // The export table may have changed but the entry in question should be
// unchanged. // unchanged.
Handle<ObjectHashTable> exports(module->exports(), isolate); Handle<ObjectHashTable> exports(module->exports(), isolate);
DCHECK(exports->Lookup(name)->IsModuleInfoEntry()); DCHECK(exports->Lookup(export_name)->IsModuleInfoEntry());
exports = ObjectHashTable::Put(exports, name, cell); exports = ObjectHashTable::Put(exports, export_name, cell);
module->set_exports(*exports); module->set_exports(*exports);
return cell; return cell;
} }
DCHECK(object->IsTheHole(isolate)); DCHECK(object->IsTheHole(isolate));
return Module::ResolveExportUsingStarExports(module, name, loc, must_resolve, return Module::ResolveExportUsingStarExports(
resolve_set); module, module_specifier, export_name, loc, must_resolve, resolve_set);
} }
MaybeHandle<Cell> Module::ResolveExportUsingStarExports( MaybeHandle<Cell> Module::ResolveExportUsingStarExports(
Handle<Module> module, Handle<String> name, MessageLocation loc, Handle<Module> module, Handle<String> module_specifier,
bool must_resolve, Module::ResolveSet* resolve_set) { Handle<String> export_name, MessageLocation loc, bool must_resolve,
Module::ResolveSet* resolve_set) {
Isolate* isolate = module->GetIsolate(); Isolate* isolate = module->GetIsolate();
if (!name->Equals(isolate->heap()->default_string())) { if (!export_name->Equals(isolate->heap()->default_string())) {
// Go through all star exports looking for the given name. If multiple star // Go through all star exports looking for the given name. If multiple star
// exports provide the name, make sure they all map it to the same cell. // exports provide the name, make sure they all map it to the same cell.
Handle<Cell> unique_cell; Handle<Cell> unique_cell;
...@@ -346,14 +352,14 @@ MaybeHandle<Cell> Module::ResolveExportUsingStarExports( ...@@ -346,14 +352,14 @@ MaybeHandle<Cell> Module::ResolveExportUsingStarExports(
MessageLocation new_loc(script, entry->beg_pos(), entry->end_pos()); MessageLocation new_loc(script, entry->beg_pos(), entry->end_pos());
Handle<Cell> cell; Handle<Cell> cell;
if (ResolveImport(module, name, entry->module_request(), new_loc, false, if (ResolveImport(module, export_name, entry->module_request(), new_loc,
resolve_set) false, resolve_set)
.ToHandle(&cell)) { .ToHandle(&cell)) {
if (unique_cell.is_null()) unique_cell = cell; if (unique_cell.is_null()) unique_cell = cell;
if (*unique_cell != *cell) { if (*unique_cell != *cell) {
return isolate->Throw<Cell>( return isolate->Throw<Cell>(isolate->factory()->NewSyntaxError(
isolate->factory()->NewSyntaxError( MessageTemplate::kAmbiguousExport,
MessageTemplate::kAmbiguousExport, name), module_specifier, export_name),
&loc); &loc);
} }
} else if (isolate->has_pending_exception()) { } else if (isolate->has_pending_exception()) {
...@@ -364,8 +370,8 @@ MaybeHandle<Cell> Module::ResolveExportUsingStarExports( ...@@ -364,8 +370,8 @@ MaybeHandle<Cell> Module::ResolveExportUsingStarExports(
if (!unique_cell.is_null()) { if (!unique_cell.is_null()) {
// Found a unique star export for this name. // Found a unique star export for this name.
Handle<ObjectHashTable> exports(module->exports(), isolate); Handle<ObjectHashTable> exports(module->exports(), isolate);
DCHECK(exports->Lookup(name)->IsTheHole(isolate)); DCHECK(exports->Lookup(export_name)->IsTheHole(isolate));
exports = ObjectHashTable::Put(exports, name, unique_cell); exports = ObjectHashTable::Put(exports, export_name, unique_cell);
module->set_exports(*exports); module->set_exports(*exports);
return unique_cell; return unique_cell;
} }
...@@ -373,8 +379,9 @@ MaybeHandle<Cell> Module::ResolveExportUsingStarExports( ...@@ -373,8 +379,9 @@ MaybeHandle<Cell> Module::ResolveExportUsingStarExports(
// Unresolvable. // Unresolvable.
if (must_resolve) { if (must_resolve) {
return isolate->Throw<Cell>(isolate->factory()->NewSyntaxError( return isolate->Throw<Cell>(
MessageTemplate::kUnresolvableExport, name), isolate->factory()->NewSyntaxError(MessageTemplate::kUnresolvableExport,
module_specifier, export_name),
&loc); &loc);
} }
return MaybeHandle<Cell>(); return MaybeHandle<Cell>();
...@@ -606,8 +613,8 @@ bool Module::FinishInstantiate(Handle<Module> module, ...@@ -606,8 +613,8 @@ bool Module::FinishInstantiate(Handle<Module> module,
if (name->IsUndefined(isolate)) continue; // Star export. if (name->IsUndefined(isolate)) continue; // Star export.
MessageLocation loc(script, entry->beg_pos(), entry->end_pos()); MessageLocation loc(script, entry->beg_pos(), entry->end_pos());
ResolveSet resolve_set(zone); ResolveSet resolve_set(zone);
if (ResolveExport(module, Handle<String>::cast(name), loc, true, if (ResolveExport(module, Handle<String>(), Handle<String>::cast(name), loc,
&resolve_set) true, &resolve_set)
.is_null()) { .is_null()) {
return false; return false;
} }
......
...@@ -154,15 +154,17 @@ class Module : public Struct { ...@@ -154,15 +154,17 @@ class Module : public Struct {
// exception (so check manually!). // exception (so check manually!).
class ResolveSet; class ResolveSet;
static MUST_USE_RESULT MaybeHandle<Cell> ResolveExport( static MUST_USE_RESULT MaybeHandle<Cell> ResolveExport(
Handle<Module> module, Handle<String> name, MessageLocation loc, Handle<Module> module, Handle<String> module_specifier,
bool must_resolve, ResolveSet* resolve_set); Handle<String> export_name, MessageLocation loc, bool must_resolve,
ResolveSet* resolve_set);
static MUST_USE_RESULT MaybeHandle<Cell> ResolveImport( static MUST_USE_RESULT MaybeHandle<Cell> ResolveImport(
Handle<Module> module, Handle<String> name, int module_request, Handle<Module> module, Handle<String> name, int module_request,
MessageLocation loc, bool must_resolve, ResolveSet* resolve_set); MessageLocation loc, bool must_resolve, ResolveSet* resolve_set);
static MUST_USE_RESULT MaybeHandle<Cell> ResolveExportUsingStarExports( static MUST_USE_RESULT MaybeHandle<Cell> ResolveExportUsingStarExports(
Handle<Module> module, Handle<String> name, MessageLocation loc, Handle<Module> module, Handle<String> module_specifier,
bool must_resolve, ResolveSet* resolve_set); Handle<String> export_name, MessageLocation loc, bool must_resolve,
ResolveSet* resolve_set);
static MUST_USE_RESULT bool PrepareInstantiate( static MUST_USE_RESULT bool PrepareInstantiate(
Handle<Module> module, v8::Local<v8::Context> context, Handle<Module> module, v8::Local<v8::Context> context,
......
*%(basename)s:7: SyntaxError: Detected cycle while resolving name 'a' *%(basename)s:7: SyntaxError: Detected cycle while resolving name 'a' in 'modules-cycle1.js'
import {a} from "modules-cycle1.js"; import {a} from "modules-cycle1.js";
^ ^
SyntaxError: Detected cycle while resolving name 'a' SyntaxError: Detected cycle while resolving name 'a' in 'modules-cycle1.js'
*%(basename)s:7: SyntaxError: Detected cycle while resolving name 'a' *%(basename)s:7: SyntaxError: Detected cycle while resolving name 'a' in 'modules-skip-cycle2.js'
import {a} from "modules-skip-cycle2.js"; import {a} from "modules-skip-cycle2.js";
^ ^
SyntaxError: Detected cycle while resolving name 'a' SyntaxError: Detected cycle while resolving name 'a' in 'modules-skip-cycle2.js'
*%(basename)s:7: SyntaxError: Detected cycle while resolving name 'a' *%(basename)s:7: SyntaxError: Detected cycle while resolving name 'a' in 'modules-skip-cycle3.js'
export {a as x} from "modules-skip-cycle3.js"; export {a as x} from "modules-skip-cycle3.js";
^^^^^^ ^^^^^^
SyntaxError: Detected cycle while resolving name 'a' SyntaxError: Detected cycle while resolving name 'a' in 'modules-skip-cycle3.js'
*modules-cycle3.js:7: SyntaxError: Detected cycle while resolving name 'a' *modules-cycle3.js:7: SyntaxError: Detected cycle while resolving name 'a' in 'modules-skip-cycle3.js'
export {a as x} from "modules-skip-cycle3.js"; export {a as x} from "modules-skip-cycle3.js";
^^^^^^ ^^^^^^
SyntaxError: Detected cycle while resolving name 'a' SyntaxError: Detected cycle while resolving name 'a' in 'modules-skip-cycle3.js'
*%(basename)s:8: SyntaxError: Detected cycle while resolving name 'foo' *%(basename)s:8: SyntaxError: Detected cycle while resolving name 'foo' in 'modules-cycle5.js'
export {foo} from "modules-cycle5.js"; export {foo} from "modules-cycle5.js";
^^^ ^^^
SyntaxError: Detected cycle while resolving name 'foo' SyntaxError: Detected cycle while resolving name 'foo' in 'modules-cycle5.js'
*modules-skip-cycle6.js:5: SyntaxError: The requested module does not provide an export named 'foo' *modules-skip-cycle6.js:5: SyntaxError: The requested module 'modules-cycle6.js' does not provide an export named 'foo'
export {foo} from "modules-cycle6.js"; export {foo} from "modules-cycle6.js";
^^^ ^^^
SyntaxError: The requested module does not provide an export named 'foo' SyntaxError: The requested module 'modules-cycle6.js' does not provide an export named 'foo'
*%(basename)s:7: SyntaxError: The requested module does not provide an export named 'a' *%(basename)s:7: SyntaxError: The requested module 'modules-import1.js' does not provide an export named 'a'
import {a} from "modules-import1.js"; import {a} from "modules-import1.js";
^ ^
SyntaxError: The requested module does not provide an export named 'a' SyntaxError: The requested module 'modules-import1.js' does not provide an export named 'a'
*%(basename)s:7: SyntaxError: The requested module does not provide an export named 'a' *%(basename)s:7: SyntaxError: The requested module 'modules-import2.js' does not provide an export named 'a'
import {a as b} from "modules-import2.js"; import {a as b} from "modules-import2.js";
^ ^
SyntaxError: The requested module does not provide an export named 'a' SyntaxError: The requested module 'modules-import2.js' does not provide an export named 'a'
*%(basename)s:7: SyntaxError: The requested module does not provide an export named 'default' *%(basename)s:7: SyntaxError: The requested module 'modules-import3.js' does not provide an export named 'default'
import foo from "modules-import3.js"; import foo from "modules-import3.js";
^^^ ^^^
SyntaxError: The requested module does not provide an export named 'default' SyntaxError: The requested module 'modules-import3.js' does not provide an export named 'default'
*%(basename)s:8: SyntaxError: The requested module does not provide an export named 'c' *%(basename)s:8: SyntaxError: The requested module 'modules-import4.js' does not provide an export named 'c'
export {c as a} from "modules-import4.js"; export {c as a} from "modules-import4.js";
^^^^^^ ^^^^^^
SyntaxError: The requested module does not provide an export named 'c' SyntaxError: The requested module 'modules-import4.js' does not provide an export named 'c'
*%(basename)s:8: SyntaxError: The requested module does not provide an export named 'c' *%(basename)s:8: SyntaxError: The requested module 'modules-import5.js' does not provide an export named 'c'
export {c as a} from "modules-import5.js"; export {c as a} from "modules-import5.js";
^^^^^^ ^^^^^^
SyntaxError: The requested module does not provide an export named 'c' SyntaxError: The requested module 'modules-import5.js' does not provide an export named 'c'
*%(basename)s:9: SyntaxError: The requested module does not provide an export named 'c' *%(basename)s:9: SyntaxError: The requested module 'modules-import6.js' does not provide an export named 'c'
import {c} from "modules-import6.js"; import {c} from "modules-import6.js";
^ ^
SyntaxError: The requested module does not provide an export named 'c' SyntaxError: The requested module 'modules-import6.js' does not provide an export named 'c'
*%(basename)s:7: SyntaxError: The requested module contains conflicting star exports for name 'a' *%(basename)s:7: SyntaxError: The requested module '../../mjsunit/modules-skip-7.js' contains conflicting star exports for name 'a'
import {a} from "../../mjsunit/modules-skip-7.js"; import {a} from "../../mjsunit/modules-skip-7.js";
^ ^
SyntaxError: The requested module contains conflicting star exports for name 'a' SyntaxError: The requested module '../../mjsunit/modules-skip-7.js' contains conflicting star exports for name 'a'
*%(basename)s:7: SyntaxError: The requested module contains conflicting star exports for name 'a' *%(basename)s:7: SyntaxError: The requested module '../../mjsunit/modules-skip-star-exports-conflict.js' contains conflicting star exports for name 'a'
export * from "../../mjsunit/modules-skip-star-exports-conflict.js"; export * from "../../mjsunit/modules-skip-star-exports-conflict.js";
^ ^
SyntaxError: The requested module contains conflicting star exports for name 'a' SyntaxError: The requested module '../../mjsunit/modules-skip-star-exports-conflict.js' contains conflicting star exports for name 'a'
*modules-import4.js:8: SyntaxError: The requested module does not provide an export named 'c' *modules-import4.js:8: SyntaxError: The requested module 'modules-import4.js' does not provide an export named 'c'
export {c as a} from "modules-import4.js"; export {c as a} from "modules-import4.js";
^^^^^^ ^^^^^^
SyntaxError: The requested module does not provide an export named 'c' SyntaxError: The requested module 'modules-import4.js' does not provide an export named 'c'
...@@ -29,7 +29,8 @@ async function test2() { ...@@ -29,7 +29,8 @@ async function test2() {
} catch(e) { } catch(e) {
assertInstanceof(e, SyntaxError); assertInstanceof(e, SyntaxError);
assertEquals( assertEquals(
"The requested module does not provide an export named 'default'", "The requested module 'modules-skip-empty.js' does not provide an " +
"export named 'default'",
e.message); e.message);
ran = true; ran = true;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment