Index: runtime/vm/dart_api_impl.cc |
diff --git a/runtime/vm/dart_api_impl.cc b/runtime/vm/dart_api_impl.cc |
index 1f2dfc3844263e120bd910b1158d735df3fa3601..a076b367fde5733537189e7c10f261fb52f38c79 100644 |
--- a/runtime/vm/dart_api_impl.cc |
+++ b/runtime/vm/dart_api_impl.cc |
@@ -390,7 +390,15 @@ Dart_Handle Api::CheckAndFinalizePendingClasses(Isolate* isolate) { |
Dart_Isolate Api::CastIsolate(Isolate* isolate) { |
- return reinterpret_cast<Dart_Isolate>(isolate); |
+ if (isolate == NULL) { |
+ return DART_ILLEGAL_ISOLATE; |
+ } |
+ return static_cast<Dart_Isolate>(isolate->main_port()); |
+} |
+ |
+ |
+Isolate* Api::CastIsolate(Dart_Isolate isolate) { |
+ return PortMap::GetIsolate(static_cast<Dart_Port>(isolate)); |
} |
@@ -1301,12 +1309,12 @@ DART_EXPORT Dart_Isolate Dart_CreateIsolate(const char* script_uri, |
Library::CheckFunctionFingerprints(); |
} |
START_TIMER(isolate, time_total_runtime); |
- return reinterpret_cast<Dart_Isolate>(isolate); |
+ return Api::CastIsolate(isolate); |
} |
*error = strdup(error_obj.ToErrorCString()); |
} |
Dart::ShutdownIsolate(); |
- return reinterpret_cast<Dart_Isolate>(NULL); |
+ return DART_ILLEGAL_ISOLATE; |
} |
@@ -1337,11 +1345,10 @@ DART_EXPORT void* Dart_CurrentIsolateData() { |
DART_EXPORT void* Dart_IsolateData(Dart_Isolate isolate) { |
TRACE_API_CALL(CURRENT_FUNC); |
- if (isolate == NULL) { |
- FATAL1("%s expects argument 'isolate' to be non-null.", CURRENT_FUNC); |
+ Isolate* iso = Api::CastIsolate(isolate); |
+ if (iso == NULL) { |
+ return NULL; |
} |
- // TODO(16615): Validate isolate parameter. |
- Isolate* iso = reinterpret_cast<Isolate*>(isolate); |
return iso->init_callback_data(); |
} |
@@ -1354,14 +1361,18 @@ DART_EXPORT Dart_Handle Dart_DebugName() { |
-DART_EXPORT void Dart_EnterIsolate(Dart_Isolate isolate) { |
+DART_EXPORT bool Dart_EnterIsolate(Dart_Isolate isolate) { |
CHECK_NO_ISOLATE(Isolate::Current()); |
- // TODO(16615): Validate isolate parameter. |
- Isolate* iso = reinterpret_cast<Isolate*>(isolate); |
+ Isolate* iso = Api::CastIsolate(isolate); |
+ if (iso == NULL) { |
+ return false; |
+ } |
if (iso->mutator_thread() != NULL) { |
FATAL("Multiple mutators within one isolate is not supported."); |
+ return false; |
} |
Thread::EnterIsolate(iso); |
+ return true; |
} |
@@ -1480,27 +1491,25 @@ DART_EXPORT Dart_Handle Dart_CreateScriptSnapshot(uint8_t** buffer, |
} |
-DART_EXPORT void Dart_InterruptIsolate(Dart_Isolate isolate) { |
+DART_EXPORT bool Dart_InterruptIsolate(Dart_Isolate isolate) { |
TRACE_API_CALL(CURRENT_FUNC); |
- if (isolate == NULL) { |
- FATAL1("%s expects argument 'isolate' to be non-null.", CURRENT_FUNC); |
+ Isolate* iso = Api::CastIsolate(isolate); |
+ if (iso == NULL) { |
+ return false; |
} |
- // TODO(16615): Validate isolate parameter. |
- Isolate* iso = reinterpret_cast<Isolate*>(isolate); |
iso->ScheduleInterrupts(Isolate::kApiInterrupt); |
// Can't use Dart_Post() since there isn't a current isolate. |
Dart_CObject api_null = { Dart_CObject_kNull , { 0 } }; |
- Dart_PostCObject(iso->main_port(), &api_null); |
+ return Dart_PostCObject(iso->main_port(), &api_null); |
} |
DART_EXPORT bool Dart_IsolateMakeRunnable(Dart_Isolate isolate) { |
CHECK_NO_ISOLATE(Isolate::Current()); |
- if (isolate == NULL) { |
- FATAL1("%s expects argument 'isolate' to be non-null.", CURRENT_FUNC); |
+ Isolate* iso = Api::CastIsolate(isolate); |
+ if (iso == NULL) { |
+ return false; |
} |
- // TODO(16615): Validate isolate parameter. |
- Isolate* iso = reinterpret_cast<Isolate*>(isolate); |
if (iso->object_store()->root_library() == Library::null()) { |
// The embedder should have called Dart_LoadScript by now. |
return false; |
@@ -1615,7 +1624,7 @@ static uint8_t* allocator(uint8_t* ptr, intptr_t old_size, intptr_t new_size) { |
DART_EXPORT bool Dart_Post(Dart_Port port_id, Dart_Handle handle) { |
Isolate* isolate = Isolate::Current(); |
DARTSCOPE(isolate); |
- if (port_id == ILLEGAL_PORT) { |
+ if (port_id == DART_ILLEGAL_PORT) { |
return false; |
} |
const Object& object = Object::Handle(isolate, Api::UnwrapHandle(handle)); |
@@ -1632,7 +1641,7 @@ DART_EXPORT Dart_Handle Dart_NewSendPort(Dart_Port port_id) { |
Isolate* isolate = Isolate::Current(); |
DARTSCOPE(isolate); |
CHECK_CALLBACK_STATE(isolate); |
- if (port_id == ILLEGAL_PORT) { |
+ if (port_id == DART_ILLEGAL_PORT) { |
return Api::NewError("%s: illegal port_id %" Pd64 ".", |
CURRENT_FUNC, |
port_id); |
@@ -5547,7 +5556,10 @@ DART_EXPORT Dart_Handle Dart_SetPeer(Dart_Handle object, void* peer) { |
// --- Service support --- |
DART_EXPORT bool Dart_IsServiceIsolate(Dart_Isolate isolate) { |
- Isolate* iso = reinterpret_cast<Isolate*>(isolate); |
+ Isolate* iso = Api::CastIsolate(isolate); |
+ if (iso == NULL) { |
+ return false; |
+ } |
return ServiceIsolate::IsServiceIsolate(iso); |
} |