OLD | NEW |
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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 #include "include/dart_mirrors_api.h" | 6 #include "include/dart_mirrors_api.h" |
7 #include "include/dart_native_api.h" | 7 #include "include/dart_native_api.h" |
8 | 8 |
9 #include "platform/assert.h" | 9 #include "platform/assert.h" |
10 #include "vm/bigint_operations.h" | 10 #include "vm/bigint_operations.h" |
(...skipping 4775 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4786 script.kind() == RawScript::kLibraryTag); | 4786 script.kind() == RawScript::kLibraryTag); |
4787 if (update_lib_status) { | 4787 if (update_lib_status) { |
4788 lib.SetLoadInProgress(); | 4788 lib.SetLoadInProgress(); |
4789 } | 4789 } |
4790 ASSERT(isolate != NULL); | 4790 ASSERT(isolate != NULL); |
4791 const Error& error = Error::Handle(isolate, Compiler::Compile(lib, script)); | 4791 const Error& error = Error::Handle(isolate, Compiler::Compile(lib, script)); |
4792 if (error.IsNull()) { | 4792 if (error.IsNull()) { |
4793 *result = Api::NewHandle(isolate, lib.raw()); | 4793 *result = Api::NewHandle(isolate, lib.raw()); |
4794 } else { | 4794 } else { |
4795 *result = Api::NewHandle(isolate, error.raw()); | 4795 *result = Api::NewHandle(isolate, error.raw()); |
4796 lib.SetLoadError(); | 4796 lib.SetLoadError(error); |
4797 } | 4797 } |
4798 } | 4798 } |
4799 | 4799 |
4800 | 4800 |
4801 DART_EXPORT Dart_Handle Dart_LoadScript(Dart_Handle url, | 4801 DART_EXPORT Dart_Handle Dart_LoadScript(Dart_Handle url, |
4802 Dart_Handle source, | 4802 Dart_Handle source, |
4803 intptr_t line_offset, | 4803 intptr_t line_offset, |
4804 intptr_t col_offset) { | 4804 intptr_t col_offset) { |
4805 Isolate* isolate = Isolate::Current(); | 4805 Isolate* isolate = Isolate::Current(); |
4806 DARTSCOPE(isolate); | 4806 DARTSCOPE(isolate); |
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5021 Library::Handle(isolate, Library::LookupLibrary(url_str)); | 5021 Library::Handle(isolate, Library::LookupLibrary(url_str)); |
5022 if (library.IsNull()) { | 5022 if (library.IsNull()) { |
5023 return Api::NewError("%s: library '%s' not found.", | 5023 return Api::NewError("%s: library '%s' not found.", |
5024 CURRENT_FUNC, url_str.ToCString()); | 5024 CURRENT_FUNC, url_str.ToCString()); |
5025 } else { | 5025 } else { |
5026 return Api::NewHandle(isolate, library.raw()); | 5026 return Api::NewHandle(isolate, library.raw()); |
5027 } | 5027 } |
5028 } | 5028 } |
5029 | 5029 |
5030 | 5030 |
| 5031 DART_EXPORT Dart_Handle Dart_LibraryHandleError(Dart_Handle library_in, |
| 5032 Dart_Handle error_in) { |
| 5033 Isolate* isolate = Isolate::Current(); |
| 5034 DARTSCOPE(isolate); |
| 5035 |
| 5036 const Library& lib = Api::UnwrapLibraryHandle(isolate, library_in); |
| 5037 if (lib.IsNull()) { |
| 5038 RETURN_TYPE_ERROR(isolate, library_in, Library); |
| 5039 } |
| 5040 const Object& err = Api::UnwrapInstanceHandle(isolate, error_in); |
| 5041 if (err.IsNull()) { |
| 5042 RETURN_TYPE_ERROR(isolate, error_in, Object); |
| 5043 } |
| 5044 CHECK_CALLBACK_STATE(isolate); |
| 5045 |
| 5046 const GrowableObjectArray& pending_deferred_loads = |
| 5047 GrowableObjectArray::Handle( |
| 5048 isolate->object_store()->pending_deferred_loads()); |
| 5049 for (intptr_t i = 0; i < pending_deferred_loads.Length(); i++) { |
| 5050 if (pending_deferred_loads.At(i) == lib.raw()) { |
| 5051 lib.SetLoadError(err); |
| 5052 return Api::Null(); |
| 5053 } |
| 5054 } |
| 5055 return error_in; |
| 5056 } |
| 5057 |
| 5058 |
5031 DART_EXPORT Dart_Handle Dart_LoadLibrary(Dart_Handle url, | 5059 DART_EXPORT Dart_Handle Dart_LoadLibrary(Dart_Handle url, |
5032 Dart_Handle source) { | 5060 Dart_Handle source) { |
5033 Isolate* isolate = Isolate::Current(); | 5061 Isolate* isolate = Isolate::Current(); |
5034 DARTSCOPE(isolate); | 5062 DARTSCOPE(isolate); |
5035 TIMERSCOPE(isolate, time_script_loading); | 5063 TIMERSCOPE(isolate, time_script_loading); |
5036 const String& url_str = Api::UnwrapStringHandle(isolate, url); | 5064 const String& url_str = Api::UnwrapStringHandle(isolate, url); |
5037 if (url_str.IsNull()) { | 5065 if (url_str.IsNull()) { |
5038 RETURN_TYPE_ERROR(isolate, url, String); | 5066 RETURN_TYPE_ERROR(isolate, url, String); |
5039 } | 5067 } |
5040 const String& source_str = Api::UnwrapStringHandle(isolate, source); | 5068 const String& source_str = Api::UnwrapStringHandle(isolate, source); |
5041 if (source_str.IsNull()) { | 5069 if (source_str.IsNull()) { |
5042 RETURN_TYPE_ERROR(isolate, source, String); | 5070 RETURN_TYPE_ERROR(isolate, source, String); |
5043 } | 5071 } |
5044 CHECK_CALLBACK_STATE(isolate); | 5072 CHECK_CALLBACK_STATE(isolate); |
5045 | 5073 |
5046 NoHeapGrowthControlScope no_growth_control; | 5074 NoHeapGrowthControlScope no_growth_control; |
5047 | 5075 |
5048 Library& library = Library::Handle(isolate, Library::LookupLibrary(url_str)); | 5076 Library& library = Library::Handle(isolate, Library::LookupLibrary(url_str)); |
5049 if (library.IsNull()) { | 5077 if (library.IsNull()) { |
5050 library = Library::New(url_str); | 5078 library = Library::New(url_str); |
5051 library.Register(); | 5079 library.Register(); |
5052 } else if (library.LoadInProgress() || | 5080 } else if (library.LoadInProgress() || |
5053 library.Loaded() || | 5081 library.Loaded() || |
5054 library.LoadError()) { | 5082 library.LoadFailed()) { |
5055 // The source for this library has either been loaded or is in the | 5083 // The source for this library has either been loaded or is in the |
5056 // process of loading. Return an error. | 5084 // process of loading. Return an error. |
5057 return Api::NewError("%s: library '%s' has already been loaded.", | 5085 return Api::NewError("%s: library '%s' has already been loaded.", |
5058 CURRENT_FUNC, url_str.ToCString()); | 5086 CURRENT_FUNC, url_str.ToCString()); |
5059 } | 5087 } |
5060 const Script& script = Script::Handle( | 5088 const Script& script = Script::Handle( |
5061 isolate, Script::New(url_str, source_str, RawScript::kLibraryTag)); | 5089 isolate, Script::New(url_str, source_str, RawScript::kLibraryTag)); |
5062 Dart_Handle result; | 5090 Dart_Handle result; |
5063 CompileSource(isolate, library, script, &result); | 5091 CompileSource(isolate, library, script, &result); |
5064 // Propagate the error out right now. | 5092 // Propagate the error out right now. |
(...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5302 | 5330 |
5303 | 5331 |
5304 DART_EXPORT void Dart_RegisterRootServiceRequestCallback( | 5332 DART_EXPORT void Dart_RegisterRootServiceRequestCallback( |
5305 const char* name, | 5333 const char* name, |
5306 Dart_ServiceRequestCallback callback, | 5334 Dart_ServiceRequestCallback callback, |
5307 void* user_data) { | 5335 void* user_data) { |
5308 Service::RegisterRootEmbedderCallback(name, callback, user_data); | 5336 Service::RegisterRootEmbedderCallback(name, callback, user_data); |
5309 } | 5337 } |
5310 | 5338 |
5311 } // namespace dart | 5339 } // namespace dart |
OLD | NEW |