Index: runtime/vm/dart_api_impl.cc |
=================================================================== |
--- runtime/vm/dart_api_impl.cc (revision 7756) |
+++ runtime/vm/dart_api_impl.cc (working copy) |
@@ -631,46 +631,11 @@ |
// --- Isolates --- |
-static char* BuildIsolateName(const char* script_uri, |
- const char* main) { |
- if (script_uri == NULL) { |
- // Just use the main as the name. |
- if (main == NULL) { |
- return strdup("isolate"); |
- } else { |
- return strdup(main); |
- } |
- } |
- |
- // Skip past any slashes and backslashes in the script uri. |
- const char* last_slash = strrchr(script_uri, '/'); |
- if (last_slash != NULL) { |
- script_uri = last_slash + 1; |
- } |
- const char* last_backslash = strrchr(script_uri, '\\'); |
- if (last_backslash != NULL) { |
- script_uri = last_backslash + 1; |
- } |
- if (main == NULL) { |
- main = "main"; |
- } |
- |
- char* chars = NULL; |
- intptr_t len = OS::SNPrint(NULL, 0, "%s/%s", script_uri, main) + 1; |
- chars = reinterpret_cast<char*>(malloc(len)); |
- OS::SNPrint(chars, len, "%s/%s", script_uri, main); |
- return chars; |
-} |
- |
- |
-DART_EXPORT Dart_Isolate Dart_CreateIsolate(const char* script_uri, |
- const char* main, |
+DART_EXPORT Dart_Isolate Dart_CreateIsolate(const char* name_prefix, |
const uint8_t* snapshot, |
void* callback_data, |
char** error) { |
- char* isolate_name = BuildIsolateName(script_uri, main); |
- Isolate* isolate = Dart::CreateIsolate(isolate_name); |
- free(isolate_name); |
+ Isolate* isolate = Dart::CreateIsolate(name_prefix); |
{ |
DARTSCOPE_NOCHECKS(isolate); |
const Error& error_obj = |
@@ -2995,18 +2960,6 @@ |
} |
-DART_EXPORT Dart_Handle Dart_SetImportMap(Dart_Handle import_map) { |
- Isolate* isolate = Isolate::Current(); |
- DARTSCOPE(isolate); |
- const Array& mapping_array = Api::UnwrapArrayHandle(isolate, import_map); |
- if (mapping_array.IsNull()) { |
- RETURN_TYPE_ERROR(isolate, import_map, Array); |
- } |
- isolate->object_store()->set_import_map(mapping_array); |
- return Api::Success(isolate); |
-} |
- |
- |
// NOTE: Need to pass 'result' as a parameter here in order to avoid |
// warning: variable 'result' might be clobbered by 'longjmp' or 'vfork' |
// which shows up because of the use of setjmp. |
@@ -3040,7 +2993,8 @@ |
DART_EXPORT Dart_Handle Dart_LoadScript(Dart_Handle url, |
- Dart_Handle source) { |
+ Dart_Handle source, |
+ Dart_Handle import_map) { |
TIMERSCOPE(time_script_loading); |
Isolate* isolate = Isolate::Current(); |
DARTSCOPE(isolate); |
@@ -3052,6 +3006,7 @@ |
if (source_str.IsNull()) { |
RETURN_TYPE_ERROR(isolate, source, String); |
} |
+ const Array& mapping_array = Api::UnwrapArrayHandle(isolate, import_map); |
Library& library = |
Library::Handle(isolate, isolate->object_store()->root_library()); |
if (!library.IsNull()) { |
@@ -3060,6 +3015,11 @@ |
CURRENT_FUNC, library_url.ToCString()); |
} |
library = Library::New(url_str); |
+ if (mapping_array.IsNull()) { |
+ library.set_import_map(Array::Handle(isolate, Array::Empty())); |
+ } else { |
+ library.set_import_map(mapping_array); |
+ } |
library.Register(); |
isolate->object_store()->set_root_library(library); |
Dart_Handle result; |
@@ -3105,15 +3065,6 @@ |
} |
-DART_EXPORT Dart_Handle Dart_RootLibrary() { |
- Isolate* isolate = Isolate::Current(); |
- DARTSCOPE(isolate); |
- Library& library = |
- Library::Handle(isolate, isolate->object_store()->root_library()); |
- return Api::NewHandle(isolate, library.raw()); |
-} |
- |
- |
static void CompileAll(Isolate* isolate, Dart_Handle* result) { |
ASSERT(isolate != NULL); |
const Error& error = Error::Handle(isolate, Library::CompileAll()); |
@@ -3199,7 +3150,8 @@ |
DART_EXPORT Dart_Handle Dart_LoadLibrary(Dart_Handle url, |
- Dart_Handle source) { |
+ Dart_Handle source, |
+ Dart_Handle import_map) { |
TIMERSCOPE(time_script_loading); |
Isolate* isolate = Isolate::Current(); |
DARTSCOPE(isolate); |
@@ -3211,9 +3163,15 @@ |
if (source_str.IsNull()) { |
RETURN_TYPE_ERROR(isolate, source, String); |
} |
+ const Array& mapping_array = Api::UnwrapArrayHandle(isolate, import_map); |
Library& library = Library::Handle(isolate, Library::LookupLibrary(url_str)); |
if (library.IsNull()) { |
library = Library::New(url_str); |
+ if (mapping_array.IsNull()) { |
+ library.set_import_map(Array::Handle(isolate, Array::Empty())); |
+ } else { |
+ library.set_import_map(mapping_array); |
+ } |
library.Register(); |
} else if (!library.LoadNotStarted()) { |
// The source for this library has either been loaded or is in the |