| OLD | NEW |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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 #include "include/dart_mirrors_api.h" | 6 #include "include/dart_mirrors_api.h" |
| 7 #include "include/dart_native_api.h" | 7 #include "include/dart_native_api.h" |
| 8 | 8 |
| 9 #include "platform/assert.h" | 9 #include "platform/assert.h" |
| 10 #include "vm/class_finalizer.h" | 10 #include "vm/class_finalizer.h" |
| (...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 167 static bool GetNativeStringArgument(NativeArguments* arguments, | 167 static bool GetNativeStringArgument(NativeArguments* arguments, |
| 168 int arg_index, | 168 int arg_index, |
| 169 Dart_Handle* str, | 169 Dart_Handle* str, |
| 170 void** peer) { | 170 void** peer) { |
| 171 ASSERT(peer != NULL); | 171 ASSERT(peer != NULL); |
| 172 if (Api::StringGetPeerHelper(arguments, arg_index, peer)) { | 172 if (Api::StringGetPeerHelper(arguments, arg_index, peer)) { |
| 173 *str = NULL; | 173 *str = NULL; |
| 174 return true; | 174 return true; |
| 175 } | 175 } |
| 176 Thread* thread = arguments->thread(); | 176 Thread* thread = arguments->thread(); |
| 177 Isolate* isolate = thread->isolate(); | 177 ASSERT(thread == Thread::Current()); |
| 178 ASSERT(isolate == Isolate::Current()); | |
| 179 *peer = NULL; | 178 *peer = NULL; |
| 180 REUSABLE_OBJECT_HANDLESCOPE(thread); | 179 REUSABLE_OBJECT_HANDLESCOPE(thread); |
| 181 Object& obj = thread->ObjectHandle(); | 180 Object& obj = thread->ObjectHandle(); |
| 182 obj = arguments->NativeArgAt(arg_index); | 181 obj = arguments->NativeArgAt(arg_index); |
| 183 if (RawObject::IsStringClassId(obj.GetClassId())) { | 182 if (RawObject::IsStringClassId(obj.GetClassId())) { |
| 184 ASSERT(isolate->api_state() && | 183 ASSERT(thread->api_top_scope() != NULL); |
| 185 isolate->api_state()->top_scope() != NULL); | 184 *str = Api::NewHandle(thread, obj.raw()); |
| 186 *str = Api::NewHandle(isolate, obj.raw()); | |
| 187 return true; | 185 return true; |
| 188 } | 186 } |
| 189 if (obj.IsNull()) { | 187 if (obj.IsNull()) { |
| 190 *str = Api::Null(); | 188 *str = Api::Null(); |
| 191 return true; | 189 return true; |
| 192 } | 190 } |
| 193 return false; | 191 return false; |
| 194 } | 192 } |
| 195 | 193 |
| 196 | 194 |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 294 } | 292 } |
| 295 const Instance& instance = Instance::Cast(obj); | 293 const Instance& instance = Instance::Cast(obj); |
| 296 int field_count = instance.NumNativeFields(); | 294 int field_count = instance.NumNativeFields(); |
| 297 ASSERT(num_fields != field_count); | 295 ASSERT(num_fields != field_count); |
| 298 return Api::NewError( | 296 return Api::NewError( |
| 299 "%s: expected %d 'num_fields' but was passed in %d.", | 297 "%s: expected %d 'num_fields' but was passed in %d.", |
| 300 current_func, field_count, num_fields); | 298 current_func, field_count, num_fields); |
| 301 } | 299 } |
| 302 | 300 |
| 303 | 301 |
| 304 Heap::Space SpaceForExternal(Isolate* isolate, intptr_t size) { | 302 Heap::Space SpaceForExternal(Thread* thread, intptr_t size) { |
| 305 Heap* heap = isolate->heap(); | 303 Heap* heap = thread->heap(); |
| 306 // If 'size' would be a significant fraction of new space, then use old. | 304 // If 'size' would be a significant fraction of new space, then use old. |
| 307 static const int kExtNewRatio = 16; | 305 static const int kExtNewRatio = 16; |
| 308 if (size > (heap->CapacityInWords(Heap::kNew) * kWordSize) / kExtNewRatio) { | 306 if (size > (heap->CapacityInWords(Heap::kNew) * kWordSize) / kExtNewRatio) { |
| 309 return Heap::kOld; | 307 return Heap::kOld; |
| 310 } else { | 308 } else { |
| 311 return Heap::kNew; | 309 return Heap::kNew; |
| 312 } | 310 } |
| 313 } | 311 } |
| 314 | 312 |
| 315 | 313 |
| (...skipping 24 matching lines...) Expand all Loading... |
| 340 if (function.IsNull()) { | 338 if (function.IsNull()) { |
| 341 return ApiError::New(String::Handle(String::New(""))); | 339 return ApiError::New(String::Handle(String::New(""))); |
| 342 } | 340 } |
| 343 const Array& args = Array::Handle(Array::New(kNumArgs)); | 341 const Array& args = Array::Handle(Array::New(kNumArgs)); |
| 344 args.SetAt(0, receiver); | 342 args.SetAt(0, receiver); |
| 345 args.SetAt(1, argument); | 343 args.SetAt(1, argument); |
| 346 return DartEntry::InvokeFunction(function, args); | 344 return DartEntry::InvokeFunction(function, args); |
| 347 } | 345 } |
| 348 | 346 |
| 349 | 347 |
| 350 Dart_Handle Api::InitNewHandle(Isolate* isolate, RawObject* raw) { | 348 Dart_Handle Api::InitNewHandle(Thread* thread, RawObject* raw) { |
| 351 LocalHandles* local_handles = Api::TopScope(isolate)->local_handles(); | 349 LocalHandles* local_handles = Api::TopScope(thread)->local_handles(); |
| 352 ASSERT(local_handles != NULL); | 350 ASSERT(local_handles != NULL); |
| 353 LocalHandle* ref = local_handles->AllocateHandle(); | 351 LocalHandle* ref = local_handles->AllocateHandle(); |
| 354 ref->set_raw(raw); | 352 ref->set_raw(raw); |
| 355 return ref->apiHandle(); | 353 return ref->apiHandle(); |
| 356 } | 354 } |
| 357 | 355 |
| 358 | 356 |
| 359 Dart_Handle Api::NewHandle(Isolate* isolate, RawObject* raw) { | 357 Dart_Handle Api::NewHandle(Thread* thread, RawObject* raw) { |
| 360 if (raw == Object::null()) { | 358 if (raw == Object::null()) { |
| 361 return Null(); | 359 return Null(); |
| 362 } | 360 } |
| 363 if (raw == Bool::True().raw()) { | 361 if (raw == Bool::True().raw()) { |
| 364 return True(); | 362 return True(); |
| 365 } | 363 } |
| 366 if (raw == Bool::False().raw()) { | 364 if (raw == Bool::False().raw()) { |
| 367 return False(); | 365 return False(); |
| 368 } | 366 } |
| 369 return InitNewHandle(isolate, raw); | 367 return InitNewHandle(thread, raw); |
| 370 } | 368 } |
| 371 | 369 |
| 372 | 370 |
| 373 RawObject* Api::UnwrapHandle(Dart_Handle object) { | 371 RawObject* Api::UnwrapHandle(Dart_Handle object) { |
| 374 #if defined(DEBUG) | 372 #if defined(DEBUG) |
| 375 ASSERT(Thread::Current()->IsMutatorThread()); | 373 Thread* thread = Thread::Current(); |
| 376 Isolate* isolate = Isolate::Current(); | 374 ASSERT(thread->IsMutatorThread()); |
| 377 ASSERT(isolate != NULL); | 375 ASSERT(thread->isolate() != NULL); |
| 378 ApiState* state = isolate->api_state(); | |
| 379 ASSERT(state != NULL); | |
| 380 ASSERT(!FLAG_verify_handles || | 376 ASSERT(!FLAG_verify_handles || |
| 381 state->IsValidLocalHandle(object) || | 377 thread->IsValidLocalHandle(object) || |
| 382 Dart::IsReadOnlyApiHandle(object)); | 378 Dart::IsReadOnlyApiHandle(object)); |
| 383 ASSERT(FinalizablePersistentHandle::raw_offset() == 0 && | 379 ASSERT(FinalizablePersistentHandle::raw_offset() == 0 && |
| 384 PersistentHandle::raw_offset() == 0 && | 380 PersistentHandle::raw_offset() == 0 && |
| 385 LocalHandle::raw_offset() == 0); | 381 LocalHandle::raw_offset() == 0); |
| 386 #endif | 382 #endif |
| 387 return (reinterpret_cast<LocalHandle*>(object))->raw(); | 383 return (reinterpret_cast<LocalHandle*>(object))->raw(); |
| 388 } | 384 } |
| 389 | 385 |
| 390 | 386 |
| 391 #define DEFINE_UNWRAP(type) \ | 387 #define DEFINE_UNWRAP(type) \ |
| (...skipping 24 matching lines...) Expand all Loading... |
| 416 const ReusableObjectHandleScope& reuse, Dart_Handle dart_handle) { | 412 const ReusableObjectHandleScope& reuse, Dart_Handle dart_handle) { |
| 417 Object& ref = reuse.Handle(); | 413 Object& ref = reuse.Handle(); |
| 418 ref = Api::UnwrapHandle(dart_handle); | 414 ref = Api::UnwrapHandle(dart_handle); |
| 419 if (ref.IsInstance()) { | 415 if (ref.IsInstance()) { |
| 420 return Instance::Cast(ref); | 416 return Instance::Cast(ref); |
| 421 } | 417 } |
| 422 return Object::null_instance(); | 418 return Object::null_instance(); |
| 423 } | 419 } |
| 424 | 420 |
| 425 | 421 |
| 426 Dart_Handle Api::CheckAndFinalizePendingClasses(Isolate* isolate) { | 422 Dart_Handle Api::CheckAndFinalizePendingClasses(Thread* thread) { |
| 423 Isolate* isolate = thread->isolate(); |
| 427 if (!isolate->AllowClassFinalization()) { | 424 if (!isolate->AllowClassFinalization()) { |
| 428 // Class finalization is blocked for the isolate. Do nothing. | 425 // Class finalization is blocked for the isolate. Do nothing. |
| 429 return Api::Success(); | 426 return Api::Success(); |
| 430 } | 427 } |
| 431 if (ClassFinalizer::ProcessPendingClasses()) { | 428 if (ClassFinalizer::ProcessPendingClasses()) { |
| 432 return Api::Success(); | 429 return Api::Success(); |
| 433 } | 430 } |
| 434 ASSERT(isolate->object_store()->sticky_error() != Object::null()); | 431 ASSERT(isolate->object_store()->sticky_error() != Object::null()); |
| 435 return Api::NewHandle(isolate, isolate->object_store()->sticky_error()); | 432 return Api::NewHandle(thread, isolate->object_store()->sticky_error()); |
| 436 } | 433 } |
| 437 | 434 |
| 438 | 435 |
| 439 Dart_Isolate Api::CastIsolate(Isolate* isolate) { | 436 Dart_Isolate Api::CastIsolate(Isolate* isolate) { |
| 440 return reinterpret_cast<Dart_Isolate>(isolate); | 437 return reinterpret_cast<Dart_Isolate>(isolate); |
| 441 } | 438 } |
| 442 | 439 |
| 443 | 440 |
| 444 Dart_Handle Api::NewError(const char* format, ...) { | 441 Dart_Handle Api::NewError(const char* format, ...) { |
| 445 DARTSCOPE(Thread::Current()); | 442 DARTSCOPE(Thread::Current()); |
| 446 CHECK_CALLBACK_STATE(T); | 443 CHECK_CALLBACK_STATE(T); |
| 447 | 444 |
| 448 va_list args; | 445 va_list args; |
| 449 va_start(args, format); | 446 va_start(args, format); |
| 450 intptr_t len = OS::VSNPrint(NULL, 0, format, args); | 447 intptr_t len = OS::VSNPrint(NULL, 0, format, args); |
| 451 va_end(args); | 448 va_end(args); |
| 452 | 449 |
| 453 char* buffer = Z->Alloc<char>(len + 1); | 450 char* buffer = Z->Alloc<char>(len + 1); |
| 454 va_list args2; | 451 va_list args2; |
| 455 va_start(args2, format); | 452 va_start(args2, format); |
| 456 OS::VSNPrint(buffer, (len + 1), format, args2); | 453 OS::VSNPrint(buffer, (len + 1), format, args2); |
| 457 va_end(args2); | 454 va_end(args2); |
| 458 | 455 |
| 459 const String& message = String::Handle(Z, String::New(buffer)); | 456 const String& message = String::Handle(Z, String::New(buffer)); |
| 460 return Api::NewHandle(I, ApiError::New(message)); | 457 return Api::NewHandle(T, ApiError::New(message)); |
| 461 } | 458 } |
| 462 | 459 |
| 463 | 460 |
| 464 void Api::SetupAcquiredError(Isolate* isolate) { | 461 void Api::SetupAcquiredError(Isolate* isolate) { |
| 465 ASSERT(isolate != NULL); | 462 ASSERT(isolate != NULL); |
| 466 ApiState* state = isolate->api_state(); | 463 ApiState* state = isolate->api_state(); |
| 467 ASSERT(state != NULL); | 464 ASSERT(state != NULL); |
| 468 state->SetupAcquiredError(); | 465 state->SetupAcquiredError(); |
| 469 } | 466 } |
| 470 | 467 |
| 471 | 468 |
| 472 Dart_Handle Api::AcquiredError(Isolate* isolate) { | 469 Dart_Handle Api::AcquiredError(Isolate* isolate) { |
| 473 ASSERT(isolate != NULL); | 470 ASSERT(isolate != NULL); |
| 474 ApiState* state = isolate->api_state(); | 471 ApiState* state = isolate->api_state(); |
| 475 ASSERT(state != NULL); | 472 ASSERT(state != NULL); |
| 476 PersistentHandle* acquired_error_handle = state->AcquiredError(); | 473 PersistentHandle* acquired_error_handle = state->AcquiredError(); |
| 477 return reinterpret_cast<Dart_Handle>(acquired_error_handle); | 474 return reinterpret_cast<Dart_Handle>(acquired_error_handle); |
| 478 } | 475 } |
| 479 | 476 |
| 480 | 477 |
| 481 ApiLocalScope* Api::TopScope(Isolate* isolate) { | 478 ApiLocalScope* Api::TopScope(Thread* thread) { |
| 482 ASSERT(isolate != NULL); | 479 ASSERT(thread != NULL); |
| 483 ApiState* state = isolate->api_state(); | 480 ApiLocalScope* scope = thread->api_top_scope(); |
| 484 ASSERT(state != NULL); | |
| 485 ApiLocalScope* scope = state->top_scope(); | |
| 486 ASSERT(scope != NULL); | 481 ASSERT(scope != NULL); |
| 487 return scope; | 482 return scope; |
| 488 } | 483 } |
| 489 | 484 |
| 490 | 485 |
| 491 void Api::InitOnce() { | 486 void Api::InitOnce() { |
| 492 ASSERT(api_native_key_ == OSThread::kUnsetThreadLocalKey); | 487 ASSERT(api_native_key_ == OSThread::kUnsetThreadLocalKey); |
| 493 api_native_key_ = OSThread::CreateThreadLocal(); | 488 api_native_key_ = OSThread::CreateThreadLocal(); |
| 494 ASSERT(api_native_key_ != OSThread::kUnsetThreadLocalKey); | 489 ASSERT(api_native_key_ != OSThread::kUnsetThreadLocalKey); |
| 495 } | 490 } |
| (...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 742 } | 737 } |
| 743 | 738 |
| 744 | 739 |
| 745 DART_EXPORT const char* Dart_GetError(Dart_Handle handle) { | 740 DART_EXPORT const char* Dart_GetError(Dart_Handle handle) { |
| 746 DARTSCOPE(Thread::Current()); | 741 DARTSCOPE(Thread::Current()); |
| 747 const Object& obj = Object::Handle(Z, Api::UnwrapHandle(handle)); | 742 const Object& obj = Object::Handle(Z, Api::UnwrapHandle(handle)); |
| 748 if (obj.IsError()) { | 743 if (obj.IsError()) { |
| 749 const Error& error = Error::Cast(obj); | 744 const Error& error = Error::Cast(obj); |
| 750 const char* str = error.ToErrorCString(); | 745 const char* str = error.ToErrorCString(); |
| 751 intptr_t len = strlen(str) + 1; | 746 intptr_t len = strlen(str) + 1; |
| 752 char* str_copy = Api::TopScope(I)->zone()->Alloc<char>(len); | 747 char* str_copy = Api::TopScope(T)->zone()->Alloc<char>(len); |
| 753 strncpy(str_copy, str, len); | 748 strncpy(str_copy, str, len); |
| 754 // Strip a possible trailing '\n'. | 749 // Strip a possible trailing '\n'. |
| 755 if ((len > 1) && (str_copy[len - 2] == '\n')) { | 750 if ((len > 1) && (str_copy[len - 2] == '\n')) { |
| 756 str_copy[len - 2] = '\0'; | 751 str_copy[len - 2] = '\0'; |
| 757 } | 752 } |
| 758 return str_copy; | 753 return str_copy; |
| 759 } else { | 754 } else { |
| 760 return ""; | 755 return ""; |
| 761 } | 756 } |
| 762 } | 757 } |
| 763 | 758 |
| 764 | 759 |
| 765 DART_EXPORT bool Dart_ErrorHasException(Dart_Handle handle) { | 760 DART_EXPORT bool Dart_ErrorHasException(Dart_Handle handle) { |
| 766 DARTSCOPE(Thread::Current()); | 761 DARTSCOPE(Thread::Current()); |
| 767 const Object& obj = Object::Handle(Z, Api::UnwrapHandle(handle)); | 762 const Object& obj = Object::Handle(Z, Api::UnwrapHandle(handle)); |
| 768 return obj.IsUnhandledException(); | 763 return obj.IsUnhandledException(); |
| 769 } | 764 } |
| 770 | 765 |
| 771 | 766 |
| 772 DART_EXPORT Dart_Handle Dart_ErrorGetException(Dart_Handle handle) { | 767 DART_EXPORT Dart_Handle Dart_ErrorGetException(Dart_Handle handle) { |
| 773 DARTSCOPE(Thread::Current()); | 768 DARTSCOPE(Thread::Current()); |
| 774 const Object& obj = Object::Handle(Z, Api::UnwrapHandle(handle)); | 769 const Object& obj = Object::Handle(Z, Api::UnwrapHandle(handle)); |
| 775 if (obj.IsUnhandledException()) { | 770 if (obj.IsUnhandledException()) { |
| 776 const UnhandledException& error = UnhandledException::Cast(obj); | 771 const UnhandledException& error = UnhandledException::Cast(obj); |
| 777 return Api::NewHandle(I, error.exception()); | 772 return Api::NewHandle(T, error.exception()); |
| 778 } else if (obj.IsError()) { | 773 } else if (obj.IsError()) { |
| 779 return Api::NewError("This error is not an unhandled exception error."); | 774 return Api::NewError("This error is not an unhandled exception error."); |
| 780 } else { | 775 } else { |
| 781 return Api::NewError("Can only get exceptions from error handles."); | 776 return Api::NewError("Can only get exceptions from error handles."); |
| 782 } | 777 } |
| 783 } | 778 } |
| 784 | 779 |
| 785 | 780 |
| 786 DART_EXPORT Dart_Handle Dart_ErrorGetStacktrace(Dart_Handle handle) { | 781 DART_EXPORT Dart_Handle Dart_ErrorGetStacktrace(Dart_Handle handle) { |
| 787 DARTSCOPE(Thread::Current()); | 782 DARTSCOPE(Thread::Current()); |
| 788 const Object& obj = Object::Handle(Z, Api::UnwrapHandle(handle)); | 783 const Object& obj = Object::Handle(Z, Api::UnwrapHandle(handle)); |
| 789 if (obj.IsUnhandledException()) { | 784 if (obj.IsUnhandledException()) { |
| 790 const UnhandledException& error = UnhandledException::Cast(obj); | 785 const UnhandledException& error = UnhandledException::Cast(obj); |
| 791 return Api::NewHandle(I, error.stacktrace()); | 786 return Api::NewHandle(T, error.stacktrace()); |
| 792 } else if (obj.IsError()) { | 787 } else if (obj.IsError()) { |
| 793 return Api::NewError("This error is not an unhandled exception error."); | 788 return Api::NewError("This error is not an unhandled exception error."); |
| 794 } else { | 789 } else { |
| 795 return Api::NewError("Can only get stacktraces from error handles."); | 790 return Api::NewError("Can only get stacktraces from error handles."); |
| 796 } | 791 } |
| 797 } | 792 } |
| 798 | 793 |
| 799 | 794 |
| 800 // TODO(turnidge): This clones Api::NewError. I need to use va_copy to | 795 // TODO(turnidge): This clones Api::NewError. I need to use va_copy to |
| 801 // fix this but not sure if it available on all of our builds. | 796 // fix this but not sure if it available on all of our builds. |
| 802 DART_EXPORT Dart_Handle Dart_NewApiError(const char* error) { | 797 DART_EXPORT Dart_Handle Dart_NewApiError(const char* error) { |
| 803 DARTSCOPE(Thread::Current()); | 798 DARTSCOPE(Thread::Current()); |
| 804 CHECK_CALLBACK_STATE(T); | 799 CHECK_CALLBACK_STATE(T); |
| 805 | 800 |
| 806 const String& message = String::Handle(Z, String::New(error)); | 801 const String& message = String::Handle(Z, String::New(error)); |
| 807 return Api::NewHandle(I, ApiError::New(message)); | 802 return Api::NewHandle(T, ApiError::New(message)); |
| 808 } | 803 } |
| 809 | 804 |
| 810 | 805 |
| 811 DART_EXPORT Dart_Handle Dart_NewUnhandledExceptionError(Dart_Handle exception) { | 806 DART_EXPORT Dart_Handle Dart_NewUnhandledExceptionError(Dart_Handle exception) { |
| 812 DARTSCOPE(Thread::Current()); | 807 DARTSCOPE(Thread::Current()); |
| 813 CHECK_CALLBACK_STATE(T); | 808 CHECK_CALLBACK_STATE(T); |
| 814 | 809 |
| 815 Instance& obj = Instance::Handle(Z); | 810 Instance& obj = Instance::Handle(Z); |
| 816 intptr_t class_id = Api::ClassId(exception); | 811 intptr_t class_id = Api::ClassId(exception); |
| 817 if ((class_id == kApiErrorCid) || (class_id == kLanguageErrorCid)) { | 812 if ((class_id == kApiErrorCid) || (class_id == kLanguageErrorCid)) { |
| 818 obj = String::New(::Dart_GetError(exception)); | 813 obj = String::New(::Dart_GetError(exception)); |
| 819 } else { | 814 } else { |
| 820 obj = Api::UnwrapInstanceHandle(Z, exception).raw(); | 815 obj = Api::UnwrapInstanceHandle(Z, exception).raw(); |
| 821 if (obj.IsNull()) { | 816 if (obj.IsNull()) { |
| 822 RETURN_TYPE_ERROR(Z, exception, Instance); | 817 RETURN_TYPE_ERROR(Z, exception, Instance); |
| 823 } | 818 } |
| 824 } | 819 } |
| 825 const Stacktrace& stacktrace = Stacktrace::Handle(Z); | 820 const Stacktrace& stacktrace = Stacktrace::Handle(Z); |
| 826 return Api::NewHandle(I, UnhandledException::New(obj, stacktrace)); | 821 return Api::NewHandle(T, UnhandledException::New(obj, stacktrace)); |
| 827 } | 822 } |
| 828 | 823 |
| 829 | 824 |
| 830 DART_EXPORT Dart_Handle Dart_PropagateError(Dart_Handle handle) { | 825 DART_EXPORT Dart_Handle Dart_PropagateError(Dart_Handle handle) { |
| 831 Thread* thread = Thread::Current(); | 826 Thread* thread = Thread::Current(); |
| 832 Isolate* isolate = thread->isolate(); | |
| 833 { | 827 { |
| 834 const Object& obj = Object::Handle(thread->zone(), | 828 const Object& obj = Object::Handle(thread->zone(), |
| 835 Api::UnwrapHandle(handle)); | 829 Api::UnwrapHandle(handle)); |
| 836 if (!obj.IsError()) { | 830 if (!obj.IsError()) { |
| 837 return Api::NewError( | 831 return Api::NewError( |
| 838 "%s expects argument 'handle' to be an error handle. " | 832 "%s expects argument 'handle' to be an error handle. " |
| 839 "Did you forget to check Dart_IsError first?", | 833 "Did you forget to check Dart_IsError first?", |
| 840 CURRENT_FUNC); | 834 CURRENT_FUNC); |
| 841 } | 835 } |
| 842 } | 836 } |
| 843 if (thread->top_exit_frame_info() == 0) { | 837 if (thread->top_exit_frame_info() == 0) { |
| 844 // There are no dart frames on the stack so it would be illegal to | 838 // There are no dart frames on the stack so it would be illegal to |
| 845 // propagate an error here. | 839 // propagate an error here. |
| 846 return Api::NewError("No Dart frames on stack, cannot propagate error."); | 840 return Api::NewError("No Dart frames on stack, cannot propagate error."); |
| 847 } | 841 } |
| 848 | 842 |
| 849 // Unwind all the API scopes till the exit frame before propagating. | 843 // Unwind all the API scopes till the exit frame before propagating. |
| 850 ApiState* state = isolate->api_state(); | |
| 851 ASSERT(state != NULL); | |
| 852 const Error* error; | 844 const Error* error; |
| 853 { | 845 { |
| 854 // We need to preserve the error object across the destruction of zones | 846 // We need to preserve the error object across the destruction of zones |
| 855 // when the ApiScopes are unwound. By using NoSafepointScope, we can ensure | 847 // when the ApiScopes are unwound. By using NoSafepointScope, we can ensure |
| 856 // that GC won't touch the raw error object before creating a valid | 848 // that GC won't touch the raw error object before creating a valid |
| 857 // handle for it in the surviving zone. | 849 // handle for it in the surviving zone. |
| 858 NoSafepointScope no_safepoint; | 850 NoSafepointScope no_safepoint; |
| 859 RawError* raw_error = Api::UnwrapErrorHandle(thread->zone(), handle).raw(); | 851 RawError* raw_error = Api::UnwrapErrorHandle(thread->zone(), handle).raw(); |
| 860 state->UnwindScopes(thread->top_exit_frame_info()); | 852 thread->UnwindScopes(thread->top_exit_frame_info()); |
| 861 // Note that thread's zone is different here than at the beginning of this | 853 // Note that thread's zone is different here than at the beginning of this |
| 862 // function. | 854 // function. |
| 863 error = &Error::Handle(thread->zone(), raw_error); | 855 error = &Error::Handle(thread->zone(), raw_error); |
| 864 } | 856 } |
| 865 Exceptions::PropagateError(*error); | 857 Exceptions::PropagateError(*error); |
| 866 UNREACHABLE(); | 858 UNREACHABLE(); |
| 867 return Api::NewError("Cannot reach here. Internal error."); | 859 return Api::NewError("Cannot reach here. Internal error."); |
| 868 } | 860 } |
| 869 | 861 |
| 870 | 862 |
| 871 DART_EXPORT void _Dart_ReportErrorHandle(const char* file, | 863 DART_EXPORT void _Dart_ReportErrorHandle(const char* file, |
| 872 int line, | 864 int line, |
| 873 const char* handle, | 865 const char* handle, |
| 874 const char* message) { | 866 const char* message) { |
| 875 fprintf(stderr, "%s:%d: error handle: '%s':\n '%s'\n", | 867 fprintf(stderr, "%s:%d: error handle: '%s':\n '%s'\n", |
| 876 file, line, handle, message); | 868 file, line, handle, message); |
| 877 OS::Abort(); | 869 OS::Abort(); |
| 878 } | 870 } |
| 879 | 871 |
| 880 | 872 |
| 881 DART_EXPORT Dart_Handle Dart_ToString(Dart_Handle object) { | 873 DART_EXPORT Dart_Handle Dart_ToString(Dart_Handle object) { |
| 882 DARTSCOPE(Thread::Current()); | 874 DARTSCOPE(Thread::Current()); |
| 883 const Object& obj = Object::Handle(Z, Api::UnwrapHandle(object)); | 875 const Object& obj = Object::Handle(Z, Api::UnwrapHandle(object)); |
| 884 if (obj.IsString()) { | 876 if (obj.IsString()) { |
| 885 return Api::NewHandle(I, obj.raw()); | 877 return Api::NewHandle(T, obj.raw()); |
| 886 } else if (obj.IsInstance()) { | 878 } else if (obj.IsInstance()) { |
| 887 CHECK_CALLBACK_STATE(T); | 879 CHECK_CALLBACK_STATE(T); |
| 888 const Instance& receiver = Instance::Cast(obj); | 880 const Instance& receiver = Instance::Cast(obj); |
| 889 return Api::NewHandle(I, DartLibraryCalls::ToString(receiver)); | 881 return Api::NewHandle(T, DartLibraryCalls::ToString(receiver)); |
| 890 } else { | 882 } else { |
| 891 CHECK_CALLBACK_STATE(T); | 883 CHECK_CALLBACK_STATE(T); |
| 892 // This is a VM internal object. Call the C++ method of printing. | 884 // This is a VM internal object. Call the C++ method of printing. |
| 893 return Api::NewHandle(I, String::New(obj.ToCString())); | 885 return Api::NewHandle(T, String::New(obj.ToCString())); |
| 894 } | 886 } |
| 895 } | 887 } |
| 896 | 888 |
| 897 | 889 |
| 898 DART_EXPORT bool Dart_IdentityEquals(Dart_Handle obj1, Dart_Handle obj2) { | 890 DART_EXPORT bool Dart_IdentityEquals(Dart_Handle obj1, Dart_Handle obj2) { |
| 899 DARTSCOPE(Thread::Current()); | 891 DARTSCOPE(Thread::Current()); |
| 900 { | 892 { |
| 901 NoSafepointScope no_safepoint_scope; | 893 NoSafepointScope no_safepoint_scope; |
| 902 if (Api::UnwrapHandle(obj1) == Api::UnwrapHandle(obj2)) { | 894 if (Api::UnwrapHandle(obj1) == Api::UnwrapHandle(obj2)) { |
| 903 return true; | 895 return true; |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 949 if (bigint.FitsIntoUint64()) { | 941 if (bigint.FitsIntoUint64()) { |
| 950 return bigint.AsUint64Value(); | 942 return bigint.AsUint64Value(); |
| 951 } | 943 } |
| 952 } | 944 } |
| 953 return 0; | 945 return 0; |
| 954 } | 946 } |
| 955 | 947 |
| 956 | 948 |
| 957 DART_EXPORT Dart_Handle Dart_HandleFromPersistent( | 949 DART_EXPORT Dart_Handle Dart_HandleFromPersistent( |
| 958 Dart_PersistentHandle object) { | 950 Dart_PersistentHandle object) { |
| 959 Isolate* isolate = Isolate::Current(); | 951 Thread* thread = Thread::Current(); |
| 952 Isolate* isolate = thread->isolate(); |
| 960 CHECK_ISOLATE(isolate); | 953 CHECK_ISOLATE(isolate); |
| 961 ApiState* state = isolate->api_state(); | 954 ApiState* state = isolate->api_state(); |
| 962 ASSERT(state != NULL); | 955 ASSERT(state != NULL); |
| 963 PersistentHandle* ref = PersistentHandle::Cast(object); | 956 PersistentHandle* ref = PersistentHandle::Cast(object); |
| 964 return Api::NewHandle(isolate, ref->raw()); | 957 return Api::NewHandle(thread, ref->raw()); |
| 965 } | 958 } |
| 966 | 959 |
| 967 | 960 |
| 968 DART_EXPORT Dart_Handle Dart_HandleFromWeakPersistent( | 961 DART_EXPORT Dart_Handle Dart_HandleFromWeakPersistent( |
| 969 Dart_WeakPersistentHandle object) { | 962 Dart_WeakPersistentHandle object) { |
| 970 Isolate* isolate = Isolate::Current(); | 963 Thread* thread = Thread::Current(); |
| 964 Isolate* isolate = thread->isolate(); |
| 971 CHECK_ISOLATE(isolate); | 965 CHECK_ISOLATE(isolate); |
| 972 ApiState* state = isolate->api_state(); | 966 ApiState* state = isolate->api_state(); |
| 973 ASSERT(state != NULL); | 967 ASSERT(state != NULL); |
| 974 FinalizablePersistentHandle* weak_ref = | 968 FinalizablePersistentHandle* weak_ref = |
| 975 FinalizablePersistentHandle::Cast(object); | 969 FinalizablePersistentHandle::Cast(object); |
| 976 return Api::NewHandle(isolate, weak_ref->raw()); | 970 return Api::NewHandle(thread, weak_ref->raw()); |
| 977 } | 971 } |
| 978 | 972 |
| 979 | 973 |
| 980 DART_EXPORT Dart_PersistentHandle Dart_NewPersistentHandle(Dart_Handle object) { | 974 DART_EXPORT Dart_PersistentHandle Dart_NewPersistentHandle(Dart_Handle object) { |
| 981 DARTSCOPE(Thread::Current()); | 975 DARTSCOPE(Thread::Current()); |
| 976 Isolate* I = T->isolate(); |
| 982 ApiState* state = I->api_state(); | 977 ApiState* state = I->api_state(); |
| 983 ASSERT(state != NULL); | 978 ASSERT(state != NULL); |
| 984 const Object& old_ref = Object::Handle(Z, Api::UnwrapHandle(object)); | 979 const Object& old_ref = Object::Handle(Z, Api::UnwrapHandle(object)); |
| 985 PersistentHandle* new_ref = state->persistent_handles().AllocateHandle(); | 980 PersistentHandle* new_ref = state->persistent_handles().AllocateHandle(); |
| 986 new_ref->set_raw(old_ref); | 981 new_ref->set_raw(old_ref); |
| 987 return new_ref->apiHandle(); | 982 return new_ref->apiHandle(); |
| 988 } | 983 } |
| 989 | 984 |
| 990 | 985 |
| 991 DART_EXPORT void Dart_SetPersistentHandle(Dart_PersistentHandle obj1, | 986 DART_EXPORT void Dart_SetPersistentHandle(Dart_PersistentHandle obj1, |
| 992 Dart_Handle obj2) { | 987 Dart_Handle obj2) { |
| 993 DARTSCOPE(Thread::Current()); | 988 DARTSCOPE(Thread::Current()); |
| 989 Isolate* I = T->isolate(); |
| 994 ApiState* state = I->api_state(); | 990 ApiState* state = I->api_state(); |
| 995 ASSERT(state != NULL); | 991 ASSERT(state != NULL); |
| 996 ASSERT(state->IsValidPersistentHandle(obj1)); | 992 ASSERT(state->IsValidPersistentHandle(obj1)); |
| 997 const Object& obj2_ref = Object::Handle(Z, Api::UnwrapHandle(obj2)); | 993 const Object& obj2_ref = Object::Handle(Z, Api::UnwrapHandle(obj2)); |
| 998 PersistentHandle* obj1_ref = PersistentHandle::Cast(obj1); | 994 PersistentHandle* obj1_ref = PersistentHandle::Cast(obj1); |
| 999 obj1_ref->set_raw(obj2_ref); | 995 obj1_ref->set_raw(obj2_ref); |
| 1000 } | 996 } |
| 1001 | 997 |
| 1002 | 998 |
| 1003 static Dart_WeakPersistentHandle AllocateFinalizableHandle( | 999 static Dart_WeakPersistentHandle AllocateFinalizableHandle( |
| (...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1281 FATAL1("%s expects argument 'isolate' to be non-null.", CURRENT_FUNC); | 1277 FATAL1("%s expects argument 'isolate' to be non-null.", CURRENT_FUNC); |
| 1282 } | 1278 } |
| 1283 // TODO(16615): Validate isolate parameter. | 1279 // TODO(16615): Validate isolate parameter. |
| 1284 Isolate* iso = reinterpret_cast<Isolate*>(isolate); | 1280 Isolate* iso = reinterpret_cast<Isolate*>(isolate); |
| 1285 return iso->init_callback_data(); | 1281 return iso->init_callback_data(); |
| 1286 } | 1282 } |
| 1287 | 1283 |
| 1288 | 1284 |
| 1289 DART_EXPORT Dart_Handle Dart_DebugName() { | 1285 DART_EXPORT Dart_Handle Dart_DebugName() { |
| 1290 DARTSCOPE(Thread::Current()); | 1286 DARTSCOPE(Thread::Current()); |
| 1291 return Api::NewHandle(I, String::New(I->name())); | 1287 Isolate* I = T->isolate(); |
| 1288 return Api::NewHandle(T, String::New(I->name())); |
| 1292 } | 1289 } |
| 1293 | 1290 |
| 1294 | 1291 |
| 1295 | 1292 |
| 1296 DART_EXPORT void Dart_EnterIsolate(Dart_Isolate isolate) { | 1293 DART_EXPORT void Dart_EnterIsolate(Dart_Isolate isolate) { |
| 1297 CHECK_NO_ISOLATE(Isolate::Current()); | 1294 CHECK_NO_ISOLATE(Isolate::Current()); |
| 1298 // TODO(16615): Validate isolate parameter. | 1295 // TODO(16615): Validate isolate parameter. |
| 1299 Isolate* iso = reinterpret_cast<Isolate*>(isolate); | 1296 Isolate* iso = reinterpret_cast<Isolate*>(isolate); |
| 1300 if (iso->HasMutatorThread()) { | 1297 if (iso->HasMutatorThread()) { |
| 1301 FATAL("Multiple mutators within one isolate is not supported."); | 1298 FATAL("Multiple mutators within one isolate is not supported."); |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1341 "%s expects that the value is set to true only.", CURRENT_FUNC); | 1338 "%s expects that the value is set to true only.", CURRENT_FUNC); |
| 1342 } | 1339 } |
| 1343 Isolate::Current()->set_strict_compilation(); | 1340 Isolate::Current()->set_strict_compilation(); |
| 1344 return Api::Null(); | 1341 return Api::Null(); |
| 1345 } | 1342 } |
| 1346 | 1343 |
| 1347 | 1344 |
| 1348 static uint8_t* ApiReallocate(uint8_t* ptr, | 1345 static uint8_t* ApiReallocate(uint8_t* ptr, |
| 1349 intptr_t old_size, | 1346 intptr_t old_size, |
| 1350 intptr_t new_size) { | 1347 intptr_t new_size) { |
| 1351 return Api::TopScope(Isolate::Current())->zone()->Realloc<uint8_t>( | 1348 return Api::TopScope(Thread::Current())->zone()->Realloc<uint8_t>( |
| 1352 ptr, old_size, new_size); | 1349 ptr, old_size, new_size); |
| 1353 } | 1350 } |
| 1354 | 1351 |
| 1355 | 1352 |
| 1356 DART_EXPORT Dart_Handle Dart_CreateSnapshot( | 1353 DART_EXPORT Dart_Handle Dart_CreateSnapshot( |
| 1357 uint8_t** vm_isolate_snapshot_buffer, | 1354 uint8_t** vm_isolate_snapshot_buffer, |
| 1358 intptr_t* vm_isolate_snapshot_size, | 1355 intptr_t* vm_isolate_snapshot_size, |
| 1359 uint8_t** isolate_snapshot_buffer, | 1356 uint8_t** isolate_snapshot_buffer, |
| 1360 intptr_t* isolate_snapshot_size) { | 1357 intptr_t* isolate_snapshot_size) { |
| 1361 ASSERT(FLAG_load_deferred_eagerly); | 1358 ASSERT(FLAG_load_deferred_eagerly); |
| 1362 DARTSCOPE(Thread::Current()); | 1359 DARTSCOPE(Thread::Current()); |
| 1360 Isolate* I = T->isolate(); |
| 1363 if (vm_isolate_snapshot_buffer != NULL && | 1361 if (vm_isolate_snapshot_buffer != NULL && |
| 1364 vm_isolate_snapshot_size == NULL) { | 1362 vm_isolate_snapshot_size == NULL) { |
| 1365 RETURN_NULL_ERROR(vm_isolate_snapshot_size); | 1363 RETURN_NULL_ERROR(vm_isolate_snapshot_size); |
| 1366 } | 1364 } |
| 1367 if (isolate_snapshot_buffer == NULL) { | 1365 if (isolate_snapshot_buffer == NULL) { |
| 1368 RETURN_NULL_ERROR(isolate_snapshot_buffer); | 1366 RETURN_NULL_ERROR(isolate_snapshot_buffer); |
| 1369 } | 1367 } |
| 1370 if (isolate_snapshot_size == NULL) { | 1368 if (isolate_snapshot_size == NULL) { |
| 1371 RETURN_NULL_ERROR(isolate_snapshot_size); | 1369 RETURN_NULL_ERROR(isolate_snapshot_size); |
| 1372 } | 1370 } |
| 1373 // Finalize all classes if needed. | 1371 // Finalize all classes if needed. |
| 1374 Dart_Handle state = Api::CheckAndFinalizePendingClasses(I); | 1372 Dart_Handle state = Api::CheckAndFinalizePendingClasses(T); |
| 1375 if (::Dart_IsError(state)) { | 1373 if (::Dart_IsError(state)) { |
| 1376 return state; | 1374 return state; |
| 1377 } | 1375 } |
| 1378 I->heap()->CollectAllGarbage(); | 1376 I->heap()->CollectAllGarbage(); |
| 1379 #if defined(DEBUG) | 1377 #if defined(DEBUG) |
| 1380 FunctionVisitor check_canonical(T); | 1378 FunctionVisitor check_canonical(T); |
| 1381 I->heap()->IterateObjects(&check_canonical); | 1379 I->heap()->IterateObjects(&check_canonical); |
| 1382 #endif // #if defined(DEBUG). | 1380 #endif // #if defined(DEBUG). |
| 1383 | 1381 |
| 1384 // Since this is only a snapshot the root library should not be set. | 1382 // Since this is only a snapshot the root library should not be set. |
| 1385 I->object_store()->set_root_library(Library::Handle(Z)); | 1383 I->object_store()->set_root_library(Library::Handle(Z)); |
| 1386 FullSnapshotWriter writer(vm_isolate_snapshot_buffer, | 1384 FullSnapshotWriter writer(vm_isolate_snapshot_buffer, |
| 1387 isolate_snapshot_buffer, | 1385 isolate_snapshot_buffer, |
| 1388 NULL, /* instructions_snapshot_buffer */ | 1386 NULL, /* instructions_snapshot_buffer */ |
| 1389 ApiReallocate, | 1387 ApiReallocate, |
| 1390 false, /* snapshot_code */ | 1388 false, /* snapshot_code */ |
| 1391 true /* vm_isolate_is_symbolic */); | 1389 true /* vm_isolate_is_symbolic */); |
| 1392 writer.WriteFullSnapshot(); | 1390 writer.WriteFullSnapshot(); |
| 1393 *vm_isolate_snapshot_size = writer.VmIsolateSnapshotSize(); | 1391 *vm_isolate_snapshot_size = writer.VmIsolateSnapshotSize(); |
| 1394 *isolate_snapshot_size = writer.IsolateSnapshotSize(); | 1392 *isolate_snapshot_size = writer.IsolateSnapshotSize(); |
| 1395 return Api::Success(); | 1393 return Api::Success(); |
| 1396 } | 1394 } |
| 1397 | 1395 |
| 1398 | 1396 |
| 1399 static Dart_Handle createLibrarySnapshot(Dart_Handle library, | 1397 static Dart_Handle createLibrarySnapshot(Dart_Handle library, |
| 1400 uint8_t** buffer, | 1398 uint8_t** buffer, |
| 1401 intptr_t* size) { | 1399 intptr_t* size) { |
| 1402 DARTSCOPE(Thread::Current()); | 1400 DARTSCOPE(Thread::Current()); |
| 1401 Isolate* I = T->isolate(); |
| 1403 if (buffer == NULL) { | 1402 if (buffer == NULL) { |
| 1404 RETURN_NULL_ERROR(buffer); | 1403 RETURN_NULL_ERROR(buffer); |
| 1405 } | 1404 } |
| 1406 if (size == NULL) { | 1405 if (size == NULL) { |
| 1407 RETURN_NULL_ERROR(size); | 1406 RETURN_NULL_ERROR(size); |
| 1408 } | 1407 } |
| 1409 // Finalize all classes if needed. | 1408 // Finalize all classes if needed. |
| 1410 Dart_Handle state = Api::CheckAndFinalizePendingClasses(I); | 1409 Dart_Handle state = Api::CheckAndFinalizePendingClasses(T); |
| 1411 if (::Dart_IsError(state)) { | 1410 if (::Dart_IsError(state)) { |
| 1412 return state; | 1411 return state; |
| 1413 } | 1412 } |
| 1414 Library& lib = Library::Handle(Z); | 1413 Library& lib = Library::Handle(Z); |
| 1415 if (library == Dart_Null()) { | 1414 if (library == Dart_Null()) { |
| 1416 lib ^= I->object_store()->root_library(); | 1415 lib ^= I->object_store()->root_library(); |
| 1417 } else { | 1416 } else { |
| 1418 lib ^= Api::UnwrapHandle(library); | 1417 lib ^= Api::UnwrapHandle(library); |
| 1419 } | 1418 } |
| 1420 I->heap()->CollectAllGarbage(); | 1419 I->heap()->CollectAllGarbage(); |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1489 ASSERT(data->monitor != NULL); | 1488 ASSERT(data->monitor != NULL); |
| 1490 MonitorLocker ml(data->monitor); | 1489 MonitorLocker ml(data->monitor); |
| 1491 data->done = true; | 1490 data->done = true; |
| 1492 ml.Notify(); | 1491 ml.Notify(); |
| 1493 } | 1492 } |
| 1494 | 1493 |
| 1495 | 1494 |
| 1496 DART_EXPORT Dart_Handle Dart_RunLoop() { | 1495 DART_EXPORT Dart_Handle Dart_RunLoop() { |
| 1497 Thread* T = Thread::Current(); | 1496 Thread* T = Thread::Current(); |
| 1498 Isolate* I = T->isolate(); | 1497 Isolate* I = T->isolate(); |
| 1499 CHECK_ISOLATE_SCOPE(I); | 1498 CHECK_API_SCOPE(T); |
| 1500 CHECK_CALLBACK_STATE(T); | 1499 CHECK_CALLBACK_STATE(T); |
| 1501 Monitor monitor; | 1500 Monitor monitor; |
| 1502 MonitorLocker ml(&monitor); | 1501 MonitorLocker ml(&monitor); |
| 1503 { | 1502 { |
| 1504 // The message handler run loop does not expect to have a current isolate | 1503 // The message handler run loop does not expect to have a current isolate |
| 1505 // so we exit the isolate here and enter it again after the runloop is done. | 1504 // so we exit the isolate here and enter it again after the runloop is done. |
| 1506 Thread::ExitIsolate(); | 1505 Thread::ExitIsolate(); |
| 1507 RunLoopData data; | 1506 RunLoopData data; |
| 1508 data.monitor = &monitor; | 1507 data.monitor = &monitor; |
| 1509 data.done = false; | 1508 data.done = false; |
| 1510 I->message_handler()->Run( | 1509 I->message_handler()->Run( |
| 1511 Dart::thread_pool(), | 1510 Dart::thread_pool(), |
| 1512 NULL, RunLoopDone, reinterpret_cast<uword>(&data)); | 1511 NULL, RunLoopDone, reinterpret_cast<uword>(&data)); |
| 1513 while (!data.done) { | 1512 while (!data.done) { |
| 1514 ml.Wait(); | 1513 ml.Wait(); |
| 1515 } | 1514 } |
| 1516 Thread::EnterIsolate(I); | 1515 Thread::EnterIsolate(I); |
| 1517 } | 1516 } |
| 1518 if (I->object_store()->sticky_error() != Object::null()) { | 1517 if (I->object_store()->sticky_error() != Object::null()) { |
| 1519 Dart_Handle error = Api::NewHandle(I, I->object_store()->sticky_error()); | 1518 Dart_Handle error = Api::NewHandle(T, I->object_store()->sticky_error()); |
| 1520 I->object_store()->clear_sticky_error(); | 1519 I->object_store()->clear_sticky_error(); |
| 1521 return error; | 1520 return error; |
| 1522 } | 1521 } |
| 1523 if (FLAG_print_class_table) { | 1522 if (FLAG_print_class_table) { |
| 1524 HANDLESCOPE(T); | 1523 HANDLESCOPE(T); |
| 1525 I->class_table()->Print(); | 1524 I->class_table()->Print(); |
| 1526 } | 1525 } |
| 1527 return Api::Success(); | 1526 return Api::Success(); |
| 1528 } | 1527 } |
| 1529 | 1528 |
| 1530 | 1529 |
| 1531 DART_EXPORT Dart_Handle Dart_HandleMessage() { | 1530 DART_EXPORT Dart_Handle Dart_HandleMessage() { |
| 1532 Thread* thread = Thread::Current(); | 1531 Thread* T = Thread::Current(); |
| 1533 Isolate* isolate = thread->isolate(); | 1532 Isolate* I = T->isolate(); |
| 1534 CHECK_ISOLATE_SCOPE(isolate); | 1533 CHECK_API_SCOPE(T); |
| 1535 CHECK_CALLBACK_STATE(thread); | 1534 CHECK_CALLBACK_STATE(T); |
| 1536 if (isolate->message_handler()->HandleNextMessage() != MessageHandler::kOK) { | 1535 if (I->message_handler()->HandleNextMessage() != MessageHandler::kOK) { |
| 1537 Dart_Handle error = Api::NewHandle(isolate, | 1536 Dart_Handle error = Api::NewHandle(T, |
| 1538 isolate->object_store()->sticky_error()); | 1537 I->object_store()->sticky_error()); |
| 1539 isolate->object_store()->clear_sticky_error(); | 1538 I->object_store()->clear_sticky_error(); |
| 1540 return error; | 1539 return error; |
| 1541 } | 1540 } |
| 1542 return Api::Success(); | 1541 return Api::Success(); |
| 1543 } | 1542 } |
| 1544 | 1543 |
| 1545 | 1544 |
| 1546 DART_EXPORT bool Dart_HandleServiceMessages() { | 1545 DART_EXPORT bool Dart_HandleServiceMessages() { |
| 1547 Thread* thread = Thread::Current(); | 1546 Thread* T = Thread::Current(); |
| 1548 Isolate* isolate = thread->isolate(); | 1547 Isolate* I = T->isolate(); |
| 1549 CHECK_ISOLATE_SCOPE(isolate); | 1548 CHECK_API_SCOPE(T); |
| 1550 CHECK_CALLBACK_STATE(thread); | 1549 CHECK_CALLBACK_STATE(T); |
| 1551 | 1550 |
| 1552 ASSERT(isolate->GetAndClearResumeRequest() == false); | 1551 ASSERT(I->GetAndClearResumeRequest() == false); |
| 1553 MessageHandler::MessageStatus status = | 1552 MessageHandler::MessageStatus status = |
| 1554 isolate->message_handler()->HandleOOBMessages(); | 1553 I->message_handler()->HandleOOBMessages(); |
| 1555 bool resume = isolate->GetAndClearResumeRequest(); | 1554 bool resume = I->GetAndClearResumeRequest(); |
| 1556 return (status != MessageHandler::kOK) || resume; | 1555 return (status != MessageHandler::kOK) || resume; |
| 1557 } | 1556 } |
| 1558 | 1557 |
| 1559 | 1558 |
| 1560 DART_EXPORT bool Dart_HasServiceMessages() { | 1559 DART_EXPORT bool Dart_HasServiceMessages() { |
| 1561 Isolate* isolate = Isolate::Current(); | 1560 Isolate* isolate = Isolate::Current(); |
| 1562 ASSERT(isolate); | 1561 ASSERT(isolate); |
| 1563 return isolate->message_handler()->HasOOBMessages(); | 1562 return isolate->message_handler()->HasOOBMessages(); |
| 1564 } | 1563 } |
| 1565 | 1564 |
| (...skipping 27 matching lines...) Expand all Loading... |
| 1593 | 1592 |
| 1594 | 1593 |
| 1595 DART_EXPORT Dart_Handle Dart_NewSendPort(Dart_Port port_id) { | 1594 DART_EXPORT Dart_Handle Dart_NewSendPort(Dart_Port port_id) { |
| 1596 DARTSCOPE(Thread::Current()); | 1595 DARTSCOPE(Thread::Current()); |
| 1597 CHECK_CALLBACK_STATE(T); | 1596 CHECK_CALLBACK_STATE(T); |
| 1598 if (port_id == ILLEGAL_PORT) { | 1597 if (port_id == ILLEGAL_PORT) { |
| 1599 return Api::NewError("%s: illegal port_id %" Pd64 ".", | 1598 return Api::NewError("%s: illegal port_id %" Pd64 ".", |
| 1600 CURRENT_FUNC, | 1599 CURRENT_FUNC, |
| 1601 port_id); | 1600 port_id); |
| 1602 } | 1601 } |
| 1603 return Api::NewHandle(I, SendPort::New(port_id)); | 1602 return Api::NewHandle(T, SendPort::New(port_id)); |
| 1604 } | 1603 } |
| 1605 | 1604 |
| 1606 | 1605 |
| 1607 DART_EXPORT Dart_Handle Dart_SendPortGetId(Dart_Handle port, | 1606 DART_EXPORT Dart_Handle Dart_SendPortGetId(Dart_Handle port, |
| 1608 Dart_Port* port_id) { | 1607 Dart_Port* port_id) { |
| 1609 DARTSCOPE(Thread::Current()); | 1608 DARTSCOPE(Thread::Current()); |
| 1610 CHECK_CALLBACK_STATE(T); | 1609 CHECK_CALLBACK_STATE(T); |
| 1611 const SendPort& send_port = Api::UnwrapSendPortHandle(Z, port); | 1610 const SendPort& send_port = Api::UnwrapSendPortHandle(Z, port); |
| 1612 if (send_port.IsNull()) { | 1611 if (send_port.IsNull()) { |
| 1613 RETURN_TYPE_ERROR(Z, port, SendPort); | 1612 RETURN_TYPE_ERROR(Z, port, SendPort); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 1626 return isolate->main_port(); | 1625 return isolate->main_port(); |
| 1627 } | 1626 } |
| 1628 | 1627 |
| 1629 | 1628 |
| 1630 // --- Scopes ---- | 1629 // --- Scopes ---- |
| 1631 | 1630 |
| 1632 DART_EXPORT void Dart_EnterScope() { | 1631 DART_EXPORT void Dart_EnterScope() { |
| 1633 Thread* thread = Thread::Current(); | 1632 Thread* thread = Thread::Current(); |
| 1634 Isolate* isolate = thread->isolate(); | 1633 Isolate* isolate = thread->isolate(); |
| 1635 CHECK_ISOLATE(isolate); | 1634 CHECK_ISOLATE(isolate); |
| 1636 ApiState* state = isolate->api_state(); | 1635 ApiLocalScope* new_scope = thread->api_reusable_scope(); |
| 1637 ASSERT(state != NULL); | |
| 1638 ApiLocalScope* new_scope = state->reusable_scope(); | |
| 1639 if (new_scope == NULL) { | 1636 if (new_scope == NULL) { |
| 1640 new_scope = new ApiLocalScope(state->top_scope(), | 1637 new_scope = new ApiLocalScope(thread->api_top_scope(), |
| 1641 thread->top_exit_frame_info()); | 1638 thread->top_exit_frame_info()); |
| 1642 ASSERT(new_scope != NULL); | 1639 ASSERT(new_scope != NULL); |
| 1643 } else { | 1640 } else { |
| 1644 new_scope->Reinit(thread, | 1641 new_scope->Reinit(thread, |
| 1645 state->top_scope(), | 1642 thread->api_top_scope(), |
| 1646 thread->top_exit_frame_info()); | 1643 thread->top_exit_frame_info()); |
| 1647 state->set_reusable_scope(NULL); | 1644 thread->set_api_reusable_scope(NULL); |
| 1648 } | 1645 } |
| 1649 state->set_top_scope(new_scope); // New scope is now the top scope. | 1646 thread->set_api_top_scope(new_scope); // New scope is now the top scope. |
| 1650 } | 1647 } |
| 1651 | 1648 |
| 1652 | 1649 |
| 1653 DART_EXPORT void Dart_ExitScope() { | 1650 DART_EXPORT void Dart_ExitScope() { |
| 1654 Thread* thread = Thread::Current(); | 1651 Thread* T = Thread::Current(); |
| 1655 Isolate* isolate = thread->isolate(); | 1652 CHECK_API_SCOPE(T); |
| 1656 CHECK_ISOLATE_SCOPE(isolate); | 1653 ApiLocalScope* scope = T->api_top_scope(); |
| 1657 ApiState* state = isolate->api_state(); | 1654 ApiLocalScope* reusable_scope = T->api_reusable_scope(); |
| 1658 ApiLocalScope* scope = state->top_scope(); | 1655 T->set_api_top_scope(scope->previous()); // Reset top scope to previous. |
| 1659 ApiLocalScope* reusable_scope = state->reusable_scope(); | |
| 1660 state->set_top_scope(scope->previous()); // Reset top scope to previous. | |
| 1661 if (reusable_scope == NULL) { | 1656 if (reusable_scope == NULL) { |
| 1662 scope->Reset(thread); // Reset the old scope which we just exited. | 1657 scope->Reset(T); // Reset the old scope which we just exited. |
| 1663 state->set_reusable_scope(scope); | 1658 T->set_api_reusable_scope(scope); |
| 1664 } else { | 1659 } else { |
| 1665 ASSERT(reusable_scope != scope); | 1660 ASSERT(reusable_scope != scope); |
| 1666 delete scope; | 1661 delete scope; |
| 1667 } | 1662 } |
| 1668 } | 1663 } |
| 1669 | 1664 |
| 1670 | 1665 |
| 1671 DART_EXPORT uint8_t* Dart_ScopeAllocate(intptr_t size) { | 1666 DART_EXPORT uint8_t* Dart_ScopeAllocate(intptr_t size) { |
| 1672 Zone* zone; | 1667 Zone* zone; |
| 1673 Isolate* isolate = Isolate::Current(); | 1668 Thread* thread = Thread::Current(); |
| 1674 if (isolate != NULL) { | 1669 if (thread != NULL) { |
| 1675 ApiState* state = isolate->api_state(); | 1670 ApiLocalScope* scope = thread->api_top_scope(); |
| 1676 if (state == NULL) return NULL; | |
| 1677 ApiLocalScope* scope = state->top_scope(); | |
| 1678 zone = scope->zone(); | 1671 zone = scope->zone(); |
| 1679 } else { | 1672 } else { |
| 1680 ApiNativeScope* scope = ApiNativeScope::Current(); | 1673 ApiNativeScope* scope = ApiNativeScope::Current(); |
| 1681 if (scope == NULL) return NULL; | 1674 if (scope == NULL) return NULL; |
| 1682 zone = scope->zone(); | 1675 zone = scope->zone(); |
| 1683 } | 1676 } |
| 1684 return reinterpret_cast<uint8_t*>(zone->AllocUnsafe(size)); | 1677 return reinterpret_cast<uint8_t*>(zone->AllocUnsafe(size)); |
| 1685 } | 1678 } |
| 1686 | 1679 |
| 1687 | 1680 |
| (...skipping 23 matching lines...) Expand all Loading... |
| 1711 const Instance& expected = | 1704 const Instance& expected = |
| 1712 Instance::CheckedHandle(Z, Api::UnwrapHandle(obj1)); | 1705 Instance::CheckedHandle(Z, Api::UnwrapHandle(obj1)); |
| 1713 const Instance& actual = | 1706 const Instance& actual = |
| 1714 Instance::CheckedHandle(Z, Api::UnwrapHandle(obj2)); | 1707 Instance::CheckedHandle(Z, Api::UnwrapHandle(obj2)); |
| 1715 const Object& result = | 1708 const Object& result = |
| 1716 Object::Handle(Z, DartLibraryCalls::Equals(expected, actual)); | 1709 Object::Handle(Z, DartLibraryCalls::Equals(expected, actual)); |
| 1717 if (result.IsBool()) { | 1710 if (result.IsBool()) { |
| 1718 *value = Bool::Cast(result).value(); | 1711 *value = Bool::Cast(result).value(); |
| 1719 return Api::Success(); | 1712 return Api::Success(); |
| 1720 } else if (result.IsError()) { | 1713 } else if (result.IsError()) { |
| 1721 return Api::NewHandle(I, result.raw()); | 1714 return Api::NewHandle(T, result.raw()); |
| 1722 } else { | 1715 } else { |
| 1723 return Api::NewError("Expected boolean result from =="); | 1716 return Api::NewError("Expected boolean result from =="); |
| 1724 } | 1717 } |
| 1725 } | 1718 } |
| 1726 | 1719 |
| 1727 | 1720 |
| 1728 // TODO(iposva): This call actually implements IsInstanceOfClass. | 1721 // TODO(iposva): This call actually implements IsInstanceOfClass. |
| 1729 // Do we also need a real Dart_IsInstanceOf, which should take an instance | 1722 // Do we also need a real Dart_IsInstanceOf, which should take an instance |
| 1730 // rather than an object? | 1723 // rather than an object? |
| 1731 DART_EXPORT Dart_Handle Dart_ObjectIsType(Dart_Handle object, | 1724 DART_EXPORT Dart_Handle Dart_ObjectIsType(Dart_Handle object, |
| (...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1886 | 1879 |
| 1887 DART_EXPORT bool Dart_IsByteBuffer(Dart_Handle handle) { | 1880 DART_EXPORT bool Dart_IsByteBuffer(Dart_Handle handle) { |
| 1888 TRACE_API_CALL(CURRENT_FUNC); | 1881 TRACE_API_CALL(CURRENT_FUNC); |
| 1889 return Api::ClassId(handle) == kByteBufferCid; | 1882 return Api::ClassId(handle) == kByteBufferCid; |
| 1890 } | 1883 } |
| 1891 | 1884 |
| 1892 | 1885 |
| 1893 DART_EXPORT bool Dart_IsFuture(Dart_Handle handle) { | 1886 DART_EXPORT bool Dart_IsFuture(Dart_Handle handle) { |
| 1894 TRACE_API_CALL(CURRENT_FUNC); | 1887 TRACE_API_CALL(CURRENT_FUNC); |
| 1895 DARTSCOPE(Thread::Current()); | 1888 DARTSCOPE(Thread::Current()); |
| 1889 Isolate* I = T->isolate(); |
| 1896 const Object& obj = Object::Handle(Z, Api::UnwrapHandle(handle)); | 1890 const Object& obj = Object::Handle(Z, Api::UnwrapHandle(handle)); |
| 1897 if (obj.IsInstance()) { | 1891 if (obj.IsInstance()) { |
| 1898 const Class& future_class = | 1892 const Class& future_class = |
| 1899 Class::Handle(I->object_store()->future_class()); | 1893 Class::Handle(I->object_store()->future_class()); |
| 1900 ASSERT(!future_class.IsNull()); | 1894 ASSERT(!future_class.IsNull()); |
| 1901 const Class& obj_class = Class::Handle(Z, obj.clazz()); | 1895 const Class& obj_class = Class::Handle(Z, obj.clazz()); |
| 1902 Error& malformed_type_error = Error::Handle(Z); | 1896 Error& malformed_type_error = Error::Handle(Z); |
| 1903 bool is_future = obj_class.IsSubtypeOf(Object::null_type_arguments(), | 1897 bool is_future = obj_class.IsSubtypeOf(Object::null_type_arguments(), |
| 1904 future_class, | 1898 future_class, |
| 1905 Object::null_type_arguments(), | 1899 Object::null_type_arguments(), |
| 1906 &malformed_type_error); | 1900 &malformed_type_error); |
| 1907 ASSERT(malformed_type_error.IsNull()); // Type is a raw Future. | 1901 ASSERT(malformed_type_error.IsNull()); // Type is a raw Future. |
| 1908 return is_future; | 1902 return is_future; |
| 1909 } | 1903 } |
| 1910 return false; | 1904 return false; |
| 1911 } | 1905 } |
| 1912 | 1906 |
| 1913 | 1907 |
| 1914 // --- Instances ---- | 1908 // --- Instances ---- |
| 1915 | 1909 |
| 1916 DART_EXPORT Dart_Handle Dart_InstanceGetType(Dart_Handle instance) { | 1910 DART_EXPORT Dart_Handle Dart_InstanceGetType(Dart_Handle instance) { |
| 1917 DARTSCOPE(Thread::Current()); | 1911 DARTSCOPE(Thread::Current()); |
| 1912 Isolate* I = T->isolate(); |
| 1918 const Object& obj = Object::Handle(Z, Api::UnwrapHandle(instance)); | 1913 const Object& obj = Object::Handle(Z, Api::UnwrapHandle(instance)); |
| 1919 if (obj.IsNull()) { | 1914 if (obj.IsNull()) { |
| 1920 return Api::NewHandle(I, I->object_store()->null_type()); | 1915 return Api::NewHandle(T, I->object_store()->null_type()); |
| 1921 } | 1916 } |
| 1922 if (!obj.IsInstance()) { | 1917 if (!obj.IsInstance()) { |
| 1923 RETURN_TYPE_ERROR(Z, instance, Instance); | 1918 RETURN_TYPE_ERROR(Z, instance, Instance); |
| 1924 } | 1919 } |
| 1925 const Type& type = Type::Handle(Instance::Cast(obj).GetType()); | 1920 const Type& type = Type::Handle(Instance::Cast(obj).GetType()); |
| 1926 return Api::NewHandle(I, type.Canonicalize()); | 1921 return Api::NewHandle(T, type.Canonicalize()); |
| 1927 } | 1922 } |
| 1928 | 1923 |
| 1929 | 1924 |
| 1930 // --- Numbers, Integers and Doubles ---- | 1925 // --- Numbers, Integers and Doubles ---- |
| 1931 | 1926 |
| 1932 DART_EXPORT Dart_Handle Dart_IntegerFitsIntoInt64(Dart_Handle integer, | 1927 DART_EXPORT Dart_Handle Dart_IntegerFitsIntoInt64(Dart_Handle integer, |
| 1933 bool* fits) { | 1928 bool* fits) { |
| 1934 // Fast path for Smis and Mints. | 1929 // Fast path for Smis and Mints. |
| 1935 Thread* thread = Thread::Current(); | 1930 Thread* thread = Thread::Current(); |
| 1936 Isolate* isolate = thread->isolate(); | 1931 Isolate* isolate = thread->isolate(); |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1978 } | 1973 } |
| 1979 | 1974 |
| 1980 | 1975 |
| 1981 DART_EXPORT Dart_Handle Dart_NewInteger(int64_t value) { | 1976 DART_EXPORT Dart_Handle Dart_NewInteger(int64_t value) { |
| 1982 // Fast path for Smis. | 1977 // Fast path for Smis. |
| 1983 Thread* thread = Thread::Current(); | 1978 Thread* thread = Thread::Current(); |
| 1984 Isolate* isolate = thread->isolate(); | 1979 Isolate* isolate = thread->isolate(); |
| 1985 CHECK_ISOLATE(isolate); | 1980 CHECK_ISOLATE(isolate); |
| 1986 if (Smi::IsValid(value)) { | 1981 if (Smi::IsValid(value)) { |
| 1987 NOHANDLESCOPE(thread); | 1982 NOHANDLESCOPE(thread); |
| 1988 return Api::NewHandle(isolate, Smi::New(static_cast<intptr_t>(value))); | 1983 return Api::NewHandle(thread, Smi::New(static_cast<intptr_t>(value))); |
| 1989 } | 1984 } |
| 1990 // Slow path for Mints and Bigints. | 1985 // Slow path for Mints and Bigints. |
| 1991 DARTSCOPE(thread); | 1986 DARTSCOPE(thread); |
| 1992 CHECK_CALLBACK_STATE(thread); | 1987 CHECK_CALLBACK_STATE(thread); |
| 1993 return Api::NewHandle(isolate, Integer::New(value)); | 1988 return Api::NewHandle(thread, Integer::New(value)); |
| 1994 } | 1989 } |
| 1995 | 1990 |
| 1996 | 1991 |
| 1997 DART_EXPORT Dart_Handle Dart_NewIntegerFromUint64(uint64_t value) { | 1992 DART_EXPORT Dart_Handle Dart_NewIntegerFromUint64(uint64_t value) { |
| 1998 DARTSCOPE(Thread::Current()); | 1993 DARTSCOPE(Thread::Current()); |
| 1999 CHECK_CALLBACK_STATE(T); | 1994 CHECK_CALLBACK_STATE(T); |
| 2000 return Api::NewHandle(I, Integer::NewFromUint64(value)); | 1995 return Api::NewHandle(T, Integer::NewFromUint64(value)); |
| 2001 } | 1996 } |
| 2002 | 1997 |
| 2003 | 1998 |
| 2004 DART_EXPORT Dart_Handle Dart_NewIntegerFromHexCString(const char* str) { | 1999 DART_EXPORT Dart_Handle Dart_NewIntegerFromHexCString(const char* str) { |
| 2005 DARTSCOPE(Thread::Current()); | 2000 DARTSCOPE(Thread::Current()); |
| 2006 CHECK_CALLBACK_STATE(T); | 2001 CHECK_CALLBACK_STATE(T); |
| 2007 const String& str_obj = String::Handle(Z, String::New(str)); | 2002 const String& str_obj = String::Handle(Z, String::New(str)); |
| 2008 return Api::NewHandle(I, Integer::New(str_obj)); | 2003 return Api::NewHandle(T, Integer::New(str_obj)); |
| 2009 } | 2004 } |
| 2010 | 2005 |
| 2011 | 2006 |
| 2012 DART_EXPORT Dart_Handle Dart_IntegerToInt64(Dart_Handle integer, | 2007 DART_EXPORT Dart_Handle Dart_IntegerToInt64(Dart_Handle integer, |
| 2013 int64_t* value) { | 2008 int64_t* value) { |
| 2014 // Fast path for Smis. | 2009 // Fast path for Smis. |
| 2015 Thread* thread = Thread::Current(); | 2010 Thread* thread = Thread::Current(); |
| 2016 Isolate* isolate = thread->isolate(); | 2011 Isolate* isolate = thread->isolate(); |
| 2017 CHECK_ISOLATE(isolate); | 2012 CHECK_ISOLATE(isolate); |
| 2018 if (Api::IsSmi(integer)) { | 2013 if (Api::IsSmi(integer)) { |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2071 *value = bigint.AsUint64Value(); | 2066 *value = bigint.AsUint64Value(); |
| 2072 return Api::Success(); | 2067 return Api::Success(); |
| 2073 } | 2068 } |
| 2074 } | 2069 } |
| 2075 return Api::NewError("%s: Integer %s cannot be represented as a uint64_t.", | 2070 return Api::NewError("%s: Integer %s cannot be represented as a uint64_t.", |
| 2076 CURRENT_FUNC, int_obj.ToCString()); | 2071 CURRENT_FUNC, int_obj.ToCString()); |
| 2077 } | 2072 } |
| 2078 | 2073 |
| 2079 | 2074 |
| 2080 static uword BigintAllocate(intptr_t size) { | 2075 static uword BigintAllocate(intptr_t size) { |
| 2081 return Api::TopScope(Isolate::Current())->zone()->AllocUnsafe(size); | 2076 return Api::TopScope(Thread::Current())->zone()->AllocUnsafe(size); |
| 2082 } | 2077 } |
| 2083 | 2078 |
| 2084 | 2079 |
| 2085 DART_EXPORT Dart_Handle Dart_IntegerToHexCString(Dart_Handle integer, | 2080 DART_EXPORT Dart_Handle Dart_IntegerToHexCString(Dart_Handle integer, |
| 2086 const char** value) { | 2081 const char** value) { |
| 2087 DARTSCOPE(Thread::Current()); | 2082 DARTSCOPE(Thread::Current()); |
| 2088 const Integer& int_obj = Api::UnwrapIntegerHandle(Z, integer); | 2083 const Integer& int_obj = Api::UnwrapIntegerHandle(Z, integer); |
| 2089 if (int_obj.IsNull()) { | 2084 if (int_obj.IsNull()) { |
| 2090 RETURN_TYPE_ERROR(Z, integer, Integer); | 2085 RETURN_TYPE_ERROR(Z, integer, Integer); |
| 2091 } | 2086 } |
| 2092 if (int_obj.IsSmi() || int_obj.IsMint()) { | 2087 if (int_obj.IsSmi() || int_obj.IsMint()) { |
| 2093 const Bigint& bigint = Bigint::Handle(Z, | 2088 const Bigint& bigint = Bigint::Handle(Z, |
| 2094 Bigint::NewFromInt64(int_obj.AsInt64Value())); | 2089 Bigint::NewFromInt64(int_obj.AsInt64Value())); |
| 2095 *value = bigint.ToHexCString(BigintAllocate); | 2090 *value = bigint.ToHexCString(BigintAllocate); |
| 2096 } else { | 2091 } else { |
| 2097 *value = Bigint::Cast(int_obj).ToHexCString(BigintAllocate); | 2092 *value = Bigint::Cast(int_obj).ToHexCString(BigintAllocate); |
| 2098 } | 2093 } |
| 2099 return Api::Success(); | 2094 return Api::Success(); |
| 2100 } | 2095 } |
| 2101 | 2096 |
| 2102 | 2097 |
| 2103 DART_EXPORT Dart_Handle Dart_NewDouble(double value) { | 2098 DART_EXPORT Dart_Handle Dart_NewDouble(double value) { |
| 2104 DARTSCOPE(Thread::Current()); | 2099 DARTSCOPE(Thread::Current()); |
| 2105 CHECK_CALLBACK_STATE(T); | 2100 CHECK_CALLBACK_STATE(T); |
| 2106 return Api::NewHandle(I, Double::New(value)); | 2101 return Api::NewHandle(T, Double::New(value)); |
| 2107 } | 2102 } |
| 2108 | 2103 |
| 2109 | 2104 |
| 2110 DART_EXPORT Dart_Handle Dart_DoubleValue(Dart_Handle double_obj, | 2105 DART_EXPORT Dart_Handle Dart_DoubleValue(Dart_Handle double_obj, |
| 2111 double* value) { | 2106 double* value) { |
| 2112 DARTSCOPE(Thread::Current()); | 2107 DARTSCOPE(Thread::Current()); |
| 2113 const Double& obj = Api::UnwrapDoubleHandle(Z, double_obj); | 2108 const Double& obj = Api::UnwrapDoubleHandle(Z, double_obj); |
| 2114 if (obj.IsNull()) { | 2109 if (obj.IsNull()) { |
| 2115 RETURN_TYPE_ERROR(Z, double_obj, Double); | 2110 RETURN_TYPE_ERROR(Z, double_obj, Double); |
| 2116 } | 2111 } |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2167 return Api::Success(); | 2162 return Api::Success(); |
| 2168 } | 2163 } |
| 2169 | 2164 |
| 2170 | 2165 |
| 2171 DART_EXPORT Dart_Handle Dart_NewStringFromCString(const char* str) { | 2166 DART_EXPORT Dart_Handle Dart_NewStringFromCString(const char* str) { |
| 2172 DARTSCOPE(Thread::Current()); | 2167 DARTSCOPE(Thread::Current()); |
| 2173 if (str == NULL) { | 2168 if (str == NULL) { |
| 2174 RETURN_NULL_ERROR(str); | 2169 RETURN_NULL_ERROR(str); |
| 2175 } | 2170 } |
| 2176 CHECK_CALLBACK_STATE(T); | 2171 CHECK_CALLBACK_STATE(T); |
| 2177 return Api::NewHandle(I, String::New(str)); | 2172 return Api::NewHandle(T, String::New(str)); |
| 2178 } | 2173 } |
| 2179 | 2174 |
| 2180 | 2175 |
| 2181 DART_EXPORT Dart_Handle Dart_NewStringFromUTF8(const uint8_t* utf8_array, | 2176 DART_EXPORT Dart_Handle Dart_NewStringFromUTF8(const uint8_t* utf8_array, |
| 2182 intptr_t length) { | 2177 intptr_t length) { |
| 2183 DARTSCOPE(Thread::Current()); | 2178 DARTSCOPE(Thread::Current()); |
| 2184 if (utf8_array == NULL && length != 0) { | 2179 if (utf8_array == NULL && length != 0) { |
| 2185 RETURN_NULL_ERROR(utf8_array); | 2180 RETURN_NULL_ERROR(utf8_array); |
| 2186 } | 2181 } |
| 2187 CHECK_LENGTH(length, String::kMaxElements); | 2182 CHECK_LENGTH(length, String::kMaxElements); |
| 2188 if (!Utf8::IsValid(utf8_array, length)) { | 2183 if (!Utf8::IsValid(utf8_array, length)) { |
| 2189 return Api::NewError("%s expects argument 'str' to be valid UTF-8.", | 2184 return Api::NewError("%s expects argument 'str' to be valid UTF-8.", |
| 2190 CURRENT_FUNC); | 2185 CURRENT_FUNC); |
| 2191 } | 2186 } |
| 2192 CHECK_CALLBACK_STATE(T); | 2187 CHECK_CALLBACK_STATE(T); |
| 2193 return Api::NewHandle(I, String::FromUTF8(utf8_array, length)); | 2188 return Api::NewHandle(T, String::FromUTF8(utf8_array, length)); |
| 2194 } | 2189 } |
| 2195 | 2190 |
| 2196 | 2191 |
| 2197 DART_EXPORT Dart_Handle Dart_NewStringFromUTF16(const uint16_t* utf16_array, | 2192 DART_EXPORT Dart_Handle Dart_NewStringFromUTF16(const uint16_t* utf16_array, |
| 2198 intptr_t length) { | 2193 intptr_t length) { |
| 2199 DARTSCOPE(Thread::Current()); | 2194 DARTSCOPE(Thread::Current()); |
| 2200 if (utf16_array == NULL && length != 0) { | 2195 if (utf16_array == NULL && length != 0) { |
| 2201 RETURN_NULL_ERROR(utf16_array); | 2196 RETURN_NULL_ERROR(utf16_array); |
| 2202 } | 2197 } |
| 2203 CHECK_LENGTH(length, String::kMaxElements); | 2198 CHECK_LENGTH(length, String::kMaxElements); |
| 2204 CHECK_CALLBACK_STATE(T); | 2199 CHECK_CALLBACK_STATE(T); |
| 2205 return Api::NewHandle(I, String::FromUTF16(utf16_array, length)); | 2200 return Api::NewHandle(T, String::FromUTF16(utf16_array, length)); |
| 2206 } | 2201 } |
| 2207 | 2202 |
| 2208 | 2203 |
| 2209 DART_EXPORT Dart_Handle Dart_NewStringFromUTF32(const int32_t* utf32_array, | 2204 DART_EXPORT Dart_Handle Dart_NewStringFromUTF32(const int32_t* utf32_array, |
| 2210 intptr_t length) { | 2205 intptr_t length) { |
| 2211 DARTSCOPE(Thread::Current()); | 2206 DARTSCOPE(Thread::Current()); |
| 2212 if (utf32_array == NULL && length != 0) { | 2207 if (utf32_array == NULL && length != 0) { |
| 2213 RETURN_NULL_ERROR(utf32_array); | 2208 RETURN_NULL_ERROR(utf32_array); |
| 2214 } | 2209 } |
| 2215 CHECK_LENGTH(length, String::kMaxElements); | 2210 CHECK_LENGTH(length, String::kMaxElements); |
| 2216 CHECK_CALLBACK_STATE(T); | 2211 CHECK_CALLBACK_STATE(T); |
| 2217 return Api::NewHandle(I, String::FromUTF32(utf32_array, length)); | 2212 return Api::NewHandle(T, String::FromUTF32(utf32_array, length)); |
| 2218 } | 2213 } |
| 2219 | 2214 |
| 2220 | 2215 |
| 2221 DART_EXPORT Dart_Handle Dart_NewExternalLatin1String( | 2216 DART_EXPORT Dart_Handle Dart_NewExternalLatin1String( |
| 2222 const uint8_t* latin1_array, | 2217 const uint8_t* latin1_array, |
| 2223 intptr_t length, | 2218 intptr_t length, |
| 2224 void* peer, | 2219 void* peer, |
| 2225 Dart_PeerFinalizer cback) { | 2220 Dart_PeerFinalizer cback) { |
| 2226 DARTSCOPE(Thread::Current()); | 2221 DARTSCOPE(Thread::Current()); |
| 2227 if (latin1_array == NULL && length != 0) { | 2222 if (latin1_array == NULL && length != 0) { |
| 2228 RETURN_NULL_ERROR(latin1_array); | 2223 RETURN_NULL_ERROR(latin1_array); |
| 2229 } | 2224 } |
| 2230 CHECK_LENGTH(length, String::kMaxElements); | 2225 CHECK_LENGTH(length, String::kMaxElements); |
| 2231 CHECK_CALLBACK_STATE(T); | 2226 CHECK_CALLBACK_STATE(T); |
| 2232 return Api::NewHandle(I, | 2227 return Api::NewHandle(T, |
| 2233 String::NewExternal(latin1_array, | 2228 String::NewExternal(latin1_array, |
| 2234 length, | 2229 length, |
| 2235 peer, | 2230 peer, |
| 2236 cback, | 2231 cback, |
| 2237 SpaceForExternal(I, length))); | 2232 SpaceForExternal(T, length))); |
| 2238 } | 2233 } |
| 2239 | 2234 |
| 2240 | 2235 |
| 2241 DART_EXPORT Dart_Handle Dart_NewExternalUTF16String(const uint16_t* utf16_array, | 2236 DART_EXPORT Dart_Handle Dart_NewExternalUTF16String(const uint16_t* utf16_array, |
| 2242 intptr_t length, | 2237 intptr_t length, |
| 2243 void* peer, | 2238 void* peer, |
| 2244 Dart_PeerFinalizer cback) { | 2239 Dart_PeerFinalizer cback) { |
| 2245 DARTSCOPE(Thread::Current()); | 2240 DARTSCOPE(Thread::Current()); |
| 2246 if (utf16_array == NULL && length != 0) { | 2241 if (utf16_array == NULL && length != 0) { |
| 2247 RETURN_NULL_ERROR(utf16_array); | 2242 RETURN_NULL_ERROR(utf16_array); |
| 2248 } | 2243 } |
| 2249 CHECK_LENGTH(length, String::kMaxElements); | 2244 CHECK_LENGTH(length, String::kMaxElements); |
| 2250 CHECK_CALLBACK_STATE(T); | 2245 CHECK_CALLBACK_STATE(T); |
| 2251 intptr_t bytes = length * sizeof(*utf16_array); | 2246 intptr_t bytes = length * sizeof(*utf16_array); |
| 2252 return Api::NewHandle(I, | 2247 return Api::NewHandle(T, |
| 2253 String::NewExternal(utf16_array, | 2248 String::NewExternal(utf16_array, |
| 2254 length, | 2249 length, |
| 2255 peer, | 2250 peer, |
| 2256 cback, | 2251 cback, |
| 2257 SpaceForExternal(I, bytes))); | 2252 SpaceForExternal(T, bytes))); |
| 2258 } | 2253 } |
| 2259 | 2254 |
| 2260 | 2255 |
| 2261 DART_EXPORT Dart_Handle Dart_StringToCString(Dart_Handle object, | 2256 DART_EXPORT Dart_Handle Dart_StringToCString(Dart_Handle object, |
| 2262 const char** cstr) { | 2257 const char** cstr) { |
| 2263 DARTSCOPE(Thread::Current()); | 2258 DARTSCOPE(Thread::Current()); |
| 2264 if (cstr == NULL) { | 2259 if (cstr == NULL) { |
| 2265 RETURN_NULL_ERROR(cstr); | 2260 RETURN_NULL_ERROR(cstr); |
| 2266 } | 2261 } |
| 2267 const String& str_obj = Api::UnwrapStringHandle(Z, object); | 2262 const String& str_obj = Api::UnwrapStringHandle(Z, object); |
| 2268 if (str_obj.IsNull()) { | 2263 if (str_obj.IsNull()) { |
| 2269 RETURN_TYPE_ERROR(Z, object, String); | 2264 RETURN_TYPE_ERROR(Z, object, String); |
| 2270 } | 2265 } |
| 2271 intptr_t string_length = Utf8::Length(str_obj); | 2266 intptr_t string_length = Utf8::Length(str_obj); |
| 2272 char* res = Api::TopScope(I)->zone()->Alloc<char>(string_length + 1); | 2267 char* res = Api::TopScope(T)->zone()->Alloc<char>(string_length + 1); |
| 2273 if (res == NULL) { | 2268 if (res == NULL) { |
| 2274 return Api::NewError("Unable to allocate memory"); | 2269 return Api::NewError("Unable to allocate memory"); |
| 2275 } | 2270 } |
| 2276 const char* string_value = str_obj.ToCString(); | 2271 const char* string_value = str_obj.ToCString(); |
| 2277 memmove(res, string_value, string_length + 1); | 2272 memmove(res, string_value, string_length + 1); |
| 2278 ASSERT(res[string_length] == '\0'); | 2273 ASSERT(res[string_length] == '\0'); |
| 2279 *cstr = res; | 2274 *cstr = res; |
| 2280 return Api::Success(); | 2275 return Api::Success(); |
| 2281 } | 2276 } |
| 2282 | 2277 |
| 2283 | 2278 |
| 2284 DART_EXPORT Dart_Handle Dart_StringToUTF8(Dart_Handle str, | 2279 DART_EXPORT Dart_Handle Dart_StringToUTF8(Dart_Handle str, |
| 2285 uint8_t** utf8_array, | 2280 uint8_t** utf8_array, |
| 2286 intptr_t* length) { | 2281 intptr_t* length) { |
| 2287 DARTSCOPE(Thread::Current()); | 2282 DARTSCOPE(Thread::Current()); |
| 2288 if (utf8_array == NULL) { | 2283 if (utf8_array == NULL) { |
| 2289 RETURN_NULL_ERROR(utf8_array); | 2284 RETURN_NULL_ERROR(utf8_array); |
| 2290 } | 2285 } |
| 2291 if (length == NULL) { | 2286 if (length == NULL) { |
| 2292 RETURN_NULL_ERROR(length); | 2287 RETURN_NULL_ERROR(length); |
| 2293 } | 2288 } |
| 2294 const String& str_obj = Api::UnwrapStringHandle(Z, str); | 2289 const String& str_obj = Api::UnwrapStringHandle(Z, str); |
| 2295 if (str_obj.IsNull()) { | 2290 if (str_obj.IsNull()) { |
| 2296 RETURN_TYPE_ERROR(Z, str, String); | 2291 RETURN_TYPE_ERROR(Z, str, String); |
| 2297 } | 2292 } |
| 2298 intptr_t str_len = Utf8::Length(str_obj); | 2293 intptr_t str_len = Utf8::Length(str_obj); |
| 2299 *utf8_array = Api::TopScope(I)->zone()->Alloc<uint8_t>(str_len); | 2294 *utf8_array = Api::TopScope(T)->zone()->Alloc<uint8_t>(str_len); |
| 2300 if (*utf8_array == NULL) { | 2295 if (*utf8_array == NULL) { |
| 2301 return Api::NewError("Unable to allocate memory"); | 2296 return Api::NewError("Unable to allocate memory"); |
| 2302 } | 2297 } |
| 2303 str_obj.ToUTF8(*utf8_array, str_len); | 2298 str_obj.ToUTF8(*utf8_array, str_len); |
| 2304 *length = str_len; | 2299 *length = str_len; |
| 2305 return Api::Success(); | 2300 return Api::Success(); |
| 2306 } | 2301 } |
| 2307 | 2302 |
| 2308 | 2303 |
| 2309 DART_EXPORT Dart_Handle Dart_StringToLatin1(Dart_Handle str, | 2304 DART_EXPORT Dart_Handle Dart_StringToLatin1(Dart_Handle str, |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2409 ASSERT(str_obj.IsTwoByteString()); | 2404 ASSERT(str_obj.IsTwoByteString()); |
| 2410 ASSERT(length >= (copy_len * str_obj.CharSize())); | 2405 ASSERT(length >= (copy_len * str_obj.CharSize())); |
| 2411 uint16_t* utf16_array = reinterpret_cast<uint16_t*>(array); | 2406 uint16_t* utf16_array = reinterpret_cast<uint16_t*>(array); |
| 2412 for (intptr_t i = 0; i < copy_len; i++) { | 2407 for (intptr_t i = 0; i < copy_len; i++) { |
| 2413 utf16_array[i] = str_obj.CharAt(i); | 2408 utf16_array[i] = str_obj.CharAt(i); |
| 2414 } | 2409 } |
| 2415 TwoByteString::SetPeer(str_obj, peer, cback); | 2410 TwoByteString::SetPeer(str_obj, peer, cback); |
| 2416 } | 2411 } |
| 2417 return str; | 2412 return str; |
| 2418 } | 2413 } |
| 2419 return Api::NewHandle(I, str_obj.MakeExternal(array, length, peer, cback)); | 2414 return Api::NewHandle(T, str_obj.MakeExternal(array, length, peer, cback)); |
| 2420 } | 2415 } |
| 2421 | 2416 |
| 2422 | 2417 |
| 2423 DART_EXPORT Dart_Handle Dart_StringGetProperties(Dart_Handle object, | 2418 DART_EXPORT Dart_Handle Dart_StringGetProperties(Dart_Handle object, |
| 2424 intptr_t* char_size, | 2419 intptr_t* char_size, |
| 2425 intptr_t* str_len, | 2420 intptr_t* str_len, |
| 2426 void** peer) { | 2421 void** peer) { |
| 2427 Thread* thread = Thread::Current(); | 2422 Thread* thread = Thread::Current(); |
| 2428 CHECK_ISOLATE(thread->isolate()); | 2423 CHECK_ISOLATE(thread->isolate()); |
| 2429 ReusableObjectHandleScope reused_obj_handle(thread); | 2424 ReusableObjectHandleScope reused_obj_handle(thread); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 2443 return Api::Success(); | 2438 return Api::Success(); |
| 2444 } | 2439 } |
| 2445 | 2440 |
| 2446 | 2441 |
| 2447 // --- Lists --- | 2442 // --- Lists --- |
| 2448 | 2443 |
| 2449 DART_EXPORT Dart_Handle Dart_NewList(intptr_t length) { | 2444 DART_EXPORT Dart_Handle Dart_NewList(intptr_t length) { |
| 2450 DARTSCOPE(Thread::Current()); | 2445 DARTSCOPE(Thread::Current()); |
| 2451 CHECK_LENGTH(length, Array::kMaxElements); | 2446 CHECK_LENGTH(length, Array::kMaxElements); |
| 2452 CHECK_CALLBACK_STATE(T); | 2447 CHECK_CALLBACK_STATE(T); |
| 2453 return Api::NewHandle(I, Array::New(length)); | 2448 return Api::NewHandle(T, Array::New(length)); |
| 2454 } | 2449 } |
| 2455 | 2450 |
| 2456 | 2451 |
| 2457 #define GET_LIST_LENGTH(zone, type, obj, len) \ | 2452 #define GET_LIST_LENGTH(zone, type, obj, len) \ |
| 2458 type& array = type::Handle(zone); \ | 2453 type& array = type::Handle(zone); \ |
| 2459 array ^= obj.raw(); \ | 2454 array ^= obj.raw(); \ |
| 2460 *len = array.Length(); \ | 2455 *len = array.Length(); \ |
| 2461 return Api::Success(); \ | 2456 return Api::Success(); \ |
| 2462 | 2457 |
| 2463 | 2458 |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2517 if (bigint.FitsIntoInt64()) { | 2512 if (bigint.FitsIntoInt64()) { |
| 2518 int64_t bigint_value = bigint.AsInt64Value(); | 2513 int64_t bigint_value = bigint.AsInt64Value(); |
| 2519 if (bigint_value >= kIntptrMin && bigint_value <= kIntptrMax) { | 2514 if (bigint_value >= kIntptrMin && bigint_value <= kIntptrMax) { |
| 2520 *len = static_cast<intptr_t>(bigint_value); | 2515 *len = static_cast<intptr_t>(bigint_value); |
| 2521 } | 2516 } |
| 2522 } | 2517 } |
| 2523 } | 2518 } |
| 2524 return Api::NewError("Length of List object is greater than the " | 2519 return Api::NewError("Length of List object is greater than the " |
| 2525 "maximum value that 'len' parameter can hold"); | 2520 "maximum value that 'len' parameter can hold"); |
| 2526 } else if (retval.IsError()) { | 2521 } else if (retval.IsError()) { |
| 2527 return Api::NewHandle(I, retval.raw()); | 2522 return Api::NewHandle(T, retval.raw()); |
| 2528 } else { | 2523 } else { |
| 2529 return Api::NewError("Length of List object is not an integer"); | 2524 return Api::NewError("Length of List object is not an integer"); |
| 2530 } | 2525 } |
| 2531 } | 2526 } |
| 2532 | 2527 |
| 2533 | 2528 |
| 2534 #define GET_LIST_ELEMENT(isolate, type, obj, index) \ | 2529 #define GET_LIST_ELEMENT(thread, type, obj, index) \ |
| 2535 const type& array_obj = type::Cast(obj); \ | 2530 const type& array_obj = type::Cast(obj); \ |
| 2536 if ((index >= 0) && (index < array_obj.Length())) { \ | 2531 if ((index >= 0) && (index < array_obj.Length())) { \ |
| 2537 return Api::NewHandle(isolate, array_obj.At(index)); \ | 2532 return Api::NewHandle(thread, array_obj.At(index)); \ |
| 2538 } \ | 2533 } \ |
| 2539 return Api::NewError("Invalid index passed in to access list element"); \ | 2534 return Api::NewError("Invalid index passed in to access list element"); \ |
| 2540 | 2535 |
| 2541 | 2536 |
| 2542 DART_EXPORT Dart_Handle Dart_ListGetAt(Dart_Handle list, intptr_t index) { | 2537 DART_EXPORT Dart_Handle Dart_ListGetAt(Dart_Handle list, intptr_t index) { |
| 2543 DARTSCOPE(Thread::Current()); | 2538 DARTSCOPE(Thread::Current()); |
| 2544 const Object& obj = Object::Handle(Z, Api::UnwrapHandle(list)); | 2539 const Object& obj = Object::Handle(Z, Api::UnwrapHandle(list)); |
| 2545 if (obj.IsArray()) { | 2540 if (obj.IsArray()) { |
| 2546 GET_LIST_ELEMENT(I, Array, obj, index); | 2541 GET_LIST_ELEMENT(T, Array, obj, index); |
| 2547 } else if (obj.IsGrowableObjectArray()) { | 2542 } else if (obj.IsGrowableObjectArray()) { |
| 2548 GET_LIST_ELEMENT(I, GrowableObjectArray, obj, index); | 2543 GET_LIST_ELEMENT(T, GrowableObjectArray, obj, index); |
| 2549 } else if (obj.IsError()) { | 2544 } else if (obj.IsError()) { |
| 2550 return list; | 2545 return list; |
| 2551 } else { | 2546 } else { |
| 2552 CHECK_CALLBACK_STATE(T); | 2547 CHECK_CALLBACK_STATE(T); |
| 2553 // Check and handle a dart object that implements the List interface. | 2548 // Check and handle a dart object that implements the List interface. |
| 2554 const Instance& instance = Instance::Handle(Z, GetListInstance(Z, obj)); | 2549 const Instance& instance = Instance::Handle(Z, GetListInstance(Z, obj)); |
| 2555 if (!instance.IsNull()) { | 2550 if (!instance.IsNull()) { |
| 2556 return Api::NewHandle(I, Send1Arg( | 2551 return Api::NewHandle(T, Send1Arg( |
| 2557 instance, | 2552 instance, |
| 2558 Symbols::IndexToken(), | 2553 Symbols::IndexToken(), |
| 2559 Instance::Handle(Z, Integer::New(index)))); | 2554 Instance::Handle(Z, Integer::New(index)))); |
| 2560 } | 2555 } |
| 2561 return Api::NewError("Object does not implement the 'List' interface"); | 2556 return Api::NewError("Object does not implement the 'List' interface"); |
| 2562 } | 2557 } |
| 2563 } | 2558 } |
| 2564 | 2559 |
| 2565 | 2560 |
| 2566 #define GET_LIST_RANGE(isolate, type, obj, offset, length) \ | 2561 #define GET_LIST_RANGE(thread, type, obj, offset, length) \ |
| 2567 const type& array_obj = type::Cast(obj); \ | 2562 const type& array_obj = type::Cast(obj); \ |
| 2568 if ((offset >= 0) && (offset + length <= array_obj.Length())) { \ | 2563 if ((offset >= 0) && (offset + length <= array_obj.Length())) { \ |
| 2569 for (intptr_t index = 0; index < length; ++index) { \ | 2564 for (intptr_t index = 0; index < length; ++index) { \ |
| 2570 result[index] = Api::NewHandle(isolate, array_obj.At(index + offset)); \ | 2565 result[index] = Api::NewHandle(thread, array_obj.At(index + offset)); \ |
| 2571 } \ | 2566 } \ |
| 2572 return Api::Success(); \ | 2567 return Api::Success(); \ |
| 2573 } \ | 2568 } \ |
| 2574 return Api::NewError("Invalid offset/length passed in to access list"); \ | 2569 return Api::NewError("Invalid offset/length passed in to access list"); \ |
| 2575 | 2570 |
| 2576 | 2571 |
| 2577 DART_EXPORT Dart_Handle Dart_ListGetRange(Dart_Handle list, | 2572 DART_EXPORT Dart_Handle Dart_ListGetRange(Dart_Handle list, |
| 2578 intptr_t offset, | 2573 intptr_t offset, |
| 2579 intptr_t length, | 2574 intptr_t length, |
| 2580 Dart_Handle* result) { | 2575 Dart_Handle* result) { |
| 2581 DARTSCOPE(Thread::Current()); | 2576 DARTSCOPE(Thread::Current()); |
| 2582 if (result == NULL) { | 2577 if (result == NULL) { |
| 2583 RETURN_NULL_ERROR(result); | 2578 RETURN_NULL_ERROR(result); |
| 2584 } | 2579 } |
| 2585 const Object& obj = Object::Handle(Z, Api::UnwrapHandle(list)); | 2580 const Object& obj = Object::Handle(Z, Api::UnwrapHandle(list)); |
| 2586 if (obj.IsArray()) { | 2581 if (obj.IsArray()) { |
| 2587 GET_LIST_RANGE(I, Array, obj, offset, length); | 2582 GET_LIST_RANGE(T, Array, obj, offset, length); |
| 2588 } else if (obj.IsGrowableObjectArray()) { | 2583 } else if (obj.IsGrowableObjectArray()) { |
| 2589 GET_LIST_RANGE(I, GrowableObjectArray, obj, offset, length); | 2584 GET_LIST_RANGE(T, GrowableObjectArray, obj, offset, length); |
| 2590 } else if (obj.IsError()) { | 2585 } else if (obj.IsError()) { |
| 2591 return list; | 2586 return list; |
| 2592 } else { | 2587 } else { |
| 2593 CHECK_CALLBACK_STATE(T); | 2588 CHECK_CALLBACK_STATE(T); |
| 2594 // Check and handle a dart object that implements the List interface. | 2589 // Check and handle a dart object that implements the List interface. |
| 2595 const Instance& instance = Instance::Handle(Z, GetListInstance(Z, obj)); | 2590 const Instance& instance = Instance::Handle(Z, GetListInstance(Z, obj)); |
| 2596 if (!instance.IsNull()) { | 2591 if (!instance.IsNull()) { |
| 2597 const intptr_t kNumArgs = 2; | 2592 const intptr_t kNumArgs = 2; |
| 2598 ArgumentsDescriptor args_desc( | 2593 ArgumentsDescriptor args_desc( |
| 2599 Array::Handle(ArgumentsDescriptor::New(kNumArgs))); | 2594 Array::Handle(ArgumentsDescriptor::New(kNumArgs))); |
| 2600 const Function& function = Function::Handle(Z, | 2595 const Function& function = Function::Handle(Z, |
| 2601 Resolver::ResolveDynamic(instance, | 2596 Resolver::ResolveDynamic(instance, |
| 2602 Symbols::AssignIndexToken(), | 2597 Symbols::AssignIndexToken(), |
| 2603 args_desc)); | 2598 args_desc)); |
| 2604 if (!function.IsNull()) { | 2599 if (!function.IsNull()) { |
| 2605 const Array& args = Array::Handle(Array::New(kNumArgs)); | 2600 const Array& args = Array::Handle(Array::New(kNumArgs)); |
| 2606 args.SetAt(0, instance); | 2601 args.SetAt(0, instance); |
| 2607 Instance& index = Instance::Handle(Z); | 2602 Instance& index = Instance::Handle(Z); |
| 2608 for (intptr_t i = 0; i < length; ++i) { | 2603 for (intptr_t i = 0; i < length; ++i) { |
| 2609 index = Integer::New(i); | 2604 index = Integer::New(i); |
| 2610 args.SetAt(1, index); | 2605 args.SetAt(1, index); |
| 2611 Dart_Handle value = Api::NewHandle(I, | 2606 Dart_Handle value = Api::NewHandle(T, |
| 2612 DartEntry::InvokeFunction(function, args)); | 2607 DartEntry::InvokeFunction(function, args)); |
| 2613 if (::Dart_IsError(value)) | 2608 if (::Dart_IsError(value)) |
| 2614 return value; | 2609 return value; |
| 2615 result[i] = value; | 2610 result[i] = value; |
| 2616 } | 2611 } |
| 2617 return Api::Success(); | 2612 return Api::Success(); |
| 2618 } | 2613 } |
| 2619 } | 2614 } |
| 2620 return Api::NewError("Object does not implement the 'List' interface"); | 2615 return Api::NewError("Object does not implement the 'List' interface"); |
| 2621 } | 2616 } |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2664 if (!function.IsNull()) { | 2659 if (!function.IsNull()) { |
| 2665 const Integer& index_obj = Integer::Handle(Z, Integer::New(index)); | 2660 const Integer& index_obj = Integer::Handle(Z, Integer::New(index)); |
| 2666 const Object& value_obj = Object::Handle(Z, Api::UnwrapHandle(value)); | 2661 const Object& value_obj = Object::Handle(Z, Api::UnwrapHandle(value)); |
| 2667 if (!value_obj.IsNull() && !value_obj.IsInstance()) { | 2662 if (!value_obj.IsNull() && !value_obj.IsInstance()) { |
| 2668 RETURN_TYPE_ERROR(Z, value, Instance); | 2663 RETURN_TYPE_ERROR(Z, value, Instance); |
| 2669 } | 2664 } |
| 2670 const Array& args = Array::Handle(Z, Array::New(kNumArgs)); | 2665 const Array& args = Array::Handle(Z, Array::New(kNumArgs)); |
| 2671 args.SetAt(0, instance); | 2666 args.SetAt(0, instance); |
| 2672 args.SetAt(1, index_obj); | 2667 args.SetAt(1, index_obj); |
| 2673 args.SetAt(2, value_obj); | 2668 args.SetAt(2, value_obj); |
| 2674 return Api::NewHandle(I, DartEntry::InvokeFunction(function, | 2669 return Api::NewHandle( |
| 2675 args)); | 2670 T, DartEntry::InvokeFunction(function, args)); |
| 2676 } | 2671 } |
| 2677 } | 2672 } |
| 2678 return Api::NewError("Object does not implement the 'List' interface"); | 2673 return Api::NewError("Object does not implement the 'List' interface"); |
| 2679 } | 2674 } |
| 2680 } | 2675 } |
| 2681 | 2676 |
| 2682 | 2677 |
| 2683 static RawObject* ResolveConstructor(const char* current_func, | 2678 static RawObject* ResolveConstructor(const char* current_func, |
| 2684 const Class& cls, | 2679 const Class& cls, |
| 2685 const String& class_name, | 2680 const String& class_name, |
| 2686 const String& dotted_name, | 2681 const String& dotted_name, |
| 2687 int num_args); | 2682 int num_args); |
| 2688 | 2683 |
| 2689 | 2684 |
| 2690 static RawObject* ThrowArgumentError(const char* exception_message) { | 2685 static RawObject* ThrowArgumentError(const char* exception_message) { |
| 2691 Thread* thread = Thread::Current(); | 2686 Thread* thread = Thread::Current(); |
| 2692 Isolate* isolate = thread->isolate(); | |
| 2693 Zone* zone = thread->zone(); | 2687 Zone* zone = thread->zone(); |
| 2694 // Lookup the class ArgumentError in dart:core. | 2688 // Lookup the class ArgumentError in dart:core. |
| 2695 const String& lib_url = String::Handle(String::New("dart:core")); | 2689 const String& lib_url = String::Handle(String::New("dart:core")); |
| 2696 const String& class_name = String::Handle(String::New("ArgumentError")); | 2690 const String& class_name = String::Handle(String::New("ArgumentError")); |
| 2697 const Library& lib = | 2691 const Library& lib = |
| 2698 Library::Handle(zone, Library::LookupLibrary(lib_url)); | 2692 Library::Handle(zone, Library::LookupLibrary(lib_url)); |
| 2699 if (lib.IsNull()) { | 2693 if (lib.IsNull()) { |
| 2700 const String& message = String::Handle( | 2694 const String& message = String::Handle( |
| 2701 String::NewFormatted("%s: library '%s' not found.", | 2695 String::NewFormatted("%s: library '%s' not found.", |
| 2702 CURRENT_FUNC, lib_url.ToCString())); | 2696 CURRENT_FUNC, lib_url.ToCString())); |
| (...skipping 28 matching lines...) Expand all Loading... |
| 2731 | 2725 |
| 2732 if (thread->top_exit_frame_info() == 0) { | 2726 if (thread->top_exit_frame_info() == 0) { |
| 2733 // There are no dart frames on the stack so it would be illegal to | 2727 // There are no dart frames on the stack so it would be illegal to |
| 2734 // throw an exception here. | 2728 // throw an exception here. |
| 2735 const String& message = String::Handle( | 2729 const String& message = String::Handle( |
| 2736 String::New("No Dart frames on stack, cannot throw exception")); | 2730 String::New("No Dart frames on stack, cannot throw exception")); |
| 2737 return ApiError::New(message); | 2731 return ApiError::New(message); |
| 2738 } | 2732 } |
| 2739 // Unwind all the API scopes till the exit frame before throwing an | 2733 // Unwind all the API scopes till the exit frame before throwing an |
| 2740 // exception. | 2734 // exception. |
| 2741 ApiState* state = isolate->api_state(); | |
| 2742 ASSERT(state != NULL); | |
| 2743 const Instance* saved_exception; | 2735 const Instance* saved_exception; |
| 2744 { | 2736 { |
| 2745 NoSafepointScope no_safepoint; | 2737 NoSafepointScope no_safepoint; |
| 2746 RawInstance* raw_exception = exception.raw(); | 2738 RawInstance* raw_exception = exception.raw(); |
| 2747 state->UnwindScopes(thread->top_exit_frame_info()); | 2739 thread->UnwindScopes(thread->top_exit_frame_info()); |
| 2748 saved_exception = &Instance::Handle(raw_exception); | 2740 saved_exception = &Instance::Handle(raw_exception); |
| 2749 } | 2741 } |
| 2750 Exceptions::Throw(thread, *saved_exception); | 2742 Exceptions::Throw(thread, *saved_exception); |
| 2751 const String& message = String::Handle( | 2743 const String& message = String::Handle( |
| 2752 String::New("Exception was not thrown, internal error")); | 2744 String::New("Exception was not thrown, internal error")); |
| 2753 return ApiError::New(message); | 2745 return ApiError::New(message); |
| 2754 } | 2746 } |
| 2755 | 2747 |
| 2756 // TODO(sgjesse): value should always be smaller then 0xff. Add error handling. | 2748 // TODO(sgjesse): value should always be smaller then 0xff. Add error handling. |
| 2757 #define GET_LIST_ELEMENT_AS_BYTES(type, obj, native_array, offset, length) \ | 2749 #define GET_LIST_ELEMENT_AS_BYTES(type, obj, native_array, offset, length) \ |
| 2758 const type& array = type::Cast(obj); \ | 2750 const type& array = type::Cast(obj); \ |
| 2759 if (Utils::RangeCheck(offset, length, array.Length())) { \ | 2751 if (Utils::RangeCheck(offset, length, array.Length())) { \ |
| 2760 Object& element = Object::Handle(Z); \ | 2752 Object& element = Object::Handle(Z); \ |
| 2761 for (int i = 0; i < length; i++) { \ | 2753 for (int i = 0; i < length; i++) { \ |
| 2762 element = array.At(offset + i); \ | 2754 element = array.At(offset + i); \ |
| 2763 if (!element.IsInteger()) { \ | 2755 if (!element.IsInteger()) { \ |
| 2764 return Api::NewHandle(I, \ | 2756 return Api::NewHandle(T, \ |
| 2765 ThrowArgumentError("List contains non-int elements")); \ | 2757 ThrowArgumentError("List contains non-int elements")); \ |
| 2766 \ | 2758 \ |
| 2767 } \ | 2759 } \ |
| 2768 const Integer& integer = Integer::Cast(element); \ | 2760 const Integer& integer = Integer::Cast(element); \ |
| 2769 native_array[i] = static_cast<uint8_t>(integer.AsInt64Value() & 0xff); \ | 2761 native_array[i] = static_cast<uint8_t>(integer.AsInt64Value() & 0xff); \ |
| 2770 ASSERT(integer.AsInt64Value() <= 0xff); \ | 2762 ASSERT(integer.AsInt64Value() <= 0xff); \ |
| 2771 } \ | 2763 } \ |
| 2772 return Api::Success(); \ | 2764 return Api::Success(); \ |
| 2773 } \ | 2765 } \ |
| 2774 return Api::NewError("Invalid length passed in to access array elements"); \ | 2766 return Api::NewError("Invalid length passed in to access array elements"); \ |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2859 Object& result = Object::Handle(Z); | 2851 Object& result = Object::Handle(Z); |
| 2860 Integer& intobj = Integer::Handle(Z); | 2852 Integer& intobj = Integer::Handle(Z); |
| 2861 const Array& args = Array::Handle(Z, Array::New(kNumArgs)); | 2853 const Array& args = Array::Handle(Z, Array::New(kNumArgs)); |
| 2862 args.SetAt(0, instance); // Set up the receiver as the first argument. | 2854 args.SetAt(0, instance); // Set up the receiver as the first argument. |
| 2863 for (int i = 0; i < length; i++) { | 2855 for (int i = 0; i < length; i++) { |
| 2864 HANDLESCOPE(T); | 2856 HANDLESCOPE(T); |
| 2865 intobj = Integer::New(offset + i); | 2857 intobj = Integer::New(offset + i); |
| 2866 args.SetAt(1, intobj); | 2858 args.SetAt(1, intobj); |
| 2867 result = DartEntry::InvokeFunction(function, args); | 2859 result = DartEntry::InvokeFunction(function, args); |
| 2868 if (result.IsError()) { | 2860 if (result.IsError()) { |
| 2869 return Api::NewHandle(I, result.raw()); | 2861 return Api::NewHandle(T, result.raw()); |
| 2870 } | 2862 } |
| 2871 if (!result.IsInteger()) { | 2863 if (!result.IsInteger()) { |
| 2872 return Api::NewError("%s expects the argument 'list' to be " | 2864 return Api::NewError("%s expects the argument 'list' to be " |
| 2873 "a List of int", CURRENT_FUNC); | 2865 "a List of int", CURRENT_FUNC); |
| 2874 } | 2866 } |
| 2875 const Integer& integer_result = Integer::Cast(result); | 2867 const Integer& integer_result = Integer::Cast(result); |
| 2876 ASSERT(integer_result.AsInt64Value() <= 0xff); | 2868 ASSERT(integer_result.AsInt64Value() <= 0xff); |
| 2877 // TODO(hpayer): value should always be smaller then 0xff. Add error | 2869 // TODO(hpayer): value should always be smaller then 0xff. Add error |
| 2878 // handling. | 2870 // handling. |
| 2879 native_array[i] = | 2871 native_array[i] = |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2948 const Array& args = Array::Handle(Z, Array::New(kNumArgs)); | 2940 const Array& args = Array::Handle(Z, Array::New(kNumArgs)); |
| 2949 args.SetAt(0, instance); // Set up the receiver as the first argument. | 2941 args.SetAt(0, instance); // Set up the receiver as the first argument. |
| 2950 for (int i = 0; i < length; i++) { | 2942 for (int i = 0; i < length; i++) { |
| 2951 indexobj = Integer::New(offset + i); | 2943 indexobj = Integer::New(offset + i); |
| 2952 valueobj = Integer::New(native_array[i]); | 2944 valueobj = Integer::New(native_array[i]); |
| 2953 args.SetAt(1, indexobj); | 2945 args.SetAt(1, indexobj); |
| 2954 args.SetAt(2, valueobj); | 2946 args.SetAt(2, valueobj); |
| 2955 const Object& result = Object::Handle(Z, | 2947 const Object& result = Object::Handle(Z, |
| 2956 DartEntry::InvokeFunction(function, args)); | 2948 DartEntry::InvokeFunction(function, args)); |
| 2957 if (result.IsError()) { | 2949 if (result.IsError()) { |
| 2958 return Api::NewHandle(I, result.raw()); | 2950 return Api::NewHandle(T, result.raw()); |
| 2959 } | 2951 } |
| 2960 } | 2952 } |
| 2961 return Api::Success(); | 2953 return Api::Success(); |
| 2962 } | 2954 } |
| 2963 } | 2955 } |
| 2964 return Api::NewError("Object does not implement the 'List' interface"); | 2956 return Api::NewError("Object does not implement the 'List' interface"); |
| 2965 } | 2957 } |
| 2966 | 2958 |
| 2967 | 2959 |
| 2968 // --- Maps --- | 2960 // --- Maps --- |
| 2969 | 2961 |
| 2970 DART_EXPORT Dart_Handle Dart_MapGetAt(Dart_Handle map, Dart_Handle key) { | 2962 DART_EXPORT Dart_Handle Dart_MapGetAt(Dart_Handle map, Dart_Handle key) { |
| 2971 DARTSCOPE(Thread::Current()); | 2963 DARTSCOPE(Thread::Current()); |
| 2972 CHECK_CALLBACK_STATE(T); | 2964 CHECK_CALLBACK_STATE(T); |
| 2973 const Object& obj = Object::Handle(Z, Api::UnwrapHandle(map)); | 2965 const Object& obj = Object::Handle(Z, Api::UnwrapHandle(map)); |
| 2974 const Instance& instance = Instance::Handle(Z, GetMapInstance(Z, obj)); | 2966 const Instance& instance = Instance::Handle(Z, GetMapInstance(Z, obj)); |
| 2975 if (!instance.IsNull()) { | 2967 if (!instance.IsNull()) { |
| 2976 const Object& key_obj = Object::Handle(Api::UnwrapHandle(key)); | 2968 const Object& key_obj = Object::Handle(Api::UnwrapHandle(key)); |
| 2977 if (!(key_obj.IsInstance() || key_obj.IsNull())) { | 2969 if (!(key_obj.IsInstance() || key_obj.IsNull())) { |
| 2978 return Api::NewError("Key is not an instance"); | 2970 return Api::NewError("Key is not an instance"); |
| 2979 } | 2971 } |
| 2980 return Api::NewHandle(I, | 2972 return Api::NewHandle(T, |
| 2981 Send1Arg(instance, Symbols::IndexToken(), Instance::Cast(key_obj))); | 2973 Send1Arg(instance, Symbols::IndexToken(), Instance::Cast(key_obj))); |
| 2982 } | 2974 } |
| 2983 return Api::NewError("Object does not implement the 'Map' interface"); | 2975 return Api::NewError("Object does not implement the 'Map' interface"); |
| 2984 } | 2976 } |
| 2985 | 2977 |
| 2986 | 2978 |
| 2987 DART_EXPORT Dart_Handle Dart_MapContainsKey(Dart_Handle map, Dart_Handle key) { | 2979 DART_EXPORT Dart_Handle Dart_MapContainsKey(Dart_Handle map, Dart_Handle key) { |
| 2988 DARTSCOPE(Thread::Current()); | 2980 DARTSCOPE(Thread::Current()); |
| 2989 CHECK_CALLBACK_STATE(T); | 2981 CHECK_CALLBACK_STATE(T); |
| 2990 const Object& obj = Object::Handle(Z, Api::UnwrapHandle(map)); | 2982 const Object& obj = Object::Handle(Z, Api::UnwrapHandle(map)); |
| 2991 const Instance& instance = Instance::Handle(Z, GetMapInstance(Z, obj)); | 2983 const Instance& instance = Instance::Handle(Z, GetMapInstance(Z, obj)); |
| 2992 if (!instance.IsNull()) { | 2984 if (!instance.IsNull()) { |
| 2993 const Object& key_obj = Object::Handle(Z, Api::UnwrapHandle(key)); | 2985 const Object& key_obj = Object::Handle(Z, Api::UnwrapHandle(key)); |
| 2994 if (!(key_obj.IsInstance() || key_obj.IsNull())) { | 2986 if (!(key_obj.IsInstance() || key_obj.IsNull())) { |
| 2995 return Api::NewError("Key is not an instance"); | 2987 return Api::NewError("Key is not an instance"); |
| 2996 } | 2988 } |
| 2997 return Api::NewHandle(I, Send1Arg( | 2989 return Api::NewHandle(T, Send1Arg( |
| 2998 instance, | 2990 instance, |
| 2999 String::Handle(Z, String::New("containsKey")), | 2991 String::Handle(Z, String::New("containsKey")), |
| 3000 Instance::Cast(key_obj))); | 2992 Instance::Cast(key_obj))); |
| 3001 } | 2993 } |
| 3002 return Api::NewError("Object does not implement the 'Map' interface"); | 2994 return Api::NewError("Object does not implement the 'Map' interface"); |
| 3003 } | 2995 } |
| 3004 | 2996 |
| 3005 | 2997 |
| 3006 DART_EXPORT Dart_Handle Dart_MapKeys(Dart_Handle map) { | 2998 DART_EXPORT Dart_Handle Dart_MapKeys(Dart_Handle map) { |
| 3007 DARTSCOPE(Thread::Current()); | 2999 DARTSCOPE(Thread::Current()); |
| 3008 CHECK_CALLBACK_STATE(T); | 3000 CHECK_CALLBACK_STATE(T); |
| 3009 Object& obj = Object::Handle(Z, Api::UnwrapHandle(map)); | 3001 Object& obj = Object::Handle(Z, Api::UnwrapHandle(map)); |
| 3010 Instance& instance = Instance::Handle(Z, GetMapInstance(Z, obj)); | 3002 Instance& instance = Instance::Handle(Z, GetMapInstance(Z, obj)); |
| 3011 if (!instance.IsNull()) { | 3003 if (!instance.IsNull()) { |
| 3012 const Object& iterator = Object::Handle(Send0Arg( | 3004 const Object& iterator = Object::Handle(Send0Arg( |
| 3013 instance, String::Handle(Z, String::New("get:keys")))); | 3005 instance, String::Handle(Z, String::New("get:keys")))); |
| 3014 if (!iterator.IsInstance()) { | 3006 if (!iterator.IsInstance()) { |
| 3015 return Api::NewHandle(I, iterator.raw()); | 3007 return Api::NewHandle(T, iterator.raw()); |
| 3016 } | 3008 } |
| 3017 return Api::NewHandle(I, Send0Arg( | 3009 return Api::NewHandle(T, Send0Arg( |
| 3018 Instance::Cast(iterator), | 3010 Instance::Cast(iterator), |
| 3019 String::Handle(String::New("toList")))); | 3011 String::Handle(String::New("toList")))); |
| 3020 } | 3012 } |
| 3021 return Api::NewError("Object does not implement the 'Map' interface"); | 3013 return Api::NewError("Object does not implement the 'Map' interface"); |
| 3022 } | 3014 } |
| 3023 | 3015 |
| 3024 | 3016 |
| 3025 // --- Typed Data --- | 3017 // --- Typed Data --- |
| 3026 | 3018 |
| 3027 // Helper method to get the type of a TypedData object. | 3019 // Helper method to get the type of a TypedData object. |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3144 return ResolveConstructor(CURRENT_FUNC, | 3136 return ResolveConstructor(CURRENT_FUNC, |
| 3145 cls, | 3137 cls, |
| 3146 Symbols::ByteData(), | 3138 Symbols::ByteData(), |
| 3147 constructor_name, | 3139 constructor_name, |
| 3148 num_args); | 3140 num_args); |
| 3149 } | 3141 } |
| 3150 | 3142 |
| 3151 | 3143 |
| 3152 static Dart_Handle NewByteData(Thread* thread, intptr_t length) { | 3144 static Dart_Handle NewByteData(Thread* thread, intptr_t length) { |
| 3153 CHECK_LENGTH(length, TypedData::MaxElements(kTypedDataInt8ArrayCid)); | 3145 CHECK_LENGTH(length, TypedData::MaxElements(kTypedDataInt8ArrayCid)); |
| 3154 Isolate* isolate = thread->isolate(); | |
| 3155 Zone* zone = thread->zone(); | 3146 Zone* zone = thread->zone(); |
| 3156 Object& result = Object::Handle(zone); | 3147 Object& result = Object::Handle(zone); |
| 3157 result = GetByteDataConstructor(thread, Symbols::ByteDataDot(), 1); | 3148 result = GetByteDataConstructor(thread, Symbols::ByteDataDot(), 1); |
| 3158 ASSERT(!result.IsNull()); | 3149 ASSERT(!result.IsNull()); |
| 3159 ASSERT(result.IsFunction()); | 3150 ASSERT(result.IsFunction()); |
| 3160 const Function& factory = Function::Cast(result); | 3151 const Function& factory = Function::Cast(result); |
| 3161 ASSERT(!factory.IsGenerativeConstructor()); | 3152 ASSERT(!factory.IsGenerativeConstructor()); |
| 3162 | 3153 |
| 3163 // Create the argument list. | 3154 // Create the argument list. |
| 3164 const Array& args = Array::Handle(zone, Array::New(2)); | 3155 const Array& args = Array::Handle(zone, Array::New(2)); |
| 3165 // Factories get type arguments. | 3156 // Factories get type arguments. |
| 3166 args.SetAt(0, Object::null_type_arguments()); | 3157 args.SetAt(0, Object::null_type_arguments()); |
| 3167 args.SetAt(1, Smi::Handle(zone, Smi::New(length))); | 3158 args.SetAt(1, Smi::Handle(zone, Smi::New(length))); |
| 3168 | 3159 |
| 3169 // Invoke the constructor and return the new object. | 3160 // Invoke the constructor and return the new object. |
| 3170 result = DartEntry::InvokeFunction(factory, args); | 3161 result = DartEntry::InvokeFunction(factory, args); |
| 3171 ASSERT(result.IsInstance() || result.IsNull() || result.IsError()); | 3162 ASSERT(result.IsInstance() || result.IsNull() || result.IsError()); |
| 3172 return Api::NewHandle(isolate, result.raw()); | 3163 return Api::NewHandle(thread, result.raw()); |
| 3173 } | 3164 } |
| 3174 | 3165 |
| 3175 | 3166 |
| 3176 static Dart_Handle NewTypedData(Isolate* isolate, | 3167 static Dart_Handle NewTypedData(Thread* thread, |
| 3177 intptr_t cid, | 3168 intptr_t cid, |
| 3178 intptr_t length) { | 3169 intptr_t length) { |
| 3179 CHECK_LENGTH(length, TypedData::MaxElements(cid)); | 3170 CHECK_LENGTH(length, TypedData::MaxElements(cid)); |
| 3180 return Api::NewHandle(isolate, TypedData::New(cid, length)); | 3171 return Api::NewHandle(thread, TypedData::New(cid, length)); |
| 3181 } | 3172 } |
| 3182 | 3173 |
| 3183 | 3174 |
| 3184 static Dart_Handle NewExternalTypedData( | 3175 static Dart_Handle NewExternalTypedData( |
| 3185 Thread* thread, intptr_t cid, void* data, intptr_t length) { | 3176 Thread* thread, intptr_t cid, void* data, intptr_t length) { |
| 3186 CHECK_LENGTH(length, ExternalTypedData::MaxElements(cid)); | 3177 CHECK_LENGTH(length, ExternalTypedData::MaxElements(cid)); |
| 3187 Isolate* isolate = thread->isolate(); | |
| 3188 Zone* zone = thread->zone(); | 3178 Zone* zone = thread->zone(); |
| 3189 intptr_t bytes = length * ExternalTypedData::ElementSizeInBytes(cid); | 3179 intptr_t bytes = length * ExternalTypedData::ElementSizeInBytes(cid); |
| 3190 const ExternalTypedData& result = ExternalTypedData::Handle( | 3180 const ExternalTypedData& result = ExternalTypedData::Handle( |
| 3191 zone, | 3181 zone, |
| 3192 ExternalTypedData::New(cid, | 3182 ExternalTypedData::New(cid, |
| 3193 reinterpret_cast<uint8_t*>(data), | 3183 reinterpret_cast<uint8_t*>(data), |
| 3194 length, | 3184 length, |
| 3195 SpaceForExternal(isolate, bytes))); | 3185 SpaceForExternal(thread, bytes))); |
| 3196 return Api::NewHandle(isolate, result.raw()); | 3186 return Api::NewHandle(thread, result.raw()); |
| 3197 } | 3187 } |
| 3198 | 3188 |
| 3199 | 3189 |
| 3200 static Dart_Handle NewExternalByteData( | 3190 static Dart_Handle NewExternalByteData( |
| 3201 Thread* thread, void* data, intptr_t length) { | 3191 Thread* thread, void* data, intptr_t length) { |
| 3202 Zone* zone = thread->zone(); | 3192 Zone* zone = thread->zone(); |
| 3203 Isolate* isolate = thread->isolate(); | |
| 3204 Dart_Handle ext_data = NewExternalTypedData( | 3193 Dart_Handle ext_data = NewExternalTypedData( |
| 3205 thread, kExternalTypedDataUint8ArrayCid, data, length); | 3194 thread, kExternalTypedDataUint8ArrayCid, data, length); |
| 3206 if (::Dart_IsError(ext_data)) { | 3195 if (::Dart_IsError(ext_data)) { |
| 3207 return ext_data; | 3196 return ext_data; |
| 3208 } | 3197 } |
| 3209 Object& result = Object::Handle(zone); | 3198 Object& result = Object::Handle(zone); |
| 3210 result = GetByteDataConstructor(thread, Symbols::ByteDataDot_view(), 3); | 3199 result = GetByteDataConstructor(thread, Symbols::ByteDataDot_view(), 3); |
| 3211 ASSERT(!result.IsNull()); | 3200 ASSERT(!result.IsNull()); |
| 3212 ASSERT(result.IsFunction()); | 3201 ASSERT(result.IsFunction()); |
| 3213 const Function& factory = Function::Cast(result); | 3202 const Function& factory = Function::Cast(result); |
| 3214 ASSERT(!factory.IsGenerativeConstructor()); | 3203 ASSERT(!factory.IsGenerativeConstructor()); |
| 3215 | 3204 |
| 3216 // Create the argument list. | 3205 // Create the argument list. |
| 3217 const intptr_t num_args = 3; | 3206 const intptr_t num_args = 3; |
| 3218 const Array& args = Array::Handle(zone, Array::New(num_args + 1)); | 3207 const Array& args = Array::Handle(zone, Array::New(num_args + 1)); |
| 3219 // Factories get type arguments. | 3208 // Factories get type arguments. |
| 3220 args.SetAt(0, Object::null_type_arguments()); | 3209 args.SetAt(0, Object::null_type_arguments()); |
| 3221 const ExternalTypedData& array = | 3210 const ExternalTypedData& array = |
| 3222 Api::UnwrapExternalTypedDataHandle(zone, ext_data); | 3211 Api::UnwrapExternalTypedDataHandle(zone, ext_data); |
| 3223 args.SetAt(1, array); | 3212 args.SetAt(1, array); |
| 3224 Smi& smi = Smi::Handle(zone); | 3213 Smi& smi = Smi::Handle(zone); |
| 3225 smi = Smi::New(0); | 3214 smi = Smi::New(0); |
| 3226 args.SetAt(2, smi); | 3215 args.SetAt(2, smi); |
| 3227 smi = Smi::New(length); | 3216 smi = Smi::New(length); |
| 3228 args.SetAt(3, smi); | 3217 args.SetAt(3, smi); |
| 3229 | 3218 |
| 3230 // Invoke the constructor and return the new object. | 3219 // Invoke the constructor and return the new object. |
| 3231 result = DartEntry::InvokeFunction(factory, args); | 3220 result = DartEntry::InvokeFunction(factory, args); |
| 3232 ASSERT(result.IsNull() || result.IsInstance() || result.IsError()); | 3221 ASSERT(result.IsNull() || result.IsInstance() || result.IsError()); |
| 3233 return Api::NewHandle(isolate, result.raw()); | 3222 return Api::NewHandle(thread, result.raw()); |
| 3234 } | 3223 } |
| 3235 | 3224 |
| 3236 | 3225 |
| 3237 DART_EXPORT Dart_Handle Dart_NewTypedData(Dart_TypedData_Type type, | 3226 DART_EXPORT Dart_Handle Dart_NewTypedData(Dart_TypedData_Type type, |
| 3238 intptr_t length) { | 3227 intptr_t length) { |
| 3239 DARTSCOPE(Thread::Current()); | 3228 DARTSCOPE(Thread::Current()); |
| 3240 CHECK_CALLBACK_STATE(T); | 3229 CHECK_CALLBACK_STATE(T); |
| 3241 switch (type) { | 3230 switch (type) { |
| 3242 case Dart_TypedData_kByteData : | 3231 case Dart_TypedData_kByteData : |
| 3243 return NewByteData(T, length); | 3232 return NewByteData(T, length); |
| 3244 case Dart_TypedData_kInt8 : | 3233 case Dart_TypedData_kInt8 : |
| 3245 return NewTypedData(I, kTypedDataInt8ArrayCid, length); | 3234 return NewTypedData(T, kTypedDataInt8ArrayCid, length); |
| 3246 case Dart_TypedData_kUint8 : | 3235 case Dart_TypedData_kUint8 : |
| 3247 return NewTypedData(I, kTypedDataUint8ArrayCid, length); | 3236 return NewTypedData(T, kTypedDataUint8ArrayCid, length); |
| 3248 case Dart_TypedData_kUint8Clamped : | 3237 case Dart_TypedData_kUint8Clamped : |
| 3249 return NewTypedData(I, kTypedDataUint8ClampedArrayCid, length); | 3238 return NewTypedData(T, kTypedDataUint8ClampedArrayCid, length); |
| 3250 case Dart_TypedData_kInt16 : | 3239 case Dart_TypedData_kInt16 : |
| 3251 return NewTypedData(I, kTypedDataInt16ArrayCid, length); | 3240 return NewTypedData(T, kTypedDataInt16ArrayCid, length); |
| 3252 case Dart_TypedData_kUint16 : | 3241 case Dart_TypedData_kUint16 : |
| 3253 return NewTypedData(I, kTypedDataUint16ArrayCid, length); | 3242 return NewTypedData(T, kTypedDataUint16ArrayCid, length); |
| 3254 case Dart_TypedData_kInt32 : | 3243 case Dart_TypedData_kInt32 : |
| 3255 return NewTypedData(I, kTypedDataInt32ArrayCid, length); | 3244 return NewTypedData(T, kTypedDataInt32ArrayCid, length); |
| 3256 case Dart_TypedData_kUint32 : | 3245 case Dart_TypedData_kUint32 : |
| 3257 return NewTypedData(I, kTypedDataUint32ArrayCid, length); | 3246 return NewTypedData(T, kTypedDataUint32ArrayCid, length); |
| 3258 case Dart_TypedData_kInt64 : | 3247 case Dart_TypedData_kInt64 : |
| 3259 return NewTypedData(I, kTypedDataInt64ArrayCid, length); | 3248 return NewTypedData(T, kTypedDataInt64ArrayCid, length); |
| 3260 case Dart_TypedData_kUint64 : | 3249 case Dart_TypedData_kUint64 : |
| 3261 return NewTypedData(I, kTypedDataUint64ArrayCid, length); | 3250 return NewTypedData(T, kTypedDataUint64ArrayCid, length); |
| 3262 case Dart_TypedData_kFloat32 : | 3251 case Dart_TypedData_kFloat32 : |
| 3263 return NewTypedData(I, kTypedDataFloat32ArrayCid, length); | 3252 return NewTypedData(T, kTypedDataFloat32ArrayCid, length); |
| 3264 case Dart_TypedData_kFloat64 : | 3253 case Dart_TypedData_kFloat64 : |
| 3265 return NewTypedData(I, kTypedDataFloat64ArrayCid, length); | 3254 return NewTypedData(T, kTypedDataFloat64ArrayCid, length); |
| 3266 case Dart_TypedData_kFloat32x4: | 3255 case Dart_TypedData_kFloat32x4: |
| 3267 return NewTypedData(I, kTypedDataFloat32x4ArrayCid, length); | 3256 return NewTypedData(T, kTypedDataFloat32x4ArrayCid, length); |
| 3268 default: | 3257 default: |
| 3269 return Api::NewError("%s expects argument 'type' to be of 'TypedData'", | 3258 return Api::NewError("%s expects argument 'type' to be of 'TypedData'", |
| 3270 CURRENT_FUNC); | 3259 CURRENT_FUNC); |
| 3271 } | 3260 } |
| 3272 UNREACHABLE(); | 3261 UNREACHABLE(); |
| 3273 return Api::Null(); | 3262 return Api::Null(); |
| 3274 } | 3263 } |
| 3275 | 3264 |
| 3276 | 3265 |
| 3277 DART_EXPORT Dart_Handle Dart_NewExternalTypedData( | 3266 DART_EXPORT Dart_Handle Dart_NewExternalTypedData( |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3370 // Create the argument list. | 3359 // Create the argument list. |
| 3371 const Array& args = Array::Handle(Z, Array::New(2)); | 3360 const Array& args = Array::Handle(Z, Array::New(2)); |
| 3372 // Factories get type arguments. | 3361 // Factories get type arguments. |
| 3373 args.SetAt(0, Object::null_type_arguments()); | 3362 args.SetAt(0, Object::null_type_arguments()); |
| 3374 const Object& obj = Object::Handle(Z, Api::UnwrapHandle(typed_data)); | 3363 const Object& obj = Object::Handle(Z, Api::UnwrapHandle(typed_data)); |
| 3375 args.SetAt(1, obj); | 3364 args.SetAt(1, obj); |
| 3376 | 3365 |
| 3377 // Invoke the factory constructor and return the new object. | 3366 // Invoke the factory constructor and return the new object. |
| 3378 result = DartEntry::InvokeFunction(factory, args); | 3367 result = DartEntry::InvokeFunction(factory, args); |
| 3379 ASSERT(result.IsInstance() || result.IsNull() || result.IsError()); | 3368 ASSERT(result.IsInstance() || result.IsNull() || result.IsError()); |
| 3380 return Api::NewHandle(I, result.raw()); | 3369 return Api::NewHandle(T, result.raw()); |
| 3381 } | 3370 } |
| 3382 | 3371 |
| 3383 | 3372 |
| 3384 // Structure to record acquired typed data for verification purposes. | 3373 // Structure to record acquired typed data for verification purposes. |
| 3385 class AcquiredData { | 3374 class AcquiredData { |
| 3386 public: | 3375 public: |
| 3387 AcquiredData(void* data, intptr_t size_in_bytes, bool copy) | 3376 AcquiredData(void* data, intptr_t size_in_bytes, bool copy) |
| 3388 : size_in_bytes_(size_in_bytes), data_(data), data_copy_(NULL) { | 3377 : size_in_bytes_(size_in_bytes), data_(data), data_copy_(NULL) { |
| 3389 if (copy) { | 3378 if (copy) { |
| 3390 data_copy_ = malloc(size_in_bytes_); | 3379 data_copy_ = malloc(size_in_bytes_); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 3412 | 3401 |
| 3413 DISALLOW_COPY_AND_ASSIGN(AcquiredData); | 3402 DISALLOW_COPY_AND_ASSIGN(AcquiredData); |
| 3414 }; | 3403 }; |
| 3415 | 3404 |
| 3416 | 3405 |
| 3417 DART_EXPORT Dart_Handle Dart_TypedDataAcquireData(Dart_Handle object, | 3406 DART_EXPORT Dart_Handle Dart_TypedDataAcquireData(Dart_Handle object, |
| 3418 Dart_TypedData_Type* type, | 3407 Dart_TypedData_Type* type, |
| 3419 void** data, | 3408 void** data, |
| 3420 intptr_t* len) { | 3409 intptr_t* len) { |
| 3421 DARTSCOPE(Thread::Current()); | 3410 DARTSCOPE(Thread::Current()); |
| 3411 Isolate* I = T->isolate(); |
| 3422 intptr_t class_id = Api::ClassId(object); | 3412 intptr_t class_id = Api::ClassId(object); |
| 3423 if (!RawObject::IsExternalTypedDataClassId(class_id) && | 3413 if (!RawObject::IsExternalTypedDataClassId(class_id) && |
| 3424 !RawObject::IsTypedDataViewClassId(class_id) && | 3414 !RawObject::IsTypedDataViewClassId(class_id) && |
| 3425 !RawObject::IsTypedDataClassId(class_id)) { | 3415 !RawObject::IsTypedDataClassId(class_id)) { |
| 3426 RETURN_TYPE_ERROR(Z, object, 'TypedData'); | 3416 RETURN_TYPE_ERROR(Z, object, 'TypedData'); |
| 3427 } | 3417 } |
| 3428 if (type == NULL) { | 3418 if (type == NULL) { |
| 3429 RETURN_NULL_ERROR(type); | 3419 RETURN_NULL_ERROR(type); |
| 3430 } | 3420 } |
| 3431 if (data == NULL) { | 3421 if (data == NULL) { |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3501 data_tmp = ad->GetData(); | 3491 data_tmp = ad->GetData(); |
| 3502 } | 3492 } |
| 3503 *data = data_tmp; | 3493 *data = data_tmp; |
| 3504 *len = length; | 3494 *len = length; |
| 3505 return Api::Success(); | 3495 return Api::Success(); |
| 3506 } | 3496 } |
| 3507 | 3497 |
| 3508 | 3498 |
| 3509 DART_EXPORT Dart_Handle Dart_TypedDataReleaseData(Dart_Handle object) { | 3499 DART_EXPORT Dart_Handle Dart_TypedDataReleaseData(Dart_Handle object) { |
| 3510 DARTSCOPE(Thread::Current()); | 3500 DARTSCOPE(Thread::Current()); |
| 3501 Isolate* I = T->isolate(); |
| 3511 intptr_t class_id = Api::ClassId(object); | 3502 intptr_t class_id = Api::ClassId(object); |
| 3512 if (!RawObject::IsExternalTypedDataClassId(class_id) && | 3503 if (!RawObject::IsExternalTypedDataClassId(class_id) && |
| 3513 !RawObject::IsTypedDataViewClassId(class_id) && | 3504 !RawObject::IsTypedDataViewClassId(class_id) && |
| 3514 !RawObject::IsTypedDataClassId(class_id)) { | 3505 !RawObject::IsTypedDataClassId(class_id)) { |
| 3515 RETURN_TYPE_ERROR(Z, object, 'TypedData'); | 3506 RETURN_TYPE_ERROR(Z, object, 'TypedData'); |
| 3516 } | 3507 } |
| 3517 if (!RawObject::IsExternalTypedDataClassId(class_id)) { | 3508 if (!RawObject::IsExternalTypedDataClassId(class_id)) { |
| 3518 T->DecrementNoSafepointScopeDepth(); | 3509 T->DecrementNoSafepointScopeDepth(); |
| 3519 END_NO_CALLBACK_SCOPE(T); | 3510 END_NO_CALLBACK_SCOPE(T); |
| 3520 } | 3511 } |
| (...skipping 16 matching lines...) Expand all Loading... |
| 3537 Thread* thread = Thread::Current(); | 3528 Thread* thread = Thread::Current(); |
| 3538 Zone* zone = thread->zone(); | 3529 Zone* zone = thread->zone(); |
| 3539 Isolate* isolate = thread->isolate(); | 3530 Isolate* isolate = thread->isolate(); |
| 3540 CHECK_ISOLATE(isolate); | 3531 CHECK_ISOLATE(isolate); |
| 3541 intptr_t class_id = Api::ClassId(object); | 3532 intptr_t class_id = Api::ClassId(object); |
| 3542 if (class_id != kByteBufferCid) { | 3533 if (class_id != kByteBufferCid) { |
| 3543 RETURN_TYPE_ERROR(zone, object, 'ByteBuffer'); | 3534 RETURN_TYPE_ERROR(zone, object, 'ByteBuffer'); |
| 3544 } | 3535 } |
| 3545 const Instance& instance = Api::UnwrapInstanceHandle(zone, object); | 3536 const Instance& instance = Api::UnwrapInstanceHandle(zone, object); |
| 3546 ASSERT(!instance.IsNull()); | 3537 ASSERT(!instance.IsNull()); |
| 3547 return Api::NewHandle(isolate, ByteBuffer::Data(instance)); | 3538 return Api::NewHandle(thread, ByteBuffer::Data(instance)); |
| 3548 } | 3539 } |
| 3549 | 3540 |
| 3550 | 3541 |
| 3551 // --- Invoking Constructors, Methods, and Field accessors --- | 3542 // --- Invoking Constructors, Methods, and Field accessors --- |
| 3552 | 3543 |
| 3553 static RawObject* ResolveConstructor(const char* current_func, | 3544 static RawObject* ResolveConstructor(const char* current_func, |
| 3554 const Class& cls, | 3545 const Class& cls, |
| 3555 const String& class_name, | 3546 const String& class_name, |
| 3556 const String& constr_name, | 3547 const String& constr_name, |
| 3557 int num_args) { | 3548 int num_args) { |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3648 | 3639 |
| 3649 // Resolve the constructor. | 3640 // Resolve the constructor. |
| 3650 String& constr_name = | 3641 String& constr_name = |
| 3651 String::Handle(String::Concat(base_constructor_name, dot_name)); | 3642 String::Handle(String::Concat(base_constructor_name, dot_name)); |
| 3652 result = ResolveConstructor("Dart_New", | 3643 result = ResolveConstructor("Dart_New", |
| 3653 cls, | 3644 cls, |
| 3654 base_constructor_name, | 3645 base_constructor_name, |
| 3655 constr_name, | 3646 constr_name, |
| 3656 number_of_arguments); | 3647 number_of_arguments); |
| 3657 if (result.IsError()) { | 3648 if (result.IsError()) { |
| 3658 return Api::NewHandle(I, result.raw()); | 3649 return Api::NewHandle(T, result.raw()); |
| 3659 } | 3650 } |
| 3660 ASSERT(result.IsFunction()); | 3651 ASSERT(result.IsFunction()); |
| 3661 Function& constructor = Function::Handle(Z); | 3652 Function& constructor = Function::Handle(Z); |
| 3662 constructor ^= result.raw(); | 3653 constructor ^= result.raw(); |
| 3663 | 3654 |
| 3664 Instance& new_object = Instance::Handle(Z); | 3655 Instance& new_object = Instance::Handle(Z); |
| 3665 if (constructor.IsRedirectingFactory()) { | 3656 if (constructor.IsRedirectingFactory()) { |
| 3666 ClassFinalizer::ResolveRedirectingFactory(cls, constructor); | 3657 ClassFinalizer::ResolveRedirectingFactory(cls, constructor); |
| 3667 Type& redirect_type = Type::Handle(constructor.RedirectionType()); | 3658 Type& redirect_type = Type::Handle(constructor.RedirectionType()); |
| 3668 constructor = constructor.RedirectionTarget(); | 3659 constructor = constructor.RedirectionTarget(); |
| 3669 if (constructor.IsNull()) { | 3660 if (constructor.IsNull()) { |
| 3670 ASSERT(redirect_type.IsMalformed()); | 3661 ASSERT(redirect_type.IsMalformed()); |
| 3671 return Api::NewHandle(I, redirect_type.error()); | 3662 return Api::NewHandle(T, redirect_type.error()); |
| 3672 } | 3663 } |
| 3673 | 3664 |
| 3674 if (!redirect_type.IsInstantiated()) { | 3665 if (!redirect_type.IsInstantiated()) { |
| 3675 // The type arguments of the redirection type are instantiated from the | 3666 // The type arguments of the redirection type are instantiated from the |
| 3676 // type arguments of the type argument. | 3667 // type arguments of the type argument. |
| 3677 Error& bound_error = Error::Handle(); | 3668 Error& bound_error = Error::Handle(); |
| 3678 redirect_type ^= redirect_type.InstantiateFrom(type_arguments, | 3669 redirect_type ^= redirect_type.InstantiateFrom(type_arguments, |
| 3679 &bound_error); | 3670 &bound_error); |
| 3680 if (!bound_error.IsNull()) { | 3671 if (!bound_error.IsNull()) { |
| 3681 return Api::NewHandle(I, bound_error.raw()); | 3672 return Api::NewHandle(T, bound_error.raw()); |
| 3682 } | 3673 } |
| 3683 redirect_type ^= redirect_type.Canonicalize(); | 3674 redirect_type ^= redirect_type.Canonicalize(); |
| 3684 } | 3675 } |
| 3685 | 3676 |
| 3686 type_obj = redirect_type.raw(); | 3677 type_obj = redirect_type.raw(); |
| 3687 type_arguments = redirect_type.arguments(); | 3678 type_arguments = redirect_type.arguments(); |
| 3688 | 3679 |
| 3689 cls = type_obj.type_class(); | 3680 cls = type_obj.type_class(); |
| 3690 } | 3681 } |
| 3691 if (constructor.IsGenerativeConstructor()) { | 3682 if (constructor.IsGenerativeConstructor()) { |
| (...skipping 18 matching lines...) Expand all Loading... |
| 3710 args.SetAt(arg_index++, Smi::Handle(Z, Smi::New(Function::kCtorPhaseAll))); | 3701 args.SetAt(arg_index++, Smi::Handle(Z, Smi::New(Function::kCtorPhaseAll))); |
| 3711 } else { | 3702 } else { |
| 3712 // Factories get type arguments. | 3703 // Factories get type arguments. |
| 3713 args.SetAt(arg_index++, type_arguments); | 3704 args.SetAt(arg_index++, type_arguments); |
| 3714 } | 3705 } |
| 3715 Object& argument = Object::Handle(Z); | 3706 Object& argument = Object::Handle(Z); |
| 3716 for (int i = 0; i < number_of_arguments; i++) { | 3707 for (int i = 0; i < number_of_arguments; i++) { |
| 3717 argument = Api::UnwrapHandle(arguments[i]); | 3708 argument = Api::UnwrapHandle(arguments[i]); |
| 3718 if (!argument.IsNull() && !argument.IsInstance()) { | 3709 if (!argument.IsNull() && !argument.IsInstance()) { |
| 3719 if (argument.IsError()) { | 3710 if (argument.IsError()) { |
| 3720 return Api::NewHandle(I, argument.raw()); | 3711 return Api::NewHandle(T, argument.raw()); |
| 3721 } else { | 3712 } else { |
| 3722 return Api::NewError( | 3713 return Api::NewError( |
| 3723 "%s expects arguments[%d] to be an Instance handle.", | 3714 "%s expects arguments[%d] to be an Instance handle.", |
| 3724 CURRENT_FUNC, i); | 3715 CURRENT_FUNC, i); |
| 3725 } | 3716 } |
| 3726 } | 3717 } |
| 3727 args.SetAt(arg_index++, argument); | 3718 args.SetAt(arg_index++, argument); |
| 3728 } | 3719 } |
| 3729 | 3720 |
| 3730 // Invoke the constructor and return the new object. | 3721 // Invoke the constructor and return the new object. |
| 3731 result = DartEntry::InvokeFunction(constructor, args); | 3722 result = DartEntry::InvokeFunction(constructor, args); |
| 3732 if (result.IsError()) { | 3723 if (result.IsError()) { |
| 3733 return Api::NewHandle(I, result.raw()); | 3724 return Api::NewHandle(T, result.raw()); |
| 3734 } | 3725 } |
| 3735 | 3726 |
| 3736 if (constructor.IsGenerativeConstructor()) { | 3727 if (constructor.IsGenerativeConstructor()) { |
| 3737 ASSERT(result.IsNull()); | 3728 ASSERT(result.IsNull()); |
| 3738 } else { | 3729 } else { |
| 3739 ASSERT(result.IsNull() || result.IsInstance()); | 3730 ASSERT(result.IsNull() || result.IsInstance()); |
| 3740 new_object ^= result.raw(); | 3731 new_object ^= result.raw(); |
| 3741 } | 3732 } |
| 3742 return Api::NewHandle(I, new_object.raw()); | 3733 return Api::NewHandle(T, new_object.raw()); |
| 3743 } | 3734 } |
| 3744 | 3735 |
| 3745 | 3736 |
| 3746 static RawInstance* AllocateObject(Thread* thread, const Class& cls) { | 3737 static RawInstance* AllocateObject(Thread* thread, const Class& cls) { |
| 3747 if (!cls.is_fields_marked_nullable()) { | 3738 if (!cls.is_fields_marked_nullable()) { |
| 3748 // Mark all fields as nullable. | 3739 // Mark all fields as nullable. |
| 3749 Zone* zone = thread->zone(); | 3740 Zone* zone = thread->zone(); |
| 3750 Class& iterate_cls = Class::Handle(zone, cls.raw()); | 3741 Class& iterate_cls = Class::Handle(zone, cls.raw()); |
| 3751 Field& field = Field::Handle(zone); | 3742 Field& field = Field::Handle(zone); |
| 3752 Array& fields = Array::Handle(zone); | 3743 Array& fields = Array::Handle(zone); |
| (...skipping 28 matching lines...) Expand all Loading... |
| 3781 } | 3772 } |
| 3782 const Class& cls = Class::Handle(Z, type_obj.type_class()); | 3773 const Class& cls = Class::Handle(Z, type_obj.type_class()); |
| 3783 #if defined(DEBUG) | 3774 #if defined(DEBUG) |
| 3784 if (!cls.is_allocated() && Dart::IsRunningPrecompiledCode()) { | 3775 if (!cls.is_allocated() && Dart::IsRunningPrecompiledCode()) { |
| 3785 return Api::NewError("Precompilation dropped '%s'", cls.ToCString()); | 3776 return Api::NewError("Precompilation dropped '%s'", cls.ToCString()); |
| 3786 } | 3777 } |
| 3787 #endif | 3778 #endif |
| 3788 const Error& error = Error::Handle(Z, cls.EnsureIsFinalized(T)); | 3779 const Error& error = Error::Handle(Z, cls.EnsureIsFinalized(T)); |
| 3789 if (!error.IsNull()) { | 3780 if (!error.IsNull()) { |
| 3790 // An error occurred, return error object. | 3781 // An error occurred, return error object. |
| 3791 return Api::NewHandle(I, error.raw()); | 3782 return Api::NewHandle(T, error.raw()); |
| 3792 } | 3783 } |
| 3793 return Api::NewHandle(I, AllocateObject(T, cls)); | 3784 return Api::NewHandle(T, AllocateObject(T, cls)); |
| 3794 } | 3785 } |
| 3795 | 3786 |
| 3796 | 3787 |
| 3797 DART_EXPORT Dart_Handle Dart_AllocateWithNativeFields( | 3788 DART_EXPORT Dart_Handle Dart_AllocateWithNativeFields( |
| 3798 Dart_Handle type, | 3789 Dart_Handle type, |
| 3799 intptr_t num_native_fields, | 3790 intptr_t num_native_fields, |
| 3800 const intptr_t* native_fields) { | 3791 const intptr_t* native_fields) { |
| 3801 DARTSCOPE(Thread::Current()); | 3792 DARTSCOPE(Thread::Current()); |
| 3802 CHECK_CALLBACK_STATE(T); | 3793 CHECK_CALLBACK_STATE(T); |
| 3803 | 3794 |
| 3804 const Type& type_obj = Api::UnwrapTypeHandle(Z, type); | 3795 const Type& type_obj = Api::UnwrapTypeHandle(Z, type); |
| 3805 // Get the class to instantiate. | 3796 // Get the class to instantiate. |
| 3806 if (type_obj.IsNull()) { | 3797 if (type_obj.IsNull()) { |
| 3807 RETURN_TYPE_ERROR(Z, type, Type); | 3798 RETURN_TYPE_ERROR(Z, type, Type); |
| 3808 } | 3799 } |
| 3809 if (native_fields == NULL) { | 3800 if (native_fields == NULL) { |
| 3810 RETURN_NULL_ERROR(native_fields); | 3801 RETURN_NULL_ERROR(native_fields); |
| 3811 } | 3802 } |
| 3812 const Class& cls = Class::Handle(Z, type_obj.type_class()); | 3803 const Class& cls = Class::Handle(Z, type_obj.type_class()); |
| 3813 #if defined(DEBUG) | 3804 #if defined(DEBUG) |
| 3814 if (!cls.is_allocated() && Dart::IsRunningPrecompiledCode()) { | 3805 if (!cls.is_allocated() && Dart::IsRunningPrecompiledCode()) { |
| 3815 return Api::NewError("Precompilation dropped '%s'", cls.ToCString()); | 3806 return Api::NewError("Precompilation dropped '%s'", cls.ToCString()); |
| 3816 } | 3807 } |
| 3817 #endif | 3808 #endif |
| 3818 const Error& error = Error::Handle(Z, cls.EnsureIsFinalized(T)); | 3809 const Error& error = Error::Handle(Z, cls.EnsureIsFinalized(T)); |
| 3819 if (!error.IsNull()) { | 3810 if (!error.IsNull()) { |
| 3820 // An error occurred, return error object. | 3811 // An error occurred, return error object. |
| 3821 return Api::NewHandle(I, error.raw()); | 3812 return Api::NewHandle(T, error.raw()); |
| 3822 } | 3813 } |
| 3823 if (num_native_fields != cls.num_native_fields()) { | 3814 if (num_native_fields != cls.num_native_fields()) { |
| 3824 return Api::NewError( | 3815 return Api::NewError( |
| 3825 "%s: invalid number of native fields %" Pd " passed in, expected %d", | 3816 "%s: invalid number of native fields %" Pd " passed in, expected %d", |
| 3826 CURRENT_FUNC, num_native_fields, cls.num_native_fields()); | 3817 CURRENT_FUNC, num_native_fields, cls.num_native_fields()); |
| 3827 } | 3818 } |
| 3828 const Instance& instance = Instance::Handle(Z, AllocateObject(T, cls)); | 3819 const Instance& instance = Instance::Handle(Z, AllocateObject(T, cls)); |
| 3829 instance.SetNativeFields(num_native_fields, native_fields); | 3820 instance.SetNativeFields(num_native_fields, native_fields); |
| 3830 return Api::NewHandle(I, instance.raw()); | 3821 return Api::NewHandle(T, instance.raw()); |
| 3831 } | 3822 } |
| 3832 | 3823 |
| 3833 | 3824 |
| 3834 static Dart_Handle SetupArguments(Thread* thread, | 3825 static Dart_Handle SetupArguments(Thread* thread, |
| 3835 int num_args, | 3826 int num_args, |
| 3836 Dart_Handle* arguments, | 3827 Dart_Handle* arguments, |
| 3837 int extra_args, | 3828 int extra_args, |
| 3838 Array* args) { | 3829 Array* args) { |
| 3839 Zone* zone = thread->zone(); | 3830 Zone* zone = thread->zone(); |
| 3840 Isolate* isolate = thread->isolate(); | |
| 3841 // Check for malformed arguments in the arguments list. | 3831 // Check for malformed arguments in the arguments list. |
| 3842 *args = Array::New(num_args + extra_args); | 3832 *args = Array::New(num_args + extra_args); |
| 3843 Object& arg = Object::Handle(zone); | 3833 Object& arg = Object::Handle(zone); |
| 3844 for (int i = 0; i < num_args; i++) { | 3834 for (int i = 0; i < num_args; i++) { |
| 3845 arg = Api::UnwrapHandle(arguments[i]); | 3835 arg = Api::UnwrapHandle(arguments[i]); |
| 3846 if (!arg.IsNull() && !arg.IsInstance()) { | 3836 if (!arg.IsNull() && !arg.IsInstance()) { |
| 3847 *args = Array::null(); | 3837 *args = Array::null(); |
| 3848 if (arg.IsError()) { | 3838 if (arg.IsError()) { |
| 3849 return Api::NewHandle(isolate, arg.raw()); | 3839 return Api::NewHandle(thread, arg.raw()); |
| 3850 } else { | 3840 } else { |
| 3851 return Api::NewError( | 3841 return Api::NewError( |
| 3852 "%s expects arguments[%d] to be an Instance handle.", | 3842 "%s expects arguments[%d] to be an Instance handle.", |
| 3853 "Dart_Invoke", i); | 3843 "Dart_Invoke", i); |
| 3854 } | 3844 } |
| 3855 } | 3845 } |
| 3856 args->SetAt((i + extra_args), arg); | 3846 args->SetAt((i + extra_args), arg); |
| 3857 } | 3847 } |
| 3858 return Api::Success(); | 3848 return Api::Success(); |
| 3859 } | 3849 } |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3917 Dart_Handle result; | 3907 Dart_Handle result; |
| 3918 Array& args = Array::Handle(Z); | 3908 Array& args = Array::Handle(Z); |
| 3919 result = SetupArguments(T, | 3909 result = SetupArguments(T, |
| 3920 number_of_arguments, arguments, extra_args, &args); | 3910 number_of_arguments, arguments, extra_args, &args); |
| 3921 if (!::Dart_IsError(result)) { | 3911 if (!::Dart_IsError(result)) { |
| 3922 args.SetAt(0, instance); | 3912 args.SetAt(0, instance); |
| 3923 args.SetAt(1, Smi::Handle(Z, Smi::New(Function::kCtorPhaseAll))); | 3913 args.SetAt(1, Smi::Handle(Z, Smi::New(Function::kCtorPhaseAll))); |
| 3924 const Object& retval = Object::Handle(Z, | 3914 const Object& retval = Object::Handle(Z, |
| 3925 DartEntry::InvokeFunction(constructor, args)); | 3915 DartEntry::InvokeFunction(constructor, args)); |
| 3926 if (retval.IsError()) { | 3916 if (retval.IsError()) { |
| 3927 result = Api::NewHandle(I, retval.raw()); | 3917 result = Api::NewHandle(T, retval.raw()); |
| 3928 } else { | 3918 } else { |
| 3929 result = Api::NewHandle(I, instance.raw()); | 3919 result = Api::NewHandle(T, instance.raw()); |
| 3930 } | 3920 } |
| 3931 } | 3921 } |
| 3932 return result; | 3922 return result; |
| 3933 } | 3923 } |
| 3934 return Api::NewError( | 3924 return Api::NewError( |
| 3935 "%s expects argument 'name' to be a valid constructor.", | 3925 "%s expects argument 'name' to be a valid constructor.", |
| 3936 CURRENT_FUNC); | 3926 CURRENT_FUNC); |
| 3937 } | 3927 } |
| 3938 | 3928 |
| 3939 | 3929 |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3975 if (function.IsNull()) { | 3965 if (function.IsNull()) { |
| 3976 const String& cls_name = String::Handle(Z, cls.Name()); | 3966 const String& cls_name = String::Handle(Z, cls.Name()); |
| 3977 return Api::NewError("%s: did not find static method '%s.%s'.", | 3967 return Api::NewError("%s: did not find static method '%s.%s'.", |
| 3978 CURRENT_FUNC, | 3968 CURRENT_FUNC, |
| 3979 cls_name.ToCString(), | 3969 cls_name.ToCString(), |
| 3980 function_name.ToCString()); | 3970 function_name.ToCString()); |
| 3981 } | 3971 } |
| 3982 // Setup args and check for malformed arguments in the arguments list. | 3972 // Setup args and check for malformed arguments in the arguments list. |
| 3983 result = SetupArguments(T, number_of_arguments, arguments, 0, &args); | 3973 result = SetupArguments(T, number_of_arguments, arguments, 0, &args); |
| 3984 if (!::Dart_IsError(result)) { | 3974 if (!::Dart_IsError(result)) { |
| 3985 result = Api::NewHandle(I, DartEntry::InvokeFunction(function, args)); | 3975 result = Api::NewHandle(T, DartEntry::InvokeFunction(function, args)); |
| 3986 } | 3976 } |
| 3987 return result; | 3977 return result; |
| 3988 } else if (obj.IsNull() || obj.IsInstance()) { | 3978 } else if (obj.IsNull() || obj.IsInstance()) { |
| 3989 // Since we have allocated an object it would mean that the type of the | 3979 // Since we have allocated an object it would mean that the type of the |
| 3990 // receiver is already resolved and finalized, hence it is not necessary | 3980 // receiver is already resolved and finalized, hence it is not necessary |
| 3991 // to check here. | 3981 // to check here. |
| 3992 Instance& instance = Instance::Handle(Z); | 3982 Instance& instance = Instance::Handle(Z); |
| 3993 instance ^= obj.raw(); | 3983 instance ^= obj.raw(); |
| 3994 ArgumentsDescriptor args_desc( | 3984 ArgumentsDescriptor args_desc( |
| 3995 Array::Handle(Z, ArgumentsDescriptor::New(number_of_arguments + 1))); | 3985 Array::Handle(Z, ArgumentsDescriptor::New(number_of_arguments + 1))); |
| 3996 const Function& function = Function::Handle(Z, | 3986 const Function& function = Function::Handle(Z, |
| 3997 Resolver::ResolveDynamic(instance, function_name, args_desc)); | 3987 Resolver::ResolveDynamic(instance, function_name, args_desc)); |
| 3998 if (function.IsNull()) { | 3988 if (function.IsNull()) { |
| 3999 // Setup args and check for malformed arguments in the arguments list. | 3989 // Setup args and check for malformed arguments in the arguments list. |
| 4000 result = SetupArguments(T, | 3990 result = SetupArguments(T, |
| 4001 number_of_arguments, | 3991 number_of_arguments, |
| 4002 arguments, | 3992 arguments, |
| 4003 1, | 3993 1, |
| 4004 &args); | 3994 &args); |
| 4005 if (!::Dart_IsError(result)) { | 3995 if (!::Dart_IsError(result)) { |
| 4006 args.SetAt(0, instance); | 3996 args.SetAt(0, instance); |
| 4007 const Array& args_descriptor = | 3997 const Array& args_descriptor = |
| 4008 Array::Handle(Z, ArgumentsDescriptor::New(args.Length())); | 3998 Array::Handle(Z, ArgumentsDescriptor::New(args.Length())); |
| 4009 result = Api::NewHandle(I, | 3999 result = Api::NewHandle(T, |
| 4010 DartEntry::InvokeNoSuchMethod(instance, | 4000 DartEntry::InvokeNoSuchMethod(instance, |
| 4011 function_name, | 4001 function_name, |
| 4012 args, | 4002 args, |
| 4013 args_descriptor)); | 4003 args_descriptor)); |
| 4014 } | 4004 } |
| 4015 return result; | 4005 return result; |
| 4016 } | 4006 } |
| 4017 // Setup args and check for malformed arguments in the arguments list. | 4007 // Setup args and check for malformed arguments in the arguments list. |
| 4018 result = SetupArguments(T, number_of_arguments, arguments, 1, &args); | 4008 result = SetupArguments(T, number_of_arguments, arguments, 1, &args); |
| 4019 if (!::Dart_IsError(result)) { | 4009 if (!::Dart_IsError(result)) { |
| 4020 args.SetAt(0, instance); | 4010 args.SetAt(0, instance); |
| 4021 result = Api::NewHandle(I, DartEntry::InvokeFunction(function, args)); | 4011 result = Api::NewHandle(T, DartEntry::InvokeFunction(function, args)); |
| 4022 } | 4012 } |
| 4023 return result; | 4013 return result; |
| 4024 } else if (obj.IsLibrary()) { | 4014 } else if (obj.IsLibrary()) { |
| 4025 // Check whether class finalization is needed. | 4015 // Check whether class finalization is needed. |
| 4026 const Library& lib = Library::Cast(obj); | 4016 const Library& lib = Library::Cast(obj); |
| 4027 | 4017 |
| 4028 // Check that the library is loaded. | 4018 // Check that the library is loaded. |
| 4029 if (!lib.Loaded()) { | 4019 if (!lib.Loaded()) { |
| 4030 return Api::NewError( | 4020 return Api::NewError( |
| 4031 "%s expects library argument 'target' to be loaded.", | 4021 "%s expects library argument 'target' to be loaded.", |
| (...skipping 14 matching lines...) Expand all Loading... |
| 4046 0, | 4036 0, |
| 4047 &error_message)) { | 4037 &error_message)) { |
| 4048 return Api::NewError("%s: wrong argument count for function '%s': %s.", | 4038 return Api::NewError("%s: wrong argument count for function '%s': %s.", |
| 4049 CURRENT_FUNC, | 4039 CURRENT_FUNC, |
| 4050 function_name.ToCString(), | 4040 function_name.ToCString(), |
| 4051 error_message.ToCString()); | 4041 error_message.ToCString()); |
| 4052 } | 4042 } |
| 4053 // Setup args and check for malformed arguments in the arguments list. | 4043 // Setup args and check for malformed arguments in the arguments list. |
| 4054 result = SetupArguments(T, number_of_arguments, arguments, 0, &args); | 4044 result = SetupArguments(T, number_of_arguments, arguments, 0, &args); |
| 4055 if (!::Dart_IsError(result)) { | 4045 if (!::Dart_IsError(result)) { |
| 4056 result = Api::NewHandle(I, DartEntry::InvokeFunction(function, args)); | 4046 result = Api::NewHandle(T, DartEntry::InvokeFunction(function, args)); |
| 4057 } | 4047 } |
| 4058 return result; | 4048 return result; |
| 4059 } else { | 4049 } else { |
| 4060 return Api::NewError( | 4050 return Api::NewError( |
| 4061 "%s expects argument 'target' to be an object, type, or library.", | 4051 "%s expects argument 'target' to be an object, type, or library.", |
| 4062 CURRENT_FUNC); | 4052 CURRENT_FUNC); |
| 4063 } | 4053 } |
| 4064 } | 4054 } |
| 4065 | 4055 |
| 4066 | 4056 |
| (...skipping 17 matching lines...) Expand all Loading... |
| 4084 Object& obj = Object::Handle(Z); | 4074 Object& obj = Object::Handle(Z); |
| 4085 args.SetAt(0, closure_obj); | 4075 args.SetAt(0, closure_obj); |
| 4086 for (int i = 0; i < number_of_arguments; i++) { | 4076 for (int i = 0; i < number_of_arguments; i++) { |
| 4087 obj = Api::UnwrapHandle(arguments[i]); | 4077 obj = Api::UnwrapHandle(arguments[i]); |
| 4088 if (!obj.IsNull() && !obj.IsInstance()) { | 4078 if (!obj.IsNull() && !obj.IsInstance()) { |
| 4089 RETURN_TYPE_ERROR(Z, arguments[i], Instance); | 4079 RETURN_TYPE_ERROR(Z, arguments[i], Instance); |
| 4090 } | 4080 } |
| 4091 args.SetAt(i + 1, obj); | 4081 args.SetAt(i + 1, obj); |
| 4092 } | 4082 } |
| 4093 // Now try to invoke the closure. | 4083 // Now try to invoke the closure. |
| 4094 return Api::NewHandle(I, DartEntry::InvokeClosure(args)); | 4084 return Api::NewHandle(T, DartEntry::InvokeClosure(args)); |
| 4095 } | 4085 } |
| 4096 | 4086 |
| 4097 | 4087 |
| 4098 DART_EXPORT Dart_Handle Dart_GetField(Dart_Handle container, Dart_Handle name) { | 4088 DART_EXPORT Dart_Handle Dart_GetField(Dart_Handle container, Dart_Handle name) { |
| 4099 DARTSCOPE(Thread::Current()); | 4089 DARTSCOPE(Thread::Current()); |
| 4100 CHECK_CALLBACK_STATE(T); | 4090 CHECK_CALLBACK_STATE(T); |
| 4101 | 4091 |
| 4102 const String& field_name = Api::UnwrapStringHandle(Z, name); | 4092 const String& field_name = Api::UnwrapStringHandle(Z, name); |
| 4103 if (field_name.IsNull()) { | 4093 if (field_name.IsNull()) { |
| 4104 RETURN_TYPE_ERROR(Z, name, String); | 4094 RETURN_TYPE_ERROR(Z, name, String); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 4122 | 4112 |
| 4123 field = cls.LookupStaticField(field_name); | 4113 field = cls.LookupStaticField(field_name); |
| 4124 if (field.IsNull() || field.IsUninitialized()) { | 4114 if (field.IsNull() || field.IsUninitialized()) { |
| 4125 const String& getter_name = | 4115 const String& getter_name = |
| 4126 String::Handle(Z, Field::GetterName(field_name)); | 4116 String::Handle(Z, Field::GetterName(field_name)); |
| 4127 getter = cls.LookupStaticFunctionAllowPrivate(getter_name); | 4117 getter = cls.LookupStaticFunctionAllowPrivate(getter_name); |
| 4128 } | 4118 } |
| 4129 | 4119 |
| 4130 if (!getter.IsNull()) { | 4120 if (!getter.IsNull()) { |
| 4131 // Invoke the getter and return the result. | 4121 // Invoke the getter and return the result. |
| 4132 return Api::NewHandle(I, | 4122 return Api::NewHandle(T, |
| 4133 DartEntry::InvokeFunction(getter, Object::empty_array())); | 4123 DartEntry::InvokeFunction(getter, Object::empty_array())); |
| 4134 } else if (!field.IsNull()) { | 4124 } else if (!field.IsNull()) { |
| 4135 return Api::NewHandle(I, field.StaticValue()); | 4125 return Api::NewHandle(T, field.StaticValue()); |
| 4136 } else { | 4126 } else { |
| 4137 return Api::NewError("%s: did not find static field '%s'.", | 4127 return Api::NewError("%s: did not find static field '%s'.", |
| 4138 CURRENT_FUNC, field_name.ToCString()); | 4128 CURRENT_FUNC, field_name.ToCString()); |
| 4139 } | 4129 } |
| 4140 | 4130 |
| 4141 } else if (obj.IsInstance()) { | 4131 } else if (obj.IsInstance()) { |
| 4142 // Every instance field has a getter Function. Try to find the | 4132 // Every instance field has a getter Function. Try to find the |
| 4143 // getter in any superclass and use that function to access the | 4133 // getter in any superclass and use that function to access the |
| 4144 // field. | 4134 // field. |
| 4145 const Instance& instance = Instance::Cast(obj); | 4135 const Instance& instance = Instance::Cast(obj); |
| 4146 Class& cls = Class::Handle(Z, instance.clazz()); | 4136 Class& cls = Class::Handle(Z, instance.clazz()); |
| 4147 String& getter_name = String::Handle(Z, Field::GetterName(field_name)); | 4137 String& getter_name = String::Handle(Z, Field::GetterName(field_name)); |
| 4148 while (!cls.IsNull()) { | 4138 while (!cls.IsNull()) { |
| 4149 getter = cls.LookupDynamicFunctionAllowPrivate(getter_name); | 4139 getter = cls.LookupDynamicFunctionAllowPrivate(getter_name); |
| 4150 if (!getter.IsNull()) { | 4140 if (!getter.IsNull()) { |
| 4151 break; | 4141 break; |
| 4152 } | 4142 } |
| 4153 cls = cls.SuperClass(); | 4143 cls = cls.SuperClass(); |
| 4154 } | 4144 } |
| 4155 | 4145 |
| 4156 // Invoke the getter and return the result. | 4146 // Invoke the getter and return the result. |
| 4157 const int kNumArgs = 1; | 4147 const int kNumArgs = 1; |
| 4158 const Array& args = Array::Handle(Z, Array::New(kNumArgs)); | 4148 const Array& args = Array::Handle(Z, Array::New(kNumArgs)); |
| 4159 args.SetAt(0, instance); | 4149 args.SetAt(0, instance); |
| 4160 if (getter.IsNull()) { | 4150 if (getter.IsNull()) { |
| 4161 const Array& args_descriptor = | 4151 const Array& args_descriptor = |
| 4162 Array::Handle(Z, ArgumentsDescriptor::New(args.Length())); | 4152 Array::Handle(Z, ArgumentsDescriptor::New(args.Length())); |
| 4163 return Api::NewHandle(I, | 4153 return Api::NewHandle(T, |
| 4164 DartEntry::InvokeNoSuchMethod(instance, | 4154 DartEntry::InvokeNoSuchMethod(instance, |
| 4165 getter_name, | 4155 getter_name, |
| 4166 args, | 4156 args, |
| 4167 args_descriptor)); | 4157 args_descriptor)); |
| 4168 } | 4158 } |
| 4169 return Api::NewHandle(I, DartEntry::InvokeFunction(getter, args)); | 4159 return Api::NewHandle(T, DartEntry::InvokeFunction(getter, args)); |
| 4170 | 4160 |
| 4171 } else if (obj.IsLibrary()) { | 4161 } else if (obj.IsLibrary()) { |
| 4172 // To access a top-level we may need to use the Field or the | 4162 // To access a top-level we may need to use the Field or the |
| 4173 // getter Function. The getter function may either be in the | 4163 // getter Function. The getter function may either be in the |
| 4174 // library or in the field's owner class, depending. | 4164 // library or in the field's owner class, depending. |
| 4175 const Library& lib = Library::Cast(obj); | 4165 const Library& lib = Library::Cast(obj); |
| 4176 // Check that the library is loaded. | 4166 // Check that the library is loaded. |
| 4177 if (!lib.Loaded()) { | 4167 if (!lib.Loaded()) { |
| 4178 return Api::NewError( | 4168 return Api::NewError( |
| 4179 "%s expects library argument 'container' to be loaded.", | 4169 "%s expects library argument 'container' to be loaded.", |
| 4180 CURRENT_FUNC); | 4170 CURRENT_FUNC); |
| 4181 } | 4171 } |
| 4182 field = lib.LookupFieldAllowPrivate(field_name); | 4172 field = lib.LookupFieldAllowPrivate(field_name); |
| 4183 if (field.IsNull()) { | 4173 if (field.IsNull()) { |
| 4184 // No field found and no ambiguity error. Check for a getter in the lib. | 4174 // No field found and no ambiguity error. Check for a getter in the lib. |
| 4185 const String& getter_name = | 4175 const String& getter_name = |
| 4186 String::Handle(Z, Field::GetterName(field_name)); | 4176 String::Handle(Z, Field::GetterName(field_name)); |
| 4187 getter = lib.LookupFunctionAllowPrivate(getter_name); | 4177 getter = lib.LookupFunctionAllowPrivate(getter_name); |
| 4188 } else if (!field.IsNull() && field.IsUninitialized()) { | 4178 } else if (!field.IsNull() && field.IsUninitialized()) { |
| 4189 // A field was found. Check for a getter in the field's owner classs. | 4179 // A field was found. Check for a getter in the field's owner classs. |
| 4190 const Class& cls = Class::Handle(Z, field.owner()); | 4180 const Class& cls = Class::Handle(Z, field.owner()); |
| 4191 const String& getter_name = String::Handle(Z, | 4181 const String& getter_name = String::Handle(Z, |
| 4192 Field::GetterName(field_name)); | 4182 Field::GetterName(field_name)); |
| 4193 getter = cls.LookupStaticFunctionAllowPrivate(getter_name); | 4183 getter = cls.LookupStaticFunctionAllowPrivate(getter_name); |
| 4194 } | 4184 } |
| 4195 | 4185 |
| 4196 if (!getter.IsNull()) { | 4186 if (!getter.IsNull()) { |
| 4197 // Invoke the getter and return the result. | 4187 // Invoke the getter and return the result. |
| 4198 return Api::NewHandle(I, | 4188 return Api::NewHandle(T, |
| 4199 DartEntry::InvokeFunction(getter, Object::empty_array())); | 4189 DartEntry::InvokeFunction(getter, Object::empty_array())); |
| 4200 } | 4190 } |
| 4201 if (!field.IsNull()) { | 4191 if (!field.IsNull()) { |
| 4202 return Api::NewHandle(I, field.StaticValue()); | 4192 return Api::NewHandle(T, field.StaticValue()); |
| 4203 } | 4193 } |
| 4204 return Api::NewError("%s: did not find top-level variable '%s'.", | 4194 return Api::NewError("%s: did not find top-level variable '%s'.", |
| 4205 CURRENT_FUNC, field_name.ToCString()); | 4195 CURRENT_FUNC, field_name.ToCString()); |
| 4206 | 4196 |
| 4207 } else if (obj.IsError()) { | 4197 } else if (obj.IsError()) { |
| 4208 return container; | 4198 return container; |
| 4209 } else { | 4199 } else { |
| 4210 return Api::NewError( | 4200 return Api::NewError( |
| 4211 "%s expects argument 'container' to be an object, type, or library.", | 4201 "%s expects argument 'container' to be an object, type, or library.", |
| 4212 CURRENT_FUNC); | 4202 CURRENT_FUNC); |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4257 } | 4247 } |
| 4258 | 4248 |
| 4259 if (!setter.IsNull()) { | 4249 if (!setter.IsNull()) { |
| 4260 // Invoke the setter and return the result. | 4250 // Invoke the setter and return the result. |
| 4261 const int kNumArgs = 1; | 4251 const int kNumArgs = 1; |
| 4262 const Array& args = Array::Handle(Z, Array::New(kNumArgs)); | 4252 const Array& args = Array::Handle(Z, Array::New(kNumArgs)); |
| 4263 args.SetAt(0, value_instance); | 4253 args.SetAt(0, value_instance); |
| 4264 const Object& result = Object::Handle(Z, | 4254 const Object& result = Object::Handle(Z, |
| 4265 DartEntry::InvokeFunction(setter, args)); | 4255 DartEntry::InvokeFunction(setter, args)); |
| 4266 if (result.IsError()) { | 4256 if (result.IsError()) { |
| 4267 return Api::NewHandle(I, result.raw()); | 4257 return Api::NewHandle(T, result.raw()); |
| 4268 } else { | 4258 } else { |
| 4269 return Api::Success(); | 4259 return Api::Success(); |
| 4270 } | 4260 } |
| 4271 } else if (!field.IsNull()) { | 4261 } else if (!field.IsNull()) { |
| 4272 if (field.is_final()) { | 4262 if (field.is_final()) { |
| 4273 return Api::NewError("%s: cannot set final field '%s'.", | 4263 return Api::NewError("%s: cannot set final field '%s'.", |
| 4274 CURRENT_FUNC, field_name.ToCString()); | 4264 CURRENT_FUNC, field_name.ToCString()); |
| 4275 } else { | 4265 } else { |
| 4276 field.SetStaticValue(value_instance); | 4266 field.SetStaticValue(value_instance); |
| 4277 return Api::Success(); | 4267 return Api::Success(); |
| (...skipping 24 matching lines...) Expand all Loading... |
| 4302 } | 4292 } |
| 4303 | 4293 |
| 4304 // Invoke the setter and return the result. | 4294 // Invoke the setter and return the result. |
| 4305 const int kNumArgs = 2; | 4295 const int kNumArgs = 2; |
| 4306 const Array& args = Array::Handle(Z, Array::New(kNumArgs)); | 4296 const Array& args = Array::Handle(Z, Array::New(kNumArgs)); |
| 4307 args.SetAt(0, instance); | 4297 args.SetAt(0, instance); |
| 4308 args.SetAt(1, value_instance); | 4298 args.SetAt(1, value_instance); |
| 4309 if (setter.IsNull()) { | 4299 if (setter.IsNull()) { |
| 4310 const Array& args_descriptor = | 4300 const Array& args_descriptor = |
| 4311 Array::Handle(Z, ArgumentsDescriptor::New(args.Length())); | 4301 Array::Handle(Z, ArgumentsDescriptor::New(args.Length())); |
| 4312 return Api::NewHandle(I, DartEntry::InvokeNoSuchMethod(instance, | 4302 return Api::NewHandle(T, DartEntry::InvokeNoSuchMethod(instance, |
| 4313 setter_name, | 4303 setter_name, |
| 4314 args, | 4304 args, |
| 4315 args_descriptor)); | 4305 args_descriptor)); |
| 4316 } | 4306 } |
| 4317 return Api::NewHandle(I, DartEntry::InvokeFunction(setter, args)); | 4307 return Api::NewHandle(T, DartEntry::InvokeFunction(setter, args)); |
| 4318 | 4308 |
| 4319 } else if (obj.IsLibrary()) { | 4309 } else if (obj.IsLibrary()) { |
| 4320 // To access a top-level we may need to use the Field or the | 4310 // To access a top-level we may need to use the Field or the |
| 4321 // setter Function. The setter function may either be in the | 4311 // setter Function. The setter function may either be in the |
| 4322 // library or in the field's owner class, depending. | 4312 // library or in the field's owner class, depending. |
| 4323 const Library& lib = Library::Cast(obj); | 4313 const Library& lib = Library::Cast(obj); |
| 4324 // Check that the library is loaded. | 4314 // Check that the library is loaded. |
| 4325 if (!lib.Loaded()) { | 4315 if (!lib.Loaded()) { |
| 4326 return Api::NewError( | 4316 return Api::NewError( |
| 4327 "%s expects library argument 'container' to be loaded.", | 4317 "%s expects library argument 'container' to be loaded.", |
| 4328 CURRENT_FUNC); | 4318 CURRENT_FUNC); |
| 4329 } | 4319 } |
| 4330 field = lib.LookupFieldAllowPrivate(field_name); | 4320 field = lib.LookupFieldAllowPrivate(field_name); |
| 4331 if (field.IsNull()) { | 4321 if (field.IsNull()) { |
| 4332 const String& setter_name = | 4322 const String& setter_name = |
| 4333 String::Handle(Z, Field::SetterName(field_name)); | 4323 String::Handle(Z, Field::SetterName(field_name)); |
| 4334 setter ^= lib.LookupFunctionAllowPrivate(setter_name); | 4324 setter ^= lib.LookupFunctionAllowPrivate(setter_name); |
| 4335 } | 4325 } |
| 4336 | 4326 |
| 4337 if (!setter.IsNull()) { | 4327 if (!setter.IsNull()) { |
| 4338 // Invoke the setter and return the result. | 4328 // Invoke the setter and return the result. |
| 4339 const int kNumArgs = 1; | 4329 const int kNumArgs = 1; |
| 4340 const Array& args = Array::Handle(Z, Array::New(kNumArgs)); | 4330 const Array& args = Array::Handle(Z, Array::New(kNumArgs)); |
| 4341 args.SetAt(0, value_instance); | 4331 args.SetAt(0, value_instance); |
| 4342 const Object& result = | 4332 const Object& result = |
| 4343 Object::Handle(Z, DartEntry::InvokeFunction(setter, args)); | 4333 Object::Handle(Z, DartEntry::InvokeFunction(setter, args)); |
| 4344 if (result.IsError()) { | 4334 if (result.IsError()) { |
| 4345 return Api::NewHandle(I, result.raw()); | 4335 return Api::NewHandle(T, result.raw()); |
| 4346 } | 4336 } |
| 4347 return Api::Success(); | 4337 return Api::Success(); |
| 4348 } | 4338 } |
| 4349 if (!field.IsNull()) { | 4339 if (!field.IsNull()) { |
| 4350 if (field.is_final()) { | 4340 if (field.is_final()) { |
| 4351 return Api::NewError("%s: cannot set final top-level variable '%s'.", | 4341 return Api::NewError("%s: cannot set final top-level variable '%s'.", |
| 4352 CURRENT_FUNC, field_name.ToCString()); | 4342 CURRENT_FUNC, field_name.ToCString()); |
| 4353 } | 4343 } |
| 4354 field.SetStaticValue(value_instance); | 4344 field.SetStaticValue(value_instance); |
| 4355 return Api::Success(); | 4345 return Api::Success(); |
| (...skipping 25 matching lines...) Expand all Loading... |
| 4381 } | 4371 } |
| 4382 } | 4372 } |
| 4383 if (thread->top_exit_frame_info() == 0) { | 4373 if (thread->top_exit_frame_info() == 0) { |
| 4384 // There are no dart frames on the stack so it would be illegal to | 4374 // There are no dart frames on the stack so it would be illegal to |
| 4385 // throw an exception here. | 4375 // throw an exception here. |
| 4386 return Api::NewError("No Dart frames on stack, cannot throw exception"); | 4376 return Api::NewError("No Dart frames on stack, cannot throw exception"); |
| 4387 } | 4377 } |
| 4388 | 4378 |
| 4389 // Unwind all the API scopes till the exit frame before throwing an | 4379 // Unwind all the API scopes till the exit frame before throwing an |
| 4390 // exception. | 4380 // exception. |
| 4391 ApiState* state = isolate->api_state(); | |
| 4392 ASSERT(state != NULL); | |
| 4393 const Instance* saved_exception; | 4381 const Instance* saved_exception; |
| 4394 { | 4382 { |
| 4395 NoSafepointScope no_safepoint; | 4383 NoSafepointScope no_safepoint; |
| 4396 RawInstance* raw_exception = | 4384 RawInstance* raw_exception = |
| 4397 Api::UnwrapInstanceHandle(zone, exception).raw(); | 4385 Api::UnwrapInstanceHandle(zone, exception).raw(); |
| 4398 state->UnwindScopes(thread->top_exit_frame_info()); | 4386 thread->UnwindScopes(thread->top_exit_frame_info()); |
| 4399 saved_exception = &Instance::Handle(raw_exception); | 4387 saved_exception = &Instance::Handle(raw_exception); |
| 4400 } | 4388 } |
| 4401 Exceptions::Throw(thread, *saved_exception); | 4389 Exceptions::Throw(thread, *saved_exception); |
| 4402 return Api::NewError("Exception was not thrown, internal error"); | 4390 return Api::NewError("Exception was not thrown, internal error"); |
| 4403 } | 4391 } |
| 4404 | 4392 |
| 4405 | 4393 |
| 4406 DART_EXPORT Dart_Handle Dart_ReThrowException(Dart_Handle exception, | 4394 DART_EXPORT Dart_Handle Dart_ReThrowException(Dart_Handle exception, |
| 4407 Dart_Handle stacktrace) { | 4395 Dart_Handle stacktrace) { |
| 4408 Thread* thread = Thread::Current(); | 4396 Thread* thread = Thread::Current(); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 4421 } | 4409 } |
| 4422 } | 4410 } |
| 4423 if (thread->top_exit_frame_info() == 0) { | 4411 if (thread->top_exit_frame_info() == 0) { |
| 4424 // There are no dart frames on the stack so it would be illegal to | 4412 // There are no dart frames on the stack so it would be illegal to |
| 4425 // throw an exception here. | 4413 // throw an exception here. |
| 4426 return Api::NewError("No Dart frames on stack, cannot throw exception"); | 4414 return Api::NewError("No Dart frames on stack, cannot throw exception"); |
| 4427 } | 4415 } |
| 4428 | 4416 |
| 4429 // Unwind all the API scopes till the exit frame before throwing an | 4417 // Unwind all the API scopes till the exit frame before throwing an |
| 4430 // exception. | 4418 // exception. |
| 4431 ApiState* state = isolate->api_state(); | |
| 4432 ASSERT(state != NULL); | |
| 4433 const Instance* saved_exception; | 4419 const Instance* saved_exception; |
| 4434 const Stacktrace* saved_stacktrace; | 4420 const Stacktrace* saved_stacktrace; |
| 4435 { | 4421 { |
| 4436 NoSafepointScope no_safepoint; | 4422 NoSafepointScope no_safepoint; |
| 4437 RawInstance* raw_exception = | 4423 RawInstance* raw_exception = |
| 4438 Api::UnwrapInstanceHandle(zone, exception).raw(); | 4424 Api::UnwrapInstanceHandle(zone, exception).raw(); |
| 4439 RawStacktrace* raw_stacktrace = | 4425 RawStacktrace* raw_stacktrace = |
| 4440 Api::UnwrapStacktraceHandle(zone, stacktrace).raw(); | 4426 Api::UnwrapStacktraceHandle(zone, stacktrace).raw(); |
| 4441 state->UnwindScopes(thread->top_exit_frame_info()); | 4427 thread->UnwindScopes(thread->top_exit_frame_info()); |
| 4442 saved_exception = &Instance::Handle(raw_exception); | 4428 saved_exception = &Instance::Handle(raw_exception); |
| 4443 saved_stacktrace = &Stacktrace::Handle(raw_stacktrace); | 4429 saved_stacktrace = &Stacktrace::Handle(raw_stacktrace); |
| 4444 } | 4430 } |
| 4445 Exceptions::ReThrow(thread, *saved_exception, *saved_stacktrace); | 4431 Exceptions::ReThrow(thread, *saved_exception, *saved_stacktrace); |
| 4446 return Api::NewError("Exception was not re thrown, internal error"); | 4432 return Api::NewError("Exception was not re thrown, internal error"); |
| 4447 } | 4433 } |
| 4448 | 4434 |
| 4449 | 4435 |
| 4450 // --- Native fields and functions --- | 4436 // --- Native fields and functions --- |
| 4451 | 4437 |
| (...skipping 15 matching lines...) Expand all Loading... |
| 4467 } | 4453 } |
| 4468 CHECK_CALLBACK_STATE(T); | 4454 CHECK_CALLBACK_STATE(T); |
| 4469 | 4455 |
| 4470 String& cls_symbol = String::Handle(Z, Symbols::New(cls_name)); | 4456 String& cls_symbol = String::Handle(Z, Symbols::New(cls_name)); |
| 4471 const Class& cls = Class::Handle(Z, | 4457 const Class& cls = Class::Handle(Z, |
| 4472 Class::NewNativeWrapper(lib, cls_symbol, field_count)); | 4458 Class::NewNativeWrapper(lib, cls_symbol, field_count)); |
| 4473 if (cls.IsNull()) { | 4459 if (cls.IsNull()) { |
| 4474 return Api::NewError( | 4460 return Api::NewError( |
| 4475 "Unable to create native wrapper class : already exists"); | 4461 "Unable to create native wrapper class : already exists"); |
| 4476 } | 4462 } |
| 4477 return Api::NewHandle(I, cls.RareType()); | 4463 return Api::NewHandle(T, cls.RareType()); |
| 4478 } | 4464 } |
| 4479 | 4465 |
| 4480 | 4466 |
| 4481 DART_EXPORT Dart_Handle Dart_GetNativeInstanceFieldCount(Dart_Handle obj, | 4467 DART_EXPORT Dart_Handle Dart_GetNativeInstanceFieldCount(Dart_Handle obj, |
| 4482 int* count) { | 4468 int* count) { |
| 4483 Thread* thread = Thread::Current(); | 4469 Thread* thread = Thread::Current(); |
| 4484 CHECK_ISOLATE(thread->isolate()); | 4470 CHECK_ISOLATE(thread->isolate()); |
| 4485 ReusableObjectHandleScope reused_obj_handle(thread); | 4471 ReusableObjectHandleScope reused_obj_handle(thread); |
| 4486 const Instance& instance = Api::UnwrapInstanceHandle(reused_obj_handle, obj); | 4472 const Instance& instance = Api::UnwrapInstanceHandle(reused_obj_handle, obj); |
| 4487 if (instance.IsNull()) { | 4473 if (instance.IsNull()) { |
| (...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4647 native_value->as_native_fields.num_fields, | 4633 native_value->as_native_fields.num_fields, |
| 4648 native_value->as_native_fields.values, | 4634 native_value->as_native_fields.values, |
| 4649 CURRENT_FUNC); | 4635 CURRENT_FUNC); |
| 4650 if (result != Api::Success()) { | 4636 if (result != Api::Success()) { |
| 4651 return result; | 4637 return result; |
| 4652 } | 4638 } |
| 4653 break; | 4639 break; |
| 4654 } | 4640 } |
| 4655 | 4641 |
| 4656 case Dart_NativeArgument_kInstance: { | 4642 case Dart_NativeArgument_kInstance: { |
| 4657 Isolate* isolate = arguments->thread()->isolate(); | 4643 ASSERT(arguments->thread() == Thread::Current()); |
| 4658 ASSERT(isolate == Isolate::Current()); | 4644 ASSERT(arguments->thread()->api_top_scope() != NULL); |
| 4659 ASSERT(isolate->api_state() && | 4645 native_value->as_instance = Api::NewHandle( |
| 4660 isolate->api_state()->top_scope() != NULL); | 4646 arguments->thread(), arguments->NativeArgAt(arg_index)); |
| 4661 native_value->as_instance = | |
| 4662 Api::NewHandle(isolate, arguments->NativeArgAt(arg_index)); | |
| 4663 break; | 4647 break; |
| 4664 } | 4648 } |
| 4665 | 4649 |
| 4666 default: | 4650 default: |
| 4667 return Api::NewError("%s: invalid argument type %d.", | 4651 return Api::NewError("%s: invalid argument type %d.", |
| 4668 CURRENT_FUNC, arg_type); | 4652 CURRENT_FUNC, arg_type); |
| 4669 } | 4653 } |
| 4670 } | 4654 } |
| 4671 return Api::Success(); | 4655 return Api::Success(); |
| 4672 } | 4656 } |
| 4673 | 4657 |
| 4674 | 4658 |
| 4675 DART_EXPORT Dart_Handle Dart_GetNativeArgument(Dart_NativeArguments args, | 4659 DART_EXPORT Dart_Handle Dart_GetNativeArgument(Dart_NativeArguments args, |
| 4676 int index) { | 4660 int index) { |
| 4677 TRACE_API_CALL(CURRENT_FUNC); | 4661 TRACE_API_CALL(CURRENT_FUNC); |
| 4678 NativeArguments* arguments = reinterpret_cast<NativeArguments*>(args); | 4662 NativeArguments* arguments = reinterpret_cast<NativeArguments*>(args); |
| 4679 if ((index < 0) || (index >= arguments->NativeArgCount())) { | 4663 if ((index < 0) || (index >= arguments->NativeArgCount())) { |
| 4680 return Api::NewError( | 4664 return Api::NewError( |
| 4681 "%s: argument 'index' out of range. Expected 0..%d but saw %d.", | 4665 "%s: argument 'index' out of range. Expected 0..%d but saw %d.", |
| 4682 CURRENT_FUNC, arguments->NativeArgCount() - 1, index); | 4666 CURRENT_FUNC, arguments->NativeArgCount() - 1, index); |
| 4683 } | 4667 } |
| 4684 return Api::NewHandle(arguments->thread()->isolate(), | 4668 return Api::NewHandle(arguments->thread(), |
| 4685 arguments->NativeArgAt(index)); | 4669 arguments->NativeArgAt(index)); |
| 4686 } | 4670 } |
| 4687 | 4671 |
| 4688 | 4672 |
| 4689 DART_EXPORT int Dart_GetNativeArgumentCount(Dart_NativeArguments args) { | 4673 DART_EXPORT int Dart_GetNativeArgumentCount(Dart_NativeArguments args) { |
| 4690 TRACE_API_CALL(CURRENT_FUNC); | 4674 TRACE_API_CALL(CURRENT_FUNC); |
| 4691 NativeArguments* arguments = reinterpret_cast<NativeArguments*>(args); | 4675 NativeArguments* arguments = reinterpret_cast<NativeArguments*>(args); |
| 4692 return arguments->NativeArgCount(); | 4676 return arguments->NativeArgCount(); |
| 4693 } | 4677 } |
| 4694 | 4678 |
| (...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4824 } | 4808 } |
| 4825 | 4809 |
| 4826 | 4810 |
| 4827 // --- Environment --- | 4811 // --- Environment --- |
| 4828 RawString* Api::CallEnvironmentCallback(Thread* thread, const String& name) { | 4812 RawString* Api::CallEnvironmentCallback(Thread* thread, const String& name) { |
| 4829 Isolate* isolate = thread->isolate(); | 4813 Isolate* isolate = thread->isolate(); |
| 4830 Scope api_scope(thread); | 4814 Scope api_scope(thread); |
| 4831 Dart_EnvironmentCallback callback = isolate->environment_callback(); | 4815 Dart_EnvironmentCallback callback = isolate->environment_callback(); |
| 4832 String& result = String::Handle(thread->zone()); | 4816 String& result = String::Handle(thread->zone()); |
| 4833 if (callback != NULL) { | 4817 if (callback != NULL) { |
| 4834 Dart_Handle response = callback(Api::NewHandle(isolate, name.raw())); | 4818 Dart_Handle response = callback(Api::NewHandle(thread, name.raw())); |
| 4835 if (::Dart_IsString(response)) { | 4819 if (::Dart_IsString(response)) { |
| 4836 result ^= Api::UnwrapHandle(response); | 4820 result ^= Api::UnwrapHandle(response); |
| 4837 } else if (::Dart_IsError(response)) { | 4821 } else if (::Dart_IsError(response)) { |
| 4838 const Object& error = Object::Handle( | 4822 const Object& error = Object::Handle( |
| 4839 thread->zone(), Api::UnwrapHandle(response)); | 4823 thread->zone(), Api::UnwrapHandle(response)); |
| 4840 Exceptions::ThrowArgumentError( | 4824 Exceptions::ThrowArgumentError( |
| 4841 String::Handle(String::New(Error::Cast(error).ToErrorCString()))); | 4825 String::Handle(String::New(Error::Cast(error).ToErrorCString()))); |
| 4842 } else if (!::Dart_IsNull(response)) { | 4826 } else if (!::Dart_IsNull(response)) { |
| 4843 // At this point everything except null are invalid environment values. | 4827 // At this point everything except null are invalid environment values. |
| 4844 Exceptions::ThrowArgumentError( | 4828 Exceptions::ThrowArgumentError( |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4918 Dart_Handle* result) { | 4902 Dart_Handle* result) { |
| 4919 bool update_lib_status = (script.kind() == RawScript::kScriptTag || | 4903 bool update_lib_status = (script.kind() == RawScript::kScriptTag || |
| 4920 script.kind() == RawScript::kLibraryTag); | 4904 script.kind() == RawScript::kLibraryTag); |
| 4921 if (update_lib_status) { | 4905 if (update_lib_status) { |
| 4922 lib.SetLoadInProgress(); | 4906 lib.SetLoadInProgress(); |
| 4923 } | 4907 } |
| 4924 ASSERT(thread != NULL); | 4908 ASSERT(thread != NULL); |
| 4925 const Error& error = | 4909 const Error& error = |
| 4926 Error::Handle(thread->zone(), Compiler::Compile(lib, script)); | 4910 Error::Handle(thread->zone(), Compiler::Compile(lib, script)); |
| 4927 if (error.IsNull()) { | 4911 if (error.IsNull()) { |
| 4928 *result = Api::NewHandle(thread->isolate(), lib.raw()); | 4912 *result = Api::NewHandle(thread, lib.raw()); |
| 4929 } else { | 4913 } else { |
| 4930 *result = Api::NewHandle(thread->isolate(), error.raw()); | 4914 *result = Api::NewHandle(thread, error.raw()); |
| 4931 // Compilation errors are not Dart instances, so just mark the library | 4915 // Compilation errors are not Dart instances, so just mark the library |
| 4932 // as having failed to load without providing an error instance. | 4916 // as having failed to load without providing an error instance. |
| 4933 lib.SetLoadError(Object::null_instance()); | 4917 lib.SetLoadError(Object::null_instance()); |
| 4934 } | 4918 } |
| 4935 } | 4919 } |
| 4936 | 4920 |
| 4937 | 4921 |
| 4938 DART_EXPORT Dart_Handle Dart_LoadScript(Dart_Handle url, | 4922 DART_EXPORT Dart_Handle Dart_LoadScript(Dart_Handle url, |
| 4939 Dart_Handle source, | 4923 Dart_Handle source, |
| 4940 intptr_t line_offset, | 4924 intptr_t line_offset, |
| 4941 intptr_t column_offset) { | 4925 intptr_t column_offset) { |
| 4942 DARTSCOPE(Thread::Current()); | 4926 DARTSCOPE(Thread::Current()); |
| 4927 Isolate* I = T->isolate(); |
| 4943 const String& url_str = Api::UnwrapStringHandle(Z, url); | 4928 const String& url_str = Api::UnwrapStringHandle(Z, url); |
| 4944 if (url_str.IsNull()) { | 4929 if (url_str.IsNull()) { |
| 4945 RETURN_TYPE_ERROR(Z, url, String); | 4930 RETURN_TYPE_ERROR(Z, url, String); |
| 4946 } | 4931 } |
| 4947 const String& source_str = Api::UnwrapStringHandle(Z, source); | 4932 const String& source_str = Api::UnwrapStringHandle(Z, source); |
| 4948 if (source_str.IsNull()) { | 4933 if (source_str.IsNull()) { |
| 4949 RETURN_TYPE_ERROR(Z, source, String); | 4934 RETURN_TYPE_ERROR(Z, source, String); |
| 4950 } | 4935 } |
| 4951 Library& library = Library::Handle(Z, I->object_store()->root_library()); | 4936 Library& library = Library::Handle(Z, I->object_store()->root_library()); |
| 4952 if (!library.IsNull()) { | 4937 if (!library.IsNull()) { |
| (...skipping 24 matching lines...) Expand all Loading... |
| 4977 script.SetLocationOffset(line_offset, column_offset); | 4962 script.SetLocationOffset(line_offset, column_offset); |
| 4978 Dart_Handle result; | 4963 Dart_Handle result; |
| 4979 CompileSource(T, library, script, &result); | 4964 CompileSource(T, library, script, &result); |
| 4980 return result; | 4965 return result; |
| 4981 } | 4966 } |
| 4982 | 4967 |
| 4983 | 4968 |
| 4984 DART_EXPORT Dart_Handle Dart_LoadScriptFromSnapshot(const uint8_t* buffer, | 4969 DART_EXPORT Dart_Handle Dart_LoadScriptFromSnapshot(const uint8_t* buffer, |
| 4985 intptr_t buffer_len) { | 4970 intptr_t buffer_len) { |
| 4986 DARTSCOPE(Thread::Current()); | 4971 DARTSCOPE(Thread::Current()); |
| 4972 Isolate* I = T->isolate(); |
| 4987 StackZone zone(T); | 4973 StackZone zone(T); |
| 4988 if (buffer == NULL) { | 4974 if (buffer == NULL) { |
| 4989 RETURN_NULL_ERROR(buffer); | 4975 RETURN_NULL_ERROR(buffer); |
| 4990 } | 4976 } |
| 4991 NoHeapGrowthControlScope no_growth_control; | 4977 NoHeapGrowthControlScope no_growth_control; |
| 4992 | 4978 |
| 4993 const Snapshot* snapshot = Snapshot::SetupFromBuffer(buffer); | 4979 const Snapshot* snapshot = Snapshot::SetupFromBuffer(buffer); |
| 4994 if (!snapshot->IsScriptSnapshot()) { | 4980 if (!snapshot->IsScriptSnapshot()) { |
| 4995 return Api::NewError("%s expects parameter 'buffer' to be a script type" | 4981 return Api::NewError("%s expects parameter 'buffer' to be a script type" |
| 4996 " snapshot.", CURRENT_FUNC); | 4982 " snapshot.", CURRENT_FUNC); |
| 4997 } | 4983 } |
| 4998 if (snapshot->length() != buffer_len) { | 4984 if (snapshot->length() != buffer_len) { |
| 4999 return Api::NewError("%s: 'buffer_len' of %" Pd " is not equal to %" Pd | 4985 return Api::NewError("%s: 'buffer_len' of %" Pd " is not equal to %" Pd |
| 5000 " which is the expected length in the snapshot.", | 4986 " which is the expected length in the snapshot.", |
| 5001 CURRENT_FUNC, buffer_len, snapshot->length()); | 4987 CURRENT_FUNC, buffer_len, snapshot->length()); |
| 5002 } | 4988 } |
| 5003 Library& library = Library::Handle(Z, I->object_store()->root_library()); | 4989 Library& library = Library::Handle(Z, I->object_store()->root_library()); |
| 5004 if (!library.IsNull()) { | 4990 if (!library.IsNull()) { |
| 5005 const String& library_url = String::Handle(Z, library.url()); | 4991 const String& library_url = String::Handle(Z, library.url()); |
| 5006 return Api::NewError("%s: A script has already been loaded from '%s'.", | 4992 return Api::NewError("%s: A script has already been loaded from '%s'.", |
| 5007 CURRENT_FUNC, library_url.ToCString()); | 4993 CURRENT_FUNC, library_url.ToCString()); |
| 5008 } | 4994 } |
| 5009 CHECK_CALLBACK_STATE(T); | 4995 CHECK_CALLBACK_STATE(T); |
| 5010 CHECK_COMPILATION_ALLOWED(I); | 4996 CHECK_COMPILATION_ALLOWED(I); |
| 5011 | 4997 |
| 5012 ASSERT(snapshot->kind() == Snapshot::kScript); | 4998 ASSERT(snapshot->kind() == Snapshot::kScript); |
| 5013 ScriptSnapshotReader reader(snapshot->content(), snapshot->length(), T); | 4999 ScriptSnapshotReader reader(snapshot->content(), snapshot->length(), T); |
| 5014 const Object& tmp = Object::Handle(Z, reader.ReadScriptSnapshot()); | 5000 const Object& tmp = Object::Handle(Z, reader.ReadScriptSnapshot()); |
| 5015 if (tmp.IsError()) { | 5001 if (tmp.IsError()) { |
| 5016 return Api::NewHandle(I, tmp.raw()); | 5002 return Api::NewHandle(T, tmp.raw()); |
| 5017 } | 5003 } |
| 5018 library ^= tmp.raw(); | 5004 library ^= tmp.raw(); |
| 5019 library.set_debuggable(true); | 5005 library.set_debuggable(true); |
| 5020 I->object_store()->set_root_library(library); | 5006 I->object_store()->set_root_library(library); |
| 5021 return Api::NewHandle(I, library.raw()); | 5007 return Api::NewHandle(T, library.raw()); |
| 5022 } | 5008 } |
| 5023 | 5009 |
| 5024 | 5010 |
| 5025 DART_EXPORT Dart_Handle Dart_RootLibrary() { | 5011 DART_EXPORT Dart_Handle Dart_RootLibrary() { |
| 5026 Isolate* isolate = Isolate::Current(); | 5012 Thread* thread = Thread::Current(); |
| 5013 Isolate* isolate = thread->isolate(); |
| 5027 CHECK_ISOLATE(isolate); | 5014 CHECK_ISOLATE(isolate); |
| 5028 return Api::NewHandle(isolate, isolate->object_store()->root_library()); | 5015 return Api::NewHandle(thread, isolate->object_store()->root_library()); |
| 5029 } | 5016 } |
| 5030 | 5017 |
| 5031 | 5018 |
| 5032 DART_EXPORT Dart_Handle Dart_SetRootLibrary(Dart_Handle library) { | 5019 DART_EXPORT Dart_Handle Dart_SetRootLibrary(Dart_Handle library) { |
| 5033 DARTSCOPE(Thread::Current()); | 5020 DARTSCOPE(Thread::Current()); |
| 5034 const Library& lib = Api::UnwrapLibraryHandle(Z, library); | 5021 const Library& lib = Api::UnwrapLibraryHandle(Z, library); |
| 5035 if (lib.IsNull()) { | 5022 if (lib.IsNull()) { |
| 5036 RETURN_TYPE_ERROR(Z, library, Library); | 5023 RETURN_TYPE_ERROR(Z, library, Library); |
| 5037 } | 5024 } |
| 5038 Isolate* isolate = Isolate::Current(); | 5025 Isolate* isolate = Isolate::Current(); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 5052 if (cls_name.IsNull()) { | 5039 if (cls_name.IsNull()) { |
| 5053 RETURN_TYPE_ERROR(Z, class_name, String); | 5040 RETURN_TYPE_ERROR(Z, class_name, String); |
| 5054 } | 5041 } |
| 5055 const Class& cls = Class::Handle(Z, lib.LookupClassAllowPrivate(cls_name)); | 5042 const Class& cls = Class::Handle(Z, lib.LookupClassAllowPrivate(cls_name)); |
| 5056 if (cls.IsNull()) { | 5043 if (cls.IsNull()) { |
| 5057 // TODO(turnidge): Return null or error in this case? | 5044 // TODO(turnidge): Return null or error in this case? |
| 5058 const String& lib_name = String::Handle(Z, lib.name()); | 5045 const String& lib_name = String::Handle(Z, lib.name()); |
| 5059 return Api::NewError("Class '%s' not found in library '%s'.", | 5046 return Api::NewError("Class '%s' not found in library '%s'.", |
| 5060 cls_name.ToCString(), lib_name.ToCString()); | 5047 cls_name.ToCString(), lib_name.ToCString()); |
| 5061 } | 5048 } |
| 5062 return Api::NewHandle(I, cls.RareType()); | 5049 return Api::NewHandle(T, cls.RareType()); |
| 5063 } | 5050 } |
| 5064 | 5051 |
| 5065 | 5052 |
| 5066 DART_EXPORT Dart_Handle Dart_GetType(Dart_Handle library, | 5053 DART_EXPORT Dart_Handle Dart_GetType(Dart_Handle library, |
| 5067 Dart_Handle class_name, | 5054 Dart_Handle class_name, |
| 5068 intptr_t number_of_type_arguments, | 5055 intptr_t number_of_type_arguments, |
| 5069 Dart_Handle* type_arguments) { | 5056 Dart_Handle* type_arguments) { |
| 5070 DARTSCOPE(Thread::Current()); | 5057 DARTSCOPE(Thread::Current()); |
| 5071 | 5058 |
| 5072 // Validate the input arguments. | 5059 // Validate the input arguments. |
| (...skipping 14 matching lines...) Expand all Loading... |
| 5087 if (cls.IsNull()) { | 5074 if (cls.IsNull()) { |
| 5088 const String& lib_name = String::Handle(Z, lib.name()); | 5075 const String& lib_name = String::Handle(Z, lib.name()); |
| 5089 return Api::NewError("Type '%s' not found in library '%s'.", | 5076 return Api::NewError("Type '%s' not found in library '%s'.", |
| 5090 name_str.ToCString(), lib_name.ToCString()); | 5077 name_str.ToCString(), lib_name.ToCString()); |
| 5091 } | 5078 } |
| 5092 if (cls.NumTypeArguments() == 0) { | 5079 if (cls.NumTypeArguments() == 0) { |
| 5093 if (number_of_type_arguments != 0) { | 5080 if (number_of_type_arguments != 0) { |
| 5094 return Api::NewError("Invalid number of type arguments specified, " | 5081 return Api::NewError("Invalid number of type arguments specified, " |
| 5095 "got %" Pd " expected 0", number_of_type_arguments); | 5082 "got %" Pd " expected 0", number_of_type_arguments); |
| 5096 } | 5083 } |
| 5097 return Api::NewHandle(I, Type::NewNonParameterizedType(cls)); | 5084 return Api::NewHandle(T, Type::NewNonParameterizedType(cls)); |
| 5098 } | 5085 } |
| 5099 intptr_t num_expected_type_arguments = cls.NumTypeParameters(); | 5086 intptr_t num_expected_type_arguments = cls.NumTypeParameters(); |
| 5100 TypeArguments& type_args_obj = TypeArguments::Handle(); | 5087 TypeArguments& type_args_obj = TypeArguments::Handle(); |
| 5101 if (number_of_type_arguments > 0) { | 5088 if (number_of_type_arguments > 0) { |
| 5102 if (type_arguments == NULL) { | 5089 if (type_arguments == NULL) { |
| 5103 RETURN_NULL_ERROR(type_arguments); | 5090 RETURN_NULL_ERROR(type_arguments); |
| 5104 } | 5091 } |
| 5105 if (num_expected_type_arguments != number_of_type_arguments) { | 5092 if (num_expected_type_arguments != number_of_type_arguments) { |
| 5106 return Api::NewError("Invalid number of type arguments specified, " | 5093 return Api::NewError("Invalid number of type arguments specified, " |
| 5107 "got %" Pd " expected %" Pd, | 5094 "got %" Pd " expected %" Pd, |
| (...skipping 17 matching lines...) Expand all Loading... |
| 5125 type_arg ^= array.At(i); | 5112 type_arg ^= array.At(i); |
| 5126 type_args_obj.SetTypeAt(i, type_arg); | 5113 type_args_obj.SetTypeAt(i, type_arg); |
| 5127 } | 5114 } |
| 5128 } | 5115 } |
| 5129 | 5116 |
| 5130 // Construct the type object, canonicalize it and return. | 5117 // Construct the type object, canonicalize it and return. |
| 5131 Type& instantiated_type = Type::Handle( | 5118 Type& instantiated_type = Type::Handle( |
| 5132 Type::New(cls, type_args_obj, Scanner::kNoSourcePos)); | 5119 Type::New(cls, type_args_obj, Scanner::kNoSourcePos)); |
| 5133 instantiated_type ^= ClassFinalizer::FinalizeType( | 5120 instantiated_type ^= ClassFinalizer::FinalizeType( |
| 5134 cls, instantiated_type, ClassFinalizer::kCanonicalize); | 5121 cls, instantiated_type, ClassFinalizer::kCanonicalize); |
| 5135 return Api::NewHandle(I, instantiated_type.raw()); | 5122 return Api::NewHandle(T, instantiated_type.raw()); |
| 5136 } | 5123 } |
| 5137 | 5124 |
| 5138 | 5125 |
| 5139 DART_EXPORT Dart_Handle Dart_LibraryUrl(Dart_Handle library) { | 5126 DART_EXPORT Dart_Handle Dart_LibraryUrl(Dart_Handle library) { |
| 5140 DARTSCOPE(Thread::Current()); | 5127 DARTSCOPE(Thread::Current()); |
| 5141 const Library& lib = Api::UnwrapLibraryHandle(Z, library); | 5128 const Library& lib = Api::UnwrapLibraryHandle(Z, library); |
| 5142 if (lib.IsNull()) { | 5129 if (lib.IsNull()) { |
| 5143 RETURN_TYPE_ERROR(Z, library, Library); | 5130 RETURN_TYPE_ERROR(Z, library, Library); |
| 5144 } | 5131 } |
| 5145 const String& url = String::Handle(Z, lib.url()); | 5132 const String& url = String::Handle(Z, lib.url()); |
| 5146 ASSERT(!url.IsNull()); | 5133 ASSERT(!url.IsNull()); |
| 5147 return Api::NewHandle(I, url.raw()); | 5134 return Api::NewHandle(T, url.raw()); |
| 5148 } | 5135 } |
| 5149 | 5136 |
| 5150 | 5137 |
| 5151 DART_EXPORT Dart_Handle Dart_LookupLibrary(Dart_Handle url) { | 5138 DART_EXPORT Dart_Handle Dart_LookupLibrary(Dart_Handle url) { |
| 5152 DARTSCOPE(Thread::Current()); | 5139 DARTSCOPE(Thread::Current()); |
| 5153 const String& url_str = Api::UnwrapStringHandle(Z, url); | 5140 const String& url_str = Api::UnwrapStringHandle(Z, url); |
| 5154 if (url_str.IsNull()) { | 5141 if (url_str.IsNull()) { |
| 5155 RETURN_TYPE_ERROR(Z, url, String); | 5142 RETURN_TYPE_ERROR(Z, url, String); |
| 5156 } | 5143 } |
| 5157 const Library& library = Library::Handle(Z, Library::LookupLibrary(url_str)); | 5144 const Library& library = Library::Handle(Z, Library::LookupLibrary(url_str)); |
| 5158 if (library.IsNull()) { | 5145 if (library.IsNull()) { |
| 5159 return Api::NewError("%s: library '%s' not found.", | 5146 return Api::NewError("%s: library '%s' not found.", |
| 5160 CURRENT_FUNC, url_str.ToCString()); | 5147 CURRENT_FUNC, url_str.ToCString()); |
| 5161 } else { | 5148 } else { |
| 5162 return Api::NewHandle(I, library.raw()); | 5149 return Api::NewHandle(T, library.raw()); |
| 5163 } | 5150 } |
| 5164 } | 5151 } |
| 5165 | 5152 |
| 5166 | 5153 |
| 5167 DART_EXPORT Dart_Handle Dart_LibraryHandleError(Dart_Handle library_in, | 5154 DART_EXPORT Dart_Handle Dart_LibraryHandleError(Dart_Handle library_in, |
| 5168 Dart_Handle error_in) { | 5155 Dart_Handle error_in) { |
| 5169 DARTSCOPE(Thread::Current()); | 5156 DARTSCOPE(Thread::Current()); |
| 5157 Isolate* I = T->isolate(); |
| 5170 | 5158 |
| 5171 const Library& lib = Api::UnwrapLibraryHandle(Z, library_in); | 5159 const Library& lib = Api::UnwrapLibraryHandle(Z, library_in); |
| 5172 if (lib.IsNull()) { | 5160 if (lib.IsNull()) { |
| 5173 RETURN_TYPE_ERROR(Z, library_in, Library); | 5161 RETURN_TYPE_ERROR(Z, library_in, Library); |
| 5174 } | 5162 } |
| 5175 const Instance& err = Api::UnwrapInstanceHandle(Z, error_in); | 5163 const Instance& err = Api::UnwrapInstanceHandle(Z, error_in); |
| 5176 if (err.IsNull()) { | 5164 if (err.IsNull()) { |
| 5177 RETURN_TYPE_ERROR(Z, error_in, Instance); | 5165 RETURN_TYPE_ERROR(Z, error_in, Instance); |
| 5178 } | 5166 } |
| 5179 CHECK_CALLBACK_STATE(T); | 5167 CHECK_CALLBACK_STATE(T); |
| 5180 | 5168 |
| 5181 const GrowableObjectArray& pending_deferred_loads = | 5169 const GrowableObjectArray& pending_deferred_loads = |
| 5182 GrowableObjectArray::Handle(Z, | 5170 GrowableObjectArray::Handle(Z, |
| 5183 I->object_store()->pending_deferred_loads()); | 5171 I->object_store()->pending_deferred_loads()); |
| 5184 for (intptr_t i = 0; i < pending_deferred_loads.Length(); i++) { | 5172 for (intptr_t i = 0; i < pending_deferred_loads.Length(); i++) { |
| 5185 if (pending_deferred_loads.At(i) == lib.raw()) { | 5173 if (pending_deferred_loads.At(i) == lib.raw()) { |
| 5186 lib.SetLoadError(err); | 5174 lib.SetLoadError(err); |
| 5187 return Api::Null(); | 5175 return Api::Null(); |
| 5188 } | 5176 } |
| 5189 } | 5177 } |
| 5190 return error_in; | 5178 return error_in; |
| 5191 } | 5179 } |
| 5192 | 5180 |
| 5193 | 5181 |
| 5194 DART_EXPORT Dart_Handle Dart_LoadLibrary(Dart_Handle url, | 5182 DART_EXPORT Dart_Handle Dart_LoadLibrary(Dart_Handle url, |
| 5195 Dart_Handle source, | 5183 Dart_Handle source, |
| 5196 intptr_t line_offset, | 5184 intptr_t line_offset, |
| 5197 intptr_t column_offset) { | 5185 intptr_t column_offset) { |
| 5198 DARTSCOPE(Thread::Current()); | 5186 DARTSCOPE(Thread::Current()); |
| 5187 Isolate* I = T->isolate(); |
| 5199 const String& url_str = Api::UnwrapStringHandle(Z, url); | 5188 const String& url_str = Api::UnwrapStringHandle(Z, url); |
| 5200 if (url_str.IsNull()) { | 5189 if (url_str.IsNull()) { |
| 5201 RETURN_TYPE_ERROR(Z, url, String); | 5190 RETURN_TYPE_ERROR(Z, url, String); |
| 5202 } | 5191 } |
| 5203 const String& source_str = Api::UnwrapStringHandle(Z, source); | 5192 const String& source_str = Api::UnwrapStringHandle(Z, source); |
| 5204 if (source_str.IsNull()) { | 5193 if (source_str.IsNull()) { |
| 5205 RETURN_TYPE_ERROR(Z, source, String); | 5194 RETURN_TYPE_ERROR(Z, source, String); |
| 5206 } | 5195 } |
| 5207 if (line_offset < 0) { | 5196 if (line_offset < 0) { |
| 5208 return Api::NewError("%s: argument 'line_offset' must be positive number", | 5197 return Api::NewError("%s: argument 'line_offset' must be positive number", |
| (...skipping 26 matching lines...) Expand all Loading... |
| 5235 Dart_Handle result; | 5224 Dart_Handle result; |
| 5236 CompileSource(T, library, script, &result); | 5225 CompileSource(T, library, script, &result); |
| 5237 // Propagate the error out right now. | 5226 // Propagate the error out right now. |
| 5238 if (::Dart_IsError(result)) { | 5227 if (::Dart_IsError(result)) { |
| 5239 return result; | 5228 return result; |
| 5240 } | 5229 } |
| 5241 | 5230 |
| 5242 // If this is the dart:_builtin library, register it with the VM. | 5231 // If this is the dart:_builtin library, register it with the VM. |
| 5243 if (url_str.Equals("dart:_builtin")) { | 5232 if (url_str.Equals("dart:_builtin")) { |
| 5244 I->object_store()->set_builtin_library(library); | 5233 I->object_store()->set_builtin_library(library); |
| 5245 Dart_Handle state = Api::CheckAndFinalizePendingClasses(I); | 5234 Dart_Handle state = Api::CheckAndFinalizePendingClasses(T); |
| 5246 if (::Dart_IsError(state)) { | 5235 if (::Dart_IsError(state)) { |
| 5247 return state; | 5236 return state; |
| 5248 } | 5237 } |
| 5249 } | 5238 } |
| 5250 return result; | 5239 return result; |
| 5251 } | 5240 } |
| 5252 | 5241 |
| 5253 | 5242 |
| 5254 DART_EXPORT Dart_Handle Dart_LibraryImportLibrary(Dart_Handle library, | 5243 DART_EXPORT Dart_Handle Dart_LibraryImportLibrary(Dart_Handle library, |
| 5255 Dart_Handle import, | 5244 Dart_Handle import, |
| 5256 Dart_Handle prefix) { | 5245 Dart_Handle prefix) { |
| 5257 DARTSCOPE(Thread::Current()); | 5246 DARTSCOPE(Thread::Current()); |
| 5247 Isolate* I = T->isolate(); |
| 5258 const Library& library_vm = Api::UnwrapLibraryHandle(Z, library); | 5248 const Library& library_vm = Api::UnwrapLibraryHandle(Z, library); |
| 5259 if (library_vm.IsNull()) { | 5249 if (library_vm.IsNull()) { |
| 5260 RETURN_TYPE_ERROR(Z, library, Library); | 5250 RETURN_TYPE_ERROR(Z, library, Library); |
| 5261 } | 5251 } |
| 5262 const Library& import_vm = Api::UnwrapLibraryHandle(Z, import); | 5252 const Library& import_vm = Api::UnwrapLibraryHandle(Z, import); |
| 5263 if (import_vm.IsNull()) { | 5253 if (import_vm.IsNull()) { |
| 5264 RETURN_TYPE_ERROR(Z, import, Library); | 5254 RETURN_TYPE_ERROR(Z, import, Library); |
| 5265 } | 5255 } |
| 5266 const Object& prefix_object = Object::Handle(Z, Api::UnwrapHandle(prefix)); | 5256 const Object& prefix_object = Object::Handle(Z, Api::UnwrapHandle(prefix)); |
| 5267 const String& prefix_vm = prefix_object.IsNull() | 5257 const String& prefix_vm = prefix_object.IsNull() |
| (...skipping 24 matching lines...) Expand all Loading... |
| 5292 return Api::Success(); | 5282 return Api::Success(); |
| 5293 } | 5283 } |
| 5294 | 5284 |
| 5295 | 5285 |
| 5296 DART_EXPORT Dart_Handle Dart_LoadSource(Dart_Handle library, | 5286 DART_EXPORT Dart_Handle Dart_LoadSource(Dart_Handle library, |
| 5297 Dart_Handle url, | 5287 Dart_Handle url, |
| 5298 Dart_Handle source, | 5288 Dart_Handle source, |
| 5299 intptr_t line_offset, | 5289 intptr_t line_offset, |
| 5300 intptr_t column_offset) { | 5290 intptr_t column_offset) { |
| 5301 DARTSCOPE(Thread::Current()); | 5291 DARTSCOPE(Thread::Current()); |
| 5292 Isolate* I = T->isolate(); |
| 5302 const Library& lib = Api::UnwrapLibraryHandle(Z, library); | 5293 const Library& lib = Api::UnwrapLibraryHandle(Z, library); |
| 5303 if (lib.IsNull()) { | 5294 if (lib.IsNull()) { |
| 5304 RETURN_TYPE_ERROR(Z, library, Library); | 5295 RETURN_TYPE_ERROR(Z, library, Library); |
| 5305 } | 5296 } |
| 5306 const String& url_str = Api::UnwrapStringHandle(Z, url); | 5297 const String& url_str = Api::UnwrapStringHandle(Z, url); |
| 5307 if (url_str.IsNull()) { | 5298 if (url_str.IsNull()) { |
| 5308 RETURN_TYPE_ERROR(Z, url, String); | 5299 RETURN_TYPE_ERROR(Z, url, String); |
| 5309 } | 5300 } |
| 5310 const String& source_str = Api::UnwrapStringHandle(Z, source); | 5301 const String& source_str = Api::UnwrapStringHandle(Z, source); |
| 5311 if (source_str.IsNull()) { | 5302 if (source_str.IsNull()) { |
| (...skipping 18 matching lines...) Expand all Loading... |
| 5330 Dart_Handle result; | 5321 Dart_Handle result; |
| 5331 CompileSource(T, lib, script, &result); | 5322 CompileSource(T, lib, script, &result); |
| 5332 return result; | 5323 return result; |
| 5333 } | 5324 } |
| 5334 | 5325 |
| 5335 | 5326 |
| 5336 DART_EXPORT Dart_Handle Dart_LibraryLoadPatch(Dart_Handle library, | 5327 DART_EXPORT Dart_Handle Dart_LibraryLoadPatch(Dart_Handle library, |
| 5337 Dart_Handle url, | 5328 Dart_Handle url, |
| 5338 Dart_Handle patch_source) { | 5329 Dart_Handle patch_source) { |
| 5339 DARTSCOPE(Thread::Current()); | 5330 DARTSCOPE(Thread::Current()); |
| 5331 Isolate* I = T->isolate(); |
| 5340 const Library& lib = Api::UnwrapLibraryHandle(Z, library); | 5332 const Library& lib = Api::UnwrapLibraryHandle(Z, library); |
| 5341 if (lib.IsNull()) { | 5333 if (lib.IsNull()) { |
| 5342 RETURN_TYPE_ERROR(Z, library, Library); | 5334 RETURN_TYPE_ERROR(Z, library, Library); |
| 5343 } | 5335 } |
| 5344 const String& url_str = Api::UnwrapStringHandle(Z, url); | 5336 const String& url_str = Api::UnwrapStringHandle(Z, url); |
| 5345 if (url_str.IsNull()) { | 5337 if (url_str.IsNull()) { |
| 5346 RETURN_TYPE_ERROR(Z, url, String); | 5338 RETURN_TYPE_ERROR(Z, url, String); |
| 5347 } | 5339 } |
| 5348 const String& source_str = Api::UnwrapStringHandle(Z, patch_source); | 5340 const String& source_str = Api::UnwrapStringHandle(Z, patch_source); |
| 5349 if (source_str.IsNull()) { | 5341 if (source_str.IsNull()) { |
| 5350 RETURN_TYPE_ERROR(Z, patch_source, String); | 5342 RETURN_TYPE_ERROR(Z, patch_source, String); |
| 5351 } | 5343 } |
| 5352 CHECK_CALLBACK_STATE(T); | 5344 CHECK_CALLBACK_STATE(T); |
| 5353 CHECK_COMPILATION_ALLOWED(I); | 5345 CHECK_COMPILATION_ALLOWED(I); |
| 5354 | 5346 |
| 5355 NoHeapGrowthControlScope no_growth_control; | 5347 NoHeapGrowthControlScope no_growth_control; |
| 5356 | 5348 |
| 5357 const Script& script = Script::Handle(Z, | 5349 const Script& script = Script::Handle(Z, |
| 5358 Script::New(url_str, source_str, RawScript::kPatchTag)); | 5350 Script::New(url_str, source_str, RawScript::kPatchTag)); |
| 5359 Dart_Handle result; | 5351 Dart_Handle result; |
| 5360 CompileSource(T, lib, script, &result); | 5352 CompileSource(T, lib, script, &result); |
| 5361 return result; | 5353 return result; |
| 5362 } | 5354 } |
| 5363 | 5355 |
| 5364 | 5356 |
| 5365 // Finalizes classes and invokes Dart core library function that completes | 5357 // Finalizes classes and invokes Dart core library function that completes |
| 5366 // futures of loadLibrary calls (deferred library loading). | 5358 // futures of loadLibrary calls (deferred library loading). |
| 5367 DART_EXPORT Dart_Handle Dart_FinalizeLoading(bool complete_futures) { | 5359 DART_EXPORT Dart_Handle Dart_FinalizeLoading(bool complete_futures) { |
| 5368 DARTSCOPE(Thread::Current()); | 5360 DARTSCOPE(Thread::Current()); |
| 5361 Isolate* I = T->isolate(); |
| 5369 CHECK_CALLBACK_STATE(T); | 5362 CHECK_CALLBACK_STATE(T); |
| 5370 | 5363 |
| 5371 I->DoneLoading(); | 5364 I->DoneLoading(); |
| 5372 | 5365 |
| 5373 // TODO(hausner): move the remaining code below (finalization and | 5366 // TODO(hausner): move the remaining code below (finalization and |
| 5374 // invoing of _completeDeferredLoads) into Isolate::DoneLoading(). | 5367 // invoing of _completeDeferredLoads) into Isolate::DoneLoading(). |
| 5375 | 5368 |
| 5376 // Finalize all classes if needed. | 5369 // Finalize all classes if needed. |
| 5377 Dart_Handle state = Api::CheckAndFinalizePendingClasses(I); | 5370 Dart_Handle state = Api::CheckAndFinalizePendingClasses(T); |
| 5378 if (::Dart_IsError(state)) { | 5371 if (::Dart_IsError(state)) { |
| 5379 return state; | 5372 return state; |
| 5380 } | 5373 } |
| 5381 | 5374 |
| 5382 // Now that the newly loaded classes are finalized, notify the debugger | 5375 // Now that the newly loaded classes are finalized, notify the debugger |
| 5383 // that new code has been loaded. If there are latent breakpoints in | 5376 // that new code has been loaded. If there are latent breakpoints in |
| 5384 // the new code, the debugger convert them to unresolved source breakpoints. | 5377 // the new code, the debugger convert them to unresolved source breakpoints. |
| 5385 // The code that completes the futures (invoked below) may call into the | 5378 // The code that completes the futures (invoked below) may call into the |
| 5386 // newly loaded code and trigger one of these breakpoints. | 5379 // newly loaded code and trigger one of these breakpoints. |
| 5387 I->debugger()->NotifyDoneLoading(); | 5380 I->debugger()->NotifyDoneLoading(); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 5399 String::Handle(Z, String::New("_completeDeferredLoads")); | 5392 String::Handle(Z, String::New("_completeDeferredLoads")); |
| 5400 const Function& function = Function::Handle(Z, | 5393 const Function& function = Function::Handle(Z, |
| 5401 corelib.LookupFunctionAllowPrivate(function_name)); | 5394 corelib.LookupFunctionAllowPrivate(function_name)); |
| 5402 ASSERT(!function.IsNull()); | 5395 ASSERT(!function.IsNull()); |
| 5403 const Array& args = Array::empty_array(); | 5396 const Array& args = Array::empty_array(); |
| 5404 | 5397 |
| 5405 const Object& res = | 5398 const Object& res = |
| 5406 Object::Handle(Z, DartEntry::InvokeFunction(function, args)); | 5399 Object::Handle(Z, DartEntry::InvokeFunction(function, args)); |
| 5407 I->object_store()->clear_pending_deferred_loads(); | 5400 I->object_store()->clear_pending_deferred_loads(); |
| 5408 if (res.IsError() || res.IsUnhandledException()) { | 5401 if (res.IsError() || res.IsUnhandledException()) { |
| 5409 return Api::NewHandle(I, res.raw()); | 5402 return Api::NewHandle(T, res.raw()); |
| 5410 } | 5403 } |
| 5411 } | 5404 } |
| 5412 return Api::Success(); | 5405 return Api::Success(); |
| 5413 } | 5406 } |
| 5414 | 5407 |
| 5415 | 5408 |
| 5416 DART_EXPORT Dart_Handle Dart_SetNativeResolver( | 5409 DART_EXPORT Dart_Handle Dart_SetNativeResolver( |
| 5417 Dart_Handle library, | 5410 Dart_Handle library, |
| 5418 Dart_NativeEntryResolver resolver, | 5411 Dart_NativeEntryResolver resolver, |
| 5419 Dart_NativeEntrySymbol symbol) { | 5412 Dart_NativeEntrySymbol symbol) { |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5536 Service::SetEmbedderStreamCallbacks(listen_callback, cancel_callback); | 5529 Service::SetEmbedderStreamCallbacks(listen_callback, cancel_callback); |
| 5537 return Api::Success(); | 5530 return Api::Success(); |
| 5538 } | 5531 } |
| 5539 | 5532 |
| 5540 | 5533 |
| 5541 DART_EXPORT Dart_Handle Dart_ServiceSendDataEvent(const char* stream_id, | 5534 DART_EXPORT Dart_Handle Dart_ServiceSendDataEvent(const char* stream_id, |
| 5542 const char* event_kind, | 5535 const char* event_kind, |
| 5543 const uint8_t* bytes, | 5536 const uint8_t* bytes, |
| 5544 intptr_t bytes_length) { | 5537 intptr_t bytes_length) { |
| 5545 DARTSCOPE(Thread::Current()); | 5538 DARTSCOPE(Thread::Current()); |
| 5539 Isolate* I = T->isolate(); |
| 5546 if (stream_id == NULL) { | 5540 if (stream_id == NULL) { |
| 5547 RETURN_NULL_ERROR(stream_id); | 5541 RETURN_NULL_ERROR(stream_id); |
| 5548 } | 5542 } |
| 5549 if (event_kind == NULL) { | 5543 if (event_kind == NULL) { |
| 5550 RETURN_NULL_ERROR(event_kind); | 5544 RETURN_NULL_ERROR(event_kind); |
| 5551 } | 5545 } |
| 5552 if (bytes == NULL) { | 5546 if (bytes == NULL) { |
| 5553 RETURN_NULL_ERROR(bytes); | 5547 RETURN_NULL_ERROR(bytes); |
| 5554 } | 5548 } |
| 5555 if (bytes_length < 0) { | 5549 if (bytes_length < 0) { |
| (...skipping 307 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5863 } | 5857 } |
| 5864 | 5858 |
| 5865 | 5859 |
| 5866 DART_EXPORT Dart_Handle Dart_Precompile( | 5860 DART_EXPORT Dart_Handle Dart_Precompile( |
| 5867 Dart_QualifiedFunctionName entry_points[], | 5861 Dart_QualifiedFunctionName entry_points[], |
| 5868 bool reset_fields) { | 5862 bool reset_fields) { |
| 5869 DARTSCOPE(Thread::Current()); | 5863 DARTSCOPE(Thread::Current()); |
| 5870 if (!FLAG_precompilation) { | 5864 if (!FLAG_precompilation) { |
| 5871 return Dart_NewApiError("Flag --precompilation was not specified."); | 5865 return Dart_NewApiError("Flag --precompilation was not specified."); |
| 5872 } | 5866 } |
| 5873 Dart_Handle result = Api::CheckAndFinalizePendingClasses(I); | 5867 Dart_Handle result = Api::CheckAndFinalizePendingClasses(T); |
| 5874 if (::Dart_IsError(result)) { | 5868 if (::Dart_IsError(result)) { |
| 5875 return result; | 5869 return result; |
| 5876 } | 5870 } |
| 5877 CHECK_CALLBACK_STATE(T); | 5871 CHECK_CALLBACK_STATE(T); |
| 5878 const Error& error = Error::Handle(Precompiler::CompileAll(entry_points, | 5872 const Error& error = Error::Handle(Precompiler::CompileAll(entry_points, |
| 5879 reset_fields)); | 5873 reset_fields)); |
| 5880 if (!error.IsNull()) { | 5874 if (!error.IsNull()) { |
| 5881 return Api::NewHandle(I, error.raw()); | 5875 return Api::NewHandle(T, error.raw()); |
| 5882 } | 5876 } |
| 5883 return Api::Success(); | 5877 return Api::Success(); |
| 5884 } | 5878 } |
| 5885 | 5879 |
| 5886 | 5880 |
| 5887 DART_EXPORT Dart_Handle Dart_CreatePrecompiledSnapshot( | 5881 DART_EXPORT Dart_Handle Dart_CreatePrecompiledSnapshot( |
| 5888 uint8_t** vm_isolate_snapshot_buffer, | 5882 uint8_t** vm_isolate_snapshot_buffer, |
| 5889 intptr_t* vm_isolate_snapshot_size, | 5883 intptr_t* vm_isolate_snapshot_size, |
| 5890 uint8_t** isolate_snapshot_buffer, | 5884 uint8_t** isolate_snapshot_buffer, |
| 5891 intptr_t* isolate_snapshot_size, | 5885 intptr_t* isolate_snapshot_size, |
| 5892 uint8_t** instructions_snapshot_buffer, | 5886 uint8_t** instructions_snapshot_buffer, |
| 5893 intptr_t* instructions_snapshot_size) { | 5887 intptr_t* instructions_snapshot_size) { |
| 5894 ASSERT(FLAG_load_deferred_eagerly); | 5888 ASSERT(FLAG_load_deferred_eagerly); |
| 5895 DARTSCOPE(Thread::Current()); | 5889 DARTSCOPE(Thread::Current()); |
| 5890 Isolate* I = T->isolate(); |
| 5896 if (I->compilation_allowed()) { | 5891 if (I->compilation_allowed()) { |
| 5897 return Dart_NewApiError("Isolate is not precompiled. " | 5892 return Dart_NewApiError("Isolate is not precompiled. " |
| 5898 "Did you forget to call Dart_Precompile?"); | 5893 "Did you forget to call Dart_Precompile?"); |
| 5899 } | 5894 } |
| 5900 if (vm_isolate_snapshot_buffer == NULL) { | 5895 if (vm_isolate_snapshot_buffer == NULL) { |
| 5901 RETURN_NULL_ERROR(vm_isolate_snapshot_buffer); | 5896 RETURN_NULL_ERROR(vm_isolate_snapshot_buffer); |
| 5902 } | 5897 } |
| 5903 if (vm_isolate_snapshot_size == NULL) { | 5898 if (vm_isolate_snapshot_size == NULL) { |
| 5904 RETURN_NULL_ERROR(vm_isolate_snapshot_size); | 5899 RETURN_NULL_ERROR(vm_isolate_snapshot_size); |
| 5905 } | 5900 } |
| 5906 if (isolate_snapshot_buffer == NULL) { | 5901 if (isolate_snapshot_buffer == NULL) { |
| 5907 RETURN_NULL_ERROR(isolate_snapshot_buffer); | 5902 RETURN_NULL_ERROR(isolate_snapshot_buffer); |
| 5908 } | 5903 } |
| 5909 if (isolate_snapshot_size == NULL) { | 5904 if (isolate_snapshot_size == NULL) { |
| 5910 RETURN_NULL_ERROR(isolate_snapshot_size); | 5905 RETURN_NULL_ERROR(isolate_snapshot_size); |
| 5911 } | 5906 } |
| 5912 if (instructions_snapshot_buffer == NULL) { | 5907 if (instructions_snapshot_buffer == NULL) { |
| 5913 RETURN_NULL_ERROR(instructions_snapshot_buffer); | 5908 RETURN_NULL_ERROR(instructions_snapshot_buffer); |
| 5914 } | 5909 } |
| 5915 if (instructions_snapshot_size == NULL) { | 5910 if (instructions_snapshot_size == NULL) { |
| 5916 RETURN_NULL_ERROR(instructions_snapshot_size); | 5911 RETURN_NULL_ERROR(instructions_snapshot_size); |
| 5917 } | 5912 } |
| 5918 // Finalize all classes if needed. | 5913 // Finalize all classes if needed. |
| 5919 Dart_Handle state = Api::CheckAndFinalizePendingClasses(I); | 5914 Dart_Handle state = Api::CheckAndFinalizePendingClasses(T); |
| 5920 if (::Dart_IsError(state)) { | 5915 if (::Dart_IsError(state)) { |
| 5921 return state; | 5916 return state; |
| 5922 } | 5917 } |
| 5923 I->heap()->CollectAllGarbage(); | 5918 I->heap()->CollectAllGarbage(); |
| 5924 PrecompiledSnapshotWriter writer(vm_isolate_snapshot_buffer, | 5919 PrecompiledSnapshotWriter writer(vm_isolate_snapshot_buffer, |
| 5925 isolate_snapshot_buffer, | 5920 isolate_snapshot_buffer, |
| 5926 instructions_snapshot_buffer, | 5921 instructions_snapshot_buffer, |
| 5927 ApiReallocate); | 5922 ApiReallocate); |
| 5928 writer.WriteFullSnapshot(); | 5923 writer.WriteFullSnapshot(); |
| 5929 *vm_isolate_snapshot_size = writer.VmIsolateSnapshotSize(); | 5924 *vm_isolate_snapshot_size = writer.VmIsolateSnapshotSize(); |
| 5930 *isolate_snapshot_size = writer.IsolateSnapshotSize(); | 5925 *isolate_snapshot_size = writer.IsolateSnapshotSize(); |
| 5931 *instructions_snapshot_size = writer.InstructionsSnapshotSize(); | 5926 *instructions_snapshot_size = writer.InstructionsSnapshotSize(); |
| 5932 | 5927 |
| 5933 return Api::Success(); | 5928 return Api::Success(); |
| 5934 } | 5929 } |
| 5935 | 5930 |
| 5936 } // namespace dart | 5931 } // namespace dart |
| OLD | NEW |