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

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

Issue 419103003: Handle load errors in deferred code (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 6 years, 4 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/debugger.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) 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
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 // Compilation errors are not Dart instances, so just mark the library
4797 // as having failed to load without providing an error instance.
4798 lib.SetLoadError(Instance::Handle());
4797 } 4799 }
4798 } 4800 }
4799 4801
4800 4802
4801 DART_EXPORT Dart_Handle Dart_LoadScript(Dart_Handle url, 4803 DART_EXPORT Dart_Handle Dart_LoadScript(Dart_Handle url,
4802 Dart_Handle source, 4804 Dart_Handle source,
4803 intptr_t line_offset, 4805 intptr_t line_offset,
4804 intptr_t col_offset) { 4806 intptr_t col_offset) {
4805 Isolate* isolate = Isolate::Current(); 4807 Isolate* isolate = Isolate::Current();
4806 DARTSCOPE(isolate); 4808 DARTSCOPE(isolate);
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after
5021 Library::Handle(isolate, Library::LookupLibrary(url_str)); 5023 Library::Handle(isolate, Library::LookupLibrary(url_str));
5022 if (library.IsNull()) { 5024 if (library.IsNull()) {
5023 return Api::NewError("%s: library '%s' not found.", 5025 return Api::NewError("%s: library '%s' not found.",
5024 CURRENT_FUNC, url_str.ToCString()); 5026 CURRENT_FUNC, url_str.ToCString());
5025 } else { 5027 } else {
5026 return Api::NewHandle(isolate, library.raw()); 5028 return Api::NewHandle(isolate, library.raw());
5027 } 5029 }
5028 } 5030 }
5029 5031
5030 5032
5033 DART_EXPORT Dart_Handle Dart_LibraryHandleError(Dart_Handle library_in,
5034 Dart_Handle error_in) {
5035 Isolate* isolate = Isolate::Current();
5036 DARTSCOPE(isolate);
5037
5038 const Library& lib = Api::UnwrapLibraryHandle(isolate, library_in);
5039 if (lib.IsNull()) {
5040 RETURN_TYPE_ERROR(isolate, library_in, Library);
5041 }
5042 const Instance& err = Api::UnwrapInstanceHandle(isolate, error_in);
5043 if (err.IsNull()) {
5044 RETURN_TYPE_ERROR(isolate, error_in, Instance);
5045 }
5046 CHECK_CALLBACK_STATE(isolate);
5047
5048 const GrowableObjectArray& pending_deferred_loads =
5049 GrowableObjectArray::Handle(
5050 isolate->object_store()->pending_deferred_loads());
5051 for (intptr_t i = 0; i < pending_deferred_loads.Length(); i++) {
5052 if (pending_deferred_loads.At(i) == lib.raw()) {
5053 lib.SetLoadError(err);
5054 return Api::Null();
5055 }
5056 }
5057 return error_in;
5058 }
5059
5060
5031 DART_EXPORT Dart_Handle Dart_LoadLibrary(Dart_Handle url, 5061 DART_EXPORT Dart_Handle Dart_LoadLibrary(Dart_Handle url,
5032 Dart_Handle source) { 5062 Dart_Handle source) {
5033 Isolate* isolate = Isolate::Current(); 5063 Isolate* isolate = Isolate::Current();
5034 DARTSCOPE(isolate); 5064 DARTSCOPE(isolate);
5035 TIMERSCOPE(isolate, time_script_loading); 5065 TIMERSCOPE(isolate, time_script_loading);
5036 const String& url_str = Api::UnwrapStringHandle(isolate, url); 5066 const String& url_str = Api::UnwrapStringHandle(isolate, url);
5037 if (url_str.IsNull()) { 5067 if (url_str.IsNull()) {
5038 RETURN_TYPE_ERROR(isolate, url, String); 5068 RETURN_TYPE_ERROR(isolate, url, String);
5039 } 5069 }
5040 const String& source_str = Api::UnwrapStringHandle(isolate, source); 5070 const String& source_str = Api::UnwrapStringHandle(isolate, source);
5041 if (source_str.IsNull()) { 5071 if (source_str.IsNull()) {
5042 RETURN_TYPE_ERROR(isolate, source, String); 5072 RETURN_TYPE_ERROR(isolate, source, String);
5043 } 5073 }
5044 CHECK_CALLBACK_STATE(isolate); 5074 CHECK_CALLBACK_STATE(isolate);
5045 5075
5046 NoHeapGrowthControlScope no_growth_control; 5076 NoHeapGrowthControlScope no_growth_control;
5047 5077
5048 Library& library = Library::Handle(isolate, Library::LookupLibrary(url_str)); 5078 Library& library = Library::Handle(isolate, Library::LookupLibrary(url_str));
5049 if (library.IsNull()) { 5079 if (library.IsNull()) {
5050 library = Library::New(url_str); 5080 library = Library::New(url_str);
5051 library.Register(); 5081 library.Register();
5052 } else if (library.LoadInProgress() || 5082 } else if (library.LoadInProgress() ||
5053 library.Loaded() || 5083 library.Loaded() ||
5054 library.LoadError()) { 5084 library.LoadFailed()) {
5055 // The source for this library has either been loaded or is in the 5085 // The source for this library has either been loaded or is in the
5056 // process of loading. Return an error. 5086 // process of loading. Return an error.
5057 return Api::NewError("%s: library '%s' has already been loaded.", 5087 return Api::NewError("%s: library '%s' has already been loaded.",
5058 CURRENT_FUNC, url_str.ToCString()); 5088 CURRENT_FUNC, url_str.ToCString());
5059 } 5089 }
5060 const Script& script = Script::Handle( 5090 const Script& script = Script::Handle(
5061 isolate, Script::New(url_str, source_str, RawScript::kLibraryTag)); 5091 isolate, Script::New(url_str, source_str, RawScript::kLibraryTag));
5062 Dart_Handle result; 5092 Dart_Handle result;
5063 CompileSource(isolate, library, script, &result); 5093 CompileSource(isolate, library, script, &result);
5064 // Propagate the error out right now. 5094 // Propagate the error out right now.
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
5205 const String& function_name = 5235 const String& function_name =
5206 String::Handle(isolate, String::New("_completeDeferredLoads")); 5236 String::Handle(isolate, String::New("_completeDeferredLoads"));
5207 const Function& function = 5237 const Function& function =
5208 Function::Handle(isolate, 5238 Function::Handle(isolate,
5209 corelib.LookupFunctionAllowPrivate(function_name)); 5239 corelib.LookupFunctionAllowPrivate(function_name));
5210 ASSERT(!function.IsNull()); 5240 ASSERT(!function.IsNull());
5211 const Array& args = Array::empty_array(); 5241 const Array& args = Array::empty_array();
5212 5242
5213 const Object& res = 5243 const Object& res =
5214 Object::Handle(isolate, DartEntry::InvokeFunction(function, args)); 5244 Object::Handle(isolate, DartEntry::InvokeFunction(function, args));
5245 isolate->object_store()->clear_pending_deferred_loads();
5215 if (res.IsError() || res.IsUnhandledException()) { 5246 if (res.IsError() || res.IsUnhandledException()) {
5216 return Api::NewHandle(isolate, res.raw()); 5247 return Api::NewHandle(isolate, res.raw());
5217 } 5248 }
5218 } 5249 }
5219 return Api::Success(); 5250 return Api::Success();
5220 } 5251 }
5221 5252
5222 5253
5223 DART_EXPORT Dart_Handle Dart_SetNativeResolver( 5254 DART_EXPORT Dart_Handle Dart_SetNativeResolver(
5224 Dart_Handle library, 5255 Dart_Handle library,
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
5302 5333
5303 5334
5304 DART_EXPORT void Dart_RegisterRootServiceRequestCallback( 5335 DART_EXPORT void Dart_RegisterRootServiceRequestCallback(
5305 const char* name, 5336 const char* name,
5306 Dart_ServiceRequestCallback callback, 5337 Dart_ServiceRequestCallback callback,
5307 void* user_data) { 5338 void* user_data) {
5308 Service::RegisterRootEmbedderCallback(name, callback, user_data); 5339 Service::RegisterRootEmbedderCallback(name, callback, user_data);
5309 } 5340 }
5310 5341
5311 } // namespace dart 5342 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/bootstrap_natives.h ('k') | runtime/vm/debugger.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698