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

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

Powered by Google App Engine
This is Rietveld 408576698