Index: runtime/vm/dart_api_impl.cc |
diff --git a/runtime/vm/dart_api_impl.cc b/runtime/vm/dart_api_impl.cc |
index a6feef09d89755ee741905a236b3a19f8211441d..bf2dfd144eece2a4c5d9e1fe4595526dcdab8de2 100644 |
--- a/runtime/vm/dart_api_impl.cc |
+++ b/runtime/vm/dart_api_impl.cc |
@@ -392,7 +392,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)); |
} |
@@ -1306,12 +1314,12 @@ DART_EXPORT Dart_Isolate Dart_CreateIsolate(const char* script_uri, |
} |
#endif // defined(DART_NO_SNAPSHOT). |
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; |
} |
@@ -1342,11 +1350,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(); |
} |
@@ -1359,15 +1366,19 @@ 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::EnsureInit(); |
Thread::EnterIsolate(iso); |
+ return true; |
} |
@@ -1484,27 +1495,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; |
@@ -1619,7 +1628,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)); |
@@ -1636,7 +1645,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); |
@@ -5551,7 +5560,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); |
} |