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

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

Issue 1541073002: Implement safepointing of threads (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: fix-tests Created 4 years, 11 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
OLDNEW
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, 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 #include "include/dart_mirrors_api.h" 6 #include "include/dart_mirrors_api.h"
7 #include "include/dart_native_api.h" 7 #include "include/dart_native_api.h"
8 8
9 #include "platform/assert.h" 9 #include "platform/assert.h"
10 #include "vm/class_finalizer.h" 10 #include "vm/class_finalizer.h"
(...skipping 336 matching lines...) Expand 10 before | Expand all | Expand 10 after
347 if (function.IsNull()) { 347 if (function.IsNull()) {
348 return ApiError::New(String::Handle(String::New(""))); 348 return ApiError::New(String::Handle(String::New("")));
349 } 349 }
350 const Array& args = Array::Handle(Array::New(kNumArgs)); 350 const Array& args = Array::Handle(Array::New(kNumArgs));
351 args.SetAt(0, receiver); 351 args.SetAt(0, receiver);
352 args.SetAt(1, argument); 352 args.SetAt(1, argument);
353 return DartEntry::InvokeFunction(function, args); 353 return DartEntry::InvokeFunction(function, args);
354 } 354 }
355 355
356 356
357 static const char* GetErrorString(Thread* thread, const Object& obj) {
358 if (obj.IsError()) {
359 const Error& error = Error::Cast(obj);
360 const char* str = error.ToErrorCString();
361 intptr_t len = strlen(str) + 1;
362 char* str_copy = Api::TopScope(thread)->zone()->Alloc<char>(len);
363 strncpy(str_copy, str, len);
364 // Strip a possible trailing '\n'.
365 if ((len > 1) && (str_copy[len - 2] == '\n')) {
366 str_copy[len - 2] = '\0';
367 }
368 return str_copy;
369 } else {
370 return "";
371 }
372 }
373
374
357 Dart_Handle Api::InitNewHandle(Thread* thread, RawObject* raw) { 375 Dart_Handle Api::InitNewHandle(Thread* thread, RawObject* raw) {
358 LocalHandles* local_handles = Api::TopScope(thread)->local_handles(); 376 LocalHandles* local_handles = Api::TopScope(thread)->local_handles();
359 ASSERT(local_handles != NULL); 377 ASSERT(local_handles != NULL);
360 LocalHandle* ref = local_handles->AllocateHandle(); 378 LocalHandle* ref = local_handles->AllocateHandle();
361 ref->set_raw(raw); 379 ref->set_raw(raw);
362 return ref->apiHandle(); 380 return ref->apiHandle();
363 } 381 }
364 382
365 383
366 Dart_Handle Api::NewHandle(Thread* thread, RawObject* raw) { 384 Dart_Handle Api::NewHandle(Thread* thread, RawObject* raw) {
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
441 return Api::NewHandle(thread, isolate->object_store()->sticky_error()); 459 return Api::NewHandle(thread, isolate->object_store()->sticky_error());
442 } 460 }
443 461
444 462
445 Dart_Isolate Api::CastIsolate(Isolate* isolate) { 463 Dart_Isolate Api::CastIsolate(Isolate* isolate) {
446 return reinterpret_cast<Dart_Isolate>(isolate); 464 return reinterpret_cast<Dart_Isolate>(isolate);
447 } 465 }
448 466
449 467
450 Dart_Handle Api::NewError(const char* format, ...) { 468 Dart_Handle Api::NewError(const char* format, ...) {
451 DARTSCOPE(Thread::Current()); 469 Thread* T = Thread::Current();
470 CHECK_API_SCOPE(T);
471 HANDLESCOPE(T);
452 CHECK_CALLBACK_STATE(T); 472 CHECK_CALLBACK_STATE(T);
453 473
454 va_list args; 474 va_list args;
455 va_start(args, format); 475 va_start(args, format);
456 intptr_t len = OS::VSNPrint(NULL, 0, format, args); 476 intptr_t len = OS::VSNPrint(NULL, 0, format, args);
457 va_end(args); 477 va_end(args);
458 478
459 char* buffer = Z->Alloc<char>(len + 1); 479 char* buffer = Z->Alloc<char>(len + 1);
460 va_list args2; 480 va_list args2;
461 va_start(args2, format); 481 va_start(args2, format);
(...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after
738 DARTSCOPE(Thread::Current()); 758 DARTSCOPE(Thread::Current());
739 const Object& obj = Object::Handle(Z, Api::UnwrapHandle(handle)); 759 const Object& obj = Object::Handle(Z, Api::UnwrapHandle(handle));
740 return (obj.IsUnwindError() && UnwindError::Cast(obj).is_vm_restart()); 760 return (obj.IsUnwindError() && UnwindError::Cast(obj).is_vm_restart());
741 } 761 }
742 762
743 763
744 DART_EXPORT const char* Dart_GetError(Dart_Handle handle) { 764 DART_EXPORT const char* Dart_GetError(Dart_Handle handle) {
745 API_TIMELINE_DURATION; 765 API_TIMELINE_DURATION;
746 DARTSCOPE(Thread::Current()); 766 DARTSCOPE(Thread::Current());
747 const Object& obj = Object::Handle(Z, Api::UnwrapHandle(handle)); 767 const Object& obj = Object::Handle(Z, Api::UnwrapHandle(handle));
748 if (obj.IsError()) { 768 return GetErrorString(T, obj);
749 const Error& error = Error::Cast(obj);
750 const char* str = error.ToErrorCString();
751 intptr_t len = strlen(str) + 1;
752 char* str_copy = Api::TopScope(T)->zone()->Alloc<char>(len);
753 strncpy(str_copy, str, len);
754 // Strip a possible trailing '\n'.
755 if ((len > 1) && (str_copy[len - 2] == '\n')) {
756 str_copy[len - 2] = '\0';
757 }
758 return str_copy;
759 } else {
760 return "";
761 }
762 } 769 }
763 770
764 771
765 DART_EXPORT bool Dart_ErrorHasException(Dart_Handle handle) { 772 DART_EXPORT bool Dart_ErrorHasException(Dart_Handle handle) {
766 DARTSCOPE(Thread::Current()); 773 DARTSCOPE(Thread::Current());
767 const Object& obj = Object::Handle(Z, Api::UnwrapHandle(handle)); 774 const Object& obj = Object::Handle(Z, Api::UnwrapHandle(handle));
768 return obj.IsUnhandledException(); 775 return obj.IsUnhandledException();
769 } 776 }
770 777
771 778
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
808 } 815 }
809 816
810 817
811 DART_EXPORT Dart_Handle Dart_NewUnhandledExceptionError(Dart_Handle exception) { 818 DART_EXPORT Dart_Handle Dart_NewUnhandledExceptionError(Dart_Handle exception) {
812 DARTSCOPE(Thread::Current()); 819 DARTSCOPE(Thread::Current());
813 CHECK_CALLBACK_STATE(T); 820 CHECK_CALLBACK_STATE(T);
814 821
815 Instance& obj = Instance::Handle(Z); 822 Instance& obj = Instance::Handle(Z);
816 intptr_t class_id = Api::ClassId(exception); 823 intptr_t class_id = Api::ClassId(exception);
817 if ((class_id == kApiErrorCid) || (class_id == kLanguageErrorCid)) { 824 if ((class_id == kApiErrorCid) || (class_id == kLanguageErrorCid)) {
818 obj = String::New(::Dart_GetError(exception)); 825 const Object& excp = Object::Handle(Z, Api::UnwrapHandle(exception));
826 obj = String::New(GetErrorString(T, excp));
819 } else { 827 } else {
820 obj = Api::UnwrapInstanceHandle(Z, exception).raw(); 828 obj = Api::UnwrapInstanceHandle(Z, exception).raw();
821 if (obj.IsNull()) { 829 if (obj.IsNull()) {
822 RETURN_TYPE_ERROR(Z, exception, Instance); 830 RETURN_TYPE_ERROR(Z, exception, Instance);
823 } 831 }
824 } 832 }
825 const Stacktrace& stacktrace = Stacktrace::Handle(Z); 833 const Stacktrace& stacktrace = Stacktrace::Handle(Z);
826 return Api::NewHandle(T, UnhandledException::New(obj, stacktrace)); 834 return Api::NewHandle(T, UnhandledException::New(obj, stacktrace));
827 } 835 }
828 836
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after
1023 DART_EXPORT Dart_WeakPersistentHandle Dart_NewWeakPersistentHandle( 1031 DART_EXPORT Dart_WeakPersistentHandle Dart_NewWeakPersistentHandle(
1024 Dart_Handle object, 1032 Dart_Handle object,
1025 void* peer, 1033 void* peer,
1026 intptr_t external_allocation_size, 1034 intptr_t external_allocation_size,
1027 Dart_WeakPersistentHandleFinalizer callback) { 1035 Dart_WeakPersistentHandleFinalizer callback) {
1028 Thread* thread = Thread::Current(); 1036 Thread* thread = Thread::Current();
1029 CHECK_ISOLATE(thread->isolate()); 1037 CHECK_ISOLATE(thread->isolate());
1030 if (callback == NULL) { 1038 if (callback == NULL) {
1031 return NULL; 1039 return NULL;
1032 } 1040 }
1041 TransitionNativeToVM transition(thread);
1033 return AllocateFinalizableHandle(thread, 1042 return AllocateFinalizableHandle(thread,
1034 object, 1043 object,
1035 peer, 1044 peer,
1036 external_allocation_size, 1045 external_allocation_size,
1037 callback); 1046 callback);
1038 } 1047 }
1039 1048
1040 1049
1041 DART_EXPORT void Dart_DeletePersistentHandle(Dart_PersistentHandle object) { 1050 DART_EXPORT void Dart_DeletePersistentHandle(Dart_PersistentHandle object) {
1042 Isolate* isolate = Isolate::Current(); 1051 Isolate* isolate = Isolate::Current();
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after
1241 const Error& error_obj = 1250 const Error& error_obj =
1242 Error::Handle(Z, Dart::InitializeIsolate(snapshot, callback_data)); 1251 Error::Handle(Z, Dart::InitializeIsolate(snapshot, callback_data));
1243 if (error_obj.IsNull()) { 1252 if (error_obj.IsNull()) {
1244 #if defined(DART_NO_SNAPSHOT) 1253 #if defined(DART_NO_SNAPSHOT)
1245 if (FLAG_check_function_fingerprints) { 1254 if (FLAG_check_function_fingerprints) {
1246 Library::CheckFunctionFingerprints(); 1255 Library::CheckFunctionFingerprints();
1247 } 1256 }
1248 #endif // defined(DART_NO_SNAPSHOT). 1257 #endif // defined(DART_NO_SNAPSHOT).
1249 // We exit the API scope entered above. 1258 // We exit the API scope entered above.
1250 Dart_ExitScope(); 1259 Dart_ExitScope();
1260 // A Thread structure has been associated to the thread, we do the
1261 // safepoint transition explicity here instead of using the
1262 // TransitionXXX scope objects as the reverse transition happens
1263 // outside this scope in Dart_ShutdownIsolate/Dart_ExitIsolate.
1264 T->set_execution_state(Thread::kThreadInNative);
1265 T->EnterSafepoint();
1251 return Api::CastIsolate(I); 1266 return Api::CastIsolate(I);
1252 } 1267 }
1253 *error = strdup(error_obj.ToErrorCString()); 1268 *error = strdup(error_obj.ToErrorCString());
1254 // We exit the API scope entered above. 1269 // We exit the API scope entered above.
1255 Dart_ExitScope(); 1270 Dart_ExitScope();
1256 } 1271 }
1257 Dart::ShutdownIsolate(); 1272 Dart::ShutdownIsolate();
1258 return reinterpret_cast<Dart_Isolate>(NULL); 1273 return reinterpret_cast<Dart_Isolate>(NULL);
1259 } 1274 }
1260 1275
1261 1276
1262 DART_EXPORT void Dart_ShutdownIsolate() { 1277 DART_EXPORT void Dart_ShutdownIsolate() {
1263 Thread* T = Thread::Current(); 1278 Thread* T = Thread::Current();
1264 Isolate* I = T->isolate(); 1279 Isolate* I = T->isolate();
1265 CHECK_ISOLATE(I); 1280 CHECK_ISOLATE(I);
1266 I->WaitForOutstandingSpawns(); 1281 I->WaitForOutstandingSpawns();
1267 { 1282 {
1268 StackZone zone(T); 1283 StackZone zone(T);
1269 HandleScope handle_scope(T); 1284 HandleScope handle_scope(T);
1270 Dart::RunShutdownCallback(); 1285 Dart::RunShutdownCallback();
1271 } 1286 }
1287 // The Thread structure is disassociated from the isolate, we do the
1288 // safepoint transition explicity here instead of using the TransitionXXX
1289 // scope objects as the original transition happened outside this scope in
1290 // Dart_EnterIsolate/Dart_CreateIsolate.
1291 T->ExitSafepoint();
1292 T->set_execution_state(Thread::kThreadInVM);
1272 Dart::ShutdownIsolate(); 1293 Dart::ShutdownIsolate();
1273 } 1294 }
1274 1295
1275 1296
1276 DART_EXPORT Dart_Isolate Dart_CurrentIsolate() { 1297 DART_EXPORT Dart_Isolate Dart_CurrentIsolate() {
1277 return Api::CastIsolate(Isolate::Current()); 1298 return Api::CastIsolate(Isolate::Current());
1278 } 1299 }
1279 1300
1280 1301
1281 DART_EXPORT void* Dart_CurrentIsolateData() { 1302 DART_EXPORT void* Dart_CurrentIsolateData() {
(...skipping 23 matching lines...) Expand all
1305 DART_EXPORT void Dart_EnterIsolate(Dart_Isolate isolate) { 1326 DART_EXPORT void Dart_EnterIsolate(Dart_Isolate isolate) {
1306 CHECK_NO_ISOLATE(Isolate::Current()); 1327 CHECK_NO_ISOLATE(Isolate::Current());
1307 // TODO(16615): Validate isolate parameter. 1328 // TODO(16615): Validate isolate parameter.
1308 Isolate* iso = reinterpret_cast<Isolate*>(isolate); 1329 Isolate* iso = reinterpret_cast<Isolate*>(isolate);
1309 if (iso->HasMutatorThread()) { 1330 if (iso->HasMutatorThread()) {
1310 FATAL("Multiple mutators within one isolate is not supported."); 1331 FATAL("Multiple mutators within one isolate is not supported.");
1311 } 1332 }
1312 if (!Thread::EnterIsolate(iso)) { 1333 if (!Thread::EnterIsolate(iso)) {
1313 FATAL("Unable to Enter Isolate as Dart VM is shutting down"); 1334 FATAL("Unable to Enter Isolate as Dart VM is shutting down");
1314 } 1335 }
1336 // A Thread structure has been associated to the thread, we do the
1337 // safepoint transition explicity here instead of using the
1338 // TransitionXXX scope objects as the reverse transition happens
1339 // outside this scope in Dart_ExitIsolate/Dart_ShutdownIsolate.
1340 Thread* T = Thread::Current();
1341 T->set_execution_state(Thread::kThreadInNative);
1342 T->EnterSafepoint();
1315 } 1343 }
1316 1344
1317 1345
1318 DART_EXPORT void Dart_ThreadDisableProfiling() { 1346 DART_EXPORT void Dart_ThreadDisableProfiling() {
1319 OSThread* os_thread = OSThread::Current(); 1347 OSThread* os_thread = OSThread::Current();
1320 if (os_thread == NULL) { 1348 if (os_thread == NULL) {
1321 return; 1349 return;
1322 } 1350 }
1323 os_thread->DisableThreadInterrupts(); 1351 os_thread->DisableThreadInterrupts();
1324 } 1352 }
1325 1353
1326 1354
1327 DART_EXPORT void Dart_ThreadEnableProfiling() { 1355 DART_EXPORT void Dart_ThreadEnableProfiling() {
1328 OSThread* os_thread = OSThread::Current(); 1356 OSThread* os_thread = OSThread::Current();
1329 if (os_thread == NULL) { 1357 if (os_thread == NULL) {
1330 return; 1358 return;
1331 } 1359 }
1332 os_thread->EnableThreadInterrupts(); 1360 os_thread->EnableThreadInterrupts();
1333 } 1361 }
1334 1362
1335 1363
1336 DART_EXPORT void Dart_ExitIsolate() { 1364 DART_EXPORT void Dart_ExitIsolate() {
1337 CHECK_ISOLATE(Isolate::Current()); 1365 Thread* T = Thread::Current();
1366 CHECK_ISOLATE(T->isolate());
1367 // The Thread structure is disassociated from the isolate, we do the
1368 // safepoint transition explicity here instead of using the TransitionXXX
1369 // scope objects as the original transition happened outside this scope in
1370 // Dart_EnterIsolate/Dart_CreateIsolate.
1371 ASSERT(T->execution_state() == Thread::kThreadInNative);
1372 T->ExitSafepoint();
1373 T->set_execution_state(Thread::kThreadInVM);
1338 Thread::ExitIsolate(); 1374 Thread::ExitIsolate();
1339 } 1375 }
1340 1376
1341 1377
1342 static uint8_t* ApiReallocate(uint8_t* ptr, 1378 static uint8_t* ApiReallocate(uint8_t* ptr,
1343 intptr_t old_size, 1379 intptr_t old_size,
1344 intptr_t new_size) { 1380 intptr_t new_size) {
1345 return Api::TopScope(Thread::Current())->zone()->Realloc<uint8_t>( 1381 return Api::TopScope(Thread::Current())->zone()->Realloc<uint8_t>(
1346 ptr, old_size, new_size); 1382 ptr, old_size, new_size);
1347 } 1383 }
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
1493 Thread* T = Thread::Current(); 1529 Thread* T = Thread::Current();
1494 Isolate* I = T->isolate(); 1530 Isolate* I = T->isolate();
1495 CHECK_API_SCOPE(T); 1531 CHECK_API_SCOPE(T);
1496 CHECK_CALLBACK_STATE(T); 1532 CHECK_CALLBACK_STATE(T);
1497 API_TIMELINE_BEGIN_END; 1533 API_TIMELINE_BEGIN_END;
1498 Monitor monitor; 1534 Monitor monitor;
1499 MonitorLocker ml(&monitor); 1535 MonitorLocker ml(&monitor);
1500 { 1536 {
1501 // The message handler run loop does not expect to have a current isolate 1537 // The message handler run loop does not expect to have a current isolate
1502 // so we exit the isolate here and enter it again after the runloop is done. 1538 // so we exit the isolate here and enter it again after the runloop is done.
1503 Thread::ExitIsolate(); 1539 Dart_ExitIsolate();
1504 RunLoopData data; 1540 RunLoopData data;
1505 data.monitor = &monitor; 1541 data.monitor = &monitor;
1506 data.done = false; 1542 data.done = false;
1507 I->message_handler()->Run( 1543 I->message_handler()->Run(
1508 Dart::thread_pool(), 1544 Dart::thread_pool(),
1509 NULL, RunLoopDone, reinterpret_cast<uword>(&data)); 1545 NULL, RunLoopDone, reinterpret_cast<uword>(&data));
1510 while (!data.done) { 1546 while (!data.done) {
1511 ml.Wait(); 1547 ml.Wait();
1512 } 1548 }
1513 if (!Thread::EnterIsolate(I)) { 1549 Dart_EnterIsolate(Api::CastIsolate(I));
1514 FATAL("Inconsistent state, VM shutting down while in run loop.");
1515 }
1516 } 1550 }
1517 if (I->object_store()->sticky_error() != Object::null()) { 1551 if (I->object_store()->sticky_error() != Object::null()) {
1518 Dart_Handle error = Api::NewHandle(T, I->object_store()->sticky_error()); 1552 Dart_Handle error = Api::NewHandle(T, I->object_store()->sticky_error());
1519 I->object_store()->clear_sticky_error(); 1553 I->object_store()->clear_sticky_error();
1520 return error; 1554 return error;
1521 } 1555 }
1522 if (FLAG_print_class_table) { 1556 if (FLAG_print_class_table) {
1523 HANDLESCOPE(T); 1557 HANDLESCOPE(T);
1524 I->class_table()->Print(); 1558 I->class_table()->Print();
1525 } 1559 }
1526 return Api::Success(); 1560 return Api::Success();
1527 } 1561 }
1528 1562
1529 1563
1530 DART_EXPORT Dart_Handle Dart_HandleMessage() { 1564 DART_EXPORT Dart_Handle Dart_HandleMessage() {
1531 Thread* T = Thread::Current(); 1565 Thread* T = Thread::Current();
1532 Isolate* I = T->isolate(); 1566 Isolate* I = T->isolate();
1533 CHECK_API_SCOPE(T); 1567 CHECK_API_SCOPE(T);
1534 CHECK_CALLBACK_STATE(T); 1568 CHECK_CALLBACK_STATE(T);
1535 API_TIMELINE_BEGIN_END; 1569 API_TIMELINE_BEGIN_END;
1570 TransitionNativeToVM trainsition(T);
1536 if (I->message_handler()->HandleNextMessage() != MessageHandler::kOK) { 1571 if (I->message_handler()->HandleNextMessage() != MessageHandler::kOK) {
1537 Dart_Handle error = Api::NewHandle(T, I->object_store()->sticky_error()); 1572 Dart_Handle error = Api::NewHandle(T, I->object_store()->sticky_error());
1538 I->object_store()->clear_sticky_error(); 1573 I->object_store()->clear_sticky_error();
1539 return error; 1574 return error;
1540 } 1575 }
1541 return Api::Success(); 1576 return Api::Success();
1542 } 1577 }
1543 1578
1544 1579
1545 DART_EXPORT bool Dart_HandleServiceMessages() { 1580 DART_EXPORT bool Dart_HandleServiceMessages() {
1546 Thread* T = Thread::Current(); 1581 Thread* T = Thread::Current();
1547 Isolate* I = T->isolate(); 1582 Isolate* I = T->isolate();
1548 CHECK_API_SCOPE(T); 1583 CHECK_API_SCOPE(T);
1549 CHECK_CALLBACK_STATE(T); 1584 CHECK_CALLBACK_STATE(T);
1550 API_TIMELINE_DURATION; 1585 API_TIMELINE_DURATION;
1586 TransitionNativeToVM trainsition(T);
1551 ASSERT(I->GetAndClearResumeRequest() == false); 1587 ASSERT(I->GetAndClearResumeRequest() == false);
1552 MessageHandler::MessageStatus status = 1588 MessageHandler::MessageStatus status =
1553 I->message_handler()->HandleOOBMessages(); 1589 I->message_handler()->HandleOOBMessages();
1554 bool resume = I->GetAndClearResumeRequest(); 1590 bool resume = I->GetAndClearResumeRequest();
1555 return (status != MessageHandler::kOK) || resume; 1591 return (status != MessageHandler::kOK) || resume;
1556 } 1592 }
1557 1593
1558 1594
1559 DART_EXPORT bool Dart_HasServiceMessages() { 1595 DART_EXPORT bool Dart_HasServiceMessages() {
1560 Isolate* isolate = Isolate::Current(); 1596 Isolate* isolate = Isolate::Current();
(...skipping 3251 matching lines...) Expand 10 before | Expand all | Expand 10 after
4812 ASSERT(isolate->api_state() != NULL && 4848 ASSERT(isolate->api_state() != NULL &&
4813 (isolate->api_state()->IsValidWeakPersistentHandle(rval))); 4849 (isolate->api_state()->IsValidWeakPersistentHandle(rval)));
4814 #endif 4850 #endif
4815 Api::SetWeakHandleReturnValue(arguments, rval); 4851 Api::SetWeakHandleReturnValue(arguments, rval);
4816 } 4852 }
4817 4853
4818 4854
4819 // --- Environment --- 4855 // --- Environment ---
4820 RawString* Api::CallEnvironmentCallback(Thread* thread, const String& name) { 4856 RawString* Api::CallEnvironmentCallback(Thread* thread, const String& name) {
4821 Isolate* isolate = thread->isolate(); 4857 Isolate* isolate = thread->isolate();
4822 Scope api_scope(thread);
4823 Dart_EnvironmentCallback callback = isolate->environment_callback(); 4858 Dart_EnvironmentCallback callback = isolate->environment_callback();
4824 String& result = String::Handle(thread->zone()); 4859 String& result = String::Handle(thread->zone());
4825 if (callback != NULL) { 4860 if (callback != NULL) {
4861 TransitionVMToNative transition(thread);
4862 Scope api_scope(thread);
4826 Dart_Handle response = callback(Api::NewHandle(thread, name.raw())); 4863 Dart_Handle response = callback(Api::NewHandle(thread, name.raw()));
4827 if (::Dart_IsString(response)) { 4864 if (::Dart_IsString(response)) {
4828 result ^= Api::UnwrapHandle(response); 4865 result ^= Api::UnwrapHandle(response);
4829 } else if (::Dart_IsError(response)) { 4866 } else if (::Dart_IsError(response)) {
4830 const Object& error = Object::Handle( 4867 const Object& error = Object::Handle(
4831 thread->zone(), Api::UnwrapHandle(response)); 4868 thread->zone(), Api::UnwrapHandle(response));
4832 Exceptions::ThrowArgumentError( 4869 Exceptions::ThrowArgumentError(
4833 String::Handle(String::New(Error::Cast(error).ToErrorCString()))); 4870 String::Handle(String::New(Error::Cast(error).ToErrorCString())));
4834 } else if (!::Dart_IsNull(response)) { 4871 } else if (!::Dart_IsNull(response)) {
4835 // At this point everything except null are invalid environment values. 4872 // At this point everything except null are invalid environment values.
(...skipping 1133 matching lines...) Expand 10 before | Expand all | Expand 10 after
5969 return Api::Success(); 6006 return Api::Success();
5970 } 6007 }
5971 #endif // DART_PRECOMPILED_RUNTIME 6008 #endif // DART_PRECOMPILED_RUNTIME
5972 6009
5973 6010
5974 DART_EXPORT bool Dart_IsRunningPrecompiledCode() { 6011 DART_EXPORT bool Dart_IsRunningPrecompiledCode() {
5975 return Dart::IsRunningPrecompiledCode(); 6012 return Dart::IsRunningPrecompiledCode();
5976 } 6013 }
5977 6014
5978 } // namespace dart 6015 } // namespace dart
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698