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

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

Issue 9316071: Dart_PropagateError, take 2. (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
« no previous file with comments | « runtime/vm/dart.cc ('k') | runtime/vm/dart_api_impl_test.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/message.h" 17 #include "vm/message.h"
19 #include "vm/native_entry.h" 18 #include "vm/native_entry.h"
20 #include "vm/native_message_handler.h" 19 #include "vm/native_message_handler.h"
21 #include "vm/object.h" 20 #include "vm/object.h"
22 #include "vm/object_store.h" 21 #include "vm/object_store.h"
23 #include "vm/port.h" 22 #include "vm/port.h"
24 #include "vm/resolver.h" 23 #include "vm/resolver.h"
25 #include "vm/snapshot.h" 24 #include "vm/snapshot.h"
26 #include "vm/stack_frame.h" 25 #include "vm/stack_frame.h"
27 #include "vm/timer.h" 26 #include "vm/timer.h"
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
80 } 79 }
81 80
82 81
83 void SetupErrorResult(Dart_Handle* handle) { 82 void SetupErrorResult(Dart_Handle* handle) {
84 const Error& error = Error::Handle( 83 const Error& error = Error::Handle(
85 Isolate::Current()->object_store()->sticky_error()); 84 Isolate::Current()->object_store()->sticky_error());
86 *handle = Api::NewLocalHandle(error); 85 *handle = Api::NewLocalHandle(error);
87 } 86 }
88 87
89 88
90 // NOTE: Need to pass 'result' as a parameter here in order to avoid
91 // warning: variable 'result' might be clobbered by 'longjmp' or 'vfork'
92 // which shows up because of the use of setjmp.
93 static void InvokeStatic(Isolate* isolate,
94 const Function& function,
95 GrowableArray<const Object*>& args,
96 Dart_Handle* result) {
97 ASSERT(isolate != NULL);
98 LongJump* base = isolate->long_jump_base();
99 LongJump jump;
100 isolate->set_long_jump_base(&jump);
101 if (setjmp(*jump.Set()) == 0) {
102 const Array& kNoArgumentNames = Array::Handle();
103 const Instance& retval = Instance::Handle(
104 DartEntry::InvokeStatic(function, args, kNoArgumentNames));
105 *result = Api::NewLocalHandle(retval);
106 } else {
107 SetupErrorResult(result);
108 }
109 isolate->set_long_jump_base(base);
110 }
111
112
113 // NOTE: Need to pass 'result' as a parameter here in order to avoid
114 // warning: variable 'result' might be clobbered by 'longjmp' or 'vfork'
115 // which shows up because of the use of setjmp.
116 static void InvokeDynamic(Isolate* isolate,
117 const Instance& receiver,
118 const Function& function,
119 GrowableArray<const Object*>& args,
120 Dart_Handle* result) {
121 ASSERT(isolate != NULL);
122 LongJump* base = isolate->long_jump_base();
123 LongJump jump;
124 isolate->set_long_jump_base(&jump);
125 if (setjmp(*jump.Set()) == 0) {
126 const Array& kNoArgumentNames = Array::Handle();
127 const Instance& retval = Instance::Handle(
128 DartEntry::InvokeDynamic(receiver, function, args, kNoArgumentNames));
129 *result = Api::NewLocalHandle(retval);
130 } else {
131 SetupErrorResult(result);
132 }
133 isolate->set_long_jump_base(base);
134 }
135
136
137 Dart_Handle Api::NewLocalHandle(const Object& object) { 89 Dart_Handle Api::NewLocalHandle(const Object& object) {
138 Isolate* isolate = Isolate::Current(); 90 Isolate* isolate = Isolate::Current();
139 ASSERT(isolate != NULL); 91 ASSERT(isolate != NULL);
140 ApiState* state = isolate->api_state(); 92 ApiState* state = isolate->api_state();
141 ASSERT(state != NULL); 93 ASSERT(state != NULL);
142 ApiLocalScope* scope = state->top_scope(); 94 ApiLocalScope* scope = state->top_scope();
143 ASSERT(scope != NULL); 95 ASSERT(scope != NULL);
144 LocalHandles* local_handles = scope->local_handles(); 96 LocalHandles* local_handles = scope->local_handles();
145 ASSERT(local_handles != NULL); 97 ASSERT(local_handles != NULL);
146 LocalHandle* ref = local_handles->AllocateHandle(); 98 LocalHandle* ref = local_handles->AllocateHandle();
(...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after
366 va_start(args2, format); 318 va_start(args2, format);
367 OS::VSNPrint(buffer, (len + 1), format, args2); 319 OS::VSNPrint(buffer, (len + 1), format, args2);
368 va_end(args2); 320 va_end(args2);
369 321
370 const String& message = String::Handle(String::New(buffer)); 322 const String& message = String::Handle(String::New(buffer));
371 const Object& obj = Object::Handle(ApiError::New(message)); 323 const Object& obj = Object::Handle(ApiError::New(message));
372 return Api::NewLocalHandle(obj); 324 return Api::NewLocalHandle(obj);
373 } 325 }
374 326
375 327
328 DART_EXPORT Dart_Handle Dart_PropagateError(Dart_Handle handle) {
329 Isolate* isolate = Isolate::Current();
330 CHECK_ISOLATE(isolate);
331 const Object& error = Object::Handle(Api::UnwrapHandle(handle));
332 if (!error.IsError()) {
333 return Api::NewError(
334 "%s expects argument 'handle' to be an error handle. "
335 "Did you forget to check Dart_IsError first?",
336 CURRENT_FUNC);
337 }
338 if (isolate->top_exit_frame_info() == 0) {
339 // There are no dart frames on the stack so it would be illegal to
340 // propagate an error here.
341 return Api::NewError("No Dart frames on stack, cannot propagate error.");
342 }
343
344 // Unwind all the API scopes till the exit frame before propagating.
345 ApiState* state = isolate->api_state();
346 ASSERT(state != NULL);
347 state->UnwindScopes(isolate->top_exit_frame_info());
348 Exceptions::PropagateError(error);
349 UNREACHABLE();
350
351 return Api::NewError("Cannot reach here. Internal error.");
352 }
353
354
376 DART_EXPORT void _Dart_ReportErrorHandle(const char* file, 355 DART_EXPORT void _Dart_ReportErrorHandle(const char* file,
377 int line, 356 int line,
378 const char* handle, 357 const char* handle,
379 const char* message) { 358 const char* message) {
380 fprintf(stderr, "%s:%d: error handle: '%s':\n '%s'\n", 359 fprintf(stderr, "%s:%d: error handle: '%s':\n '%s'\n",
381 file, line, handle, message); 360 file, line, handle, message);
382 OS::Abort(); 361 OS::Abort();
383 } 362 }
384 363
385 364
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
493 472
494 // --- Isolates --- 473 // --- Isolates ---
495 474
496 475
497 DART_EXPORT Dart_Isolate Dart_CreateIsolate(const char* name_prefix, 476 DART_EXPORT Dart_Isolate Dart_CreateIsolate(const char* name_prefix,
498 const uint8_t* snapshot, 477 const uint8_t* snapshot,
499 void* callback_data, 478 void* callback_data,
500 char** error) { 479 char** error) {
501 Isolate* isolate = Dart::CreateIsolate(name_prefix); 480 Isolate* isolate = Dart::CreateIsolate(name_prefix);
502 assert(isolate != NULL); 481 assert(isolate != NULL);
503 LongJump* base = isolate->long_jump_base(); 482 DARTSCOPE_NOCHECKS(isolate);
504 LongJump jump; 483 const Error& error_obj =
505 isolate->set_long_jump_base(&jump); 484 Error::Handle(Dart::InitializeIsolate(snapshot, callback_data));
506 if (setjmp(*jump.Set()) == 0) { 485 if (error_obj.IsNull()) {
507 Dart::InitializeIsolate(snapshot, callback_data);
508 START_TIMER(time_total_runtime); 486 START_TIMER(time_total_runtime);
509 isolate->set_long_jump_base(base);
510 return reinterpret_cast<Dart_Isolate>(isolate); 487 return reinterpret_cast<Dart_Isolate>(isolate);
511 } else { 488 } else {
512 { 489 *error = strdup(error_obj.ToErrorCString());
513 DARTSCOPE_NOCHECKS(isolate);
514 const Error& error_obj =
515 Error::Handle(isolate->object_store()->sticky_error());
516 *error = strdup(error_obj.ToErrorCString());
517 }
518 Dart::ShutdownIsolate(); 490 Dart::ShutdownIsolate();
491 return reinterpret_cast<Dart_Isolate>(NULL);
519 } 492 }
520 return reinterpret_cast<Dart_Isolate>(NULL);
521 } 493 }
522 494
523 495
524 DART_EXPORT void Dart_ShutdownIsolate() { 496 DART_EXPORT void Dart_ShutdownIsolate() {
525 CHECK_ISOLATE(Isolate::Current()); 497 CHECK_ISOLATE(Isolate::Current());
526 STOP_TIMER(time_total_runtime); 498 STOP_TIMER(time_total_runtime);
527 Dart::ShutdownIsolate(); 499 Dart::ShutdownIsolate();
528 } 500 }
529 501
530 502
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
629 Dart_MessageNotifyCallback message_notify_callback) { 601 Dart_MessageNotifyCallback message_notify_callback) {
630 Isolate* isolate = Isolate::Current(); 602 Isolate* isolate = Isolate::Current();
631 CHECK_ISOLATE(isolate); 603 CHECK_ISOLATE(isolate);
632 isolate->set_message_notify_callback(message_notify_callback); 604 isolate->set_message_notify_callback(message_notify_callback);
633 } 605 }
634 606
635 607
636 DART_EXPORT Dart_Handle Dart_RunLoop() { 608 DART_EXPORT Dart_Handle Dart_RunLoop() {
637 Isolate* isolate = Isolate::Current(); 609 Isolate* isolate = Isolate::Current();
638 DARTSCOPE(isolate); 610 DARTSCOPE(isolate);
639 611 const Object& obj = Object::Handle(isolate->StandardRunLoop());
640 LongJump* base = isolate->long_jump_base(); 612 if (obj.IsError()) {
641 LongJump jump; 613 return Api::NewLocalHandle(obj);
642 Dart_Handle result;
643 isolate->set_long_jump_base(&jump);
644 if (setjmp(*jump.Set()) == 0) {
645 const Object& obj = Object::Handle(isolate->StandardRunLoop());
646 if (obj.IsError()) {
647 result = Api::NewLocalHandle(obj);
648 } else {
649 ASSERT(obj.IsNull());
650 result = Api::Success();
651 }
652 } else {
653 SetupErrorResult(&result);
654 } 614 }
655 isolate->set_long_jump_base(base); 615 ASSERT(obj.IsNull());
656 return result; 616 return Api::Success();
657 } 617 }
658 618
659 619
660 static RawInstance* DeserializeMessage(void* data) { 620 static RawInstance* DeserializeMessage(void* data) {
661 // Create a snapshot object using the buffer. 621 // Create a snapshot object using the buffer.
662 const Snapshot* snapshot = Snapshot::SetupFromBuffer(data); 622 const Snapshot* snapshot = Snapshot::SetupFromBuffer(data);
663 ASSERT(snapshot->IsMessageSnapshot()); 623 ASSERT(snapshot->IsMessageSnapshot());
664 624
665 // Read object back from the snapshot. 625 // Read object back from the snapshot.
666 SnapshotReader reader(snapshot, Isolate::Current()); 626 SnapshotReader reader(snapshot, Isolate::Current());
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
786 // function resolution by class name and function name more concise. 746 // function resolution by class name and function name more concise.
787 const Function& function = Function::Handle( 747 const Function& function = Function::Handle(
788 Resolver::ResolveStatic(Library::Handle(Library::CoreLibrary()), 748 Resolver::ResolveStatic(Library::Handle(Library::CoreLibrary()),
789 class_name, 749 class_name,
790 function_name, 750 function_name,
791 kNumArguments, 751 kNumArguments,
792 kNoArgumentNames, 752 kNoArgumentNames,
793 Resolver::kIsQualified)); 753 Resolver::kIsQualified));
794 GrowableArray<const Object*> arguments(kNumArguments); 754 GrowableArray<const Object*> arguments(kNumArguments);
795 arguments.Add(&Integer::Handle(Integer::New(port_id))); 755 arguments.Add(&Integer::Handle(Integer::New(port_id)));
796 Dart_Handle result; 756 const Object& result = Object::Handle(
797 InvokeStatic(isolate, function, arguments, &result); 757 DartEntry::InvokeStatic(function, arguments, kNoArgumentNames));
798 return result; 758 return Api::NewLocalHandle(result);
799 } 759 }
800 760
801 761
802 DART_EXPORT Dart_Handle Dart_GetReceivePort(Dart_Port port_id) { 762 DART_EXPORT Dart_Handle Dart_GetReceivePort(Dart_Port port_id) {
803 Isolate* isolate = Isolate::Current(); 763 Isolate* isolate = Isolate::Current();
804 DARTSCOPE(isolate); 764 DARTSCOPE(isolate);
805 const String& class_name = 765 const String& class_name =
806 String::Handle(String::NewSymbol("ReceivePortImpl")); 766 String::Handle(String::NewSymbol("ReceivePortImpl"));
807 const String& function_name = 767 const String& function_name =
808 String::Handle(String::NewSymbol("_get_or_create")); 768 String::Handle(String::NewSymbol("_get_or_create"));
809 const int kNumArguments = 1; 769 const int kNumArguments = 1;
810 const Array& kNoArgumentNames = Array::Handle(); 770 const Array& kNoArgumentNames = Array::Handle();
811 const Function& function = Function::Handle( 771 const Function& function = Function::Handle(
812 Resolver::ResolveStatic(Library::Handle(Library::CoreLibrary()), 772 Resolver::ResolveStatic(Library::Handle(Library::CoreLibrary()),
813 class_name, 773 class_name,
814 function_name, 774 function_name,
815 kNumArguments, 775 kNumArguments,
816 kNoArgumentNames, 776 kNoArgumentNames,
817 Resolver::kIsQualified)); 777 Resolver::kIsQualified));
818 GrowableArray<const Object*> arguments(kNumArguments); 778 GrowableArray<const Object*> arguments(kNumArguments);
819 arguments.Add(&Integer::Handle(Integer::New(port_id))); 779 arguments.Add(&Integer::Handle(Integer::New(port_id)));
820 Dart_Handle result; 780 const Object& result = Object::Handle(
821 InvokeStatic(isolate, function, arguments, &result); 781 DartEntry::InvokeStatic(function, arguments, kNoArgumentNames));
822 return result; 782 return Api::NewLocalHandle(result);
823 } 783 }
824 784
825 785
826 DART_EXPORT Dart_Port Dart_GetMainPortId() { 786 DART_EXPORT Dart_Port Dart_GetMainPortId() {
827 Isolate* isolate = Isolate::Current(); 787 Isolate* isolate = Isolate::Current();
828 CHECK_ISOLATE(isolate); 788 CHECK_ISOLATE(isolate);
829 return isolate->main_port(); 789 return isolate->main_port();
830 } 790 }
831 791
832 // --- Scopes ---- 792 // --- Scopes ----
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
869 const Object& obj = Object::Handle(Api::UnwrapHandle(object)); 829 const Object& obj = Object::Handle(Api::UnwrapHandle(object));
870 return obj.IsNull(); 830 return obj.IsNull();
871 } 831 }
872 832
873 833
874 DART_EXPORT Dart_Handle Dart_ObjectEquals(Dart_Handle obj1, Dart_Handle obj2, 834 DART_EXPORT Dart_Handle Dart_ObjectEquals(Dart_Handle obj1, Dart_Handle obj2,
875 bool* value) { 835 bool* value) {
876 DARTSCOPE(Isolate::Current()); 836 DARTSCOPE(Isolate::Current());
877 const Instance& expected = Instance::CheckedHandle(Api::UnwrapHandle(obj1)); 837 const Instance& expected = Instance::CheckedHandle(Api::UnwrapHandle(obj1));
878 const Instance& actual = Instance::CheckedHandle(Api::UnwrapHandle(obj2)); 838 const Instance& actual = Instance::CheckedHandle(Api::UnwrapHandle(obj2));
879 const Instance& result = 839 const Object& result =
880 Instance::Handle(DartLibraryCalls::Equals(expected, actual)); 840 Object::Handle(DartLibraryCalls::Equals(expected, actual));
881 if (result.IsBool()) { 841 if (result.IsBool()) {
882 Bool& b = Bool::Handle(); 842 Bool& b = Bool::Handle();
883 b ^= result.raw(); 843 b ^= result.raw();
884 *value = b.value(); 844 *value = b.value();
885 return Api::Success(); 845 return Api::Success();
886 } else if (result.IsError()) { 846 } else if (result.IsError()) {
887 return Api::NewLocalHandle(result); 847 return Api::NewLocalHandle(result);
888 } else { 848 } else {
889 return Api::NewError("Expected boolean result from =="); 849 return Api::NewError("Expected boolean result from ==");
890 } 850 }
(...skipping 508 matching lines...) Expand 10 before | Expand all | Expand 10 after
1399 } 1359 }
1400 if (obj.IsArray()) { 1360 if (obj.IsArray()) {
1401 Array& array_obj = Array::Handle(); 1361 Array& array_obj = Array::Handle();
1402 array_obj ^= obj.raw(); 1362 array_obj ^= obj.raw();
1403 *len = array_obj.Length(); 1363 *len = array_obj.Length();
1404 return Api::Success(); 1364 return Api::Success();
1405 } 1365 }
1406 // TODO(5526318): Make access to GrowableObjectArray more efficient. 1366 // TODO(5526318): Make access to GrowableObjectArray more efficient.
1407 // Now check and handle a dart object that implements the List interface. 1367 // Now check and handle a dart object that implements the List interface.
1408 const Instance& instance = Instance::Handle(GetListInstance(isolate, obj)); 1368 const Instance& instance = Instance::Handle(GetListInstance(isolate, obj));
1409 if (!instance.IsNull()) { 1369 if (instance.IsNull()) {
1410 String& name = String::Handle(String::New("length")); 1370 return Api::NewError("Object does not implement the List inteface");
1411 name = Field::GetterName(name); 1371 }
1412 const Function& function = Function::Handle( 1372 String& name = String::Handle(String::New("length"));
1413 Resolver::ResolveDynamic(instance, name, 1, 0)); 1373 name = Field::GetterName(name);
1414 if (!function.IsNull()) { 1374 const Function& function = Function::Handle(
1415 GrowableArray<const Object*> args(0); 1375 Resolver::ResolveDynamic(instance, name, 1, 0));
1416 LongJump* base = isolate->long_jump_base(); 1376 if (function.IsNull()) {
1417 LongJump jump; 1377 return Api::NewError("List object does not have a 'length' field.");
1418 isolate->set_long_jump_base(&jump); 1378 }
1419 Dart_Handle result; 1379
1420 if (setjmp(*jump.Set()) == 0) { 1380 GrowableArray<const Object*> args(0);
1421 const Array& kNoArgumentNames = Array::Handle(); 1381 const Array& kNoArgumentNames = Array::Handle();
1422 const Instance& retval = Instance::Handle( 1382 const Object& retval = Object::Handle(
1423 DartEntry::InvokeDynamic(instance, 1383 DartEntry::InvokeDynamic(instance, function, args, kNoArgumentNames));
1424 function, 1384 if (retval.IsSmi() || retval.IsMint()) {
1425 args, 1385 Integer& integer = Integer::Handle();
1426 kNoArgumentNames)); 1386 integer ^= retval.raw();
1427 result = Api::Success(); 1387 *len = integer.AsInt64Value();
1428 if (retval.IsSmi() || retval.IsMint()) { 1388 return Api::Success();
1429 Integer& integer = Integer::Handle(); 1389 } else if (retval.IsBigint()) {
1430 integer ^= retval.raw(); 1390 Bigint& bigint = Bigint::Handle();
1431 *len = integer.AsInt64Value(); 1391 bigint ^= retval.raw();
1432 } else if (retval.IsBigint()) { 1392 if (BigintOperations::FitsIntoInt64(bigint)) {
1433 Bigint& bigint = Bigint::Handle(); 1393 *len = BigintOperations::ToInt64(bigint);
1434 bigint ^= retval.raw(); 1394 return Api::Success();
1435 if (BigintOperations::FitsIntoInt64(bigint)) { 1395 } else {
1436 *len = BigintOperations::ToInt64(bigint); 1396 return Api::NewError("Length of List object is greater than the "
1437 } else { 1397 "maximum value that 'len' parameter can hold");
1438 result =
1439 Api::NewError("Length of List object is greater than the "
1440 "maximum value that 'len' parameter can hold");
1441 }
1442 } else if (retval.IsError()) {
1443 result = Api::NewLocalHandle(retval);
1444 } else {
1445 result = Api::NewError("Length of List object is not an integer");
1446 }
1447 } else {
1448 SetupErrorResult(&result);
1449 }
1450 isolate->set_long_jump_base(base);
1451 return result;
1452 } 1398 }
1399 } else if (retval.IsError()) {
1400 return Api::NewLocalHandle(retval);
1401 } else {
1402 return Api::NewError("Length of List object is not an integer");
1453 } 1403 }
1454 return Api::NewError("Object does not implement the 'List' inteface");
1455 }
1456
1457 static RawObject* GetListAt(Isolate* isolate,
1458 const Instance& instance,
1459 const Integer& index,
1460 const Function& function,
1461 Dart_Handle* result) {
1462 ASSERT(isolate != NULL);
1463 ASSERT(result != NULL);
1464 LongJump* base = isolate->long_jump_base();
1465 LongJump jump;
1466 isolate->set_long_jump_base(&jump);
1467 if (setjmp(*jump.Set()) == 0) {
1468 Instance& retval = Instance::Handle();
1469 GrowableArray<const Object*> args(0);
1470 args.Add(&index);
1471 const Array& kNoArgumentNames = Array::Handle();
1472 retval = DartEntry::InvokeDynamic(instance,
1473 function,
1474 args,
1475 kNoArgumentNames);
1476 if (retval.IsError()) {
1477 *result = Api::NewLocalHandle(retval);
1478 } else {
1479 *result = Api::Success();
1480 }
1481 isolate->set_long_jump_base(base);
1482 return retval.raw();
1483 }
1484 SetupErrorResult(result);
1485 isolate->set_long_jump_base(base);
1486 return Object::null();
1487 } 1404 }
1488 1405
1489 1406
1490 DART_EXPORT Dart_Handle Dart_ListGetAt(Dart_Handle list, intptr_t index) { 1407 DART_EXPORT Dart_Handle Dart_ListGetAt(Dart_Handle list, intptr_t index) {
1491 Isolate* isolate = Isolate::Current(); 1408 Isolate* isolate = Isolate::Current();
1492 DARTSCOPE(isolate); 1409 DARTSCOPE(isolate);
1493 const Object& obj = Object::Handle(Api::UnwrapHandle(list)); 1410 const Object& obj = Object::Handle(Api::UnwrapHandle(list));
1494 if (obj.IsArray()) { 1411 if (obj.IsArray()) {
1495 Array& array_obj = Array::Handle(); 1412 Array& array_obj = Array::Handle();
1496 array_obj ^= obj.raw(); 1413 array_obj ^= obj.raw();
1497 if ((index >= 0) && (index < array_obj.Length())) { 1414 if ((index >= 0) && (index < array_obj.Length())) {
1498 const Object& element = Object::Handle(array_obj.At(index)); 1415 const Object& element = Object::Handle(array_obj.At(index));
1499 return Api::NewLocalHandle(element); 1416 return Api::NewLocalHandle(element);
1500 } 1417 }
1501 return Api::NewError("Invalid index passed in to access array element"); 1418 return Api::NewError("Invalid index passed in to access array element");
1502 } 1419 }
1503 // TODO(5526318): Make access to GrowableObjectArray more efficient. 1420 // TODO(5526318): Make access to GrowableObjectArray more efficient.
1504 // Now check and handle a dart object that implements the List interface. 1421 // Now check and handle a dart object that implements the List interface.
1505 const Instance& instance = Instance::Handle(GetListInstance(isolate, obj)); 1422 const Instance& instance = Instance::Handle(GetListInstance(isolate, obj));
1506 if (!instance.IsNull()) { 1423 if (!instance.IsNull()) {
1507 String& name = String::Handle(String::New("[]")); 1424 String& name = String::Handle(String::New("[]"));
1508 const Function& function = Function::Handle( 1425 const Function& function = Function::Handle(
1509 Resolver::ResolveDynamic(instance, name, 2, 0)); 1426 Resolver::ResolveDynamic(instance, name, 2, 0));
1510 if (!function.IsNull()) { 1427 if (!function.IsNull()) {
1511 Object& element = Object::Handle(); 1428 GrowableArray<const Object*> args(1);
1512 Integer& indexobj = Integer::Handle(); 1429 Integer& indexobj = Integer::Handle();
1513 Dart_Handle result;
1514 indexobj = Integer::New(index); 1430 indexobj = Integer::New(index);
1515 element = GetListAt(isolate, instance, indexobj, function, &result); 1431 args.Add(&indexobj);
1516 if (::Dart_IsError(result)) { 1432 const Array& kNoArgumentNames = Array::Handle();
1517 return result; // Error condition. 1433 const Object& result = Object::Handle(
1518 } 1434 DartEntry::InvokeDynamic(instance, function, args, kNoArgumentNames));
1519 return Api::NewLocalHandle(element); 1435 return Api::NewLocalHandle(result);
1520 } 1436 }
1521 } 1437 }
1522 return Api::NewError("Object does not implement the 'List' interface"); 1438 return Api::NewError("Object does not implement the 'List' interface");
1523 } 1439 }
1524 1440
1525 1441
1526 static void SetListAt(Isolate* isolate,
1527 const Instance& instance,
1528 const Integer& index,
1529 const Object& value,
1530 const Function& function,
1531 Dart_Handle* result) {
1532 ASSERT(isolate != NULL);
1533 ASSERT(result != NULL);
1534 LongJump* base = isolate->long_jump_base();
1535 LongJump jump;
1536 isolate->set_long_jump_base(&jump);
1537 if (setjmp(*jump.Set()) == 0) {
1538 GrowableArray<const Object*> args(1);
1539 args.Add(&index);
1540 args.Add(&value);
1541 Instance& retval = Instance::Handle();
1542 const Array& kNoArgumentNames = Array::Handle();
1543 retval = DartEntry::InvokeDynamic(instance,
1544 function,
1545 args,
1546 kNoArgumentNames);
1547 if (retval.IsError()) {
1548 *result = Api::NewLocalHandle(retval);
1549 } else {
1550 *result = Api::Success();
1551 }
1552 } else {
1553 SetupErrorResult(result);
1554 }
1555 isolate->set_long_jump_base(base);
1556 }
1557
1558
1559 DART_EXPORT Dart_Handle Dart_ListSetAt(Dart_Handle list, 1442 DART_EXPORT Dart_Handle Dart_ListSetAt(Dart_Handle list,
1560 intptr_t index, 1443 intptr_t index,
1561 Dart_Handle value) { 1444 Dart_Handle value) {
1562 Isolate* isolate = Isolate::Current(); 1445 Isolate* isolate = Isolate::Current();
1563 DARTSCOPE(isolate); 1446 DARTSCOPE(isolate);
1564 const Object& obj = Object::Handle(Api::UnwrapHandle(list)); 1447 const Object& obj = Object::Handle(Api::UnwrapHandle(list));
1565 if (obj.IsArray()) { 1448 if (obj.IsArray()) {
1566 if (obj.IsImmutableArray()) { 1449 if (obj.IsImmutableArray()) {
1567 return Api::NewError("Cannot modify immutable array"); 1450 return Api::NewError("Cannot modify immutable array");
1568 } 1451 }
1569 Array& array_obj = Array::Handle(); 1452 Array& array_obj = Array::Handle();
1570 array_obj ^= obj.raw(); 1453 array_obj ^= obj.raw();
1571 const Object& value_obj = Object::Handle(Api::UnwrapHandle(value)); 1454 const Object& value_obj = Object::Handle(Api::UnwrapHandle(value));
1572 if ((index >= 0) && (index < array_obj.Length())) { 1455 if ((index >= 0) && (index < array_obj.Length())) {
1573 array_obj.SetAt(index, value_obj); 1456 array_obj.SetAt(index, value_obj);
1574 return Api::Success(); 1457 return Api::Success();
1575 } 1458 }
1576 return Api::NewError("Invalid index passed in to set array element"); 1459 return Api::NewError("Invalid index passed in to set array element");
1577 } 1460 }
1578 // TODO(5526318): Make access to GrowableObjectArray more efficient. 1461 // TODO(5526318): Make access to GrowableObjectArray more efficient.
1579 // Now check and handle a dart object that implements the List interface. 1462 // Now check and handle a dart object that implements the List interface.
1580 const Instance& instance = Instance::Handle(GetListInstance(isolate, obj)); 1463 const Instance& instance = Instance::Handle(GetListInstance(isolate, obj));
1581 if (!instance.IsNull()) { 1464 if (!instance.IsNull()) {
1582 String& name = String::Handle(String::New("[]=")); 1465 String& name = String::Handle(String::New("[]="));
1583 const Function& function = Function::Handle( 1466 const Function& function = Function::Handle(
1584 Resolver::ResolveDynamic(instance, name, 3, 0)); 1467 Resolver::ResolveDynamic(instance, name, 3, 0));
1585 if (!function.IsNull()) { 1468 if (!function.IsNull()) {
1586 Dart_Handle result;
1587 const Integer& index_obj = Integer::Handle(Integer::New(index)); 1469 const Integer& index_obj = Integer::Handle(Integer::New(index));
1588 const Object& value_obj = Object::Handle(Api::UnwrapHandle(value)); 1470 const Object& value_obj = Object::Handle(Api::UnwrapHandle(value));
1589 SetListAt(isolate, instance, index_obj, value_obj, function, &result); 1471 GrowableArray<const Object*> args(2);
1590 return result; 1472 args.Add(&index_obj);
1473 args.Add(&value_obj);
1474 const Array& kNoArgumentNames = Array::Handle();
1475 const Object& result = Object::Handle(
1476 DartEntry::InvokeDynamic(instance, function, args, kNoArgumentNames));
1477 return Api::NewLocalHandle(result);
1591 } 1478 }
1592 } 1479 }
1593 return Api::NewError("Object does not implement the 'List' interface"); 1480 return Api::NewError("Object does not implement the 'List' interface");
1594 } 1481 }
1595 1482
1596 1483
1597 DART_EXPORT Dart_Handle Dart_ListGetAsBytes(Dart_Handle list, 1484 DART_EXPORT Dart_Handle Dart_ListGetAsBytes(Dart_Handle list,
1598 intptr_t offset, 1485 intptr_t offset,
1599 uint8_t* native_array, 1486 uint8_t* native_array,
1600 intptr_t length) { 1487 intptr_t length) {
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
1633 return Api::NewError("Invalid length passed in to access array elements"); 1520 return Api::NewError("Invalid length passed in to access array elements");
1634 } 1521 }
1635 // TODO(5526318): Make access to GrowableObjectArray more efficient. 1522 // TODO(5526318): Make access to GrowableObjectArray more efficient.
1636 // Now check and handle a dart object that implements the List interface. 1523 // Now check and handle a dart object that implements the List interface.
1637 const Instance& instance = Instance::Handle(GetListInstance(isolate, obj)); 1524 const Instance& instance = Instance::Handle(GetListInstance(isolate, obj));
1638 if (!instance.IsNull()) { 1525 if (!instance.IsNull()) {
1639 String& name = String::Handle(String::New("[]")); 1526 String& name = String::Handle(String::New("[]"));
1640 const Function& function = Function::Handle( 1527 const Function& function = Function::Handle(
1641 Resolver::ResolveDynamic(instance, name, 2, 0)); 1528 Resolver::ResolveDynamic(instance, name, 2, 0));
1642 if (!function.IsNull()) { 1529 if (!function.IsNull()) {
1643 Object& element = Object::Handle(); 1530 Object& result = Object::Handle();
1644 Integer& intobj = Integer::Handle(); 1531 Integer& intobj = Integer::Handle();
1645 Dart_Handle result;
1646 for (int i = 0; i < length; i++) { 1532 for (int i = 0; i < length; i++) {
1647 intobj = Integer::New(offset + i); 1533 intobj = Integer::New(offset + i);
1648 element = GetListAt(isolate, instance, intobj, function, &result); 1534 GrowableArray<const Object*> args(1);
1649 if (::Dart_IsError(result)) { 1535 args.Add(&intobj);
1650 return result; // Error condition. 1536 const Array& kNoArgumentNames = Array::Handle();
1537 result = DartEntry::InvokeDynamic(
1538 instance, function, args, kNoArgumentNames);
1539 if (result.IsError()) {
1540 return Api::NewLocalHandle(result);
1651 } 1541 }
1652 if (!element.IsInteger()) { 1542 if (!result.IsInteger()) {
1653 return Api::NewError("%s expects the argument 'list' to be " 1543 return Api::NewError("%s expects the argument 'list' to be "
1654 "a List of int", CURRENT_FUNC); 1544 "a List of int", CURRENT_FUNC);
1655 } 1545 }
1656 intobj ^= element.raw(); 1546 intobj ^= result.raw();
1657 ASSERT(intobj.AsInt64Value() <= 0xff); 1547 ASSERT(intobj.AsInt64Value() <= 0xff);
1658 // TODO(hpayer): value should always be smaller then 0xff. Add error 1548 // TODO(hpayer): value should always be smaller then 0xff. Add error
1659 // handling. 1549 // handling.
1660 native_array[i] = static_cast<uint8_t>(intobj.AsInt64Value() & 0xff); 1550 native_array[i] = static_cast<uint8_t>(intobj.AsInt64Value() & 0xff);
1661 } 1551 }
1662 return Api::Success(); 1552 return Api::Success();
1663 } 1553 }
1664 } 1554 }
1665 return Api::NewError("Object does not implement the 'List' interface"); 1555 return Api::NewError("Object does not implement the 'List' interface");
1666 } 1556 }
(...skipping 27 matching lines...) Expand all
1694 integer = Integer::New(native_array[i]); 1584 integer = Integer::New(native_array[i]);
1695 array_obj.SetAt(offset + i, integer); 1585 array_obj.SetAt(offset + i, integer);
1696 } 1586 }
1697 return Api::Success(); 1587 return Api::Success();
1698 } 1588 }
1699 return Api::NewError("Invalid length passed in to set array elements"); 1589 return Api::NewError("Invalid length passed in to set array elements");
1700 } 1590 }
1701 // TODO(5526318): Make access to GrowableObjectArray more efficient. 1591 // TODO(5526318): Make access to GrowableObjectArray more efficient.
1702 // Now check and handle a dart object that implements the List interface. 1592 // Now check and handle a dart object that implements the List interface.
1703 const Instance& instance = Instance::Handle(GetListInstance(isolate, obj)); 1593 const Instance& instance = Instance::Handle(GetListInstance(isolate, obj));
1704 Dart_Handle result;
1705 if (!instance.IsNull()) { 1594 if (!instance.IsNull()) {
1706 String& name = String::Handle(String::New("[]=")); 1595 String& name = String::Handle(String::New("[]="));
1707 const Function& function = Function::Handle( 1596 const Function& function = Function::Handle(
1708 Resolver::ResolveDynamic(instance, name, 3, 0)); 1597 Resolver::ResolveDynamic(instance, name, 3, 0));
1709 if (!function.IsNull()) { 1598 if (!function.IsNull()) {
1710 Integer& indexobj = Integer::Handle(); 1599 Integer& indexobj = Integer::Handle();
1711 Integer& valueobj = Integer::Handle(); 1600 Integer& valueobj = Integer::Handle();
1712 for (int i = 0; i < length; i++) { 1601 for (int i = 0; i < length; i++) {
1713 indexobj = Integer::New(offset + i); 1602 indexobj = Integer::New(offset + i);
1714 valueobj = Integer::New(native_array[i]); 1603 valueobj = Integer::New(native_array[i]);
1715 SetListAt(isolate, instance, indexobj, valueobj, function, &result); 1604 GrowableArray<const Object*> args(2);
1716 if (::Dart_IsError(result)) { 1605 args.Add(&indexobj);
1717 return result; // Error condition. 1606 args.Add(&valueobj);
1607 const Array& kNoArgumentNames = Array::Handle();
1608 const Object& result = Object::Handle(
1609 DartEntry::InvokeDynamic(
1610 instance, function, args, kNoArgumentNames));
1611 if (result.IsError()) {
1612 return Api::NewLocalHandle(result);
1718 } 1613 }
1719 } 1614 }
1720 return Api::Success(); 1615 return Api::Success();
1721 } 1616 }
1722 } 1617 }
1723 return Api::NewError("Object does not implement the 'List' interface"); 1618 return Api::NewError("Object does not implement the 'List' interface");
1724 } 1619 }
1725 1620
1726 1621
1727 // --- Byte Arrays --- 1622 // --- Byte Arrays ---
(...skipping 17 matching lines...) Expand all
1745 // --- Closures --- 1640 // --- Closures ---
1746 1641
1747 1642
1748 DART_EXPORT bool Dart_IsClosure(Dart_Handle object) { 1643 DART_EXPORT bool Dart_IsClosure(Dart_Handle object) {
1749 DARTSCOPE(Isolate::Current()); 1644 DARTSCOPE(Isolate::Current());
1750 const Object& obj = Object::Handle(Api::UnwrapHandle(object)); 1645 const Object& obj = Object::Handle(Api::UnwrapHandle(object));
1751 return obj.IsClosure(); 1646 return obj.IsClosure();
1752 } 1647 }
1753 1648
1754 1649
1755 // NOTE: Need to pass 'result' as a parameter here in order to avoid
1756 // warning: variable 'result' might be clobbered by 'longjmp' or 'vfork'
1757 // which shows up because of the use of setjmp.
1758 static void InvokeClosure(Isolate* isolate,
1759 const Closure& closure,
1760 GrowableArray<const Object*>& args,
1761 Dart_Handle* result) {
1762 ASSERT(isolate != NULL);
1763 LongJump* base = isolate->long_jump_base();
1764 LongJump jump;
1765 isolate->set_long_jump_base(&jump);
1766 if (setjmp(*jump.Set()) == 0) {
1767 const Array& kNoArgumentNames = Array::Handle();
1768 const Instance& retval = Instance::Handle(
1769 DartEntry::InvokeClosure(closure, args, kNoArgumentNames));
1770 *result = Api::NewLocalHandle(retval);
1771 } else {
1772 SetupErrorResult(result);
1773 }
1774 isolate->set_long_jump_base(base);
1775 }
1776
1777
1778 DART_EXPORT Dart_Handle Dart_InvokeClosure(Dart_Handle closure, 1650 DART_EXPORT Dart_Handle Dart_InvokeClosure(Dart_Handle closure,
1779 int number_of_arguments, 1651 int number_of_arguments,
1780 Dart_Handle* arguments) { 1652 Dart_Handle* arguments) {
1781 Isolate* isolate = Isolate::Current(); 1653 Isolate* isolate = Isolate::Current();
1782 DARTSCOPE(isolate); 1654 DARTSCOPE(isolate);
1783 const Object& obj = Object::Handle(Api::UnwrapHandle(closure)); 1655 const Object& obj = Object::Handle(Api::UnwrapHandle(closure));
1784 if (obj.IsNull()) { 1656 if (obj.IsNull()) {
1785 return Api::NewError("Null object passed in to invoke closure"); 1657 return Api::NewError("Null object passed in to invoke closure");
1786 } 1658 }
1787 if (!obj.IsClosure()) { 1659 if (!obj.IsClosure()) {
1788 return Api::NewError("Invalid closure passed to invoke closure"); 1660 return Api::NewError("Invalid closure passed to invoke closure");
1789 } 1661 }
1790 ASSERT(ClassFinalizer::AllClassesFinalized()); 1662 ASSERT(ClassFinalizer::AllClassesFinalized());
1791 1663
1792 // Now try to invoke the closure. 1664 // Now try to invoke the closure.
1793 Closure& closure_obj = Closure::Handle(); 1665 Closure& closure_obj = Closure::Handle();
1794 closure_obj ^= obj.raw(); 1666 closure_obj ^= obj.raw();
1795 Dart_Handle retval;
1796 GrowableArray<const Object*> dart_arguments(number_of_arguments); 1667 GrowableArray<const Object*> dart_arguments(number_of_arguments);
1797 for (int i = 0; i < number_of_arguments; i++) { 1668 for (int i = 0; i < number_of_arguments; i++) {
1798 const Object& arg = Object::Handle(Api::UnwrapHandle(arguments[i])); 1669 const Object& arg = Object::Handle(Api::UnwrapHandle(arguments[i]));
1799 dart_arguments.Add(&arg); 1670 dart_arguments.Add(&arg);
1800 } 1671 }
1801 InvokeClosure(isolate, closure_obj, dart_arguments, &retval); 1672 const Array& kNoArgumentNames = Array::Handle();
1802 return retval; 1673 const Object& result = Object::Handle(
1674 DartEntry::InvokeClosure(closure_obj, dart_arguments, kNoArgumentNames));
1675 return Api::NewLocalHandle(result);
1803 } 1676 }
1804 1677
1805 1678
1806 DART_EXPORT int64_t Dart_ClosureSmrck(Dart_Handle object) { 1679 DART_EXPORT int64_t Dart_ClosureSmrck(Dart_Handle object) {
1807 DARTSCOPE(Isolate::Current()); 1680 DARTSCOPE(Isolate::Current());
1808 const Closure& obj = Closure::CheckedHandle(Api::UnwrapHandle(object)); 1681 const Closure& obj = Closure::CheckedHandle(Api::UnwrapHandle(object));
1809 const Integer& smrck = Integer::Handle(obj.smrck()); 1682 const Integer& smrck = Integer::Handle(obj.smrck());
1810 return smrck.IsNull() ? 0 : smrck.AsInt64Value(); 1683 return smrck.IsNull() ? 0 : smrck.AsInt64Value();
1811 } 1684 }
1812 1685
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
1869 OS::SNPrint(msg, (length + 1), format, 1742 OS::SNPrint(msg, (length + 1), format,
1870 class_name.ToCString(), function_name.ToCString()); 1743 class_name.ToCString(), function_name.ToCString());
1871 } 1744 }
1872 return Api::NewError(msg); 1745 return Api::NewError(msg);
1873 } 1746 }
1874 GrowableArray<const Object*> dart_arguments(number_of_arguments); 1747 GrowableArray<const Object*> dart_arguments(number_of_arguments);
1875 for (int i = 0; i < number_of_arguments; i++) { 1748 for (int i = 0; i < number_of_arguments; i++) {
1876 const Object& arg = Object::Handle(Api::UnwrapHandle(arguments[i])); 1749 const Object& arg = Object::Handle(Api::UnwrapHandle(arguments[i]));
1877 dart_arguments.Add(&arg); 1750 dart_arguments.Add(&arg);
1878 } 1751 }
1879 Dart_Handle retval; 1752 const Array& kNoArgumentNames = Array::Handle();
1880 InvokeStatic(isolate, function, dart_arguments, &retval); 1753 const Object& result = Object::Handle(
1881 return retval; 1754 DartEntry::InvokeStatic(function, dart_arguments, kNoArgumentNames));
1755 return Api::NewLocalHandle(result);
1882 } 1756 }
1883 1757
1884 1758
1885 DART_EXPORT Dart_Handle Dart_InvokeDynamic(Dart_Handle object, 1759 DART_EXPORT Dart_Handle Dart_InvokeDynamic(Dart_Handle object,
1886 Dart_Handle function_name, 1760 Dart_Handle function_name,
1887 int number_of_arguments, 1761 int number_of_arguments,
1888 Dart_Handle* arguments) { 1762 Dart_Handle* arguments) {
1889 Isolate* isolate = Isolate::Current(); 1763 Isolate* isolate = Isolate::Current();
1890 DARTSCOPE(isolate); 1764 DARTSCOPE(isolate);
1891 const Object& obj = Object::Handle(Api::UnwrapHandle(object)); 1765 const Object& obj = Object::Handle(Api::UnwrapHandle(object));
(...skipping 20 matching lines...) Expand all
1912 if (function.IsNull()) { 1786 if (function.IsNull()) {
1913 // TODO(5415268): Invoke noSuchMethod instead of failing. 1787 // TODO(5415268): Invoke noSuchMethod instead of failing.
1914 OS::PrintErr("Unable to find instance function: %s\n", name.ToCString()); 1788 OS::PrintErr("Unable to find instance function: %s\n", name.ToCString());
1915 return Api::NewError("Unable to find instance function"); 1789 return Api::NewError("Unable to find instance function");
1916 } 1790 }
1917 GrowableArray<const Object*> dart_arguments(number_of_arguments); 1791 GrowableArray<const Object*> dart_arguments(number_of_arguments);
1918 for (int i = 0; i < number_of_arguments; i++) { 1792 for (int i = 0; i < number_of_arguments; i++) {
1919 const Object& arg = Object::Handle(Api::UnwrapHandle(arguments[i])); 1793 const Object& arg = Object::Handle(Api::UnwrapHandle(arguments[i]));
1920 dart_arguments.Add(&arg); 1794 dart_arguments.Add(&arg);
1921 } 1795 }
1922 Dart_Handle retval; 1796 const Array& kNoArgumentNames = Array::Handle();
1923 InvokeDynamic(isolate, receiver, function, dart_arguments, &retval); 1797 const Object& result = Object::Handle(
1924 return retval; 1798 DartEntry::InvokeDynamic(
1799 receiver, function, dart_arguments, kNoArgumentNames));
1800 return Api::NewLocalHandle(result);
1925 } 1801 }
1926 1802
1927 1803
1928 static const bool kGetter = true; 1804 static const bool kGetter = true;
1929 static const bool kSetter = false; 1805 static const bool kSetter = false;
1930 1806
1931 1807
1932 static bool UseGetterForStaticField(const Field& fld) { 1808 static bool UseGetterForStaticField(const Field& fld) {
1933 if (fld.IsNull()) { 1809 if (fld.IsNull()) {
1934 return true; 1810 return true;
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
2021 const Object& obj = Object::Handle(Api::UnwrapHandle(result)); 1897 const Object& obj = Object::Handle(Api::UnwrapHandle(result));
2022 if (obj.IsField()) { 1898 if (obj.IsField()) {
2023 Field& fld = Field::Handle(); 1899 Field& fld = Field::Handle();
2024 fld ^= obj.raw(); 1900 fld ^= obj.raw();
2025 retval = fld.value(); 1901 retval = fld.value();
2026 return Api::NewLocalHandle(retval); 1902 return Api::NewLocalHandle(retval);
2027 } else { 1903 } else {
2028 Function& func = Function::Handle(); 1904 Function& func = Function::Handle();
2029 func ^= obj.raw(); 1905 func ^= obj.raw();
2030 GrowableArray<const Object*> args; 1906 GrowableArray<const Object*> args;
2031 InvokeStatic(isolate, func, args, &result); 1907 const Array& kNoArgumentNames = Array::Handle();
2032 return result; 1908 const Object& result = Object::Handle(
1909 DartEntry::InvokeStatic(func, args, kNoArgumentNames));
1910 return Api::NewLocalHandle(result);
2033 } 1911 }
2034 } 1912 }
2035 1913
2036 1914
2037 // TODO(iposva): The value parameter should be documented as being an instance. 1915 // TODO(iposva): The value parameter should be documented as being an instance.
2038 // TODO(turnidge): Is this skipping the setter? 1916 // TODO(turnidge): Is this skipping the setter?
2039 DART_EXPORT Dart_Handle Dart_SetStaticField(Dart_Handle cls, 1917 DART_EXPORT Dart_Handle Dart_SetStaticField(Dart_Handle cls,
2040 Dart_Handle name, 1918 Dart_Handle name,
2041 Dart_Handle value) { 1919 Dart_Handle value) {
2042 DARTSCOPE(Isolate::Current()); 1920 DARTSCOPE(Isolate::Current());
(...skipping 25 matching lines...) Expand all
2068 } 1946 }
2069 Instance& object = Instance::Handle(); 1947 Instance& object = Instance::Handle();
2070 object ^= param.raw(); 1948 object ^= param.raw();
2071 Dart_Handle result = LookupInstanceField(object, name, kGetter); 1949 Dart_Handle result = LookupInstanceField(object, name, kGetter);
2072 if (::Dart_IsError(result)) { 1950 if (::Dart_IsError(result)) {
2073 return result; 1951 return result;
2074 } 1952 }
2075 Function& func = Function::Handle(); 1953 Function& func = Function::Handle();
2076 func ^= Api::UnwrapHandle(result); 1954 func ^= Api::UnwrapHandle(result);
2077 GrowableArray<const Object*> arguments; 1955 GrowableArray<const Object*> arguments;
2078 InvokeDynamic(isolate, object, func, arguments, &result); 1956 const Array& kNoArgumentNames = Array::Handle();
2079 return result; 1957 const Object& retval = Object::Handle(
1958 DartEntry::InvokeDynamic(object, func, arguments, kNoArgumentNames));
1959 return Api::NewLocalHandle(retval);
2080 } 1960 }
2081 1961
2082 1962
2083 DART_EXPORT Dart_Handle Dart_SetInstanceField(Dart_Handle obj, 1963 DART_EXPORT Dart_Handle Dart_SetInstanceField(Dart_Handle obj,
2084 Dart_Handle name, 1964 Dart_Handle name,
2085 Dart_Handle value) { 1965 Dart_Handle value) {
2086 Isolate* isolate = Isolate::Current(); 1966 Isolate* isolate = Isolate::Current();
2087 DARTSCOPE(isolate); 1967 DARTSCOPE(isolate);
2088 const Object& param = Object::Handle(Api::UnwrapHandle(obj)); 1968 const Object& param = Object::Handle(Api::UnwrapHandle(obj));
2089 if (param.IsNull() || !param.IsInstance()) { 1969 if (param.IsNull() || !param.IsInstance()) {
2090 return Api::NewError("Invalid object passed in to access instance field"); 1970 return Api::NewError("Invalid object passed in to access instance field");
2091 } 1971 }
2092 Instance& object = Instance::Handle(); 1972 Instance& object = Instance::Handle();
2093 object ^= param.raw(); 1973 object ^= param.raw();
2094 Dart_Handle result = LookupInstanceField(object, name, kSetter); 1974 Dart_Handle result = LookupInstanceField(object, name, kSetter);
2095 if (::Dart_IsError(result)) { 1975 if (::Dart_IsError(result)) {
2096 return result; 1976 return result;
2097 } 1977 }
2098 Function& func = Function::Handle(); 1978 Function& func = Function::Handle();
2099 func ^= Api::UnwrapHandle(result); 1979 func ^= Api::UnwrapHandle(result);
2100 GrowableArray<const Object*> arguments(1); 1980 GrowableArray<const Object*> arguments(1);
2101 const Object& arg = Object::Handle(Api::UnwrapHandle(value)); 1981 const Object& arg = Object::Handle(Api::UnwrapHandle(value));
2102 arguments.Add(&arg); 1982 arguments.Add(&arg);
2103 InvokeDynamic(isolate, object, func, arguments, &result); 1983 const Array& kNoArgumentNames = Array::Handle();
2104 return result; 1984 const Object& retval = Object::Handle(
1985 DartEntry::InvokeDynamic(object, func, arguments, kNoArgumentNames));
1986 return Api::NewLocalHandle(retval);
2105 } 1987 }
2106 1988
2107 1989
2108 DART_EXPORT Dart_Handle Dart_CreateNativeWrapperClass(Dart_Handle library, 1990 DART_EXPORT Dart_Handle Dart_CreateNativeWrapperClass(Dart_Handle library,
2109 Dart_Handle name, 1991 Dart_Handle name,
2110 int field_count) { 1992 int field_count) {
2111 Isolate* isolate = Isolate::Current(); 1993 Isolate* isolate = Isolate::Current();
2112 DARTSCOPE(isolate); 1994 DARTSCOPE(isolate);
2113 const Object& param = Object::Handle(Api::UnwrapHandle(name)); 1995 const Object& param = Object::Handle(Api::UnwrapHandle(name));
2114 if (param.IsNull() || !param.IsString() || field_count <= 0) { 1996 if (param.IsNull() || !param.IsString() || field_count <= 0) {
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
2258 const String& source, 2140 const String& source,
2259 RawScript::Kind kind, 2141 RawScript::Kind kind,
2260 Dart_Handle* result) { 2142 Dart_Handle* result) {
2261 bool update_lib_status = (kind == RawScript::kScript || 2143 bool update_lib_status = (kind == RawScript::kScript ||
2262 kind == RawScript::kLibrary); 2144 kind == RawScript::kLibrary);
2263 if (update_lib_status) { 2145 if (update_lib_status) {
2264 lib.SetLoadInProgress(); 2146 lib.SetLoadInProgress();
2265 } 2147 }
2266 const Script& script = Script::Handle(Script::New(url, source, kind)); 2148 const Script& script = Script::Handle(Script::New(url, source, kind));
2267 ASSERT(isolate != NULL); 2149 ASSERT(isolate != NULL);
2268 LongJump* base = isolate->long_jump_base(); 2150 const Error& error = Error::Handle(Compiler::Compile(lib, script));
2269 LongJump jump; 2151 if (error.IsNull()) {
2270 isolate->set_long_jump_base(&jump);
2271 if (setjmp(*jump.Set()) == 0) {
2272 Compiler::Compile(lib, script);
2273 *result = Api::NewLocalHandle(lib); 2152 *result = Api::NewLocalHandle(lib);
2274 if (update_lib_status) { 2153 if (update_lib_status) {
2275 lib.SetLoaded(); 2154 lib.SetLoaded();
2276 } 2155 }
2277 } else { 2156 } else {
2278 SetupErrorResult(result); 2157 *result = Api::NewLocalHandle(error);
2279 if (update_lib_status) { 2158 if (update_lib_status) {
2280 lib.SetLoadError(); 2159 lib.SetLoadError();
2281 } 2160 }
2282 } 2161 }
2283 isolate->set_long_jump_base(base);
2284 } 2162 }
2285 2163
2286 2164
2287 DART_EXPORT Dart_Handle Dart_LoadScript(Dart_Handle url, 2165 DART_EXPORT Dart_Handle Dart_LoadScript(Dart_Handle url,
2288 Dart_Handle source, 2166 Dart_Handle source,
2289 Dart_LibraryTagHandler handler) { 2167 Dart_LibraryTagHandler handler) {
2290 TIMERSCOPE(time_script_loading); 2168 TIMERSCOPE(time_script_loading);
2291 Isolate* isolate = Isolate::Current(); 2169 Isolate* isolate = Isolate::Current();
2292 DARTSCOPE(isolate); 2170 DARTSCOPE(isolate);
2293 const String& url_str = Api::UnwrapStringHandle(url); 2171 const String& url_str = Api::UnwrapStringHandle(url);
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
2344 return Api::NewError("%s: Unable to deserialize snapshot correctly.", 2222 return Api::NewError("%s: Unable to deserialize snapshot correctly.",
2345 CURRENT_FUNC); 2223 CURRENT_FUNC);
2346 } 2224 }
2347 library ^= tmp.raw(); 2225 library ^= tmp.raw();
2348 isolate->object_store()->set_root_library(library); 2226 isolate->object_store()->set_root_library(library);
2349 return Api::NewLocalHandle(library); 2227 return Api::NewLocalHandle(library);
2350 } 2228 }
2351 2229
2352 2230
2353 static void CompileAll(Isolate* isolate, Dart_Handle* result) { 2231 static void CompileAll(Isolate* isolate, Dart_Handle* result) {
2354 *result = Api::Success();
2355 ASSERT(isolate != NULL); 2232 ASSERT(isolate != NULL);
2356 LongJump* base = isolate->long_jump_base(); 2233 const Error& error = Error::Handle(Library::CompileAll());
2357 LongJump jump; 2234 if (error.IsNull()) {
2358 isolate->set_long_jump_base(&jump); 2235 *result = Api::Success();
2359 if (setjmp(*jump.Set()) == 0) {
2360 Library::CompileAll();
2361 } else { 2236 } else {
2362 SetupErrorResult(result); 2237 *result = Api::NewLocalHandle(error);
2363 } 2238 }
2364 isolate->set_long_jump_base(base);
2365 } 2239 }
2366 2240
2367 2241
2368 DART_EXPORT Dart_Handle Dart_CompileAll() { 2242 DART_EXPORT Dart_Handle Dart_CompileAll() {
2369 Isolate* isolate = Isolate::Current(); 2243 Isolate* isolate = Isolate::Current();
2370 DARTSCOPE(isolate); 2244 DARTSCOPE(isolate);
2371 Dart_Handle result; 2245 Dart_Handle result;
2372 const char* msg = CheckIsolateState(isolate); 2246 const char* msg = CheckIsolateState(isolate);
2373 if (msg != NULL) { 2247 if (msg != NULL) {
2374 return Api::NewError(msg); 2248 return Api::NewError(msg);
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after
2546 } 2420 }
2547 delete debug_region; 2421 delete debug_region;
2548 } else { 2422 } else {
2549 *buffer = NULL; 2423 *buffer = NULL;
2550 *buffer_size = 0; 2424 *buffer_size = 0;
2551 } 2425 }
2552 } 2426 }
2553 2427
2554 2428
2555 } // namespace dart 2429 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/dart.cc ('k') | runtime/vm/dart_api_impl_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698