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