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

Side by Side Diff: runtime/vm/dart_api_impl.cc

Issue 10386107: Implement spawnUri from dart:isolate. This function allows us to (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 7 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « runtime/vm/bootstrap_natives.h ('k') | runtime/vm/dart_api_impl_test.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 #include "include/dart_api.h" 5 #include "include/dart_api.h"
6 6
7 #include "vm/bigint_operations.h" 7 #include "vm/bigint_operations.h"
8 #include "vm/class_finalizer.h" 8 #include "vm/class_finalizer.h"
9 #include "vm/compiler.h" 9 #include "vm/compiler.h"
10 #include "vm/dart.h" 10 #include "vm/dart.h"
(...skipping 613 matching lines...) Expand 10 before | Expand all | Expand 10 after
624 if (Flags::Lookup(flag_name) != NULL) { 624 if (Flags::Lookup(flag_name) != NULL) {
625 return true; 625 return true;
626 } 626 }
627 return false; 627 return false;
628 } 628 }
629 629
630 630
631 // --- Isolates --- 631 // --- Isolates ---
632 632
633 633
634 DART_EXPORT Dart_Isolate Dart_CreateIsolate(const char* name_prefix, 634 static char* BuildIsolateName(const char* script_uri,
635 const char* main) {
636 if (script_uri == NULL) {
637 // Just use the main as the name.
638 if (main == NULL) {
639 return strdup("isolate");
640 } else {
641 return strdup(main);
642 }
643 }
644
645 // Skip past any slashes and backslashes in the script uri.
646 const char* last_slash = strrchr(script_uri, '/');
647 if (last_slash != NULL) {
648 script_uri = last_slash + 1;
649 }
650 const char* last_backslash = strrchr(script_uri, '\\');
651 if (last_backslash != NULL) {
652 script_uri = last_backslash + 1;
653 }
654 if (main == NULL) {
655 main = "main";
656 }
657
658 char* chars = NULL;
659 intptr_t len = OS::SNPrint(NULL, 0, "%s/%s", script_uri, main) + 1;
660 chars = reinterpret_cast<char*>(malloc(len));
661 OS::SNPrint(chars, len, "%s/%s", script_uri, main);
662 return chars;
663 }
664
665
666 DART_EXPORT Dart_Isolate Dart_CreateIsolate(const char* script_uri,
667 const char* main,
635 const uint8_t* snapshot, 668 const uint8_t* snapshot,
636 void* callback_data, 669 void* callback_data,
637 char** error) { 670 char** error) {
638 Isolate* isolate = Dart::CreateIsolate(name_prefix); 671 char* isolate_name = BuildIsolateName(script_uri, main);
672 Isolate* isolate = Dart::CreateIsolate(isolate_name);
673 free(isolate_name);
639 { 674 {
640 DARTSCOPE_NOCHECKS(isolate); 675 DARTSCOPE_NOCHECKS(isolate);
641 const Error& error_obj = 676 const Error& error_obj =
642 Error::Handle(isolate, 677 Error::Handle(isolate,
643 Dart::InitializeIsolate(snapshot, callback_data)); 678 Dart::InitializeIsolate(snapshot, callback_data));
644 if (error_obj.IsNull()) { 679 if (error_obj.IsNull()) {
645 START_TIMER(time_total_runtime); 680 START_TIMER(time_total_runtime);
646 return reinterpret_cast<Dart_Isolate>(isolate); 681 return reinterpret_cast<Dart_Isolate>(isolate);
647 } 682 }
648 *error = strdup(error_obj.ToErrorCString()); 683 *error = strdup(error_obj.ToErrorCString());
(...skipping 2304 matching lines...) Expand 10 before | Expand all | Expand 10 after
2953 2988
2954 DART_EXPORT Dart_Handle Dart_SetLibraryTagHandler( 2989 DART_EXPORT Dart_Handle Dart_SetLibraryTagHandler(
2955 Dart_LibraryTagHandler handler) { 2990 Dart_LibraryTagHandler handler) {
2956 Isolate* isolate = Isolate::Current(); 2991 Isolate* isolate = Isolate::Current();
2957 CHECK_ISOLATE(isolate); 2992 CHECK_ISOLATE(isolate);
2958 isolate->set_library_tag_handler(handler); 2993 isolate->set_library_tag_handler(handler);
2959 return Api::Success(isolate); 2994 return Api::Success(isolate);
2960 } 2995 }
2961 2996
2962 2997
2998 DART_EXPORT Dart_Handle Dart_SetImportMap(Dart_Handle import_map) {
2999 Isolate* isolate = Isolate::Current();
3000 DARTSCOPE(isolate);
3001 const Array& mapping_array = Api::UnwrapArrayHandle(isolate, import_map);
3002 if (mapping_array.IsNull()) {
3003 RETURN_TYPE_ERROR(isolate, import_map, Array);
3004 }
3005 isolate->object_store()->set_import_map(mapping_array);
3006 return Api::Success(isolate);
3007 }
3008
3009
2963 // NOTE: Need to pass 'result' as a parameter here in order to avoid 3010 // NOTE: Need to pass 'result' as a parameter here in order to avoid
2964 // warning: variable 'result' might be clobbered by 'longjmp' or 'vfork' 3011 // warning: variable 'result' might be clobbered by 'longjmp' or 'vfork'
2965 // which shows up because of the use of setjmp. 3012 // which shows up because of the use of setjmp.
2966 static void CompileSource(Isolate* isolate, 3013 static void CompileSource(Isolate* isolate,
2967 const Library& lib, 3014 const Library& lib,
2968 const String& url, 3015 const String& url,
2969 const String& source, 3016 const String& source,
2970 RawScript::Kind kind, 3017 RawScript::Kind kind,
2971 Dart_Handle* result) { 3018 Dart_Handle* result) {
2972 bool update_lib_status = (kind == RawScript::kScript || 3019 bool update_lib_status = (kind == RawScript::kScript ||
(...skipping 13 matching lines...) Expand all
2986 } else { 3033 } else {
2987 *result = Api::NewHandle(isolate, error.raw()); 3034 *result = Api::NewHandle(isolate, error.raw());
2988 if (update_lib_status) { 3035 if (update_lib_status) {
2989 lib.SetLoadError(); 3036 lib.SetLoadError();
2990 } 3037 }
2991 } 3038 }
2992 } 3039 }
2993 3040
2994 3041
2995 DART_EXPORT Dart_Handle Dart_LoadScript(Dart_Handle url, 3042 DART_EXPORT Dart_Handle Dart_LoadScript(Dart_Handle url,
2996 Dart_Handle source, 3043 Dart_Handle source) {
2997 Dart_Handle import_map) {
2998 TIMERSCOPE(time_script_loading); 3044 TIMERSCOPE(time_script_loading);
2999 Isolate* isolate = Isolate::Current(); 3045 Isolate* isolate = Isolate::Current();
3000 DARTSCOPE(isolate); 3046 DARTSCOPE(isolate);
3001 const String& url_str = Api::UnwrapStringHandle(isolate, url); 3047 const String& url_str = Api::UnwrapStringHandle(isolate, url);
3002 if (url_str.IsNull()) { 3048 if (url_str.IsNull()) {
3003 RETURN_TYPE_ERROR(isolate, url, String); 3049 RETURN_TYPE_ERROR(isolate, url, String);
3004 } 3050 }
3005 const String& source_str = Api::UnwrapStringHandle(isolate, source); 3051 const String& source_str = Api::UnwrapStringHandle(isolate, source);
3006 if (source_str.IsNull()) { 3052 if (source_str.IsNull()) {
3007 RETURN_TYPE_ERROR(isolate, source, String); 3053 RETURN_TYPE_ERROR(isolate, source, String);
3008 } 3054 }
3009 const Array& mapping_array = Api::UnwrapArrayHandle(isolate, import_map);
3010 Library& library = 3055 Library& library =
3011 Library::Handle(isolate, isolate->object_store()->root_library()); 3056 Library::Handle(isolate, isolate->object_store()->root_library());
3012 if (!library.IsNull()) { 3057 if (!library.IsNull()) {
3013 const String& library_url = String::Handle(isolate, library.url()); 3058 const String& library_url = String::Handle(isolate, library.url());
3014 return Api::NewError("%s: A script has already been loaded from '%s'.", 3059 return Api::NewError("%s: A script has already been loaded from '%s'.",
3015 CURRENT_FUNC, library_url.ToCString()); 3060 CURRENT_FUNC, library_url.ToCString());
3016 } 3061 }
3017 library = Library::New(url_str); 3062 library = Library::New(url_str);
3018 if (mapping_array.IsNull()) {
3019 library.set_import_map(Array::Handle(isolate, Array::Empty()));
3020 } else {
3021 library.set_import_map(mapping_array);
3022 }
3023 library.Register(); 3063 library.Register();
3024 isolate->object_store()->set_root_library(library); 3064 isolate->object_store()->set_root_library(library);
3025 Dart_Handle result; 3065 Dart_Handle result;
3026 CompileSource(isolate, 3066 CompileSource(isolate,
3027 library, 3067 library,
3028 url_str, 3068 url_str,
3029 source_str, 3069 source_str,
3030 RawScript::kScript, 3070 RawScript::kScript,
3031 &result); 3071 &result);
3032 return result; 3072 return result;
(...skipping 25 matching lines...) Expand all
3058 if (!tmp.IsLibrary()) { 3098 if (!tmp.IsLibrary()) {
3059 return Api::NewError("%s: Unable to deserialize snapshot correctly.", 3099 return Api::NewError("%s: Unable to deserialize snapshot correctly.",
3060 CURRENT_FUNC); 3100 CURRENT_FUNC);
3061 } 3101 }
3062 library ^= tmp.raw(); 3102 library ^= tmp.raw();
3063 isolate->object_store()->set_root_library(library); 3103 isolate->object_store()->set_root_library(library);
3064 return Api::NewHandle(isolate, library.raw()); 3104 return Api::NewHandle(isolate, library.raw());
3065 } 3105 }
3066 3106
3067 3107
3108 DART_EXPORT Dart_Handle Dart_RootLibrary() {
3109 Isolate* isolate = Isolate::Current();
3110 DARTSCOPE(isolate);
3111 Library& library =
3112 Library::Handle(isolate, isolate->object_store()->root_library());
3113 return Api::NewHandle(isolate, library.raw());
3114 }
3115
3116
3068 static void CompileAll(Isolate* isolate, Dart_Handle* result) { 3117 static void CompileAll(Isolate* isolate, Dart_Handle* result) {
3069 ASSERT(isolate != NULL); 3118 ASSERT(isolate != NULL);
3070 const Error& error = Error::Handle(isolate, Library::CompileAll()); 3119 const Error& error = Error::Handle(isolate, Library::CompileAll());
3071 if (error.IsNull()) { 3120 if (error.IsNull()) {
3072 *result = Api::Success(isolate); 3121 *result = Api::Success(isolate);
3073 } else { 3122 } else {
3074 *result = Api::NewHandle(isolate, error.raw()); 3123 *result = Api::NewHandle(isolate, error.raw());
3075 } 3124 }
3076 } 3125 }
3077 3126
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
3143 if (library.IsNull()) { 3192 if (library.IsNull()) {
3144 return Api::NewError("%s: library '%s' not found.", 3193 return Api::NewError("%s: library '%s' not found.",
3145 CURRENT_FUNC, url_str.ToCString()); 3194 CURRENT_FUNC, url_str.ToCString());
3146 } else { 3195 } else {
3147 return Api::NewHandle(isolate, library.raw()); 3196 return Api::NewHandle(isolate, library.raw());
3148 } 3197 }
3149 } 3198 }
3150 3199
3151 3200
3152 DART_EXPORT Dart_Handle Dart_LoadLibrary(Dart_Handle url, 3201 DART_EXPORT Dart_Handle Dart_LoadLibrary(Dart_Handle url,
3153 Dart_Handle source, 3202 Dart_Handle source) {
3154 Dart_Handle import_map) {
3155 TIMERSCOPE(time_script_loading); 3203 TIMERSCOPE(time_script_loading);
3156 Isolate* isolate = Isolate::Current(); 3204 Isolate* isolate = Isolate::Current();
3157 DARTSCOPE(isolate); 3205 DARTSCOPE(isolate);
3158 const String& url_str = Api::UnwrapStringHandle(isolate, url); 3206 const String& url_str = Api::UnwrapStringHandle(isolate, url);
3159 if (url_str.IsNull()) { 3207 if (url_str.IsNull()) {
3160 RETURN_TYPE_ERROR(isolate, url, String); 3208 RETURN_TYPE_ERROR(isolate, url, String);
3161 } 3209 }
3162 const String& source_str = Api::UnwrapStringHandle(isolate, source); 3210 const String& source_str = Api::UnwrapStringHandle(isolate, source);
3163 if (source_str.IsNull()) { 3211 if (source_str.IsNull()) {
3164 RETURN_TYPE_ERROR(isolate, source, String); 3212 RETURN_TYPE_ERROR(isolate, source, String);
3165 } 3213 }
3166 const Array& mapping_array = Api::UnwrapArrayHandle(isolate, import_map);
3167 Library& library = Library::Handle(isolate, Library::LookupLibrary(url_str)); 3214 Library& library = Library::Handle(isolate, Library::LookupLibrary(url_str));
3168 if (library.IsNull()) { 3215 if (library.IsNull()) {
3169 library = Library::New(url_str); 3216 library = Library::New(url_str);
3170 if (mapping_array.IsNull()) {
3171 library.set_import_map(Array::Handle(isolate, Array::Empty()));
3172 } else {
3173 library.set_import_map(mapping_array);
3174 }
3175 library.Register(); 3217 library.Register();
3176 } else if (!library.LoadNotStarted()) { 3218 } else if (!library.LoadNotStarted()) {
3177 // The source for this library has either been loaded or is in the 3219 // The source for this library has either been loaded or is in the
3178 // process of loading. Return an error. 3220 // process of loading. Return an error.
3179 return Api::NewError("%s: library '%s' has already been loaded.", 3221 return Api::NewError("%s: library '%s' has already been loaded.",
3180 CURRENT_FUNC, url_str.ToCString()); 3222 CURRENT_FUNC, url_str.ToCString());
3181 } 3223 }
3182 Dart_Handle result; 3224 Dart_Handle result;
3183 CompileSource(isolate, 3225 CompileSource(isolate,
3184 library, 3226 library,
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
3283 *buffer = NULL; 3325 *buffer = NULL;
3284 } 3326 }
3285 delete debug_region; 3327 delete debug_region;
3286 } else { 3328 } else {
3287 *buffer = NULL; 3329 *buffer = NULL;
3288 *buffer_size = 0; 3330 *buffer_size = 0;
3289 } 3331 }
3290 } 3332 }
3291 3333
3292 } // namespace dart 3334 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/bootstrap_natives.h ('k') | runtime/vm/dart_api_impl_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698