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

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

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