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