| 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 21 matching lines...) Expand all Loading... |
| 32 return func + 6; | 32 return func + 6; |
| 33 } else { | 33 } else { |
| 34 return func; | 34 return func; |
| 35 } | 35 } |
| 36 } | 36 } |
| 37 | 37 |
| 38 #define RETURN_TYPE_ERROR(dart_handle, Type) \ | 38 #define RETURN_TYPE_ERROR(dart_handle, Type) \ |
| 39 do { \ | 39 do { \ |
| 40 const Object& tmp = Object::Handle(Api::UnwrapHandle((dart_handle))); \ | 40 const Object& tmp = Object::Handle(Api::UnwrapHandle((dart_handle))); \ |
| 41 if (tmp.IsNull()) { \ | 41 if (tmp.IsNull()) { \ |
| 42 return Api::Error("%s expects argument '%s' to be non-null.", \ | 42 return Api::NewError("%s expects argument '%s' to be non-null.", \ |
| 43 CURRENT_FUNC, #dart_handle); \ | 43 CURRENT_FUNC, #dart_handle); \ |
| 44 } else if (tmp.IsApiError()) { \ | 44 } else if (tmp.IsError()) { \ |
| 45 return dart_handle; \ | 45 return dart_handle; \ |
| 46 } else { \ | 46 } else { \ |
| 47 return Api::Error("%s expects argument '%s' to be of type %s.", \ | 47 return Api::NewError("%s expects argument '%s' to be of type %s.", \ |
| 48 CURRENT_FUNC, #dart_handle, #Type); \ | 48 CURRENT_FUNC, #dart_handle, #Type); \ |
| 49 } \ | 49 } \ |
| 50 } while (0) | 50 } while (0) |
| 51 | 51 |
| 52 | 52 |
| 53 // Return error if isolate is in an inconsistent state. | 53 // Return error if isolate is in an inconsistent state. |
| 54 // Return NULL when no error condition exists. | 54 // Return NULL when no error condition exists. |
| 55 const char* CheckIsolateState(Isolate* isolate, bool generating_snapshot) { | 55 const char* CheckIsolateState(Isolate* isolate, bool generating_snapshot) { |
| 56 bool success = true; | 56 bool success = true; |
| 57 if (!ClassFinalizer::AllClassesFinalized()) { | 57 if (!ClassFinalizer::AllClassesFinalized()) { |
| 58 success = (generating_snapshot) ? | 58 success = (generating_snapshot) ? |
| (...skipping 17 matching lines...) Expand all Loading... |
| 76 return msg; | 76 return msg; |
| 77 } | 77 } |
| 78 } | 78 } |
| 79 | 79 |
| 80 | 80 |
| 81 void SetupErrorResult(Dart_Handle* handle) { | 81 void SetupErrorResult(Dart_Handle* handle) { |
| 82 // Make a copy of the error message as the original message string | 82 // Make a copy of the error message as the original message string |
| 83 // may get deallocated when we return back from the Dart API call. | 83 // may get deallocated when we return back from the Dart API call. |
| 84 const String& error = String::Handle( | 84 const String& error = String::Handle( |
| 85 Isolate::Current()->object_store()->sticky_error()); | 85 Isolate::Current()->object_store()->sticky_error()); |
| 86 const Object& obj = Object::Handle(ApiError::New(error)); | 86 const Object& obj = Object::Handle(LanguageError::New(error)); |
| 87 *handle = Api::NewLocalHandle(obj); | 87 *handle = Api::NewLocalHandle(obj); |
| 88 } | 88 } |
| 89 | 89 |
| 90 | 90 |
| 91 // NOTE: Need to pass 'result' as a parameter here in order to avoid | 91 // NOTE: Need to pass 'result' as a parameter here in order to avoid |
| 92 // warning: variable 'result' might be clobbered by 'longjmp' or 'vfork' | 92 // warning: variable 'result' might be clobbered by 'longjmp' or 'vfork' |
| 93 // which shows up because of the use of setjmp. | 93 // which shows up because of the use of setjmp. |
| 94 static void InvokeStatic(Isolate* isolate, | 94 static void InvokeStatic(Isolate* isolate, |
| 95 const Function& function, | 95 const Function& function, |
| 96 GrowableArray<const Object*>& args, | 96 GrowableArray<const Object*>& args, |
| 97 Dart_Handle* result) { | 97 Dart_Handle* result) { |
| 98 ASSERT(isolate != NULL); | 98 ASSERT(isolate != NULL); |
| 99 LongJump* base = isolate->long_jump_base(); | 99 LongJump* base = isolate->long_jump_base(); |
| 100 LongJump jump; | 100 LongJump jump; |
| 101 isolate->set_long_jump_base(&jump); | 101 isolate->set_long_jump_base(&jump); |
| 102 if (setjmp(*jump.Set()) == 0) { | 102 if (setjmp(*jump.Set()) == 0) { |
| 103 const Array& kNoArgumentNames = Array::Handle(); | 103 const Array& kNoArgumentNames = Array::Handle(); |
| 104 const Instance& retval = Instance::Handle( | 104 const Instance& retval = Instance::Handle( |
| 105 DartEntry::InvokeStatic(function, args, kNoArgumentNames)); | 105 DartEntry::InvokeStatic(function, args, kNoArgumentNames)); |
| 106 if (retval.IsUnhandledException()) { | 106 *result = Api::NewLocalHandle(retval); |
| 107 *result = Api::ErrorFromException(retval); | |
| 108 } else { | |
| 109 *result = Api::NewLocalHandle(retval); | |
| 110 } | |
| 111 } else { | 107 } else { |
| 112 SetupErrorResult(result); | 108 SetupErrorResult(result); |
| 113 } | 109 } |
| 114 isolate->set_long_jump_base(base); | 110 isolate->set_long_jump_base(base); |
| 115 } | 111 } |
| 116 | 112 |
| 117 | 113 |
| 118 // NOTE: Need to pass 'result' as a parameter here in order to avoid | 114 // NOTE: Need to pass 'result' as a parameter here in order to avoid |
| 119 // warning: variable 'result' might be clobbered by 'longjmp' or 'vfork' | 115 // warning: variable 'result' might be clobbered by 'longjmp' or 'vfork' |
| 120 // which shows up because of the use of setjmp. | 116 // which shows up because of the use of setjmp. |
| 121 static void InvokeDynamic(Isolate* isolate, | 117 static void InvokeDynamic(Isolate* isolate, |
| 122 const Instance& receiver, | 118 const Instance& receiver, |
| 123 const Function& function, | 119 const Function& function, |
| 124 GrowableArray<const Object*>& args, | 120 GrowableArray<const Object*>& args, |
| 125 Dart_Handle* result) { | 121 Dart_Handle* result) { |
| 126 ASSERT(isolate != NULL); | 122 ASSERT(isolate != NULL); |
| 127 LongJump* base = isolate->long_jump_base(); | 123 LongJump* base = isolate->long_jump_base(); |
| 128 LongJump jump; | 124 LongJump jump; |
| 129 isolate->set_long_jump_base(&jump); | 125 isolate->set_long_jump_base(&jump); |
| 130 if (setjmp(*jump.Set()) == 0) { | 126 if (setjmp(*jump.Set()) == 0) { |
| 131 const Array& kNoArgumentNames = Array::Handle(); | 127 const Array& kNoArgumentNames = Array::Handle(); |
| 132 const Instance& retval = Instance::Handle( | 128 const Instance& retval = Instance::Handle( |
| 133 DartEntry::InvokeDynamic(receiver, function, args, kNoArgumentNames)); | 129 DartEntry::InvokeDynamic(receiver, function, args, kNoArgumentNames)); |
| 134 if (retval.IsUnhandledException()) { | 130 *result = Api::NewLocalHandle(retval); |
| 135 *result = Api::ErrorFromException(retval); | |
| 136 } else { | |
| 137 *result = Api::NewLocalHandle(retval); | |
| 138 } | |
| 139 } else { | 131 } else { |
| 140 SetupErrorResult(result); | 132 SetupErrorResult(result); |
| 141 } | 133 } |
| 142 isolate->set_long_jump_base(base); | 134 isolate->set_long_jump_base(base); |
| 143 } | 135 } |
| 144 | 136 |
| 145 | 137 |
| 146 Dart_Handle Api::NewLocalHandle(const Object& object) { | 138 Dart_Handle Api::NewLocalHandle(const Object& object) { |
| 147 Isolate* isolate = Isolate::Current(); | 139 Isolate* isolate = Isolate::Current(); |
| 148 ASSERT(isolate != NULL); | 140 ASSERT(isolate != NULL); |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 211 Dart_Handle Api::Success() { | 203 Dart_Handle Api::Success() { |
| 212 Isolate* isolate = Isolate::Current(); | 204 Isolate* isolate = Isolate::Current(); |
| 213 ASSERT(isolate != NULL); | 205 ASSERT(isolate != NULL); |
| 214 ApiState* state = isolate->api_state(); | 206 ApiState* state = isolate->api_state(); |
| 215 ASSERT(state != NULL); | 207 ASSERT(state != NULL); |
| 216 PersistentHandle* true_handle = state->True(); | 208 PersistentHandle* true_handle = state->True(); |
| 217 return reinterpret_cast<Dart_Handle>(true_handle); | 209 return reinterpret_cast<Dart_Handle>(true_handle); |
| 218 } | 210 } |
| 219 | 211 |
| 220 | 212 |
| 221 Dart_Handle Api::Error(const char* format, ...) { | 213 Dart_Handle Api::NewError(const char* format, ...) { |
| 222 DARTSCOPE_NOCHECKS(Isolate::Current()); | 214 DARTSCOPE_NOCHECKS(Isolate::Current()); |
| 223 | 215 |
| 224 va_list args; | 216 va_list args; |
| 225 va_start(args, format); | 217 va_start(args, format); |
| 226 intptr_t len = OS::VSNPrint(NULL, 0, format, args); | 218 intptr_t len = OS::VSNPrint(NULL, 0, format, args); |
| 227 va_end(args); | 219 va_end(args); |
| 228 | 220 |
| 229 char* buffer = reinterpret_cast<char*>(zone.Allocate(len + 1)); | 221 char* buffer = reinterpret_cast<char*>(zone.Allocate(len + 1)); |
| 230 va_list args2; | 222 va_list args2; |
| 231 va_start(args2, format); | 223 va_start(args2, format); |
| 232 OS::VSNPrint(buffer, (len + 1), format, args2); | 224 OS::VSNPrint(buffer, (len + 1), format, args2); |
| 233 va_end(args2); | 225 va_end(args2); |
| 234 | 226 |
| 235 const String& message = String::Handle(String::New(buffer)); | 227 const String& message = String::Handle(String::New(buffer)); |
| 236 const Object& obj = Object::Handle(ApiError::New(message)); | 228 const Object& obj = Object::Handle(ApiError::New(message)); |
| 237 return Api::NewLocalHandle(obj); | 229 return Api::NewLocalHandle(obj); |
| 238 } | 230 } |
| 239 | 231 |
| 240 | 232 |
| 241 Dart_Handle Api::ErrorFromException(const Object& obj) { | |
| 242 DARTSCOPE_NOCHECKS(Isolate::Current()); | |
| 243 | |
| 244 ASSERT(obj.IsUnhandledException()); | |
| 245 if (obj.IsUnhandledException()) { | |
| 246 UnhandledException& uhe = UnhandledException::Handle(); | |
| 247 uhe ^= obj.raw(); | |
| 248 const Object& error = Object::Handle(ApiError::New(uhe)); | |
| 249 return Api::NewLocalHandle(error); | |
| 250 } else { | |
| 251 return Api::Error("Internal error: expected obj.IsUnhandledException()."); | |
| 252 } | |
| 253 } | |
| 254 | |
| 255 | |
| 256 Dart_Handle Api::Null() { | 233 Dart_Handle Api::Null() { |
| 257 Isolate* isolate = Isolate::Current(); | 234 Isolate* isolate = Isolate::Current(); |
| 258 ASSERT(isolate != NULL); | 235 ASSERT(isolate != NULL); |
| 259 ApiState* state = isolate->api_state(); | 236 ApiState* state = isolate->api_state(); |
| 260 ASSERT(state != NULL); | 237 ASSERT(state != NULL); |
| 261 PersistentHandle* null_handle = state->Null(); | 238 PersistentHandle* null_handle = state->Null(); |
| 262 return reinterpret_cast<Dart_Handle>(null_handle); | 239 return reinterpret_cast<Dart_Handle>(null_handle); |
| 263 } | 240 } |
| 264 | 241 |
| 265 | 242 |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 304 return scope->zone().Reallocate(ptr, old_size, new_size); | 281 return scope->zone().Reallocate(ptr, old_size, new_size); |
| 305 } | 282 } |
| 306 | 283 |
| 307 | 284 |
| 308 // --- Handles --- | 285 // --- Handles --- |
| 309 | 286 |
| 310 | 287 |
| 311 DART_EXPORT bool Dart_IsError(Dart_Handle handle) { | 288 DART_EXPORT bool Dart_IsError(Dart_Handle handle) { |
| 312 DARTSCOPE(Isolate::Current()); | 289 DARTSCOPE(Isolate::Current()); |
| 313 const Object& obj = Object::Handle(Api::UnwrapHandle(handle)); | 290 const Object& obj = Object::Handle(Api::UnwrapHandle(handle)); |
| 314 return obj.IsApiError(); | 291 return obj.IsError(); |
| 315 } | 292 } |
| 316 | 293 |
| 317 | 294 |
| 318 static const char* MakeUnhandledExceptionCString( | 295 static const char* MakeUnhandledExceptionCString( |
| 319 const UnhandledException& uhe) { | 296 const UnhandledException& uhe) { |
| 320 const Instance& exception = Instance::Handle(uhe.exception()); | 297 const Instance& exception = Instance::Handle(uhe.exception()); |
| 321 Object& strtmp = Object::Handle(DartLibraryCalls::ToString(exception)); | 298 Object& strtmp = Object::Handle(DartLibraryCalls::ToString(exception)); |
| 322 const char* exc_str = | 299 const char* exc_str = |
| 323 "<Received exception while converting exception to string>"; | 300 "<Received error while converting exception to string>"; |
| 324 if (!strtmp.IsUnhandledException()) { | 301 if (!strtmp.IsError()) { |
| 325 exc_str = strtmp.ToCString(); | 302 exc_str = strtmp.ToCString(); |
| 326 } | 303 } |
| 327 | 304 |
| 328 const Instance& stack = Instance::Handle(uhe.stacktrace()); | 305 const Instance& stack = Instance::Handle(uhe.stacktrace()); |
| 329 strtmp = DartLibraryCalls::ToString(stack); | 306 strtmp = DartLibraryCalls::ToString(stack); |
| 330 const char* stack_str = | 307 const char* stack_str = |
| 331 "<Received exception while converting stack trace to string>"; | 308 "<Received error while converting stack trace to string>"; |
| 332 if (!strtmp.IsUnhandledException()) { | 309 if (!strtmp.IsError()) { |
| 333 stack_str = strtmp.ToCString(); | 310 stack_str = strtmp.ToCString(); |
| 334 } | 311 } |
| 335 | 312 |
| 336 const char* format = "Unhandled exception:\n%s\n%s"; | 313 const char* format = "Unhandled exception:\n%s\n%s"; |
| 337 int len = (strlen(exc_str) + strlen(stack_str) + strlen(format) | 314 int len = (strlen(exc_str) + strlen(stack_str) + strlen(format) |
| 338 - 4 // Two '%s' | 315 - 4 // Two '%s' |
| 339 + 1); // '\0' | 316 + 1); // '\0' |
| 340 char* buffer = reinterpret_cast<char*>(Api::Allocate(len)); | 317 char* buffer = reinterpret_cast<char*>(Api::Allocate(len)); |
| 341 OS::SNPrint(buffer, len, format, exc_str, stack_str); | 318 OS::SNPrint(buffer, len, format, exc_str, stack_str); |
| 342 return buffer; | 319 return buffer; |
| 343 } | 320 } |
| 344 | 321 |
| 345 | 322 |
| 346 DART_EXPORT const char* Dart_GetError(Dart_Handle handle) { | 323 DART_EXPORT const char* Dart_GetError(Dart_Handle handle) { |
| 347 DARTSCOPE(Isolate::Current()); | 324 DARTSCOPE(Isolate::Current()); |
| 348 | 325 |
| 349 const Object& obj = Object::Handle(Api::UnwrapHandle(handle)); | 326 const Object& obj = Object::Handle(Api::UnwrapHandle(handle)); |
| 350 if (!obj.IsApiError()) { | 327 if (!obj.IsError()) { |
| 351 return ""; | 328 return ""; |
| 352 } | 329 } |
| 353 ApiError& failure = ApiError::Handle(); | 330 if (obj.IsApiError()) { |
| 354 failure ^= obj.raw(); | 331 ApiError& error = ApiError::Handle(); |
| 355 const Object& data = Object::Handle(failure.data()); | 332 error ^= obj.raw(); |
| 356 if (data.IsString()) { | 333 const String& message = String::Handle(error.message()); |
| 357 // Simple error message. | |
| 358 String& message = String::Handle(); | |
| 359 message ^= failure.data(); | |
| 360 const char* msg = message.ToCString(); | 334 const char* msg = message.ToCString(); |
| 361 intptr_t len = strlen(msg) + 1; | 335 intptr_t len = strlen(msg) + 1; |
| 362 char* msg_copy = reinterpret_cast<char*>(Api::Allocate(len)); | 336 char* msg_copy = reinterpret_cast<char*>(Api::Allocate(len)); |
| 363 strncpy(msg_copy, msg, len); | 337 strncpy(msg_copy, msg, len); |
| 364 return msg_copy; | 338 return msg_copy; |
| 365 | 339 } else if (obj.IsLanguageError()) { |
| 366 } else if (data.IsUnhandledException()) { | 340 LanguageError& error = LanguageError::Handle(); |
| 367 UnhandledException& uhe = UnhandledException::Handle(); | 341 error ^= obj.raw(); |
| 368 uhe ^= data.raw(); | 342 const String& message = String::Handle(error.message()); |
| 369 return MakeUnhandledExceptionCString(uhe); | 343 const char* msg = message.ToCString(); |
| 370 | 344 intptr_t len = strlen(msg) + 1; |
| 345 char* msg_copy = reinterpret_cast<char*>(Api::Allocate(len)); |
| 346 strncpy(msg_copy, msg, len); |
| 347 return msg_copy; |
| 348 } else if (obj.IsUnhandledException()) { |
| 349 UnhandledException& error = UnhandledException::Handle(); |
| 350 error ^= obj.raw(); |
| 351 return MakeUnhandledExceptionCString(error); |
| 352 } else if (obj.IsUnwindError()) { |
| 353 UNIMPLEMENTED(); |
| 354 return "<unimplemented>;"; |
| 371 } else { | 355 } else { |
| 372 return "<Internal error in Dart_GetError: malformed error handle>"; | 356 return "<Internal error in Dart_GetError: unexpected error type>"; |
| 373 } | 357 } |
| 374 } | 358 } |
| 375 | 359 |
| 376 | 360 |
| 377 DART_EXPORT bool Dart_ErrorHasException(Dart_Handle handle) { | 361 DART_EXPORT bool Dart_ErrorHasException(Dart_Handle handle) { |
| 378 DARTSCOPE(Isolate::Current()); | 362 DARTSCOPE(Isolate::Current()); |
| 379 const Object& obj = Object::Handle(Api::UnwrapHandle(handle)); | 363 const Object& obj = Object::Handle(Api::UnwrapHandle(handle)); |
| 380 if (obj.IsApiError()) { | 364 return obj.IsUnhandledException(); |
| 381 const ApiError& error = ApiError::CheckedHandle(obj.raw()); | |
| 382 const Object& data = Object::Handle(error.data()); | |
| 383 return data.IsUnhandledException(); | |
| 384 } | |
| 385 return false; | |
| 386 } | 365 } |
| 387 | 366 |
| 388 | 367 |
| 389 DART_EXPORT Dart_Handle Dart_ErrorGetException(Dart_Handle handle) { | 368 DART_EXPORT Dart_Handle Dart_ErrorGetException(Dart_Handle handle) { |
| 390 DARTSCOPE(Isolate::Current()); | 369 DARTSCOPE(Isolate::Current()); |
| 391 const Object& obj = Object::Handle(Api::UnwrapHandle(handle)); | 370 const Object& obj = Object::Handle(Api::UnwrapHandle(handle)); |
| 392 if (obj.IsApiError()) { | 371 if (obj.IsUnhandledException()) { |
| 393 const ApiError& error = ApiError::CheckedHandle(obj.raw()); | 372 UnhandledException& error = UnhandledException::Handle(); |
| 394 const Object& data = Object::Handle(error.data()); | 373 error ^= obj.raw(); |
| 395 if (data.IsUnhandledException()) { | 374 const Object& exception = Object::Handle(error.exception()); |
| 396 const UnhandledException& unhandled = UnhandledException::Handle( | 375 return Api::NewLocalHandle(exception); |
| 397 reinterpret_cast<RawUnhandledException*>(data.raw())); | 376 } else if (obj.IsError()) { |
| 398 const Object& exception = Object::Handle(unhandled.exception()); | 377 return Api::NewError("This error is not an unhandled exception error."); |
| 399 return Api::NewLocalHandle(exception); | |
| 400 } else { | |
| 401 return Api::Error("This error is not an unhandled exception error."); | |
| 402 } | |
| 403 } else { | 378 } else { |
| 404 return Api::Error("Can only get exceptions from error handles."); | 379 return Api::NewError("Can only get exceptions from error handles."); |
| 405 } | 380 } |
| 406 } | 381 } |
| 407 | 382 |
| 408 | 383 |
| 409 DART_EXPORT Dart_Handle Dart_ErrorGetStacktrace(Dart_Handle handle) { | 384 DART_EXPORT Dart_Handle Dart_ErrorGetStacktrace(Dart_Handle handle) { |
| 410 DARTSCOPE(Isolate::Current()); | 385 DARTSCOPE(Isolate::Current()); |
| 411 const Object& obj = Object::Handle(Api::UnwrapHandle(handle)); | 386 const Object& obj = Object::Handle(Api::UnwrapHandle(handle)); |
| 412 if (obj.IsApiError()) { | 387 if (obj.IsUnhandledException()) { |
| 413 ApiError& failure = ApiError::Handle(); | 388 UnhandledException& error = UnhandledException::Handle(); |
| 414 failure ^= obj.raw(); | 389 error ^= obj.raw(); |
| 415 const Object& data = Object::Handle(failure.data()); | 390 const Object& stacktrace = Object::Handle(error.stacktrace()); |
| 416 if (data.IsUnhandledException()) { | 391 return Api::NewLocalHandle(stacktrace); |
| 417 const UnhandledException& unhandled = UnhandledException::Handle( | 392 } else if (obj.IsError()) { |
| 418 reinterpret_cast<RawUnhandledException*>(data.raw())); | 393 return Api::NewError("This error is not an unhandled exception error."); |
| 419 const Object& stacktrace = Object::Handle(unhandled.stacktrace()); | |
| 420 return Api::NewLocalHandle(stacktrace); | |
| 421 } else { | |
| 422 return Api::Error("This error is not an unhandled exception error."); | |
| 423 } | |
| 424 } else { | 394 } else { |
| 425 return Api::Error("Can only get stacktraces from error handles."); | 395 return Api::NewError("Can only get stacktraces from error handles."); |
| 426 } | 396 } |
| 427 } | 397 } |
| 428 | 398 |
| 429 | 399 |
| 430 // TODO(turnidge): This clones Api::Error. I need to use va_copy to | 400 // TODO(turnidge): This clones Api::NewError. I need to use va_copy to |
| 431 // fix this but not sure if it available on all of our builds. | 401 // fix this but not sure if it available on all of our builds. |
| 432 DART_EXPORT Dart_Handle Dart_Error(const char* format, ...) { | 402 DART_EXPORT Dart_Handle Dart_Error(const char* format, ...) { |
| 433 DARTSCOPE(Isolate::Current()); | 403 DARTSCOPE(Isolate::Current()); |
| 434 | 404 |
| 435 va_list args; | 405 va_list args; |
| 436 va_start(args, format); | 406 va_start(args, format); |
| 437 intptr_t len = OS::VSNPrint(NULL, 0, format, args); | 407 intptr_t len = OS::VSNPrint(NULL, 0, format, args); |
| 438 va_end(args); | 408 va_end(args); |
| 439 | 409 |
| 440 char* buffer = reinterpret_cast<char*>(zone.Allocate(len + 1)); | 410 char* buffer = reinterpret_cast<char*>(zone.Allocate(len + 1)); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 462 DART_EXPORT Dart_Handle Dart_ToString(Dart_Handle object) { | 432 DART_EXPORT Dart_Handle Dart_ToString(Dart_Handle object) { |
| 463 DARTSCOPE(Isolate::Current()); | 433 DARTSCOPE(Isolate::Current()); |
| 464 const Object& obj = Object::Handle(Api::UnwrapHandle(object)); | 434 const Object& obj = Object::Handle(Api::UnwrapHandle(object)); |
| 465 Object& result = Object::Handle(); | 435 Object& result = Object::Handle(); |
| 466 if (obj.IsString()) { | 436 if (obj.IsString()) { |
| 467 result = obj.raw(); | 437 result = obj.raw(); |
| 468 } else if (obj.IsInstance()) { | 438 } else if (obj.IsInstance()) { |
| 469 Instance& receiver = Instance::Handle(); | 439 Instance& receiver = Instance::Handle(); |
| 470 receiver ^= obj.raw(); | 440 receiver ^= obj.raw(); |
| 471 result = DartLibraryCalls::ToString(receiver); | 441 result = DartLibraryCalls::ToString(receiver); |
| 472 if (result.IsUnhandledException()) { | |
| 473 return Api::ErrorFromException(result); | |
| 474 } | |
| 475 } else { | 442 } else { |
| 476 // This is a VM internal object. Call the C++ method of printing. | 443 // This is a VM internal object. Call the C++ method of printing. |
| 477 result = String::New(obj.ToCString()); | 444 result = String::New(obj.ToCString()); |
| 478 } | 445 } |
| 479 return Api::NewLocalHandle(result); | 446 return Api::NewLocalHandle(result); |
| 480 } | 447 } |
| 481 | 448 |
| 482 | 449 |
| 483 DART_EXPORT Dart_Handle Dart_IsSame(Dart_Handle obj1, Dart_Handle obj2, | 450 DART_EXPORT Dart_Handle Dart_IsSame(Dart_Handle obj1, Dart_Handle obj2, |
| 484 bool* value) { | 451 bool* value) { |
| (...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 630 return reinterpret_cast<uint8_t*>(new_ptr); | 597 return reinterpret_cast<uint8_t*>(new_ptr); |
| 631 } | 598 } |
| 632 | 599 |
| 633 | 600 |
| 634 DART_EXPORT Dart_Handle Dart_CreateSnapshot(uint8_t** buffer, | 601 DART_EXPORT Dart_Handle Dart_CreateSnapshot(uint8_t** buffer, |
| 635 intptr_t* size) { | 602 intptr_t* size) { |
| 636 Isolate* isolate = Isolate::Current(); | 603 Isolate* isolate = Isolate::Current(); |
| 637 DARTSCOPE(isolate); | 604 DARTSCOPE(isolate); |
| 638 TIMERSCOPE(time_creating_snapshot); | 605 TIMERSCOPE(time_creating_snapshot); |
| 639 if (buffer == NULL) { | 606 if (buffer == NULL) { |
| 640 return Api::Error("%s expects argument 'buffer' to be non-null.", | 607 return Api::NewError("%s expects argument 'buffer' to be non-null.", |
| 641 CURRENT_FUNC); | 608 CURRENT_FUNC); |
| 642 } | 609 } |
| 643 if (size == NULL) { | 610 if (size == NULL) { |
| 644 return Api::Error("%s expects argument 'size' to be non-null.", | 611 return Api::NewError("%s expects argument 'size' to be non-null.", |
| 645 CURRENT_FUNC); | 612 CURRENT_FUNC); |
| 646 } | 613 } |
| 647 const char* msg = CheckIsolateState(isolate, | 614 const char* msg = CheckIsolateState(isolate, |
| 648 ClassFinalizer::kGeneratingSnapshot); | 615 ClassFinalizer::kGeneratingSnapshot); |
| 649 if (msg != NULL) { | 616 if (msg != NULL) { |
| 650 return Api::Error(msg); | 617 return Api::NewError(msg); |
| 651 } | 618 } |
| 652 // Since this is only a snapshot the root library should not be set. | 619 // Since this is only a snapshot the root library should not be set. |
| 653 isolate->object_store()->set_root_library(Library::Handle()); | 620 isolate->object_store()->set_root_library(Library::Handle()); |
| 654 SnapshotWriter writer(Snapshot::kFull, buffer, ApiAllocator); | 621 SnapshotWriter writer(Snapshot::kFull, buffer, ApiAllocator); |
| 655 writer.WriteFullSnapshot(); | 622 writer.WriteFullSnapshot(); |
| 656 *size = writer.BytesWritten(); | 623 *size = writer.BytesWritten(); |
| 657 return Api::Success(); | 624 return Api::Success(); |
| 658 } | 625 } |
| 659 | 626 |
| 660 | 627 |
| 661 DART_EXPORT Dart_Handle Dart_CreateScriptSnapshot(uint8_t** buffer, | 628 DART_EXPORT Dart_Handle Dart_CreateScriptSnapshot(uint8_t** buffer, |
| 662 intptr_t* size) { | 629 intptr_t* size) { |
| 663 Isolate* isolate = Isolate::Current(); | 630 Isolate* isolate = Isolate::Current(); |
| 664 DARTSCOPE(isolate); | 631 DARTSCOPE(isolate); |
| 665 TIMERSCOPE(time_creating_snapshot); | 632 TIMERSCOPE(time_creating_snapshot); |
| 666 if (buffer == NULL) { | 633 if (buffer == NULL) { |
| 667 return Api::Error("%s expects argument 'buffer' to be non-null.", | 634 return Api::NewError("%s expects argument 'buffer' to be non-null.", |
| 668 CURRENT_FUNC); | 635 CURRENT_FUNC); |
| 669 } | 636 } |
| 670 if (size == NULL) { | 637 if (size == NULL) { |
| 671 return Api::Error("%s expects argument 'size' to be non-null.", | 638 return Api::NewError("%s expects argument 'size' to be non-null.", |
| 672 CURRENT_FUNC); | 639 CURRENT_FUNC); |
| 673 } | 640 } |
| 674 const char* msg = CheckIsolateState(isolate); | 641 const char* msg = CheckIsolateState(isolate); |
| 675 if (msg != NULL) { | 642 if (msg != NULL) { |
| 676 return Api::Error(msg); | 643 return Api::NewError(msg); |
| 677 } | 644 } |
| 678 Library& library = Library::Handle(isolate->object_store()->root_library()); | 645 Library& library = Library::Handle(isolate->object_store()->root_library()); |
| 679 if (library.IsNull()) { | 646 if (library.IsNull()) { |
| 680 return Api::Error("%s expects the isolate to have a script loaded in it.", | 647 return |
| 648 Api::NewError("%s expects the isolate to have a script loaded in it.", |
| 681 CURRENT_FUNC); | 649 CURRENT_FUNC); |
| 682 } | 650 } |
| 683 ScriptSnapshotWriter writer(buffer, ApiAllocator); | 651 ScriptSnapshotWriter writer(buffer, ApiAllocator); |
| 684 writer.WriteScriptSnapshot(library); | 652 writer.WriteScriptSnapshot(library); |
| 685 *size = writer.BytesWritten(); | 653 *size = writer.BytesWritten(); |
| 686 return Api::Success(); | 654 return Api::Success(); |
| 687 } | 655 } |
| 688 | 656 |
| 689 | 657 |
| 690 DART_EXPORT void Dart_InterruptIsolate(Dart_Isolate isolate) { | 658 DART_EXPORT void Dart_InterruptIsolate(Dart_Isolate isolate) { |
| (...skipping 23 matching lines...) Expand all Loading... |
| 714 DART_EXPORT Dart_Handle Dart_RunLoop() { | 682 DART_EXPORT Dart_Handle Dart_RunLoop() { |
| 715 Isolate* isolate = Isolate::Current(); | 683 Isolate* isolate = Isolate::Current(); |
| 716 DARTSCOPE(isolate); | 684 DARTSCOPE(isolate); |
| 717 | 685 |
| 718 LongJump* base = isolate->long_jump_base(); | 686 LongJump* base = isolate->long_jump_base(); |
| 719 LongJump jump; | 687 LongJump jump; |
| 720 Dart_Handle result; | 688 Dart_Handle result; |
| 721 isolate->set_long_jump_base(&jump); | 689 isolate->set_long_jump_base(&jump); |
| 722 if (setjmp(*jump.Set()) == 0) { | 690 if (setjmp(*jump.Set()) == 0) { |
| 723 const Object& obj = Object::Handle(isolate->StandardRunLoop()); | 691 const Object& obj = Object::Handle(isolate->StandardRunLoop()); |
| 724 if (obj.IsUnhandledException()) { | 692 if (obj.IsError()) { |
| 725 result = Api::ErrorFromException(obj); | 693 result = Api::NewLocalHandle(obj); |
| 726 } else { | 694 } else { |
| 727 ASSERT(obj.IsNull()); | 695 ASSERT(obj.IsNull()); |
| 728 result = Api::Success(); | 696 result = Api::Success(); |
| 729 } | 697 } |
| 730 } else { | 698 } else { |
| 731 SetupErrorResult(&result); | 699 SetupErrorResult(&result); |
| 732 } | 700 } |
| 733 isolate->set_long_jump_base(base); | 701 isolate->set_long_jump_base(base); |
| 734 return result; | 702 return result; |
| 735 } | 703 } |
| (...skipping 15 matching lines...) Expand all Loading... |
| 751 DART_EXPORT Dart_Handle Dart_HandleMessage(Dart_Port dest_port_id, | 719 DART_EXPORT Dart_Handle Dart_HandleMessage(Dart_Port dest_port_id, |
| 752 Dart_Port reply_port_id, | 720 Dart_Port reply_port_id, |
| 753 Dart_Message dart_message) { | 721 Dart_Message dart_message) { |
| 754 DARTSCOPE(Isolate::Current()); | 722 DARTSCOPE(Isolate::Current()); |
| 755 const Instance& msg = Instance::Handle(DeserializeMessage(dart_message)); | 723 const Instance& msg = Instance::Handle(DeserializeMessage(dart_message)); |
| 756 // TODO(turnidge): Should this call be wrapped in a longjmp? | 724 // TODO(turnidge): Should this call be wrapped in a longjmp? |
| 757 const Object& result = | 725 const Object& result = |
| 758 Object::Handle(DartLibraryCalls::HandleMessage(dest_port_id, | 726 Object::Handle(DartLibraryCalls::HandleMessage(dest_port_id, |
| 759 reply_port_id, | 727 reply_port_id, |
| 760 msg)); | 728 msg)); |
| 761 if (result.IsUnhandledException()) { | 729 if (result.IsError()) { |
| 762 return Api::ErrorFromException(result); | 730 return Api::NewLocalHandle(result); |
| 763 } | 731 } |
| 764 ASSERT(result.IsNull()); | 732 ASSERT(result.IsNull()); |
| 765 return Api::Success(); | 733 return Api::Success(); |
| 766 } | 734 } |
| 767 | 735 |
| 768 | 736 |
| 769 DART_EXPORT bool Dart_HasLivePorts() { | 737 DART_EXPORT bool Dart_HasLivePorts() { |
| 770 Isolate* isolate = Isolate::Current(); | 738 Isolate* isolate = Isolate::Current(); |
| 771 ASSERT(isolate); | 739 ASSERT(isolate); |
| 772 return isolate->live_ports() > 0; | 740 return isolate->live_ports() > 0; |
| (...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 906 DARTSCOPE(Isolate::Current()); | 874 DARTSCOPE(Isolate::Current()); |
| 907 const Instance& expected = Instance::CheckedHandle(Api::UnwrapHandle(obj1)); | 875 const Instance& expected = Instance::CheckedHandle(Api::UnwrapHandle(obj1)); |
| 908 const Instance& actual = Instance::CheckedHandle(Api::UnwrapHandle(obj2)); | 876 const Instance& actual = Instance::CheckedHandle(Api::UnwrapHandle(obj2)); |
| 909 const Instance& result = | 877 const Instance& result = |
| 910 Instance::Handle(DartLibraryCalls::Equals(expected, actual)); | 878 Instance::Handle(DartLibraryCalls::Equals(expected, actual)); |
| 911 if (result.IsBool()) { | 879 if (result.IsBool()) { |
| 912 Bool& b = Bool::Handle(); | 880 Bool& b = Bool::Handle(); |
| 913 b ^= result.raw(); | 881 b ^= result.raw(); |
| 914 *value = b.value(); | 882 *value = b.value(); |
| 915 return Api::Success(); | 883 return Api::Success(); |
| 916 } else if (result.IsUnhandledException()) { | 884 } else if (result.IsError()) { |
| 917 return Api::ErrorFromException(result); | 885 return Api::NewLocalHandle(result); |
| 918 } else { | 886 } else { |
| 919 return Api::Error("Expected boolean result from =="); | 887 return Api::NewError("Expected boolean result from =="); |
| 920 } | 888 } |
| 921 } | 889 } |
| 922 | 890 |
| 923 | 891 |
| 924 // TODO(iposva): This call actually implements IsInstanceOfClass. | 892 // TODO(iposva): This call actually implements IsInstanceOfClass. |
| 925 // Do we also need a real Dart_IsInstanceOf, which should take an instance | 893 // Do we also need a real Dart_IsInstanceOf, which should take an instance |
| 926 // rather than an object and a type rather than a class? | 894 // rather than an object and a type rather than a class? |
| 927 DART_EXPORT Dart_Handle Dart_ObjectIsType(Dart_Handle object, | 895 DART_EXPORT Dart_Handle Dart_ObjectIsType(Dart_Handle object, |
| 928 Dart_Handle clazz, | 896 Dart_Handle clazz, |
| 929 bool* value) { | 897 bool* value) { |
| 930 Isolate* isolate = Isolate::Current(); | 898 Isolate* isolate = Isolate::Current(); |
| 931 DARTSCOPE(isolate); | 899 DARTSCOPE(isolate); |
| 932 const Class& cls = Class::CheckedHandle(Api::UnwrapHandle(clazz)); | 900 const Class& cls = Class::CheckedHandle(Api::UnwrapHandle(clazz)); |
| 933 if (cls.IsNull()) { | 901 if (cls.IsNull()) { |
| 934 return Api::Error("instanceof check against null class"); | 902 return Api::NewError("instanceof check against null class"); |
| 935 } | 903 } |
| 936 const Object& obj = Object::Handle(Api::UnwrapHandle(object)); | 904 const Object& obj = Object::Handle(Api::UnwrapHandle(object)); |
| 937 Instance& instance = Instance::Handle(); | 905 Instance& instance = Instance::Handle(); |
| 938 instance ^= obj.raw(); | 906 instance ^= obj.raw(); |
| 939 // Finalize all classes. | 907 // Finalize all classes. |
| 940 const char* msg = CheckIsolateState(isolate); | 908 const char* msg = CheckIsolateState(isolate); |
| 941 if (msg != NULL) { | 909 if (msg != NULL) { |
| 942 return Api::Error(msg); | 910 return Api::NewError(msg); |
| 943 } | 911 } |
| 944 const Type& type = Type::Handle(Type::NewNonParameterizedType(cls)); | 912 const Type& type = Type::Handle(Type::NewNonParameterizedType(cls)); |
| 945 *value = instance.IsInstanceOf(type, TypeArguments::Handle()); | 913 *value = instance.IsInstanceOf(type, TypeArguments::Handle()); |
| 946 return Api::Success(); | 914 return Api::Success(); |
| 947 } | 915 } |
| 948 | 916 |
| 949 | 917 |
| 950 // --- Numbers ---- | 918 // --- Numbers ---- |
| 951 | 919 |
| 952 | 920 |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1036 return Api::Success(); | 1004 return Api::Success(); |
| 1037 } else { | 1005 } else { |
| 1038 ASSERT(int_obj.IsBigint()); | 1006 ASSERT(int_obj.IsBigint()); |
| 1039 Bigint& bigint = Bigint::Handle(); | 1007 Bigint& bigint = Bigint::Handle(); |
| 1040 bigint ^= int_obj.raw(); | 1008 bigint ^= int_obj.raw(); |
| 1041 if (BigintOperations::FitsIntoInt64(bigint)) { | 1009 if (BigintOperations::FitsIntoInt64(bigint)) { |
| 1042 *value = BigintOperations::ToInt64(bigint); | 1010 *value = BigintOperations::ToInt64(bigint); |
| 1043 return Api::Success(); | 1011 return Api::Success(); |
| 1044 } | 1012 } |
| 1045 } | 1013 } |
| 1046 return Api::Error("%s: Integer %s cannot be represented as an int64_t.", | 1014 return Api::NewError("%s: Integer %s cannot be represented as an int64_t.", |
| 1047 CURRENT_FUNC, int_obj.ToCString()); | 1015 CURRENT_FUNC, int_obj.ToCString()); |
| 1048 } | 1016 } |
| 1049 | 1017 |
| 1050 | 1018 |
| 1051 DART_EXPORT Dart_Handle Dart_IntegerToUint64(Dart_Handle integer, | 1019 DART_EXPORT Dart_Handle Dart_IntegerToUint64(Dart_Handle integer, |
| 1052 uint64_t* value) { | 1020 uint64_t* value) { |
| 1053 DARTSCOPE(Isolate::Current()); | 1021 DARTSCOPE(Isolate::Current()); |
| 1054 const Integer& int_obj = Api::UnwrapIntegerHandle(integer); | 1022 const Integer& int_obj = Api::UnwrapIntegerHandle(integer); |
| 1055 if (int_obj.IsNull()) { | 1023 if (int_obj.IsNull()) { |
| 1056 RETURN_TYPE_ERROR(integer, Integer); | 1024 RETURN_TYPE_ERROR(integer, Integer); |
| 1057 } | 1025 } |
| 1058 if (int_obj.IsSmi() || int_obj.IsMint()) { | 1026 if (int_obj.IsSmi() || int_obj.IsMint()) { |
| 1059 if (!int_obj.IsNegative()) { | 1027 if (!int_obj.IsNegative()) { |
| 1060 *value = int_obj.AsInt64Value(); | 1028 *value = int_obj.AsInt64Value(); |
| 1061 return Api::Success(); | 1029 return Api::Success(); |
| 1062 } | 1030 } |
| 1063 } else { | 1031 } else { |
| 1064 ASSERT(int_obj.IsBigint()); | 1032 ASSERT(int_obj.IsBigint()); |
| 1065 Bigint& bigint = Bigint::Handle(); | 1033 Bigint& bigint = Bigint::Handle(); |
| 1066 bigint ^= int_obj.raw(); | 1034 bigint ^= int_obj.raw(); |
| 1067 if (BigintOperations::FitsIntoUint64(bigint)) { | 1035 if (BigintOperations::FitsIntoUint64(bigint)) { |
| 1068 *value = BigintOperations::ToUint64(bigint); | 1036 *value = BigintOperations::ToUint64(bigint); |
| 1069 return Api::Success(); | 1037 return Api::Success(); |
| 1070 } | 1038 } |
| 1071 } | 1039 } |
| 1072 return Api::Error("%s: Integer %s cannot be represented as a uint64_t.", | 1040 return Api::NewError("%s: Integer %s cannot be represented as a uint64_t.", |
| 1073 CURRENT_FUNC, int_obj.ToCString()); | 1041 CURRENT_FUNC, int_obj.ToCString()); |
| 1074 } | 1042 } |
| 1075 | 1043 |
| 1076 | 1044 |
| 1077 DART_EXPORT Dart_Handle Dart_IntegerToHexCString(Dart_Handle integer, | 1045 DART_EXPORT Dart_Handle Dart_IntegerToHexCString(Dart_Handle integer, |
| 1078 const char** value) { | 1046 const char** value) { |
| 1079 DARTSCOPE(Isolate::Current()); | 1047 DARTSCOPE(Isolate::Current()); |
| 1080 const Integer& int_obj = Api::UnwrapIntegerHandle(integer); | 1048 const Integer& int_obj = Api::UnwrapIntegerHandle(integer); |
| 1081 if (int_obj.IsNull()) { | 1049 if (int_obj.IsNull()) { |
| 1082 RETURN_TYPE_ERROR(integer, Integer); | 1050 RETURN_TYPE_ERROR(integer, Integer); |
| 1083 } | 1051 } |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1190 | 1158 |
| 1191 DART_EXPORT Dart_Handle Dart_StringLength(Dart_Handle str, intptr_t* len) { | 1159 DART_EXPORT Dart_Handle Dart_StringLength(Dart_Handle str, intptr_t* len) { |
| 1192 DARTSCOPE(Isolate::Current()); | 1160 DARTSCOPE(Isolate::Current()); |
| 1193 const Object& obj = Object::Handle(Api::UnwrapHandle(str)); | 1161 const Object& obj = Object::Handle(Api::UnwrapHandle(str)); |
| 1194 if (obj.IsString()) { | 1162 if (obj.IsString()) { |
| 1195 String& string_obj = String::Handle(); | 1163 String& string_obj = String::Handle(); |
| 1196 string_obj ^= obj.raw(); | 1164 string_obj ^= obj.raw(); |
| 1197 *len = string_obj.Length(); | 1165 *len = string_obj.Length(); |
| 1198 return Api::Success(); | 1166 return Api::Success(); |
| 1199 } | 1167 } |
| 1200 return Api::Error("Object is not a String"); | 1168 return Api::NewError("Object is not a String"); |
| 1201 } | 1169 } |
| 1202 | 1170 |
| 1203 | 1171 |
| 1204 DART_EXPORT Dart_Handle Dart_NewString(const char* str) { | 1172 DART_EXPORT Dart_Handle Dart_NewString(const char* str) { |
| 1205 DARTSCOPE(Isolate::Current()); | 1173 DARTSCOPE(Isolate::Current()); |
| 1206 const String& obj = String::Handle(String::New(str)); | 1174 const String& obj = String::Handle(String::New(str)); |
| 1207 return Api::NewLocalHandle(obj); | 1175 return Api::NewLocalHandle(obj); |
| 1208 } | 1176 } |
| 1209 | 1177 |
| 1210 | 1178 |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1243 | 1211 |
| 1244 | 1212 |
| 1245 DART_EXPORT Dart_Handle Dart_ExternalStringGetPeer(Dart_Handle object, | 1213 DART_EXPORT Dart_Handle Dart_ExternalStringGetPeer(Dart_Handle object, |
| 1246 void** peer) { | 1214 void** peer) { |
| 1247 DARTSCOPE(Isolate::Current()); | 1215 DARTSCOPE(Isolate::Current()); |
| 1248 const String& str = Api::UnwrapStringHandle(object); | 1216 const String& str = Api::UnwrapStringHandle(object); |
| 1249 if (str.IsNull()) { | 1217 if (str.IsNull()) { |
| 1250 RETURN_TYPE_ERROR(object, String); | 1218 RETURN_TYPE_ERROR(object, String); |
| 1251 } | 1219 } |
| 1252 if (!str.IsExternal()) { | 1220 if (!str.IsExternal()) { |
| 1253 return Api::Error("%s expects argument 'object' to be an external String.", | 1221 return |
| 1222 Api::NewError("%s expects argument 'object' to be an external String.", |
| 1254 CURRENT_FUNC); | 1223 CURRENT_FUNC); |
| 1255 } | 1224 } |
| 1256 if (peer == NULL) { | 1225 if (peer == NULL) { |
| 1257 return Api::Error("%s expects argument 'peer' to be non-null.", | 1226 return Api::NewError("%s expects argument 'peer' to be non-null.", |
| 1258 CURRENT_FUNC); | 1227 CURRENT_FUNC); |
| 1259 } | 1228 } |
| 1260 *peer = str.GetPeer(); | 1229 *peer = str.GetPeer(); |
| 1261 return Api::Success(); | 1230 return Api::Success(); |
| 1262 } | 1231 } |
| 1263 | 1232 |
| 1264 | 1233 |
| 1265 DART_EXPORT Dart_Handle Dart_NewExternalString8(const uint8_t* codepoints, | 1234 DART_EXPORT Dart_Handle Dart_NewExternalString8(const uint8_t* codepoints, |
| 1266 intptr_t length, | 1235 intptr_t length, |
| 1267 void* peer, | 1236 void* peer, |
| 1268 Dart_PeerFinalizer callback) { | 1237 Dart_PeerFinalizer callback) { |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1306 if (string_obj.CharSize() == String::kOneByteChar) { | 1275 if (string_obj.CharSize() == String::kOneByteChar) { |
| 1307 intptr_t str_len = string_obj.Length(); | 1276 intptr_t str_len = string_obj.Length(); |
| 1308 intptr_t copy_len = (str_len > *length) ? *length : str_len; | 1277 intptr_t copy_len = (str_len > *length) ? *length : str_len; |
| 1309 for (intptr_t i = 0; i < copy_len; i++) { | 1278 for (intptr_t i = 0; i < copy_len; i++) { |
| 1310 codepoints[i] = static_cast<uint8_t>(string_obj.CharAt(i)); | 1279 codepoints[i] = static_cast<uint8_t>(string_obj.CharAt(i)); |
| 1311 } | 1280 } |
| 1312 *length= copy_len; | 1281 *length= copy_len; |
| 1313 return Api::Success(); | 1282 return Api::Success(); |
| 1314 } | 1283 } |
| 1315 } | 1284 } |
| 1316 return Api::Error(obj.IsString() | 1285 return Api::NewError(obj.IsString() |
| 1317 ? "Object is not a String8" | 1286 ? "Object is not a String8" |
| 1318 : "Object is not a String"); | 1287 : "Object is not a String"); |
| 1319 } | 1288 } |
| 1320 | 1289 |
| 1321 | 1290 |
| 1322 DART_EXPORT Dart_Handle Dart_StringGet16(Dart_Handle str, | 1291 DART_EXPORT Dart_Handle Dart_StringGet16(Dart_Handle str, |
| 1323 uint16_t* codepoints, | 1292 uint16_t* codepoints, |
| 1324 intptr_t* length) { | 1293 intptr_t* length) { |
| 1325 DARTSCOPE(Isolate::Current()); | 1294 DARTSCOPE(Isolate::Current()); |
| 1326 const Object& obj = Object::Handle(Api::UnwrapHandle(str)); | 1295 const Object& obj = Object::Handle(Api::UnwrapHandle(str)); |
| 1327 if (obj.IsString()) { | 1296 if (obj.IsString()) { |
| 1328 String& string_obj = String::Handle(); | 1297 String& string_obj = String::Handle(); |
| 1329 string_obj ^= obj.raw(); | 1298 string_obj ^= obj.raw(); |
| 1330 if (string_obj.CharSize() <= String::kTwoByteChar) { | 1299 if (string_obj.CharSize() <= String::kTwoByteChar) { |
| 1331 intptr_t str_len = string_obj.Length(); | 1300 intptr_t str_len = string_obj.Length(); |
| 1332 intptr_t copy_len = (str_len > *length) ? *length : str_len; | 1301 intptr_t copy_len = (str_len > *length) ? *length : str_len; |
| 1333 for (intptr_t i = 0; i < copy_len; i++) { | 1302 for (intptr_t i = 0; i < copy_len; i++) { |
| 1334 codepoints[i] = static_cast<uint16_t>(string_obj.CharAt(i)); | 1303 codepoints[i] = static_cast<uint16_t>(string_obj.CharAt(i)); |
| 1335 } | 1304 } |
| 1336 *length = copy_len; | 1305 *length = copy_len; |
| 1337 return Api::Success(); | 1306 return Api::Success(); |
| 1338 } | 1307 } |
| 1339 } | 1308 } |
| 1340 return Api::Error(obj.IsString() | 1309 return Api::NewError(obj.IsString() |
| 1341 ? "Object is not a String16" | 1310 ? "Object is not a String16" |
| 1342 : "Object is not a String"); | 1311 : "Object is not a String"); |
| 1343 } | 1312 } |
| 1344 | 1313 |
| 1345 | 1314 |
| 1346 DART_EXPORT Dart_Handle Dart_StringGet32(Dart_Handle str, | 1315 DART_EXPORT Dart_Handle Dart_StringGet32(Dart_Handle str, |
| 1347 uint32_t* codepoints, | 1316 uint32_t* codepoints, |
| 1348 intptr_t* length) { | 1317 intptr_t* length) { |
| 1349 DARTSCOPE(Isolate::Current()); | 1318 DARTSCOPE(Isolate::Current()); |
| 1350 const Object& obj = Object::Handle(Api::UnwrapHandle(str)); | 1319 const Object& obj = Object::Handle(Api::UnwrapHandle(str)); |
| 1351 if (obj.IsString()) { | 1320 if (obj.IsString()) { |
| 1352 String& string_obj = String::Handle(); | 1321 String& string_obj = String::Handle(); |
| 1353 string_obj ^= obj.raw(); | 1322 string_obj ^= obj.raw(); |
| 1354 intptr_t str_len = string_obj.Length(); | 1323 intptr_t str_len = string_obj.Length(); |
| 1355 intptr_t copy_len = (str_len > *length) ? *length : str_len; | 1324 intptr_t copy_len = (str_len > *length) ? *length : str_len; |
| 1356 for (intptr_t i = 0; i < copy_len; i++) { | 1325 for (intptr_t i = 0; i < copy_len; i++) { |
| 1357 codepoints[i] = static_cast<uint32_t>(string_obj.CharAt(i)); | 1326 codepoints[i] = static_cast<uint32_t>(string_obj.CharAt(i)); |
| 1358 } | 1327 } |
| 1359 *length = copy_len; | 1328 *length = copy_len; |
| 1360 return Api::Success(); | 1329 return Api::Success(); |
| 1361 } | 1330 } |
| 1362 return Api::Error("Object is not a String"); | 1331 return Api::NewError("Object is not a String"); |
| 1363 } | 1332 } |
| 1364 | 1333 |
| 1365 | 1334 |
| 1366 DART_EXPORT Dart_Handle Dart_StringToCString(Dart_Handle object, | 1335 DART_EXPORT Dart_Handle Dart_StringToCString(Dart_Handle object, |
| 1367 const char** result) { | 1336 const char** result) { |
| 1368 DARTSCOPE(Isolate::Current()); | 1337 DARTSCOPE(Isolate::Current()); |
| 1369 const Object& obj = Object::Handle(Api::UnwrapHandle(object)); | 1338 const Object& obj = Object::Handle(Api::UnwrapHandle(object)); |
| 1370 if (obj.IsString()) { | 1339 if (obj.IsString()) { |
| 1371 const char* string_value = obj.ToCString(); | 1340 const char* string_value = obj.ToCString(); |
| 1372 intptr_t string_length = strlen(string_value); | 1341 intptr_t string_length = strlen(string_value); |
| 1373 char* res = reinterpret_cast<char*>(Api::Allocate(string_length + 1)); | 1342 char* res = reinterpret_cast<char*>(Api::Allocate(string_length + 1)); |
| 1374 if (res == NULL) { | 1343 if (res == NULL) { |
| 1375 return Api::Error("Unable to allocate memory"); | 1344 return Api::NewError("Unable to allocate memory"); |
| 1376 } | 1345 } |
| 1377 strncpy(res, string_value, string_length + 1); | 1346 strncpy(res, string_value, string_length + 1); |
| 1378 ASSERT(res[string_length] == '\0'); | 1347 ASSERT(res[string_length] == '\0'); |
| 1379 *result = res; | 1348 *result = res; |
| 1380 return Api::Success(); | 1349 return Api::Success(); |
| 1381 } | 1350 } |
| 1382 return Api::Error("Object is not a String"); | 1351 return Api::NewError("Object is not a String"); |
| 1383 } | 1352 } |
| 1384 | 1353 |
| 1385 | 1354 |
| 1386 // --- Lists --- | 1355 // --- Lists --- |
| 1387 | 1356 |
| 1388 | 1357 |
| 1389 static RawInstance* GetListInstance(Isolate* isolate, const Object& obj) { | 1358 static RawInstance* GetListInstance(Isolate* isolate, const Object& obj) { |
| 1390 if (obj.IsInstance()) { | 1359 if (obj.IsInstance()) { |
| 1391 Instance& instance = Instance::Handle(); | 1360 Instance& instance = Instance::Handle(); |
| 1392 instance ^= obj.raw(); | 1361 instance ^= obj.raw(); |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1451 if (retval.IsSmi() || retval.IsMint()) { | 1420 if (retval.IsSmi() || retval.IsMint()) { |
| 1452 Integer& integer = Integer::Handle(); | 1421 Integer& integer = Integer::Handle(); |
| 1453 integer ^= retval.raw(); | 1422 integer ^= retval.raw(); |
| 1454 *len = integer.AsInt64Value(); | 1423 *len = integer.AsInt64Value(); |
| 1455 } else if (retval.IsBigint()) { | 1424 } else if (retval.IsBigint()) { |
| 1456 Bigint& bigint = Bigint::Handle(); | 1425 Bigint& bigint = Bigint::Handle(); |
| 1457 bigint ^= retval.raw(); | 1426 bigint ^= retval.raw(); |
| 1458 if (BigintOperations::FitsIntoInt64(bigint)) { | 1427 if (BigintOperations::FitsIntoInt64(bigint)) { |
| 1459 *len = BigintOperations::ToInt64(bigint); | 1428 *len = BigintOperations::ToInt64(bigint); |
| 1460 } else { | 1429 } else { |
| 1461 result = Api::Error("Length of List object is greater than the " | 1430 result = |
| 1462 "maximum value that 'len' parameter can hold"); | 1431 Api::NewError("Length of List object is greater than the " |
| 1432 "maximum value that 'len' parameter can hold"); |
| 1463 } | 1433 } |
| 1464 } else if (retval.IsUnhandledException()) { | 1434 } else if (retval.IsError()) { |
| 1465 result = Api::ErrorFromException(retval); | 1435 result = Api::NewLocalHandle(retval); |
| 1466 } else { | 1436 } else { |
| 1467 result = Api::Error("Length of List object is not an integer"); | 1437 result = Api::NewError("Length of List object is not an integer"); |
| 1468 } | 1438 } |
| 1469 } else { | 1439 } else { |
| 1470 SetupErrorResult(&result); | 1440 SetupErrorResult(&result); |
| 1471 } | 1441 } |
| 1472 isolate->set_long_jump_base(base); | 1442 isolate->set_long_jump_base(base); |
| 1473 return result; | 1443 return result; |
| 1474 } | 1444 } |
| 1475 } | 1445 } |
| 1476 return Api::Error("Object does not implement the list inteface"); | 1446 return Api::NewError("Object does not implement the list inteface"); |
| 1477 } | 1447 } |
| 1478 | 1448 |
| 1479 | 1449 |
| 1480 static RawObject* GetListAt(Isolate* isolate, | 1450 static RawObject* GetListAt(Isolate* isolate, |
| 1481 const Instance& instance, | 1451 const Instance& instance, |
| 1482 const Integer& index, | 1452 const Integer& index, |
| 1483 const Function& function, | 1453 const Function& function, |
| 1484 Dart_Handle* result) { | 1454 Dart_Handle* result) { |
| 1485 ASSERT(isolate != NULL); | 1455 ASSERT(isolate != NULL); |
| 1486 ASSERT(result != NULL); | 1456 ASSERT(result != NULL); |
| 1487 LongJump* base = isolate->long_jump_base(); | 1457 LongJump* base = isolate->long_jump_base(); |
| 1488 LongJump jump; | 1458 LongJump jump; |
| 1489 isolate->set_long_jump_base(&jump); | 1459 isolate->set_long_jump_base(&jump); |
| 1490 if (setjmp(*jump.Set()) == 0) { | 1460 if (setjmp(*jump.Set()) == 0) { |
| 1491 Instance& retval = Instance::Handle(); | 1461 Instance& retval = Instance::Handle(); |
| 1492 GrowableArray<const Object*> args(0); | 1462 GrowableArray<const Object*> args(0); |
| 1493 args.Add(&index); | 1463 args.Add(&index); |
| 1494 const Array& kNoArgumentNames = Array::Handle(); | 1464 const Array& kNoArgumentNames = Array::Handle(); |
| 1495 retval = DartEntry::InvokeDynamic(instance, | 1465 retval = DartEntry::InvokeDynamic(instance, |
| 1496 function, | 1466 function, |
| 1497 args, | 1467 args, |
| 1498 kNoArgumentNames); | 1468 kNoArgumentNames); |
| 1499 if (retval.IsUnhandledException()) { | 1469 if (retval.IsError()) { |
| 1500 *result = Api::ErrorFromException(retval); | 1470 *result = Api::NewLocalHandle(retval); |
| 1501 } else { | 1471 } else { |
| 1502 *result = Api::Success(); | 1472 *result = Api::Success(); |
| 1503 } | 1473 } |
| 1504 isolate->set_long_jump_base(base); | 1474 isolate->set_long_jump_base(base); |
| 1505 return retval.raw(); | 1475 return retval.raw(); |
| 1506 } | 1476 } |
| 1507 SetupErrorResult(result); | 1477 SetupErrorResult(result); |
| 1508 isolate->set_long_jump_base(base); | 1478 isolate->set_long_jump_base(base); |
| 1509 return Object::null(); | 1479 return Object::null(); |
| 1510 } | 1480 } |
| 1511 | 1481 |
| 1512 | 1482 |
| 1513 DART_EXPORT Dart_Handle Dart_ListGetAt(Dart_Handle list, intptr_t index) { | 1483 DART_EXPORT Dart_Handle Dart_ListGetAt(Dart_Handle list, intptr_t index) { |
| 1514 Isolate* isolate = Isolate::Current(); | 1484 Isolate* isolate = Isolate::Current(); |
| 1515 DARTSCOPE(isolate); | 1485 DARTSCOPE(isolate); |
| 1516 const Object& obj = Object::Handle(Api::UnwrapHandle(list)); | 1486 const Object& obj = Object::Handle(Api::UnwrapHandle(list)); |
| 1517 if (obj.IsArray()) { | 1487 if (obj.IsArray()) { |
| 1518 Array& array_obj = Array::Handle(); | 1488 Array& array_obj = Array::Handle(); |
| 1519 array_obj ^= obj.raw(); | 1489 array_obj ^= obj.raw(); |
| 1520 if ((index >= 0) && (index < array_obj.Length())) { | 1490 if ((index >= 0) && (index < array_obj.Length())) { |
| 1521 const Object& element = Object::Handle(array_obj.At(index)); | 1491 const Object& element = Object::Handle(array_obj.At(index)); |
| 1522 return Api::NewLocalHandle(element); | 1492 return Api::NewLocalHandle(element); |
| 1523 } | 1493 } |
| 1524 return Api::Error("Invalid index passed in to access array element"); | 1494 return Api::NewError("Invalid index passed in to access array element"); |
| 1525 } | 1495 } |
| 1526 // TODO(5526318): Make access to GrowableObjectArray more efficient. | 1496 // TODO(5526318): Make access to GrowableObjectArray more efficient. |
| 1527 // Now check and handle a dart object that implements the List interface. | 1497 // Now check and handle a dart object that implements the List interface. |
| 1528 const Instance& instance = Instance::Handle(GetListInstance(isolate, obj)); | 1498 const Instance& instance = Instance::Handle(GetListInstance(isolate, obj)); |
| 1529 if (!instance.IsNull()) { | 1499 if (!instance.IsNull()) { |
| 1530 String& name = String::Handle(String::New("[]")); | 1500 String& name = String::Handle(String::New("[]")); |
| 1531 const Function& function = Function::Handle( | 1501 const Function& function = Function::Handle( |
| 1532 Resolver::ResolveDynamic(instance, name, 2, 0)); | 1502 Resolver::ResolveDynamic(instance, name, 2, 0)); |
| 1533 if (!function.IsNull()) { | 1503 if (!function.IsNull()) { |
| 1534 Object& element = Object::Handle(); | 1504 Object& element = Object::Handle(); |
| 1535 Integer& indexobj = Integer::Handle(); | 1505 Integer& indexobj = Integer::Handle(); |
| 1536 Dart_Handle result; | 1506 Dart_Handle result; |
| 1537 indexobj = Integer::New(index); | 1507 indexobj = Integer::New(index); |
| 1538 element = GetListAt(isolate, instance, indexobj, function, &result); | 1508 element = GetListAt(isolate, instance, indexobj, function, &result); |
| 1539 if (::Dart_IsError(result)) { | 1509 if (::Dart_IsError(result)) { |
| 1540 return result; // Error condition. | 1510 return result; // Error condition. |
| 1541 } | 1511 } |
| 1542 return Api::NewLocalHandle(element); | 1512 return Api::NewLocalHandle(element); |
| 1543 } | 1513 } |
| 1544 } | 1514 } |
| 1545 return Api::Error("Object does not implement the 'List' interface"); | 1515 return Api::NewError("Object does not implement the 'List' interface"); |
| 1546 } | 1516 } |
| 1547 | 1517 |
| 1548 | 1518 |
| 1549 static void SetListAt(Isolate* isolate, | 1519 static void SetListAt(Isolate* isolate, |
| 1550 const Instance& instance, | 1520 const Instance& instance, |
| 1551 const Integer& index, | 1521 const Integer& index, |
| 1552 const Object& value, | 1522 const Object& value, |
| 1553 const Function& function, | 1523 const Function& function, |
| 1554 Dart_Handle* result) { | 1524 Dart_Handle* result) { |
| 1555 ASSERT(isolate != NULL); | 1525 ASSERT(isolate != NULL); |
| 1556 ASSERT(result != NULL); | 1526 ASSERT(result != NULL); |
| 1557 LongJump* base = isolate->long_jump_base(); | 1527 LongJump* base = isolate->long_jump_base(); |
| 1558 LongJump jump; | 1528 LongJump jump; |
| 1559 isolate->set_long_jump_base(&jump); | 1529 isolate->set_long_jump_base(&jump); |
| 1560 if (setjmp(*jump.Set()) == 0) { | 1530 if (setjmp(*jump.Set()) == 0) { |
| 1561 GrowableArray<const Object*> args(1); | 1531 GrowableArray<const Object*> args(1); |
| 1562 args.Add(&index); | 1532 args.Add(&index); |
| 1563 args.Add(&value); | 1533 args.Add(&value); |
| 1564 Instance& retval = Instance::Handle(); | 1534 Instance& retval = Instance::Handle(); |
| 1565 const Array& kNoArgumentNames = Array::Handle(); | 1535 const Array& kNoArgumentNames = Array::Handle(); |
| 1566 retval = DartEntry::InvokeDynamic(instance, | 1536 retval = DartEntry::InvokeDynamic(instance, |
| 1567 function, | 1537 function, |
| 1568 args, | 1538 args, |
| 1569 kNoArgumentNames); | 1539 kNoArgumentNames); |
| 1570 if (retval.IsUnhandledException()) { | 1540 if (retval.IsError()) { |
| 1571 *result = Api::ErrorFromException(retval); | 1541 *result = Api::NewLocalHandle(retval); |
| 1572 } else { | 1542 } else { |
| 1573 *result = Api::Success(); | 1543 *result = Api::Success(); |
| 1574 } | 1544 } |
| 1575 } else { | 1545 } else { |
| 1576 SetupErrorResult(result); | 1546 SetupErrorResult(result); |
| 1577 } | 1547 } |
| 1578 isolate->set_long_jump_base(base); | 1548 isolate->set_long_jump_base(base); |
| 1579 } | 1549 } |
| 1580 | 1550 |
| 1581 | 1551 |
| 1582 DART_EXPORT Dart_Handle Dart_ListSetAt(Dart_Handle list, | 1552 DART_EXPORT Dart_Handle Dart_ListSetAt(Dart_Handle list, |
| 1583 intptr_t index, | 1553 intptr_t index, |
| 1584 Dart_Handle value) { | 1554 Dart_Handle value) { |
| 1585 Isolate* isolate = Isolate::Current(); | 1555 Isolate* isolate = Isolate::Current(); |
| 1586 DARTSCOPE(isolate); | 1556 DARTSCOPE(isolate); |
| 1587 const Object& obj = Object::Handle(Api::UnwrapHandle(list)); | 1557 const Object& obj = Object::Handle(Api::UnwrapHandle(list)); |
| 1588 if (obj.IsArray()) { | 1558 if (obj.IsArray()) { |
| 1589 if (obj.IsImmutableArray()) { | 1559 if (obj.IsImmutableArray()) { |
| 1590 return Api::Error("Cannot modify immutable array"); | 1560 return Api::NewError("Cannot modify immutable array"); |
| 1591 } | 1561 } |
| 1592 Array& array_obj = Array::Handle(); | 1562 Array& array_obj = Array::Handle(); |
| 1593 array_obj ^= obj.raw(); | 1563 array_obj ^= obj.raw(); |
| 1594 const Object& value_obj = Object::Handle(Api::UnwrapHandle(value)); | 1564 const Object& value_obj = Object::Handle(Api::UnwrapHandle(value)); |
| 1595 if ((index >= 0) && (index < array_obj.Length())) { | 1565 if ((index >= 0) && (index < array_obj.Length())) { |
| 1596 array_obj.SetAt(index, value_obj); | 1566 array_obj.SetAt(index, value_obj); |
| 1597 return Api::Success(); | 1567 return Api::Success(); |
| 1598 } | 1568 } |
| 1599 return Api::Error("Invalid index passed in to set array element"); | 1569 return Api::NewError("Invalid index passed in to set array element"); |
| 1600 } | 1570 } |
| 1601 // TODO(5526318): Make access to GrowableObjectArray more efficient. | 1571 // TODO(5526318): Make access to GrowableObjectArray more efficient. |
| 1602 // Now check and handle a dart object that implements the List interface. | 1572 // Now check and handle a dart object that implements the List interface. |
| 1603 const Instance& instance = Instance::Handle(GetListInstance(isolate, obj)); | 1573 const Instance& instance = Instance::Handle(GetListInstance(isolate, obj)); |
| 1604 if (!instance.IsNull()) { | 1574 if (!instance.IsNull()) { |
| 1605 String& name = String::Handle(String::New("[]=")); | 1575 String& name = String::Handle(String::New("[]=")); |
| 1606 const Function& function = Function::Handle( | 1576 const Function& function = Function::Handle( |
| 1607 Resolver::ResolveDynamic(instance, name, 3, 0)); | 1577 Resolver::ResolveDynamic(instance, name, 3, 0)); |
| 1608 if (!function.IsNull()) { | 1578 if (!function.IsNull()) { |
| 1609 Dart_Handle result; | 1579 Dart_Handle result; |
| 1610 const Integer& index_obj = Integer::Handle(Integer::New(index)); | 1580 const Integer& index_obj = Integer::Handle(Integer::New(index)); |
| 1611 const Object& value_obj = Object::Handle(Api::UnwrapHandle(value)); | 1581 const Object& value_obj = Object::Handle(Api::UnwrapHandle(value)); |
| 1612 SetListAt(isolate, instance, index_obj, value_obj, function, &result); | 1582 SetListAt(isolate, instance, index_obj, value_obj, function, &result); |
| 1613 return result; | 1583 return result; |
| 1614 } | 1584 } |
| 1615 } | 1585 } |
| 1616 return Api::Error("Object does not implement the 'List' interface"); | 1586 return Api::NewError("Object does not implement the 'List' interface"); |
| 1617 } | 1587 } |
| 1618 | 1588 |
| 1619 | 1589 |
| 1620 DART_EXPORT Dart_Handle Dart_ListGetAsBytes(Dart_Handle list, | 1590 DART_EXPORT Dart_Handle Dart_ListGetAsBytes(Dart_Handle list, |
| 1621 intptr_t offset, | 1591 intptr_t offset, |
| 1622 uint8_t* native_array, | 1592 uint8_t* native_array, |
| 1623 intptr_t length) { | 1593 intptr_t length) { |
| 1624 Isolate* isolate = Isolate::Current(); | 1594 Isolate* isolate = Isolate::Current(); |
| 1625 DARTSCOPE(isolate); | 1595 DARTSCOPE(isolate); |
| 1626 const Object& obj = Object::Handle(Api::UnwrapHandle(list)); | 1596 const Object& obj = Object::Handle(Api::UnwrapHandle(list)); |
| 1627 if (obj.IsArray()) { | 1597 if (obj.IsArray()) { |
| 1628 Array& array_obj = Array::Handle(); | 1598 Array& array_obj = Array::Handle(); |
| 1629 array_obj ^= obj.raw(); | 1599 array_obj ^= obj.raw(); |
| 1630 if ((offset + length) <= array_obj.Length()) { | 1600 if ((offset + length) <= array_obj.Length()) { |
| 1631 Object& element = Object::Handle(); | 1601 Object& element = Object::Handle(); |
| 1632 Integer& integer = Integer::Handle(); | 1602 Integer& integer = Integer::Handle(); |
| 1633 for (int i = 0; i < length; i++) { | 1603 for (int i = 0; i < length; i++) { |
| 1634 element = array_obj.At(offset + i); | 1604 element = array_obj.At(offset + i); |
| 1635 if (!element.IsInteger()) { | 1605 if (!element.IsInteger()) { |
| 1636 return Api::Error("%s expects the argument 'list' to be " | 1606 return Api::NewError("%s expects the argument 'list' to be " |
| 1637 "a List of int", CURRENT_FUNC); | 1607 "a List of int", CURRENT_FUNC); |
| 1638 } | 1608 } |
| 1639 integer ^= element.raw(); | 1609 integer ^= element.raw(); |
| 1640 native_array[i] = static_cast<uint8_t>(integer.AsInt64Value() & 0xff); | 1610 native_array[i] = static_cast<uint8_t>(integer.AsInt64Value() & 0xff); |
| 1641 ASSERT(integer.AsInt64Value() <= 0xff); | 1611 ASSERT(integer.AsInt64Value() <= 0xff); |
| 1642 // TODO(hpayer): value should always be smaller then 0xff. Add error | 1612 // TODO(hpayer): value should always be smaller then 0xff. Add error |
| 1643 // handling. | 1613 // handling. |
| 1644 } | 1614 } |
| 1645 return Api::Success(); | 1615 return Api::Success(); |
| 1646 } | 1616 } |
| 1647 return Api::Error("Invalid length passed in to access array elements"); | 1617 return Api::NewError("Invalid length passed in to access array elements"); |
| 1648 } | 1618 } |
| 1649 // TODO(5526318): Make access to GrowableObjectArray more efficient. | 1619 // TODO(5526318): Make access to GrowableObjectArray more efficient. |
| 1650 // Now check and handle a dart object that implements the List interface. | 1620 // Now check and handle a dart object that implements the List interface. |
| 1651 const Instance& instance = Instance::Handle(GetListInstance(isolate, obj)); | 1621 const Instance& instance = Instance::Handle(GetListInstance(isolate, obj)); |
| 1652 if (!instance.IsNull()) { | 1622 if (!instance.IsNull()) { |
| 1653 String& name = String::Handle(String::New("[]")); | 1623 String& name = String::Handle(String::New("[]")); |
| 1654 const Function& function = Function::Handle( | 1624 const Function& function = Function::Handle( |
| 1655 Resolver::ResolveDynamic(instance, name, 2, 0)); | 1625 Resolver::ResolveDynamic(instance, name, 2, 0)); |
| 1656 if (!function.IsNull()) { | 1626 if (!function.IsNull()) { |
| 1657 Object& element = Object::Handle(); | 1627 Object& element = Object::Handle(); |
| 1658 Integer& intobj = Integer::Handle(); | 1628 Integer& intobj = Integer::Handle(); |
| 1659 Dart_Handle result; | 1629 Dart_Handle result; |
| 1660 for (int i = 0; i < length; i++) { | 1630 for (int i = 0; i < length; i++) { |
| 1661 intobj = Integer::New(offset + i); | 1631 intobj = Integer::New(offset + i); |
| 1662 element = GetListAt(isolate, instance, intobj, function, &result); | 1632 element = GetListAt(isolate, instance, intobj, function, &result); |
| 1663 if (::Dart_IsError(result)) { | 1633 if (::Dart_IsError(result)) { |
| 1664 return result; // Error condition. | 1634 return result; // Error condition. |
| 1665 } | 1635 } |
| 1666 if (!element.IsInteger()) { | 1636 if (!element.IsInteger()) { |
| 1667 return Api::Error("%s expects the argument 'list' to be " | 1637 return Api::NewError("%s expects the argument 'list' to be " |
| 1668 "a List of int", CURRENT_FUNC); | 1638 "a List of int", CURRENT_FUNC); |
| 1669 } | 1639 } |
| 1670 intobj ^= element.raw(); | 1640 intobj ^= element.raw(); |
| 1671 ASSERT(intobj.AsInt64Value() <= 0xff); | 1641 ASSERT(intobj.AsInt64Value() <= 0xff); |
| 1672 // TODO(hpayer): value should always be smaller then 0xff. Add error | 1642 // TODO(hpayer): value should always be smaller then 0xff. Add error |
| 1673 // handling. | 1643 // handling. |
| 1674 native_array[i] = static_cast<uint8_t>(intobj.AsInt64Value() & 0xff); | 1644 native_array[i] = static_cast<uint8_t>(intobj.AsInt64Value() & 0xff); |
| 1675 } | 1645 } |
| 1676 return Api::Success(); | 1646 return Api::Success(); |
| 1677 } | 1647 } |
| 1678 } | 1648 } |
| 1679 return Api::Error("Object does not implement the 'List' interface"); | 1649 return Api::NewError("Object does not implement the 'List' interface"); |
| 1680 } | 1650 } |
| 1681 | 1651 |
| 1682 | 1652 |
| 1683 DART_EXPORT Dart_Handle Dart_ListSetAsBytes(Dart_Handle list, | 1653 DART_EXPORT Dart_Handle Dart_ListSetAsBytes(Dart_Handle list, |
| 1684 intptr_t offset, | 1654 intptr_t offset, |
| 1685 uint8_t* native_array, | 1655 uint8_t* native_array, |
| 1686 intptr_t length) { | 1656 intptr_t length) { |
| 1687 Isolate* isolate = Isolate::Current(); | 1657 Isolate* isolate = Isolate::Current(); |
| 1688 DARTSCOPE(isolate); | 1658 DARTSCOPE(isolate); |
| 1689 const Object& obj = Object::Handle(Api::UnwrapHandle(list)); | 1659 const Object& obj = Object::Handle(Api::UnwrapHandle(list)); |
| 1690 if (obj.IsArray()) { | 1660 if (obj.IsArray()) { |
| 1691 if (obj.IsImmutableArray()) { | 1661 if (obj.IsImmutableArray()) { |
| 1692 return Api::Error("Cannot modify immutable array"); | 1662 return Api::NewError("Cannot modify immutable array"); |
| 1693 } | 1663 } |
| 1694 Array& array_obj = Array::Handle(); | 1664 Array& array_obj = Array::Handle(); |
| 1695 array_obj ^= obj.raw(); | 1665 array_obj ^= obj.raw(); |
| 1696 Integer& integer = Integer::Handle(); | 1666 Integer& integer = Integer::Handle(); |
| 1697 if ((offset + length) <= array_obj.Length()) { | 1667 if ((offset + length) <= array_obj.Length()) { |
| 1698 for (int i = 0; i < length; i++) { | 1668 for (int i = 0; i < length; i++) { |
| 1699 integer = Integer::New(native_array[i]); | 1669 integer = Integer::New(native_array[i]); |
| 1700 array_obj.SetAt(offset + i, integer); | 1670 array_obj.SetAt(offset + i, integer); |
| 1701 } | 1671 } |
| 1702 return Api::Success(); | 1672 return Api::Success(); |
| 1703 } | 1673 } |
| 1704 return Api::Error("Invalid length passed in to set array elements"); | 1674 return Api::NewError("Invalid length passed in to set array elements"); |
| 1705 } | 1675 } |
| 1706 // TODO(5526318): Make access to GrowableObjectArray more efficient. | 1676 // TODO(5526318): Make access to GrowableObjectArray more efficient. |
| 1707 // Now check and handle a dart object that implements the List interface. | 1677 // Now check and handle a dart object that implements the List interface. |
| 1708 const Instance& instance = Instance::Handle(GetListInstance(isolate, obj)); | 1678 const Instance& instance = Instance::Handle(GetListInstance(isolate, obj)); |
| 1709 if (!instance.IsNull()) { | 1679 if (!instance.IsNull()) { |
| 1710 String& name = String::Handle(String::New("[]=")); | 1680 String& name = String::Handle(String::New("[]=")); |
| 1711 const Function& function = Function::Handle( | 1681 const Function& function = Function::Handle( |
| 1712 Resolver::ResolveDynamic(instance, name, 3, 0)); | 1682 Resolver::ResolveDynamic(instance, name, 3, 0)); |
| 1713 if (!function.IsNull()) { | 1683 if (!function.IsNull()) { |
| 1714 Integer& indexobj = Integer::Handle(); | 1684 Integer& indexobj = Integer::Handle(); |
| 1715 Integer& valueobj = Integer::Handle(); | 1685 Integer& valueobj = Integer::Handle(); |
| 1716 Dart_Handle result; | 1686 Dart_Handle result; |
| 1717 for (int i = 0; i < length; i++) { | 1687 for (int i = 0; i < length; i++) { |
| 1718 indexobj = Integer::New(offset + i); | 1688 indexobj = Integer::New(offset + i); |
| 1719 valueobj = Integer::New(native_array[i]); | 1689 valueobj = Integer::New(native_array[i]); |
| 1720 SetListAt(isolate, instance, indexobj, valueobj, function, &result); | 1690 SetListAt(isolate, instance, indexobj, valueobj, function, &result); |
| 1721 if (::Dart_IsError(result)) { | 1691 if (::Dart_IsError(result)) { |
| 1722 return result; // Error condition. | 1692 return result; // Error condition. |
| 1723 } | 1693 } |
| 1724 } | 1694 } |
| 1725 return Api::Success(); | 1695 return Api::Success(); |
| 1726 } | 1696 } |
| 1727 } | 1697 } |
| 1728 return Api::Error("Object does not implement the 'List' interface"); | 1698 return Api::NewError("Object does not implement the 'List' interface"); |
| 1729 } | 1699 } |
| 1730 | 1700 |
| 1731 | 1701 |
| 1732 // --- Closures --- | 1702 // --- Closures --- |
| 1733 | 1703 |
| 1734 | 1704 |
| 1735 DART_EXPORT bool Dart_IsClosure(Dart_Handle object) { | 1705 DART_EXPORT bool Dart_IsClosure(Dart_Handle object) { |
| 1736 DARTSCOPE(Isolate::Current()); | 1706 DARTSCOPE(Isolate::Current()); |
| 1737 const Object& obj = Object::Handle(Api::UnwrapHandle(object)); | 1707 const Object& obj = Object::Handle(Api::UnwrapHandle(object)); |
| 1738 return obj.IsClosure(); | 1708 return obj.IsClosure(); |
| 1739 } | 1709 } |
| 1740 | 1710 |
| 1741 | 1711 |
| 1742 // NOTE: Need to pass 'result' as a parameter here in order to avoid | 1712 // NOTE: Need to pass 'result' as a parameter here in order to avoid |
| 1743 // warning: variable 'result' might be clobbered by 'longjmp' or 'vfork' | 1713 // warning: variable 'result' might be clobbered by 'longjmp' or 'vfork' |
| 1744 // which shows up because of the use of setjmp. | 1714 // which shows up because of the use of setjmp. |
| 1745 static void InvokeClosure(Isolate* isolate, | 1715 static void InvokeClosure(Isolate* isolate, |
| 1746 const Closure& closure, | 1716 const Closure& closure, |
| 1747 GrowableArray<const Object*>& args, | 1717 GrowableArray<const Object*>& args, |
| 1748 Dart_Handle* result) { | 1718 Dart_Handle* result) { |
| 1749 ASSERT(isolate != NULL); | 1719 ASSERT(isolate != NULL); |
| 1750 LongJump* base = isolate->long_jump_base(); | 1720 LongJump* base = isolate->long_jump_base(); |
| 1751 LongJump jump; | 1721 LongJump jump; |
| 1752 isolate->set_long_jump_base(&jump); | 1722 isolate->set_long_jump_base(&jump); |
| 1753 if (setjmp(*jump.Set()) == 0) { | 1723 if (setjmp(*jump.Set()) == 0) { |
| 1754 const Array& kNoArgumentNames = Array::Handle(); | 1724 const Array& kNoArgumentNames = Array::Handle(); |
| 1755 const Instance& retval = Instance::Handle( | 1725 const Instance& retval = Instance::Handle( |
| 1756 DartEntry::InvokeClosure(closure, args, kNoArgumentNames)); | 1726 DartEntry::InvokeClosure(closure, args, kNoArgumentNames)); |
| 1757 if (retval.IsUnhandledException()) { | 1727 *result = Api::NewLocalHandle(retval); |
| 1758 *result = Api::ErrorFromException(retval); | |
| 1759 } else { | |
| 1760 *result = Api::NewLocalHandle(retval); | |
| 1761 } | |
| 1762 } else { | 1728 } else { |
| 1763 SetupErrorResult(result); | 1729 SetupErrorResult(result); |
| 1764 } | 1730 } |
| 1765 isolate->set_long_jump_base(base); | 1731 isolate->set_long_jump_base(base); |
| 1766 } | 1732 } |
| 1767 | 1733 |
| 1768 | 1734 |
| 1769 DART_EXPORT Dart_Handle Dart_InvokeClosure(Dart_Handle closure, | 1735 DART_EXPORT Dart_Handle Dart_InvokeClosure(Dart_Handle closure, |
| 1770 int number_of_arguments, | 1736 int number_of_arguments, |
| 1771 Dart_Handle* arguments) { | 1737 Dart_Handle* arguments) { |
| 1772 Isolate* isolate = Isolate::Current(); | 1738 Isolate* isolate = Isolate::Current(); |
| 1773 DARTSCOPE(isolate); | 1739 DARTSCOPE(isolate); |
| 1774 const Object& obj = Object::Handle(Api::UnwrapHandle(closure)); | 1740 const Object& obj = Object::Handle(Api::UnwrapHandle(closure)); |
| 1775 if (obj.IsNull()) { | 1741 if (obj.IsNull()) { |
| 1776 return Api::Error("Null object passed in to invoke closure"); | 1742 return Api::NewError("Null object passed in to invoke closure"); |
| 1777 } | 1743 } |
| 1778 if (!obj.IsClosure()) { | 1744 if (!obj.IsClosure()) { |
| 1779 return Api::Error("Invalid closure passed to invoke closure"); | 1745 return Api::NewError("Invalid closure passed to invoke closure"); |
| 1780 } | 1746 } |
| 1781 ASSERT(ClassFinalizer::AllClassesFinalized()); | 1747 ASSERT(ClassFinalizer::AllClassesFinalized()); |
| 1782 | 1748 |
| 1783 // Now try to invoke the closure. | 1749 // Now try to invoke the closure. |
| 1784 Closure& closure_obj = Closure::Handle(); | 1750 Closure& closure_obj = Closure::Handle(); |
| 1785 closure_obj ^= obj.raw(); | 1751 closure_obj ^= obj.raw(); |
| 1786 Dart_Handle retval; | 1752 Dart_Handle retval; |
| 1787 GrowableArray<const Object*> dart_arguments(number_of_arguments); | 1753 GrowableArray<const Object*> dart_arguments(number_of_arguments); |
| 1788 for (int i = 0; i < number_of_arguments; i++) { | 1754 for (int i = 0; i < number_of_arguments; i++) { |
| 1789 const Object& arg = Object::Handle(Api::UnwrapHandle(arguments[i])); | 1755 const Object& arg = Object::Handle(Api::UnwrapHandle(arguments[i])); |
| (...skipping 26 matching lines...) Expand all Loading... |
| 1816 DART_EXPORT Dart_Handle Dart_InvokeStatic(Dart_Handle library_in, | 1782 DART_EXPORT Dart_Handle Dart_InvokeStatic(Dart_Handle library_in, |
| 1817 Dart_Handle class_name_in, | 1783 Dart_Handle class_name_in, |
| 1818 Dart_Handle function_name_in, | 1784 Dart_Handle function_name_in, |
| 1819 int number_of_arguments, | 1785 int number_of_arguments, |
| 1820 Dart_Handle* arguments) { | 1786 Dart_Handle* arguments) { |
| 1821 Isolate* isolate = Isolate::Current(); | 1787 Isolate* isolate = Isolate::Current(); |
| 1822 DARTSCOPE(isolate); | 1788 DARTSCOPE(isolate); |
| 1823 // Finalize all classes. | 1789 // Finalize all classes. |
| 1824 const char* msg = CheckIsolateState(isolate); | 1790 const char* msg = CheckIsolateState(isolate); |
| 1825 if (msg != NULL) { | 1791 if (msg != NULL) { |
| 1826 return Api::Error(msg); | 1792 return Api::NewError(msg); |
| 1827 } | 1793 } |
| 1828 | 1794 |
| 1829 // Now try to resolve and invoke the static function. | 1795 // Now try to resolve and invoke the static function. |
| 1830 const Library& library = | 1796 const Library& library = |
| 1831 Library::CheckedHandle(Api::UnwrapHandle(library_in)); | 1797 Library::CheckedHandle(Api::UnwrapHandle(library_in)); |
| 1832 if (library.IsNull()) { | 1798 if (library.IsNull()) { |
| 1833 return Api::Error("No library specified"); | 1799 return Api::NewError("No library specified"); |
| 1834 } | 1800 } |
| 1835 const String& class_name = | 1801 const String& class_name = |
| 1836 String::CheckedHandle(Api::UnwrapHandle(class_name_in)); | 1802 String::CheckedHandle(Api::UnwrapHandle(class_name_in)); |
| 1837 const String& function_name = | 1803 const String& function_name = |
| 1838 String::CheckedHandle(Api::UnwrapHandle(function_name_in)); | 1804 String::CheckedHandle(Api::UnwrapHandle(function_name_in)); |
| 1839 const Function& function = Function::Handle( | 1805 const Function& function = Function::Handle( |
| 1840 Resolver::ResolveStatic(library, | 1806 Resolver::ResolveStatic(library, |
| 1841 class_name, | 1807 class_name, |
| 1842 function_name, | 1808 function_name, |
| 1843 number_of_arguments, | 1809 number_of_arguments, |
| 1844 Array::Handle(), // Named arguments are not yet | 1810 Array::Handle(), // Named arguments are not yet |
| 1845 // supported in the API. | 1811 // supported in the API. |
| 1846 Resolver::kIsQualified)); | 1812 Resolver::kIsQualified)); |
| 1847 if (function.IsNull()) { | 1813 if (function.IsNull()) { |
| 1848 char* msg; | 1814 char* msg; |
| 1849 if (class_name.IsNull()) { | 1815 if (class_name.IsNull()) { |
| 1850 const char* format = "Unable to find entrypoint: %s()"; | 1816 const char* format = "Unable to find entrypoint: %s()"; |
| 1851 intptr_t length = OS::SNPrint(NULL, 0, format, function_name.ToCString()); | 1817 intptr_t length = OS::SNPrint(NULL, 0, format, function_name.ToCString()); |
| 1852 msg = reinterpret_cast<char*>(Api::Allocate(length + 1)); | 1818 msg = reinterpret_cast<char*>(Api::Allocate(length + 1)); |
| 1853 OS::SNPrint(msg, (length + 1), format, function_name.ToCString()); | 1819 OS::SNPrint(msg, (length + 1), format, function_name.ToCString()); |
| 1854 } else { | 1820 } else { |
| 1855 const char* format = "Unable to find entrypoint: static %s.%s()"; | 1821 const char* format = "Unable to find entrypoint: static %s.%s()"; |
| 1856 intptr_t length = OS::SNPrint(NULL, 0, format, | 1822 intptr_t length = OS::SNPrint(NULL, 0, format, |
| 1857 class_name.ToCString(), | 1823 class_name.ToCString(), |
| 1858 function_name.ToCString()); | 1824 function_name.ToCString()); |
| 1859 msg = reinterpret_cast<char*>(Api::Allocate(length + 1)); | 1825 msg = reinterpret_cast<char*>(Api::Allocate(length + 1)); |
| 1860 OS::SNPrint(msg, (length + 1), format, | 1826 OS::SNPrint(msg, (length + 1), format, |
| 1861 class_name.ToCString(), function_name.ToCString()); | 1827 class_name.ToCString(), function_name.ToCString()); |
| 1862 } | 1828 } |
| 1863 return Api::Error(msg); | 1829 return Api::NewError(msg); |
| 1864 } | 1830 } |
| 1865 Dart_Handle retval; | 1831 Dart_Handle retval; |
| 1866 GrowableArray<const Object*> dart_arguments(number_of_arguments); | 1832 GrowableArray<const Object*> dart_arguments(number_of_arguments); |
| 1867 for (int i = 0; i < number_of_arguments; i++) { | 1833 for (int i = 0; i < number_of_arguments; i++) { |
| 1868 const Object& arg = Object::Handle(Api::UnwrapHandle(arguments[i])); | 1834 const Object& arg = Object::Handle(Api::UnwrapHandle(arguments[i])); |
| 1869 dart_arguments.Add(&arg); | 1835 dart_arguments.Add(&arg); |
| 1870 } | 1836 } |
| 1871 InvokeStatic(isolate, function, dart_arguments, &retval); | 1837 InvokeStatic(isolate, function, dart_arguments, &retval); |
| 1872 return retval; | 1838 return retval; |
| 1873 } | 1839 } |
| 1874 | 1840 |
| 1875 | 1841 |
| 1876 DART_EXPORT Dart_Handle Dart_InvokeDynamic(Dart_Handle object, | 1842 DART_EXPORT Dart_Handle Dart_InvokeDynamic(Dart_Handle object, |
| 1877 Dart_Handle function_name, | 1843 Dart_Handle function_name, |
| 1878 int number_of_arguments, | 1844 int number_of_arguments, |
| 1879 Dart_Handle* arguments) { | 1845 Dart_Handle* arguments) { |
| 1880 Isolate* isolate = Isolate::Current(); | 1846 Isolate* isolate = Isolate::Current(); |
| 1881 DARTSCOPE(isolate); | 1847 DARTSCOPE(isolate); |
| 1882 const Object& obj = Object::Handle(Api::UnwrapHandle(object)); | 1848 const Object& obj = Object::Handle(Api::UnwrapHandle(object)); |
| 1883 // Let the resolver figure out the correct target for null receiver. | 1849 // Let the resolver figure out the correct target for null receiver. |
| 1884 // E.g., (null).toString() should execute correctly. | 1850 // E.g., (null).toString() should execute correctly. |
| 1885 if (!obj.IsNull() && !obj.IsInstance()) { | 1851 if (!obj.IsNull() && !obj.IsInstance()) { |
| 1886 return Api::Error( | 1852 return Api::NewError( |
| 1887 "Invalid receiver (not instance) passed to invoke dynamic"); | 1853 "Invalid receiver (not instance) passed to invoke dynamic"); |
| 1888 } | 1854 } |
| 1889 if (function_name == NULL) { | 1855 if (function_name == NULL) { |
| 1890 return Api::Error("Invalid function name specified"); | 1856 return Api::NewError("Invalid function name specified"); |
| 1891 } | 1857 } |
| 1892 ASSERT(ClassFinalizer::AllClassesFinalized()); | 1858 ASSERT(ClassFinalizer::AllClassesFinalized()); |
| 1893 | 1859 |
| 1894 // Now try to resolve and invoke the dynamic function on this object. | 1860 // Now try to resolve and invoke the dynamic function on this object. |
| 1895 Instance& receiver = Instance::Handle(); | 1861 Instance& receiver = Instance::Handle(); |
| 1896 receiver ^= obj.raw(); | 1862 receiver ^= obj.raw(); |
| 1897 const String& name = String::CheckedHandle(Api::UnwrapHandle(function_name)); | 1863 const String& name = String::CheckedHandle(Api::UnwrapHandle(function_name)); |
| 1898 const Function& function = Function::Handle( | 1864 const Function& function = Function::Handle( |
| 1899 Resolver::ResolveDynamic(receiver, | 1865 Resolver::ResolveDynamic(receiver, |
| 1900 name, | 1866 name, |
| 1901 (number_of_arguments + 1), | 1867 (number_of_arguments + 1), |
| 1902 0)); // Named args not yet supported in API. | 1868 0)); // Named args not yet supported in API. |
| 1903 if (function.IsNull()) { | 1869 if (function.IsNull()) { |
| 1904 // TODO(5415268): Invoke noSuchMethod instead of failing. | 1870 // TODO(5415268): Invoke noSuchMethod instead of failing. |
| 1905 OS::PrintErr("Unable to find instance function: %s\n", name.ToCString()); | 1871 OS::PrintErr("Unable to find instance function: %s\n", name.ToCString()); |
| 1906 return Api::Error("Unable to find instance function"); | 1872 return Api::NewError("Unable to find instance function"); |
| 1907 } | 1873 } |
| 1908 Dart_Handle retval; | 1874 Dart_Handle retval; |
| 1909 GrowableArray<const Object*> dart_arguments(number_of_arguments); | 1875 GrowableArray<const Object*> dart_arguments(number_of_arguments); |
| 1910 for (int i = 0; i < number_of_arguments; i++) { | 1876 for (int i = 0; i < number_of_arguments; i++) { |
| 1911 const Object& arg = Object::Handle(Api::UnwrapHandle(arguments[i])); | 1877 const Object& arg = Object::Handle(Api::UnwrapHandle(arguments[i])); |
| 1912 dart_arguments.Add(&arg); | 1878 dart_arguments.Add(&arg); |
| 1913 } | 1879 } |
| 1914 InvokeDynamic(isolate, receiver, function, dart_arguments, &retval); | 1880 InvokeDynamic(isolate, receiver, function, dart_arguments, &retval); |
| 1915 return retval; | 1881 return retval; |
| 1916 } | 1882 } |
| (...skipping 16 matching lines...) Expand all Loading... |
| 1933 return value.raw() == Object::sentinel(); | 1899 return value.raw() == Object::sentinel(); |
| 1934 } | 1900 } |
| 1935 | 1901 |
| 1936 | 1902 |
| 1937 static Dart_Handle LookupStaticField(Dart_Handle clazz, | 1903 static Dart_Handle LookupStaticField(Dart_Handle clazz, |
| 1938 Dart_Handle field_name, | 1904 Dart_Handle field_name, |
| 1939 bool is_getter) { | 1905 bool is_getter) { |
| 1940 const Object& param1 = Object::Handle(Api::UnwrapHandle(clazz)); | 1906 const Object& param1 = Object::Handle(Api::UnwrapHandle(clazz)); |
| 1941 const Object& param2 = Object::Handle(Api::UnwrapHandle(field_name)); | 1907 const Object& param2 = Object::Handle(Api::UnwrapHandle(field_name)); |
| 1942 if (param1.IsNull() || !param1.IsClass()) { | 1908 if (param1.IsNull() || !param1.IsClass()) { |
| 1943 return Api::Error("Invalid class specified"); | 1909 return Api::NewError("Invalid class specified"); |
| 1944 } | 1910 } |
| 1945 if (param2.IsNull() || !param2.IsString()) { | 1911 if (param2.IsNull() || !param2.IsString()) { |
| 1946 return Api::Error("Invalid field name specified"); | 1912 return Api::NewError("Invalid field name specified"); |
| 1947 } | 1913 } |
| 1948 Class& cls = Class::Handle(); | 1914 Class& cls = Class::Handle(); |
| 1949 cls ^= param1.raw(); | 1915 cls ^= param1.raw(); |
| 1950 String& fld_name = String::Handle(); | 1916 String& fld_name = String::Handle(); |
| 1951 fld_name ^= param2.raw(); | 1917 fld_name ^= param2.raw(); |
| 1952 const Field& fld = Field::Handle(cls.LookupStaticField(fld_name)); | 1918 const Field& fld = Field::Handle(cls.LookupStaticField(fld_name)); |
| 1953 if (is_getter && UseGetterForStaticField(fld)) { | 1919 if (is_getter && UseGetterForStaticField(fld)) { |
| 1954 const String& func_name = String::Handle(Field::GetterName(fld_name)); | 1920 const String& func_name = String::Handle(Field::GetterName(fld_name)); |
| 1955 const Function& function = | 1921 const Function& function = |
| 1956 Function::Handle(cls.LookupStaticFunction(func_name)); | 1922 Function::Handle(cls.LookupStaticFunction(func_name)); |
| 1957 if (!function.IsNull()) { | 1923 if (!function.IsNull()) { |
| 1958 return Api::NewLocalHandle(function); | 1924 return Api::NewLocalHandle(function); |
| 1959 } | 1925 } |
| 1960 return Api::Error("Specified field is not found in the class"); | 1926 return Api::NewError("Specified field is not found in the class"); |
| 1961 } | 1927 } |
| 1962 if (fld.IsNull()) { | 1928 if (fld.IsNull()) { |
| 1963 return Api::Error("Specified field is not found in the class"); | 1929 return Api::NewError("Specified field is not found in the class"); |
| 1964 } | 1930 } |
| 1965 return Api::NewLocalHandle(fld); | 1931 return Api::NewLocalHandle(fld); |
| 1966 } | 1932 } |
| 1967 | 1933 |
| 1968 | 1934 |
| 1969 static Dart_Handle LookupInstanceField(const Object& object, | 1935 static Dart_Handle LookupInstanceField(const Object& object, |
| 1970 Dart_Handle name, | 1936 Dart_Handle name, |
| 1971 bool is_getter) { | 1937 bool is_getter) { |
| 1972 const Object& param = Object::Handle(Api::UnwrapHandle(name)); | 1938 const Object& param = Object::Handle(Api::UnwrapHandle(name)); |
| 1973 if (param.IsNull() || !param.IsString()) { | 1939 if (param.IsNull() || !param.IsString()) { |
| 1974 return Api::Error("Invalid field name specified"); | 1940 return Api::NewError("Invalid field name specified"); |
| 1975 } | 1941 } |
| 1976 String& field_name = String::Handle(); | 1942 String& field_name = String::Handle(); |
| 1977 field_name ^= param.raw(); | 1943 field_name ^= param.raw(); |
| 1978 String& func_name = String::Handle(); | 1944 String& func_name = String::Handle(); |
| 1979 Field& fld = Field::Handle(); | 1945 Field& fld = Field::Handle(); |
| 1980 Class& cls = Class::Handle(object.clazz()); | 1946 Class& cls = Class::Handle(object.clazz()); |
| 1981 while (!cls.IsNull()) { | 1947 while (!cls.IsNull()) { |
| 1982 fld = cls.LookupInstanceField(field_name); | 1948 fld = cls.LookupInstanceField(field_name); |
| 1983 if (!fld.IsNull()) { | 1949 if (!fld.IsNull()) { |
| 1984 if (!is_getter && fld.is_final()) { | 1950 if (!is_getter && fld.is_final()) { |
| 1985 return Api::Error("Cannot set value of final fields"); | 1951 return Api::NewError("Cannot set value of final fields"); |
| 1986 } | 1952 } |
| 1987 func_name = (is_getter | 1953 func_name = (is_getter |
| 1988 ? Field::GetterName(field_name) | 1954 ? Field::GetterName(field_name) |
| 1989 : Field::SetterName(field_name)); | 1955 : Field::SetterName(field_name)); |
| 1990 const Function& function = Function::Handle( | 1956 const Function& function = Function::Handle( |
| 1991 cls.LookupDynamicFunction(func_name)); | 1957 cls.LookupDynamicFunction(func_name)); |
| 1992 if (function.IsNull()) { | 1958 if (function.IsNull()) { |
| 1993 return Api::Error("Unable to find accessor function in the class"); | 1959 return Api::NewError("Unable to find accessor function in the class"); |
| 1994 } | 1960 } |
| 1995 return Api::NewLocalHandle(function); | 1961 return Api::NewLocalHandle(function); |
| 1996 } | 1962 } |
| 1997 cls = cls.SuperClass(); | 1963 cls = cls.SuperClass(); |
| 1998 } | 1964 } |
| 1999 return Api::Error("Unable to find field in the class"); | 1965 return Api::NewError("Unable to find field in the class"); |
| 2000 } | 1966 } |
| 2001 | 1967 |
| 2002 | 1968 |
| 2003 DART_EXPORT Dart_Handle Dart_GetStaticField(Dart_Handle cls, | 1969 DART_EXPORT Dart_Handle Dart_GetStaticField(Dart_Handle cls, |
| 2004 Dart_Handle name) { | 1970 Dart_Handle name) { |
| 2005 Isolate* isolate = Isolate::Current(); | 1971 Isolate* isolate = Isolate::Current(); |
| 2006 DARTSCOPE(isolate); | 1972 DARTSCOPE(isolate); |
| 2007 Dart_Handle result = LookupStaticField(cls, name, kGetter); | 1973 Dart_Handle result = LookupStaticField(cls, name, kGetter); |
| 2008 if (::Dart_IsError(result)) { | 1974 if (::Dart_IsError(result)) { |
| 2009 return result; | 1975 return result; |
| (...skipping 21 matching lines...) Expand all Loading... |
| 2031 Dart_Handle name, | 1997 Dart_Handle name, |
| 2032 Dart_Handle value) { | 1998 Dart_Handle value) { |
| 2033 DARTSCOPE(Isolate::Current()); | 1999 DARTSCOPE(Isolate::Current()); |
| 2034 Dart_Handle result = LookupStaticField(cls, name, kSetter); | 2000 Dart_Handle result = LookupStaticField(cls, name, kSetter); |
| 2035 if (::Dart_IsError(result)) { | 2001 if (::Dart_IsError(result)) { |
| 2036 return result; | 2002 return result; |
| 2037 } | 2003 } |
| 2038 Field& fld = Field::Handle(); | 2004 Field& fld = Field::Handle(); |
| 2039 fld ^= Api::UnwrapHandle(result); | 2005 fld ^= Api::UnwrapHandle(result); |
| 2040 if (fld.is_final()) { | 2006 if (fld.is_final()) { |
| 2041 return Api::Error("Specified field is a static final field in the class"); | 2007 return Api::NewError( |
| 2008 "Specified field is a static final field in the class"); |
| 2042 } | 2009 } |
| 2043 const Object& val = Object::Handle(Api::UnwrapHandle(value)); | 2010 const Object& val = Object::Handle(Api::UnwrapHandle(value)); |
| 2044 Instance& instance = Instance::Handle(); | 2011 Instance& instance = Instance::Handle(); |
| 2045 instance ^= val.raw(); | 2012 instance ^= val.raw(); |
| 2046 fld.set_value(instance); | 2013 fld.set_value(instance); |
| 2047 return Api::NewLocalHandle(val); | 2014 return Api::NewLocalHandle(val); |
| 2048 } | 2015 } |
| 2049 | 2016 |
| 2050 | 2017 |
| 2051 DART_EXPORT Dart_Handle Dart_GetInstanceField(Dart_Handle obj, | 2018 DART_EXPORT Dart_Handle Dart_GetInstanceField(Dart_Handle obj, |
| 2052 Dart_Handle name) { | 2019 Dart_Handle name) { |
| 2053 Isolate* isolate = Isolate::Current(); | 2020 Isolate* isolate = Isolate::Current(); |
| 2054 DARTSCOPE(isolate); | 2021 DARTSCOPE(isolate); |
| 2055 const Object& param = Object::Handle(Api::UnwrapHandle(obj)); | 2022 const Object& param = Object::Handle(Api::UnwrapHandle(obj)); |
| 2056 if (param.IsNull() || !param.IsInstance()) { | 2023 if (param.IsNull() || !param.IsInstance()) { |
| 2057 return Api::Error("Invalid object passed in to access instance field"); | 2024 return Api::NewError("Invalid object passed in to access instance field"); |
| 2058 } | 2025 } |
| 2059 Instance& object = Instance::Handle(); | 2026 Instance& object = Instance::Handle(); |
| 2060 object ^= param.raw(); | 2027 object ^= param.raw(); |
| 2061 Dart_Handle result = LookupInstanceField(object, name, kGetter); | 2028 Dart_Handle result = LookupInstanceField(object, name, kGetter); |
| 2062 if (::Dart_IsError(result)) { | 2029 if (::Dart_IsError(result)) { |
| 2063 return result; | 2030 return result; |
| 2064 } | 2031 } |
| 2065 Function& func = Function::Handle(); | 2032 Function& func = Function::Handle(); |
| 2066 func ^= Api::UnwrapHandle(result); | 2033 func ^= Api::UnwrapHandle(result); |
| 2067 GrowableArray<const Object*> arguments; | 2034 GrowableArray<const Object*> arguments; |
| 2068 InvokeDynamic(isolate, object, func, arguments, &result); | 2035 InvokeDynamic(isolate, object, func, arguments, &result); |
| 2069 return result; | 2036 return result; |
| 2070 } | 2037 } |
| 2071 | 2038 |
| 2072 | 2039 |
| 2073 DART_EXPORT Dart_Handle Dart_SetInstanceField(Dart_Handle obj, | 2040 DART_EXPORT Dart_Handle Dart_SetInstanceField(Dart_Handle obj, |
| 2074 Dart_Handle name, | 2041 Dart_Handle name, |
| 2075 Dart_Handle value) { | 2042 Dart_Handle value) { |
| 2076 Isolate* isolate = Isolate::Current(); | 2043 Isolate* isolate = Isolate::Current(); |
| 2077 DARTSCOPE(isolate); | 2044 DARTSCOPE(isolate); |
| 2078 const Object& param = Object::Handle(Api::UnwrapHandle(obj)); | 2045 const Object& param = Object::Handle(Api::UnwrapHandle(obj)); |
| 2079 if (param.IsNull() || !param.IsInstance()) { | 2046 if (param.IsNull() || !param.IsInstance()) { |
| 2080 return Api::Error("Invalid object passed in to access instance field"); | 2047 return Api::NewError("Invalid object passed in to access instance field"); |
| 2081 } | 2048 } |
| 2082 Instance& object = Instance::Handle(); | 2049 Instance& object = Instance::Handle(); |
| 2083 object ^= param.raw(); | 2050 object ^= param.raw(); |
| 2084 Dart_Handle result = LookupInstanceField(object, name, kSetter); | 2051 Dart_Handle result = LookupInstanceField(object, name, kSetter); |
| 2085 if (::Dart_IsError(result)) { | 2052 if (::Dart_IsError(result)) { |
| 2086 return result; | 2053 return result; |
| 2087 } | 2054 } |
| 2088 Function& func = Function::Handle(); | 2055 Function& func = Function::Handle(); |
| 2089 func ^= Api::UnwrapHandle(result); | 2056 func ^= Api::UnwrapHandle(result); |
| 2090 GrowableArray<const Object*> arguments(1); | 2057 GrowableArray<const Object*> arguments(1); |
| 2091 const Object& arg = Object::Handle(Api::UnwrapHandle(value)); | 2058 const Object& arg = Object::Handle(Api::UnwrapHandle(value)); |
| 2092 arguments.Add(&arg); | 2059 arguments.Add(&arg); |
| 2093 InvokeDynamic(isolate, object, func, arguments, &result); | 2060 InvokeDynamic(isolate, object, func, arguments, &result); |
| 2094 return result; | 2061 return result; |
| 2095 } | 2062 } |
| 2096 | 2063 |
| 2097 | 2064 |
| 2098 DART_EXPORT Dart_Handle Dart_CreateNativeWrapperClass(Dart_Handle library, | 2065 DART_EXPORT Dart_Handle Dart_CreateNativeWrapperClass(Dart_Handle library, |
| 2099 Dart_Handle name, | 2066 Dart_Handle name, |
| 2100 int field_count) { | 2067 int field_count) { |
| 2101 Isolate* isolate = Isolate::Current(); | 2068 Isolate* isolate = Isolate::Current(); |
| 2102 DARTSCOPE(isolate); | 2069 DARTSCOPE(isolate); |
| 2103 const Object& param = Object::Handle(Api::UnwrapHandle(name)); | 2070 const Object& param = Object::Handle(Api::UnwrapHandle(name)); |
| 2104 if (param.IsNull() || !param.IsString() || field_count <= 0) { | 2071 if (param.IsNull() || !param.IsString() || field_count <= 0) { |
| 2105 return Api::Error( | 2072 return Api::NewError( |
| 2106 "Invalid arguments passed to Dart_CreateNativeWrapperClass"); | 2073 "Invalid arguments passed to Dart_CreateNativeWrapperClass"); |
| 2107 } | 2074 } |
| 2108 String& cls_name = String::Handle(); | 2075 String& cls_name = String::Handle(); |
| 2109 cls_name ^= param.raw(); | 2076 cls_name ^= param.raw(); |
| 2110 cls_name = String::NewSymbol(cls_name); | 2077 cls_name = String::NewSymbol(cls_name); |
| 2111 Library& lib = Library::Handle(); | 2078 Library& lib = Library::Handle(); |
| 2112 lib ^= Api::UnwrapHandle(library); | 2079 lib ^= Api::UnwrapHandle(library); |
| 2113 if (lib.IsNull()) { | 2080 if (lib.IsNull()) { |
| 2114 return Api::Error( | 2081 return Api::NewError( |
| 2115 "Invalid arguments passed to Dart_CreateNativeWrapperClass"); | 2082 "Invalid arguments passed to Dart_CreateNativeWrapperClass"); |
| 2116 } | 2083 } |
| 2117 const Class& cls = Class::Handle(Class::NewNativeWrapper(&lib, | 2084 const Class& cls = Class::Handle(Class::NewNativeWrapper(&lib, |
| 2118 cls_name, | 2085 cls_name, |
| 2119 field_count)); | 2086 field_count)); |
| 2120 if (cls.IsNull()) { | 2087 if (cls.IsNull()) { |
| 2121 return Api::Error( | 2088 return Api::NewError( |
| 2122 "Unable to create native wrapper class : already exists"); | 2089 "Unable to create native wrapper class : already exists"); |
| 2123 } | 2090 } |
| 2124 return Api::NewLocalHandle(cls); | 2091 return Api::NewLocalHandle(cls); |
| 2125 } | 2092 } |
| 2126 | 2093 |
| 2127 | 2094 |
| 2128 DART_EXPORT Dart_Handle Dart_GetNativeInstanceField(Dart_Handle obj, | 2095 DART_EXPORT Dart_Handle Dart_GetNativeInstanceField(Dart_Handle obj, |
| 2129 int index, | 2096 int index, |
| 2130 intptr_t* value) { | 2097 intptr_t* value) { |
| 2131 DARTSCOPE(Isolate::Current()); | 2098 DARTSCOPE(Isolate::Current()); |
| 2132 const Object& param = Object::Handle(Api::UnwrapHandle(obj)); | 2099 const Object& param = Object::Handle(Api::UnwrapHandle(obj)); |
| 2133 if (param.IsNull() || !param.IsInstance()) { | 2100 if (param.IsNull() || !param.IsInstance()) { |
| 2134 return Api::Error( | 2101 return Api::NewError( |
| 2135 "Invalid object passed in to access native instance field"); | 2102 "Invalid object passed in to access native instance field"); |
| 2136 } | 2103 } |
| 2137 Instance& object = Instance::Handle(); | 2104 Instance& object = Instance::Handle(); |
| 2138 object ^= param.raw(); | 2105 object ^= param.raw(); |
| 2139 if (!object.IsValidNativeIndex(index)) { | 2106 if (!object.IsValidNativeIndex(index)) { |
| 2140 return Api::Error( | 2107 return Api::NewError( |
| 2141 "Invalid index passed in to access native instance field"); | 2108 "Invalid index passed in to access native instance field"); |
| 2142 } | 2109 } |
| 2143 *value = object.GetNativeField(index); | 2110 *value = object.GetNativeField(index); |
| 2144 return Api::Success(); | 2111 return Api::Success(); |
| 2145 } | 2112 } |
| 2146 | 2113 |
| 2147 | 2114 |
| 2148 DART_EXPORT Dart_Handle Dart_SetNativeInstanceField(Dart_Handle obj, | 2115 DART_EXPORT Dart_Handle Dart_SetNativeInstanceField(Dart_Handle obj, |
| 2149 int index, | 2116 int index, |
| 2150 intptr_t value) { | 2117 intptr_t value) { |
| 2151 DARTSCOPE(Isolate::Current()); | 2118 DARTSCOPE(Isolate::Current()); |
| 2152 const Object& param = Object::Handle(Api::UnwrapHandle(obj)); | 2119 const Object& param = Object::Handle(Api::UnwrapHandle(obj)); |
| 2153 if (param.IsNull() || !param.IsInstance()) { | 2120 if (param.IsNull() || !param.IsInstance()) { |
| 2154 return Api::Error("Invalid object passed in to set native instance field"); | 2121 return Api::NewError( |
| 2122 "Invalid object passed in to set native instance field"); |
| 2155 } | 2123 } |
| 2156 Instance& object = Instance::Handle(); | 2124 Instance& object = Instance::Handle(); |
| 2157 object ^= param.raw(); | 2125 object ^= param.raw(); |
| 2158 if (!object.IsValidNativeIndex(index)) { | 2126 if (!object.IsValidNativeIndex(index)) { |
| 2159 return Api::Error("Invalid index passed in to set native instance field"); | 2127 return Api::NewError( |
| 2128 "Invalid index passed in to set native instance field"); |
| 2160 } | 2129 } |
| 2161 object.SetNativeField(index, value); | 2130 object.SetNativeField(index, value); |
| 2162 return Api::Success(); | 2131 return Api::Success(); |
| 2163 } | 2132 } |
| 2164 | 2133 |
| 2165 | 2134 |
| 2166 // --- Exceptions ---- | 2135 // --- Exceptions ---- |
| 2167 | 2136 |
| 2168 | 2137 |
| 2169 DART_EXPORT Dart_Handle Dart_ThrowException(Dart_Handle exception) { | 2138 DART_EXPORT Dart_Handle Dart_ThrowException(Dart_Handle exception) { |
| 2170 Isolate* isolate = Isolate::Current(); | 2139 Isolate* isolate = Isolate::Current(); |
| 2171 DARTSCOPE(isolate); | 2140 DARTSCOPE(isolate); |
| 2172 if (isolate->top_exit_frame_info() == 0) { | 2141 if (isolate->top_exit_frame_info() == 0) { |
| 2173 // There are no dart frames on the stack so it would be illegal to | 2142 // There are no dart frames on the stack so it would be illegal to |
| 2174 // throw an exception here. | 2143 // throw an exception here. |
| 2175 return Api::Error("No Dart frames on stack, cannot throw exception"); | 2144 return Api::NewError("No Dart frames on stack, cannot throw exception"); |
| 2176 } | 2145 } |
| 2177 const Instance& excp = Instance::CheckedHandle(Api::UnwrapHandle(exception)); | 2146 const Instance& excp = Instance::CheckedHandle(Api::UnwrapHandle(exception)); |
| 2178 // Unwind all the API scopes till the exit frame before throwing an | 2147 // Unwind all the API scopes till the exit frame before throwing an |
| 2179 // exception. | 2148 // exception. |
| 2180 ApiState* state = isolate->api_state(); | 2149 ApiState* state = isolate->api_state(); |
| 2181 ASSERT(state != NULL); | 2150 ASSERT(state != NULL); |
| 2182 state->UnwindScopes(isolate->top_exit_frame_info()); | 2151 state->UnwindScopes(isolate->top_exit_frame_info()); |
| 2183 Exceptions::Throw(excp); | 2152 Exceptions::Throw(excp); |
| 2184 return Api::Error("Exception was not thrown, internal error"); | 2153 return Api::NewError("Exception was not thrown, internal error"); |
| 2185 } | 2154 } |
| 2186 | 2155 |
| 2187 | 2156 |
| 2188 DART_EXPORT Dart_Handle Dart_ReThrowException(Dart_Handle exception, | 2157 DART_EXPORT Dart_Handle Dart_ReThrowException(Dart_Handle exception, |
| 2189 Dart_Handle stacktrace) { | 2158 Dart_Handle stacktrace) { |
| 2190 Isolate* isolate = Isolate::Current(); | 2159 Isolate* isolate = Isolate::Current(); |
| 2191 CHECK_ISOLATE(isolate); | 2160 CHECK_ISOLATE(isolate); |
| 2192 if (isolate->top_exit_frame_info() == 0) { | 2161 if (isolate->top_exit_frame_info() == 0) { |
| 2193 // There are no dart frames on the stack so it would be illegal to | 2162 // There are no dart frames on the stack so it would be illegal to |
| 2194 // throw an exception here. | 2163 // throw an exception here. |
| 2195 return Api::Error("No Dart frames on stack, cannot throw exception"); | 2164 return Api::NewError("No Dart frames on stack, cannot throw exception"); |
| 2196 } | 2165 } |
| 2197 DARTSCOPE(isolate); | 2166 DARTSCOPE(isolate); |
| 2198 const Instance& excp = Instance::CheckedHandle(Api::UnwrapHandle(exception)); | 2167 const Instance& excp = Instance::CheckedHandle(Api::UnwrapHandle(exception)); |
| 2199 const Instance& stk = Instance::CheckedHandle(Api::UnwrapHandle(stacktrace)); | 2168 const Instance& stk = Instance::CheckedHandle(Api::UnwrapHandle(stacktrace)); |
| 2200 // Unwind all the API scopes till the exit frame before throwing an | 2169 // Unwind all the API scopes till the exit frame before throwing an |
| 2201 // exception. | 2170 // exception. |
| 2202 ApiState* state = isolate->api_state(); | 2171 ApiState* state = isolate->api_state(); |
| 2203 ASSERT(state != NULL); | 2172 ASSERT(state != NULL); |
| 2204 state->UnwindScopes(isolate->top_exit_frame_info()); | 2173 state->UnwindScopes(isolate->top_exit_frame_info()); |
| 2205 Exceptions::ReThrow(excp, stk); | 2174 Exceptions::ReThrow(excp, stk); |
| 2206 return Api::Error("Exception was not re thrown, internal error"); | 2175 return Api::NewError("Exception was not re thrown, internal error"); |
| 2207 } | 2176 } |
| 2208 | 2177 |
| 2209 | 2178 |
| 2210 // --- Native functions --- | 2179 // --- Native functions --- |
| 2211 | 2180 |
| 2212 | 2181 |
| 2213 DART_EXPORT Dart_Handle Dart_GetNativeArgument(Dart_NativeArguments args, | 2182 DART_EXPORT Dart_Handle Dart_GetNativeArgument(Dart_NativeArguments args, |
| 2214 int index) { | 2183 int index) { |
| 2215 DARTSCOPE(Isolate::Current()); | 2184 DARTSCOPE(Isolate::Current()); |
| 2216 NativeArguments* arguments = reinterpret_cast<NativeArguments*>(args); | 2185 NativeArguments* arguments = reinterpret_cast<NativeArguments*>(args); |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2282 if (url_str.IsNull()) { | 2251 if (url_str.IsNull()) { |
| 2283 RETURN_TYPE_ERROR(url, String); | 2252 RETURN_TYPE_ERROR(url, String); |
| 2284 } | 2253 } |
| 2285 const String& source_str = Api::UnwrapStringHandle(source); | 2254 const String& source_str = Api::UnwrapStringHandle(source); |
| 2286 if (source_str.IsNull()) { | 2255 if (source_str.IsNull()) { |
| 2287 RETURN_TYPE_ERROR(source, String); | 2256 RETURN_TYPE_ERROR(source, String); |
| 2288 } | 2257 } |
| 2289 Library& library = Library::Handle(isolate->object_store()->root_library()); | 2258 Library& library = Library::Handle(isolate->object_store()->root_library()); |
| 2290 if (!library.IsNull()) { | 2259 if (!library.IsNull()) { |
| 2291 const String& library_url = String::Handle(library.url()); | 2260 const String& library_url = String::Handle(library.url()); |
| 2292 return Api::Error("%s: A script has already been loaded from '%s'.", | 2261 return Api::NewError("%s: A script has already been loaded from '%s'.", |
| 2293 CURRENT_FUNC, library_url.ToCString()); | 2262 CURRENT_FUNC, library_url.ToCString()); |
| 2294 } | 2263 } |
| 2295 isolate->set_library_tag_handler(handler); | 2264 isolate->set_library_tag_handler(handler); |
| 2296 library = Library::New(url_str); | 2265 library = Library::New(url_str); |
| 2297 library.Register(); | 2266 library.Register(); |
| 2298 isolate->object_store()->set_root_library(library); | 2267 isolate->object_store()->set_root_library(library); |
| 2299 Dart_Handle result; | 2268 Dart_Handle result; |
| 2300 CompileSource(isolate, | 2269 CompileSource(isolate, |
| 2301 library, | 2270 library, |
| 2302 url_str, | 2271 url_str, |
| 2303 source_str, | 2272 source_str, |
| 2304 RawScript::kScript, | 2273 RawScript::kScript, |
| 2305 &result); | 2274 &result); |
| 2306 return result; | 2275 return result; |
| 2307 } | 2276 } |
| 2308 | 2277 |
| 2309 | 2278 |
| 2310 DART_EXPORT Dart_Handle Dart_LoadScriptFromSnapshot(const uint8_t* buffer) { | 2279 DART_EXPORT Dart_Handle Dart_LoadScriptFromSnapshot(const uint8_t* buffer) { |
| 2311 Isolate* isolate = Isolate::Current(); | 2280 Isolate* isolate = Isolate::Current(); |
| 2312 DARTSCOPE(isolate); | 2281 DARTSCOPE(isolate); |
| 2313 TIMERSCOPE(time_script_loading); | 2282 TIMERSCOPE(time_script_loading); |
| 2314 if (buffer == NULL) { | 2283 if (buffer == NULL) { |
| 2315 return Api::Error("%s expects argument 'buffer' to be non-null.", | 2284 return Api::NewError("%s expects argument 'buffer' to be non-null.", |
| 2316 CURRENT_FUNC); | 2285 CURRENT_FUNC); |
| 2317 } | 2286 } |
| 2318 const Snapshot* snapshot = Snapshot::SetupFromBuffer(buffer); | 2287 const Snapshot* snapshot = Snapshot::SetupFromBuffer(buffer); |
| 2319 if (!snapshot->IsScriptSnapshot()) { | 2288 if (!snapshot->IsScriptSnapshot()) { |
| 2320 return Api::Error("%s expects parameter 'buffer' to be a script type" | 2289 return Api::NewError("%s expects parameter 'buffer' to be a script type" |
| 2321 " snapshot", CURRENT_FUNC); | 2290 " snapshot", CURRENT_FUNC); |
| 2322 } | 2291 } |
| 2323 Library& library = Library::Handle(isolate->object_store()->root_library()); | 2292 Library& library = Library::Handle(isolate->object_store()->root_library()); |
| 2324 if (!library.IsNull()) { | 2293 if (!library.IsNull()) { |
| 2325 const String& library_url = String::Handle(library.url()); | 2294 const String& library_url = String::Handle(library.url()); |
| 2326 return Api::Error("%s: A script has already been loaded from '%s'.", | 2295 return Api::NewError("%s: A script has already been loaded from '%s'.", |
| 2327 CURRENT_FUNC, library_url.ToCString()); | 2296 CURRENT_FUNC, library_url.ToCString()); |
| 2328 } | 2297 } |
| 2329 SnapshotReader reader(snapshot, isolate); | 2298 SnapshotReader reader(snapshot, isolate); |
| 2330 const Object& tmp = Object::Handle(reader.ReadObject()); | 2299 const Object& tmp = Object::Handle(reader.ReadObject()); |
| 2331 if (!tmp.IsLibrary()) { | 2300 if (!tmp.IsLibrary()) { |
| 2332 return Api::Error("%s: Unable to deserialize snapshot correctly.", | 2301 return Api::NewError("%s: Unable to deserialize snapshot correctly.", |
| 2333 CURRENT_FUNC); | 2302 CURRENT_FUNC); |
| 2334 } | 2303 } |
| 2335 library ^= tmp.raw(); | 2304 library ^= tmp.raw(); |
| 2336 library.Register(); | 2305 library.Register(); |
| 2337 isolate->object_store()->set_root_library(library); | 2306 isolate->object_store()->set_root_library(library); |
| 2338 return Api::NewLocalHandle(library); | 2307 return Api::NewLocalHandle(library); |
| 2339 } | 2308 } |
| 2340 | 2309 |
| 2341 | 2310 |
| 2342 static void CompileAll(Isolate* isolate, Dart_Handle* result) { | 2311 static void CompileAll(Isolate* isolate, Dart_Handle* result) { |
| 2343 *result = Api::Success(); | 2312 *result = Api::Success(); |
| 2344 ASSERT(isolate != NULL); | 2313 ASSERT(isolate != NULL); |
| 2345 LongJump* base = isolate->long_jump_base(); | 2314 LongJump* base = isolate->long_jump_base(); |
| 2346 LongJump jump; | 2315 LongJump jump; |
| 2347 isolate->set_long_jump_base(&jump); | 2316 isolate->set_long_jump_base(&jump); |
| 2348 if (setjmp(*jump.Set()) == 0) { | 2317 if (setjmp(*jump.Set()) == 0) { |
| 2349 Library::CompileAll(); | 2318 Library::CompileAll(); |
| 2350 } else { | 2319 } else { |
| 2351 SetupErrorResult(result); | 2320 SetupErrorResult(result); |
| 2352 } | 2321 } |
| 2353 isolate->set_long_jump_base(base); | 2322 isolate->set_long_jump_base(base); |
| 2354 } | 2323 } |
| 2355 | 2324 |
| 2356 | 2325 |
| 2357 DART_EXPORT Dart_Handle Dart_CompileAll() { | 2326 DART_EXPORT Dart_Handle Dart_CompileAll() { |
| 2358 Isolate* isolate = Isolate::Current(); | 2327 Isolate* isolate = Isolate::Current(); |
| 2359 DARTSCOPE(isolate); | 2328 DARTSCOPE(isolate); |
| 2360 Dart_Handle result; | 2329 Dart_Handle result; |
| 2361 const char* msg = CheckIsolateState(isolate); | 2330 const char* msg = CheckIsolateState(isolate); |
| 2362 if (msg != NULL) { | 2331 if (msg != NULL) { |
| 2363 return Api::Error(msg); | 2332 return Api::NewError(msg); |
| 2364 } | 2333 } |
| 2365 CompileAll(isolate, &result); | 2334 CompileAll(isolate, &result); |
| 2366 return result; | 2335 return result; |
| 2367 } | 2336 } |
| 2368 | 2337 |
| 2369 | 2338 |
| 2370 DART_EXPORT bool Dart_IsLibrary(Dart_Handle object) { | 2339 DART_EXPORT bool Dart_IsLibrary(Dart_Handle object) { |
| 2371 DARTSCOPE(Isolate::Current()); | 2340 DARTSCOPE(Isolate::Current()); |
| 2372 const Object& obj = Object::Handle(Api::UnwrapHandle(object)); | 2341 const Object& obj = Object::Handle(Api::UnwrapHandle(object)); |
| 2373 return obj.IsLibrary(); | 2342 return obj.IsLibrary(); |
| 2374 } | 2343 } |
| 2375 | 2344 |
| 2376 | 2345 |
| 2377 DART_EXPORT Dart_Handle Dart_GetClass(Dart_Handle library, Dart_Handle name) { | 2346 DART_EXPORT Dart_Handle Dart_GetClass(Dart_Handle library, Dart_Handle name) { |
| 2378 DARTSCOPE(Isolate::Current()); | 2347 DARTSCOPE(Isolate::Current()); |
| 2379 const Object& param = Object::Handle(Api::UnwrapHandle(name)); | 2348 const Object& param = Object::Handle(Api::UnwrapHandle(name)); |
| 2380 if (param.IsNull() || !param.IsString()) { | 2349 if (param.IsNull() || !param.IsString()) { |
| 2381 return Api::Error("Invalid class name specified"); | 2350 return Api::NewError("Invalid class name specified"); |
| 2382 } | 2351 } |
| 2383 const Library& lib = Library::CheckedHandle(Api::UnwrapHandle(library)); | 2352 const Library& lib = Library::CheckedHandle(Api::UnwrapHandle(library)); |
| 2384 if (lib.IsNull()) { | 2353 if (lib.IsNull()) { |
| 2385 return Api::Error("Invalid parameter, Unknown library specified"); | 2354 return Api::NewError("Invalid parameter, Unknown library specified"); |
| 2386 } | 2355 } |
| 2387 String& cls_name = String::Handle(); | 2356 String& cls_name = String::Handle(); |
| 2388 cls_name ^= param.raw(); | 2357 cls_name ^= param.raw(); |
| 2389 const Class& cls = Class::Handle(lib.LookupClass(cls_name)); | 2358 const Class& cls = Class::Handle(lib.LookupClass(cls_name)); |
| 2390 if (cls.IsNull()) { | 2359 if (cls.IsNull()) { |
| 2391 const String& lib_name = String::Handle(lib.name()); | 2360 const String& lib_name = String::Handle(lib.name()); |
| 2392 return Api::Error("Class '%s' not found in library '%s'.", | 2361 return Api::NewError("Class '%s' not found in library '%s'.", |
| 2393 cls_name.ToCString(), lib_name.ToCString()); | 2362 cls_name.ToCString(), lib_name.ToCString()); |
| 2394 } | 2363 } |
| 2395 return Api::NewLocalHandle(cls); | 2364 return Api::NewLocalHandle(cls); |
| 2396 } | 2365 } |
| 2397 | 2366 |
| 2398 | 2367 |
| 2399 DART_EXPORT Dart_Handle Dart_LibraryUrl(Dart_Handle library) { | 2368 DART_EXPORT Dart_Handle Dart_LibraryUrl(Dart_Handle library) { |
| 2400 DARTSCOPE(Isolate::Current()); | 2369 DARTSCOPE(Isolate::Current()); |
| 2401 const Library& lib = Api::UnwrapLibraryHandle(library); | 2370 const Library& lib = Api::UnwrapLibraryHandle(library); |
| 2402 if (lib.IsNull()) { | 2371 if (lib.IsNull()) { |
| 2403 RETURN_TYPE_ERROR(library, Library); | 2372 RETURN_TYPE_ERROR(library, Library); |
| 2404 } | 2373 } |
| 2405 const String& url = String::Handle(lib.url()); | 2374 const String& url = String::Handle(lib.url()); |
| 2406 ASSERT(!url.IsNull()); | 2375 ASSERT(!url.IsNull()); |
| 2407 return Api::NewLocalHandle(url); | 2376 return Api::NewLocalHandle(url); |
| 2408 } | 2377 } |
| 2409 | 2378 |
| 2410 | 2379 |
| 2411 DART_EXPORT Dart_Handle Dart_LookupLibrary(Dart_Handle url) { | 2380 DART_EXPORT Dart_Handle Dart_LookupLibrary(Dart_Handle url) { |
| 2412 DARTSCOPE(Isolate::Current()); | 2381 DARTSCOPE(Isolate::Current()); |
| 2413 const String& url_str = Api::UnwrapStringHandle(url); | 2382 const String& url_str = Api::UnwrapStringHandle(url); |
| 2414 if (url_str.IsNull()) { | 2383 if (url_str.IsNull()) { |
| 2415 RETURN_TYPE_ERROR(url, String); | 2384 RETURN_TYPE_ERROR(url, String); |
| 2416 } | 2385 } |
| 2417 const Library& library = Library::Handle(Library::LookupLibrary(url_str)); | 2386 const Library& library = Library::Handle(Library::LookupLibrary(url_str)); |
| 2418 if (library.IsNull()) { | 2387 if (library.IsNull()) { |
| 2419 return Api::Error("%s: library '%s' not found.", | 2388 return Api::NewError("%s: library '%s' not found.", |
| 2420 CURRENT_FUNC, url_str.ToCString()); | 2389 CURRENT_FUNC, url_str.ToCString()); |
| 2421 } else { | 2390 } else { |
| 2422 return Api::NewLocalHandle(library); | 2391 return Api::NewLocalHandle(library); |
| 2423 } | 2392 } |
| 2424 } | 2393 } |
| 2425 | 2394 |
| 2426 | 2395 |
| 2427 DART_EXPORT Dart_Handle Dart_LoadLibrary(Dart_Handle url, Dart_Handle source) { | 2396 DART_EXPORT Dart_Handle Dart_LoadLibrary(Dart_Handle url, Dart_Handle source) { |
| 2428 Isolate* isolate = Isolate::Current(); | 2397 Isolate* isolate = Isolate::Current(); |
| 2429 DARTSCOPE(isolate); | 2398 DARTSCOPE(isolate); |
| 2430 const String& url_str = Api::UnwrapStringHandle(url); | 2399 const String& url_str = Api::UnwrapStringHandle(url); |
| 2431 if (url_str.IsNull()) { | 2400 if (url_str.IsNull()) { |
| 2432 RETURN_TYPE_ERROR(url, String); | 2401 RETURN_TYPE_ERROR(url, String); |
| 2433 } | 2402 } |
| 2434 const String& source_str = Api::UnwrapStringHandle(source); | 2403 const String& source_str = Api::UnwrapStringHandle(source); |
| 2435 if (source_str.IsNull()) { | 2404 if (source_str.IsNull()) { |
| 2436 RETURN_TYPE_ERROR(source, String); | 2405 RETURN_TYPE_ERROR(source, String); |
| 2437 } | 2406 } |
| 2438 Library& library = Library::Handle(Library::LookupLibrary(url_str)); | 2407 Library& library = Library::Handle(Library::LookupLibrary(url_str)); |
| 2439 if (library.IsNull()) { | 2408 if (library.IsNull()) { |
| 2440 library = Library::New(url_str); | 2409 library = Library::New(url_str); |
| 2441 library.Register(); | 2410 library.Register(); |
| 2442 } else if (!library.LoadNotStarted()) { | 2411 } else if (!library.LoadNotStarted()) { |
| 2443 // The source for this library has either been loaded or is in the | 2412 // The source for this library has either been loaded or is in the |
| 2444 // process of loading. Return an error. | 2413 // process of loading. Return an error. |
| 2445 return Api::Error("%s: library '%s' has already been loaded.", | 2414 return Api::NewError("%s: library '%s' has already been loaded.", |
| 2446 CURRENT_FUNC, url_str.ToCString()); | 2415 CURRENT_FUNC, url_str.ToCString()); |
| 2447 } | 2416 } |
| 2448 Dart_Handle result; | 2417 Dart_Handle result; |
| 2449 CompileSource(isolate, | 2418 CompileSource(isolate, |
| 2450 library, | 2419 library, |
| 2451 url_str, | 2420 url_str, |
| 2452 source_str, | 2421 source_str, |
| 2453 RawScript::kLibrary, | 2422 RawScript::kLibrary, |
| 2454 &result); | 2423 &result); |
| 2455 return result; | 2424 return result; |
| 2456 } | 2425 } |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2533 } | 2502 } |
| 2534 delete debug_region; | 2503 delete debug_region; |
| 2535 } else { | 2504 } else { |
| 2536 *buffer = NULL; | 2505 *buffer = NULL; |
| 2537 *buffer_size = 0; | 2506 *buffer_size = 0; |
| 2538 } | 2507 } |
| 2539 } | 2508 } |
| 2540 | 2509 |
| 2541 | 2510 |
| 2542 } // namespace dart | 2511 } // namespace dart |
| OLD | NEW |