| 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" |
| (...skipping 27 matching lines...) Expand all Loading... |
| 38 #define CURRENT_FUNC CanonicalFunction(__FUNCTION__) | 38 #define CURRENT_FUNC CanonicalFunction(__FUNCTION__) |
| 39 | 39 |
| 40 #define UNWRAP_NONNULL(dart_handle, vm_handle, Type) \ | 40 #define UNWRAP_NONNULL(dart_handle, vm_handle, Type) \ |
| 41 do { \ | 41 do { \ |
| 42 const Object& tmp = Object::Handle(Api::UnwrapHandle((dart_handle))); \ | 42 const Object& tmp = Object::Handle(Api::UnwrapHandle((dart_handle))); \ |
| 43 if (tmp.Is##Type()) { \ | 43 if (tmp.Is##Type()) { \ |
| 44 (vm_handle) ^= tmp.raw(); \ | 44 (vm_handle) ^= tmp.raw(); \ |
| 45 } else if (tmp.IsNull()) { \ | 45 } else if (tmp.IsNull()) { \ |
| 46 return Api::Error("%s expects argument '%s' to be non-null.", \ | 46 return Api::Error("%s expects argument '%s' to be non-null.", \ |
| 47 CURRENT_FUNC, #dart_handle); \ | 47 CURRENT_FUNC, #dart_handle); \ |
| 48 } else if (tmp.IsApiFailure()) { \ | 48 } else if (tmp.IsApiError()) { \ |
| 49 return dart_handle; \ | 49 return dart_handle; \ |
| 50 } else { \ | 50 } else { \ |
| 51 return Api::Error("%s expects argument '%s' to be of type %s.", \ | 51 return Api::Error("%s expects argument '%s' to be of type %s.", \ |
| 52 CURRENT_FUNC, #dart_handle, #Type); \ | 52 CURRENT_FUNC, #dart_handle, #Type); \ |
| 53 } \ | 53 } \ |
| 54 } while (0) | 54 } while (0) |
| 55 | 55 |
| 56 | 56 |
| 57 DART_EXPORT bool Dart_IsValid(const Dart_Handle& handle) { | 57 DART_EXPORT bool Dart_IsError(const Dart_Handle& handle) { |
| 58 ASSERT(Isolate::Current() != NULL); | 58 ASSERT(Isolate::Current() != NULL); |
| 59 Zone zone; // Setup a VM zone as we are creating some handles. | 59 Zone zone; // Setup a VM zone as we are creating some handles. |
| 60 HandleScope scope; // Setup a VM handle scope. | 60 HandleScope scope; // Setup a VM handle scope. |
| 61 | |
| 62 // Make sure that the object isn't an ApiFailure. | |
| 63 const Object& obj = Object::Handle(Api::UnwrapHandle(handle)); | 61 const Object& obj = Object::Handle(Api::UnwrapHandle(handle)); |
| 64 return !obj.IsApiFailure(); | 62 return obj.IsApiError(); |
| 65 } | 63 } |
| 66 | 64 |
| 67 | 65 |
| 68 DART_EXPORT void _Dart_ReportInvalidHandle(const char* file, | 66 DART_EXPORT bool Dart_ErrorHasException(Dart_Handle handle) { |
| 67 Zone zone; // Setup a VM zone as we are creating some handles. |
| 68 HandleScope scope; // Setup a VM handle scope. |
| 69 const Object& obj = Object::Handle(Api::UnwrapHandle(handle)); |
| 70 if (obj.IsApiError()) { |
| 71 const ApiError& error = ApiError::CheckedHandle(obj.raw()); |
| 72 const Object& data = Object::Handle(error.data()); |
| 73 return data.IsUnhandledException(); |
| 74 } |
| 75 return false; |
| 76 } |
| 77 |
| 78 |
| 79 DART_EXPORT Dart_Handle Dart_ErrorGetException(Dart_Handle handle) { |
| 80 Zone zone; // Setup a VM zone as we are creating some handles. |
| 81 HandleScope scope; // Setup a VM handle scope. |
| 82 const Object& obj = Object::Handle(Api::UnwrapHandle(handle)); |
| 83 if (obj.IsApiError()) { |
| 84 const ApiError& error = ApiError::CheckedHandle(obj.raw()); |
| 85 const Object& data = Object::Handle(error.data()); |
| 86 if (data.IsUnhandledException()) { |
| 87 const UnhandledException& unhandled = UnhandledException::Handle( |
| 88 reinterpret_cast<RawUnhandledException*>(data.raw())); |
| 89 const Object& exception = Object::Handle(unhandled.exception()); |
| 90 return Api::NewLocalHandle(exception); |
| 91 } else { |
| 92 return Api::Error("This error is not an unhandled exception error."); |
| 93 } |
| 94 } else { |
| 95 return Api::Error("Can only get exceptions from error handles."); |
| 96 } |
| 97 } |
| 98 |
| 99 |
| 100 DART_EXPORT Dart_Handle Dart_ErrorGetStacktrace(Dart_Handle handle) { |
| 101 Zone zone; // Setup a VM zone as we are creating some handles. |
| 102 HandleScope scope; // Setup a VM handle scope. |
| 103 const Object& obj = Object::Handle(Api::UnwrapHandle(handle)); |
| 104 if (obj.IsApiError()) { |
| 105 ApiError& failure = ApiError::Handle(); |
| 106 failure ^= obj.raw(); |
| 107 const Object& data = Object::Handle(failure.data()); |
| 108 if (data.IsUnhandledException()) { |
| 109 const UnhandledException& unhandled = UnhandledException::Handle( |
| 110 reinterpret_cast<RawUnhandledException*>(data.raw())); |
| 111 const Object& stacktrace = Object::Handle(unhandled.stacktrace()); |
| 112 return Api::NewLocalHandle(stacktrace); |
| 113 } else { |
| 114 return Api::Error("This error is not an unhandled exception error."); |
| 115 } |
| 116 } else { |
| 117 return Api::Error("Can only get stacktraces from error handles."); |
| 118 } |
| 119 } |
| 120 |
| 121 |
| 122 DART_EXPORT void _Dart_ReportErrorHandle(const char* file, |
| 69 int line, | 123 int line, |
| 70 const char* handle, | 124 const char* handle, |
| 71 const char* message) { | 125 const char* message) { |
| 72 fprintf(stderr, "%s:%d: invalid handle: '%s':\n '%s'\n", | 126 fprintf(stderr, "%s:%d: error handle: '%s':\n '%s'\n", |
| 73 file, line, handle, message); | 127 file, line, handle, message); |
| 74 OS::Abort(); | 128 OS::Abort(); |
| 75 } | 129 } |
| 76 | 130 |
| 77 | 131 |
| 132 static const char* MakeUnhandledExceptionCString( |
| 133 const UnhandledException& uhe) { |
| 134 const Instance& exception = Instance::Handle(uhe.exception()); |
| 135 Object& strtmp = Object::Handle(DartLibraryCalls::ToString(exception)); |
| 136 const char* exc_str = |
| 137 "<Received exception while converting exception to string>"; |
| 138 if (!strtmp.IsUnhandledException()) { |
| 139 exc_str = strtmp.ToCString(); |
| 140 } |
| 141 |
| 142 const Instance& stack = Instance::Handle(uhe.stacktrace()); |
| 143 strtmp = DartLibraryCalls::ToString(stack); |
| 144 const char* stack_str = |
| 145 "<Received exception while converting stack trace to string>"; |
| 146 if (!strtmp.IsUnhandledException()) { |
| 147 stack_str = strtmp.ToCString(); |
| 148 } |
| 149 |
| 150 const char* format = "Unhandled exception:\n%s\n%s"; |
| 151 int len = (strlen(exc_str) + strlen(stack_str) + strlen(format) |
| 152 - 4 // Two '%s' |
| 153 + 1); // '\0' |
| 154 char* buffer = reinterpret_cast<char*>(Api::Allocate(len)); |
| 155 OS::SNPrint(buffer, len, format, exc_str, stack_str); |
| 156 return buffer; |
| 157 } |
| 158 |
| 159 |
| 78 DART_EXPORT const char* Dart_GetError(const Dart_Handle& handle) { | 160 DART_EXPORT const char* Dart_GetError(const Dart_Handle& handle) { |
| 79 ASSERT(Isolate::Current() != NULL); | 161 ASSERT(Isolate::Current() != NULL); |
| 80 Zone zone; // Setup a VM zone as we are creating some handles. | 162 Zone zone; // Setup a VM zone as we are creating some handles. |
| 81 HandleScope scope; // Setup a VM handle scope. | 163 HandleScope scope; // Setup a VM handle scope. |
| 82 const Object& obj = Object::Handle(Api::UnwrapHandle(handle)); | 164 const Object& obj = Object::Handle(Api::UnwrapHandle(handle)); |
| 83 if (!obj.IsApiFailure()) { | 165 if (!obj.IsApiError()) { |
| 84 return ""; | 166 return ""; |
| 85 } | 167 } |
| 86 ApiFailure& failure = ApiFailure::Handle(); | 168 ApiError& failure = ApiError::Handle(); |
| 87 failure ^= obj.raw(); | 169 failure ^= obj.raw(); |
| 88 const String& message = String::Handle(failure.message()); | 170 const Object& data = Object::Handle(failure.data()); |
| 89 const char* msg = message.ToCString(); | 171 if (data.IsString()) { |
| 90 intptr_t len = strlen(msg) + 1; | 172 // Simple error message. |
| 91 char* msg_copy = reinterpret_cast<char*>(Api::Allocate(len)); | 173 String& message = String::Handle(); |
| 92 OS::SNPrint(msg_copy, len, "%s", msg); | 174 message ^= failure.data(); |
| 93 return msg_copy; | 175 const char* msg = message.ToCString(); |
| 176 intptr_t len = strlen(msg) + 1; |
| 177 char* msg_copy = reinterpret_cast<char*>(Api::Allocate(len)); |
| 178 strncpy(msg_copy, msg, len); |
| 179 return msg_copy; |
| 180 |
| 181 } else if (data.IsUnhandledException()) { |
| 182 UnhandledException& uhe = UnhandledException::Handle(); |
| 183 uhe ^= data.raw(); |
| 184 return MakeUnhandledExceptionCString(uhe); |
| 185 |
| 186 } else { |
| 187 return "<Internal error in Dart_GetError: malformed error handle>"; |
| 188 } |
| 94 } | 189 } |
| 95 | 190 |
| 96 | 191 |
| 97 // TODO(turnidge): This clonse Api::Error. I need to use va_copy to | 192 // TODO(turnidge): This clonse Api::Error. I need to use va_copy to |
| 98 // fix this but not sure if it available on all of our builds. | 193 // fix this but not sure if it available on all of our builds. |
| 99 DART_EXPORT Dart_Handle Dart_Error(const char* format, ...) { | 194 DART_EXPORT Dart_Handle Dart_Error(const char* format, ...) { |
| 100 Zone zone; // Setup a VM zone as we are creating some handles. | 195 Zone zone; // Setup a VM zone as we are creating some handles. |
| 101 HandleScope scope; // Setup a VM handle scope. | 196 HandleScope scope; // Setup a VM handle scope. |
| 102 | 197 |
| 103 va_list args; | 198 va_list args; |
| 104 va_start(args, format); | 199 va_start(args, format); |
| 105 intptr_t len = OS::VSNPrint(NULL, 0, format, args); | 200 intptr_t len = OS::VSNPrint(NULL, 0, format, args); |
| 106 va_end(args); | 201 va_end(args); |
| 107 | 202 |
| 108 char* buffer = reinterpret_cast<char*>(zone.Allocate(len + 1)); | 203 char* buffer = reinterpret_cast<char*>(zone.Allocate(len + 1)); |
| 109 va_list args2; | 204 va_list args2; |
| 110 va_start(args2, format); | 205 va_start(args2, format); |
| 111 OS::VSNPrint(buffer, (len + 1), format, args2); | 206 OS::VSNPrint(buffer, (len + 1), format, args2); |
| 112 va_end(args2); | 207 va_end(args2); |
| 113 | 208 |
| 114 const String& message = String::Handle(String::New(buffer)); | 209 const String& message = String::Handle(String::New(buffer)); |
| 115 const Object& obj = Object::Handle(ApiFailure::New(message)); | 210 const Object& obj = Object::Handle(ApiError::New(message)); |
| 116 return Api::NewLocalHandle(obj); | 211 return Api::NewLocalHandle(obj); |
| 117 } | 212 } |
| 118 | 213 |
| 119 | 214 |
| 120 // TODO(iposva): This is a placeholder for the eventual external Dart API. | 215 // TODO(iposva): This is a placeholder for the eventual external Dart API. |
| 121 DART_EXPORT bool Dart_Initialize(int argc, | 216 DART_EXPORT bool Dart_Initialize(int argc, |
| 122 char** argv, | 217 char** argv, |
| 123 Dart_IsolateInitCallback callback) { | 218 Dart_IsolateInitCallback callback) { |
| 124 return Dart::InitOnce(argc, argv, callback); | 219 return Dart::InitOnce(argc, argv, callback); |
| 125 } | 220 } |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 175 ASSERT(Isolate::Current() != NULL); | 270 ASSERT(Isolate::Current() != NULL); |
| 176 Isolate::SetCurrent(NULL); | 271 Isolate::SetCurrent(NULL); |
| 177 } | 272 } |
| 178 | 273 |
| 179 | 274 |
| 180 static void SetupErrorResult(Dart_Handle* handle) { | 275 static void SetupErrorResult(Dart_Handle* handle) { |
| 181 // Make a copy of the error message as the original message string | 276 // Make a copy of the error message as the original message string |
| 182 // may get deallocated when we return back from the Dart API call. | 277 // may get deallocated when we return back from the Dart API call. |
| 183 const String& error = String::Handle( | 278 const String& error = String::Handle( |
| 184 Isolate::Current()->object_store()->sticky_error()); | 279 Isolate::Current()->object_store()->sticky_error()); |
| 185 const Object& obj = Object::Handle(ApiFailure::New(error)); | 280 const Object& obj = Object::Handle(ApiError::New(error)); |
| 186 *handle = Api::NewLocalHandle(obj); | 281 *handle = Api::NewLocalHandle(obj); |
| 187 } | 282 } |
| 188 | 283 |
| 189 | 284 |
| 190 DART_EXPORT void Dart_SetMessageCallbacks( | 285 DART_EXPORT void Dart_SetMessageCallbacks( |
| 191 Dart_PostMessageCallback post_message_callback, | 286 Dart_PostMessageCallback post_message_callback, |
| 192 Dart_ClosePortCallback close_port_callback) { | 287 Dart_ClosePortCallback close_port_callback) { |
| 193 Isolate* isolate = Isolate::Current(); | 288 Isolate* isolate = Isolate::Current(); |
| 194 ASSERT(isolate != NULL); | 289 ASSERT(isolate != NULL); |
| 195 ASSERT(post_message_callback != NULL); | 290 ASSERT(post_message_callback != NULL); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 206 | 301 |
| 207 // Read object back from the snapshot. | 302 // Read object back from the snapshot. |
| 208 Isolate* isolate = Isolate::Current(); | 303 Isolate* isolate = Isolate::Current(); |
| 209 SnapshotReader reader(snapshot, isolate->heap(), isolate->object_store()); | 304 SnapshotReader reader(snapshot, isolate->heap(), isolate->object_store()); |
| 210 Instance& instance = Instance::Handle(); | 305 Instance& instance = Instance::Handle(); |
| 211 instance ^= reader.ReadObject(); | 306 instance ^= reader.ReadObject(); |
| 212 return instance.raw(); | 307 return instance.raw(); |
| 213 } | 308 } |
| 214 | 309 |
| 215 | 310 |
| 216 static void ProcessUnhandledException(const UnhandledException& uhe) { | 311 DART_EXPORT Dart_Handle Dart_HandleMessage(Dart_Port dest_port, |
| 217 const Instance& exception = Instance::Handle(uhe.exception()); | 312 Dart_Port reply_port, |
| 218 Instance& strtmp = Instance::Handle(DartLibraryCalls::ToString(exception)); | 313 Dart_Message dart_message) { |
| 219 const char* str = strtmp.ToCString(); | |
| 220 fprintf(stderr, "%s\n", str); | |
| 221 const Instance& stack = Instance::Handle(uhe.stacktrace()); | |
| 222 strtmp = DartLibraryCalls::ToString(stack); | |
| 223 str = strtmp.ToCString(); | |
| 224 fprintf(stderr, "%s\n", str); | |
| 225 exit(255); | |
| 226 } | |
| 227 | |
| 228 | |
| 229 DART_EXPORT void Dart_HandleMessage(Dart_Port dest_port, | |
| 230 Dart_Port reply_port, | |
| 231 Dart_Message dart_message) { | |
| 232 Zone zone; // Setup a VM zone as we are creating some handles. | 314 Zone zone; // Setup a VM zone as we are creating some handles. |
| 233 HandleScope scope; // Setup a VM handle scope. | 315 HandleScope scope; // Setup a VM handle scope. |
| 234 const Instance& msg = Instance::Handle(DeserializeMessage(dart_message)); | 316 const Instance& msg = Instance::Handle(DeserializeMessage(dart_message)); |
| 235 const String& class_name = | 317 const String& class_name = |
| 236 String::Handle(String::NewSymbol("ReceivePortImpl")); | 318 String::Handle(String::NewSymbol("ReceivePortImpl")); |
| 237 const String& function_name = | 319 const String& function_name = |
| 238 String::Handle(String::NewSymbol("handleMessage_")); | 320 String::Handle(String::NewSymbol("handleMessage_")); |
| 239 const int kNumArguments = 3; | 321 const int kNumArguments = 3; |
| 240 const Array& kNoArgumentNames = Array::Handle(); | 322 const Array& kNoArgumentNames = Array::Handle(); |
| 241 const Function& function = Function::Handle( | 323 const Function& function = Function::Handle( |
| 242 Resolver::ResolveStatic(Library::Handle(Library::CoreLibrary()), | 324 Resolver::ResolveStatic(Library::Handle(Library::CoreLibrary()), |
| 243 class_name, | 325 class_name, |
| 244 function_name, | 326 function_name, |
| 245 kNumArguments, | 327 kNumArguments, |
| 246 kNoArgumentNames, | 328 kNoArgumentNames, |
| 247 Resolver::kIsQualified)); | 329 Resolver::kIsQualified)); |
| 248 GrowableArray<const Object*> arguments(kNumArguments); | 330 GrowableArray<const Object*> arguments(kNumArguments); |
| 249 arguments.Add(&Integer::Handle(Integer::New(dest_port))); | 331 arguments.Add(&Integer::Handle(Integer::New(dest_port))); |
| 250 arguments.Add(&Integer::Handle(Integer::New(reply_port))); | 332 arguments.Add(&Integer::Handle(Integer::New(reply_port))); |
| 251 arguments.Add(&msg); | 333 arguments.Add(&msg); |
| 252 const Object& result = Object::Handle( | 334 const Object& result = Object::Handle( |
| 253 DartEntry::InvokeStatic(function, arguments, kNoArgumentNames)); | 335 DartEntry::InvokeStatic(function, arguments, kNoArgumentNames)); |
| 254 if (result.IsUnhandledException()) { | 336 if (result.IsUnhandledException()) { |
| 255 UnhandledException& uhe = UnhandledException::Handle(); | 337 return Api::ErrorFromException(result); |
| 256 uhe ^= result.raw(); | |
| 257 // TODO(turnidge): Instead of exiting here, just return the | |
| 258 // exception so that the embedder can choose how to handle this | |
| 259 // case. | |
| 260 ProcessUnhandledException(uhe); | |
| 261 } | 338 } |
| 262 ASSERT(result.IsNull()); | 339 ASSERT(result.IsNull()); |
| 340 return Api::Success(); |
| 263 } | 341 } |
| 264 | 342 |
| 265 | 343 |
| 266 DART_EXPORT Dart_Handle Dart_RunLoop() { | 344 DART_EXPORT Dart_Handle Dart_RunLoop() { |
| 267 Zone zone; // Setup a VM zone as we are creating some handles. | 345 Zone zone; // Setup a VM zone as we are creating some handles. |
| 268 HandleScope scope; // Setup a VM handle scope. | 346 HandleScope scope; // Setup a VM handle scope. |
| 269 | 347 |
| 270 Isolate* isolate = Isolate::Current(); | 348 Isolate* isolate = Isolate::Current(); |
| 271 LongJump* base = isolate->long_jump_base(); | 349 LongJump* base = isolate->long_jump_base(); |
| 272 LongJump jump; | 350 LongJump jump; |
| (...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 484 HandleScope scope; // Setup a VM handle scope. | 562 HandleScope scope; // Setup a VM handle scope. |
| 485 const Object& obj = Object::Handle(Api::UnwrapHandle(object)); | 563 const Object& obj = Object::Handle(Api::UnwrapHandle(object)); |
| 486 Object& result = Object::Handle(); | 564 Object& result = Object::Handle(); |
| 487 if (obj.IsString()) { | 565 if (obj.IsString()) { |
| 488 result = obj.raw(); | 566 result = obj.raw(); |
| 489 } else if (obj.IsInstance()) { | 567 } else if (obj.IsInstance()) { |
| 490 Instance& receiver = Instance::Handle(); | 568 Instance& receiver = Instance::Handle(); |
| 491 receiver ^= obj.raw(); | 569 receiver ^= obj.raw(); |
| 492 result = DartLibraryCalls::ToString(receiver); | 570 result = DartLibraryCalls::ToString(receiver); |
| 493 if (result.IsUnhandledException()) { | 571 if (result.IsUnhandledException()) { |
| 494 return Api::Error("An exception occurred when converting to string"); | 572 return Api::ErrorFromException(result); |
| 495 } | 573 } |
| 496 } else { | 574 } else { |
| 497 // This is a VM internal object. Call the C++ method of printing. | 575 // This is a VM internal object. Call the C++ method of printing. |
| 498 result = String::New(obj.ToCString()); | 576 result = String::New(obj.ToCString()); |
| 499 } | 577 } |
| 500 return Api::NewLocalHandle(result); | 578 return Api::NewLocalHandle(result); |
| 501 } | 579 } |
| 502 | 580 |
| 503 | 581 |
| 504 DART_EXPORT Dart_Handle Dart_Null() { | 582 DART_EXPORT Dart_Handle Dart_Null() { |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 546 HandleScope scope; // Setup a VM handle scope. | 624 HandleScope scope; // Setup a VM handle scope. |
| 547 const Instance& expected = Instance::CheckedHandle(Api::UnwrapHandle(obj1)); | 625 const Instance& expected = Instance::CheckedHandle(Api::UnwrapHandle(obj1)); |
| 548 const Instance& actual = Instance::CheckedHandle(Api::UnwrapHandle(obj2)); | 626 const Instance& actual = Instance::CheckedHandle(Api::UnwrapHandle(obj2)); |
| 549 const Instance& result = | 627 const Instance& result = |
| 550 Instance::Handle(DartLibraryCalls::Equals(expected, actual)); | 628 Instance::Handle(DartLibraryCalls::Equals(expected, actual)); |
| 551 if (result.IsBool()) { | 629 if (result.IsBool()) { |
| 552 Bool& b = Bool::Handle(); | 630 Bool& b = Bool::Handle(); |
| 553 b ^= result.raw(); | 631 b ^= result.raw(); |
| 554 *value = b.value(); | 632 *value = b.value(); |
| 555 return Api::Success(); | 633 return Api::Success(); |
| 634 } else if (result.IsUnhandledException()) { |
| 635 return Api::ErrorFromException(result); |
| 556 } else { | 636 } else { |
| 557 return Api::Error("An exception occured when calling '=='"); | 637 return Api::Error("Expected boolean result from =="); |
| 558 } | 638 } |
| 559 } | 639 } |
| 560 | 640 |
| 561 | 641 |
| 562 DART_EXPORT Dart_Handle Dart_IsSame(Dart_Handle obj1, Dart_Handle obj2, | 642 DART_EXPORT Dart_Handle Dart_IsSame(Dart_Handle obj1, Dart_Handle obj2, |
| 563 bool* value) { | 643 bool* value) { |
| 564 Zone zone; // Setup a VM zone as we are creating some handles. | 644 Zone zone; // Setup a VM zone as we are creating some handles. |
| 565 HandleScope scope; // Setup a VM handle scope. | 645 HandleScope scope; // Setup a VM handle scope. |
| 566 const Object& expected = Object::Handle(Api::UnwrapHandle(obj1)); | 646 const Object& expected = Object::Handle(Api::UnwrapHandle(obj1)); |
| 567 const Object& actual = Object::Handle(Api::UnwrapHandle(obj2)); | 647 const Object& actual = Object::Handle(Api::UnwrapHandle(obj2)); |
| (...skipping 449 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1017 *len = integer.AsInt64Value(); | 1097 *len = integer.AsInt64Value(); |
| 1018 } else if (retval.IsBigint()) { | 1098 } else if (retval.IsBigint()) { |
| 1019 Bigint& bigint = Bigint::Handle(); | 1099 Bigint& bigint = Bigint::Handle(); |
| 1020 bigint ^= retval.raw(); | 1100 bigint ^= retval.raw(); |
| 1021 if (BigintOperations::FitsIntoInt64(bigint)) { | 1101 if (BigintOperations::FitsIntoInt64(bigint)) { |
| 1022 *len = BigintOperations::ToInt64(bigint); | 1102 *len = BigintOperations::ToInt64(bigint); |
| 1023 } else { | 1103 } else { |
| 1024 result = Api::Error("Length of List object is greater than the " | 1104 result = Api::Error("Length of List object is greater than the " |
| 1025 "maximum value that 'len' parameter can hold"); | 1105 "maximum value that 'len' parameter can hold"); |
| 1026 } | 1106 } |
| 1107 } else if (retval.IsUnhandledException()) { |
| 1108 result = Api::ErrorFromException(retval); |
| 1027 } else { | 1109 } else { |
| 1028 result = Api::Error("Length of List object is not an integer"); | 1110 result = Api::Error("Length of List object is not an integer"); |
| 1029 } | 1111 } |
| 1030 } else { | 1112 } else { |
| 1031 SetupErrorResult(&result); | 1113 SetupErrorResult(&result); |
| 1032 } | 1114 } |
| 1033 isolate->set_long_jump_base(base); | 1115 isolate->set_long_jump_base(base); |
| 1034 return result; | 1116 return result; |
| 1035 } | 1117 } |
| 1036 } | 1118 } |
| (...skipping 14 matching lines...) Expand all Loading... |
| 1051 if (setjmp(*jump.Set()) == 0) { | 1133 if (setjmp(*jump.Set()) == 0) { |
| 1052 Instance& retval = Instance::Handle(); | 1134 Instance& retval = Instance::Handle(); |
| 1053 GrowableArray<const Object*> args(0); | 1135 GrowableArray<const Object*> args(0); |
| 1054 args.Add(&index); | 1136 args.Add(&index); |
| 1055 const Array& kNoArgumentNames = Array::Handle(); | 1137 const Array& kNoArgumentNames = Array::Handle(); |
| 1056 retval = DartEntry::InvokeDynamic(instance, | 1138 retval = DartEntry::InvokeDynamic(instance, |
| 1057 function, | 1139 function, |
| 1058 args, | 1140 args, |
| 1059 kNoArgumentNames); | 1141 kNoArgumentNames); |
| 1060 if (retval.IsUnhandledException()) { | 1142 if (retval.IsUnhandledException()) { |
| 1061 *result = Api::Error("Unexpected exception in '[]'"); | 1143 *result = Api::ErrorFromException(retval); |
| 1062 } else { | 1144 } else { |
| 1063 *result = Api::Success(); | 1145 *result = Api::Success(); |
| 1064 } | 1146 } |
| 1065 isolate->set_long_jump_base(base); | 1147 isolate->set_long_jump_base(base); |
| 1066 return retval.raw(); | 1148 return retval.raw(); |
| 1067 } | 1149 } |
| 1068 SetupErrorResult(result); | 1150 SetupErrorResult(result); |
| 1069 isolate->set_long_jump_base(base); | 1151 isolate->set_long_jump_base(base); |
| 1070 return Object::null(); | 1152 return Object::null(); |
| 1071 } | 1153 } |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1104 String& name = String::Handle(String::New("[]")); | 1186 String& name = String::Handle(String::New("[]")); |
| 1105 const Function& function = Function::Handle( | 1187 const Function& function = Function::Handle( |
| 1106 Resolver::ResolveDynamic(instance, name, 2, 0)); | 1188 Resolver::ResolveDynamic(instance, name, 2, 0)); |
| 1107 if (!function.IsNull()) { | 1189 if (!function.IsNull()) { |
| 1108 Object& element = Object::Handle(); | 1190 Object& element = Object::Handle(); |
| 1109 Integer& intobj = Integer::Handle(); | 1191 Integer& intobj = Integer::Handle(); |
| 1110 Dart_Handle result; | 1192 Dart_Handle result; |
| 1111 for (int i = 0; i < length; i++) { | 1193 for (int i = 0; i < length; i++) { |
| 1112 intobj = Integer::New(offset + i); | 1194 intobj = Integer::New(offset + i); |
| 1113 element = GetListAt(isolate, instance, intobj, function, &result); | 1195 element = GetListAt(isolate, instance, intobj, 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 intobj ^= element.raw(); | 1199 intobj ^= element.raw(); |
| 1118 ASSERT(intobj.AsInt64Value() <= 0xff); | 1200 ASSERT(intobj.AsInt64Value() <= 0xff); |
| 1119 // TODO(hpayer): value should always be smaller then 0xff. Add error | 1201 // TODO(hpayer): value should always be smaller then 0xff. Add error |
| 1120 // handling. | 1202 // handling. |
| 1121 native_array[i] = static_cast<uint8_t>(intobj.AsInt64Value() & 0xff); | 1203 native_array[i] = static_cast<uint8_t>(intobj.AsInt64Value() & 0xff); |
| 1122 } | 1204 } |
| 1123 return Api::Success(); | 1205 return Api::Success(); |
| 1124 } | 1206 } |
| (...skipping 22 matching lines...) Expand all Loading... |
| 1147 if (!instance.IsNull()) { | 1229 if (!instance.IsNull()) { |
| 1148 String& name = String::Handle(String::New("[]")); | 1230 String& name = String::Handle(String::New("[]")); |
| 1149 const Function& function = Function::Handle( | 1231 const Function& function = Function::Handle( |
| 1150 Resolver::ResolveDynamic(instance, name, 2, 0)); | 1232 Resolver::ResolveDynamic(instance, name, 2, 0)); |
| 1151 if (!function.IsNull()) { | 1233 if (!function.IsNull()) { |
| 1152 Object& element = Object::Handle(); | 1234 Object& element = Object::Handle(); |
| 1153 Integer& indexobj = Integer::Handle(); | 1235 Integer& indexobj = Integer::Handle(); |
| 1154 Dart_Handle result; | 1236 Dart_Handle result; |
| 1155 indexobj = Integer::New(index); | 1237 indexobj = Integer::New(index); |
| 1156 element = GetListAt(isolate, instance, indexobj, function, &result); | 1238 element = GetListAt(isolate, instance, indexobj, function, &result); |
| 1157 if (!Dart_IsValid(result)) { | 1239 if (Dart_IsError(result)) { |
| 1158 return result; // Error condition. | 1240 return result; // Error condition. |
| 1159 } | 1241 } |
| 1160 return Api::NewLocalHandle(element); | 1242 return Api::NewLocalHandle(element); |
| 1161 } | 1243 } |
| 1162 } | 1244 } |
| 1163 return Api::Error("Object does not implement the 'List' interface"); | 1245 return Api::Error("Object does not implement the 'List' interface"); |
| 1164 } | 1246 } |
| 1165 | 1247 |
| 1166 | 1248 |
| 1167 static void SetListAt(Isolate* isolate, | 1249 static void SetListAt(Isolate* isolate, |
| (...skipping 11 matching lines...) Expand all Loading... |
| 1179 GrowableArray<const Object*> args(1); | 1261 GrowableArray<const Object*> args(1); |
| 1180 args.Add(&index); | 1262 args.Add(&index); |
| 1181 args.Add(&value); | 1263 args.Add(&value); |
| 1182 Instance& retval = Instance::Handle(); | 1264 Instance& retval = Instance::Handle(); |
| 1183 const Array& kNoArgumentNames = Array::Handle(); | 1265 const Array& kNoArgumentNames = Array::Handle(); |
| 1184 retval = DartEntry::InvokeDynamic(instance, | 1266 retval = DartEntry::InvokeDynamic(instance, |
| 1185 function, | 1267 function, |
| 1186 args, | 1268 args, |
| 1187 kNoArgumentNames); | 1269 kNoArgumentNames); |
| 1188 if (retval.IsUnhandledException()) { | 1270 if (retval.IsUnhandledException()) { |
| 1189 *result = Api::Error("Unexpected exception in '[]='"); | 1271 *result = Api::ErrorFromException(retval); |
| 1190 } else { | 1272 } else { |
| 1191 *result = Api::Success(); | 1273 *result = Api::Success(); |
| 1192 } | 1274 } |
| 1193 } else { | 1275 } else { |
| 1194 SetupErrorResult(result); | 1276 SetupErrorResult(result); |
| 1195 } | 1277 } |
| 1196 isolate->set_long_jump_base(base); | 1278 isolate->set_long_jump_base(base); |
| 1197 } | 1279 } |
| 1198 | 1280 |
| 1199 | 1281 |
| (...skipping 26 matching lines...) Expand all Loading... |
| 1226 const Function& function = Function::Handle( | 1308 const Function& function = Function::Handle( |
| 1227 Resolver::ResolveDynamic(instance, name, 3, 0)); | 1309 Resolver::ResolveDynamic(instance, name, 3, 0)); |
| 1228 if (!function.IsNull()) { | 1310 if (!function.IsNull()) { |
| 1229 Integer& indexobj = Integer::Handle(); | 1311 Integer& indexobj = Integer::Handle(); |
| 1230 Integer& valueobj = Integer::Handle(); | 1312 Integer& valueobj = Integer::Handle(); |
| 1231 Dart_Handle result; | 1313 Dart_Handle result; |
| 1232 for (int i = 0; i < length; i++) { | 1314 for (int i = 0; i < length; i++) { |
| 1233 indexobj = Integer::New(offset + i); | 1315 indexobj = Integer::New(offset + i); |
| 1234 valueobj ^= Integer::New(native_array[i]); | 1316 valueobj ^= Integer::New(native_array[i]); |
| 1235 SetListAt(isolate, instance, indexobj, valueobj, function, &result); | 1317 SetListAt(isolate, instance, indexobj, valueobj, function, &result); |
| 1236 if (!Dart_IsValid(result)) { | 1318 if (Dart_IsError(result)) { |
| 1237 return result; // Error condition. | 1319 return result; // Error condition. |
| 1238 } | 1320 } |
| 1239 } | 1321 } |
| 1240 return Api::Success(); | 1322 return Api::Success(); |
| 1241 } | 1323 } |
| 1242 } | 1324 } |
| 1243 return Api::Error("Object does not implement the 'List' interface"); | 1325 return Api::Error("Object does not implement the 'List' interface"); |
| 1244 } | 1326 } |
| 1245 | 1327 |
| 1246 | 1328 |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1288 Dart_Handle* result) { | 1370 Dart_Handle* result) { |
| 1289 Isolate* isolate = Isolate::Current(); | 1371 Isolate* isolate = Isolate::Current(); |
| 1290 ASSERT(isolate != NULL); | 1372 ASSERT(isolate != NULL); |
| 1291 LongJump* base = isolate->long_jump_base(); | 1373 LongJump* base = isolate->long_jump_base(); |
| 1292 LongJump jump; | 1374 LongJump jump; |
| 1293 isolate->set_long_jump_base(&jump); | 1375 isolate->set_long_jump_base(&jump); |
| 1294 if (setjmp(*jump.Set()) == 0) { | 1376 if (setjmp(*jump.Set()) == 0) { |
| 1295 const Array& kNoArgumentNames = Array::Handle(); | 1377 const Array& kNoArgumentNames = Array::Handle(); |
| 1296 const Instance& retval = Instance::Handle( | 1378 const Instance& retval = Instance::Handle( |
| 1297 DartEntry::InvokeStatic(function, args, kNoArgumentNames)); | 1379 DartEntry::InvokeStatic(function, args, kNoArgumentNames)); |
| 1298 *result = Api::NewLocalHandle(retval); | 1380 if (retval.IsUnhandledException()) { |
| 1381 *result = Api::ErrorFromException(retval); |
| 1382 } else { |
| 1383 *result = Api::NewLocalHandle(retval); |
| 1384 } |
| 1299 } else { | 1385 } else { |
| 1300 SetupErrorResult(result); | 1386 SetupErrorResult(result); |
| 1301 } | 1387 } |
| 1302 isolate->set_long_jump_base(base); | 1388 isolate->set_long_jump_base(base); |
| 1303 } | 1389 } |
| 1304 | 1390 |
| 1305 | 1391 |
| 1306 // NOTE: Need to pass 'result' as a parameter here in order to avoid | 1392 // NOTE: Need to pass 'result' as a parameter here in order to avoid |
| 1307 // warning: variable 'result' might be clobbered by 'longjmp' or 'vfork' | 1393 // warning: variable 'result' might be clobbered by 'longjmp' or 'vfork' |
| 1308 // which shows up because of the use of setjmp. | 1394 // which shows up because of the use of setjmp. |
| 1309 static void InvokeDynamic(const Instance& receiver, | 1395 static void InvokeDynamic(const Instance& receiver, |
| 1310 const Function& function, | 1396 const Function& function, |
| 1311 GrowableArray<const Object*>& args, | 1397 GrowableArray<const Object*>& args, |
| 1312 Dart_Handle* result) { | 1398 Dart_Handle* result) { |
| 1313 Isolate* isolate = Isolate::Current(); | 1399 Isolate* isolate = Isolate::Current(); |
| 1314 ASSERT(isolate != NULL); | 1400 ASSERT(isolate != NULL); |
| 1315 LongJump* base = isolate->long_jump_base(); | 1401 LongJump* base = isolate->long_jump_base(); |
| 1316 LongJump jump; | 1402 LongJump jump; |
| 1317 isolate->set_long_jump_base(&jump); | 1403 isolate->set_long_jump_base(&jump); |
| 1318 if (setjmp(*jump.Set()) == 0) { | 1404 if (setjmp(*jump.Set()) == 0) { |
| 1319 const Array& kNoArgumentNames = Array::Handle(); | 1405 const Array& kNoArgumentNames = Array::Handle(); |
| 1320 const Instance& retval = Instance::Handle( | 1406 const Instance& retval = Instance::Handle( |
| 1321 DartEntry::InvokeDynamic(receiver, function, args, kNoArgumentNames)); | 1407 DartEntry::InvokeDynamic(receiver, function, args, kNoArgumentNames)); |
| 1322 *result = Api::NewLocalHandle(retval); | 1408 if (retval.IsUnhandledException()) { |
| 1409 *result = Api::ErrorFromException(retval); |
| 1410 } else { |
| 1411 *result = Api::NewLocalHandle(retval); |
| 1412 } |
| 1323 } else { | 1413 } else { |
| 1324 SetupErrorResult(result); | 1414 SetupErrorResult(result); |
| 1325 } | 1415 } |
| 1326 isolate->set_long_jump_base(base); | 1416 isolate->set_long_jump_base(base); |
| 1327 } | 1417 } |
| 1328 | 1418 |
| 1329 | 1419 |
| 1330 // NOTE: Need to pass 'result' as a parameter here in order to avoid | 1420 // NOTE: Need to pass 'result' as a parameter here in order to avoid |
| 1331 // warning: variable 'result' might be clobbered by 'longjmp' or 'vfork' | 1421 // warning: variable 'result' might be clobbered by 'longjmp' or 'vfork' |
| 1332 // which shows up because of the use of setjmp. | 1422 // which shows up because of the use of setjmp. |
| 1333 static void InvokeClosure(const Closure& closure, | 1423 static void InvokeClosure(const Closure& closure, |
| 1334 GrowableArray<const Object*>& args, | 1424 GrowableArray<const Object*>& args, |
| 1335 Dart_Handle* result) { | 1425 Dart_Handle* result) { |
| 1336 Isolate* isolate = Isolate::Current(); | 1426 Isolate* isolate = Isolate::Current(); |
| 1337 ASSERT(isolate != NULL); | 1427 ASSERT(isolate != NULL); |
| 1338 LongJump* base = isolate->long_jump_base(); | 1428 LongJump* base = isolate->long_jump_base(); |
| 1339 LongJump jump; | 1429 LongJump jump; |
| 1340 isolate->set_long_jump_base(&jump); | 1430 isolate->set_long_jump_base(&jump); |
| 1341 if (setjmp(*jump.Set()) == 0) { | 1431 if (setjmp(*jump.Set()) == 0) { |
| 1342 const Array& kNoArgumentNames = Array::Handle(); | 1432 const Array& kNoArgumentNames = Array::Handle(); |
| 1343 const Instance& retval = Instance::Handle( | 1433 const Instance& retval = Instance::Handle( |
| 1344 DartEntry::InvokeClosure(closure, args, kNoArgumentNames)); | 1434 DartEntry::InvokeClosure(closure, args, kNoArgumentNames)); |
| 1345 *result = Api::NewLocalHandle(retval); | 1435 if (retval.IsUnhandledException()) { |
| 1436 *result = Api::ErrorFromException(retval); |
| 1437 } else { |
| 1438 *result = Api::NewLocalHandle(retval); |
| 1439 } |
| 1346 } else { | 1440 } else { |
| 1347 SetupErrorResult(result); | 1441 SetupErrorResult(result); |
| 1348 } | 1442 } |
| 1349 isolate->set_long_jump_base(base); | 1443 isolate->set_long_jump_base(base); |
| 1350 } | 1444 } |
| 1351 | 1445 |
| 1352 | 1446 |
| 1353 DART_EXPORT Dart_Handle Dart_InvokeStatic(Dart_Handle library_in, | 1447 DART_EXPORT Dart_Handle Dart_InvokeStatic(Dart_Handle library_in, |
| 1354 Dart_Handle class_name_in, | 1448 Dart_Handle class_name_in, |
| 1355 Dart_Handle function_name_in, | 1449 Dart_Handle function_name_in, |
| (...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1499 | 1593 |
| 1500 DART_EXPORT void Dart_SetReturnValue(Dart_NativeArguments args, | 1594 DART_EXPORT void Dart_SetReturnValue(Dart_NativeArguments args, |
| 1501 Dart_Handle retval) { | 1595 Dart_Handle retval) { |
| 1502 Zone zone; // Setup a VM zone as we are creating some handles. | 1596 Zone zone; // Setup a VM zone as we are creating some handles. |
| 1503 HandleScope scope; // Setup a VM handle scope. | 1597 HandleScope scope; // Setup a VM handle scope. |
| 1504 NativeArguments* arguments = reinterpret_cast<NativeArguments*>(args); | 1598 NativeArguments* arguments = reinterpret_cast<NativeArguments*>(args); |
| 1505 arguments->SetReturn(Object::Handle(Api::UnwrapHandle(retval))); | 1599 arguments->SetReturn(Object::Handle(Api::UnwrapHandle(retval))); |
| 1506 } | 1600 } |
| 1507 | 1601 |
| 1508 | 1602 |
| 1509 DART_EXPORT bool Dart_ExceptionOccurred(Dart_Handle result) { | |
| 1510 Zone zone; // Setup a VM zone as we are creating some handles. | |
| 1511 HandleScope scope; // Setup a VM handle scope. | |
| 1512 const Object& retval = Object::Handle(Api::UnwrapHandle(result)); | |
| 1513 return retval.IsUnhandledException(); | |
| 1514 } | |
| 1515 | |
| 1516 | |
| 1517 DART_EXPORT Dart_Handle Dart_GetException(Dart_Handle result) { | |
| 1518 Zone zone; // Setup a VM zone as we are creating some handles. | |
| 1519 HandleScope scope; // Setup a VM handle scope. | |
| 1520 const Object& retval = Object::Handle(Api::UnwrapHandle(result)); | |
| 1521 if (retval.IsUnhandledException()) { | |
| 1522 const UnhandledException& unhandled = UnhandledException::Handle( | |
| 1523 reinterpret_cast<RawUnhandledException*>(retval.raw())); | |
| 1524 const Object& exception = Object::Handle(unhandled.exception()); | |
| 1525 return Api::NewLocalHandle(exception); | |
| 1526 } | |
| 1527 return Api::Error("Object is not an unhandled exception object"); | |
| 1528 } | |
| 1529 | |
| 1530 | |
| 1531 DART_EXPORT Dart_Handle Dart_GetStacktrace(Dart_Handle unhandled_excp) { | |
| 1532 Zone zone; // Setup a VM zone as we are creating some handles. | |
| 1533 HandleScope scope; // Setup a VM handle scope. | |
| 1534 const Object& retval = Object::Handle(Api::UnwrapHandle(unhandled_excp)); | |
| 1535 if (retval.IsUnhandledException()) { | |
| 1536 const UnhandledException& unhandled = UnhandledException::Handle( | |
| 1537 reinterpret_cast<RawUnhandledException*>(retval.raw())); | |
| 1538 const Object& stacktrace = Object::Handle(unhandled.stacktrace()); | |
| 1539 return Api::NewLocalHandle(stacktrace); | |
| 1540 } | |
| 1541 return Api::Error("Object is not an unhandled exception object"); | |
| 1542 } | |
| 1543 | |
| 1544 | |
| 1545 DART_EXPORT Dart_Handle Dart_ThrowException(Dart_Handle exception) { | 1603 DART_EXPORT Dart_Handle Dart_ThrowException(Dart_Handle exception) { |
| 1546 Isolate* isolate = Isolate::Current(); | 1604 Isolate* isolate = Isolate::Current(); |
| 1547 ASSERT(isolate != NULL); | 1605 ASSERT(isolate != NULL); |
| 1548 Zone zone; // Setup a VM zone as we are creating some handles. | 1606 Zone zone; // Setup a VM zone as we are creating some handles. |
| 1549 HandleScope scope; // Setup a VM handle scope. | 1607 HandleScope scope; // Setup a VM handle scope. |
| 1550 if (isolate->top_exit_frame_info() == 0) { | 1608 if (isolate->top_exit_frame_info() == 0) { |
| 1551 // There are no dart frames on the stack so it would be illegal to | 1609 // There are no dart frames on the stack so it would be illegal to |
| 1552 // throw an exception here. | 1610 // throw an exception here. |
| 1553 return Api::Error("No Dart frames on stack, cannot throw exception"); | 1611 return Api::Error("No Dart frames on stack, cannot throw exception"); |
| 1554 } | 1612 } |
| (...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1731 } | 1789 } |
| 1732 return Api::Error("Unable to find field in the class"); | 1790 return Api::Error("Unable to find field in the class"); |
| 1733 } | 1791 } |
| 1734 | 1792 |
| 1735 | 1793 |
| 1736 DART_EXPORT Dart_Handle Dart_GetStaticField(Dart_Handle cls, | 1794 DART_EXPORT Dart_Handle Dart_GetStaticField(Dart_Handle cls, |
| 1737 Dart_Handle name) { | 1795 Dart_Handle name) { |
| 1738 Zone zone; // Setup a VM zone as we are creating some handles. | 1796 Zone zone; // Setup a VM zone as we are creating some handles. |
| 1739 HandleScope scope; // Setup a VM handle scope. | 1797 HandleScope scope; // Setup a VM handle scope. |
| 1740 Dart_Handle result = LookupStaticField(cls, name, kGetter); | 1798 Dart_Handle result = LookupStaticField(cls, name, kGetter); |
| 1741 if (!::Dart_IsValid(result)) { | 1799 if (::Dart_IsError(result)) { |
| 1742 return result; | 1800 return result; |
| 1743 } | 1801 } |
| 1744 Object& retval = Object::Handle(); | 1802 Object& retval = Object::Handle(); |
| 1745 const Object& obj = Object::Handle(Api::UnwrapHandle(result)); | 1803 const Object& obj = Object::Handle(Api::UnwrapHandle(result)); |
| 1746 if (obj.IsField()) { | 1804 if (obj.IsField()) { |
| 1747 Field& fld = Field::Handle(); | 1805 Field& fld = Field::Handle(); |
| 1748 fld ^= obj.raw(); | 1806 fld ^= obj.raw(); |
| 1749 retval = fld.value(); | 1807 retval = fld.value(); |
| 1750 return Api::NewLocalHandle(retval); | 1808 return Api::NewLocalHandle(retval); |
| 1751 } else { | 1809 } else { |
| 1752 Function& func = Function::Handle(); | 1810 Function& func = Function::Handle(); |
| 1753 func ^= obj.raw(); | 1811 func ^= obj.raw(); |
| 1754 GrowableArray<const Object*> args; | 1812 GrowableArray<const Object*> args; |
| 1755 InvokeStatic(func, args, &result); | 1813 InvokeStatic(func, args, &result); |
| 1756 if (::Dart_IsValid(result)) { | |
| 1757 if (Dart_ExceptionOccurred(result)) { | |
| 1758 return Api::Error( | |
| 1759 "An exception occurred when getting the static field"); | |
| 1760 } | |
| 1761 } | |
| 1762 return result; | 1814 return result; |
| 1763 } | 1815 } |
| 1764 } | 1816 } |
| 1765 | 1817 |
| 1766 | 1818 |
| 1767 // TODO(iposva): The value parameter should be documented as being an instance. | 1819 // TODO(iposva): The value parameter should be documented as being an instance. |
| 1820 // TODO(turnidge): Is this skipping the setter? |
| 1768 DART_EXPORT Dart_Handle Dart_SetStaticField(Dart_Handle cls, | 1821 DART_EXPORT Dart_Handle Dart_SetStaticField(Dart_Handle cls, |
| 1769 Dart_Handle name, | 1822 Dart_Handle name, |
| 1770 Dart_Handle value) { | 1823 Dart_Handle value) { |
| 1771 Zone zone; // Setup a VM zone as we are creating some handles. | 1824 Zone zone; // Setup a VM zone as we are creating some handles. |
| 1772 HandleScope scope; // Setup a VM handle scope. | 1825 HandleScope scope; // Setup a VM handle scope. |
| 1773 Dart_Handle result = LookupStaticField(cls, name, kSetter); | 1826 Dart_Handle result = LookupStaticField(cls, name, kSetter); |
| 1774 if (!::Dart_IsValid(result)) { | 1827 if (::Dart_IsError(result)) { |
| 1775 return result; | 1828 return result; |
| 1776 } | 1829 } |
| 1777 Field& fld = Field::Handle(); | 1830 Field& fld = Field::Handle(); |
| 1778 fld ^= Api::UnwrapHandle(result); | 1831 fld ^= Api::UnwrapHandle(result); |
| 1779 if (fld.is_final()) { | 1832 if (fld.is_final()) { |
| 1780 return Api::Error("Specified field is a static final field in the class"); | 1833 return Api::Error("Specified field is a static final field in the class"); |
| 1781 } | 1834 } |
| 1782 const Object& val = Object::Handle(Api::UnwrapHandle(value)); | 1835 const Object& val = Object::Handle(Api::UnwrapHandle(value)); |
| 1783 Instance& instance = Instance::Handle(); | 1836 Instance& instance = Instance::Handle(); |
| 1784 instance ^= val.raw(); | 1837 instance ^= val.raw(); |
| 1785 fld.set_value(instance); | 1838 fld.set_value(instance); |
| 1786 return Api::NewLocalHandle(val); | 1839 return Api::NewLocalHandle(val); |
| 1787 } | 1840 } |
| 1788 | 1841 |
| 1789 | 1842 |
| 1790 DART_EXPORT Dart_Handle Dart_GetInstanceField(Dart_Handle obj, | 1843 DART_EXPORT Dart_Handle Dart_GetInstanceField(Dart_Handle obj, |
| 1791 Dart_Handle name) { | 1844 Dart_Handle name) { |
| 1792 Zone zone; // Setup a VM zone as we are creating some handles. | 1845 Zone zone; // Setup a VM zone as we are creating some handles. |
| 1793 HandleScope scope; // Setup a VM handle scope. | 1846 HandleScope scope; // Setup a VM handle scope. |
| 1794 const Object& param = Object::Handle(Api::UnwrapHandle(obj)); | 1847 const Object& param = Object::Handle(Api::UnwrapHandle(obj)); |
| 1795 if (param.IsNull() || !param.IsInstance()) { | 1848 if (param.IsNull() || !param.IsInstance()) { |
| 1796 return Api::Error("Invalid object passed in to access instance field"); | 1849 return Api::Error("Invalid object passed in to access instance field"); |
| 1797 } | 1850 } |
| 1798 Instance& object = Instance::Handle(); | 1851 Instance& object = Instance::Handle(); |
| 1799 object ^= param.raw(); | 1852 object ^= param.raw(); |
| 1800 Dart_Handle result = LookupInstanceField(object, name, kGetter); | 1853 Dart_Handle result = LookupInstanceField(object, name, kGetter); |
| 1801 if (!::Dart_IsValid(result)) { | 1854 if (::Dart_IsError(result)) { |
| 1802 return result; | 1855 return result; |
| 1803 } | 1856 } |
| 1804 Function& func = Function::Handle(); | 1857 Function& func = Function::Handle(); |
| 1805 func ^= Api::UnwrapHandle(result); | 1858 func ^= Api::UnwrapHandle(result); |
| 1806 GrowableArray<const Object*> arguments; | 1859 GrowableArray<const Object*> arguments; |
| 1807 InvokeDynamic(object, func, arguments, &result); | 1860 InvokeDynamic(object, func, arguments, &result); |
| 1808 if (::Dart_IsValid(result)) { | |
| 1809 if (Dart_ExceptionOccurred(result)) { | |
| 1810 return Api::Error( | |
| 1811 "An exception occurred when accessing the instance field"); | |
| 1812 } | |
| 1813 } | |
| 1814 return result; | 1861 return result; |
| 1815 } | 1862 } |
| 1816 | 1863 |
| 1817 | 1864 |
| 1818 DART_EXPORT Dart_Handle Dart_SetInstanceField(Dart_Handle obj, | 1865 DART_EXPORT Dart_Handle Dart_SetInstanceField(Dart_Handle obj, |
| 1819 Dart_Handle name, | 1866 Dart_Handle name, |
| 1820 Dart_Handle value) { | 1867 Dart_Handle value) { |
| 1821 Zone zone; // Setup a VM zone as we are creating some handles. | 1868 Zone zone; // Setup a VM zone as we are creating some handles. |
| 1822 HandleScope scope; // Setup a VM handle scope. | 1869 HandleScope scope; // Setup a VM handle scope. |
| 1823 const Object& param = Object::Handle(Api::UnwrapHandle(obj)); | 1870 const Object& param = Object::Handle(Api::UnwrapHandle(obj)); |
| 1824 if (param.IsNull() || !param.IsInstance()) { | 1871 if (param.IsNull() || !param.IsInstance()) { |
| 1825 return Api::Error("Invalid object passed in to access instance field"); | 1872 return Api::Error("Invalid object passed in to access instance field"); |
| 1826 } | 1873 } |
| 1827 Instance& object = Instance::Handle(); | 1874 Instance& object = Instance::Handle(); |
| 1828 object ^= param.raw(); | 1875 object ^= param.raw(); |
| 1829 Dart_Handle result = LookupInstanceField(object, name, kSetter); | 1876 Dart_Handle result = LookupInstanceField(object, name, kSetter); |
| 1830 if (!::Dart_IsValid(result)) { | 1877 if (::Dart_IsError(result)) { |
| 1831 return result; | 1878 return result; |
| 1832 } | 1879 } |
| 1833 Function& func = Function::Handle(); | 1880 Function& func = Function::Handle(); |
| 1834 func ^= Api::UnwrapHandle(result); | 1881 func ^= Api::UnwrapHandle(result); |
| 1835 GrowableArray<const Object*> arguments(1); | 1882 GrowableArray<const Object*> arguments(1); |
| 1836 const Object& arg = Object::Handle(Api::UnwrapHandle(value)); | 1883 const Object& arg = Object::Handle(Api::UnwrapHandle(value)); |
| 1837 arguments.Add(&arg); | 1884 arguments.Add(&arg); |
| 1838 InvokeDynamic(object, func, arguments, &result); | 1885 InvokeDynamic(object, func, arguments, &result); |
| 1839 if (::Dart_IsValid(result)) { | |
| 1840 if (Dart_ExceptionOccurred(result)) { | |
| 1841 return Api::Error( | |
| 1842 "An exception occurred when setting the instance field"); | |
| 1843 } | |
| 1844 } | |
| 1845 return result; | 1886 return result; |
| 1846 } | 1887 } |
| 1847 | 1888 |
| 1848 | 1889 |
| 1849 DART_EXPORT Dart_Handle Dart_CreateNativeWrapperClass(Dart_Handle library, | 1890 DART_EXPORT Dart_Handle Dart_CreateNativeWrapperClass(Dart_Handle library, |
| 1850 Dart_Handle name, | 1891 Dart_Handle name, |
| 1851 int field_count) { | 1892 int field_count) { |
| 1852 Zone zone; // Setup a VM zone as we are creating some handles. | 1893 Zone zone; // Setup a VM zone as we are creating some handles. |
| 1853 HandleScope scope; // Setup a VM handle scope. | 1894 HandleScope scope; // Setup a VM handle scope. |
| 1854 const Object& param = Object::Handle(Api::UnwrapHandle(name)); | 1895 const Object& param = Object::Handle(Api::UnwrapHandle(name)); |
| (...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2077 intptr_t len = OS::VSNPrint(NULL, 0, format, args); | 2118 intptr_t len = OS::VSNPrint(NULL, 0, format, args); |
| 2078 va_end(args); | 2119 va_end(args); |
| 2079 | 2120 |
| 2080 char* buffer = reinterpret_cast<char*>(zone.Allocate(len + 1)); | 2121 char* buffer = reinterpret_cast<char*>(zone.Allocate(len + 1)); |
| 2081 va_list args2; | 2122 va_list args2; |
| 2082 va_start(args2, format); | 2123 va_start(args2, format); |
| 2083 OS::VSNPrint(buffer, (len + 1), format, args2); | 2124 OS::VSNPrint(buffer, (len + 1), format, args2); |
| 2084 va_end(args2); | 2125 va_end(args2); |
| 2085 | 2126 |
| 2086 const String& message = String::Handle(String::New(buffer)); | 2127 const String& message = String::Handle(String::New(buffer)); |
| 2087 const Object& obj = Object::Handle(ApiFailure::New(message)); | 2128 const Object& obj = Object::Handle(ApiError::New(message)); |
| 2088 return Api::NewLocalHandle(obj); | 2129 return Api::NewLocalHandle(obj); |
| 2089 } | 2130 } |
| 2090 | 2131 |
| 2091 | 2132 |
| 2133 Dart_Handle Api::ErrorFromException(const Object& obj) { |
| 2134 Zone zone; // Setup a VM zone as we are creating some handles. |
| 2135 HandleScope scope; // Setup a VM handle scope. |
| 2136 |
| 2137 ASSERT(obj.IsUnhandledException()); |
| 2138 if (obj.IsUnhandledException()) { |
| 2139 UnhandledException& uhe = UnhandledException::Handle(); |
| 2140 uhe ^= obj.raw(); |
| 2141 const Object& error = Object::Handle(ApiError::New(uhe)); |
| 2142 return Api::NewLocalHandle(error); |
| 2143 } else { |
| 2144 return Api::Error("Internal error: expected obj.IsUnhandledException()."); |
| 2145 } |
| 2146 } |
| 2147 |
| 2148 |
| 2092 Dart_Handle Api::Null() { | 2149 Dart_Handle Api::Null() { |
| 2093 Isolate* isolate = Isolate::Current(); | 2150 Isolate* isolate = Isolate::Current(); |
| 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 PersistentHandle* null_handle = state->Null(); | 2154 PersistentHandle* null_handle = state->Null(); |
| 2098 return reinterpret_cast<Dart_Handle>(null_handle); | 2155 return reinterpret_cast<Dart_Handle>(null_handle); |
| 2099 } | 2156 } |
| 2100 | 2157 |
| 2101 | 2158 |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2135 ASSERT(isolate != NULL); | 2192 ASSERT(isolate != NULL); |
| 2136 ApiState* state = isolate->api_state(); | 2193 ApiState* state = isolate->api_state(); |
| 2137 ASSERT(state != NULL); | 2194 ASSERT(state != NULL); |
| 2138 ApiLocalScope* scope = state->top_scope(); | 2195 ApiLocalScope* scope = state->top_scope(); |
| 2139 ASSERT(scope != NULL); | 2196 ASSERT(scope != NULL); |
| 2140 return scope->zone().Reallocate(ptr, old_size, new_size); | 2197 return scope->zone().Reallocate(ptr, old_size, new_size); |
| 2141 } | 2198 } |
| 2142 | 2199 |
| 2143 | 2200 |
| 2144 } // namespace dart | 2201 } // namespace dart |
| OLD | NEW |