Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(177)

Side by Side Diff: runtime/vm/dart_api_impl.cc

Issue 9169102: Add Dart_PropagateError. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: '' Created 8 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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
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
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
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
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
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
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,
1412 const Instance& instance,
1413 const Integer& index,
1414 const Function& function,
1415 Dart_Handle* result) {
1416 ASSERT(isolate != NULL);
1417 ASSERT(result != NULL);
1418 LongJump* base = isolate->long_jump_base();
1419 LongJump jump;
1420 isolate->set_long_jump_base(&jump);
1421 if (setjmp(*jump.Set()) == 0) {
1422 Instance& retval = Instance::Handle();
1423 GrowableArray<const Object*> args(0);
1424 args.Add(&index);
1425 const Array& kNoArgumentNames = Array::Handle();
1426 retval = DartEntry::InvokeDynamic(instance,
1427 function,
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();
1437 }
1438 SetupErrorResult(result);
1439 isolate->set_long_jump_base(base);
1440 return Object::null();
1441 }
1442
1443
1444 DART_EXPORT Dart_Handle Dart_ListGetAt(Dart_Handle list, intptr_t index) { 1363 DART_EXPORT Dart_Handle Dart_ListGetAt(Dart_Handle list, intptr_t index) {
1445 Isolate* isolate = Isolate::Current(); 1364 Isolate* isolate = Isolate::Current();
1446 DARTSCOPE(isolate); 1365 DARTSCOPE(isolate);
1447 const Object& obj = Object::Handle(Api::UnwrapHandle(list)); 1366 const Object& obj = Object::Handle(Api::UnwrapHandle(list));
1448 if (obj.IsArray()) { 1367 if (obj.IsArray()) {
1449 Array& array_obj = Array::Handle(); 1368 Array& array_obj = Array::Handle();
1450 array_obj ^= obj.raw(); 1369 array_obj ^= obj.raw();
1451 if ((index >= 0) && (index < array_obj.Length())) { 1370 if ((index >= 0) && (index < array_obj.Length())) {
1452 const Object& element = Object::Handle(array_obj.At(index)); 1371 const Object& element = Object::Handle(array_obj.At(index));
1453 return Api::NewLocalHandle(element); 1372 return Api::NewLocalHandle(element);
1454 } 1373 }
1455 return Api::NewError("Invalid index passed in to access array element"); 1374 return Api::NewError("Invalid index passed in to access array element");
1456 } 1375 }
1457 // TODO(5526318): Make access to GrowableObjectArray more efficient. 1376 // TODO(5526318): Make access to GrowableObjectArray more efficient.
1458 // Now check and handle a dart object that implements the List interface. 1377 // Now check and handle a dart object that implements the List interface.
1459 const Instance& instance = Instance::Handle(GetListInstance(isolate, obj)); 1378 const Instance& instance = Instance::Handle(GetListInstance(isolate, obj));
1460 if (!instance.IsNull()) { 1379 if (!instance.IsNull()) {
1461 String& name = String::Handle(String::New("[]")); 1380 String& name = String::Handle(String::New("[]"));
1462 const Function& function = Function::Handle( 1381 const Function& function = Function::Handle(
1463 Resolver::ResolveDynamic(instance, name, 2, 0)); 1382 Resolver::ResolveDynamic(instance, name, 2, 0));
1464 if (!function.IsNull()) { 1383 if (!function.IsNull()) {
1465 Object& element = Object::Handle(); 1384 GrowableArray<const Object*> args(1);
1466 Integer& indexobj = Integer::Handle(); 1385 Integer& indexobj = Integer::Handle();
1467 Dart_Handle result;
1468 indexobj = Integer::New(index); 1386 indexobj = Integer::New(index);
1469 element = GetListAt(isolate, instance, indexobj, function, &result); 1387 args.Add(&indexobj);
1470 if (::Dart_IsError(result)) { 1388 const Array& kNoArgumentNames = Array::Handle();
1471 return result; // Error condition. 1389 const Object& result = Object::Handle(
1472 } 1390 DartEntry::InvokeDynamic(instance, function, args, kNoArgumentNames));
1473 return Api::NewLocalHandle(element); 1391 return Api::NewLocalHandle(result);
1474 } 1392 }
1475 } 1393 }
1476 return Api::NewError("Object does not implement the 'List' interface"); 1394 return Api::NewError("Object does not implement the 'List' interface");
1477 } 1395 }
1478 1396
1479 1397
1480 static void SetListAt(Isolate* isolate,
1481 const Instance& instance,
1482 const Integer& index,
1483 const Object& value,
1484 const Function& function,
1485 Dart_Handle* result) {
1486 ASSERT(isolate != NULL);
1487 ASSERT(result != NULL);
1488 LongJump* base = isolate->long_jump_base();
1489 LongJump jump;
1490 isolate->set_long_jump_base(&jump);
1491 if (setjmp(*jump.Set()) == 0) {
1492 GrowableArray<const Object*> args(1);
1493 args.Add(&index);
1494 args.Add(&value);
1495 Instance& retval = Instance::Handle();
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 {
1507 SetupErrorResult(result);
1508 }
1509 isolate->set_long_jump_base(base);
1510 }
1511
1512
1513 DART_EXPORT Dart_Handle Dart_ListSetAt(Dart_Handle list, 1398 DART_EXPORT Dart_Handle Dart_ListSetAt(Dart_Handle list,
1514 intptr_t index, 1399 intptr_t index,
1515 Dart_Handle value) { 1400 Dart_Handle value) {
1516 Isolate* isolate = Isolate::Current(); 1401 Isolate* isolate = Isolate::Current();
1517 DARTSCOPE(isolate); 1402 DARTSCOPE(isolate);
1518 const Object& obj = Object::Handle(Api::UnwrapHandle(list)); 1403 const Object& obj = Object::Handle(Api::UnwrapHandle(list));
1519 if (obj.IsArray()) { 1404 if (obj.IsArray()) {
1520 if (obj.IsImmutableArray()) { 1405 if (obj.IsImmutableArray()) {
1521 return Api::NewError("Cannot modify immutable array"); 1406 return Api::NewError("Cannot modify immutable array");
1522 } 1407 }
1523 Array& array_obj = Array::Handle(); 1408 Array& array_obj = Array::Handle();
1524 array_obj ^= obj.raw(); 1409 array_obj ^= obj.raw();
1525 const Object& value_obj = Object::Handle(Api::UnwrapHandle(value)); 1410 const Object& value_obj = Object::Handle(Api::UnwrapHandle(value));
1526 if ((index >= 0) && (index < array_obj.Length())) { 1411 if ((index >= 0) && (index < array_obj.Length())) {
1527 array_obj.SetAt(index, value_obj); 1412 array_obj.SetAt(index, value_obj);
1528 return Api::Success(); 1413 return Api::Success();
1529 } 1414 }
1530 return Api::NewError("Invalid index passed in to set array element"); 1415 return Api::NewError("Invalid index passed in to set array element");
1531 } 1416 }
1532 // TODO(5526318): Make access to GrowableObjectArray more efficient. 1417 // TODO(5526318): Make access to GrowableObjectArray more efficient.
1533 // Now check and handle a dart object that implements the List interface. 1418 // Now check and handle a dart object that implements the List interface.
1534 const Instance& instance = Instance::Handle(GetListInstance(isolate, obj)); 1419 const Instance& instance = Instance::Handle(GetListInstance(isolate, obj));
1535 if (!instance.IsNull()) { 1420 if (!instance.IsNull()) {
1536 String& name = String::Handle(String::New("[]=")); 1421 String& name = String::Handle(String::New("[]="));
1537 const Function& function = Function::Handle( 1422 const Function& function = Function::Handle(
1538 Resolver::ResolveDynamic(instance, name, 3, 0)); 1423 Resolver::ResolveDynamic(instance, name, 3, 0));
1539 if (!function.IsNull()) { 1424 if (!function.IsNull()) {
1540 Dart_Handle result;
1541 const Integer& index_obj = Integer::Handle(Integer::New(index)); 1425 const Integer& index_obj = Integer::Handle(Integer::New(index));
1542 const Object& value_obj = Object::Handle(Api::UnwrapHandle(value)); 1426 const Object& value_obj = Object::Handle(Api::UnwrapHandle(value));
1543 SetListAt(isolate, instance, index_obj, value_obj, function, &result); 1427 GrowableArray<const Object*> args(2);
1544 return result; 1428 args.Add(&index_obj);
1429 args.Add(&value_obj);
1430 const Array& kNoArgumentNames = Array::Handle();
1431 const Object& result = Object::Handle(
1432 DartEntry::InvokeDynamic(instance, function, args, kNoArgumentNames));
1433 return Api::NewLocalHandle(result);
1545 } 1434 }
1546 } 1435 }
1547 return Api::NewError("Object does not implement the 'List' interface"); 1436 return Api::NewError("Object does not implement the 'List' interface");
1548 } 1437 }
1549 1438
1550 1439
1551 DART_EXPORT Dart_Handle Dart_ListGetAsBytes(Dart_Handle list, 1440 DART_EXPORT Dart_Handle Dart_ListGetAsBytes(Dart_Handle list,
1552 intptr_t offset, 1441 intptr_t offset,
1553 uint8_t* native_array, 1442 uint8_t* native_array,
1554 intptr_t length) { 1443 intptr_t length) {
(...skipping 23 matching lines...) Expand all
1578 return Api::NewError("Invalid length passed in to access array elements"); 1467 return Api::NewError("Invalid length passed in to access array elements");
1579 } 1468 }
1580 // TODO(5526318): Make access to GrowableObjectArray more efficient. 1469 // TODO(5526318): Make access to GrowableObjectArray more efficient.
1581 // Now check and handle a dart object that implements the List interface. 1470 // Now check and handle a dart object that implements the List interface.
1582 const Instance& instance = Instance::Handle(GetListInstance(isolate, obj)); 1471 const Instance& instance = Instance::Handle(GetListInstance(isolate, obj));
1583 if (!instance.IsNull()) { 1472 if (!instance.IsNull()) {
1584 String& name = String::Handle(String::New("[]")); 1473 String& name = String::Handle(String::New("[]"));
1585 const Function& function = Function::Handle( 1474 const Function& function = Function::Handle(
1586 Resolver::ResolveDynamic(instance, name, 2, 0)); 1475 Resolver::ResolveDynamic(instance, name, 2, 0));
1587 if (!function.IsNull()) { 1476 if (!function.IsNull()) {
1588 Object& element = Object::Handle(); 1477 Object& result = Object::Handle();
1589 Integer& intobj = Integer::Handle(); 1478 Integer& intobj = Integer::Handle();
1590 Dart_Handle result;
1591 for (int i = 0; i < length; i++) { 1479 for (int i = 0; i < length; i++) {
1592 intobj = Integer::New(offset + i); 1480 intobj = Integer::New(offset + i);
1593 element = GetListAt(isolate, instance, intobj, function, &result); 1481 GrowableArray<const Object*> args(1);
1594 if (::Dart_IsError(result)) { 1482 args.Add(&intobj);
1595 return result; // Error condition. 1483 const Array& kNoArgumentNames = Array::Handle();
1484 result = DartEntry::InvokeDynamic(
1485 instance, function, args, kNoArgumentNames);
1486 if (result.IsError()) {
1487 return Api::NewLocalHandle(result);
1596 } 1488 }
1597 if (!element.IsInteger()) { 1489 if (!result.IsInteger()) {
1598 return Api::NewError("%s expects the argument 'list' to be " 1490 return Api::NewError("%s expects the argument 'list' to be "
1599 "a List of int", CURRENT_FUNC); 1491 "a List of int", CURRENT_FUNC);
1600 } 1492 }
1601 intobj ^= element.raw(); 1493 intobj ^= result.raw();
1602 ASSERT(intobj.AsInt64Value() <= 0xff); 1494 ASSERT(intobj.AsInt64Value() <= 0xff);
1603 // TODO(hpayer): value should always be smaller then 0xff. Add error 1495 // TODO(hpayer): value should always be smaller then 0xff. Add error
1604 // handling. 1496 // handling.
1605 native_array[i] = static_cast<uint8_t>(intobj.AsInt64Value() & 0xff); 1497 native_array[i] = static_cast<uint8_t>(intobj.AsInt64Value() & 0xff);
1606 } 1498 }
1607 return Api::Success(); 1499 return Api::Success();
1608 } 1500 }
1609 } 1501 }
1610 return Api::NewError("Object does not implement the 'List' interface"); 1502 return Api::NewError("Object does not implement the 'List' interface");
1611 } 1503 }
(...skipping 29 matching lines...) Expand all
1641 String& name = String::Handle(String::New("[]=")); 1533 String& name = String::Handle(String::New("[]="));
1642 const Function& function = Function::Handle( 1534 const Function& function = Function::Handle(
1643 Resolver::ResolveDynamic(instance, name, 3, 0)); 1535 Resolver::ResolveDynamic(instance, name, 3, 0));
1644 if (!function.IsNull()) { 1536 if (!function.IsNull()) {
1645 Integer& indexobj = Integer::Handle(); 1537 Integer& indexobj = Integer::Handle();
1646 Integer& valueobj = Integer::Handle(); 1538 Integer& valueobj = Integer::Handle();
1647 Dart_Handle result; 1539 Dart_Handle result;
1648 for (int i = 0; i < length; i++) { 1540 for (int i = 0; i < length; i++) {
1649 indexobj = Integer::New(offset + i); 1541 indexobj = Integer::New(offset + i);
1650 valueobj = Integer::New(native_array[i]); 1542 valueobj = Integer::New(native_array[i]);
1651 SetListAt(isolate, instance, indexobj, valueobj, function, &result); 1543 GrowableArray<const Object*> args(2);
1652 if (::Dart_IsError(result)) { 1544 args.Add(&indexobj);
1653 return result; // Error condition. 1545 args.Add(&valueobj);
1546 const Array& kNoArgumentNames = Array::Handle();
1547 const Object& result = Object::Handle(
1548 DartEntry::InvokeDynamic(
1549 instance, function, args, kNoArgumentNames));
1550 if (result.IsError()) {
1551 return Api::NewLocalHandle(result);
1654 } 1552 }
1655 } 1553 }
1656 return Api::Success(); 1554 return Api::Success();
1657 } 1555 }
1658 } 1556 }
1659 return Api::NewError("Object does not implement the 'List' interface"); 1557 return Api::NewError("Object does not implement the 'List' interface");
1660 } 1558 }
1661 1559
1662 1560
1663 // --- Closures --- 1561 // --- Closures ---
1664 1562
1665 1563
1666 DART_EXPORT bool Dart_IsClosure(Dart_Handle object) { 1564 DART_EXPORT bool Dart_IsClosure(Dart_Handle object) {
1667 DARTSCOPE(Isolate::Current()); 1565 DARTSCOPE(Isolate::Current());
1668 const Object& obj = Object::Handle(Api::UnwrapHandle(object)); 1566 const Object& obj = Object::Handle(Api::UnwrapHandle(object));
1669 return obj.IsClosure(); 1567 return obj.IsClosure();
1670 } 1568 }
1671 1569
1672 1570
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, 1571 DART_EXPORT Dart_Handle Dart_InvokeClosure(Dart_Handle closure,
1697 int number_of_arguments, 1572 int number_of_arguments,
1698 Dart_Handle* arguments) { 1573 Dart_Handle* arguments) {
1699 Isolate* isolate = Isolate::Current(); 1574 Isolate* isolate = Isolate::Current();
1700 DARTSCOPE(isolate); 1575 DARTSCOPE(isolate);
1701 const Object& obj = Object::Handle(Api::UnwrapHandle(closure)); 1576 const Object& obj = Object::Handle(Api::UnwrapHandle(closure));
1702 if (obj.IsNull()) { 1577 if (obj.IsNull()) {
1703 return Api::NewError("Null object passed in to invoke closure"); 1578 return Api::NewError("Null object passed in to invoke closure");
1704 } 1579 }
1705 if (!obj.IsClosure()) { 1580 if (!obj.IsClosure()) {
1706 return Api::NewError("Invalid closure passed to invoke closure"); 1581 return Api::NewError("Invalid closure passed to invoke closure");
1707 } 1582 }
1708 ASSERT(ClassFinalizer::AllClassesFinalized()); 1583 ASSERT(ClassFinalizer::AllClassesFinalized());
1709 1584
1710 // Now try to invoke the closure. 1585 // Now try to invoke the closure.
1711 Closure& closure_obj = Closure::Handle(); 1586 Closure& closure_obj = Closure::Handle();
1712 closure_obj ^= obj.raw(); 1587 closure_obj ^= obj.raw();
1713 Dart_Handle retval;
1714 GrowableArray<const Object*> dart_arguments(number_of_arguments); 1588 GrowableArray<const Object*> dart_arguments(number_of_arguments);
1715 for (int i = 0; i < number_of_arguments; i++) { 1589 for (int i = 0; i < number_of_arguments; i++) {
1716 const Object& arg = Object::Handle(Api::UnwrapHandle(arguments[i])); 1590 const Object& arg = Object::Handle(Api::UnwrapHandle(arguments[i]));
1717 dart_arguments.Add(&arg); 1591 dart_arguments.Add(&arg);
1718 } 1592 }
1719 InvokeClosure(isolate, closure_obj, dart_arguments, &retval); 1593 const Array& kNoArgumentNames = Array::Handle();
1720 return retval; 1594 const Object& result = Object::Handle(
1595 DartEntry::InvokeClosure(closure_obj, dart_arguments, kNoArgumentNames));
1596 return Api::NewLocalHandle(result);
1721 } 1597 }
1722 1598
1723 1599
1724 DART_EXPORT int64_t Dart_ClosureSmrck(Dart_Handle object) { 1600 DART_EXPORT int64_t Dart_ClosureSmrck(Dart_Handle object) {
1725 DARTSCOPE(Isolate::Current()); 1601 DARTSCOPE(Isolate::Current());
1726 const Closure& obj = Closure::CheckedHandle(Api::UnwrapHandle(object)); 1602 const Closure& obj = Closure::CheckedHandle(Api::UnwrapHandle(object));
1727 const Integer& smrck = Integer::Handle(obj.smrck()); 1603 const Integer& smrck = Integer::Handle(obj.smrck());
1728 return smrck.IsNull() ? 0 : smrck.AsInt64Value(); 1604 return smrck.IsNull() ? 0 : smrck.AsInt64Value();
1729 } 1605 }
1730 1606
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
1788 class_name.ToCString(), function_name.ToCString()); 1664 class_name.ToCString(), function_name.ToCString());
1789 } 1665 }
1790 return Api::NewError(msg); 1666 return Api::NewError(msg);
1791 } 1667 }
1792 Dart_Handle retval; 1668 Dart_Handle retval;
1793 GrowableArray<const Object*> dart_arguments(number_of_arguments); 1669 GrowableArray<const Object*> dart_arguments(number_of_arguments);
1794 for (int i = 0; i < number_of_arguments; i++) { 1670 for (int i = 0; i < number_of_arguments; i++) {
1795 const Object& arg = Object::Handle(Api::UnwrapHandle(arguments[i])); 1671 const Object& arg = Object::Handle(Api::UnwrapHandle(arguments[i]));
1796 dart_arguments.Add(&arg); 1672 dart_arguments.Add(&arg);
1797 } 1673 }
1798 InvokeStatic(isolate, function, dart_arguments, &retval); 1674 const Array& kNoArgumentNames = Array::Handle();
1799 return retval; 1675 const Object& result = Object::Handle(
1676 DartEntry::InvokeStatic(function, dart_arguments, kNoArgumentNames));
1677 return Api::NewLocalHandle(result);
1800 } 1678 }
1801 1679
1802 1680
1803 DART_EXPORT Dart_Handle Dart_InvokeDynamic(Dart_Handle object, 1681 DART_EXPORT Dart_Handle Dart_InvokeDynamic(Dart_Handle object,
1804 Dart_Handle function_name, 1682 Dart_Handle function_name,
1805 int number_of_arguments, 1683 int number_of_arguments,
1806 Dart_Handle* arguments) { 1684 Dart_Handle* arguments) {
1807 Isolate* isolate = Isolate::Current(); 1685 Isolate* isolate = Isolate::Current();
1808 DARTSCOPE(isolate); 1686 DARTSCOPE(isolate);
1809 const Object& obj = Object::Handle(Api::UnwrapHandle(object)); 1687 const Object& obj = Object::Handle(Api::UnwrapHandle(object));
(...skipping 21 matching lines...) Expand all
1831 // TODO(5415268): Invoke noSuchMethod instead of failing. 1709 // TODO(5415268): Invoke noSuchMethod instead of failing.
1832 OS::PrintErr("Unable to find instance function: %s\n", name.ToCString()); 1710 OS::PrintErr("Unable to find instance function: %s\n", name.ToCString());
1833 return Api::NewError("Unable to find instance function"); 1711 return Api::NewError("Unable to find instance function");
1834 } 1712 }
1835 Dart_Handle retval; 1713 Dart_Handle retval;
1836 GrowableArray<const Object*> dart_arguments(number_of_arguments); 1714 GrowableArray<const Object*> dart_arguments(number_of_arguments);
1837 for (int i = 0; i < number_of_arguments; i++) { 1715 for (int i = 0; i < number_of_arguments; i++) {
1838 const Object& arg = Object::Handle(Api::UnwrapHandle(arguments[i])); 1716 const Object& arg = Object::Handle(Api::UnwrapHandle(arguments[i]));
1839 dart_arguments.Add(&arg); 1717 dart_arguments.Add(&arg);
1840 } 1718 }
1841 InvokeDynamic(isolate, receiver, function, dart_arguments, &retval); 1719 const Array& kNoArgumentNames = Array::Handle();
1842 return retval; 1720 const Object& result = Object::Handle(
1721 DartEntry::InvokeDynamic(
1722 receiver, function, dart_arguments, kNoArgumentNames));
1723 return Api::NewLocalHandle(result);
1843 } 1724 }
1844 1725
1845 1726
1846 static const bool kGetter = true; 1727 static const bool kGetter = true;
1847 static const bool kSetter = false; 1728 static const bool kSetter = false;
1848 1729
1849 1730
1850 static bool UseGetterForStaticField(const Field& fld) { 1731 static bool UseGetterForStaticField(const Field& fld) {
1851 if (fld.IsNull()) { 1732 if (fld.IsNull()) {
1852 return true; 1733 return true;
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
1939 const Object& obj = Object::Handle(Api::UnwrapHandle(result)); 1820 const Object& obj = Object::Handle(Api::UnwrapHandle(result));
1940 if (obj.IsField()) { 1821 if (obj.IsField()) {
1941 Field& fld = Field::Handle(); 1822 Field& fld = Field::Handle();
1942 fld ^= obj.raw(); 1823 fld ^= obj.raw();
1943 retval = fld.value(); 1824 retval = fld.value();
1944 return Api::NewLocalHandle(retval); 1825 return Api::NewLocalHandle(retval);
1945 } else { 1826 } else {
1946 Function& func = Function::Handle(); 1827 Function& func = Function::Handle();
1947 func ^= obj.raw(); 1828 func ^= obj.raw();
1948 GrowableArray<const Object*> args; 1829 GrowableArray<const Object*> args;
1949 InvokeStatic(isolate, func, args, &result); 1830 const Array& kNoArgumentNames = Array::Handle();
1950 return result; 1831 const Object& result = Object::Handle(
1832 DartEntry::InvokeStatic(func, args, kNoArgumentNames));
1833 return Api::NewLocalHandle(result);
1951 } 1834 }
1952 } 1835 }
1953 1836
1954 1837
1955 // TODO(iposva): The value parameter should be documented as being an instance. 1838 // TODO(iposva): The value parameter should be documented as being an instance.
1956 // TODO(turnidge): Is this skipping the setter? 1839 // TODO(turnidge): Is this skipping the setter?
1957 DART_EXPORT Dart_Handle Dart_SetStaticField(Dart_Handle cls, 1840 DART_EXPORT Dart_Handle Dart_SetStaticField(Dart_Handle cls,
1958 Dart_Handle name, 1841 Dart_Handle name,
1959 Dart_Handle value) { 1842 Dart_Handle value) {
1960 DARTSCOPE(Isolate::Current()); 1843 DARTSCOPE(Isolate::Current());
(...skipping 25 matching lines...) Expand all
1986 } 1869 }
1987 Instance& object = Instance::Handle(); 1870 Instance& object = Instance::Handle();
1988 object ^= param.raw(); 1871 object ^= param.raw();
1989 Dart_Handle result = LookupInstanceField(object, name, kGetter); 1872 Dart_Handle result = LookupInstanceField(object, name, kGetter);
1990 if (::Dart_IsError(result)) { 1873 if (::Dart_IsError(result)) {
1991 return result; 1874 return result;
1992 } 1875 }
1993 Function& func = Function::Handle(); 1876 Function& func = Function::Handle();
1994 func ^= Api::UnwrapHandle(result); 1877 func ^= Api::UnwrapHandle(result);
1995 GrowableArray<const Object*> arguments; 1878 GrowableArray<const Object*> arguments;
1996 InvokeDynamic(isolate, object, func, arguments, &result); 1879 const Array& kNoArgumentNames = Array::Handle();
1997 return result; 1880 const Object& retval = Object::Handle(
1881 DartEntry::InvokeDynamic(object, func, arguments, kNoArgumentNames));
1882 return Api::NewLocalHandle(retval);
1998 } 1883 }
1999 1884
2000 1885
2001 DART_EXPORT Dart_Handle Dart_SetInstanceField(Dart_Handle obj, 1886 DART_EXPORT Dart_Handle Dart_SetInstanceField(Dart_Handle obj,
2002 Dart_Handle name, 1887 Dart_Handle name,
2003 Dart_Handle value) { 1888 Dart_Handle value) {
2004 Isolate* isolate = Isolate::Current(); 1889 Isolate* isolate = Isolate::Current();
2005 DARTSCOPE(isolate); 1890 DARTSCOPE(isolate);
2006 const Object& param = Object::Handle(Api::UnwrapHandle(obj)); 1891 const Object& param = Object::Handle(Api::UnwrapHandle(obj));
2007 if (param.IsNull() || !param.IsInstance()) { 1892 if (param.IsNull() || !param.IsInstance()) {
2008 return Api::NewError("Invalid object passed in to access instance field"); 1893 return Api::NewError("Invalid object passed in to access instance field");
2009 } 1894 }
2010 Instance& object = Instance::Handle(); 1895 Instance& object = Instance::Handle();
2011 object ^= param.raw(); 1896 object ^= param.raw();
2012 Dart_Handle result = LookupInstanceField(object, name, kSetter); 1897 Dart_Handle result = LookupInstanceField(object, name, kSetter);
2013 if (::Dart_IsError(result)) { 1898 if (::Dart_IsError(result)) {
2014 return result; 1899 return result;
2015 } 1900 }
2016 Function& func = Function::Handle(); 1901 Function& func = Function::Handle();
2017 func ^= Api::UnwrapHandle(result); 1902 func ^= Api::UnwrapHandle(result);
2018 GrowableArray<const Object*> arguments(1); 1903 GrowableArray<const Object*> arguments(1);
2019 const Object& arg = Object::Handle(Api::UnwrapHandle(value)); 1904 const Object& arg = Object::Handle(Api::UnwrapHandle(value));
2020 arguments.Add(&arg); 1905 arguments.Add(&arg);
2021 InvokeDynamic(isolate, object, func, arguments, &result); 1906 const Array& kNoArgumentNames = Array::Handle();
2022 return result; 1907 const Object& retval = Object::Handle(
1908 DartEntry::InvokeDynamic(object, func, arguments, kNoArgumentNames));
1909 return Api::NewLocalHandle(retval);
2023 } 1910 }
2024 1911
2025 1912
2026 DART_EXPORT Dart_Handle Dart_CreateNativeWrapperClass(Dart_Handle library, 1913 DART_EXPORT Dart_Handle Dart_CreateNativeWrapperClass(Dart_Handle library,
2027 Dart_Handle name, 1914 Dart_Handle name,
2028 int field_count) { 1915 int field_count) {
2029 Isolate* isolate = Isolate::Current(); 1916 Isolate* isolate = Isolate::Current();
2030 DARTSCOPE(isolate); 1917 DARTSCOPE(isolate);
2031 const Object& param = Object::Handle(Api::UnwrapHandle(name)); 1918 const Object& param = Object::Handle(Api::UnwrapHandle(name));
2032 if (param.IsNull() || !param.IsString() || field_count <= 0) { 1919 if (param.IsNull() || !param.IsString() || field_count <= 0) {
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
2176 const String& source, 2063 const String& source,
2177 RawScript::Kind kind, 2064 RawScript::Kind kind,
2178 Dart_Handle* result) { 2065 Dart_Handle* result) {
2179 bool update_lib_status = (kind == RawScript::kScript || 2066 bool update_lib_status = (kind == RawScript::kScript ||
2180 kind == RawScript::kLibrary); 2067 kind == RawScript::kLibrary);
2181 if (update_lib_status) { 2068 if (update_lib_status) {
2182 lib.SetLoadInProgress(); 2069 lib.SetLoadInProgress();
2183 } 2070 }
2184 const Script& script = Script::Handle(Script::New(url, source, kind)); 2071 const Script& script = Script::Handle(Script::New(url, source, kind));
2185 ASSERT(isolate != NULL); 2072 ASSERT(isolate != NULL);
2186 LongJump* base = isolate->long_jump_base(); 2073 const Error& error = Error::Handle(Compiler::Compile(lib, script));
2187 LongJump jump; 2074 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); 2075 *result = Api::NewLocalHandle(lib);
2192 if (update_lib_status) { 2076 if (update_lib_status) {
2193 lib.SetLoaded(); 2077 lib.SetLoaded();
2194 } 2078 }
2195 } else { 2079 } else {
2196 SetupErrorResult(result); 2080 *result = Api::NewLocalHandle(error);
2197 if (update_lib_status) { 2081 if (update_lib_status) {
2198 lib.SetLoadError(); 2082 lib.SetLoadError();
2199 } 2083 }
2200 } 2084 }
2201 isolate->set_long_jump_base(base);
2202 } 2085 }
2203 2086
2204 2087
2205 DART_EXPORT Dart_Handle Dart_LoadScript(Dart_Handle url, 2088 DART_EXPORT Dart_Handle Dart_LoadScript(Dart_Handle url,
2206 Dart_Handle source, 2089 Dart_Handle source,
2207 Dart_LibraryTagHandler handler) { 2090 Dart_LibraryTagHandler handler) {
2208 TIMERSCOPE(time_script_loading); 2091 TIMERSCOPE(time_script_loading);
2209 Isolate* isolate = Isolate::Current(); 2092 Isolate* isolate = Isolate::Current();
2210 DARTSCOPE(isolate); 2093 DARTSCOPE(isolate);
2211 const String& url_str = Api::UnwrapStringHandle(url); 2094 const String& url_str = Api::UnwrapStringHandle(url);
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
2263 CURRENT_FUNC); 2146 CURRENT_FUNC);
2264 } 2147 }
2265 library ^= tmp.raw(); 2148 library ^= tmp.raw();
2266 library.Register(); 2149 library.Register();
2267 isolate->object_store()->set_root_library(library); 2150 isolate->object_store()->set_root_library(library);
2268 return Api::NewLocalHandle(library); 2151 return Api::NewLocalHandle(library);
2269 } 2152 }
2270 2153
2271 2154
2272 static void CompileAll(Isolate* isolate, Dart_Handle* result) { 2155 static void CompileAll(Isolate* isolate, Dart_Handle* result) {
2273 *result = Api::Success();
2274 ASSERT(isolate != NULL); 2156 ASSERT(isolate != NULL);
2275 LongJump* base = isolate->long_jump_base(); 2157 const Error& error = Error::Handle(Library::CompileAll());
2276 LongJump jump; 2158 if (error.IsNull()) {
2277 isolate->set_long_jump_base(&jump); 2159 *result = Api::Success();
2278 if (setjmp(*jump.Set()) == 0) {
2279 Library::CompileAll();
2280 } else { 2160 } else {
2281 SetupErrorResult(result); 2161 *result = Api::NewLocalHandle(error);
2282 } 2162 }
2283 isolate->set_long_jump_base(base);
2284 } 2163 }
2285 2164
2286 2165
2287 DART_EXPORT Dart_Handle Dart_CompileAll() { 2166 DART_EXPORT Dart_Handle Dart_CompileAll() {
2288 Isolate* isolate = Isolate::Current(); 2167 Isolate* isolate = Isolate::Current();
2289 DARTSCOPE(isolate); 2168 DARTSCOPE(isolate);
2290 Dart_Handle result; 2169 Dart_Handle result;
2291 const char* msg = CheckIsolateState(isolate); 2170 const char* msg = CheckIsolateState(isolate);
2292 if (msg != NULL) { 2171 if (msg != NULL) {
2293 return Api::NewError(msg); 2172 return Api::NewError(msg);
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after
2465 } 2344 }
2466 delete debug_region; 2345 delete debug_region;
2467 } else { 2346 } else {
2468 *buffer = NULL; 2347 *buffer = NULL;
2469 *buffer_size = 0; 2348 *buffer_size = 0;
2470 } 2349 }
2471 } 2350 }
2472 2351
2473 2352
2474 } // namespace dart 2353 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/dart.cc ('k') | runtime/vm/dart_api_impl_test.cc » ('j') | runtime/vm/exceptions.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698