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 273 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 284 if (function.IsNull()) { | 284 if (function.IsNull()) { |
| 285 return ApiError::New(String::Handle(String::New(""))); | 285 return ApiError::New(String::Handle(String::New(""))); |
| 286 } | 286 } |
| 287 const Array& args = Array::Handle(Array::New(kNumArgs)); | 287 const Array& args = Array::Handle(Array::New(kNumArgs)); |
| 288 args.SetAt(0, receiver); | 288 args.SetAt(0, receiver); |
| 289 args.SetAt(1, argument); | 289 args.SetAt(1, argument); |
| 290 return DartEntry::InvokeFunction(function, args); | 290 return DartEntry::InvokeFunction(function, args); |
| 291 } | 291 } |
| 292 | 292 |
| 293 | 293 |
| 294 // Convert a |Dart_Isolate| into an |Isolate|. Returns NULL if no isolate | |
|
Ivan Posva
2015/05/11 04:50:15
Why not move this helper function to where it is b
Cutch
2015/05/12 03:21:28
Done.
| |
| 295 // could be found. | |
| 296 static Isolate* LookupIsolate(Dart_Isolate isolate) { | |
| 297 return PortMap::GetIsolate(static_cast<Dart_Port>(isolate)); | |
| 298 } | |
| 299 | |
| 300 | |
| 294 WeakReferenceSetBuilder* ApiState::NewWeakReferenceSetBuilder() { | 301 WeakReferenceSetBuilder* ApiState::NewWeakReferenceSetBuilder() { |
| 295 return new WeakReferenceSetBuilder(this); | 302 return new WeakReferenceSetBuilder(this); |
| 296 } | 303 } |
| 297 | 304 |
| 298 | 305 |
| 299 void ApiState::DelayWeakReferenceSet(WeakReferenceSet* reference_set) { | 306 void ApiState::DelayWeakReferenceSet(WeakReferenceSet* reference_set) { |
| 300 WeakReferenceSet::Push(reference_set, &delayed_weak_reference_sets_); | 307 WeakReferenceSet::Push(reference_set, &delayed_weak_reference_sets_); |
| 301 } | 308 } |
| 302 | 309 |
| 303 | 310 |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 383 } | 390 } |
| 384 if (ClassFinalizer::ProcessPendingClasses()) { | 391 if (ClassFinalizer::ProcessPendingClasses()) { |
| 385 return Api::Success(); | 392 return Api::Success(); |
| 386 } | 393 } |
| 387 ASSERT(isolate->object_store()->sticky_error() != Object::null()); | 394 ASSERT(isolate->object_store()->sticky_error() != Object::null()); |
| 388 return Api::NewHandle(isolate, isolate->object_store()->sticky_error()); | 395 return Api::NewHandle(isolate, isolate->object_store()->sticky_error()); |
| 389 } | 396 } |
| 390 | 397 |
| 391 | 398 |
| 392 Dart_Isolate Api::CastIsolate(Isolate* isolate) { | 399 Dart_Isolate Api::CastIsolate(Isolate* isolate) { |
| 393 return reinterpret_cast<Dart_Isolate>(isolate); | 400 if (isolate == NULL) { |
| 401 return ILLEGAL_ISOLATE; | |
| 402 } | |
| 403 return static_cast<Dart_Isolate>(isolate->main_port()); | |
| 394 } | 404 } |
| 395 | 405 |
| 396 | 406 |
| 407 Isolate* Api::CastIsolate(Dart_Isolate isolate) { | |
| 408 return LookupIsolate(isolate); | |
| 409 } | |
| 410 | |
| 411 | |
| 397 Dart_Handle Api::NewError(const char* format, ...) { | 412 Dart_Handle Api::NewError(const char* format, ...) { |
| 398 Isolate* isolate = Isolate::Current(); | 413 Isolate* isolate = Isolate::Current(); |
| 399 DARTSCOPE(isolate); | 414 DARTSCOPE(isolate); |
| 400 CHECK_CALLBACK_STATE(isolate); | 415 CHECK_CALLBACK_STATE(isolate); |
| 401 | 416 |
| 402 va_list args; | 417 va_list args; |
| 403 va_start(args, format); | 418 va_start(args, format); |
| 404 intptr_t len = OS::VSNPrint(NULL, 0, format, args); | 419 intptr_t len = OS::VSNPrint(NULL, 0, format, args); |
| 405 va_end(args); | 420 va_end(args); |
| 406 | 421 |
| (...skipping 887 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1294 StackZone zone(isolate); | 1309 StackZone zone(isolate); |
| 1295 HANDLESCOPE(isolate); | 1310 HANDLESCOPE(isolate); |
| 1296 const Error& error_obj = | 1311 const Error& error_obj = |
| 1297 Error::Handle(isolate, | 1312 Error::Handle(isolate, |
| 1298 Dart::InitializeIsolate(snapshot, callback_data)); | 1313 Dart::InitializeIsolate(snapshot, callback_data)); |
| 1299 if (error_obj.IsNull()) { | 1314 if (error_obj.IsNull()) { |
| 1300 if (FLAG_check_function_fingerprints) { | 1315 if (FLAG_check_function_fingerprints) { |
| 1301 Library::CheckFunctionFingerprints(); | 1316 Library::CheckFunctionFingerprints(); |
| 1302 } | 1317 } |
| 1303 START_TIMER(isolate, time_total_runtime); | 1318 START_TIMER(isolate, time_total_runtime); |
| 1304 return reinterpret_cast<Dart_Isolate>(isolate); | 1319 return Api::CastIsolate(isolate); |
| 1305 } | 1320 } |
| 1306 *error = strdup(error_obj.ToErrorCString()); | 1321 *error = strdup(error_obj.ToErrorCString()); |
| 1307 } | 1322 } |
| 1308 Dart::ShutdownIsolate(); | 1323 Dart::ShutdownIsolate(); |
| 1309 return reinterpret_cast<Dart_Isolate>(NULL); | 1324 return ILLEGAL_ISOLATE; |
| 1310 } | 1325 } |
| 1311 | 1326 |
| 1312 | 1327 |
| 1313 DART_EXPORT void Dart_ShutdownIsolate() { | 1328 DART_EXPORT void Dart_ShutdownIsolate() { |
| 1314 Isolate* isolate = Isolate::Current(); | 1329 Isolate* isolate = Isolate::Current(); |
| 1315 CHECK_ISOLATE(isolate); | 1330 CHECK_ISOLATE(isolate); |
| 1316 { | 1331 { |
| 1317 StackZone zone(isolate); | 1332 StackZone zone(isolate); |
| 1318 HandleScope handle_scope(isolate); | 1333 HandleScope handle_scope(isolate); |
| 1319 Dart::RunShutdownCallback(); | 1334 Dart::RunShutdownCallback(); |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 1330 | 1345 |
| 1331 DART_EXPORT void* Dart_CurrentIsolateData() { | 1346 DART_EXPORT void* Dart_CurrentIsolateData() { |
| 1332 Isolate* isolate = Isolate::Current(); | 1347 Isolate* isolate = Isolate::Current(); |
| 1333 CHECK_ISOLATE(isolate); | 1348 CHECK_ISOLATE(isolate); |
| 1334 return isolate->init_callback_data(); | 1349 return isolate->init_callback_data(); |
| 1335 } | 1350 } |
| 1336 | 1351 |
| 1337 | 1352 |
| 1338 DART_EXPORT void* Dart_IsolateData(Dart_Isolate isolate) { | 1353 DART_EXPORT void* Dart_IsolateData(Dart_Isolate isolate) { |
| 1339 TRACE_API_CALL(CURRENT_FUNC); | 1354 TRACE_API_CALL(CURRENT_FUNC); |
| 1340 if (isolate == NULL) { | 1355 Isolate* iso = LookupIsolate(isolate); |
|
Ivan Posva
2015/05/11 04:50:15
Why not Api::CastIsolate?
Cutch
2015/05/12 03:21:28
Done.
| |
| 1341 FATAL1("%s expects argument 'isolate' to be non-null.", CURRENT_FUNC); | 1356 if (iso == NULL) { |
| 1357 FATAL1("%s expects argument 'isolate' to be a valid isolate.", | |
| 1358 CURRENT_FUNC); | |
|
Ivan Posva
2015/05/11 04:50:15
FATAL is a very unfriendly error from the position
Cutch
2015/05/12 03:21:29
I've removed most uses of FATAL in this file. PTAL
| |
| 1342 } | 1359 } |
| 1343 // TODO(16615): Validate isolate parameter. | |
| 1344 Isolate* iso = reinterpret_cast<Isolate*>(isolate); | |
| 1345 return iso->init_callback_data(); | 1360 return iso->init_callback_data(); |
| 1346 } | 1361 } |
| 1347 | 1362 |
| 1348 | 1363 |
| 1349 DART_EXPORT Dart_Handle Dart_DebugName() { | 1364 DART_EXPORT Dart_Handle Dart_DebugName() { |
| 1350 Isolate* isolate = Isolate::Current(); | 1365 Isolate* isolate = Isolate::Current(); |
| 1351 DARTSCOPE(isolate); | 1366 DARTSCOPE(isolate); |
| 1352 return Api::NewHandle(isolate, String::New(isolate->name())); | 1367 return Api::NewHandle(isolate, String::New(isolate->name())); |
| 1353 } | 1368 } |
| 1354 | 1369 |
| 1355 | 1370 |
| 1356 | 1371 |
| 1357 DART_EXPORT void Dart_EnterIsolate(Dart_Isolate isolate) { | 1372 DART_EXPORT void Dart_EnterIsolate(Dart_Isolate isolate) { |
| 1358 CHECK_NO_ISOLATE(Isolate::Current()); | 1373 CHECK_NO_ISOLATE(Isolate::Current()); |
| 1359 // TODO(16615): Validate isolate parameter. | 1374 Isolate* iso = LookupIsolate(isolate); |
|
Ivan Posva
2015/05/11 04:50:15
ditto here and below.
Cutch
2015/05/12 03:21:28
Done.
| |
| 1360 Isolate* iso = reinterpret_cast<Isolate*>(isolate); | 1375 if (iso == NULL) { |
| 1376 FATAL1("%s expects argument 'isolate' to be a valid isolate.", | |
| 1377 CURRENT_FUNC); | |
| 1378 } | |
| 1361 if (iso->mutator_thread() != NULL) { | 1379 if (iso->mutator_thread() != NULL) { |
| 1362 FATAL("Multiple mutators within one isolate is not supported."); | 1380 FATAL("Multiple mutators within one isolate is not supported."); |
| 1363 } | 1381 } |
| 1364 Thread::EnterIsolate(iso); | 1382 Thread::EnterIsolate(iso); |
| 1365 } | 1383 } |
| 1366 | 1384 |
| 1367 | 1385 |
| 1368 DART_EXPORT void Dart_IsolateBlocked() { | 1386 DART_EXPORT void Dart_IsolateBlocked() { |
| 1369 Isolate* isolate = Isolate::Current(); | 1387 Isolate* isolate = Isolate::Current(); |
| 1370 CHECK_ISOLATE(isolate); | 1388 CHECK_ISOLATE(isolate); |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1475 } | 1493 } |
| 1476 ScriptSnapshotWriter writer(buffer, ApiReallocate); | 1494 ScriptSnapshotWriter writer(buffer, ApiReallocate); |
| 1477 writer.WriteScriptSnapshot(library); | 1495 writer.WriteScriptSnapshot(library); |
| 1478 *size = writer.BytesWritten(); | 1496 *size = writer.BytesWritten(); |
| 1479 return Api::Success(); | 1497 return Api::Success(); |
| 1480 } | 1498 } |
| 1481 | 1499 |
| 1482 | 1500 |
| 1483 DART_EXPORT void Dart_InterruptIsolate(Dart_Isolate isolate) { | 1501 DART_EXPORT void Dart_InterruptIsolate(Dart_Isolate isolate) { |
| 1484 TRACE_API_CALL(CURRENT_FUNC); | 1502 TRACE_API_CALL(CURRENT_FUNC); |
| 1485 if (isolate == NULL) { | 1503 Isolate* iso = LookupIsolate(isolate); |
| 1486 FATAL1("%s expects argument 'isolate' to be non-null.", CURRENT_FUNC); | 1504 if (iso == NULL) { |
| 1505 FATAL1("%s expects argument 'isolate' to be a valid isolate.", | |
| 1506 CURRENT_FUNC); | |
| 1487 } | 1507 } |
| 1488 // TODO(16615): Validate isolate parameter. | |
| 1489 Isolate* iso = reinterpret_cast<Isolate*>(isolate); | |
| 1490 iso->ScheduleInterrupts(Isolate::kApiInterrupt); | 1508 iso->ScheduleInterrupts(Isolate::kApiInterrupt); |
| 1491 // Can't use Dart_Post() since there isn't a current isolate. | 1509 // Can't use Dart_Post() since there isn't a current isolate. |
| 1492 Dart_CObject api_null = { Dart_CObject_kNull , { 0 } }; | 1510 Dart_CObject api_null = { Dart_CObject_kNull , { 0 } }; |
| 1493 Dart_PostCObject(iso->main_port(), &api_null); | 1511 Dart_PostCObject(iso->main_port(), &api_null); |
| 1494 } | 1512 } |
| 1495 | 1513 |
| 1496 | 1514 |
| 1497 DART_EXPORT bool Dart_IsolateMakeRunnable(Dart_Isolate isolate) { | 1515 DART_EXPORT bool Dart_IsolateMakeRunnable(Dart_Isolate isolate) { |
| 1498 CHECK_NO_ISOLATE(Isolate::Current()); | 1516 CHECK_NO_ISOLATE(Isolate::Current()); |
| 1499 if (isolate == NULL) { | 1517 Isolate* iso = LookupIsolate(isolate); |
| 1500 FATAL1("%s expects argument 'isolate' to be non-null.", CURRENT_FUNC); | 1518 if (iso == NULL) { |
| 1519 FATAL1("%s expects argument 'isolate' to be a valid isolate.", | |
| 1520 CURRENT_FUNC); | |
| 1501 } | 1521 } |
| 1502 // TODO(16615): Validate isolate parameter. | |
| 1503 Isolate* iso = reinterpret_cast<Isolate*>(isolate); | |
| 1504 if (iso->object_store()->root_library() == Library::null()) { | 1522 if (iso->object_store()->root_library() == Library::null()) { |
| 1505 // The embedder should have called Dart_LoadScript by now. | 1523 // The embedder should have called Dart_LoadScript by now. |
| 1506 return false; | 1524 return false; |
| 1507 } | 1525 } |
| 1508 return iso->MakeRunnable(); | 1526 return iso->MakeRunnable(); |
| 1509 } | 1527 } |
| 1510 | 1528 |
| 1511 | 1529 |
| 1512 // --- Messages and Ports --- | 1530 // --- Messages and Ports --- |
| 1513 | 1531 |
| (...skipping 4026 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 5540 RawObject* raw_obj = obj.raw(); | 5558 RawObject* raw_obj = obj.raw(); |
| 5541 isolate->heap()->SetPeer(raw_obj, peer); | 5559 isolate->heap()->SetPeer(raw_obj, peer); |
| 5542 } | 5560 } |
| 5543 return Api::Success(); | 5561 return Api::Success(); |
| 5544 } | 5562 } |
| 5545 | 5563 |
| 5546 | 5564 |
| 5547 // --- Service support --- | 5565 // --- Service support --- |
| 5548 | 5566 |
| 5549 DART_EXPORT bool Dart_IsServiceIsolate(Dart_Isolate isolate) { | 5567 DART_EXPORT bool Dart_IsServiceIsolate(Dart_Isolate isolate) { |
| 5550 Isolate* iso = reinterpret_cast<Isolate*>(isolate); | 5568 Isolate* iso = LookupIsolate(isolate); |
| 5551 return ServiceIsolate::IsServiceIsolate(iso); | 5569 return ServiceIsolate::IsServiceIsolate(iso); |
| 5552 } | 5570 } |
| 5553 | 5571 |
| 5554 | 5572 |
| 5555 DART_EXPORT Dart_Port Dart_ServiceWaitForLoadPort() { | 5573 DART_EXPORT Dart_Port Dart_ServiceWaitForLoadPort() { |
| 5556 return ServiceIsolate::WaitForLoadPort(); | 5574 return ServiceIsolate::WaitForLoadPort(); |
| 5557 } | 5575 } |
| 5558 | 5576 |
| 5559 | 5577 |
| 5560 DART_EXPORT void Dart_RegisterIsolateServiceRequestCallback( | 5578 DART_EXPORT void Dart_RegisterIsolateServiceRequestCallback( |
| 5561 const char* name, | 5579 const char* name, |
| 5562 Dart_ServiceRequestCallback callback, | 5580 Dart_ServiceRequestCallback callback, |
| 5563 void* user_data) { | 5581 void* user_data) { |
| 5564 Service::RegisterIsolateEmbedderCallback(name, callback, user_data); | 5582 Service::RegisterIsolateEmbedderCallback(name, callback, user_data); |
| 5565 } | 5583 } |
| 5566 | 5584 |
| 5567 | 5585 |
| 5568 DART_EXPORT void Dart_RegisterRootServiceRequestCallback( | 5586 DART_EXPORT void Dart_RegisterRootServiceRequestCallback( |
| 5569 const char* name, | 5587 const char* name, |
| 5570 Dart_ServiceRequestCallback callback, | 5588 Dart_ServiceRequestCallback callback, |
| 5571 void* user_data) { | 5589 void* user_data) { |
| 5572 Service::RegisterRootEmbedderCallback(name, callback, user_data); | 5590 Service::RegisterRootEmbedderCallback(name, callback, user_data); |
| 5573 } | 5591 } |
| 5574 | 5592 |
| 5575 } // namespace dart | 5593 } // namespace dart |
| OLD | NEW |