OLD | NEW |
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 #include "include/dart_api.h" | 5 #include "include/dart_api.h" |
6 | 6 |
7 #include "vm/bigint_operations.h" | 7 #include "vm/bigint_operations.h" |
8 #include "vm/class_finalizer.h" | 8 #include "vm/class_finalizer.h" |
9 #include "vm/compiler.h" | 9 #include "vm/compiler.h" |
10 #include "vm/dart.h" | 10 #include "vm/dart.h" |
11 #include "vm/dart_api_impl.h" | 11 #include "vm/dart_api_impl.h" |
12 #include "vm/dart_api_state.h" | 12 #include "vm/dart_api_state.h" |
13 #include "vm/dart_entry.h" | 13 #include "vm/dart_entry.h" |
14 #include "vm/debuginfo.h" | 14 #include "vm/debuginfo.h" |
15 #include "vm/exceptions.h" | 15 #include "vm/exceptions.h" |
16 #include "vm/growable_array.h" | 16 #include "vm/growable_array.h" |
17 #include "vm/longjump.h" | |
18 #include "vm/message.h" | 17 #include "vm/message.h" |
19 #include "vm/native_entry.h" | 18 #include "vm/native_entry.h" |
20 #include "vm/native_message_handler.h" | 19 #include "vm/native_message_handler.h" |
21 #include "vm/object.h" | 20 #include "vm/object.h" |
22 #include "vm/object_store.h" | 21 #include "vm/object_store.h" |
23 #include "vm/port.h" | 22 #include "vm/port.h" |
24 #include "vm/resolver.h" | 23 #include "vm/resolver.h" |
25 #include "vm/snapshot.h" | 24 #include "vm/snapshot.h" |
26 #include "vm/stack_frame.h" | 25 #include "vm/stack_frame.h" |
27 #include "vm/timer.h" | 26 #include "vm/timer.h" |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
80 } | 79 } |
81 | 80 |
82 | 81 |
83 void SetupErrorResult(Dart_Handle* handle) { | 82 void SetupErrorResult(Dart_Handle* handle) { |
84 const Error& error = Error::Handle( | 83 const Error& error = Error::Handle( |
85 Isolate::Current()->object_store()->sticky_error()); | 84 Isolate::Current()->object_store()->sticky_error()); |
86 *handle = Api::NewLocalHandle(error); | 85 *handle = Api::NewLocalHandle(error); |
87 } | 86 } |
88 | 87 |
89 | 88 |
90 // NOTE: Need to pass 'result' as a parameter here in order to avoid | |
91 // warning: variable 'result' might be clobbered by 'longjmp' or 'vfork' | |
92 // which shows up because of the use of setjmp. | |
93 static void InvokeStatic(Isolate* isolate, | |
94 const Function& function, | |
95 GrowableArray<const Object*>& args, | |
96 Dart_Handle* result) { | |
97 ASSERT(isolate != NULL); | |
98 LongJump* base = isolate->long_jump_base(); | |
99 LongJump jump; | |
100 isolate->set_long_jump_base(&jump); | |
101 if (setjmp(*jump.Set()) == 0) { | |
102 const Array& kNoArgumentNames = Array::Handle(); | |
103 const Instance& retval = Instance::Handle( | |
104 DartEntry::InvokeStatic(function, args, kNoArgumentNames)); | |
105 *result = Api::NewLocalHandle(retval); | |
106 } else { | |
107 SetupErrorResult(result); | |
108 } | |
109 isolate->set_long_jump_base(base); | |
110 } | |
111 | |
112 | |
113 // NOTE: Need to pass 'result' as a parameter here in order to avoid | |
114 // warning: variable 'result' might be clobbered by 'longjmp' or 'vfork' | |
115 // which shows up because of the use of setjmp. | |
116 static void InvokeDynamic(Isolate* isolate, | |
117 const Instance& receiver, | |
118 const Function& function, | |
119 GrowableArray<const Object*>& args, | |
120 Dart_Handle* result) { | |
121 ASSERT(isolate != NULL); | |
122 LongJump* base = isolate->long_jump_base(); | |
123 LongJump jump; | |
124 isolate->set_long_jump_base(&jump); | |
125 if (setjmp(*jump.Set()) == 0) { | |
126 const Array& kNoArgumentNames = Array::Handle(); | |
127 const Instance& retval = Instance::Handle( | |
128 DartEntry::InvokeDynamic(receiver, function, args, kNoArgumentNames)); | |
129 *result = Api::NewLocalHandle(retval); | |
130 } else { | |
131 SetupErrorResult(result); | |
132 } | |
133 isolate->set_long_jump_base(base); | |
134 } | |
135 | |
136 | |
137 Dart_Handle Api::NewLocalHandle(const Object& object) { | 89 Dart_Handle Api::NewLocalHandle(const Object& object) { |
138 Isolate* isolate = Isolate::Current(); | 90 Isolate* isolate = Isolate::Current(); |
139 ASSERT(isolate != NULL); | 91 ASSERT(isolate != NULL); |
140 ApiState* state = isolate->api_state(); | 92 ApiState* state = isolate->api_state(); |
141 ASSERT(state != NULL); | 93 ASSERT(state != NULL); |
142 ApiLocalScope* scope = state->top_scope(); | 94 ApiLocalScope* scope = state->top_scope(); |
143 ASSERT(scope != NULL); | 95 ASSERT(scope != NULL); |
144 LocalHandles* local_handles = scope->local_handles(); | 96 LocalHandles* local_handles = scope->local_handles(); |
145 ASSERT(local_handles != NULL); | 97 ASSERT(local_handles != NULL); |
146 LocalHandle* ref = local_handles->AllocateHandle(); | 98 LocalHandle* ref = local_handles->AllocateHandle(); |
(...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
366 va_start(args2, format); | 318 va_start(args2, format); |
367 OS::VSNPrint(buffer, (len + 1), format, args2); | 319 OS::VSNPrint(buffer, (len + 1), format, args2); |
368 va_end(args2); | 320 va_end(args2); |
369 | 321 |
370 const String& message = String::Handle(String::New(buffer)); | 322 const String& message = String::Handle(String::New(buffer)); |
371 const Object& obj = Object::Handle(ApiError::New(message)); | 323 const Object& obj = Object::Handle(ApiError::New(message)); |
372 return Api::NewLocalHandle(obj); | 324 return Api::NewLocalHandle(obj); |
373 } | 325 } |
374 | 326 |
375 | 327 |
| 328 DART_EXPORT Dart_Handle Dart_PropagateError(Dart_Handle handle) { |
| 329 Isolate* isolate = Isolate::Current(); |
| 330 CHECK_ISOLATE(isolate); |
| 331 const Object& error = Object::Handle(Api::UnwrapHandle(handle)); |
| 332 if (!error.IsError()) { |
| 333 return Api::NewError( |
| 334 "%s expects argument 'handle' to be an error handle. " |
| 335 "Did you forget to check Dart_IsError first?", |
| 336 CURRENT_FUNC); |
| 337 } |
| 338 if (isolate->top_exit_frame_info() == 0) { |
| 339 // There are no dart frames on the stack so it would be illegal to |
| 340 // propagate an error here. |
| 341 return Api::NewError("No Dart frames on stack, cannot propagate error."); |
| 342 } |
| 343 |
| 344 // Unwind all the API scopes till the exit frame before propagating. |
| 345 ApiState* state = isolate->api_state(); |
| 346 ASSERT(state != NULL); |
| 347 state->UnwindScopes(isolate->top_exit_frame_info()); |
| 348 Exceptions::PropagateError(error); |
| 349 UNREACHABLE(); |
| 350 |
| 351 return Api::NewError("Cannot reach here. Internal error."); |
| 352 } |
| 353 |
| 354 |
376 DART_EXPORT void _Dart_ReportErrorHandle(const char* file, | 355 DART_EXPORT void _Dart_ReportErrorHandle(const char* file, |
377 int line, | 356 int line, |
378 const char* handle, | 357 const char* handle, |
379 const char* message) { | 358 const char* message) { |
380 fprintf(stderr, "%s:%d: error handle: '%s':\n '%s'\n", | 359 fprintf(stderr, "%s:%d: error handle: '%s':\n '%s'\n", |
381 file, line, handle, message); | 360 file, line, handle, message); |
382 OS::Abort(); | 361 OS::Abort(); |
383 } | 362 } |
384 | 363 |
385 | 364 |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
493 | 472 |
494 // --- Isolates --- | 473 // --- Isolates --- |
495 | 474 |
496 | 475 |
497 DART_EXPORT Dart_Isolate Dart_CreateIsolate(const char* name_prefix, | 476 DART_EXPORT Dart_Isolate Dart_CreateIsolate(const char* name_prefix, |
498 const uint8_t* snapshot, | 477 const uint8_t* snapshot, |
499 void* callback_data, | 478 void* callback_data, |
500 char** error) { | 479 char** error) { |
501 Isolate* isolate = Dart::CreateIsolate(name_prefix); | 480 Isolate* isolate = Dart::CreateIsolate(name_prefix); |
502 assert(isolate != NULL); | 481 assert(isolate != NULL); |
503 LongJump* base = isolate->long_jump_base(); | 482 DARTSCOPE_NOCHECKS(isolate); |
504 LongJump jump; | 483 const Error& error_obj = |
505 isolate->set_long_jump_base(&jump); | 484 Error::Handle(Dart::InitializeIsolate(snapshot, callback_data)); |
506 if (setjmp(*jump.Set()) == 0) { | 485 if (error_obj.IsNull()) { |
507 Dart::InitializeIsolate(snapshot, callback_data); | |
508 START_TIMER(time_total_runtime); | 486 START_TIMER(time_total_runtime); |
509 isolate->set_long_jump_base(base); | |
510 return reinterpret_cast<Dart_Isolate>(isolate); | 487 return reinterpret_cast<Dart_Isolate>(isolate); |
511 } else { | 488 } else { |
512 { | 489 *error = strdup(error_obj.ToErrorCString()); |
513 DARTSCOPE_NOCHECKS(isolate); | |
514 const Error& error_obj = | |
515 Error::Handle(isolate->object_store()->sticky_error()); | |
516 *error = strdup(error_obj.ToErrorCString()); | |
517 } | |
518 Dart::ShutdownIsolate(); | 490 Dart::ShutdownIsolate(); |
| 491 return reinterpret_cast<Dart_Isolate>(NULL); |
519 } | 492 } |
520 return reinterpret_cast<Dart_Isolate>(NULL); | |
521 } | 493 } |
522 | 494 |
523 | 495 |
524 DART_EXPORT void Dart_ShutdownIsolate() { | 496 DART_EXPORT void Dart_ShutdownIsolate() { |
525 CHECK_ISOLATE(Isolate::Current()); | 497 CHECK_ISOLATE(Isolate::Current()); |
526 STOP_TIMER(time_total_runtime); | 498 STOP_TIMER(time_total_runtime); |
527 Dart::ShutdownIsolate(); | 499 Dart::ShutdownIsolate(); |
528 } | 500 } |
529 | 501 |
530 | 502 |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
629 Dart_MessageNotifyCallback message_notify_callback) { | 601 Dart_MessageNotifyCallback message_notify_callback) { |
630 Isolate* isolate = Isolate::Current(); | 602 Isolate* isolate = Isolate::Current(); |
631 CHECK_ISOLATE(isolate); | 603 CHECK_ISOLATE(isolate); |
632 isolate->set_message_notify_callback(message_notify_callback); | 604 isolate->set_message_notify_callback(message_notify_callback); |
633 } | 605 } |
634 | 606 |
635 | 607 |
636 DART_EXPORT Dart_Handle Dart_RunLoop() { | 608 DART_EXPORT Dart_Handle Dart_RunLoop() { |
637 Isolate* isolate = Isolate::Current(); | 609 Isolate* isolate = Isolate::Current(); |
638 DARTSCOPE(isolate); | 610 DARTSCOPE(isolate); |
639 | 611 const Object& obj = Object::Handle(isolate->StandardRunLoop()); |
640 LongJump* base = isolate->long_jump_base(); | 612 if (obj.IsError()) { |
641 LongJump jump; | 613 return Api::NewLocalHandle(obj); |
642 Dart_Handle result; | |
643 isolate->set_long_jump_base(&jump); | |
644 if (setjmp(*jump.Set()) == 0) { | |
645 const Object& obj = Object::Handle(isolate->StandardRunLoop()); | |
646 if (obj.IsError()) { | |
647 result = Api::NewLocalHandle(obj); | |
648 } else { | |
649 ASSERT(obj.IsNull()); | |
650 result = Api::Success(); | |
651 } | |
652 } else { | |
653 SetupErrorResult(&result); | |
654 } | 614 } |
655 isolate->set_long_jump_base(base); | 615 ASSERT(obj.IsNull()); |
656 return result; | 616 return Api::Success(); |
657 } | 617 } |
658 | 618 |
659 | 619 |
660 static RawInstance* DeserializeMessage(void* data) { | 620 static RawInstance* DeserializeMessage(void* data) { |
661 // Create a snapshot object using the buffer. | 621 // Create a snapshot object using the buffer. |
662 const Snapshot* snapshot = Snapshot::SetupFromBuffer(data); | 622 const Snapshot* snapshot = Snapshot::SetupFromBuffer(data); |
663 ASSERT(snapshot->IsMessageSnapshot()); | 623 ASSERT(snapshot->IsMessageSnapshot()); |
664 | 624 |
665 // Read object back from the snapshot. | 625 // Read object back from the snapshot. |
666 SnapshotReader reader(snapshot, Isolate::Current()); | 626 SnapshotReader reader(snapshot, Isolate::Current()); |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
786 // function resolution by class name and function name more concise. | 746 // function resolution by class name and function name more concise. |
787 const Function& function = Function::Handle( | 747 const Function& function = Function::Handle( |
788 Resolver::ResolveStatic(Library::Handle(Library::CoreLibrary()), | 748 Resolver::ResolveStatic(Library::Handle(Library::CoreLibrary()), |
789 class_name, | 749 class_name, |
790 function_name, | 750 function_name, |
791 kNumArguments, | 751 kNumArguments, |
792 kNoArgumentNames, | 752 kNoArgumentNames, |
793 Resolver::kIsQualified)); | 753 Resolver::kIsQualified)); |
794 GrowableArray<const Object*> arguments(kNumArguments); | 754 GrowableArray<const Object*> arguments(kNumArguments); |
795 arguments.Add(&Integer::Handle(Integer::New(port_id))); | 755 arguments.Add(&Integer::Handle(Integer::New(port_id))); |
796 Dart_Handle result; | 756 const Object& result = Object::Handle( |
797 InvokeStatic(isolate, function, arguments, &result); | 757 DartEntry::InvokeStatic(function, arguments, kNoArgumentNames)); |
798 return result; | 758 return Api::NewLocalHandle(result); |
799 } | 759 } |
800 | 760 |
801 | 761 |
802 DART_EXPORT Dart_Handle Dart_GetReceivePort(Dart_Port port_id) { | 762 DART_EXPORT Dart_Handle Dart_GetReceivePort(Dart_Port port_id) { |
803 Isolate* isolate = Isolate::Current(); | 763 Isolate* isolate = Isolate::Current(); |
804 DARTSCOPE(isolate); | 764 DARTSCOPE(isolate); |
805 const String& class_name = | 765 const String& class_name = |
806 String::Handle(String::NewSymbol("ReceivePortImpl")); | 766 String::Handle(String::NewSymbol("ReceivePortImpl")); |
807 const String& function_name = | 767 const String& function_name = |
808 String::Handle(String::NewSymbol("_get_or_create")); | 768 String::Handle(String::NewSymbol("_get_or_create")); |
809 const int kNumArguments = 1; | 769 const int kNumArguments = 1; |
810 const Array& kNoArgumentNames = Array::Handle(); | 770 const Array& kNoArgumentNames = Array::Handle(); |
811 const Function& function = Function::Handle( | 771 const Function& function = Function::Handle( |
812 Resolver::ResolveStatic(Library::Handle(Library::CoreLibrary()), | 772 Resolver::ResolveStatic(Library::Handle(Library::CoreLibrary()), |
813 class_name, | 773 class_name, |
814 function_name, | 774 function_name, |
815 kNumArguments, | 775 kNumArguments, |
816 kNoArgumentNames, | 776 kNoArgumentNames, |
817 Resolver::kIsQualified)); | 777 Resolver::kIsQualified)); |
818 GrowableArray<const Object*> arguments(kNumArguments); | 778 GrowableArray<const Object*> arguments(kNumArguments); |
819 arguments.Add(&Integer::Handle(Integer::New(port_id))); | 779 arguments.Add(&Integer::Handle(Integer::New(port_id))); |
820 Dart_Handle result; | 780 const Object& result = Object::Handle( |
821 InvokeStatic(isolate, function, arguments, &result); | 781 DartEntry::InvokeStatic(function, arguments, kNoArgumentNames)); |
822 return result; | 782 return Api::NewLocalHandle(result); |
823 } | 783 } |
824 | 784 |
825 | 785 |
826 DART_EXPORT Dart_Port Dart_GetMainPortId() { | 786 DART_EXPORT Dart_Port Dart_GetMainPortId() { |
827 Isolate* isolate = Isolate::Current(); | 787 Isolate* isolate = Isolate::Current(); |
828 CHECK_ISOLATE(isolate); | 788 CHECK_ISOLATE(isolate); |
829 return isolate->main_port(); | 789 return isolate->main_port(); |
830 } | 790 } |
831 | 791 |
832 // --- Scopes ---- | 792 // --- Scopes ---- |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
869 const Object& obj = Object::Handle(Api::UnwrapHandle(object)); | 829 const Object& obj = Object::Handle(Api::UnwrapHandle(object)); |
870 return obj.IsNull(); | 830 return obj.IsNull(); |
871 } | 831 } |
872 | 832 |
873 | 833 |
874 DART_EXPORT Dart_Handle Dart_ObjectEquals(Dart_Handle obj1, Dart_Handle obj2, | 834 DART_EXPORT Dart_Handle Dart_ObjectEquals(Dart_Handle obj1, Dart_Handle obj2, |
875 bool* value) { | 835 bool* value) { |
876 DARTSCOPE(Isolate::Current()); | 836 DARTSCOPE(Isolate::Current()); |
877 const Instance& expected = Instance::CheckedHandle(Api::UnwrapHandle(obj1)); | 837 const Instance& expected = Instance::CheckedHandle(Api::UnwrapHandle(obj1)); |
878 const Instance& actual = Instance::CheckedHandle(Api::UnwrapHandle(obj2)); | 838 const Instance& actual = Instance::CheckedHandle(Api::UnwrapHandle(obj2)); |
879 const Instance& result = | 839 const Object& result = |
880 Instance::Handle(DartLibraryCalls::Equals(expected, actual)); | 840 Object::Handle(DartLibraryCalls::Equals(expected, actual)); |
881 if (result.IsBool()) { | 841 if (result.IsBool()) { |
882 Bool& b = Bool::Handle(); | 842 Bool& b = Bool::Handle(); |
883 b ^= result.raw(); | 843 b ^= result.raw(); |
884 *value = b.value(); | 844 *value = b.value(); |
885 return Api::Success(); | 845 return Api::Success(); |
886 } else if (result.IsError()) { | 846 } else if (result.IsError()) { |
887 return Api::NewLocalHandle(result); | 847 return Api::NewLocalHandle(result); |
888 } else { | 848 } else { |
889 return Api::NewError("Expected boolean result from =="); | 849 return Api::NewError("Expected boolean result from =="); |
890 } | 850 } |
(...skipping 502 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1393 const Object& obj = Object::Handle(Api::UnwrapHandle(list)); | 1353 const Object& obj = Object::Handle(Api::UnwrapHandle(list)); |
1394 if (obj.IsArray()) { | 1354 if (obj.IsArray()) { |
1395 Array& array_obj = Array::Handle(); | 1355 Array& array_obj = Array::Handle(); |
1396 array_obj ^= obj.raw(); | 1356 array_obj ^= obj.raw(); |
1397 *len = array_obj.Length(); | 1357 *len = array_obj.Length(); |
1398 return Api::Success(); | 1358 return Api::Success(); |
1399 } | 1359 } |
1400 // TODO(5526318): Make access to GrowableObjectArray more efficient. | 1360 // TODO(5526318): Make access to GrowableObjectArray more efficient. |
1401 // Now check and handle a dart object that implements the List interface. | 1361 // Now check and handle a dart object that implements the List interface. |
1402 const Instance& instance = Instance::Handle(GetListInstance(isolate, obj)); | 1362 const Instance& instance = Instance::Handle(GetListInstance(isolate, obj)); |
1403 if (!instance.IsNull()) { | 1363 if (instance.IsNull()) { |
1404 String& name = String::Handle(String::New("length")); | 1364 return Api::NewError("Object does not implement the List inteface"); |
1405 name = Field::GetterName(name); | 1365 } |
1406 const Function& function = Function::Handle( | 1366 String& name = String::Handle(String::New("length")); |
1407 Resolver::ResolveDynamic(instance, name, 1, 0)); | 1367 name = Field::GetterName(name); |
1408 if (!function.IsNull()) { | 1368 const Function& function = Function::Handle( |
1409 GrowableArray<const Object*> args(0); | 1369 Resolver::ResolveDynamic(instance, name, 1, 0)); |
1410 LongJump* base = isolate->long_jump_base(); | 1370 if (function.IsNull()) { |
1411 LongJump jump; | 1371 return Api::NewError("List object does not have a 'length' field."); |
1412 isolate->set_long_jump_base(&jump); | 1372 } |
1413 Dart_Handle result; | 1373 |
1414 if (setjmp(*jump.Set()) == 0) { | 1374 GrowableArray<const Object*> args(0); |
1415 const Array& kNoArgumentNames = Array::Handle(); | 1375 Dart_Handle result; |
1416 const Instance& retval = Instance::Handle( | 1376 const Array& kNoArgumentNames = Array::Handle(); |
1417 DartEntry::InvokeDynamic(instance, | 1377 const Object& retval = Object::Handle( |
1418 function, | 1378 DartEntry::InvokeDynamic(instance, function, args, kNoArgumentNames)); |
1419 args, | 1379 if (retval.IsSmi() || retval.IsMint()) { |
1420 kNoArgumentNames)); | 1380 Integer& integer = Integer::Handle(); |
1421 result = Api::Success(); | 1381 integer ^= retval.raw(); |
1422 if (retval.IsSmi() || retval.IsMint()) { | 1382 *len = integer.AsInt64Value(); |
1423 Integer& integer = Integer::Handle(); | 1383 return Api::Success(); |
1424 integer ^= retval.raw(); | 1384 } else if (retval.IsBigint()) { |
1425 *len = integer.AsInt64Value(); | 1385 Bigint& bigint = Bigint::Handle(); |
1426 } else if (retval.IsBigint()) { | 1386 bigint ^= retval.raw(); |
1427 Bigint& bigint = Bigint::Handle(); | 1387 if (BigintOperations::FitsIntoInt64(bigint)) { |
1428 bigint ^= retval.raw(); | 1388 *len = BigintOperations::ToInt64(bigint); |
1429 if (BigintOperations::FitsIntoInt64(bigint)) { | 1389 return Api::Success(); |
1430 *len = BigintOperations::ToInt64(bigint); | 1390 } else { |
1431 } else { | 1391 return Api::NewError("Length of List object is greater than the " |
1432 result = | 1392 "maximum value that 'len' parameter can hold"); |
1433 Api::NewError("Length of List object is greater than the " | |
1434 "maximum value that 'len' parameter can hold"); | |
1435 } | |
1436 } else if (retval.IsError()) { | |
1437 result = Api::NewLocalHandle(retval); | |
1438 } else { | |
1439 result = Api::NewError("Length of List object is not an integer"); | |
1440 } | |
1441 } else { | |
1442 SetupErrorResult(&result); | |
1443 } | |
1444 isolate->set_long_jump_base(base); | |
1445 return result; | |
1446 } | 1393 } |
| 1394 } else if (retval.IsError()) { |
| 1395 return Api::NewLocalHandle(retval); |
| 1396 } else { |
| 1397 return Api::NewError("Length of List object is not an integer"); |
1447 } | 1398 } |
1448 return Api::NewError("Object does not implement the 'List' inteface"); | |
1449 } | 1399 } |
1450 | 1400 |
1451 | 1401 |
1452 static RawObject* GetListAt(Isolate* isolate, | |
1453 const Instance& instance, | |
1454 const Integer& index, | |
1455 const Function& function, | |
1456 Dart_Handle* result) { | |
1457 ASSERT(isolate != NULL); | |
1458 ASSERT(result != NULL); | |
1459 LongJump* base = isolate->long_jump_base(); | |
1460 LongJump jump; | |
1461 isolate->set_long_jump_base(&jump); | |
1462 if (setjmp(*jump.Set()) == 0) { | |
1463 Instance& retval = Instance::Handle(); | |
1464 GrowableArray<const Object*> args(0); | |
1465 args.Add(&index); | |
1466 const Array& kNoArgumentNames = Array::Handle(); | |
1467 retval = DartEntry::InvokeDynamic(instance, | |
1468 function, | |
1469 args, | |
1470 kNoArgumentNames); | |
1471 if (retval.IsError()) { | |
1472 *result = Api::NewLocalHandle(retval); | |
1473 } else { | |
1474 *result = Api::Success(); | |
1475 } | |
1476 isolate->set_long_jump_base(base); | |
1477 return retval.raw(); | |
1478 } | |
1479 SetupErrorResult(result); | |
1480 isolate->set_long_jump_base(base); | |
1481 return Object::null(); | |
1482 } | |
1483 | |
1484 | |
1485 DART_EXPORT Dart_Handle Dart_ListGetAt(Dart_Handle list, intptr_t index) { | 1402 DART_EXPORT Dart_Handle Dart_ListGetAt(Dart_Handle list, intptr_t index) { |
1486 Isolate* isolate = Isolate::Current(); | 1403 Isolate* isolate = Isolate::Current(); |
1487 DARTSCOPE(isolate); | 1404 DARTSCOPE(isolate); |
1488 const Object& obj = Object::Handle(Api::UnwrapHandle(list)); | 1405 const Object& obj = Object::Handle(Api::UnwrapHandle(list)); |
1489 if (obj.IsArray()) { | 1406 if (obj.IsArray()) { |
1490 Array& array_obj = Array::Handle(); | 1407 Array& array_obj = Array::Handle(); |
1491 array_obj ^= obj.raw(); | 1408 array_obj ^= obj.raw(); |
1492 if ((index >= 0) && (index < array_obj.Length())) { | 1409 if ((index >= 0) && (index < array_obj.Length())) { |
1493 const Object& element = Object::Handle(array_obj.At(index)); | 1410 const Object& element = Object::Handle(array_obj.At(index)); |
1494 return Api::NewLocalHandle(element); | 1411 return Api::NewLocalHandle(element); |
1495 } | 1412 } |
1496 return Api::NewError("Invalid index passed in to access array element"); | 1413 return Api::NewError("Invalid index passed in to access array element"); |
1497 } | 1414 } |
1498 // TODO(5526318): Make access to GrowableObjectArray more efficient. | 1415 // TODO(5526318): Make access to GrowableObjectArray more efficient. |
1499 // Now check and handle a dart object that implements the List interface. | 1416 // Now check and handle a dart object that implements the List interface. |
1500 const Instance& instance = Instance::Handle(GetListInstance(isolate, obj)); | 1417 const Instance& instance = Instance::Handle(GetListInstance(isolate, obj)); |
1501 if (!instance.IsNull()) { | 1418 if (!instance.IsNull()) { |
1502 String& name = String::Handle(String::New("[]")); | 1419 String& name = String::Handle(String::New("[]")); |
1503 const Function& function = Function::Handle( | 1420 const Function& function = Function::Handle( |
1504 Resolver::ResolveDynamic(instance, name, 2, 0)); | 1421 Resolver::ResolveDynamic(instance, name, 2, 0)); |
1505 if (!function.IsNull()) { | 1422 if (!function.IsNull()) { |
1506 Object& element = Object::Handle(); | 1423 GrowableArray<const Object*> args(1); |
1507 Integer& indexobj = Integer::Handle(); | 1424 Integer& indexobj = Integer::Handle(); |
1508 Dart_Handle result; | |
1509 indexobj = Integer::New(index); | 1425 indexobj = Integer::New(index); |
1510 element = GetListAt(isolate, instance, indexobj, function, &result); | 1426 args.Add(&indexobj); |
1511 if (::Dart_IsError(result)) { | 1427 const Array& kNoArgumentNames = Array::Handle(); |
1512 return result; // Error condition. | 1428 const Object& result = Object::Handle( |
1513 } | 1429 DartEntry::InvokeDynamic(instance, function, args, kNoArgumentNames)); |
1514 return Api::NewLocalHandle(element); | 1430 return Api::NewLocalHandle(result); |
1515 } | 1431 } |
1516 } | 1432 } |
1517 return Api::NewError("Object does not implement the 'List' interface"); | 1433 return Api::NewError("Object does not implement the 'List' interface"); |
1518 } | 1434 } |
1519 | 1435 |
1520 | 1436 |
1521 static void SetListAt(Isolate* isolate, | |
1522 const Instance& instance, | |
1523 const Integer& index, | |
1524 const Object& value, | |
1525 const Function& function, | |
1526 Dart_Handle* result) { | |
1527 ASSERT(isolate != NULL); | |
1528 ASSERT(result != NULL); | |
1529 LongJump* base = isolate->long_jump_base(); | |
1530 LongJump jump; | |
1531 isolate->set_long_jump_base(&jump); | |
1532 if (setjmp(*jump.Set()) == 0) { | |
1533 GrowableArray<const Object*> args(1); | |
1534 args.Add(&index); | |
1535 args.Add(&value); | |
1536 Instance& retval = Instance::Handle(); | |
1537 const Array& kNoArgumentNames = Array::Handle(); | |
1538 retval = DartEntry::InvokeDynamic(instance, | |
1539 function, | |
1540 args, | |
1541 kNoArgumentNames); | |
1542 if (retval.IsError()) { | |
1543 *result = Api::NewLocalHandle(retval); | |
1544 } else { | |
1545 *result = Api::Success(); | |
1546 } | |
1547 } else { | |
1548 SetupErrorResult(result); | |
1549 } | |
1550 isolate->set_long_jump_base(base); | |
1551 } | |
1552 | |
1553 | |
1554 DART_EXPORT Dart_Handle Dart_ListSetAt(Dart_Handle list, | 1437 DART_EXPORT Dart_Handle Dart_ListSetAt(Dart_Handle list, |
1555 intptr_t index, | 1438 intptr_t index, |
1556 Dart_Handle value) { | 1439 Dart_Handle value) { |
1557 Isolate* isolate = Isolate::Current(); | 1440 Isolate* isolate = Isolate::Current(); |
1558 DARTSCOPE(isolate); | 1441 DARTSCOPE(isolate); |
1559 const Object& obj = Object::Handle(Api::UnwrapHandle(list)); | 1442 const Object& obj = Object::Handle(Api::UnwrapHandle(list)); |
1560 if (obj.IsArray()) { | 1443 if (obj.IsArray()) { |
1561 if (obj.IsImmutableArray()) { | 1444 if (obj.IsImmutableArray()) { |
1562 return Api::NewError("Cannot modify immutable array"); | 1445 return Api::NewError("Cannot modify immutable array"); |
1563 } | 1446 } |
1564 Array& array_obj = Array::Handle(); | 1447 Array& array_obj = Array::Handle(); |
1565 array_obj ^= obj.raw(); | 1448 array_obj ^= obj.raw(); |
1566 const Object& value_obj = Object::Handle(Api::UnwrapHandle(value)); | 1449 const Object& value_obj = Object::Handle(Api::UnwrapHandle(value)); |
1567 if ((index >= 0) && (index < array_obj.Length())) { | 1450 if ((index >= 0) && (index < array_obj.Length())) { |
1568 array_obj.SetAt(index, value_obj); | 1451 array_obj.SetAt(index, value_obj); |
1569 return Api::Success(); | 1452 return Api::Success(); |
1570 } | 1453 } |
1571 return Api::NewError("Invalid index passed in to set array element"); | 1454 return Api::NewError("Invalid index passed in to set array element"); |
1572 } | 1455 } |
1573 // TODO(5526318): Make access to GrowableObjectArray more efficient. | 1456 // TODO(5526318): Make access to GrowableObjectArray more efficient. |
1574 // Now check and handle a dart object that implements the List interface. | 1457 // Now check and handle a dart object that implements the List interface. |
1575 const Instance& instance = Instance::Handle(GetListInstance(isolate, obj)); | 1458 const Instance& instance = Instance::Handle(GetListInstance(isolate, obj)); |
1576 if (!instance.IsNull()) { | 1459 if (!instance.IsNull()) { |
1577 String& name = String::Handle(String::New("[]=")); | 1460 String& name = String::Handle(String::New("[]=")); |
1578 const Function& function = Function::Handle( | 1461 const Function& function = Function::Handle( |
1579 Resolver::ResolveDynamic(instance, name, 3, 0)); | 1462 Resolver::ResolveDynamic(instance, name, 3, 0)); |
1580 if (!function.IsNull()) { | 1463 if (!function.IsNull()) { |
1581 Dart_Handle result; | |
1582 const Integer& index_obj = Integer::Handle(Integer::New(index)); | 1464 const Integer& index_obj = Integer::Handle(Integer::New(index)); |
1583 const Object& value_obj = Object::Handle(Api::UnwrapHandle(value)); | 1465 const Object& value_obj = Object::Handle(Api::UnwrapHandle(value)); |
1584 SetListAt(isolate, instance, index_obj, value_obj, function, &result); | 1466 GrowableArray<const Object*> args(2); |
1585 return result; | 1467 args.Add(&index_obj); |
| 1468 args.Add(&value_obj); |
| 1469 const Array& kNoArgumentNames = Array::Handle(); |
| 1470 const Object& result = Object::Handle( |
| 1471 DartEntry::InvokeDynamic(instance, function, args, kNoArgumentNames)); |
| 1472 return Api::NewLocalHandle(result); |
1586 } | 1473 } |
1587 } | 1474 } |
1588 return Api::NewError("Object does not implement the 'List' interface"); | 1475 return Api::NewError("Object does not implement the 'List' interface"); |
1589 } | 1476 } |
1590 | 1477 |
1591 | 1478 |
1592 DART_EXPORT Dart_Handle Dart_ListGetAsBytes(Dart_Handle list, | 1479 DART_EXPORT Dart_Handle Dart_ListGetAsBytes(Dart_Handle list, |
1593 intptr_t offset, | 1480 intptr_t offset, |
1594 uint8_t* native_array, | 1481 uint8_t* native_array, |
1595 intptr_t length) { | 1482 intptr_t length) { |
(...skipping 23 matching lines...) Expand all Loading... |
1619 return Api::NewError("Invalid length passed in to access array elements"); | 1506 return Api::NewError("Invalid length passed in to access array elements"); |
1620 } | 1507 } |
1621 // TODO(5526318): Make access to GrowableObjectArray more efficient. | 1508 // TODO(5526318): Make access to GrowableObjectArray more efficient. |
1622 // Now check and handle a dart object that implements the List interface. | 1509 // Now check and handle a dart object that implements the List interface. |
1623 const Instance& instance = Instance::Handle(GetListInstance(isolate, obj)); | 1510 const Instance& instance = Instance::Handle(GetListInstance(isolate, obj)); |
1624 if (!instance.IsNull()) { | 1511 if (!instance.IsNull()) { |
1625 String& name = String::Handle(String::New("[]")); | 1512 String& name = String::Handle(String::New("[]")); |
1626 const Function& function = Function::Handle( | 1513 const Function& function = Function::Handle( |
1627 Resolver::ResolveDynamic(instance, name, 2, 0)); | 1514 Resolver::ResolveDynamic(instance, name, 2, 0)); |
1628 if (!function.IsNull()) { | 1515 if (!function.IsNull()) { |
1629 Object& element = Object::Handle(); | 1516 Object& result = Object::Handle(); |
1630 Integer& intobj = Integer::Handle(); | 1517 Integer& intobj = Integer::Handle(); |
1631 Dart_Handle result; | |
1632 for (int i = 0; i < length; i++) { | 1518 for (int i = 0; i < length; i++) { |
1633 intobj = Integer::New(offset + i); | 1519 intobj = Integer::New(offset + i); |
1634 element = GetListAt(isolate, instance, intobj, function, &result); | 1520 GrowableArray<const Object*> args(1); |
1635 if (::Dart_IsError(result)) { | 1521 args.Add(&intobj); |
1636 return result; // Error condition. | 1522 const Array& kNoArgumentNames = Array::Handle(); |
| 1523 result = DartEntry::InvokeDynamic( |
| 1524 instance, function, args, kNoArgumentNames); |
| 1525 if (result.IsError()) { |
| 1526 return Api::NewLocalHandle(result); |
1637 } | 1527 } |
1638 if (!element.IsInteger()) { | 1528 if (!result.IsInteger()) { |
1639 return Api::NewError("%s expects the argument 'list' to be " | 1529 return Api::NewError("%s expects the argument 'list' to be " |
1640 "a List of int", CURRENT_FUNC); | 1530 "a List of int", CURRENT_FUNC); |
1641 } | 1531 } |
1642 intobj ^= element.raw(); | 1532 intobj ^= result.raw(); |
1643 ASSERT(intobj.AsInt64Value() <= 0xff); | 1533 ASSERT(intobj.AsInt64Value() <= 0xff); |
1644 // TODO(hpayer): value should always be smaller then 0xff. Add error | 1534 // TODO(hpayer): value should always be smaller then 0xff. Add error |
1645 // handling. | 1535 // handling. |
1646 native_array[i] = static_cast<uint8_t>(intobj.AsInt64Value() & 0xff); | 1536 native_array[i] = static_cast<uint8_t>(intobj.AsInt64Value() & 0xff); |
1647 } | 1537 } |
1648 return Api::Success(); | 1538 return Api::Success(); |
1649 } | 1539 } |
1650 } | 1540 } |
1651 return Api::NewError("Object does not implement the 'List' interface"); | 1541 return Api::NewError("Object does not implement the 'List' interface"); |
1652 } | 1542 } |
(...skipping 29 matching lines...) Expand all Loading... |
1682 String& name = String::Handle(String::New("[]=")); | 1572 String& name = String::Handle(String::New("[]=")); |
1683 const Function& function = Function::Handle( | 1573 const Function& function = Function::Handle( |
1684 Resolver::ResolveDynamic(instance, name, 3, 0)); | 1574 Resolver::ResolveDynamic(instance, name, 3, 0)); |
1685 if (!function.IsNull()) { | 1575 if (!function.IsNull()) { |
1686 Integer& indexobj = Integer::Handle(); | 1576 Integer& indexobj = Integer::Handle(); |
1687 Integer& valueobj = Integer::Handle(); | 1577 Integer& valueobj = Integer::Handle(); |
1688 Dart_Handle result; | 1578 Dart_Handle result; |
1689 for (int i = 0; i < length; i++) { | 1579 for (int i = 0; i < length; i++) { |
1690 indexobj = Integer::New(offset + i); | 1580 indexobj = Integer::New(offset + i); |
1691 valueobj = Integer::New(native_array[i]); | 1581 valueobj = Integer::New(native_array[i]); |
1692 SetListAt(isolate, instance, indexobj, valueobj, function, &result); | 1582 GrowableArray<const Object*> args(2); |
1693 if (::Dart_IsError(result)) { | 1583 args.Add(&indexobj); |
1694 return result; // Error condition. | 1584 args.Add(&valueobj); |
| 1585 const Array& kNoArgumentNames = Array::Handle(); |
| 1586 const Object& result = Object::Handle( |
| 1587 DartEntry::InvokeDynamic( |
| 1588 instance, function, args, kNoArgumentNames)); |
| 1589 if (result.IsError()) { |
| 1590 return Api::NewLocalHandle(result); |
1695 } | 1591 } |
1696 } | 1592 } |
1697 return Api::Success(); | 1593 return Api::Success(); |
1698 } | 1594 } |
1699 } | 1595 } |
1700 return Api::NewError("Object does not implement the 'List' interface"); | 1596 return Api::NewError("Object does not implement the 'List' interface"); |
1701 } | 1597 } |
1702 | 1598 |
1703 | 1599 |
1704 // --- Byte Arrays --- | 1600 // --- Byte Arrays --- |
(...skipping 17 matching lines...) Expand all Loading... |
1722 // --- Closures --- | 1618 // --- Closures --- |
1723 | 1619 |
1724 | 1620 |
1725 DART_EXPORT bool Dart_IsClosure(Dart_Handle object) { | 1621 DART_EXPORT bool Dart_IsClosure(Dart_Handle object) { |
1726 DARTSCOPE(Isolate::Current()); | 1622 DARTSCOPE(Isolate::Current()); |
1727 const Object& obj = Object::Handle(Api::UnwrapHandle(object)); | 1623 const Object& obj = Object::Handle(Api::UnwrapHandle(object)); |
1728 return obj.IsClosure(); | 1624 return obj.IsClosure(); |
1729 } | 1625 } |
1730 | 1626 |
1731 | 1627 |
1732 // NOTE: Need to pass 'result' as a parameter here in order to avoid | |
1733 // warning: variable 'result' might be clobbered by 'longjmp' or 'vfork' | |
1734 // which shows up because of the use of setjmp. | |
1735 static void InvokeClosure(Isolate* isolate, | |
1736 const Closure& closure, | |
1737 GrowableArray<const Object*>& args, | |
1738 Dart_Handle* result) { | |
1739 ASSERT(isolate != NULL); | |
1740 LongJump* base = isolate->long_jump_base(); | |
1741 LongJump jump; | |
1742 isolate->set_long_jump_base(&jump); | |
1743 if (setjmp(*jump.Set()) == 0) { | |
1744 const Array& kNoArgumentNames = Array::Handle(); | |
1745 const Instance& retval = Instance::Handle( | |
1746 DartEntry::InvokeClosure(closure, args, kNoArgumentNames)); | |
1747 *result = Api::NewLocalHandle(retval); | |
1748 } else { | |
1749 SetupErrorResult(result); | |
1750 } | |
1751 isolate->set_long_jump_base(base); | |
1752 } | |
1753 | |
1754 | |
1755 DART_EXPORT Dart_Handle Dart_InvokeClosure(Dart_Handle closure, | 1628 DART_EXPORT Dart_Handle Dart_InvokeClosure(Dart_Handle closure, |
1756 int number_of_arguments, | 1629 int number_of_arguments, |
1757 Dart_Handle* arguments) { | 1630 Dart_Handle* arguments) { |
1758 Isolate* isolate = Isolate::Current(); | 1631 Isolate* isolate = Isolate::Current(); |
1759 DARTSCOPE(isolate); | 1632 DARTSCOPE(isolate); |
1760 const Object& obj = Object::Handle(Api::UnwrapHandle(closure)); | 1633 const Object& obj = Object::Handle(Api::UnwrapHandle(closure)); |
1761 if (obj.IsNull()) { | 1634 if (obj.IsNull()) { |
1762 return Api::NewError("Null object passed in to invoke closure"); | 1635 return Api::NewError("Null object passed in to invoke closure"); |
1763 } | 1636 } |
1764 if (!obj.IsClosure()) { | 1637 if (!obj.IsClosure()) { |
1765 return Api::NewError("Invalid closure passed to invoke closure"); | 1638 return Api::NewError("Invalid closure passed to invoke closure"); |
1766 } | 1639 } |
1767 ASSERT(ClassFinalizer::AllClassesFinalized()); | 1640 ASSERT(ClassFinalizer::AllClassesFinalized()); |
1768 | 1641 |
1769 // Now try to invoke the closure. | 1642 // Now try to invoke the closure. |
1770 Closure& closure_obj = Closure::Handle(); | 1643 Closure& closure_obj = Closure::Handle(); |
1771 closure_obj ^= obj.raw(); | 1644 closure_obj ^= obj.raw(); |
1772 Dart_Handle retval; | |
1773 GrowableArray<const Object*> dart_arguments(number_of_arguments); | 1645 GrowableArray<const Object*> dart_arguments(number_of_arguments); |
1774 for (int i = 0; i < number_of_arguments; i++) { | 1646 for (int i = 0; i < number_of_arguments; i++) { |
1775 const Object& arg = Object::Handle(Api::UnwrapHandle(arguments[i])); | 1647 const Object& arg = Object::Handle(Api::UnwrapHandle(arguments[i])); |
1776 dart_arguments.Add(&arg); | 1648 dart_arguments.Add(&arg); |
1777 } | 1649 } |
1778 InvokeClosure(isolate, closure_obj, dart_arguments, &retval); | 1650 const Array& kNoArgumentNames = Array::Handle(); |
1779 return retval; | 1651 const Object& result = Object::Handle( |
| 1652 DartEntry::InvokeClosure(closure_obj, dart_arguments, kNoArgumentNames)); |
| 1653 return Api::NewLocalHandle(result); |
1780 } | 1654 } |
1781 | 1655 |
1782 | 1656 |
1783 DART_EXPORT int64_t Dart_ClosureSmrck(Dart_Handle object) { | 1657 DART_EXPORT int64_t Dart_ClosureSmrck(Dart_Handle object) { |
1784 DARTSCOPE(Isolate::Current()); | 1658 DARTSCOPE(Isolate::Current()); |
1785 const Closure& obj = Closure::CheckedHandle(Api::UnwrapHandle(object)); | 1659 const Closure& obj = Closure::CheckedHandle(Api::UnwrapHandle(object)); |
1786 const Integer& smrck = Integer::Handle(obj.smrck()); | 1660 const Integer& smrck = Integer::Handle(obj.smrck()); |
1787 return smrck.IsNull() ? 0 : smrck.AsInt64Value(); | 1661 return smrck.IsNull() ? 0 : smrck.AsInt64Value(); |
1788 } | 1662 } |
1789 | 1663 |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1847 class_name.ToCString(), function_name.ToCString()); | 1721 class_name.ToCString(), function_name.ToCString()); |
1848 } | 1722 } |
1849 return Api::NewError(msg); | 1723 return Api::NewError(msg); |
1850 } | 1724 } |
1851 Dart_Handle retval; | 1725 Dart_Handle retval; |
1852 GrowableArray<const Object*> dart_arguments(number_of_arguments); | 1726 GrowableArray<const Object*> dart_arguments(number_of_arguments); |
1853 for (int i = 0; i < number_of_arguments; i++) { | 1727 for (int i = 0; i < number_of_arguments; i++) { |
1854 const Object& arg = Object::Handle(Api::UnwrapHandle(arguments[i])); | 1728 const Object& arg = Object::Handle(Api::UnwrapHandle(arguments[i])); |
1855 dart_arguments.Add(&arg); | 1729 dart_arguments.Add(&arg); |
1856 } | 1730 } |
1857 InvokeStatic(isolate, function, dart_arguments, &retval); | 1731 const Array& kNoArgumentNames = Array::Handle(); |
1858 return retval; | 1732 const Object& result = Object::Handle( |
| 1733 DartEntry::InvokeStatic(function, dart_arguments, kNoArgumentNames)); |
| 1734 return Api::NewLocalHandle(result); |
1859 } | 1735 } |
1860 | 1736 |
1861 | 1737 |
1862 DART_EXPORT Dart_Handle Dart_InvokeDynamic(Dart_Handle object, | 1738 DART_EXPORT Dart_Handle Dart_InvokeDynamic(Dart_Handle object, |
1863 Dart_Handle function_name, | 1739 Dart_Handle function_name, |
1864 int number_of_arguments, | 1740 int number_of_arguments, |
1865 Dart_Handle* arguments) { | 1741 Dart_Handle* arguments) { |
1866 Isolate* isolate = Isolate::Current(); | 1742 Isolate* isolate = Isolate::Current(); |
1867 DARTSCOPE(isolate); | 1743 DARTSCOPE(isolate); |
1868 const Object& obj = Object::Handle(Api::UnwrapHandle(object)); | 1744 const Object& obj = Object::Handle(Api::UnwrapHandle(object)); |
(...skipping 21 matching lines...) Expand all Loading... |
1890 // TODO(5415268): Invoke noSuchMethod instead of failing. | 1766 // TODO(5415268): Invoke noSuchMethod instead of failing. |
1891 OS::PrintErr("Unable to find instance function: %s\n", name.ToCString()); | 1767 OS::PrintErr("Unable to find instance function: %s\n", name.ToCString()); |
1892 return Api::NewError("Unable to find instance function"); | 1768 return Api::NewError("Unable to find instance function"); |
1893 } | 1769 } |
1894 Dart_Handle retval; | 1770 Dart_Handle retval; |
1895 GrowableArray<const Object*> dart_arguments(number_of_arguments); | 1771 GrowableArray<const Object*> dart_arguments(number_of_arguments); |
1896 for (int i = 0; i < number_of_arguments; i++) { | 1772 for (int i = 0; i < number_of_arguments; i++) { |
1897 const Object& arg = Object::Handle(Api::UnwrapHandle(arguments[i])); | 1773 const Object& arg = Object::Handle(Api::UnwrapHandle(arguments[i])); |
1898 dart_arguments.Add(&arg); | 1774 dart_arguments.Add(&arg); |
1899 } | 1775 } |
1900 InvokeDynamic(isolate, receiver, function, dart_arguments, &retval); | 1776 const Array& kNoArgumentNames = Array::Handle(); |
1901 return retval; | 1777 const Object& result = Object::Handle( |
| 1778 DartEntry::InvokeDynamic( |
| 1779 receiver, function, dart_arguments, kNoArgumentNames)); |
| 1780 return Api::NewLocalHandle(result); |
1902 } | 1781 } |
1903 | 1782 |
1904 | 1783 |
1905 static const bool kGetter = true; | 1784 static const bool kGetter = true; |
1906 static const bool kSetter = false; | 1785 static const bool kSetter = false; |
1907 | 1786 |
1908 | 1787 |
1909 static bool UseGetterForStaticField(const Field& fld) { | 1788 static bool UseGetterForStaticField(const Field& fld) { |
1910 if (fld.IsNull()) { | 1789 if (fld.IsNull()) { |
1911 return true; | 1790 return true; |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1998 const Object& obj = Object::Handle(Api::UnwrapHandle(result)); | 1877 const Object& obj = Object::Handle(Api::UnwrapHandle(result)); |
1999 if (obj.IsField()) { | 1878 if (obj.IsField()) { |
2000 Field& fld = Field::Handle(); | 1879 Field& fld = Field::Handle(); |
2001 fld ^= obj.raw(); | 1880 fld ^= obj.raw(); |
2002 retval = fld.value(); | 1881 retval = fld.value(); |
2003 return Api::NewLocalHandle(retval); | 1882 return Api::NewLocalHandle(retval); |
2004 } else { | 1883 } else { |
2005 Function& func = Function::Handle(); | 1884 Function& func = Function::Handle(); |
2006 func ^= obj.raw(); | 1885 func ^= obj.raw(); |
2007 GrowableArray<const Object*> args; | 1886 GrowableArray<const Object*> args; |
2008 InvokeStatic(isolate, func, args, &result); | 1887 const Array& kNoArgumentNames = Array::Handle(); |
2009 return result; | 1888 const Object& result = Object::Handle( |
| 1889 DartEntry::InvokeStatic(func, args, kNoArgumentNames)); |
| 1890 return Api::NewLocalHandle(result); |
2010 } | 1891 } |
2011 } | 1892 } |
2012 | 1893 |
2013 | 1894 |
2014 // TODO(iposva): The value parameter should be documented as being an instance. | 1895 // TODO(iposva): The value parameter should be documented as being an instance. |
2015 // TODO(turnidge): Is this skipping the setter? | 1896 // TODO(turnidge): Is this skipping the setter? |
2016 DART_EXPORT Dart_Handle Dart_SetStaticField(Dart_Handle cls, | 1897 DART_EXPORT Dart_Handle Dart_SetStaticField(Dart_Handle cls, |
2017 Dart_Handle name, | 1898 Dart_Handle name, |
2018 Dart_Handle value) { | 1899 Dart_Handle value) { |
2019 DARTSCOPE(Isolate::Current()); | 1900 DARTSCOPE(Isolate::Current()); |
(...skipping 25 matching lines...) Expand all Loading... |
2045 } | 1926 } |
2046 Instance& object = Instance::Handle(); | 1927 Instance& object = Instance::Handle(); |
2047 object ^= param.raw(); | 1928 object ^= param.raw(); |
2048 Dart_Handle result = LookupInstanceField(object, name, kGetter); | 1929 Dart_Handle result = LookupInstanceField(object, name, kGetter); |
2049 if (::Dart_IsError(result)) { | 1930 if (::Dart_IsError(result)) { |
2050 return result; | 1931 return result; |
2051 } | 1932 } |
2052 Function& func = Function::Handle(); | 1933 Function& func = Function::Handle(); |
2053 func ^= Api::UnwrapHandle(result); | 1934 func ^= Api::UnwrapHandle(result); |
2054 GrowableArray<const Object*> arguments; | 1935 GrowableArray<const Object*> arguments; |
2055 InvokeDynamic(isolate, object, func, arguments, &result); | 1936 const Array& kNoArgumentNames = Array::Handle(); |
2056 return result; | 1937 const Object& retval = Object::Handle( |
| 1938 DartEntry::InvokeDynamic(object, func, arguments, kNoArgumentNames)); |
| 1939 return Api::NewLocalHandle(retval); |
2057 } | 1940 } |
2058 | 1941 |
2059 | 1942 |
2060 DART_EXPORT Dart_Handle Dart_SetInstanceField(Dart_Handle obj, | 1943 DART_EXPORT Dart_Handle Dart_SetInstanceField(Dart_Handle obj, |
2061 Dart_Handle name, | 1944 Dart_Handle name, |
2062 Dart_Handle value) { | 1945 Dart_Handle value) { |
2063 Isolate* isolate = Isolate::Current(); | 1946 Isolate* isolate = Isolate::Current(); |
2064 DARTSCOPE(isolate); | 1947 DARTSCOPE(isolate); |
2065 const Object& param = Object::Handle(Api::UnwrapHandle(obj)); | 1948 const Object& param = Object::Handle(Api::UnwrapHandle(obj)); |
2066 if (param.IsNull() || !param.IsInstance()) { | 1949 if (param.IsNull() || !param.IsInstance()) { |
2067 return Api::NewError("Invalid object passed in to access instance field"); | 1950 return Api::NewError("Invalid object passed in to access instance field"); |
2068 } | 1951 } |
2069 Instance& object = Instance::Handle(); | 1952 Instance& object = Instance::Handle(); |
2070 object ^= param.raw(); | 1953 object ^= param.raw(); |
2071 Dart_Handle result = LookupInstanceField(object, name, kSetter); | 1954 Dart_Handle result = LookupInstanceField(object, name, kSetter); |
2072 if (::Dart_IsError(result)) { | 1955 if (::Dart_IsError(result)) { |
2073 return result; | 1956 return result; |
2074 } | 1957 } |
2075 Function& func = Function::Handle(); | 1958 Function& func = Function::Handle(); |
2076 func ^= Api::UnwrapHandle(result); | 1959 func ^= Api::UnwrapHandle(result); |
2077 GrowableArray<const Object*> arguments(1); | 1960 GrowableArray<const Object*> arguments(1); |
2078 const Object& arg = Object::Handle(Api::UnwrapHandle(value)); | 1961 const Object& arg = Object::Handle(Api::UnwrapHandle(value)); |
2079 arguments.Add(&arg); | 1962 arguments.Add(&arg); |
2080 InvokeDynamic(isolate, object, func, arguments, &result); | 1963 const Array& kNoArgumentNames = Array::Handle(); |
2081 return result; | 1964 const Object& retval = Object::Handle( |
| 1965 DartEntry::InvokeDynamic(object, func, arguments, kNoArgumentNames)); |
| 1966 return Api::NewLocalHandle(retval); |
2082 } | 1967 } |
2083 | 1968 |
2084 | 1969 |
2085 DART_EXPORT Dart_Handle Dart_CreateNativeWrapperClass(Dart_Handle library, | 1970 DART_EXPORT Dart_Handle Dart_CreateNativeWrapperClass(Dart_Handle library, |
2086 Dart_Handle name, | 1971 Dart_Handle name, |
2087 int field_count) { | 1972 int field_count) { |
2088 Isolate* isolate = Isolate::Current(); | 1973 Isolate* isolate = Isolate::Current(); |
2089 DARTSCOPE(isolate); | 1974 DARTSCOPE(isolate); |
2090 const Object& param = Object::Handle(Api::UnwrapHandle(name)); | 1975 const Object& param = Object::Handle(Api::UnwrapHandle(name)); |
2091 if (param.IsNull() || !param.IsString() || field_count <= 0) { | 1976 if (param.IsNull() || !param.IsString() || field_count <= 0) { |
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2235 const String& source, | 2120 const String& source, |
2236 RawScript::Kind kind, | 2121 RawScript::Kind kind, |
2237 Dart_Handle* result) { | 2122 Dart_Handle* result) { |
2238 bool update_lib_status = (kind == RawScript::kScript || | 2123 bool update_lib_status = (kind == RawScript::kScript || |
2239 kind == RawScript::kLibrary); | 2124 kind == RawScript::kLibrary); |
2240 if (update_lib_status) { | 2125 if (update_lib_status) { |
2241 lib.SetLoadInProgress(); | 2126 lib.SetLoadInProgress(); |
2242 } | 2127 } |
2243 const Script& script = Script::Handle(Script::New(url, source, kind)); | 2128 const Script& script = Script::Handle(Script::New(url, source, kind)); |
2244 ASSERT(isolate != NULL); | 2129 ASSERT(isolate != NULL); |
2245 LongJump* base = isolate->long_jump_base(); | 2130 const Error& error = Error::Handle(Compiler::Compile(lib, script)); |
2246 LongJump jump; | 2131 if (error.IsNull()) { |
2247 isolate->set_long_jump_base(&jump); | |
2248 if (setjmp(*jump.Set()) == 0) { | |
2249 Compiler::Compile(lib, script); | |
2250 *result = Api::NewLocalHandle(lib); | 2132 *result = Api::NewLocalHandle(lib); |
2251 if (update_lib_status) { | 2133 if (update_lib_status) { |
2252 lib.SetLoaded(); | 2134 lib.SetLoaded(); |
2253 } | 2135 } |
2254 } else { | 2136 } else { |
2255 SetupErrorResult(result); | 2137 *result = Api::NewLocalHandle(error); |
2256 if (update_lib_status) { | 2138 if (update_lib_status) { |
2257 lib.SetLoadError(); | 2139 lib.SetLoadError(); |
2258 } | 2140 } |
2259 } | 2141 } |
2260 isolate->set_long_jump_base(base); | |
2261 } | 2142 } |
2262 | 2143 |
2263 | 2144 |
2264 DART_EXPORT Dart_Handle Dart_LoadScript(Dart_Handle url, | 2145 DART_EXPORT Dart_Handle Dart_LoadScript(Dart_Handle url, |
2265 Dart_Handle source, | 2146 Dart_Handle source, |
2266 Dart_LibraryTagHandler handler) { | 2147 Dart_LibraryTagHandler handler) { |
2267 TIMERSCOPE(time_script_loading); | 2148 TIMERSCOPE(time_script_loading); |
2268 Isolate* isolate = Isolate::Current(); | 2149 Isolate* isolate = Isolate::Current(); |
2269 DARTSCOPE(isolate); | 2150 DARTSCOPE(isolate); |
2270 const String& url_str = Api::UnwrapStringHandle(url); | 2151 const String& url_str = Api::UnwrapStringHandle(url); |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2322 CURRENT_FUNC); | 2203 CURRENT_FUNC); |
2323 } | 2204 } |
2324 library ^= tmp.raw(); | 2205 library ^= tmp.raw(); |
2325 library.Register(); | 2206 library.Register(); |
2326 isolate->object_store()->set_root_library(library); | 2207 isolate->object_store()->set_root_library(library); |
2327 return Api::NewLocalHandle(library); | 2208 return Api::NewLocalHandle(library); |
2328 } | 2209 } |
2329 | 2210 |
2330 | 2211 |
2331 static void CompileAll(Isolate* isolate, Dart_Handle* result) { | 2212 static void CompileAll(Isolate* isolate, Dart_Handle* result) { |
2332 *result = Api::Success(); | |
2333 ASSERT(isolate != NULL); | 2213 ASSERT(isolate != NULL); |
2334 LongJump* base = isolate->long_jump_base(); | 2214 const Error& error = Error::Handle(Library::CompileAll()); |
2335 LongJump jump; | 2215 if (error.IsNull()) { |
2336 isolate->set_long_jump_base(&jump); | 2216 *result = Api::Success(); |
2337 if (setjmp(*jump.Set()) == 0) { | |
2338 Library::CompileAll(); | |
2339 } else { | 2217 } else { |
2340 SetupErrorResult(result); | 2218 *result = Api::NewLocalHandle(error); |
2341 } | 2219 } |
2342 isolate->set_long_jump_base(base); | |
2343 } | 2220 } |
2344 | 2221 |
2345 | 2222 |
2346 DART_EXPORT Dart_Handle Dart_CompileAll() { | 2223 DART_EXPORT Dart_Handle Dart_CompileAll() { |
2347 Isolate* isolate = Isolate::Current(); | 2224 Isolate* isolate = Isolate::Current(); |
2348 DARTSCOPE(isolate); | 2225 DARTSCOPE(isolate); |
2349 Dart_Handle result; | 2226 Dart_Handle result; |
2350 const char* msg = CheckIsolateState(isolate); | 2227 const char* msg = CheckIsolateState(isolate); |
2351 if (msg != NULL) { | 2228 if (msg != NULL) { |
2352 return Api::NewError(msg); | 2229 return Api::NewError(msg); |
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2524 } | 2401 } |
2525 delete debug_region; | 2402 delete debug_region; |
2526 } else { | 2403 } else { |
2527 *buffer = NULL; | 2404 *buffer = NULL; |
2528 *buffer_size = 0; | 2405 *buffer_size = 0; |
2529 } | 2406 } |
2530 } | 2407 } |
2531 | 2408 |
2532 | 2409 |
2533 } // namespace dart | 2410 } // namespace dart |
OLD | NEW |