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/native_entry.h" | 17 #include "vm/native_entry.h" |
19 #include "vm/object.h" | 18 #include "vm/object.h" |
20 #include "vm/object_store.h" | 19 #include "vm/object_store.h" |
21 #include "vm/port.h" | 20 #include "vm/port.h" |
22 #include "vm/resolver.h" | 21 #include "vm/resolver.h" |
23 #include "vm/snapshot.h" | 22 #include "vm/snapshot.h" |
24 #include "vm/stack_frame.h" | 23 #include "vm/stack_frame.h" |
25 #include "vm/timer.h" | 24 #include "vm/timer.h" |
26 #include "vm/verifier.h" | 25 #include "vm/verifier.h" |
27 | 26 |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
78 } | 77 } |
79 | 78 |
80 | 79 |
81 void SetupErrorResult(Dart_Handle* handle) { | 80 void SetupErrorResult(Dart_Handle* handle) { |
82 const Error& error = Error::Handle( | 81 const Error& error = Error::Handle( |
83 Isolate::Current()->object_store()->sticky_error()); | 82 Isolate::Current()->object_store()->sticky_error()); |
84 *handle = Api::NewLocalHandle(error); | 83 *handle = Api::NewLocalHandle(error); |
85 } | 84 } |
86 | 85 |
87 | 86 |
88 // NOTE: Need to pass 'result' as a parameter here in order to avoid | |
89 // warning: variable 'result' might be clobbered by 'longjmp' or 'vfork' | |
90 // which shows up because of the use of setjmp. | |
91 static void InvokeStatic(Isolate* isolate, | |
92 const Function& function, | |
93 GrowableArray<const Object*>& args, | |
94 Dart_Handle* result) { | |
95 ASSERT(isolate != NULL); | |
96 LongJump* base = isolate->long_jump_base(); | |
97 LongJump jump; | |
98 isolate->set_long_jump_base(&jump); | |
99 if (setjmp(*jump.Set()) == 0) { | |
100 const Array& kNoArgumentNames = Array::Handle(); | |
101 const Instance& retval = Instance::Handle( | |
102 DartEntry::InvokeStatic(function, args, kNoArgumentNames)); | |
103 *result = Api::NewLocalHandle(retval); | |
104 } else { | |
105 SetupErrorResult(result); | |
106 } | |
107 isolate->set_long_jump_base(base); | |
108 } | |
109 | |
110 | |
111 // NOTE: Need to pass 'result' as a parameter here in order to avoid | |
112 // warning: variable 'result' might be clobbered by 'longjmp' or 'vfork' | |
113 // which shows up because of the use of setjmp. | |
114 static void InvokeDynamic(Isolate* isolate, | |
115 const Instance& receiver, | |
116 const Function& function, | |
117 GrowableArray<const Object*>& args, | |
118 Dart_Handle* result) { | |
119 ASSERT(isolate != NULL); | |
120 LongJump* base = isolate->long_jump_base(); | |
121 LongJump jump; | |
122 isolate->set_long_jump_base(&jump); | |
123 if (setjmp(*jump.Set()) == 0) { | |
124 const Array& kNoArgumentNames = Array::Handle(); | |
125 const Instance& retval = Instance::Handle( | |
126 DartEntry::InvokeDynamic(receiver, function, args, kNoArgumentNames)); | |
127 *result = Api::NewLocalHandle(retval); | |
128 } else { | |
129 SetupErrorResult(result); | |
130 } | |
131 isolate->set_long_jump_base(base); | |
132 } | |
133 | |
134 | |
135 Dart_Handle Api::NewLocalHandle(const Object& object) { | 87 Dart_Handle Api::NewLocalHandle(const Object& object) { |
136 Isolate* isolate = Isolate::Current(); | 88 Isolate* isolate = Isolate::Current(); |
137 ASSERT(isolate != NULL); | 89 ASSERT(isolate != NULL); |
138 ApiState* state = isolate->api_state(); | 90 ApiState* state = isolate->api_state(); |
139 ASSERT(state != NULL); | 91 ASSERT(state != NULL); |
140 ApiLocalScope* scope = state->top_scope(); | 92 ApiLocalScope* scope = state->top_scope(); |
141 ASSERT(scope != NULL); | 93 ASSERT(scope != NULL); |
142 LocalHandles* local_handles = scope->local_handles(); | 94 LocalHandles* local_handles = scope->local_handles(); |
143 ASSERT(local_handles != NULL); | 95 ASSERT(local_handles != NULL); |
144 LocalHandle* ref = local_handles->AllocateHandle(); | 96 LocalHandle* ref = local_handles->AllocateHandle(); |
(...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
369 va_start(args2, format); | 321 va_start(args2, format); |
370 OS::VSNPrint(buffer, (len + 1), format, args2); | 322 OS::VSNPrint(buffer, (len + 1), format, args2); |
371 va_end(args2); | 323 va_end(args2); |
372 | 324 |
373 const String& message = String::Handle(String::New(buffer)); | 325 const String& message = String::Handle(String::New(buffer)); |
374 const Object& obj = Object::Handle(ApiError::New(message)); | 326 const Object& obj = Object::Handle(ApiError::New(message)); |
375 return Api::NewLocalHandle(obj); | 327 return Api::NewLocalHandle(obj); |
376 } | 328 } |
377 | 329 |
378 | 330 |
331 DART_EXPORT Dart_Handle Dart_PropagateError(Dart_Handle handle) { | |
332 Isolate* isolate = Isolate::Current(); | |
333 CHECK_ISOLATE(isolate); | |
334 const Object& obj = Object::Handle(Api::UnwrapHandle(handle)); | |
335 if (!obj.IsError()) { | |
336 return Api::NewError( | |
337 "%s expects argument 'handle' to be an error handle. " | |
338 "Did you forget to check Dart_IsError first?", | |
339 CURRENT_FUNC); | |
340 } | |
341 if (isolate->top_exit_frame_info() == 0) { | |
342 // There are no dart frames on the stack so it would be illegal to | |
343 // propagate an error here. | |
344 return Api::NewError("No Dart frames on stack, cannot propagate error."); | |
345 } | |
346 | |
347 // Unwind all the API scopes till the exit frame before propagating. | |
348 ApiState* state = isolate->api_state(); | |
349 ASSERT(state != NULL); | |
350 state->UnwindScopes(isolate->top_exit_frame_info()); | |
351 | |
352 Error& error = Error::Handle(); | |
353 error ^= obj.raw(); | |
354 Exceptions::PropagateError(error); | |
355 UNREACHABLE(); | |
356 | |
357 return Api::NewError("Cannot reach here. Internal error."); | |
358 } | |
359 | |
360 | |
379 DART_EXPORT void _Dart_ReportErrorHandle(const char* file, | 361 DART_EXPORT void _Dart_ReportErrorHandle(const char* file, |
380 int line, | 362 int line, |
381 const char* handle, | 363 const char* handle, |
382 const char* message) { | 364 const char* message) { |
383 fprintf(stderr, "%s:%d: error handle: '%s':\n '%s'\n", | 365 fprintf(stderr, "%s:%d: error handle: '%s':\n '%s'\n", |
384 file, line, handle, message); | 366 file, line, handle, message); |
385 OS::Abort(); | 367 OS::Abort(); |
386 } | 368 } |
387 | 369 |
388 | 370 |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
496 | 478 |
497 // --- Isolates --- | 479 // --- Isolates --- |
498 | 480 |
499 | 481 |
500 DART_EXPORT Dart_Isolate Dart_CreateIsolate(const char* name_prefix, | 482 DART_EXPORT Dart_Isolate Dart_CreateIsolate(const char* name_prefix, |
501 const uint8_t* snapshot, | 483 const uint8_t* snapshot, |
502 void* callback_data, | 484 void* callback_data, |
503 char** error) { | 485 char** error) { |
504 Isolate* isolate = Dart::CreateIsolate(name_prefix); | 486 Isolate* isolate = Dart::CreateIsolate(name_prefix); |
505 assert(isolate != NULL); | 487 assert(isolate != NULL); |
506 LongJump* base = isolate->long_jump_base(); | 488 DARTSCOPE_NOCHECKS(isolate); |
507 LongJump jump; | 489 const Error& error_obj = |
508 isolate->set_long_jump_base(&jump); | 490 Error::Handle(Dart::InitializeIsolate(snapshot, callback_data)); |
509 if (setjmp(*jump.Set()) == 0) { | 491 if (error_obj.IsNull()) { |
510 Dart::InitializeIsolate(snapshot, callback_data); | |
511 START_TIMER(time_total_runtime); | 492 START_TIMER(time_total_runtime); |
512 isolate->set_long_jump_base(base); | |
513 return reinterpret_cast<Dart_Isolate>(isolate); | 493 return reinterpret_cast<Dart_Isolate>(isolate); |
514 } else { | 494 } else { |
515 { | 495 *error = strdup(error_obj.ToErrorCString()); |
516 DARTSCOPE_NOCHECKS(isolate); | |
517 const Error& error_obj = | |
518 Error::Handle(isolate->object_store()->sticky_error()); | |
519 *error = strdup(error_obj.ToErrorCString()); | |
520 } | |
521 Dart::ShutdownIsolate(); | 496 Dart::ShutdownIsolate(); |
497 return reinterpret_cast<Dart_Isolate>(NULL); | |
522 } | 498 } |
523 return reinterpret_cast<Dart_Isolate>(NULL); | |
524 } | 499 } |
525 | 500 |
526 | 501 |
527 DART_EXPORT void Dart_ShutdownIsolate() { | 502 DART_EXPORT void Dart_ShutdownIsolate() { |
528 CHECK_ISOLATE(Isolate::Current()); | 503 CHECK_ISOLATE(Isolate::Current()); |
529 STOP_TIMER(time_total_runtime); | 504 STOP_TIMER(time_total_runtime); |
530 Dart::ShutdownIsolate(); | 505 Dart::ShutdownIsolate(); |
531 } | 506 } |
532 | 507 |
533 | 508 |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
636 ASSERT(post_message_callback != NULL); | 611 ASSERT(post_message_callback != NULL); |
637 ASSERT(close_port_callback != NULL); | 612 ASSERT(close_port_callback != NULL); |
638 isolate->set_post_message_callback(post_message_callback); | 613 isolate->set_post_message_callback(post_message_callback); |
639 isolate->set_close_port_callback(close_port_callback); | 614 isolate->set_close_port_callback(close_port_callback); |
640 } | 615 } |
641 | 616 |
642 | 617 |
643 DART_EXPORT Dart_Handle Dart_RunLoop() { | 618 DART_EXPORT Dart_Handle Dart_RunLoop() { |
644 Isolate* isolate = Isolate::Current(); | 619 Isolate* isolate = Isolate::Current(); |
645 DARTSCOPE(isolate); | 620 DARTSCOPE(isolate); |
646 | 621 const Object& obj = Object::Handle(isolate->StandardRunLoop()); |
647 LongJump* base = isolate->long_jump_base(); | 622 if (obj.IsError()) { |
648 LongJump jump; | 623 return Api::NewLocalHandle(obj); |
649 Dart_Handle result; | |
650 isolate->set_long_jump_base(&jump); | |
651 if (setjmp(*jump.Set()) == 0) { | |
652 const Object& obj = Object::Handle(isolate->StandardRunLoop()); | |
653 if (obj.IsError()) { | |
654 result = Api::NewLocalHandle(obj); | |
655 } else { | |
656 ASSERT(obj.IsNull()); | |
657 result = Api::Success(); | |
658 } | |
659 } else { | |
660 SetupErrorResult(&result); | |
661 } | 624 } |
662 isolate->set_long_jump_base(base); | 625 ASSERT(obj.IsNull()); |
663 return result; | 626 return Api::Success(); |
664 } | 627 } |
665 | 628 |
666 | 629 |
667 static RawInstance* DeserializeMessage(void* data) { | 630 static RawInstance* DeserializeMessage(void* data) { |
668 // Create a snapshot object using the buffer. | 631 // Create a snapshot object using the buffer. |
669 const Snapshot* snapshot = Snapshot::SetupFromBuffer(data); | 632 const Snapshot* snapshot = Snapshot::SetupFromBuffer(data); |
670 ASSERT(snapshot->IsMessageSnapshot()); | 633 ASSERT(snapshot->IsMessageSnapshot()); |
671 | 634 |
672 // Read object back from the snapshot. | 635 // Read object back from the snapshot. |
673 SnapshotReader reader(snapshot, Isolate::Current()); | 636 SnapshotReader reader(snapshot, Isolate::Current()); |
674 Instance& instance = Instance::Handle(); | 637 Instance& instance = Instance::Handle(); |
675 instance ^= reader.ReadObject(); | 638 instance ^= reader.ReadObject(); |
676 return instance.raw(); | 639 return instance.raw(); |
677 } | 640 } |
678 | 641 |
679 | 642 |
680 DART_EXPORT Dart_Handle Dart_HandleMessage(Dart_Port dest_port_id, | 643 DART_EXPORT Dart_Handle Dart_HandleMessage(Dart_Port dest_port_id, |
681 Dart_Port reply_port_id, | 644 Dart_Port reply_port_id, |
682 Dart_Message dart_message) { | 645 Dart_Message dart_message) { |
683 DARTSCOPE(Isolate::Current()); | 646 DARTSCOPE(Isolate::Current()); |
684 const Instance& msg = Instance::Handle(DeserializeMessage(dart_message)); | 647 const Instance& msg = Instance::Handle(DeserializeMessage(dart_message)); |
685 // TODO(turnidge): Should this call be wrapped in a longjmp? | |
686 const Object& result = | 648 const Object& result = |
687 Object::Handle(DartLibraryCalls::HandleMessage(dest_port_id, | 649 Object::Handle(DartLibraryCalls::HandleMessage(dest_port_id, |
688 reply_port_id, | 650 reply_port_id, |
689 msg)); | 651 msg)); |
690 if (result.IsError()) { | 652 if (result.IsError()) { |
691 return Api::NewLocalHandle(result); | 653 return Api::NewLocalHandle(result); |
692 } | 654 } |
693 ASSERT(result.IsNull()); | 655 ASSERT(result.IsNull()); |
694 return Api::Success(); | 656 return Api::Success(); |
695 } | 657 } |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
745 // function resolution by class name and function name more concise. | 707 // function resolution by class name and function name more concise. |
746 const Function& function = Function::Handle( | 708 const Function& function = Function::Handle( |
747 Resolver::ResolveStatic(Library::Handle(Library::CoreLibrary()), | 709 Resolver::ResolveStatic(Library::Handle(Library::CoreLibrary()), |
748 class_name, | 710 class_name, |
749 function_name, | 711 function_name, |
750 kNumArguments, | 712 kNumArguments, |
751 kNoArgumentNames, | 713 kNoArgumentNames, |
752 Resolver::kIsQualified)); | 714 Resolver::kIsQualified)); |
753 GrowableArray<const Object*> arguments(kNumArguments); | 715 GrowableArray<const Object*> arguments(kNumArguments); |
754 arguments.Add(&Integer::Handle(Integer::New(port_id))); | 716 arguments.Add(&Integer::Handle(Integer::New(port_id))); |
755 Dart_Handle result; | 717 const Object& result = Object::Handle( |
756 InvokeStatic(isolate, function, arguments, &result); | 718 DartEntry::InvokeStatic(function, arguments, kNoArgumentNames)); |
757 return result; | 719 return Api::NewLocalHandle(result); |
758 } | 720 } |
759 | 721 |
760 | 722 |
761 DART_EXPORT Dart_Handle Dart_GetReceivePort(Dart_Port port_id) { | 723 DART_EXPORT Dart_Handle Dart_GetReceivePort(Dart_Port port_id) { |
762 Isolate* isolate = Isolate::Current(); | 724 Isolate* isolate = Isolate::Current(); |
763 DARTSCOPE(isolate); | 725 DARTSCOPE(isolate); |
764 const String& class_name = | 726 const String& class_name = |
765 String::Handle(String::NewSymbol("ReceivePortImpl")); | 727 String::Handle(String::NewSymbol("ReceivePortImpl")); |
766 const String& function_name = | 728 const String& function_name = |
767 String::Handle(String::NewSymbol("_get_or_create")); | 729 String::Handle(String::NewSymbol("_get_or_create")); |
768 const int kNumArguments = 1; | 730 const int kNumArguments = 1; |
769 const Array& kNoArgumentNames = Array::Handle(); | 731 const Array& kNoArgumentNames = Array::Handle(); |
770 const Function& function = Function::Handle( | 732 const Function& function = Function::Handle( |
771 Resolver::ResolveStatic(Library::Handle(Library::CoreLibrary()), | 733 Resolver::ResolveStatic(Library::Handle(Library::CoreLibrary()), |
772 class_name, | 734 class_name, |
773 function_name, | 735 function_name, |
774 kNumArguments, | 736 kNumArguments, |
775 kNoArgumentNames, | 737 kNoArgumentNames, |
776 Resolver::kIsQualified)); | 738 Resolver::kIsQualified)); |
777 GrowableArray<const Object*> arguments(kNumArguments); | 739 GrowableArray<const Object*> arguments(kNumArguments); |
778 arguments.Add(&Integer::Handle(Integer::New(port_id))); | 740 arguments.Add(&Integer::Handle(Integer::New(port_id))); |
779 Dart_Handle result; | 741 const Object& result = Object::Handle( |
780 InvokeStatic(isolate, function, arguments, &result); | 742 DartEntry::InvokeStatic(function, arguments, kNoArgumentNames)); |
781 return result; | 743 return Api::NewLocalHandle(result); |
782 } | 744 } |
783 | 745 |
784 | 746 |
785 DART_EXPORT Dart_Port Dart_GetMainPortId() { | 747 DART_EXPORT Dart_Port Dart_GetMainPortId() { |
786 Isolate* isolate = Isolate::Current(); | 748 Isolate* isolate = Isolate::Current(); |
787 CHECK_ISOLATE(isolate); | 749 CHECK_ISOLATE(isolate); |
788 return isolate->main_port(); | 750 return isolate->main_port(); |
789 } | 751 } |
790 | 752 |
791 // --- Scopes ---- | 753 // --- Scopes ---- |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
828 const Object& obj = Object::Handle(Api::UnwrapHandle(object)); | 790 const Object& obj = Object::Handle(Api::UnwrapHandle(object)); |
829 return obj.IsNull(); | 791 return obj.IsNull(); |
830 } | 792 } |
831 | 793 |
832 | 794 |
833 DART_EXPORT Dart_Handle Dart_ObjectEquals(Dart_Handle obj1, Dart_Handle obj2, | 795 DART_EXPORT Dart_Handle Dart_ObjectEquals(Dart_Handle obj1, Dart_Handle obj2, |
834 bool* value) { | 796 bool* value) { |
835 DARTSCOPE(Isolate::Current()); | 797 DARTSCOPE(Isolate::Current()); |
836 const Instance& expected = Instance::CheckedHandle(Api::UnwrapHandle(obj1)); | 798 const Instance& expected = Instance::CheckedHandle(Api::UnwrapHandle(obj1)); |
837 const Instance& actual = Instance::CheckedHandle(Api::UnwrapHandle(obj2)); | 799 const Instance& actual = Instance::CheckedHandle(Api::UnwrapHandle(obj2)); |
838 const Instance& result = | 800 const Object& result = |
839 Instance::Handle(DartLibraryCalls::Equals(expected, actual)); | 801 Object::Handle(DartLibraryCalls::Equals(expected, actual)); |
840 if (result.IsBool()) { | 802 if (result.IsBool()) { |
841 Bool& b = Bool::Handle(); | 803 Bool& b = Bool::Handle(); |
842 b ^= result.raw(); | 804 b ^= result.raw(); |
843 *value = b.value(); | 805 *value = b.value(); |
844 return Api::Success(); | 806 return Api::Success(); |
845 } else if (result.IsError()) { | 807 } else if (result.IsError()) { |
846 return Api::NewLocalHandle(result); | 808 return Api::NewLocalHandle(result); |
847 } else { | 809 } else { |
848 return Api::NewError("Expected boolean result from =="); | 810 return Api::NewError("Expected boolean result from =="); |
849 } | 811 } |
(...skipping 502 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1352 const Object& obj = Object::Handle(Api::UnwrapHandle(list)); | 1314 const Object& obj = Object::Handle(Api::UnwrapHandle(list)); |
1353 if (obj.IsArray()) { | 1315 if (obj.IsArray()) { |
1354 Array& array_obj = Array::Handle(); | 1316 Array& array_obj = Array::Handle(); |
1355 array_obj ^= obj.raw(); | 1317 array_obj ^= obj.raw(); |
1356 *len = array_obj.Length(); | 1318 *len = array_obj.Length(); |
1357 return Api::Success(); | 1319 return Api::Success(); |
1358 } | 1320 } |
1359 // TODO(5526318): Make access to GrowableObjectArray more efficient. | 1321 // TODO(5526318): Make access to GrowableObjectArray more efficient. |
1360 // Now check and handle a dart object that implements the List interface. | 1322 // Now check and handle a dart object that implements the List interface. |
1361 const Instance& instance = Instance::Handle(GetListInstance(isolate, obj)); | 1323 const Instance& instance = Instance::Handle(GetListInstance(isolate, obj)); |
1362 if (!instance.IsNull()) { | 1324 if (instance.IsNull()) { |
1363 String& name = String::Handle(String::New("length")); | 1325 return Api::NewError("Object does not implement the List inteface"); |
1364 name = Field::GetterName(name); | 1326 } |
1365 const Function& function = Function::Handle( | 1327 String& name = String::Handle(String::New("length")); |
1366 Resolver::ResolveDynamic(instance, name, 1, 0)); | 1328 name = Field::GetterName(name); |
1367 if (!function.IsNull()) { | 1329 const Function& function = Function::Handle( |
1368 GrowableArray<const Object*> args(0); | 1330 Resolver::ResolveDynamic(instance, name, 1, 0)); |
1369 LongJump* base = isolate->long_jump_base(); | 1331 if (function.IsNull()) { |
1370 LongJump jump; | 1332 return Api::NewError("List object does not have a 'length' field."); |
1371 isolate->set_long_jump_base(&jump); | 1333 } |
1372 Dart_Handle result; | 1334 |
1373 if (setjmp(*jump.Set()) == 0) { | 1335 GrowableArray<const Object*> args(0); |
1374 const Array& kNoArgumentNames = Array::Handle(); | 1336 Dart_Handle result; |
1375 const Instance& retval = Instance::Handle( | 1337 const Array& kNoArgumentNames = Array::Handle(); |
1376 DartEntry::InvokeDynamic(instance, | 1338 const Object& retval = Object::Handle( |
1377 function, | 1339 DartEntry::InvokeDynamic(instance, function, args, kNoArgumentNames)); |
1378 args, | 1340 if (retval.IsSmi() || retval.IsMint()) { |
1379 kNoArgumentNames)); | 1341 Integer& integer = Integer::Handle(); |
1380 result = Api::Success(); | 1342 integer ^= retval.raw(); |
1381 if (retval.IsSmi() || retval.IsMint()) { | 1343 *len = integer.AsInt64Value(); |
1382 Integer& integer = Integer::Handle(); | 1344 return Api::Success(); |
1383 integer ^= retval.raw(); | 1345 } else if (retval.IsBigint()) { |
1384 *len = integer.AsInt64Value(); | 1346 Bigint& bigint = Bigint::Handle(); |
1385 } else if (retval.IsBigint()) { | 1347 bigint ^= retval.raw(); |
1386 Bigint& bigint = Bigint::Handle(); | 1348 if (BigintOperations::FitsIntoInt64(bigint)) { |
1387 bigint ^= retval.raw(); | 1349 *len = BigintOperations::ToInt64(bigint); |
1388 if (BigintOperations::FitsIntoInt64(bigint)) { | 1350 return Api::Success(); |
1389 *len = BigintOperations::ToInt64(bigint); | 1351 } else { |
1390 } else { | 1352 return Api::NewError("Length of List object is greater than the " |
1391 result = | 1353 "maximum value that 'len' parameter can hold"); |
1392 Api::NewError("Length of List object is greater than the " | |
1393 "maximum value that 'len' parameter can hold"); | |
1394 } | |
1395 } else if (retval.IsError()) { | |
1396 result = Api::NewLocalHandle(retval); | |
1397 } else { | |
1398 result = Api::NewError("Length of List object is not an integer"); | |
1399 } | |
1400 } else { | |
1401 SetupErrorResult(&result); | |
1402 } | |
1403 isolate->set_long_jump_base(base); | |
1404 return result; | |
1405 } | 1354 } |
1355 } else if (retval.IsError()) { | |
1356 return Api::NewLocalHandle(retval); | |
1357 } else { | |
1358 return Api::NewError("Length of List object is not an integer"); | |
1406 } | 1359 } |
1407 return Api::NewError("Object does not implement the list inteface"); | |
1408 } | 1360 } |
1409 | 1361 |
1410 | 1362 |
1411 static RawObject* GetListAt(Isolate* isolate, | 1363 static RawObject* GetListAt(Isolate* isolate, |
1412 const Instance& instance, | 1364 const Instance& instance, |
1413 const Integer& index, | 1365 const Integer& index, |
1414 const Function& function, | 1366 const Function& function, |
1415 Dart_Handle* result) { | 1367 Dart_Handle* result) { |
siva
2012/01/31 00:52:34
Why does this have to take the result as parameter
turnidge
2012/01/31 21:56:31
Got rid of GetListAt. It made more trouble than i
| |
1416 ASSERT(isolate != NULL); | 1368 ASSERT(isolate != NULL); |
1417 ASSERT(result != NULL); | 1369 ASSERT(result != NULL); |
1418 LongJump* base = isolate->long_jump_base(); | 1370 GrowableArray<const Object*> args(0); |
1419 LongJump jump; | 1371 args.Add(&index); |
1420 isolate->set_long_jump_base(&jump); | 1372 const Array& kNoArgumentNames = Array::Handle(); |
1421 if (setjmp(*jump.Set()) == 0) { | 1373 const Object& retval = Object::Handle(DartEntry::InvokeDynamic( |
1422 Instance& retval = Instance::Handle(); | 1374 instance, function, args, kNoArgumentNames)); |
1423 GrowableArray<const Object*> args(0); | 1375 if (retval.IsError()) { |
1424 args.Add(&index); | 1376 *result = Api::NewLocalHandle(retval); |
1425 const Array& kNoArgumentNames = Array::Handle(); | 1377 return Object::null(); |
1426 retval = DartEntry::InvokeDynamic(instance, | 1378 } else { |
1427 function, | 1379 *result = Api::Success(); |
1428 args, | |
1429 kNoArgumentNames); | |
1430 if (retval.IsError()) { | |
1431 *result = Api::NewLocalHandle(retval); | |
1432 } else { | |
1433 *result = Api::Success(); | |
1434 } | |
1435 isolate->set_long_jump_base(base); | |
1436 return retval.raw(); | 1380 return retval.raw(); |
1437 } | 1381 } |
1438 SetupErrorResult(result); | |
1439 isolate->set_long_jump_base(base); | |
1440 return Object::null(); | |
1441 } | 1382 } |
1442 | 1383 |
1443 | 1384 |
1444 DART_EXPORT Dart_Handle Dart_ListGetAt(Dart_Handle list, intptr_t index) { | 1385 DART_EXPORT Dart_Handle Dart_ListGetAt(Dart_Handle list, intptr_t index) { |
1445 Isolate* isolate = Isolate::Current(); | 1386 Isolate* isolate = Isolate::Current(); |
1446 DARTSCOPE(isolate); | 1387 DARTSCOPE(isolate); |
1447 const Object& obj = Object::Handle(Api::UnwrapHandle(list)); | 1388 const Object& obj = Object::Handle(Api::UnwrapHandle(list)); |
1448 if (obj.IsArray()) { | 1389 if (obj.IsArray()) { |
1449 Array& array_obj = Array::Handle(); | 1390 Array& array_obj = Array::Handle(); |
1450 array_obj ^= obj.raw(); | 1391 array_obj ^= obj.raw(); |
(...skipping 12 matching lines...) Expand all Loading... | |
1463 Resolver::ResolveDynamic(instance, name, 2, 0)); | 1404 Resolver::ResolveDynamic(instance, name, 2, 0)); |
1464 if (!function.IsNull()) { | 1405 if (!function.IsNull()) { |
1465 Object& element = Object::Handle(); | 1406 Object& element = Object::Handle(); |
1466 Integer& indexobj = Integer::Handle(); | 1407 Integer& indexobj = Integer::Handle(); |
1467 Dart_Handle result; | 1408 Dart_Handle result; |
1468 indexobj = Integer::New(index); | 1409 indexobj = Integer::New(index); |
1469 element = GetListAt(isolate, instance, indexobj, function, &result); | 1410 element = GetListAt(isolate, instance, indexobj, function, &result); |
1470 if (::Dart_IsError(result)) { | 1411 if (::Dart_IsError(result)) { |
1471 return result; // Error condition. | 1412 return result; // Error condition. |
1472 } | 1413 } |
1473 return Api::NewLocalHandle(element); | 1414 return Api::NewLocalHandle(element); |
siva
2012/01/31 00:52:34
Should just be:
element = GetListAt(instance, inde
turnidge
2012/01/31 21:56:31
Reworked this.
| |
1474 } | 1415 } |
1475 } | 1416 } |
1476 return Api::NewError("Object does not implement the 'List' interface"); | 1417 return Api::NewError("Object does not implement the 'List' interface"); |
1477 } | 1418 } |
1478 | 1419 |
1479 | 1420 |
1480 static void SetListAt(Isolate* isolate, | 1421 static void SetListAt(Isolate* isolate, |
1481 const Instance& instance, | 1422 const Instance& instance, |
1482 const Integer& index, | 1423 const Integer& index, |
1483 const Object& value, | 1424 const Object& value, |
1484 const Function& function, | 1425 const Function& function, |
1485 Dart_Handle* result) { | 1426 Dart_Handle* result) { |
siva
2012/01/31 00:52:34
Why does this need the isolate parameter?
Also co
turnidge
2012/01/31 21:56:31
Got rid of SetListAt as well.
| |
1486 ASSERT(isolate != NULL); | 1427 ASSERT(isolate != NULL); |
1487 ASSERT(result != NULL); | 1428 ASSERT(result != NULL); |
1488 LongJump* base = isolate->long_jump_base(); | 1429 GrowableArray<const Object*> args(1); |
1489 LongJump jump; | 1430 args.Add(&index); |
1490 isolate->set_long_jump_base(&jump); | 1431 args.Add(&value); |
1491 if (setjmp(*jump.Set()) == 0) { | 1432 const Array& kNoArgumentNames = Array::Handle(); |
1492 GrowableArray<const Object*> args(1); | 1433 const Object& retval = Object::Handle( |
1493 args.Add(&index); | 1434 DartEntry::InvokeDynamic(instance, function, args, kNoArgumentNames)); |
1494 args.Add(&value); | 1435 if (retval.IsError()) { |
1495 Instance& retval = Instance::Handle(); | 1436 *result = Api::NewLocalHandle(retval); |
1496 const Array& kNoArgumentNames = Array::Handle(); | |
1497 retval = DartEntry::InvokeDynamic(instance, | |
1498 function, | |
1499 args, | |
1500 kNoArgumentNames); | |
1501 if (retval.IsError()) { | |
1502 *result = Api::NewLocalHandle(retval); | |
1503 } else { | |
1504 *result = Api::Success(); | |
1505 } | |
1506 } else { | 1437 } else { |
1507 SetupErrorResult(result); | 1438 *result = Api::Success(); |
1508 } | 1439 } |
1509 isolate->set_long_jump_base(base); | |
1510 } | 1440 } |
1511 | 1441 |
1512 | 1442 |
1513 DART_EXPORT Dart_Handle Dart_ListSetAt(Dart_Handle list, | 1443 DART_EXPORT Dart_Handle Dart_ListSetAt(Dart_Handle list, |
1514 intptr_t index, | 1444 intptr_t index, |
1515 Dart_Handle value) { | 1445 Dart_Handle value) { |
1516 Isolate* isolate = Isolate::Current(); | 1446 Isolate* isolate = Isolate::Current(); |
1517 DARTSCOPE(isolate); | 1447 DARTSCOPE(isolate); |
1518 const Object& obj = Object::Handle(Api::UnwrapHandle(list)); | 1448 const Object& obj = Object::Handle(Api::UnwrapHandle(list)); |
1519 if (obj.IsArray()) { | 1449 if (obj.IsArray()) { |
(...skipping 13 matching lines...) Expand all Loading... | |
1533 // Now check and handle a dart object that implements the List interface. | 1463 // Now check and handle a dart object that implements the List interface. |
1534 const Instance& instance = Instance::Handle(GetListInstance(isolate, obj)); | 1464 const Instance& instance = Instance::Handle(GetListInstance(isolate, obj)); |
1535 if (!instance.IsNull()) { | 1465 if (!instance.IsNull()) { |
1536 String& name = String::Handle(String::New("[]=")); | 1466 String& name = String::Handle(String::New("[]=")); |
1537 const Function& function = Function::Handle( | 1467 const Function& function = Function::Handle( |
1538 Resolver::ResolveDynamic(instance, name, 3, 0)); | 1468 Resolver::ResolveDynamic(instance, name, 3, 0)); |
1539 if (!function.IsNull()) { | 1469 if (!function.IsNull()) { |
1540 Dart_Handle result; | 1470 Dart_Handle result; |
1541 const Integer& index_obj = Integer::Handle(Integer::New(index)); | 1471 const Integer& index_obj = Integer::Handle(Integer::New(index)); |
1542 const Object& value_obj = Object::Handle(Api::UnwrapHandle(value)); | 1472 const Object& value_obj = Object::Handle(Api::UnwrapHandle(value)); |
1543 SetListAt(isolate, instance, index_obj, value_obj, function, &result); | 1473 SetListAt(isolate, instance, index_obj, value_obj, function, &result); |
siva
2012/01/31 00:52:34
return SetListAt(instance, index_obj, value_obj, f
turnidge
2012/01/31 21:56:31
Code has changed.
| |
1544 return result; | 1474 return result; |
1545 } | 1475 } |
1546 } | 1476 } |
1547 return Api::NewError("Object does not implement the 'List' interface"); | 1477 return Api::NewError("Object does not implement the 'List' interface"); |
1548 } | 1478 } |
1549 | 1479 |
1550 | 1480 |
1551 DART_EXPORT Dart_Handle Dart_ListGetAsBytes(Dart_Handle list, | 1481 DART_EXPORT Dart_Handle Dart_ListGetAsBytes(Dart_Handle list, |
1552 intptr_t offset, | 1482 intptr_t offset, |
1553 uint8_t* native_array, | 1483 uint8_t* native_array, |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1586 Resolver::ResolveDynamic(instance, name, 2, 0)); | 1516 Resolver::ResolveDynamic(instance, name, 2, 0)); |
1587 if (!function.IsNull()) { | 1517 if (!function.IsNull()) { |
1588 Object& element = Object::Handle(); | 1518 Object& element = Object::Handle(); |
1589 Integer& intobj = Integer::Handle(); | 1519 Integer& intobj = Integer::Handle(); |
1590 Dart_Handle result; | 1520 Dart_Handle result; |
1591 for (int i = 0; i < length; i++) { | 1521 for (int i = 0; i < length; i++) { |
1592 intobj = Integer::New(offset + i); | 1522 intobj = Integer::New(offset + i); |
1593 element = GetListAt(isolate, instance, intobj, function, &result); | 1523 element = GetListAt(isolate, instance, intobj, function, &result); |
1594 if (::Dart_IsError(result)) { | 1524 if (::Dart_IsError(result)) { |
1595 return result; // Error condition. | 1525 return result; // Error condition. |
1596 } | 1526 } |
siva
2012/01/31 00:52:34
Ditto comment.
turnidge
2012/01/31 21:56:31
Code changed.
| |
1597 if (!element.IsInteger()) { | 1527 if (!element.IsInteger()) { |
1598 return Api::NewError("%s expects the argument 'list' to be " | 1528 return Api::NewError("%s expects the argument 'list' to be " |
1599 "a List of int", CURRENT_FUNC); | 1529 "a List of int", CURRENT_FUNC); |
1600 } | 1530 } |
1601 intobj ^= element.raw(); | 1531 intobj ^= element.raw(); |
1602 ASSERT(intobj.AsInt64Value() <= 0xff); | 1532 ASSERT(intobj.AsInt64Value() <= 0xff); |
1603 // TODO(hpayer): value should always be smaller then 0xff. Add error | 1533 // TODO(hpayer): value should always be smaller then 0xff. Add error |
1604 // handling. | 1534 // handling. |
1605 native_array[i] = static_cast<uint8_t>(intobj.AsInt64Value() & 0xff); | 1535 native_array[i] = static_cast<uint8_t>(intobj.AsInt64Value() & 0xff); |
1606 } | 1536 } |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1641 String& name = String::Handle(String::New("[]=")); | 1571 String& name = String::Handle(String::New("[]=")); |
1642 const Function& function = Function::Handle( | 1572 const Function& function = Function::Handle( |
1643 Resolver::ResolveDynamic(instance, name, 3, 0)); | 1573 Resolver::ResolveDynamic(instance, name, 3, 0)); |
1644 if (!function.IsNull()) { | 1574 if (!function.IsNull()) { |
1645 Integer& indexobj = Integer::Handle(); | 1575 Integer& indexobj = Integer::Handle(); |
1646 Integer& valueobj = Integer::Handle(); | 1576 Integer& valueobj = Integer::Handle(); |
1647 Dart_Handle result; | 1577 Dart_Handle result; |
1648 for (int i = 0; i < length; i++) { | 1578 for (int i = 0; i < length; i++) { |
1649 indexobj = Integer::New(offset + i); | 1579 indexobj = Integer::New(offset + i); |
1650 valueobj = Integer::New(native_array[i]); | 1580 valueobj = Integer::New(native_array[i]); |
1651 SetListAt(isolate, instance, indexobj, valueobj, function, &result); | 1581 SetListAt(isolate, instance, indexobj, valueobj, function, &result); |
siva
2012/01/31 00:52:34
Ditto.
turnidge
2012/01/31 21:56:31
Code changed.
| |
1652 if (::Dart_IsError(result)) { | 1582 if (::Dart_IsError(result)) { |
1653 return result; // Error condition. | 1583 return result; // Error condition. |
1654 } | 1584 } |
1655 } | 1585 } |
1656 return Api::Success(); | 1586 return Api::Success(); |
1657 } | 1587 } |
1658 } | 1588 } |
1659 return Api::NewError("Object does not implement the 'List' interface"); | 1589 return Api::NewError("Object does not implement the 'List' interface"); |
1660 } | 1590 } |
1661 | 1591 |
1662 | 1592 |
1663 // --- Closures --- | 1593 // --- Closures --- |
1664 | 1594 |
1665 | 1595 |
1666 DART_EXPORT bool Dart_IsClosure(Dart_Handle object) { | 1596 DART_EXPORT bool Dart_IsClosure(Dart_Handle object) { |
1667 DARTSCOPE(Isolate::Current()); | 1597 DARTSCOPE(Isolate::Current()); |
1668 const Object& obj = Object::Handle(Api::UnwrapHandle(object)); | 1598 const Object& obj = Object::Handle(Api::UnwrapHandle(object)); |
1669 return obj.IsClosure(); | 1599 return obj.IsClosure(); |
1670 } | 1600 } |
1671 | 1601 |
1672 | 1602 |
1673 // NOTE: Need to pass 'result' as a parameter here in order to avoid | |
1674 // warning: variable 'result' might be clobbered by 'longjmp' or 'vfork' | |
1675 // which shows up because of the use of setjmp. | |
1676 static void InvokeClosure(Isolate* isolate, | |
1677 const Closure& closure, | |
1678 GrowableArray<const Object*>& args, | |
1679 Dart_Handle* result) { | |
1680 ASSERT(isolate != NULL); | |
1681 LongJump* base = isolate->long_jump_base(); | |
1682 LongJump jump; | |
1683 isolate->set_long_jump_base(&jump); | |
1684 if (setjmp(*jump.Set()) == 0) { | |
1685 const Array& kNoArgumentNames = Array::Handle(); | |
1686 const Instance& retval = Instance::Handle( | |
1687 DartEntry::InvokeClosure(closure, args, kNoArgumentNames)); | |
1688 *result = Api::NewLocalHandle(retval); | |
1689 } else { | |
1690 SetupErrorResult(result); | |
1691 } | |
1692 isolate->set_long_jump_base(base); | |
1693 } | |
1694 | |
1695 | |
1696 DART_EXPORT Dart_Handle Dart_InvokeClosure(Dart_Handle closure, | 1603 DART_EXPORT Dart_Handle Dart_InvokeClosure(Dart_Handle closure, |
1697 int number_of_arguments, | 1604 int number_of_arguments, |
1698 Dart_Handle* arguments) { | 1605 Dart_Handle* arguments) { |
1699 Isolate* isolate = Isolate::Current(); | 1606 Isolate* isolate = Isolate::Current(); |
1700 DARTSCOPE(isolate); | 1607 DARTSCOPE(isolate); |
1701 const Object& obj = Object::Handle(Api::UnwrapHandle(closure)); | 1608 const Object& obj = Object::Handle(Api::UnwrapHandle(closure)); |
1702 if (obj.IsNull()) { | 1609 if (obj.IsNull()) { |
1703 return Api::NewError("Null object passed in to invoke closure"); | 1610 return Api::NewError("Null object passed in to invoke closure"); |
1704 } | 1611 } |
1705 if (!obj.IsClosure()) { | 1612 if (!obj.IsClosure()) { |
1706 return Api::NewError("Invalid closure passed to invoke closure"); | 1613 return Api::NewError("Invalid closure passed to invoke closure"); |
1707 } | 1614 } |
1708 ASSERT(ClassFinalizer::AllClassesFinalized()); | 1615 ASSERT(ClassFinalizer::AllClassesFinalized()); |
1709 | 1616 |
1710 // Now try to invoke the closure. | 1617 // Now try to invoke the closure. |
1711 Closure& closure_obj = Closure::Handle(); | 1618 Closure& closure_obj = Closure::Handle(); |
1712 closure_obj ^= obj.raw(); | 1619 closure_obj ^= obj.raw(); |
1713 Dart_Handle retval; | |
1714 GrowableArray<const Object*> dart_arguments(number_of_arguments); | 1620 GrowableArray<const Object*> dart_arguments(number_of_arguments); |
1715 for (int i = 0; i < number_of_arguments; i++) { | 1621 for (int i = 0; i < number_of_arguments; i++) { |
1716 const Object& arg = Object::Handle(Api::UnwrapHandle(arguments[i])); | 1622 const Object& arg = Object::Handle(Api::UnwrapHandle(arguments[i])); |
1717 dart_arguments.Add(&arg); | 1623 dart_arguments.Add(&arg); |
1718 } | 1624 } |
1719 InvokeClosure(isolate, closure_obj, dart_arguments, &retval); | 1625 const Array& kNoArgumentNames = Array::Handle(); |
1720 return retval; | 1626 const Object& result = Object::Handle( |
1627 DartEntry::InvokeClosure(closure_obj, dart_arguments, kNoArgumentNames)); | |
1628 return Api::NewLocalHandle(result); | |
1721 } | 1629 } |
1722 | 1630 |
1723 | 1631 |
1724 DART_EXPORT int64_t Dart_ClosureSmrck(Dart_Handle object) { | 1632 DART_EXPORT int64_t Dart_ClosureSmrck(Dart_Handle object) { |
1725 DARTSCOPE(Isolate::Current()); | 1633 DARTSCOPE(Isolate::Current()); |
1726 const Closure& obj = Closure::CheckedHandle(Api::UnwrapHandle(object)); | 1634 const Closure& obj = Closure::CheckedHandle(Api::UnwrapHandle(object)); |
1727 const Integer& smrck = Integer::Handle(obj.smrck()); | 1635 const Integer& smrck = Integer::Handle(obj.smrck()); |
1728 return smrck.IsNull() ? 0 : smrck.AsInt64Value(); | 1636 return smrck.IsNull() ? 0 : smrck.AsInt64Value(); |
1729 } | 1637 } |
1730 | 1638 |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1788 class_name.ToCString(), function_name.ToCString()); | 1696 class_name.ToCString(), function_name.ToCString()); |
1789 } | 1697 } |
1790 return Api::NewError(msg); | 1698 return Api::NewError(msg); |
1791 } | 1699 } |
1792 Dart_Handle retval; | 1700 Dart_Handle retval; |
1793 GrowableArray<const Object*> dart_arguments(number_of_arguments); | 1701 GrowableArray<const Object*> dart_arguments(number_of_arguments); |
1794 for (int i = 0; i < number_of_arguments; i++) { | 1702 for (int i = 0; i < number_of_arguments; i++) { |
1795 const Object& arg = Object::Handle(Api::UnwrapHandle(arguments[i])); | 1703 const Object& arg = Object::Handle(Api::UnwrapHandle(arguments[i])); |
1796 dart_arguments.Add(&arg); | 1704 dart_arguments.Add(&arg); |
1797 } | 1705 } |
1798 InvokeStatic(isolate, function, dart_arguments, &retval); | 1706 const Array& kNoArgumentNames = Array::Handle(); |
1799 return retval; | 1707 const Object& result = Object::Handle( |
1708 DartEntry::InvokeStatic(function, dart_arguments, kNoArgumentNames)); | |
1709 return Api::NewLocalHandle(result); | |
1800 } | 1710 } |
1801 | 1711 |
1802 | 1712 |
1803 DART_EXPORT Dart_Handle Dart_InvokeDynamic(Dart_Handle object, | 1713 DART_EXPORT Dart_Handle Dart_InvokeDynamic(Dart_Handle object, |
1804 Dart_Handle function_name, | 1714 Dart_Handle function_name, |
1805 int number_of_arguments, | 1715 int number_of_arguments, |
1806 Dart_Handle* arguments) { | 1716 Dart_Handle* arguments) { |
1807 Isolate* isolate = Isolate::Current(); | 1717 Isolate* isolate = Isolate::Current(); |
1808 DARTSCOPE(isolate); | 1718 DARTSCOPE(isolate); |
1809 const Object& obj = Object::Handle(Api::UnwrapHandle(object)); | 1719 const Object& obj = Object::Handle(Api::UnwrapHandle(object)); |
(...skipping 21 matching lines...) Expand all Loading... | |
1831 // TODO(5415268): Invoke noSuchMethod instead of failing. | 1741 // TODO(5415268): Invoke noSuchMethod instead of failing. |
1832 OS::PrintErr("Unable to find instance function: %s\n", name.ToCString()); | 1742 OS::PrintErr("Unable to find instance function: %s\n", name.ToCString()); |
1833 return Api::NewError("Unable to find instance function"); | 1743 return Api::NewError("Unable to find instance function"); |
1834 } | 1744 } |
1835 Dart_Handle retval; | 1745 Dart_Handle retval; |
1836 GrowableArray<const Object*> dart_arguments(number_of_arguments); | 1746 GrowableArray<const Object*> dart_arguments(number_of_arguments); |
1837 for (int i = 0; i < number_of_arguments; i++) { | 1747 for (int i = 0; i < number_of_arguments; i++) { |
1838 const Object& arg = Object::Handle(Api::UnwrapHandle(arguments[i])); | 1748 const Object& arg = Object::Handle(Api::UnwrapHandle(arguments[i])); |
1839 dart_arguments.Add(&arg); | 1749 dart_arguments.Add(&arg); |
1840 } | 1750 } |
1841 InvokeDynamic(isolate, receiver, function, dart_arguments, &retval); | 1751 const Array& kNoArgumentNames = Array::Handle(); |
1842 return retval; | 1752 const Object& result = Object::Handle( |
1753 DartEntry::InvokeDynamic( | |
1754 receiver, function, dart_arguments, kNoArgumentNames)); | |
1755 return Api::NewLocalHandle(result); | |
1843 } | 1756 } |
1844 | 1757 |
1845 | 1758 |
1846 static const bool kGetter = true; | 1759 static const bool kGetter = true; |
1847 static const bool kSetter = false; | 1760 static const bool kSetter = false; |
1848 | 1761 |
1849 | 1762 |
1850 static bool UseGetterForStaticField(const Field& fld) { | 1763 static bool UseGetterForStaticField(const Field& fld) { |
1851 if (fld.IsNull()) { | 1764 if (fld.IsNull()) { |
1852 return true; | 1765 return true; |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1939 const Object& obj = Object::Handle(Api::UnwrapHandle(result)); | 1852 const Object& obj = Object::Handle(Api::UnwrapHandle(result)); |
1940 if (obj.IsField()) { | 1853 if (obj.IsField()) { |
1941 Field& fld = Field::Handle(); | 1854 Field& fld = Field::Handle(); |
1942 fld ^= obj.raw(); | 1855 fld ^= obj.raw(); |
1943 retval = fld.value(); | 1856 retval = fld.value(); |
1944 return Api::NewLocalHandle(retval); | 1857 return Api::NewLocalHandle(retval); |
1945 } else { | 1858 } else { |
1946 Function& func = Function::Handle(); | 1859 Function& func = Function::Handle(); |
1947 func ^= obj.raw(); | 1860 func ^= obj.raw(); |
1948 GrowableArray<const Object*> args; | 1861 GrowableArray<const Object*> args; |
1949 InvokeStatic(isolate, func, args, &result); | 1862 const Array& kNoArgumentNames = Array::Handle(); |
1950 return result; | 1863 const Object& result = Object::Handle( |
1864 DartEntry::InvokeStatic(func, args, kNoArgumentNames)); | |
1865 return Api::NewLocalHandle(result); | |
1951 } | 1866 } |
1952 } | 1867 } |
1953 | 1868 |
1954 | 1869 |
1955 // TODO(iposva): The value parameter should be documented as being an instance. | 1870 // TODO(iposva): The value parameter should be documented as being an instance. |
1956 // TODO(turnidge): Is this skipping the setter? | 1871 // TODO(turnidge): Is this skipping the setter? |
1957 DART_EXPORT Dart_Handle Dart_SetStaticField(Dart_Handle cls, | 1872 DART_EXPORT Dart_Handle Dart_SetStaticField(Dart_Handle cls, |
1958 Dart_Handle name, | 1873 Dart_Handle name, |
1959 Dart_Handle value) { | 1874 Dart_Handle value) { |
1960 DARTSCOPE(Isolate::Current()); | 1875 DARTSCOPE(Isolate::Current()); |
(...skipping 25 matching lines...) Expand all Loading... | |
1986 } | 1901 } |
1987 Instance& object = Instance::Handle(); | 1902 Instance& object = Instance::Handle(); |
1988 object ^= param.raw(); | 1903 object ^= param.raw(); |
1989 Dart_Handle result = LookupInstanceField(object, name, kGetter); | 1904 Dart_Handle result = LookupInstanceField(object, name, kGetter); |
1990 if (::Dart_IsError(result)) { | 1905 if (::Dart_IsError(result)) { |
1991 return result; | 1906 return result; |
1992 } | 1907 } |
1993 Function& func = Function::Handle(); | 1908 Function& func = Function::Handle(); |
1994 func ^= Api::UnwrapHandle(result); | 1909 func ^= Api::UnwrapHandle(result); |
1995 GrowableArray<const Object*> arguments; | 1910 GrowableArray<const Object*> arguments; |
1996 InvokeDynamic(isolate, object, func, arguments, &result); | 1911 const Array& kNoArgumentNames = Array::Handle(); |
1997 return result; | 1912 const Object& retval = Object::Handle( |
1913 DartEntry::InvokeDynamic(object, func, arguments, kNoArgumentNames)); | |
1914 return Api::NewLocalHandle(retval); | |
1998 } | 1915 } |
1999 | 1916 |
2000 | 1917 |
2001 DART_EXPORT Dart_Handle Dart_SetInstanceField(Dart_Handle obj, | 1918 DART_EXPORT Dart_Handle Dart_SetInstanceField(Dart_Handle obj, |
2002 Dart_Handle name, | 1919 Dart_Handle name, |
2003 Dart_Handle value) { | 1920 Dart_Handle value) { |
2004 Isolate* isolate = Isolate::Current(); | 1921 Isolate* isolate = Isolate::Current(); |
2005 DARTSCOPE(isolate); | 1922 DARTSCOPE(isolate); |
2006 const Object& param = Object::Handle(Api::UnwrapHandle(obj)); | 1923 const Object& param = Object::Handle(Api::UnwrapHandle(obj)); |
2007 if (param.IsNull() || !param.IsInstance()) { | 1924 if (param.IsNull() || !param.IsInstance()) { |
2008 return Api::NewError("Invalid object passed in to access instance field"); | 1925 return Api::NewError("Invalid object passed in to access instance field"); |
2009 } | 1926 } |
2010 Instance& object = Instance::Handle(); | 1927 Instance& object = Instance::Handle(); |
2011 object ^= param.raw(); | 1928 object ^= param.raw(); |
2012 Dart_Handle result = LookupInstanceField(object, name, kSetter); | 1929 Dart_Handle result = LookupInstanceField(object, name, kSetter); |
2013 if (::Dart_IsError(result)) { | 1930 if (::Dart_IsError(result)) { |
2014 return result; | 1931 return result; |
2015 } | 1932 } |
2016 Function& func = Function::Handle(); | 1933 Function& func = Function::Handle(); |
2017 func ^= Api::UnwrapHandle(result); | 1934 func ^= Api::UnwrapHandle(result); |
2018 GrowableArray<const Object*> arguments(1); | 1935 GrowableArray<const Object*> arguments(1); |
2019 const Object& arg = Object::Handle(Api::UnwrapHandle(value)); | 1936 const Object& arg = Object::Handle(Api::UnwrapHandle(value)); |
2020 arguments.Add(&arg); | 1937 arguments.Add(&arg); |
2021 InvokeDynamic(isolate, object, func, arguments, &result); | 1938 const Array& kNoArgumentNames = Array::Handle(); |
2022 return result; | 1939 const Object& retval = Object::Handle( |
1940 DartEntry::InvokeDynamic(object, func, arguments, kNoArgumentNames)); | |
1941 return Api::NewLocalHandle(retval); | |
2023 } | 1942 } |
2024 | 1943 |
2025 | 1944 |
2026 DART_EXPORT Dart_Handle Dart_CreateNativeWrapperClass(Dart_Handle library, | 1945 DART_EXPORT Dart_Handle Dart_CreateNativeWrapperClass(Dart_Handle library, |
2027 Dart_Handle name, | 1946 Dart_Handle name, |
2028 int field_count) { | 1947 int field_count) { |
2029 Isolate* isolate = Isolate::Current(); | 1948 Isolate* isolate = Isolate::Current(); |
2030 DARTSCOPE(isolate); | 1949 DARTSCOPE(isolate); |
2031 const Object& param = Object::Handle(Api::UnwrapHandle(name)); | 1950 const Object& param = Object::Handle(Api::UnwrapHandle(name)); |
2032 if (param.IsNull() || !param.IsString() || field_count <= 0) { | 1951 if (param.IsNull() || !param.IsString() || field_count <= 0) { |
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2176 const String& source, | 2095 const String& source, |
2177 RawScript::Kind kind, | 2096 RawScript::Kind kind, |
2178 Dart_Handle* result) { | 2097 Dart_Handle* result) { |
2179 bool update_lib_status = (kind == RawScript::kScript || | 2098 bool update_lib_status = (kind == RawScript::kScript || |
2180 kind == RawScript::kLibrary); | 2099 kind == RawScript::kLibrary); |
2181 if (update_lib_status) { | 2100 if (update_lib_status) { |
2182 lib.SetLoadInProgress(); | 2101 lib.SetLoadInProgress(); |
2183 } | 2102 } |
2184 const Script& script = Script::Handle(Script::New(url, source, kind)); | 2103 const Script& script = Script::Handle(Script::New(url, source, kind)); |
2185 ASSERT(isolate != NULL); | 2104 ASSERT(isolate != NULL); |
2186 LongJump* base = isolate->long_jump_base(); | 2105 const Error& error = Error::Handle(Compiler::Compile(lib, script)); |
2187 LongJump jump; | 2106 if (error.IsNull()) { |
2188 isolate->set_long_jump_base(&jump); | |
2189 if (setjmp(*jump.Set()) == 0) { | |
2190 Compiler::Compile(lib, script); | |
2191 *result = Api::NewLocalHandle(lib); | 2107 *result = Api::NewLocalHandle(lib); |
2192 if (update_lib_status) { | 2108 if (update_lib_status) { |
2193 lib.SetLoaded(); | 2109 lib.SetLoaded(); |
2194 } | 2110 } |
2195 } else { | 2111 } else { |
2196 SetupErrorResult(result); | 2112 *result = Api::NewLocalHandle(error); |
2197 if (update_lib_status) { | 2113 if (update_lib_status) { |
2198 lib.SetLoadError(); | 2114 lib.SetLoadError(); |
2199 } | 2115 } |
2200 } | 2116 } |
2201 isolate->set_long_jump_base(base); | |
2202 } | 2117 } |
2203 | 2118 |
2204 | 2119 |
2205 DART_EXPORT Dart_Handle Dart_LoadScript(Dart_Handle url, | 2120 DART_EXPORT Dart_Handle Dart_LoadScript(Dart_Handle url, |
2206 Dart_Handle source, | 2121 Dart_Handle source, |
2207 Dart_LibraryTagHandler handler) { | 2122 Dart_LibraryTagHandler handler) { |
2208 TIMERSCOPE(time_script_loading); | 2123 TIMERSCOPE(time_script_loading); |
2209 Isolate* isolate = Isolate::Current(); | 2124 Isolate* isolate = Isolate::Current(); |
2210 DARTSCOPE(isolate); | 2125 DARTSCOPE(isolate); |
2211 const String& url_str = Api::UnwrapStringHandle(url); | 2126 const String& url_str = Api::UnwrapStringHandle(url); |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2263 CURRENT_FUNC); | 2178 CURRENT_FUNC); |
2264 } | 2179 } |
2265 library ^= tmp.raw(); | 2180 library ^= tmp.raw(); |
2266 library.Register(); | 2181 library.Register(); |
2267 isolate->object_store()->set_root_library(library); | 2182 isolate->object_store()->set_root_library(library); |
2268 return Api::NewLocalHandle(library); | 2183 return Api::NewLocalHandle(library); |
2269 } | 2184 } |
2270 | 2185 |
2271 | 2186 |
2272 static void CompileAll(Isolate* isolate, Dart_Handle* result) { | 2187 static void CompileAll(Isolate* isolate, Dart_Handle* result) { |
2273 *result = Api::Success(); | |
2274 ASSERT(isolate != NULL); | 2188 ASSERT(isolate != NULL); |
2275 LongJump* base = isolate->long_jump_base(); | 2189 const Error& error = Error::Handle(Library::CompileAll()); |
2276 LongJump jump; | 2190 if (error.IsNull()) { |
2277 isolate->set_long_jump_base(&jump); | 2191 *result = Api::Success(); |
2278 if (setjmp(*jump.Set()) == 0) { | |
2279 Library::CompileAll(); | |
2280 } else { | 2192 } else { |
2281 SetupErrorResult(result); | 2193 *result = Api::NewLocalHandle(error); |
2282 } | 2194 } |
2283 isolate->set_long_jump_base(base); | |
2284 } | 2195 } |
2285 | 2196 |
2286 | 2197 |
2287 DART_EXPORT Dart_Handle Dart_CompileAll() { | 2198 DART_EXPORT Dart_Handle Dart_CompileAll() { |
2288 Isolate* isolate = Isolate::Current(); | 2199 Isolate* isolate = Isolate::Current(); |
2289 DARTSCOPE(isolate); | 2200 DARTSCOPE(isolate); |
2290 Dart_Handle result; | 2201 Dart_Handle result; |
2291 const char* msg = CheckIsolateState(isolate); | 2202 const char* msg = CheckIsolateState(isolate); |
2292 if (msg != NULL) { | 2203 if (msg != NULL) { |
2293 return Api::NewError(msg); | 2204 return Api::NewError(msg); |
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2465 } | 2376 } |
2466 delete debug_region; | 2377 delete debug_region; |
2467 } else { | 2378 } else { |
2468 *buffer = NULL; | 2379 *buffer = NULL; |
2469 *buffer_size = 0; | 2380 *buffer_size = 0; |
2470 } | 2381 } |
2471 } | 2382 } |
2472 | 2383 |
2473 | 2384 |
2474 } // namespace dart | 2385 } // namespace dart |
OLD | NEW |