| Index: runtime/vm/dart_api_impl.cc
|
| ===================================================================
|
| --- runtime/vm/dart_api_impl.cc (revision 18014)
|
| +++ runtime/vm/dart_api_impl.cc (working copy)
|
| @@ -79,6 +79,29 @@
|
| } while (0)
|
|
|
|
|
| +// Return error if isolate is in an inconsistent state.
|
| +// Return NULL when no error condition exists.
|
| +//
|
| +// TODO(turnidge): Make this function return an error handle directly
|
| +// rather than returning an error string. The current behavior can
|
| +// cause compilation errors to appear to be api errors.
|
| +const char* CheckIsolateState(Isolate* isolate) {
|
| + if (ClassFinalizer::FinalizePendingClasses() &&
|
| + isolate->object_store()->PreallocateObjects()) {
|
| + // Success.
|
| + return NULL;
|
| + }
|
| + // Make a copy of the error message as the original message string
|
| + // may get deallocated when we return back from the Dart API call.
|
| + const Error& err = Error::Handle(isolate->object_store()->sticky_error());
|
| + const char* errmsg = err.ToErrorCString();
|
| + intptr_t errlen = strlen(errmsg) + 1;
|
| + char* msg = Api::TopScope(isolate)->zone()->Alloc<char>(errlen);
|
| + OS::SNPrint(msg, errlen, "%s", errmsg);
|
| + return msg;
|
| +}
|
| +
|
| +
|
| void SetupErrorResult(Isolate* isolate, Dart_Handle* handle) {
|
| *handle = Api::NewHandle(
|
| isolate, Isolate::Current()->object_store()->sticky_error());
|
| @@ -153,17 +176,6 @@
|
| }
|
|
|
|
|
| -Dart_Handle Api::CheckIsolateState(Isolate* isolate) {
|
| - if (ClassFinalizer::FinalizePendingClasses() &&
|
| - isolate->object_store()->PreallocateObjects()) {
|
| - return Api::Success(isolate);
|
| - }
|
| - const Object& obj = Object::Handle(isolate->object_store()->sticky_error());
|
| - ASSERT(obj.IsError());
|
| - return Api::NewHandle(isolate, obj.raw());
|
| -}
|
| -
|
| -
|
| Dart_Isolate Api::CastIsolate(Isolate* isolate) {
|
| return reinterpret_cast<Dart_Isolate>(isolate);
|
| }
|
| @@ -893,9 +905,9 @@
|
| if (size == NULL) {
|
| RETURN_NULL_ERROR(size);
|
| }
|
| - Dart_Handle state = Api::CheckIsolateState(isolate);
|
| - if (Dart_IsError(state)) {
|
| - return state;
|
| + const char* msg = CheckIsolateState(isolate);
|
| + if (msg != NULL) {
|
| + return Api::NewError("%s", msg);
|
| }
|
| // Since this is only a snapshot the root library should not be set.
|
| isolate->object_store()->set_root_library(Library::Handle(isolate));
|
| @@ -917,9 +929,9 @@
|
| if (size == NULL) {
|
| RETURN_NULL_ERROR(size);
|
| }
|
| - Dart_Handle state = Api::CheckIsolateState(isolate);
|
| - if (Dart_IsError(state)) {
|
| - return state;
|
| + const char* msg = CheckIsolateState(isolate);
|
| + if (msg != NULL) {
|
| + return Api::NewError("%s", msg);
|
| }
|
| Library& library =
|
| Library::Handle(isolate, isolate->object_store()->root_library());
|
| @@ -1243,9 +1255,9 @@
|
| CURRENT_FUNC);
|
| }
|
| // Finalize all classes.
|
| - Dart_Handle state = Api::CheckIsolateState(isolate);
|
| - if (Dart_IsError(state)) {
|
| - return state;
|
| + const char* msg = CheckIsolateState(isolate);
|
| + if (msg != NULL) {
|
| + return Api::NewError("%s", msg);
|
| }
|
| if (obj.IsInstance()) {
|
| CHECK_CALLBACK_STATE(isolate);
|
| @@ -2518,9 +2530,9 @@
|
| }
|
|
|
| // Finalize all classes.
|
| - Dart_Handle state = Api::CheckIsolateState(isolate);
|
| - if (Dart_IsError(state)) {
|
| - return state;
|
| + const char* msg = CheckIsolateState(isolate);
|
| + if (msg != NULL) {
|
| + return Api::NewError("%s", msg);
|
| }
|
|
|
| const Array& interface_types = Array::Handle(isolate, cls.interfaces());
|
| @@ -3284,9 +3296,9 @@
|
| } else {
|
| RETURN_TYPE_ERROR(isolate, constructor_name, String);
|
| }
|
| - Dart_Handle state = Api::CheckIsolateState(isolate);
|
| - if (Dart_IsError(state)) {
|
| - return state;
|
| + const char* msg = CheckIsolateState(isolate);
|
| + if (msg != NULL) {
|
| + return Api::NewError("%s", msg);
|
| }
|
|
|
| // Resolve the constructor.
|
| @@ -3414,9 +3426,9 @@
|
|
|
| } else if (obj.IsClass()) {
|
| // Finalize all classes.
|
| - Dart_Handle state = Api::CheckIsolateState(isolate);
|
| - if (Dart_IsError(state)) {
|
| - return state;
|
| + const char* msg = CheckIsolateState(isolate);
|
| + if (msg != NULL) {
|
| + return Api::NewError("%s", msg);
|
| }
|
|
|
| const Class& cls = Class::Cast(obj);
|
| @@ -3451,9 +3463,9 @@
|
|
|
| // Finalize all classes if needed.
|
| if (finalize_classes) {
|
| - Dart_Handle state = Api::CheckIsolateState(isolate);
|
| - if (Dart_IsError(state)) {
|
| - return state;
|
| + const char* msg = CheckIsolateState(isolate);
|
| + if (msg != NULL) {
|
| + return Api::NewError("%s", msg);
|
| }
|
| }
|
|
|
| @@ -3543,9 +3555,9 @@
|
|
|
| } else if (obj.IsClass()) {
|
| // Finalize all classes.
|
| - Dart_Handle state = Api::CheckIsolateState(isolate);
|
| - if (Dart_IsError(state)) {
|
| - return state;
|
| + const char* msg = CheckIsolateState(isolate);
|
| + if (msg != NULL) {
|
| + return Api::NewError("%s", msg);
|
| }
|
| // To access a static field we may need to use the Field or the
|
| // getter Function.
|
| @@ -4128,9 +4140,10 @@
|
| DART_EXPORT Dart_Handle Dart_CompileAll() {
|
| Isolate* isolate = Isolate::Current();
|
| DARTSCOPE(isolate);
|
| - Dart_Handle result = Api::CheckIsolateState(isolate);
|
| - if (Dart_IsError(result)) {
|
| - return result;
|
| + Dart_Handle result;
|
| + const char* msg = CheckIsolateState(isolate);
|
| + if (msg != NULL) {
|
| + return Api::NewError("%s", msg);
|
| }
|
| CHECK_CALLBACK_STATE(isolate);
|
| CompileAll(isolate, &result);
|
| @@ -4280,9 +4293,9 @@
|
| // If this is the dart:builtin library, register it with the VM.
|
| if (url_str.Equals("dart:builtin")) {
|
| isolate->object_store()->set_builtin_library(library);
|
| - Dart_Handle state = Api::CheckIsolateState(isolate);
|
| - if (Dart_IsError(state)) {
|
| - return state;
|
| + const char* msg = CheckIsolateState(isolate);
|
| + if (msg != NULL) {
|
| + return Api::NewError("%s", msg);
|
| }
|
| }
|
| return result;
|
|
|