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

Unified Diff: runtime/vm/dart_api_impl.cc

Issue 9166016: Introduce the Error object class in the vm. It represents all of the (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 11 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « runtime/vm/dart_api_impl.h ('k') | runtime/vm/dart_api_impl_test.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/vm/dart_api_impl.cc
===================================================================
--- runtime/vm/dart_api_impl.cc (revision 3167)
+++ runtime/vm/dart_api_impl.cc (working copy)
@@ -39,13 +39,13 @@
do { \
const Object& tmp = Object::Handle(Api::UnwrapHandle((dart_handle))); \
if (tmp.IsNull()) { \
- return Api::Error("%s expects argument '%s' to be non-null.", \
- CURRENT_FUNC, #dart_handle); \
- } else if (tmp.IsApiError()) { \
+ return Api::NewError("%s expects argument '%s' to be non-null.", \
+ CURRENT_FUNC, #dart_handle); \
+ } else if (tmp.IsError()) { \
return dart_handle; \
} else { \
- return Api::Error("%s expects argument '%s' to be of type %s.", \
- CURRENT_FUNC, #dart_handle, #Type); \
+ return Api::NewError("%s expects argument '%s' to be of type %s.", \
+ CURRENT_FUNC, #dart_handle, #Type); \
} \
} while (0)
@@ -83,7 +83,7 @@
// may get deallocated when we return back from the Dart API call.
const String& error = String::Handle(
Isolate::Current()->object_store()->sticky_error());
- const Object& obj = Object::Handle(ApiError::New(error));
+ const Object& obj = Object::Handle(LanguageError::New(error));
*handle = Api::NewLocalHandle(obj);
}
@@ -103,11 +103,7 @@
const Array& kNoArgumentNames = Array::Handle();
const Instance& retval = Instance::Handle(
DartEntry::InvokeStatic(function, args, kNoArgumentNames));
- if (retval.IsUnhandledException()) {
- *result = Api::ErrorFromException(retval);
- } else {
- *result = Api::NewLocalHandle(retval);
- }
+ *result = Api::NewLocalHandle(retval);
} else {
SetupErrorResult(result);
}
@@ -131,11 +127,7 @@
const Array& kNoArgumentNames = Array::Handle();
const Instance& retval = Instance::Handle(
DartEntry::InvokeDynamic(receiver, function, args, kNoArgumentNames));
- if (retval.IsUnhandledException()) {
- *result = Api::ErrorFromException(retval);
- } else {
- *result = Api::NewLocalHandle(retval);
- }
+ *result = Api::NewLocalHandle(retval);
} else {
SetupErrorResult(result);
}
@@ -218,7 +210,7 @@
}
-Dart_Handle Api::Error(const char* format, ...) {
+Dart_Handle Api::NewError(const char* format, ...) {
DARTSCOPE_NOCHECKS(Isolate::Current());
va_list args;
@@ -238,21 +230,6 @@
}
-Dart_Handle Api::ErrorFromException(const Object& obj) {
- DARTSCOPE_NOCHECKS(Isolate::Current());
-
- ASSERT(obj.IsUnhandledException());
- if (obj.IsUnhandledException()) {
- UnhandledException& uhe = UnhandledException::Handle();
- uhe ^= obj.raw();
- const Object& error = Object::Handle(ApiError::New(uhe));
- return Api::NewLocalHandle(error);
- } else {
- return Api::Error("Internal error: expected obj.IsUnhandledException().");
- }
-}
-
-
Dart_Handle Api::Null() {
Isolate* isolate = Isolate::Current();
ASSERT(isolate != NULL);
@@ -311,7 +288,7 @@
DART_EXPORT bool Dart_IsError(Dart_Handle handle) {
DARTSCOPE(Isolate::Current());
const Object& obj = Object::Handle(Api::UnwrapHandle(handle));
- return obj.IsApiError();
+ return obj.IsError();
}
@@ -320,16 +297,16 @@
const Instance& exception = Instance::Handle(uhe.exception());
Object& strtmp = Object::Handle(DartLibraryCalls::ToString(exception));
const char* exc_str =
- "<Received exception while converting exception to string>";
- if (!strtmp.IsUnhandledException()) {
+ "<Received error while converting exception to string>";
+ if (!strtmp.IsError()) {
exc_str = strtmp.ToCString();
}
const Instance& stack = Instance::Handle(uhe.stacktrace());
strtmp = DartLibraryCalls::ToString(stack);
const char* stack_str =
- "<Received exception while converting stack trace to string>";
- if (!strtmp.IsUnhandledException()) {
+ "<Received error while converting stack trace to string>";
+ if (!strtmp.IsError()) {
stack_str = strtmp.ToCString();
}
@@ -347,29 +324,36 @@
DARTSCOPE(Isolate::Current());
const Object& obj = Object::Handle(Api::UnwrapHandle(handle));
- if (!obj.IsApiError()) {
+ if (!obj.IsError()) {
return "";
}
- ApiError& failure = ApiError::Handle();
- failure ^= obj.raw();
- const Object& data = Object::Handle(failure.data());
- if (data.IsString()) {
- // Simple error message.
- String& message = String::Handle();
- message ^= failure.data();
+ if (obj.IsApiError()) {
+ ApiError& error = ApiError::Handle();
+ error ^= obj.raw();
+ const String& message = String::Handle(error.message());
const char* msg = message.ToCString();
intptr_t len = strlen(msg) + 1;
char* msg_copy = reinterpret_cast<char*>(Api::Allocate(len));
strncpy(msg_copy, msg, len);
return msg_copy;
-
- } else if (data.IsUnhandledException()) {
- UnhandledException& uhe = UnhandledException::Handle();
- uhe ^= data.raw();
- return MakeUnhandledExceptionCString(uhe);
-
+ } else if (obj.IsLanguageError()) {
+ LanguageError& error = LanguageError::Handle();
+ error ^= obj.raw();
+ const String& message = String::Handle(error.message());
+ const char* msg = message.ToCString();
+ intptr_t len = strlen(msg) + 1;
+ char* msg_copy = reinterpret_cast<char*>(Api::Allocate(len));
+ strncpy(msg_copy, msg, len);
+ return msg_copy;
+ } else if (obj.IsUnhandledException()) {
+ UnhandledException& error = UnhandledException::Handle();
+ error ^= obj.raw();
+ return MakeUnhandledExceptionCString(error);
+ } else if (obj.IsUnwindError()) {
+ UNIMPLEMENTED();
+ return "<unimplemented>;";
} else {
- return "<Internal error in Dart_GetError: malformed error handle>";
+ return "<Internal error in Dart_GetError: unexpected error type>";
}
}
@@ -377,31 +361,22 @@
DART_EXPORT bool Dart_ErrorHasException(Dart_Handle handle) {
DARTSCOPE(Isolate::Current());
const Object& obj = Object::Handle(Api::UnwrapHandle(handle));
- if (obj.IsApiError()) {
- const ApiError& error = ApiError::CheckedHandle(obj.raw());
- const Object& data = Object::Handle(error.data());
- return data.IsUnhandledException();
- }
- return false;
+ return obj.IsUnhandledException();
}
DART_EXPORT Dart_Handle Dart_ErrorGetException(Dart_Handle handle) {
DARTSCOPE(Isolate::Current());
const Object& obj = Object::Handle(Api::UnwrapHandle(handle));
- if (obj.IsApiError()) {
- const ApiError& error = ApiError::CheckedHandle(obj.raw());
- const Object& data = Object::Handle(error.data());
- if (data.IsUnhandledException()) {
- const UnhandledException& unhandled = UnhandledException::Handle(
- reinterpret_cast<RawUnhandledException*>(data.raw()));
- const Object& exception = Object::Handle(unhandled.exception());
- return Api::NewLocalHandle(exception);
- } else {
- return Api::Error("This error is not an unhandled exception error.");
- }
+ if (obj.IsUnhandledException()) {
+ UnhandledException& error = UnhandledException::Handle();
+ error ^= obj.raw();
+ const Object& exception = Object::Handle(error.exception());
+ return Api::NewLocalHandle(exception);
+ } else if (obj.IsError()) {
+ return Api::NewError("This error is not an unhandled exception error.");
} else {
- return Api::Error("Can only get exceptions from error handles.");
+ return Api::NewError("Can only get exceptions from error handles.");
}
}
@@ -409,25 +384,20 @@
DART_EXPORT Dart_Handle Dart_ErrorGetStacktrace(Dart_Handle handle) {
DARTSCOPE(Isolate::Current());
const Object& obj = Object::Handle(Api::UnwrapHandle(handle));
- if (obj.IsApiError()) {
- ApiError& failure = ApiError::Handle();
- failure ^= obj.raw();
- const Object& data = Object::Handle(failure.data());
- if (data.IsUnhandledException()) {
- const UnhandledException& unhandled = UnhandledException::Handle(
- reinterpret_cast<RawUnhandledException*>(data.raw()));
- const Object& stacktrace = Object::Handle(unhandled.stacktrace());
- return Api::NewLocalHandle(stacktrace);
- } else {
- return Api::Error("This error is not an unhandled exception error.");
- }
+ if (obj.IsUnhandledException()) {
+ UnhandledException& error = UnhandledException::Handle();
+ error ^= obj.raw();
+ const Object& stacktrace = Object::Handle(error.stacktrace());
+ return Api::NewLocalHandle(stacktrace);
+ } else if (obj.IsError()) {
+ return Api::NewError("This error is not an unhandled exception error.");
} else {
- return Api::Error("Can only get stacktraces from error handles.");
+ return Api::NewError("Can only get stacktraces from error handles.");
}
}
-// TODO(turnidge): This clones Api::Error. I need to use va_copy to
+// TODO(turnidge): This clones Api::NewError. I need to use va_copy to
// fix this but not sure if it available on all of our builds.
DART_EXPORT Dart_Handle Dart_Error(const char* format, ...) {
DARTSCOPE(Isolate::Current());
@@ -469,9 +439,6 @@
Instance& receiver = Instance::Handle();
receiver ^= obj.raw();
result = DartLibraryCalls::ToString(receiver);
- if (result.IsUnhandledException()) {
- return Api::ErrorFromException(result);
- }
} else {
// This is a VM internal object. Call the C++ method of printing.
result = String::New(obj.ToCString());
@@ -637,17 +604,17 @@
DARTSCOPE(isolate);
TIMERSCOPE(time_creating_snapshot);
if (buffer == NULL) {
- return Api::Error("%s expects argument 'buffer' to be non-null.",
- CURRENT_FUNC);
+ return Api::NewError("%s expects argument 'buffer' to be non-null.",
+ CURRENT_FUNC);
}
if (size == NULL) {
- return Api::Error("%s expects argument 'size' to be non-null.",
- CURRENT_FUNC);
+ return Api::NewError("%s expects argument 'size' to be non-null.",
+ CURRENT_FUNC);
}
const char* msg = CheckIsolateState(isolate,
ClassFinalizer::kGeneratingSnapshot);
if (msg != NULL) {
- return Api::Error(msg);
+ return Api::NewError(msg);
}
// Since this is only a snapshot the root library should not be set.
isolate->object_store()->set_root_library(Library::Handle());
@@ -664,20 +631,21 @@
DARTSCOPE(isolate);
TIMERSCOPE(time_creating_snapshot);
if (buffer == NULL) {
- return Api::Error("%s expects argument 'buffer' to be non-null.",
- CURRENT_FUNC);
+ return Api::NewError("%s expects argument 'buffer' to be non-null.",
+ CURRENT_FUNC);
}
if (size == NULL) {
- return Api::Error("%s expects argument 'size' to be non-null.",
- CURRENT_FUNC);
+ return Api::NewError("%s expects argument 'size' to be non-null.",
+ CURRENT_FUNC);
}
const char* msg = CheckIsolateState(isolate);
if (msg != NULL) {
- return Api::Error(msg);
+ return Api::NewError(msg);
}
Library& library = Library::Handle(isolate->object_store()->root_library());
if (library.IsNull()) {
- return Api::Error("%s expects the isolate to have a script loaded in it.",
+ return
+ Api::NewError("%s expects the isolate to have a script loaded in it.",
CURRENT_FUNC);
}
ScriptSnapshotWriter writer(buffer, ApiAllocator);
@@ -721,8 +689,8 @@
isolate->set_long_jump_base(&jump);
if (setjmp(*jump.Set()) == 0) {
const Object& obj = Object::Handle(isolate->StandardRunLoop());
- if (obj.IsUnhandledException()) {
- result = Api::ErrorFromException(obj);
+ if (obj.IsError()) {
+ result = Api::NewLocalHandle(obj);
} else {
ASSERT(obj.IsNull());
result = Api::Success();
@@ -758,8 +726,8 @@
Object::Handle(DartLibraryCalls::HandleMessage(dest_port_id,
reply_port_id,
msg));
- if (result.IsUnhandledException()) {
- return Api::ErrorFromException(result);
+ if (result.IsError()) {
+ return Api::NewLocalHandle(result);
}
ASSERT(result.IsNull());
return Api::Success();
@@ -913,10 +881,10 @@
b ^= result.raw();
*value = b.value();
return Api::Success();
- } else if (result.IsUnhandledException()) {
- return Api::ErrorFromException(result);
+ } else if (result.IsError()) {
+ return Api::NewLocalHandle(result);
} else {
- return Api::Error("Expected boolean result from ==");
+ return Api::NewError("Expected boolean result from ==");
}
}
@@ -931,7 +899,7 @@
DARTSCOPE(isolate);
const Class& cls = Class::CheckedHandle(Api::UnwrapHandle(clazz));
if (cls.IsNull()) {
- return Api::Error("instanceof check against null class");
+ return Api::NewError("instanceof check against null class");
}
const Object& obj = Object::Handle(Api::UnwrapHandle(object));
Instance& instance = Instance::Handle();
@@ -939,7 +907,7 @@
// Finalize all classes.
const char* msg = CheckIsolateState(isolate);
if (msg != NULL) {
- return Api::Error(msg);
+ return Api::NewError(msg);
}
const Type& type = Type::Handle(Type::NewNonParameterizedType(cls));
*value = instance.IsInstanceOf(type, TypeArguments::Handle());
@@ -1043,8 +1011,8 @@
return Api::Success();
}
}
- return Api::Error("%s: Integer %s cannot be represented as an int64_t.",
- CURRENT_FUNC, int_obj.ToCString());
+ return Api::NewError("%s: Integer %s cannot be represented as an int64_t.",
+ CURRENT_FUNC, int_obj.ToCString());
}
@@ -1069,8 +1037,8 @@
return Api::Success();
}
}
- return Api::Error("%s: Integer %s cannot be represented as a uint64_t.",
- CURRENT_FUNC, int_obj.ToCString());
+ return Api::NewError("%s: Integer %s cannot be represented as a uint64_t.",
+ CURRENT_FUNC, int_obj.ToCString());
}
@@ -1197,7 +1165,7 @@
*len = string_obj.Length();
return Api::Success();
}
- return Api::Error("Object is not a String");
+ return Api::NewError("Object is not a String");
}
@@ -1250,12 +1218,13 @@
RETURN_TYPE_ERROR(object, String);
}
if (!str.IsExternal()) {
- return Api::Error("%s expects argument 'object' to be an external String.",
+ return
+ Api::NewError("%s expects argument 'object' to be an external String.",
CURRENT_FUNC);
}
if (peer == NULL) {
- return Api::Error("%s expects argument 'peer' to be non-null.",
- CURRENT_FUNC);
+ return Api::NewError("%s expects argument 'peer' to be non-null.",
+ CURRENT_FUNC);
}
*peer = str.GetPeer();
return Api::Success();
@@ -1313,9 +1282,9 @@
return Api::Success();
}
}
- return Api::Error(obj.IsString()
- ? "Object is not a String8"
- : "Object is not a String");
+ return Api::NewError(obj.IsString()
+ ? "Object is not a String8"
+ : "Object is not a String");
}
@@ -1337,9 +1306,9 @@
return Api::Success();
}
}
- return Api::Error(obj.IsString()
- ? "Object is not a String16"
- : "Object is not a String");
+ return Api::NewError(obj.IsString()
+ ? "Object is not a String16"
+ : "Object is not a String");
}
@@ -1359,7 +1328,7 @@
*length = copy_len;
return Api::Success();
}
- return Api::Error("Object is not a String");
+ return Api::NewError("Object is not a String");
}
@@ -1372,14 +1341,14 @@
intptr_t string_length = strlen(string_value);
char* res = reinterpret_cast<char*>(Api::Allocate(string_length + 1));
if (res == NULL) {
- return Api::Error("Unable to allocate memory");
+ return Api::NewError("Unable to allocate memory");
}
strncpy(res, string_value, string_length + 1);
ASSERT(res[string_length] == '\0');
*result = res;
return Api::Success();
}
- return Api::Error("Object is not a String");
+ return Api::NewError("Object is not a String");
}
@@ -1458,13 +1427,14 @@
if (BigintOperations::FitsIntoInt64(bigint)) {
*len = BigintOperations::ToInt64(bigint);
} else {
- result = Api::Error("Length of List object is greater than the "
- "maximum value that 'len' parameter can hold");
+ result =
+ Api::NewError("Length of List object is greater than the "
+ "maximum value that 'len' parameter can hold");
}
- } else if (retval.IsUnhandledException()) {
- result = Api::ErrorFromException(retval);
+ } else if (retval.IsError()) {
+ result = Api::NewLocalHandle(retval);
} else {
- result = Api::Error("Length of List object is not an integer");
+ result = Api::NewError("Length of List object is not an integer");
}
} else {
SetupErrorResult(&result);
@@ -1473,7 +1443,7 @@
return result;
}
}
- return Api::Error("Object does not implement the list inteface");
+ return Api::NewError("Object does not implement the list inteface");
}
@@ -1496,8 +1466,8 @@
function,
args,
kNoArgumentNames);
- if (retval.IsUnhandledException()) {
- *result = Api::ErrorFromException(retval);
+ if (retval.IsError()) {
+ *result = Api::NewLocalHandle(retval);
} else {
*result = Api::Success();
}
@@ -1521,7 +1491,7 @@
const Object& element = Object::Handle(array_obj.At(index));
return Api::NewLocalHandle(element);
}
- return Api::Error("Invalid index passed in to access array element");
+ return Api::NewError("Invalid index passed in to access array element");
}
// TODO(5526318): Make access to GrowableObjectArray more efficient.
// Now check and handle a dart object that implements the List interface.
@@ -1542,7 +1512,7 @@
return Api::NewLocalHandle(element);
}
}
- return Api::Error("Object does not implement the 'List' interface");
+ return Api::NewError("Object does not implement the 'List' interface");
}
@@ -1567,8 +1537,8 @@
function,
args,
kNoArgumentNames);
- if (retval.IsUnhandledException()) {
- *result = Api::ErrorFromException(retval);
+ if (retval.IsError()) {
+ *result = Api::NewLocalHandle(retval);
} else {
*result = Api::Success();
}
@@ -1587,7 +1557,7 @@
const Object& obj = Object::Handle(Api::UnwrapHandle(list));
if (obj.IsArray()) {
if (obj.IsImmutableArray()) {
- return Api::Error("Cannot modify immutable array");
+ return Api::NewError("Cannot modify immutable array");
}
Array& array_obj = Array::Handle();
array_obj ^= obj.raw();
@@ -1596,7 +1566,7 @@
array_obj.SetAt(index, value_obj);
return Api::Success();
}
- return Api::Error("Invalid index passed in to set array element");
+ return Api::NewError("Invalid index passed in to set array element");
}
// TODO(5526318): Make access to GrowableObjectArray more efficient.
// Now check and handle a dart object that implements the List interface.
@@ -1613,7 +1583,7 @@
return result;
}
}
- return Api::Error("Object does not implement the 'List' interface");
+ return Api::NewError("Object does not implement the 'List' interface");
}
@@ -1633,7 +1603,7 @@
for (int i = 0; i < length; i++) {
element = array_obj.At(offset + i);
if (!element.IsInteger()) {
- return Api::Error("%s expects the argument 'list' to be "
+ return Api::NewError("%s expects the argument 'list' to be "
"a List of int", CURRENT_FUNC);
}
integer ^= element.raw();
@@ -1644,7 +1614,7 @@
}
return Api::Success();
}
- return Api::Error("Invalid length passed in to access array elements");
+ return Api::NewError("Invalid length passed in to access array elements");
}
// TODO(5526318): Make access to GrowableObjectArray more efficient.
// Now check and handle a dart object that implements the List interface.
@@ -1664,7 +1634,7 @@
return result; // Error condition.
}
if (!element.IsInteger()) {
- return Api::Error("%s expects the argument 'list' to be "
+ return Api::NewError("%s expects the argument 'list' to be "
"a List of int", CURRENT_FUNC);
}
intobj ^= element.raw();
@@ -1676,7 +1646,7 @@
return Api::Success();
}
}
- return Api::Error("Object does not implement the 'List' interface");
+ return Api::NewError("Object does not implement the 'List' interface");
}
@@ -1689,7 +1659,7 @@
const Object& obj = Object::Handle(Api::UnwrapHandle(list));
if (obj.IsArray()) {
if (obj.IsImmutableArray()) {
- return Api::Error("Cannot modify immutable array");
+ return Api::NewError("Cannot modify immutable array");
}
Array& array_obj = Array::Handle();
array_obj ^= obj.raw();
@@ -1701,7 +1671,7 @@
}
return Api::Success();
}
- return Api::Error("Invalid length passed in to set array elements");
+ return Api::NewError("Invalid length passed in to set array elements");
}
// TODO(5526318): Make access to GrowableObjectArray more efficient.
// Now check and handle a dart object that implements the List interface.
@@ -1725,7 +1695,7 @@
return Api::Success();
}
}
- return Api::Error("Object does not implement the 'List' interface");
+ return Api::NewError("Object does not implement the 'List' interface");
}
@@ -1754,11 +1724,7 @@
const Array& kNoArgumentNames = Array::Handle();
const Instance& retval = Instance::Handle(
DartEntry::InvokeClosure(closure, args, kNoArgumentNames));
- if (retval.IsUnhandledException()) {
- *result = Api::ErrorFromException(retval);
- } else {
- *result = Api::NewLocalHandle(retval);
- }
+ *result = Api::NewLocalHandle(retval);
} else {
SetupErrorResult(result);
}
@@ -1773,10 +1739,10 @@
DARTSCOPE(isolate);
const Object& obj = Object::Handle(Api::UnwrapHandle(closure));
if (obj.IsNull()) {
- return Api::Error("Null object passed in to invoke closure");
+ return Api::NewError("Null object passed in to invoke closure");
}
if (!obj.IsClosure()) {
- return Api::Error("Invalid closure passed to invoke closure");
+ return Api::NewError("Invalid closure passed to invoke closure");
}
ASSERT(ClassFinalizer::AllClassesFinalized());
@@ -1823,14 +1789,14 @@
// Finalize all classes.
const char* msg = CheckIsolateState(isolate);
if (msg != NULL) {
- return Api::Error(msg);
+ return Api::NewError(msg);
}
// Now try to resolve and invoke the static function.
const Library& library =
Library::CheckedHandle(Api::UnwrapHandle(library_in));
if (library.IsNull()) {
- return Api::Error("No library specified");
+ return Api::NewError("No library specified");
}
const String& class_name =
String::CheckedHandle(Api::UnwrapHandle(class_name_in));
@@ -1860,7 +1826,7 @@
OS::SNPrint(msg, (length + 1), format,
class_name.ToCString(), function_name.ToCString());
}
- return Api::Error(msg);
+ return Api::NewError(msg);
}
Dart_Handle retval;
GrowableArray<const Object*> dart_arguments(number_of_arguments);
@@ -1883,11 +1849,11 @@
// Let the resolver figure out the correct target for null receiver.
// E.g., (null).toString() should execute correctly.
if (!obj.IsNull() && !obj.IsInstance()) {
- return Api::Error(
+ return Api::NewError(
"Invalid receiver (not instance) passed to invoke dynamic");
}
if (function_name == NULL) {
- return Api::Error("Invalid function name specified");
+ return Api::NewError("Invalid function name specified");
}
ASSERT(ClassFinalizer::AllClassesFinalized());
@@ -1903,7 +1869,7 @@
if (function.IsNull()) {
// TODO(5415268): Invoke noSuchMethod instead of failing.
OS::PrintErr("Unable to find instance function: %s\n", name.ToCString());
- return Api::Error("Unable to find instance function");
+ return Api::NewError("Unable to find instance function");
}
Dart_Handle retval;
GrowableArray<const Object*> dart_arguments(number_of_arguments);
@@ -1940,10 +1906,10 @@
const Object& param1 = Object::Handle(Api::UnwrapHandle(clazz));
const Object& param2 = Object::Handle(Api::UnwrapHandle(field_name));
if (param1.IsNull() || !param1.IsClass()) {
- return Api::Error("Invalid class specified");
+ return Api::NewError("Invalid class specified");
}
if (param2.IsNull() || !param2.IsString()) {
- return Api::Error("Invalid field name specified");
+ return Api::NewError("Invalid field name specified");
}
Class& cls = Class::Handle();
cls ^= param1.raw();
@@ -1957,10 +1923,10 @@
if (!function.IsNull()) {
return Api::NewLocalHandle(function);
}
- return Api::Error("Specified field is not found in the class");
+ return Api::NewError("Specified field is not found in the class");
}
if (fld.IsNull()) {
- return Api::Error("Specified field is not found in the class");
+ return Api::NewError("Specified field is not found in the class");
}
return Api::NewLocalHandle(fld);
}
@@ -1971,7 +1937,7 @@
bool is_getter) {
const Object& param = Object::Handle(Api::UnwrapHandle(name));
if (param.IsNull() || !param.IsString()) {
- return Api::Error("Invalid field name specified");
+ return Api::NewError("Invalid field name specified");
}
String& field_name = String::Handle();
field_name ^= param.raw();
@@ -1982,7 +1948,7 @@
fld = cls.LookupInstanceField(field_name);
if (!fld.IsNull()) {
if (!is_getter && fld.is_final()) {
- return Api::Error("Cannot set value of final fields");
+ return Api::NewError("Cannot set value of final fields");
}
func_name = (is_getter
? Field::GetterName(field_name)
@@ -1990,13 +1956,13 @@
const Function& function = Function::Handle(
cls.LookupDynamicFunction(func_name));
if (function.IsNull()) {
- return Api::Error("Unable to find accessor function in the class");
+ return Api::NewError("Unable to find accessor function in the class");
}
return Api::NewLocalHandle(function);
}
cls = cls.SuperClass();
}
- return Api::Error("Unable to find field in the class");
+ return Api::NewError("Unable to find field in the class");
}
@@ -2038,7 +2004,8 @@
Field& fld = Field::Handle();
fld ^= Api::UnwrapHandle(result);
if (fld.is_final()) {
- return Api::Error("Specified field is a static final field in the class");
+ return Api::NewError(
+ "Specified field is a static final field in the class");
}
const Object& val = Object::Handle(Api::UnwrapHandle(value));
Instance& instance = Instance::Handle();
@@ -2054,7 +2021,7 @@
DARTSCOPE(isolate);
const Object& param = Object::Handle(Api::UnwrapHandle(obj));
if (param.IsNull() || !param.IsInstance()) {
- return Api::Error("Invalid object passed in to access instance field");
+ return Api::NewError("Invalid object passed in to access instance field");
}
Instance& object = Instance::Handle();
object ^= param.raw();
@@ -2077,7 +2044,7 @@
DARTSCOPE(isolate);
const Object& param = Object::Handle(Api::UnwrapHandle(obj));
if (param.IsNull() || !param.IsInstance()) {
- return Api::Error("Invalid object passed in to access instance field");
+ return Api::NewError("Invalid object passed in to access instance field");
}
Instance& object = Instance::Handle();
object ^= param.raw();
@@ -2102,7 +2069,7 @@
DARTSCOPE(isolate);
const Object& param = Object::Handle(Api::UnwrapHandle(name));
if (param.IsNull() || !param.IsString() || field_count <= 0) {
- return Api::Error(
+ return Api::NewError(
"Invalid arguments passed to Dart_CreateNativeWrapperClass");
}
String& cls_name = String::Handle();
@@ -2111,14 +2078,14 @@
Library& lib = Library::Handle();
lib ^= Api::UnwrapHandle(library);
if (lib.IsNull()) {
- return Api::Error(
+ return Api::NewError(
"Invalid arguments passed to Dart_CreateNativeWrapperClass");
}
const Class& cls = Class::Handle(Class::NewNativeWrapper(&lib,
cls_name,
field_count));
if (cls.IsNull()) {
- return Api::Error(
+ return Api::NewError(
"Unable to create native wrapper class : already exists");
}
return Api::NewLocalHandle(cls);
@@ -2131,13 +2098,13 @@
DARTSCOPE(Isolate::Current());
const Object& param = Object::Handle(Api::UnwrapHandle(obj));
if (param.IsNull() || !param.IsInstance()) {
- return Api::Error(
+ return Api::NewError(
"Invalid object passed in to access native instance field");
}
Instance& object = Instance::Handle();
object ^= param.raw();
if (!object.IsValidNativeIndex(index)) {
- return Api::Error(
+ return Api::NewError(
"Invalid index passed in to access native instance field");
}
*value = object.GetNativeField(index);
@@ -2151,12 +2118,14 @@
DARTSCOPE(Isolate::Current());
const Object& param = Object::Handle(Api::UnwrapHandle(obj));
if (param.IsNull() || !param.IsInstance()) {
- return Api::Error("Invalid object passed in to set native instance field");
+ return Api::NewError(
+ "Invalid object passed in to set native instance field");
}
Instance& object = Instance::Handle();
object ^= param.raw();
if (!object.IsValidNativeIndex(index)) {
- return Api::Error("Invalid index passed in to set native instance field");
+ return Api::NewError(
+ "Invalid index passed in to set native instance field");
}
object.SetNativeField(index, value);
return Api::Success();
@@ -2172,7 +2141,7 @@
if (isolate->top_exit_frame_info() == 0) {
// There are no dart frames on the stack so it would be illegal to
// throw an exception here.
- return Api::Error("No Dart frames on stack, cannot throw exception");
+ return Api::NewError("No Dart frames on stack, cannot throw exception");
}
const Instance& excp = Instance::CheckedHandle(Api::UnwrapHandle(exception));
// Unwind all the API scopes till the exit frame before throwing an
@@ -2181,7 +2150,7 @@
ASSERT(state != NULL);
state->UnwindScopes(isolate->top_exit_frame_info());
Exceptions::Throw(excp);
- return Api::Error("Exception was not thrown, internal error");
+ return Api::NewError("Exception was not thrown, internal error");
}
@@ -2192,7 +2161,7 @@
if (isolate->top_exit_frame_info() == 0) {
// There are no dart frames on the stack so it would be illegal to
// throw an exception here.
- return Api::Error("No Dart frames on stack, cannot throw exception");
+ return Api::NewError("No Dart frames on stack, cannot throw exception");
}
DARTSCOPE(isolate);
const Instance& excp = Instance::CheckedHandle(Api::UnwrapHandle(exception));
@@ -2203,7 +2172,7 @@
ASSERT(state != NULL);
state->UnwindScopes(isolate->top_exit_frame_info());
Exceptions::ReThrow(excp, stk);
- return Api::Error("Exception was not re thrown, internal error");
+ return Api::NewError("Exception was not re thrown, internal error");
}
@@ -2289,8 +2258,8 @@
Library& library = Library::Handle(isolate->object_store()->root_library());
if (!library.IsNull()) {
const String& library_url = String::Handle(library.url());
- return Api::Error("%s: A script has already been loaded from '%s'.",
- CURRENT_FUNC, library_url.ToCString());
+ return Api::NewError("%s: A script has already been loaded from '%s'.",
+ CURRENT_FUNC, library_url.ToCString());
}
isolate->set_library_tag_handler(handler);
library = Library::New(url_str);
@@ -2312,25 +2281,25 @@
DARTSCOPE(isolate);
TIMERSCOPE(time_script_loading);
if (buffer == NULL) {
- return Api::Error("%s expects argument 'buffer' to be non-null.",
- CURRENT_FUNC);
+ return Api::NewError("%s expects argument 'buffer' to be non-null.",
+ CURRENT_FUNC);
}
const Snapshot* snapshot = Snapshot::SetupFromBuffer(buffer);
if (!snapshot->IsScriptSnapshot()) {
- return Api::Error("%s expects parameter 'buffer' to be a script type"
- " snapshot", CURRENT_FUNC);
+ return Api::NewError("%s expects parameter 'buffer' to be a script type"
+ " snapshot", CURRENT_FUNC);
}
Library& library = Library::Handle(isolate->object_store()->root_library());
if (!library.IsNull()) {
const String& library_url = String::Handle(library.url());
- return Api::Error("%s: A script has already been loaded from '%s'.",
- CURRENT_FUNC, library_url.ToCString());
+ return Api::NewError("%s: A script has already been loaded from '%s'.",
+ CURRENT_FUNC, library_url.ToCString());
}
SnapshotReader reader(snapshot, isolate);
const Object& tmp = Object::Handle(reader.ReadObject());
if (!tmp.IsLibrary()) {
- return Api::Error("%s: Unable to deserialize snapshot correctly.",
- CURRENT_FUNC);
+ return Api::NewError("%s: Unable to deserialize snapshot correctly.",
+ CURRENT_FUNC);
}
library ^= tmp.raw();
library.Register();
@@ -2360,7 +2329,7 @@
Dart_Handle result;
const char* msg = CheckIsolateState(isolate);
if (msg != NULL) {
- return Api::Error(msg);
+ return Api::NewError(msg);
}
CompileAll(isolate, &result);
return result;
@@ -2378,19 +2347,19 @@
DARTSCOPE(Isolate::Current());
const Object& param = Object::Handle(Api::UnwrapHandle(name));
if (param.IsNull() || !param.IsString()) {
- return Api::Error("Invalid class name specified");
+ return Api::NewError("Invalid class name specified");
}
const Library& lib = Library::CheckedHandle(Api::UnwrapHandle(library));
if (lib.IsNull()) {
- return Api::Error("Invalid parameter, Unknown library specified");
+ return Api::NewError("Invalid parameter, Unknown library specified");
}
String& cls_name = String::Handle();
cls_name ^= param.raw();
const Class& cls = Class::Handle(lib.LookupClass(cls_name));
if (cls.IsNull()) {
const String& lib_name = String::Handle(lib.name());
- return Api::Error("Class '%s' not found in library '%s'.",
- cls_name.ToCString(), lib_name.ToCString());
+ return Api::NewError("Class '%s' not found in library '%s'.",
+ cls_name.ToCString(), lib_name.ToCString());
}
return Api::NewLocalHandle(cls);
}
@@ -2416,8 +2385,8 @@
}
const Library& library = Library::Handle(Library::LookupLibrary(url_str));
if (library.IsNull()) {
- return Api::Error("%s: library '%s' not found.",
- CURRENT_FUNC, url_str.ToCString());
+ return Api::NewError("%s: library '%s' not found.",
+ CURRENT_FUNC, url_str.ToCString());
} else {
return Api::NewLocalHandle(library);
}
@@ -2442,8 +2411,8 @@
} else if (!library.LoadNotStarted()) {
// The source for this library has either been loaded or is in the
// process of loading. Return an error.
- return Api::Error("%s: library '%s' has already been loaded.",
- CURRENT_FUNC, url_str.ToCString());
+ return Api::NewError("%s: library '%s' has already been loaded.",
+ CURRENT_FUNC, url_str.ToCString());
}
Dart_Handle result;
CompileSource(isolate,
« no previous file with comments | « runtime/vm/dart_api_impl.h ('k') | runtime/vm/dart_api_impl_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698