- Make sure to lookup main in re-exported namespaces too.

R=asiva@google.com

Review URL: https://codereview.chromium.org//864233003

git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@43078 260f80e4-7a28-3924-810f-c04153c831b5
This commit is contained in:
iposva@google.com 2015-01-22 21:28:27 +00:00
parent 03aa9c33e5
commit fc044a7294
4 changed files with 64 additions and 18 deletions

View file

@ -1569,31 +1569,46 @@ IsolateSpawnState::~IsolateSpawnState() {
RawObject* IsolateSpawnState::ResolveFunction() {
const String& func_name = String::Handle(String::New(function_name()));
if (library_url() == NULL) {
// Handle spawnUri lookup rules.
// Check whether the root library defines a main function.
const Library& lib = Library::Handle(I->object_store()->root_library());
Function& func = Function::Handle(lib.LookupLocalFunction(func_name));
if (func.IsNull()) {
// Check whether main is reexported from the root library.
const Object& obj = Object::Handle(lib.LookupReExport(func_name));
if (obj.IsFunction()) {
func ^= obj.raw();
}
}
if (func.IsNull()) {
const String& msg = String::Handle(String::NewFormatted(
"Unable to resolve function '%s' in script '%s'.",
function_name(), script_url()));
return LanguageError::New(msg);
}
return func.raw();
}
ASSERT(script_url() == NULL);
// Resolve the library.
Library& lib = Library::Handle();
if (library_url()) {
const String& lib_url = String::Handle(String::New(library_url()));
lib = Library::LookupLibrary(lib_url);
const Library& lib = Library::Handle(Library::LookupLibrary(lib_url));
if (lib.IsNull() || lib.IsError()) {
const String& msg = String::Handle(String::NewFormatted(
"Unable to find library '%s'.", library_url()));
return LanguageError::New(msg);
}
} else {
lib = I->object_store()->root_library();
}
ASSERT(!lib.IsNull());
// Resolve the function.
const String& func_name = String::Handle(String::New(function_name()));
if (class_name() == NULL) {
const Function& func = Function::Handle(lib.LookupLocalFunction(func_name));
if (func.IsNull()) {
const String& msg = String::Handle(String::NewFormatted(
"Unable to resolve function '%s' in library '%s'.",
function_name(),
(library_url() != NULL ? library_url() : script_url())));
function_name(), library_url()));
return LanguageError::New(msg);
}
return func.raw();

View file

@ -0,0 +1,5 @@
export "spawn_uri_exported_main_lib.dart";
maine() {
print("This is not the maine you are looking for.");
}

View file

@ -0,0 +1,6 @@
library spawn_uri_exported_main_lib;
main(args, msg) {
print("From main!");
msg.send(50);
}

View file

@ -0,0 +1,20 @@
import "dart:async";
import "dart:isolate";
import "package:expect/expect.dart";
main() {
print("Spawning isolate.");
var t = new Timer(new Duration(seconds:5), () {
Expect.fail("Isolate was not spawned successfully.");
});
var rp = new RawReceivePort();
rp.handler = (msg) {
print("Spawned main called.");
Expect.equals(msg, 50);
rp.close();
};
Isolate.spawnUri(Uri.parse("spawn_uri_exported_main.dart"), null, rp.sendPort).then((_) {
print("Loaded");
t.cancel();
});
}