Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, 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" |
| 11 #include "vm/dart_api_impl.h" | 11 #include "vm/dart_api_impl.h" |
| 12 #include "vm/dart_api_state.h" | 12 #include "vm/dart_api_state.h" |
| 13 #include "vm/dart_entry.h" | 13 #include "vm/dart_entry.h" |
| 14 #include "vm/debuginfo.h" | 14 #include "vm/debuginfo.h" |
| 15 #include "vm/exceptions.h" | 15 #include "vm/exceptions.h" |
| 16 #include "vm/growable_array.h" | 16 #include "vm/growable_array.h" |
| 17 #include "vm/longjump.h" | 17 #include "vm/longjump.h" |
| 18 #include "vm/native_entry.h" | 18 #include "vm/native_entry.h" |
| 19 #include "vm/object.h" | 19 #include "vm/object.h" |
| 20 #include "vm/object_store.h" | 20 #include "vm/object_store.h" |
| 21 #include "vm/port.h" | 21 #include "vm/port.h" |
| 22 #include "vm/resolver.h" | 22 #include "vm/resolver.h" |
| 23 #include "vm/snapshot.h" | 23 #include "vm/snapshot.h" |
| 24 #include "vm/stack_frame.h" | 24 #include "vm/stack_frame.h" |
| 25 #include "vm/timer.h" | 25 #include "vm/timer.h" |
| 26 #include "vm/verifier.h" | 26 #include "vm/verifier.h" |
| 27 | 27 |
| 28 namespace dart { | 28 namespace dart { |
| 29 | 29 |
| 30 DART_EXPORT bool Dart_IsValid(const Dart_Handle& handle) { | 30 DART_EXPORT bool Dart_IsError(const Dart_Handle& handle) { |
| 31 ASSERT(Isolate::Current() != NULL); | 31 ASSERT(Isolate::Current() != NULL); |
| 32 Zone zone; // Setup a VM zone as we are creating some handles. | 32 Zone zone; // Setup a VM zone as we are creating some handles. |
| 33 HandleScope scope; // Setup a VM handle scope. | 33 HandleScope scope; // Setup a VM handle scope. |
| 34 | |
| 35 // Make sure that the object isn't an ApiFailure. | |
| 36 const Object& obj = Object::Handle(Api::UnwrapHandle(handle)); | 34 const Object& obj = Object::Handle(Api::UnwrapHandle(handle)); |
| 37 return !obj.IsApiFailure(); | 35 return obj.IsApiError(); |
| 38 } | 36 } |
| 39 | 37 |
| 40 | 38 |
| 41 DART_EXPORT void _Dart_ReportInvalidHandle(const char* file, | 39 DART_EXPORT bool Dart_IsUnhandledException(Dart_Handle handle) { |
| 40 Zone zone; // Setup a VM zone as we are creating some handles. | |
| 41 HandleScope scope; // Setup a VM handle scope. | |
| 42 const Object& obj = Object::Handle(Api::UnwrapHandle(handle)); | |
| 43 if (obj.IsApiError()) { | |
| 44 const ApiError& error = ApiError::CheckedHandle(obj.raw()); | |
| 45 const Object& data = Object::Handle(error.data()); | |
| 46 return data.IsUnhandledException(); | |
| 47 } | |
| 48 return false; | |
| 49 } | |
| 50 | |
| 51 | |
| 52 DART_EXPORT Dart_Handle Dart_GetException(Dart_Handle handle) { | |
| 53 Zone zone; // Setup a VM zone as we are creating some handles. | |
| 54 HandleScope scope; // Setup a VM handle scope. | |
| 55 const Object& obj = Object::Handle(Api::UnwrapHandle(handle)); | |
| 56 if (obj.IsApiError()) { | |
| 57 ApiError& failure = ApiError::Handle(); | |
| 58 failure ^= obj.raw(); | |
| 59 const Object& data = Object::Handle(failure.data()); | |
| 60 if (data.IsUnhandledException()) { | |
| 61 const UnhandledException& unhandled = UnhandledException::Handle( | |
| 62 reinterpret_cast<RawUnhandledException*>(data.raw())); | |
| 63 const Object& exception = Object::Handle(unhandled.exception()); | |
| 64 return Api::NewLocalHandle(exception); | |
| 65 } else { | |
| 66 return Api::Error("This error is not an unhandled exception error."); | |
| 67 } | |
| 68 } else { | |
| 69 return Api::Error("Can only get exceptions from error handles."); | |
| 70 } | |
| 71 } | |
| 72 | |
| 73 | |
| 74 DART_EXPORT Dart_Handle Dart_GetStacktrace(Dart_Handle handle) { | |
| 75 Zone zone; // Setup a VM zone as we are creating some handles. | |
| 76 HandleScope scope; // Setup a VM handle scope. | |
| 77 const Object& obj = Object::Handle(Api::UnwrapHandle(handle)); | |
| 78 if (obj.IsApiError()) { | |
| 79 ApiError& failure = ApiError::Handle(); | |
| 80 failure ^= obj.raw(); | |
| 81 const Object& data = Object::Handle(failure.data()); | |
| 82 if (data.IsUnhandledException()) { | |
| 83 const UnhandledException& unhandled = UnhandledException::Handle( | |
| 84 reinterpret_cast<RawUnhandledException*>(data.raw())); | |
| 85 const Object& stacktrace = Object::Handle(unhandled.stacktrace()); | |
| 86 return Api::NewLocalHandle(stacktrace); | |
| 87 } else { | |
| 88 return Api::Error("This error is not an unhandled exception error."); | |
| 89 } | |
| 90 } else { | |
| 91 return Api::Error("Can only get stacktraces from error handles."); | |
| 92 } | |
| 93 } | |
| 94 | |
| 95 | |
| 96 DART_EXPORT void _Dart_ReportErrorHandle(const char* file, | |
| 42 int line, | 97 int line, |
| 43 const char* handle, | 98 const char* handle, |
| 44 const char* message) { | 99 const char* message) { |
| 45 fprintf(stderr, "%s:%d: invalid handle: '%s':\n '%s'\n", | 100 fprintf(stderr, "%s:%d: error handle: '%s':\n '%s'\n", |
| 46 file, line, handle, message); | 101 file, line, handle, message); |
| 47 OS::Abort(); | 102 OS::Abort(); |
| 48 } | 103 } |
| 49 | 104 |
| 50 | 105 |
| 106 static const char* MakeUnhandledExceptionCString( | |
| 107 const UnhandledException& uhe) { | |
| 108 const Instance& exception = Instance::Handle(uhe.exception()); | |
| 109 Object& strtmp = Object::Handle(DartLibraryCalls::ToString(exception)); | |
| 110 const char* exc_str = | |
| 111 "<Received exception while converting exception to string>"; | |
| 112 if (!strtmp.IsUnhandledException()) { | |
| 113 exc_str = strtmp.ToCString(); | |
| 114 } | |
| 115 | |
| 116 const Instance& stack = Instance::Handle(uhe.stacktrace()); | |
| 117 strtmp = DartLibraryCalls::ToString(stack); | |
| 118 const char* stack_str = | |
| 119 "<Received exception while converting stack trace to string>"; | |
| 120 if (!strtmp.IsUnhandledException()) { | |
| 121 stack_str = strtmp.ToCString(); | |
| 122 } | |
| 123 | |
| 124 const char* format = "Unhandled exception:\n%s\n%s"; | |
| 125 int len = (strlen(exc_str) + strlen(stack_str) + strlen(format) | |
| 126 - 4 // Two '%s' | |
| 127 + 1); // '\0' | |
| 128 char* buffer = reinterpret_cast<char*>(Api::Allocate(len)); | |
| 129 OS::SNPrint(buffer, len, format, exc_str, stack_str); | |
| 130 return buffer; | |
| 131 } | |
| 132 | |
| 133 | |
| 51 DART_EXPORT const char* Dart_GetError(const Dart_Handle& handle) { | 134 DART_EXPORT const char* Dart_GetError(const Dart_Handle& handle) { |
| 52 ASSERT(Isolate::Current() != NULL); | 135 ASSERT(Isolate::Current() != NULL); |
| 53 Zone zone; // Setup a VM zone as we are creating some handles. | 136 Zone zone; // Setup a VM zone as we are creating some handles. |
| 54 HandleScope scope; // Setup a VM handle scope. | 137 HandleScope scope; // Setup a VM handle scope. |
| 55 const Object& obj = Object::Handle(Api::UnwrapHandle(handle)); | 138 const Object& obj = Object::Handle(Api::UnwrapHandle(handle)); |
| 56 if (!obj.IsApiFailure()) { | 139 if (!obj.IsApiError()) { |
| 57 return ""; | 140 return ""; |
| 58 } | 141 } |
| 59 ApiFailure& failure = ApiFailure::Handle(); | 142 ApiError& failure = ApiError::Handle(); |
| 60 failure ^= obj.raw(); | 143 failure ^= obj.raw(); |
| 61 const String& message = String::Handle(failure.message()); | 144 const Object& data = Object::Handle(failure.data()); |
| 62 const char* msg = message.ToCString(); | 145 if (data.IsString()) { |
| 63 intptr_t len = strlen(msg) + 1; | 146 // Simple error message. |
| 64 char* msg_copy = reinterpret_cast<char*>(Api::Allocate(len)); | 147 String& message = String::Handle(); |
| 65 OS::SNPrint(msg_copy, len, "%s", msg); | 148 message ^= failure.data(); |
| 66 return msg_copy; | 149 const char* msg = message.ToCString(); |
| 150 intptr_t len = strlen(msg) + 1; | |
| 151 char* msg_copy = reinterpret_cast<char*>(Api::Allocate(len)); | |
| 152 strncpy(msg_copy, msg, len); | |
| 153 return msg_copy; | |
| 154 | |
|
Ivan Posva
2011/11/10 18:05:46
extra empty lines?
turnidge
2011/11/10 20:59:13
The extra empty lines help me scan the code -- oth
| |
| 155 } else if (data.IsUnhandledException()) { | |
| 156 UnhandledException& uhe = UnhandledException::Handle(); | |
| 157 uhe ^= data.raw(); | |
| 158 return MakeUnhandledExceptionCString(uhe); | |
| 159 | |
| 160 } else { | |
| 161 return "<Internal error in Dart_GetError: malformed error handle>"; | |
| 162 } | |
| 67 } | 163 } |
| 68 | 164 |
| 69 | 165 |
| 70 DART_EXPORT Dart_Handle Dart_Error(const char* format, ...) { | 166 DART_EXPORT Dart_Handle Dart_Error(const char* format, ...) { |
| 71 va_list args; | 167 va_list args; |
| 72 va_start(args, format); | 168 va_start(args, format); |
| 73 Dart_Handle error = Api::VError(format, args); | 169 Dart_Handle error = Api::VError(format, args); |
| 74 va_end(args); | 170 va_end(args); |
| 75 return error; | 171 return error; |
| 76 } | 172 } |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 134 ASSERT(Isolate::Current() != NULL); | 230 ASSERT(Isolate::Current() != NULL); |
| 135 Isolate::SetCurrent(NULL); | 231 Isolate::SetCurrent(NULL); |
| 136 } | 232 } |
| 137 | 233 |
| 138 | 234 |
| 139 static void SetupErrorResult(Dart_Handle* handle) { | 235 static void SetupErrorResult(Dart_Handle* handle) { |
| 140 // Make a copy of the error message as the original message string | 236 // Make a copy of the error message as the original message string |
| 141 // may get deallocated when we return back from the Dart API call. | 237 // may get deallocated when we return back from the Dart API call. |
| 142 const String& error = String::Handle( | 238 const String& error = String::Handle( |
| 143 Isolate::Current()->object_store()->sticky_error()); | 239 Isolate::Current()->object_store()->sticky_error()); |
| 144 const Object& obj = Object::Handle(ApiFailure::New(error)); | 240 const Object& obj = Object::Handle(ApiError::New(error)); |
| 145 *handle = Api::NewLocalHandle(obj); | 241 *handle = Api::NewLocalHandle(obj); |
| 146 } | 242 } |
| 147 | 243 |
| 148 | 244 |
| 149 DART_EXPORT void Dart_SetMessageCallbacks( | 245 DART_EXPORT void Dart_SetMessageCallbacks( |
| 150 Dart_PostMessageCallback post_message_callback, | 246 Dart_PostMessageCallback post_message_callback, |
| 151 Dart_ClosePortCallback close_port_callback) { | 247 Dart_ClosePortCallback close_port_callback) { |
| 152 Isolate* isolate = Isolate::Current(); | 248 Isolate* isolate = Isolate::Current(); |
| 153 ASSERT(isolate != NULL); | 249 ASSERT(isolate != NULL); |
| 154 ASSERT(post_message_callback != NULL); | 250 ASSERT(post_message_callback != NULL); |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 165 | 261 |
| 166 // Read object back from the snapshot. | 262 // Read object back from the snapshot. |
| 167 Isolate* isolate = Isolate::Current(); | 263 Isolate* isolate = Isolate::Current(); |
| 168 SnapshotReader reader(snapshot, isolate->heap(), isolate->object_store()); | 264 SnapshotReader reader(snapshot, isolate->heap(), isolate->object_store()); |
| 169 Instance& instance = Instance::Handle(); | 265 Instance& instance = Instance::Handle(); |
| 170 instance ^= reader.ReadObject(); | 266 instance ^= reader.ReadObject(); |
| 171 return instance.raw(); | 267 return instance.raw(); |
| 172 } | 268 } |
| 173 | 269 |
| 174 | 270 |
| 175 static void ProcessUnhandledException(const UnhandledException& uhe) { | 271 DART_EXPORT Dart_Handle Dart_HandleMessage(Dart_Port dest_port, |
| 176 const Instance& exception = Instance::Handle(uhe.exception()); | 272 Dart_Port reply_port, |
| 177 Instance& strtmp = Instance::Handle(DartLibraryCalls::ToString(exception)); | 273 Dart_Message dart_message) { |
| 178 const char* str = strtmp.ToCString(); | |
| 179 fprintf(stderr, "%s\n", str); | |
| 180 const Instance& stack = Instance::Handle(uhe.stacktrace()); | |
| 181 strtmp = DartLibraryCalls::ToString(stack); | |
| 182 str = strtmp.ToCString(); | |
| 183 fprintf(stderr, "%s\n", str); | |
| 184 exit(255); | |
| 185 } | |
| 186 | |
| 187 | |
| 188 DART_EXPORT void Dart_HandleMessage(Dart_Port dest_port, | |
| 189 Dart_Port reply_port, | |
| 190 Dart_Message dart_message) { | |
| 191 Zone zone; // Setup a VM zone as we are creating some handles. | 274 Zone zone; // Setup a VM zone as we are creating some handles. |
| 192 HandleScope scope; // Setup a VM handle scope. | 275 HandleScope scope; // Setup a VM handle scope. |
| 193 const Instance& msg = Instance::Handle(DeserializeMessage(dart_message)); | 276 const Instance& msg = Instance::Handle(DeserializeMessage(dart_message)); |
| 194 const String& class_name = | 277 const String& class_name = |
| 195 String::Handle(String::NewSymbol("ReceivePortImpl")); | 278 String::Handle(String::NewSymbol("ReceivePortImpl")); |
| 196 const String& function_name = | 279 const String& function_name = |
| 197 String::Handle(String::NewSymbol("handleMessage_")); | 280 String::Handle(String::NewSymbol("handleMessage_")); |
| 198 const int kNumArguments = 3; | 281 const int kNumArguments = 3; |
| 199 const Array& kNoArgumentNames = Array::Handle(); | 282 const Array& kNoArgumentNames = Array::Handle(); |
| 200 const Function& function = Function::Handle( | 283 const Function& function = Function::Handle( |
| 201 Resolver::ResolveStatic(Library::Handle(Library::CoreLibrary()), | 284 Resolver::ResolveStatic(Library::Handle(Library::CoreLibrary()), |
| 202 class_name, | 285 class_name, |
| 203 function_name, | 286 function_name, |
| 204 kNumArguments, | 287 kNumArguments, |
| 205 kNoArgumentNames, | 288 kNoArgumentNames, |
| 206 Resolver::kIsQualified)); | 289 Resolver::kIsQualified)); |
| 207 GrowableArray<const Object*> arguments(kNumArguments); | 290 GrowableArray<const Object*> arguments(kNumArguments); |
| 208 arguments.Add(&Integer::Handle(Integer::New(dest_port))); | 291 arguments.Add(&Integer::Handle(Integer::New(dest_port))); |
| 209 arguments.Add(&Integer::Handle(Integer::New(reply_port))); | 292 arguments.Add(&Integer::Handle(Integer::New(reply_port))); |
| 210 arguments.Add(&msg); | 293 arguments.Add(&msg); |
| 211 const Object& result = Object::Handle( | 294 const Object& result = Object::Handle( |
| 212 DartEntry::InvokeStatic(function, arguments, kNoArgumentNames)); | 295 DartEntry::InvokeStatic(function, arguments, kNoArgumentNames)); |
| 213 if (result.IsUnhandledException()) { | 296 if (result.IsUnhandledException()) { |
| 214 UnhandledException& uhe = UnhandledException::Handle(); | 297 return Api::ErrorFromException(result); |
| 215 uhe ^= result.raw(); | |
| 216 // TODO(turnidge): Instead of exiting here, just return the | |
| 217 // exception so that the embedder can choose how to handle this | |
| 218 // case. | |
| 219 ProcessUnhandledException(uhe); | |
| 220 } | 298 } |
| 221 ASSERT(result.IsNull()); | 299 ASSERT(result.IsNull()); |
| 300 return Api::Success(); | |
| 222 } | 301 } |
| 223 | 302 |
| 224 | 303 |
| 225 DART_EXPORT Dart_Handle Dart_RunLoop() { | 304 DART_EXPORT Dart_Handle Dart_RunLoop() { |
| 226 Zone zone; // Setup a VM zone as we are creating some handles. | 305 Zone zone; // Setup a VM zone as we are creating some handles. |
| 227 HandleScope scope; // Setup a VM handle scope. | 306 HandleScope scope; // Setup a VM handle scope. |
| 228 | 307 |
| 229 Isolate* isolate = Isolate::Current(); | 308 Isolate* isolate = Isolate::Current(); |
| 230 LongJump* base = isolate->long_jump_base(); | 309 LongJump* base = isolate->long_jump_base(); |
| 231 LongJump jump; | 310 LongJump jump; |
| (...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 441 HandleScope scope; // Setup a VM handle scope. | 520 HandleScope scope; // Setup a VM handle scope. |
| 442 const Object& obj = Object::Handle(Api::UnwrapHandle(object)); | 521 const Object& obj = Object::Handle(Api::UnwrapHandle(object)); |
| 443 Object& result = Object::Handle(); | 522 Object& result = Object::Handle(); |
| 444 if (obj.IsString()) { | 523 if (obj.IsString()) { |
| 445 result = obj.raw(); | 524 result = obj.raw(); |
| 446 } else if (obj.IsInstance()) { | 525 } else if (obj.IsInstance()) { |
| 447 Instance& receiver = Instance::Handle(); | 526 Instance& receiver = Instance::Handle(); |
| 448 receiver ^= obj.raw(); | 527 receiver ^= obj.raw(); |
| 449 result = DartLibraryCalls::ToString(receiver); | 528 result = DartLibraryCalls::ToString(receiver); |
| 450 if (result.IsUnhandledException()) { | 529 if (result.IsUnhandledException()) { |
| 451 return Api::Error("An exception occurred when converting to string"); | 530 return Api::ErrorFromException(result); |
| 452 } | 531 } |
| 453 } else { | 532 } else { |
| 454 // This is a VM internal object. Call the C++ method of printing. | 533 // This is a VM internal object. Call the C++ method of printing. |
| 455 result = String::New(obj.ToCString()); | 534 result = String::New(obj.ToCString()); |
| 456 } | 535 } |
| 457 return Api::NewLocalHandle(result); | 536 return Api::NewLocalHandle(result); |
| 458 } | 537 } |
| 459 | 538 |
| 460 | 539 |
| 461 DART_EXPORT Dart_Handle Dart_Null() { | 540 DART_EXPORT Dart_Handle Dart_Null() { |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 503 HandleScope scope; // Setup a VM handle scope. | 582 HandleScope scope; // Setup a VM handle scope. |
| 504 const Instance& expected = Instance::CheckedHandle(Api::UnwrapHandle(obj1)); | 583 const Instance& expected = Instance::CheckedHandle(Api::UnwrapHandle(obj1)); |
| 505 const Instance& actual = Instance::CheckedHandle(Api::UnwrapHandle(obj2)); | 584 const Instance& actual = Instance::CheckedHandle(Api::UnwrapHandle(obj2)); |
| 506 const Instance& result = | 585 const Instance& result = |
| 507 Instance::Handle(DartLibraryCalls::Equals(expected, actual)); | 586 Instance::Handle(DartLibraryCalls::Equals(expected, actual)); |
| 508 if (result.IsBool()) { | 587 if (result.IsBool()) { |
| 509 Bool& b = Bool::Handle(); | 588 Bool& b = Bool::Handle(); |
| 510 b ^= result.raw(); | 589 b ^= result.raw(); |
| 511 *value = b.value(); | 590 *value = b.value(); |
| 512 return Api::Success(); | 591 return Api::Success(); |
| 592 } else if (result.IsUnhandledException()) { | |
| 593 return Api::ErrorFromException(result); | |
| 513 } else { | 594 } else { |
| 514 return Api::Error("An exception occured when calling '=='"); | 595 return Api::Error("Expected boolean result from =="); |
| 515 } | 596 } |
| 516 } | 597 } |
| 517 | 598 |
| 518 | 599 |
| 519 DART_EXPORT Dart_Handle Dart_IsSame(Dart_Handle obj1, Dart_Handle obj2, | 600 DART_EXPORT Dart_Handle Dart_IsSame(Dart_Handle obj1, Dart_Handle obj2, |
| 520 bool* value) { | 601 bool* value) { |
| 521 Zone zone; // Setup a VM zone as we are creating some handles. | 602 Zone zone; // Setup a VM zone as we are creating some handles. |
| 522 HandleScope scope; // Setup a VM handle scope. | 603 HandleScope scope; // Setup a VM handle scope. |
| 523 const Object& expected = Object::Handle(Api::UnwrapHandle(obj1)); | 604 const Object& expected = Object::Handle(Api::UnwrapHandle(obj1)); |
| 524 const Object& actual = Object::Handle(Api::UnwrapHandle(obj2)); | 605 const Object& actual = Object::Handle(Api::UnwrapHandle(obj2)); |
| (...skipping 449 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 974 *len = integer.AsInt64Value(); | 1055 *len = integer.AsInt64Value(); |
| 975 } else if (retval.IsBigint()) { | 1056 } else if (retval.IsBigint()) { |
| 976 Bigint& bigint = Bigint::Handle(); | 1057 Bigint& bigint = Bigint::Handle(); |
| 977 bigint ^= retval.raw(); | 1058 bigint ^= retval.raw(); |
| 978 if (BigintOperations::FitsIntoInt64(bigint)) { | 1059 if (BigintOperations::FitsIntoInt64(bigint)) { |
| 979 *len = BigintOperations::ToInt64(bigint); | 1060 *len = BigintOperations::ToInt64(bigint); |
| 980 } else { | 1061 } else { |
| 981 result = Api::Error("Length of List object is greater than the " | 1062 result = Api::Error("Length of List object is greater than the " |
| 982 "maximum value that 'len' parameter can hold"); | 1063 "maximum value that 'len' parameter can hold"); |
| 983 } | 1064 } |
| 1065 } else if (retval.IsUnhandledException()) { | |
| 1066 result = Api::ErrorFromException(retval); | |
| 984 } else { | 1067 } else { |
| 985 result = Api::Error("Length of List object is not an integer"); | 1068 result = Api::Error("Length of List object is not an integer"); |
| 986 } | 1069 } |
| 987 } else { | 1070 } else { |
| 988 SetupErrorResult(&result); | 1071 SetupErrorResult(&result); |
| 989 } | 1072 } |
| 990 isolate->set_long_jump_base(base); | 1073 isolate->set_long_jump_base(base); |
| 991 return result; | 1074 return result; |
| 992 } | 1075 } |
| 993 } | 1076 } |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 1008 if (setjmp(*jump.Set()) == 0) { | 1091 if (setjmp(*jump.Set()) == 0) { |
| 1009 Instance& retval = Instance::Handle(); | 1092 Instance& retval = Instance::Handle(); |
| 1010 GrowableArray<const Object*> args(0); | 1093 GrowableArray<const Object*> args(0); |
| 1011 args.Add(&index); | 1094 args.Add(&index); |
| 1012 const Array& kNoArgumentNames = Array::Handle(); | 1095 const Array& kNoArgumentNames = Array::Handle(); |
| 1013 retval = DartEntry::InvokeDynamic(instance, | 1096 retval = DartEntry::InvokeDynamic(instance, |
| 1014 function, | 1097 function, |
| 1015 args, | 1098 args, |
| 1016 kNoArgumentNames); | 1099 kNoArgumentNames); |
| 1017 if (retval.IsUnhandledException()) { | 1100 if (retval.IsUnhandledException()) { |
| 1018 *result = Api::Error("Unexpected exception in '[]'"); | 1101 *result = Api::ErrorFromException(retval); |
| 1019 } else { | 1102 } else { |
| 1020 *result = Api::Success(); | 1103 *result = Api::Success(); |
| 1021 } | 1104 } |
| 1022 isolate->set_long_jump_base(base); | 1105 isolate->set_long_jump_base(base); |
| 1023 return retval.raw(); | 1106 return retval.raw(); |
| 1024 } | 1107 } |
| 1025 SetupErrorResult(result); | 1108 SetupErrorResult(result); |
| 1026 isolate->set_long_jump_base(base); | 1109 isolate->set_long_jump_base(base); |
| 1027 return Object::null(); | 1110 return Object::null(); |
| 1028 } | 1111 } |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1061 String& name = String::Handle(String::New("[]")); | 1144 String& name = String::Handle(String::New("[]")); |
| 1062 const Function& function = Function::Handle( | 1145 const Function& function = Function::Handle( |
| 1063 Resolver::ResolveDynamic(instance, name, 2, 0)); | 1146 Resolver::ResolveDynamic(instance, name, 2, 0)); |
| 1064 if (!function.IsNull()) { | 1147 if (!function.IsNull()) { |
| 1065 Object& element = Object::Handle(); | 1148 Object& element = Object::Handle(); |
| 1066 Integer& intobj = Integer::Handle(); | 1149 Integer& intobj = Integer::Handle(); |
| 1067 Dart_Handle result; | 1150 Dart_Handle result; |
| 1068 for (int i = 0; i < length; i++) { | 1151 for (int i = 0; i < length; i++) { |
| 1069 intobj = Integer::New(offset + i); | 1152 intobj = Integer::New(offset + i); |
| 1070 element = GetListAt(isolate, instance, intobj, function, &result); | 1153 element = GetListAt(isolate, instance, intobj, function, &result); |
| 1071 if (!Dart_IsValid(result)) { | 1154 if (Dart_IsError(result)) { |
| 1072 return result; // Error condition. | 1155 return result; // Error condition. |
| 1073 } | 1156 } |
| 1074 intobj ^= element.raw(); | 1157 intobj ^= element.raw(); |
| 1075 ASSERT(intobj.AsInt64Value() <= 0xff); | 1158 ASSERT(intobj.AsInt64Value() <= 0xff); |
| 1076 // TODO(hpayer): value should always be smaller then 0xff. Add error | 1159 // TODO(hpayer): value should always be smaller then 0xff. Add error |
| 1077 // handling. | 1160 // handling. |
| 1078 native_array[i] = static_cast<uint8_t>(intobj.AsInt64Value() & 0xff); | 1161 native_array[i] = static_cast<uint8_t>(intobj.AsInt64Value() & 0xff); |
| 1079 } | 1162 } |
| 1080 return Api::Success(); | 1163 return Api::Success(); |
| 1081 } | 1164 } |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 1104 if (!instance.IsNull()) { | 1187 if (!instance.IsNull()) { |
| 1105 String& name = String::Handle(String::New("[]")); | 1188 String& name = String::Handle(String::New("[]")); |
| 1106 const Function& function = Function::Handle( | 1189 const Function& function = Function::Handle( |
| 1107 Resolver::ResolveDynamic(instance, name, 2, 0)); | 1190 Resolver::ResolveDynamic(instance, name, 2, 0)); |
| 1108 if (!function.IsNull()) { | 1191 if (!function.IsNull()) { |
| 1109 Object& element = Object::Handle(); | 1192 Object& element = Object::Handle(); |
| 1110 Integer& indexobj = Integer::Handle(); | 1193 Integer& indexobj = Integer::Handle(); |
| 1111 Dart_Handle result; | 1194 Dart_Handle result; |
| 1112 indexobj = Integer::New(index); | 1195 indexobj = Integer::New(index); |
| 1113 element = GetListAt(isolate, instance, indexobj, function, &result); | 1196 element = GetListAt(isolate, instance, indexobj, function, &result); |
| 1114 if (!Dart_IsValid(result)) { | 1197 if (Dart_IsError(result)) { |
| 1115 return result; // Error condition. | 1198 return result; // Error condition. |
| 1116 } | 1199 } |
| 1117 return Api::NewLocalHandle(element); | 1200 return Api::NewLocalHandle(element); |
| 1118 } | 1201 } |
| 1119 } | 1202 } |
| 1120 return Api::Error("Object does not implement the 'List' interface"); | 1203 return Api::Error("Object does not implement the 'List' interface"); |
| 1121 } | 1204 } |
| 1122 | 1205 |
| 1123 | 1206 |
| 1124 static void SetListAt(Isolate* isolate, | 1207 static void SetListAt(Isolate* isolate, |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 1136 GrowableArray<const Object*> args(1); | 1219 GrowableArray<const Object*> args(1); |
| 1137 args.Add(&index); | 1220 args.Add(&index); |
| 1138 args.Add(&value); | 1221 args.Add(&value); |
| 1139 Instance& retval = Instance::Handle(); | 1222 Instance& retval = Instance::Handle(); |
| 1140 const Array& kNoArgumentNames = Array::Handle(); | 1223 const Array& kNoArgumentNames = Array::Handle(); |
| 1141 retval = DartEntry::InvokeDynamic(instance, | 1224 retval = DartEntry::InvokeDynamic(instance, |
| 1142 function, | 1225 function, |
| 1143 args, | 1226 args, |
| 1144 kNoArgumentNames); | 1227 kNoArgumentNames); |
| 1145 if (retval.IsUnhandledException()) { | 1228 if (retval.IsUnhandledException()) { |
| 1146 *result = Api::Error("Unexpected exception in '[]='"); | 1229 *result = Api::ErrorFromException(retval); |
| 1147 } else { | 1230 } else { |
| 1148 *result = Api::Success(); | 1231 *result = Api::Success(); |
| 1149 } | 1232 } |
| 1150 } else { | 1233 } else { |
| 1151 SetupErrorResult(result); | 1234 SetupErrorResult(result); |
| 1152 } | 1235 } |
| 1153 isolate->set_long_jump_base(base); | 1236 isolate->set_long_jump_base(base); |
| 1154 } | 1237 } |
| 1155 | 1238 |
| 1156 | 1239 |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 1183 const Function& function = Function::Handle( | 1266 const Function& function = Function::Handle( |
| 1184 Resolver::ResolveDynamic(instance, name, 3, 0)); | 1267 Resolver::ResolveDynamic(instance, name, 3, 0)); |
| 1185 if (!function.IsNull()) { | 1268 if (!function.IsNull()) { |
| 1186 Integer& indexobj = Integer::Handle(); | 1269 Integer& indexobj = Integer::Handle(); |
| 1187 Integer& valueobj = Integer::Handle(); | 1270 Integer& valueobj = Integer::Handle(); |
| 1188 Dart_Handle result; | 1271 Dart_Handle result; |
| 1189 for (int i = 0; i < length; i++) { | 1272 for (int i = 0; i < length; i++) { |
| 1190 indexobj = Integer::New(offset + i); | 1273 indexobj = Integer::New(offset + i); |
| 1191 valueobj ^= Integer::New(native_array[i]); | 1274 valueobj ^= Integer::New(native_array[i]); |
| 1192 SetListAt(isolate, instance, indexobj, valueobj, function, &result); | 1275 SetListAt(isolate, instance, indexobj, valueobj, function, &result); |
| 1193 if (!Dart_IsValid(result)) { | 1276 if (Dart_IsError(result)) { |
| 1194 return result; // Error condition. | 1277 return result; // Error condition. |
| 1195 } | 1278 } |
| 1196 } | 1279 } |
| 1197 return Api::Success(); | 1280 return Api::Success(); |
| 1198 } | 1281 } |
| 1199 } | 1282 } |
| 1200 return Api::Error("Object does not implement the 'List' interface"); | 1283 return Api::Error("Object does not implement the 'List' interface"); |
| 1201 } | 1284 } |
| 1202 | 1285 |
| 1203 | 1286 |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1245 Dart_Handle* result) { | 1328 Dart_Handle* result) { |
| 1246 Isolate* isolate = Isolate::Current(); | 1329 Isolate* isolate = Isolate::Current(); |
| 1247 ASSERT(isolate != NULL); | 1330 ASSERT(isolate != NULL); |
| 1248 LongJump* base = isolate->long_jump_base(); | 1331 LongJump* base = isolate->long_jump_base(); |
| 1249 LongJump jump; | 1332 LongJump jump; |
| 1250 isolate->set_long_jump_base(&jump); | 1333 isolate->set_long_jump_base(&jump); |
| 1251 if (setjmp(*jump.Set()) == 0) { | 1334 if (setjmp(*jump.Set()) == 0) { |
| 1252 const Array& kNoArgumentNames = Array::Handle(); | 1335 const Array& kNoArgumentNames = Array::Handle(); |
| 1253 const Instance& retval = Instance::Handle( | 1336 const Instance& retval = Instance::Handle( |
| 1254 DartEntry::InvokeStatic(function, args, kNoArgumentNames)); | 1337 DartEntry::InvokeStatic(function, args, kNoArgumentNames)); |
| 1255 *result = Api::NewLocalHandle(retval); | 1338 if (retval.IsUnhandledException()) { |
| 1339 *result = Api::ErrorFromException(retval); | |
| 1340 } else { | |
| 1341 *result = Api::NewLocalHandle(retval); | |
| 1342 } | |
| 1256 } else { | 1343 } else { |
| 1257 SetupErrorResult(result); | 1344 SetupErrorResult(result); |
| 1258 } | 1345 } |
| 1259 isolate->set_long_jump_base(base); | 1346 isolate->set_long_jump_base(base); |
| 1260 } | 1347 } |
| 1261 | 1348 |
| 1262 | 1349 |
| 1263 // NOTE: Need to pass 'result' as a parameter here in order to avoid | 1350 // NOTE: Need to pass 'result' as a parameter here in order to avoid |
| 1264 // warning: variable 'result' might be clobbered by 'longjmp' or 'vfork' | 1351 // warning: variable 'result' might be clobbered by 'longjmp' or 'vfork' |
| 1265 // which shows up because of the use of setjmp. | 1352 // which shows up because of the use of setjmp. |
| 1266 static void InvokeDynamic(const Instance& receiver, | 1353 static void InvokeDynamic(const Instance& receiver, |
| 1267 const Function& function, | 1354 const Function& function, |
| 1268 GrowableArray<const Object*>& args, | 1355 GrowableArray<const Object*>& args, |
| 1269 Dart_Handle* result) { | 1356 Dart_Handle* result) { |
| 1270 Isolate* isolate = Isolate::Current(); | 1357 Isolate* isolate = Isolate::Current(); |
| 1271 ASSERT(isolate != NULL); | 1358 ASSERT(isolate != NULL); |
| 1272 LongJump* base = isolate->long_jump_base(); | 1359 LongJump* base = isolate->long_jump_base(); |
| 1273 LongJump jump; | 1360 LongJump jump; |
| 1274 isolate->set_long_jump_base(&jump); | 1361 isolate->set_long_jump_base(&jump); |
| 1275 if (setjmp(*jump.Set()) == 0) { | 1362 if (setjmp(*jump.Set()) == 0) { |
| 1276 const Array& kNoArgumentNames = Array::Handle(); | 1363 const Array& kNoArgumentNames = Array::Handle(); |
| 1277 const Instance& retval = Instance::Handle( | 1364 const Instance& retval = Instance::Handle( |
| 1278 DartEntry::InvokeDynamic(receiver, function, args, kNoArgumentNames)); | 1365 DartEntry::InvokeDynamic(receiver, function, args, kNoArgumentNames)); |
| 1279 *result = Api::NewLocalHandle(retval); | 1366 if (retval.IsUnhandledException()) { |
| 1367 *result = Api::ErrorFromException(retval); | |
| 1368 } else { | |
| 1369 *result = Api::NewLocalHandle(retval); | |
| 1370 } | |
| 1280 } else { | 1371 } else { |
| 1281 SetupErrorResult(result); | 1372 SetupErrorResult(result); |
| 1282 } | 1373 } |
| 1283 isolate->set_long_jump_base(base); | 1374 isolate->set_long_jump_base(base); |
| 1284 } | 1375 } |
| 1285 | 1376 |
| 1286 | 1377 |
| 1287 // NOTE: Need to pass 'result' as a parameter here in order to avoid | 1378 // NOTE: Need to pass 'result' as a parameter here in order to avoid |
| 1288 // warning: variable 'result' might be clobbered by 'longjmp' or 'vfork' | 1379 // warning: variable 'result' might be clobbered by 'longjmp' or 'vfork' |
| 1289 // which shows up because of the use of setjmp. | 1380 // which shows up because of the use of setjmp. |
| 1290 static void InvokeClosure(const Closure& closure, | 1381 static void InvokeClosure(const Closure& closure, |
| 1291 GrowableArray<const Object*>& args, | 1382 GrowableArray<const Object*>& args, |
| 1292 Dart_Handle* result) { | 1383 Dart_Handle* result) { |
| 1293 Isolate* isolate = Isolate::Current(); | 1384 Isolate* isolate = Isolate::Current(); |
| 1294 ASSERT(isolate != NULL); | 1385 ASSERT(isolate != NULL); |
| 1295 LongJump* base = isolate->long_jump_base(); | 1386 LongJump* base = isolate->long_jump_base(); |
| 1296 LongJump jump; | 1387 LongJump jump; |
| 1297 isolate->set_long_jump_base(&jump); | 1388 isolate->set_long_jump_base(&jump); |
| 1298 if (setjmp(*jump.Set()) == 0) { | 1389 if (setjmp(*jump.Set()) == 0) { |
| 1299 const Array& kNoArgumentNames = Array::Handle(); | 1390 const Array& kNoArgumentNames = Array::Handle(); |
| 1300 const Instance& retval = Instance::Handle( | 1391 const Instance& retval = Instance::Handle( |
| 1301 DartEntry::InvokeClosure(closure, args, kNoArgumentNames)); | 1392 DartEntry::InvokeClosure(closure, args, kNoArgumentNames)); |
| 1302 *result = Api::NewLocalHandle(retval); | 1393 if (retval.IsUnhandledException()) { |
| 1394 *result = Api::ErrorFromException(retval); | |
| 1395 } else { | |
| 1396 *result = Api::NewLocalHandle(retval); | |
| 1397 } | |
| 1303 } else { | 1398 } else { |
| 1304 SetupErrorResult(result); | 1399 SetupErrorResult(result); |
| 1305 } | 1400 } |
| 1306 isolate->set_long_jump_base(base); | 1401 isolate->set_long_jump_base(base); |
| 1307 } | 1402 } |
| 1308 | 1403 |
| 1309 | 1404 |
| 1310 DART_EXPORT Dart_Handle Dart_InvokeStatic(Dart_Handle library_in, | 1405 DART_EXPORT Dart_Handle Dart_InvokeStatic(Dart_Handle library_in, |
| 1311 Dart_Handle class_name_in, | 1406 Dart_Handle class_name_in, |
| 1312 Dart_Handle function_name_in, | 1407 Dart_Handle function_name_in, |
| (...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1456 | 1551 |
| 1457 DART_EXPORT void Dart_SetReturnValue(Dart_NativeArguments args, | 1552 DART_EXPORT void Dart_SetReturnValue(Dart_NativeArguments args, |
| 1458 Dart_Handle retval) { | 1553 Dart_Handle retval) { |
| 1459 Zone zone; // Setup a VM zone as we are creating some handles. | 1554 Zone zone; // Setup a VM zone as we are creating some handles. |
| 1460 HandleScope scope; // Setup a VM handle scope. | 1555 HandleScope scope; // Setup a VM handle scope. |
| 1461 NativeArguments* arguments = reinterpret_cast<NativeArguments*>(args); | 1556 NativeArguments* arguments = reinterpret_cast<NativeArguments*>(args); |
| 1462 arguments->SetReturn(Object::Handle(Api::UnwrapHandle(retval))); | 1557 arguments->SetReturn(Object::Handle(Api::UnwrapHandle(retval))); |
| 1463 } | 1558 } |
| 1464 | 1559 |
| 1465 | 1560 |
| 1466 DART_EXPORT bool Dart_ExceptionOccurred(Dart_Handle result) { | |
| 1467 Zone zone; // Setup a VM zone as we are creating some handles. | |
| 1468 HandleScope scope; // Setup a VM handle scope. | |
| 1469 const Object& retval = Object::Handle(Api::UnwrapHandle(result)); | |
| 1470 return retval.IsUnhandledException(); | |
| 1471 } | |
| 1472 | |
| 1473 | |
| 1474 DART_EXPORT Dart_Handle Dart_GetException(Dart_Handle result) { | |
| 1475 Zone zone; // Setup a VM zone as we are creating some handles. | |
| 1476 HandleScope scope; // Setup a VM handle scope. | |
| 1477 const Object& retval = Object::Handle(Api::UnwrapHandle(result)); | |
| 1478 if (retval.IsUnhandledException()) { | |
| 1479 const UnhandledException& unhandled = UnhandledException::Handle( | |
| 1480 reinterpret_cast<RawUnhandledException*>(retval.raw())); | |
| 1481 const Object& exception = Object::Handle(unhandled.exception()); | |
| 1482 return Api::NewLocalHandle(exception); | |
| 1483 } | |
| 1484 return Api::Error("Object is not an unhandled exception object"); | |
| 1485 } | |
| 1486 | |
| 1487 | |
| 1488 DART_EXPORT Dart_Handle Dart_GetStacktrace(Dart_Handle unhandled_excp) { | |
| 1489 Zone zone; // Setup a VM zone as we are creating some handles. | |
| 1490 HandleScope scope; // Setup a VM handle scope. | |
| 1491 const Object& retval = Object::Handle(Api::UnwrapHandle(unhandled_excp)); | |
| 1492 if (retval.IsUnhandledException()) { | |
| 1493 const UnhandledException& unhandled = UnhandledException::Handle( | |
| 1494 reinterpret_cast<RawUnhandledException*>(retval.raw())); | |
| 1495 const Object& stacktrace = Object::Handle(unhandled.stacktrace()); | |
| 1496 return Api::NewLocalHandle(stacktrace); | |
| 1497 } | |
| 1498 return Api::Error("Object is not an unhandled exception object"); | |
| 1499 } | |
| 1500 | |
| 1501 | |
| 1502 DART_EXPORT Dart_Handle Dart_ThrowException(Dart_Handle exception) { | 1561 DART_EXPORT Dart_Handle Dart_ThrowException(Dart_Handle exception) { |
| 1503 Isolate* isolate = Isolate::Current(); | 1562 Isolate* isolate = Isolate::Current(); |
| 1504 ASSERT(isolate != NULL); | 1563 ASSERT(isolate != NULL); |
| 1505 Zone zone; // Setup a VM zone as we are creating some handles. | 1564 Zone zone; // Setup a VM zone as we are creating some handles. |
| 1506 HandleScope scope; // Setup a VM handle scope. | 1565 HandleScope scope; // Setup a VM handle scope. |
| 1507 if (isolate->top_exit_frame_info() == 0) { | 1566 if (isolate->top_exit_frame_info() == 0) { |
| 1508 // There are no dart frames on the stack so it would be illegal to | 1567 // There are no dart frames on the stack so it would be illegal to |
| 1509 // throw an exception here. | 1568 // throw an exception here. |
| 1510 return Api::Error("No Dart frames on stack, cannot throw exception"); | 1569 return Api::Error("No Dart frames on stack, cannot throw exception"); |
| 1511 } | 1570 } |
| (...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1688 } | 1747 } |
| 1689 return Api::Error("Unable to find field in the class"); | 1748 return Api::Error("Unable to find field in the class"); |
| 1690 } | 1749 } |
| 1691 | 1750 |
| 1692 | 1751 |
| 1693 DART_EXPORT Dart_Handle Dart_GetStaticField(Dart_Handle cls, | 1752 DART_EXPORT Dart_Handle Dart_GetStaticField(Dart_Handle cls, |
| 1694 Dart_Handle name) { | 1753 Dart_Handle name) { |
| 1695 Zone zone; // Setup a VM zone as we are creating some handles. | 1754 Zone zone; // Setup a VM zone as we are creating some handles. |
| 1696 HandleScope scope; // Setup a VM handle scope. | 1755 HandleScope scope; // Setup a VM handle scope. |
| 1697 Dart_Handle result = LookupStaticField(cls, name, kGetter); | 1756 Dart_Handle result = LookupStaticField(cls, name, kGetter); |
| 1698 if (!::Dart_IsValid(result)) { | 1757 if (::Dart_IsError(result)) { |
| 1699 return result; | 1758 return result; |
| 1700 } | 1759 } |
| 1701 Object& retval = Object::Handle(); | 1760 Object& retval = Object::Handle(); |
| 1702 const Object& obj = Object::Handle(Api::UnwrapHandle(result)); | 1761 const Object& obj = Object::Handle(Api::UnwrapHandle(result)); |
| 1703 if (obj.IsField()) { | 1762 if (obj.IsField()) { |
| 1704 Field& fld = Field::Handle(); | 1763 Field& fld = Field::Handle(); |
| 1705 fld ^= obj.raw(); | 1764 fld ^= obj.raw(); |
| 1706 retval = fld.value(); | 1765 retval = fld.value(); |
| 1707 return Api::NewLocalHandle(retval); | 1766 return Api::NewLocalHandle(retval); |
| 1708 } else { | 1767 } else { |
| 1709 Function& func = Function::Handle(); | 1768 Function& func = Function::Handle(); |
| 1710 func ^= obj.raw(); | 1769 func ^= obj.raw(); |
| 1711 GrowableArray<const Object*> args; | 1770 GrowableArray<const Object*> args; |
| 1712 InvokeStatic(func, args, &result); | 1771 InvokeStatic(func, args, &result); |
| 1713 if (::Dart_IsValid(result)) { | |
| 1714 if (Dart_ExceptionOccurred(result)) { | |
| 1715 return Api::Error( | |
| 1716 "An exception occurred when getting the static field"); | |
| 1717 } | |
| 1718 } | |
| 1719 return result; | 1772 return result; |
| 1720 } | 1773 } |
| 1721 } | 1774 } |
| 1722 | 1775 |
| 1723 | 1776 |
| 1724 // TODO(iposva): The value parameter should be documented as being an instance. | 1777 // TODO(iposva): The value parameter should be documented as being an instance. |
| 1778 // TODO(turnidge): Is this skipping the setter? | |
| 1725 DART_EXPORT Dart_Handle Dart_SetStaticField(Dart_Handle cls, | 1779 DART_EXPORT Dart_Handle Dart_SetStaticField(Dart_Handle cls, |
| 1726 Dart_Handle name, | 1780 Dart_Handle name, |
| 1727 Dart_Handle value) { | 1781 Dart_Handle value) { |
| 1728 Zone zone; // Setup a VM zone as we are creating some handles. | 1782 Zone zone; // Setup a VM zone as we are creating some handles. |
| 1729 HandleScope scope; // Setup a VM handle scope. | 1783 HandleScope scope; // Setup a VM handle scope. |
| 1730 Dart_Handle result = LookupStaticField(cls, name, kSetter); | 1784 Dart_Handle result = LookupStaticField(cls, name, kSetter); |
| 1731 if (!::Dart_IsValid(result)) { | 1785 if (::Dart_IsError(result)) { |
| 1732 return result; | 1786 return result; |
| 1733 } | 1787 } |
| 1734 Field& fld = Field::Handle(); | 1788 Field& fld = Field::Handle(); |
| 1735 fld ^= Api::UnwrapHandle(result); | 1789 fld ^= Api::UnwrapHandle(result); |
| 1736 if (fld.is_final()) { | 1790 if (fld.is_final()) { |
| 1737 return Api::Error("Specified field is a static final field in the class"); | 1791 return Api::Error("Specified field is a static final field in the class"); |
| 1738 } | 1792 } |
| 1739 const Object& val = Object::Handle(Api::UnwrapHandle(value)); | 1793 const Object& val = Object::Handle(Api::UnwrapHandle(value)); |
| 1740 Instance& instance = Instance::Handle(); | 1794 Instance& instance = Instance::Handle(); |
| 1741 instance ^= val.raw(); | 1795 instance ^= val.raw(); |
| 1742 fld.set_value(instance); | 1796 fld.set_value(instance); |
| 1743 return Api::NewLocalHandle(val); | 1797 return Api::NewLocalHandle(val); |
| 1744 } | 1798 } |
| 1745 | 1799 |
| 1746 | 1800 |
| 1747 DART_EXPORT Dart_Handle Dart_GetInstanceField(Dart_Handle obj, | 1801 DART_EXPORT Dart_Handle Dart_GetInstanceField(Dart_Handle obj, |
| 1748 Dart_Handle name) { | 1802 Dart_Handle name) { |
| 1749 Zone zone; // Setup a VM zone as we are creating some handles. | 1803 Zone zone; // Setup a VM zone as we are creating some handles. |
| 1750 HandleScope scope; // Setup a VM handle scope. | 1804 HandleScope scope; // Setup a VM handle scope. |
| 1751 const Object& param = Object::Handle(Api::UnwrapHandle(obj)); | 1805 const Object& param = Object::Handle(Api::UnwrapHandle(obj)); |
| 1752 if (param.IsNull() || !param.IsInstance()) { | 1806 if (param.IsNull() || !param.IsInstance()) { |
| 1753 return Api::Error("Invalid object passed in to access instance field"); | 1807 return Api::Error("Invalid object passed in to access instance field"); |
| 1754 } | 1808 } |
| 1755 Instance& object = Instance::Handle(); | 1809 Instance& object = Instance::Handle(); |
| 1756 object ^= param.raw(); | 1810 object ^= param.raw(); |
| 1757 Dart_Handle result = LookupInstanceField(object, name, kGetter); | 1811 Dart_Handle result = LookupInstanceField(object, name, kGetter); |
| 1758 if (!::Dart_IsValid(result)) { | 1812 if (::Dart_IsError(result)) { |
| 1759 return result; | 1813 return result; |
| 1760 } | 1814 } |
| 1761 Function& func = Function::Handle(); | 1815 Function& func = Function::Handle(); |
| 1762 func ^= Api::UnwrapHandle(result); | 1816 func ^= Api::UnwrapHandle(result); |
| 1763 GrowableArray<const Object*> arguments; | 1817 GrowableArray<const Object*> arguments; |
| 1764 InvokeDynamic(object, func, arguments, &result); | 1818 InvokeDynamic(object, func, arguments, &result); |
| 1765 if (::Dart_IsValid(result)) { | |
| 1766 if (Dart_ExceptionOccurred(result)) { | |
| 1767 return Api::Error( | |
| 1768 "An exception occurred when accessing the instance field"); | |
| 1769 } | |
| 1770 } | |
| 1771 return result; | 1819 return result; |
| 1772 } | 1820 } |
| 1773 | 1821 |
| 1774 | 1822 |
| 1775 DART_EXPORT Dart_Handle Dart_SetInstanceField(Dart_Handle obj, | 1823 DART_EXPORT Dart_Handle Dart_SetInstanceField(Dart_Handle obj, |
| 1776 Dart_Handle name, | 1824 Dart_Handle name, |
| 1777 Dart_Handle value) { | 1825 Dart_Handle value) { |
| 1778 Zone zone; // Setup a VM zone as we are creating some handles. | 1826 Zone zone; // Setup a VM zone as we are creating some handles. |
| 1779 HandleScope scope; // Setup a VM handle scope. | 1827 HandleScope scope; // Setup a VM handle scope. |
| 1780 const Object& param = Object::Handle(Api::UnwrapHandle(obj)); | 1828 const Object& param = Object::Handle(Api::UnwrapHandle(obj)); |
| 1781 if (param.IsNull() || !param.IsInstance()) { | 1829 if (param.IsNull() || !param.IsInstance()) { |
| 1782 return Api::Error("Invalid object passed in to access instance field"); | 1830 return Api::Error("Invalid object passed in to access instance field"); |
| 1783 } | 1831 } |
| 1784 Instance& object = Instance::Handle(); | 1832 Instance& object = Instance::Handle(); |
| 1785 object ^= param.raw(); | 1833 object ^= param.raw(); |
| 1786 Dart_Handle result = LookupInstanceField(object, name, kSetter); | 1834 Dart_Handle result = LookupInstanceField(object, name, kSetter); |
| 1787 if (!::Dart_IsValid(result)) { | 1835 if (::Dart_IsError(result)) { |
| 1788 return result; | 1836 return result; |
| 1789 } | 1837 } |
| 1790 Function& func = Function::Handle(); | 1838 Function& func = Function::Handle(); |
| 1791 func ^= Api::UnwrapHandle(result); | 1839 func ^= Api::UnwrapHandle(result); |
| 1792 GrowableArray<const Object*> arguments(1); | 1840 GrowableArray<const Object*> arguments(1); |
| 1793 const Object& arg = Object::Handle(Api::UnwrapHandle(value)); | 1841 const Object& arg = Object::Handle(Api::UnwrapHandle(value)); |
| 1794 arguments.Add(&arg); | 1842 arguments.Add(&arg); |
| 1795 InvokeDynamic(object, func, arguments, &result); | 1843 InvokeDynamic(object, func, arguments, &result); |
| 1796 if (::Dart_IsValid(result)) { | |
| 1797 if (Dart_ExceptionOccurred(result)) { | |
| 1798 return Api::Error( | |
| 1799 "An exception occurred when setting the instance field"); | |
| 1800 } | |
| 1801 } | |
| 1802 return result; | 1844 return result; |
| 1803 } | 1845 } |
| 1804 | 1846 |
| 1805 | 1847 |
| 1806 DART_EXPORT Dart_Handle Dart_CreateNativeWrapperClass(Dart_Handle library, | 1848 DART_EXPORT Dart_Handle Dart_CreateNativeWrapperClass(Dart_Handle library, |
| 1807 Dart_Handle name, | 1849 Dart_Handle name, |
| 1808 int field_count) { | 1850 int field_count) { |
| 1809 Zone zone; // Setup a VM zone as we are creating some handles. | 1851 Zone zone; // Setup a VM zone as we are creating some handles. |
| 1810 HandleScope scope; // Setup a VM handle scope. | 1852 HandleScope scope; // Setup a VM handle scope. |
| 1811 const Object& param = Object::Handle(Api::UnwrapHandle(name)); | 1853 const Object& param = Object::Handle(Api::UnwrapHandle(name)); |
| (...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2027 | 2069 |
| 2028 Dart_Handle Api::VError(const char* format, va_list args) { | 2070 Dart_Handle Api::VError(const char* format, va_list args) { |
| 2029 Zone zone; // Setup a VM zone as we are creating some handles. | 2071 Zone zone; // Setup a VM zone as we are creating some handles. |
| 2030 HandleScope scope; // Setup a VM handle scope. | 2072 HandleScope scope; // Setup a VM handle scope. |
| 2031 | 2073 |
| 2032 intptr_t len = OS::VSNPrint(NULL, 0, format, args); | 2074 intptr_t len = OS::VSNPrint(NULL, 0, format, args); |
| 2033 char* buffer = reinterpret_cast<char*>(zone.Allocate(len + 1)); | 2075 char* buffer = reinterpret_cast<char*>(zone.Allocate(len + 1)); |
| 2034 OS::VSNPrint(buffer, (len + 1), format, args); | 2076 OS::VSNPrint(buffer, (len + 1), format, args); |
| 2035 | 2077 |
| 2036 const String& message = String::Handle(String::New(buffer)); | 2078 const String& message = String::Handle(String::New(buffer)); |
| 2037 const Object& obj = Object::Handle(ApiFailure::New(message)); | 2079 const Object& obj = Object::Handle(ApiError::New(message)); |
| 2038 return Api::NewLocalHandle(obj); | 2080 return Api::NewLocalHandle(obj); |
| 2039 } | 2081 } |
| 2040 | 2082 |
| 2041 | 2083 |
| 2042 Dart_Handle Api::Error(const char* format, ...) { | 2084 Dart_Handle Api::Error(const char* format, ...) { |
| 2043 va_list args; | 2085 va_list args; |
| 2044 va_start(args, format); | 2086 va_start(args, format); |
| 2045 Dart_Handle error = Api::VError(format, args); | 2087 Dart_Handle error = Api::VError(format, args); |
| 2046 va_end(args); | 2088 va_end(args); |
| 2047 return error; | 2089 return error; |
| 2048 } | 2090 } |
| 2049 | 2091 |
| 2050 | 2092 |
| 2093 Dart_Handle Api::ErrorFromException(const Object& obj) { | |
| 2094 Zone zone; // Setup a VM zone as we are creating some handles. | |
| 2095 HandleScope scope; // Setup a VM handle scope. | |
| 2096 | |
| 2097 ASSERT(obj.IsUnhandledException()); | |
| 2098 if (obj.IsUnhandledException()) { | |
| 2099 UnhandledException& uhe = UnhandledException::Handle(); | |
| 2100 uhe ^= obj.raw(); | |
| 2101 const Object& error = Object::Handle(ApiError::New(uhe)); | |
| 2102 return Api::NewLocalHandle(error); | |
| 2103 } else { | |
| 2104 return Api::Error("Internal error: expected obj.IsUnhandledException()."); | |
| 2105 } | |
| 2106 } | |
| 2107 | |
| 2108 | |
| 2051 Dart_Handle Api::Null() { | 2109 Dart_Handle Api::Null() { |
| 2052 Isolate* isolate = Isolate::Current(); | 2110 Isolate* isolate = Isolate::Current(); |
| 2053 ASSERT(isolate != NULL); | 2111 ASSERT(isolate != NULL); |
| 2054 ApiState* state = isolate->api_state(); | 2112 ApiState* state = isolate->api_state(); |
| 2055 ASSERT(state != NULL); | 2113 ASSERT(state != NULL); |
| 2056 PersistentHandle* null_handle = state->Null(); | 2114 PersistentHandle* null_handle = state->Null(); |
| 2057 return reinterpret_cast<Dart_Handle>(null_handle); | 2115 return reinterpret_cast<Dart_Handle>(null_handle); |
| 2058 } | 2116 } |
| 2059 | 2117 |
| 2060 | 2118 |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2094 ASSERT(isolate != NULL); | 2152 ASSERT(isolate != NULL); |
| 2095 ApiState* state = isolate->api_state(); | 2153 ApiState* state = isolate->api_state(); |
| 2096 ASSERT(state != NULL); | 2154 ASSERT(state != NULL); |
| 2097 ApiLocalScope* scope = state->top_scope(); | 2155 ApiLocalScope* scope = state->top_scope(); |
| 2098 ASSERT(scope != NULL); | 2156 ASSERT(scope != NULL); |
| 2099 return scope->zone().Reallocate(ptr, old_size, new_size); | 2157 return scope->zone().Reallocate(ptr, old_size, new_size); |
| 2100 } | 2158 } |
| 2101 | 2159 |
| 2102 | 2160 |
| 2103 } // namespace dart | 2161 } // namespace dart |
| OLD | NEW |