| OLD | NEW |
| 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 2158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2169 *result = Api::NewLocalHandle(error); | 2169 *result = Api::NewLocalHandle(error); |
| 2170 if (update_lib_status) { | 2170 if (update_lib_status) { |
| 2171 lib.SetLoadError(); | 2171 lib.SetLoadError(); |
| 2172 } | 2172 } |
| 2173 } | 2173 } |
| 2174 } | 2174 } |
| 2175 | 2175 |
| 2176 | 2176 |
| 2177 DART_EXPORT Dart_Handle Dart_LoadScript(Dart_Handle url, | 2177 DART_EXPORT Dart_Handle Dart_LoadScript(Dart_Handle url, |
| 2178 Dart_Handle source, | 2178 Dart_Handle source, |
| 2179 Dart_LibraryTagHandler handler) { | 2179 Dart_LibraryTagHandler handler, |
| 2180 Dart_Handle import_map) { |
| 2180 TIMERSCOPE(time_script_loading); | 2181 TIMERSCOPE(time_script_loading); |
| 2181 Isolate* isolate = Isolate::Current(); | 2182 Isolate* isolate = Isolate::Current(); |
| 2182 DARTSCOPE(isolate); | 2183 DARTSCOPE(isolate); |
| 2183 const String& url_str = Api::UnwrapStringHandle(url); | 2184 const String& url_str = Api::UnwrapStringHandle(url); |
| 2184 if (url_str.IsNull()) { | 2185 if (url_str.IsNull()) { |
| 2185 RETURN_TYPE_ERROR(url, String); | 2186 RETURN_TYPE_ERROR(url, String); |
| 2186 } | 2187 } |
| 2187 const String& source_str = Api::UnwrapStringHandle(source); | 2188 const String& source_str = Api::UnwrapStringHandle(source); |
| 2188 if (source_str.IsNull()) { | 2189 if (source_str.IsNull()) { |
| 2189 RETURN_TYPE_ERROR(source, String); | 2190 RETURN_TYPE_ERROR(source, String); |
| 2190 } | 2191 } |
| 2192 const Array& mapping_array = Api::UnwrapArrayHandle(import_map); |
| 2193 if (mapping_array.IsNull()) { |
| 2194 RETURN_TYPE_ERROR(import_map, Array); |
| 2195 } |
| 2191 Library& library = Library::Handle(isolate->object_store()->root_library()); | 2196 Library& library = Library::Handle(isolate->object_store()->root_library()); |
| 2192 if (!library.IsNull()) { | 2197 if (!library.IsNull()) { |
| 2193 const String& library_url = String::Handle(library.url()); | 2198 const String& library_url = String::Handle(library.url()); |
| 2194 return Api::NewError("%s: A script has already been loaded from '%s'.", | 2199 return Api::NewError("%s: A script has already been loaded from '%s'.", |
| 2195 CURRENT_FUNC, library_url.ToCString()); | 2200 CURRENT_FUNC, library_url.ToCString()); |
| 2196 } | 2201 } |
| 2197 isolate->set_library_tag_handler(handler); | 2202 isolate->set_library_tag_handler(handler); |
| 2198 library = Library::New(url_str); | 2203 library = Library::New(url_str); |
| 2204 library.set_import_map(mapping_array); |
| 2199 library.Register(); | 2205 library.Register(); |
| 2200 isolate->object_store()->set_root_library(library); | 2206 isolate->object_store()->set_root_library(library); |
| 2201 Dart_Handle result; | 2207 Dart_Handle result; |
| 2202 CompileSource(isolate, | 2208 CompileSource(isolate, |
| 2203 library, | 2209 library, |
| 2204 url_str, | 2210 url_str, |
| 2205 source_str, | 2211 source_str, |
| 2206 RawScript::kScript, | 2212 RawScript::kScript, |
| 2207 &result); | 2213 &result); |
| 2208 return result; | 2214 return result; |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2314 const Library& library = Library::Handle(Library::LookupLibrary(url_str)); | 2320 const Library& library = Library::Handle(Library::LookupLibrary(url_str)); |
| 2315 if (library.IsNull()) { | 2321 if (library.IsNull()) { |
| 2316 return Api::NewError("%s: library '%s' not found.", | 2322 return Api::NewError("%s: library '%s' not found.", |
| 2317 CURRENT_FUNC, url_str.ToCString()); | 2323 CURRENT_FUNC, url_str.ToCString()); |
| 2318 } else { | 2324 } else { |
| 2319 return Api::NewLocalHandle(library); | 2325 return Api::NewLocalHandle(library); |
| 2320 } | 2326 } |
| 2321 } | 2327 } |
| 2322 | 2328 |
| 2323 | 2329 |
| 2324 DART_EXPORT Dart_Handle Dart_LoadLibrary(Dart_Handle url, Dart_Handle source) { | 2330 DART_EXPORT Dart_Handle Dart_LoadLibrary(Dart_Handle url, |
| 2331 Dart_Handle source, |
| 2332 Dart_Handle import_map) { |
| 2325 TIMERSCOPE(time_script_loading); | 2333 TIMERSCOPE(time_script_loading); |
| 2326 Isolate* isolate = Isolate::Current(); | 2334 Isolate* isolate = Isolate::Current(); |
| 2327 DARTSCOPE(isolate); | 2335 DARTSCOPE(isolate); |
| 2328 const String& url_str = Api::UnwrapStringHandle(url); | 2336 const String& url_str = Api::UnwrapStringHandle(url); |
| 2329 if (url_str.IsNull()) { | 2337 if (url_str.IsNull()) { |
| 2330 RETURN_TYPE_ERROR(url, String); | 2338 RETURN_TYPE_ERROR(url, String); |
| 2331 } | 2339 } |
| 2332 const String& source_str = Api::UnwrapStringHandle(source); | 2340 const String& source_str = Api::UnwrapStringHandle(source); |
| 2333 if (source_str.IsNull()) { | 2341 if (source_str.IsNull()) { |
| 2334 RETURN_TYPE_ERROR(source, String); | 2342 RETURN_TYPE_ERROR(source, String); |
| 2335 } | 2343 } |
| 2344 const Array& mapping_array = Api::UnwrapArrayHandle(import_map); |
| 2345 if (mapping_array.IsNull()) { |
| 2346 RETURN_TYPE_ERROR(import_map, Array); |
| 2347 } |
| 2336 Library& library = Library::Handle(Library::LookupLibrary(url_str)); | 2348 Library& library = Library::Handle(Library::LookupLibrary(url_str)); |
| 2337 if (library.IsNull()) { | 2349 if (library.IsNull()) { |
| 2338 library = Library::New(url_str); | 2350 library = Library::New(url_str); |
| 2351 library.set_import_map(mapping_array); |
| 2339 library.Register(); | 2352 library.Register(); |
| 2340 } else if (!library.LoadNotStarted()) { | 2353 } else if (!library.LoadNotStarted()) { |
| 2341 // The source for this library has either been loaded or is in the | 2354 // The source for this library has either been loaded or is in the |
| 2342 // process of loading. Return an error. | 2355 // process of loading. Return an error. |
| 2343 return Api::NewError("%s: library '%s' has already been loaded.", | 2356 return Api::NewError("%s: library '%s' has already been loaded.", |
| 2344 CURRENT_FUNC, url_str.ToCString()); | 2357 CURRENT_FUNC, url_str.ToCString()); |
| 2345 } | 2358 } |
| 2346 Dart_Handle result; | 2359 Dart_Handle result; |
| 2347 CompileSource(isolate, | 2360 CompileSource(isolate, |
| 2348 library, | 2361 library, |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2432 } | 2445 } |
| 2433 delete debug_region; | 2446 delete debug_region; |
| 2434 } else { | 2447 } else { |
| 2435 *buffer = NULL; | 2448 *buffer = NULL; |
| 2436 *buffer_size = 0; | 2449 *buffer_size = 0; |
| 2437 } | 2450 } |
| 2438 } | 2451 } |
| 2439 | 2452 |
| 2440 | 2453 |
| 2441 } // namespace dart | 2454 } // namespace dart |
| OLD | NEW |