Skip to content

Commit

Permalink
client: Add check if worker exists to worker methods
Browse files Browse the repository at this point in the history
Former-commit-id: e193175
  • Loading branch information
LeonMrBonnie committed Oct 17, 2021
1 parent fa55d40 commit 8e1172e
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion client/src/bindings/Worker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ static void ToString(const v8::FunctionCallbackInfo<v8::Value>& info)
{
V8_GET_ISOLATE_CONTEXT();
V8_GET_THIS_INTERNAL_FIELD_EXTERNAL(1, worker, CWorker);
V8_CHECK(worker, "Worker is invalid");

std::ostringstream stream;
stream << "Worker{ file: " << worker->GetFilePath() << " }";
Expand All @@ -50,6 +51,7 @@ static void FilePathGetter(v8::Local<v8::String>, const v8::PropertyCallbackInfo
{
V8_GET_ISOLATE();
V8_GET_THIS_INTERNAL_FIELD_EXTERNAL(1, worker, CWorker);
V8_CHECK(worker, "Worker is invalid");

V8_RETURN_STRING(worker->GetFilePath().c_str());
}
Expand All @@ -58,6 +60,7 @@ static void Start(const v8::FunctionCallbackInfo<v8::Value>& info)
{
V8_GET_ISOLATE_CONTEXT();
V8_GET_THIS_INTERNAL_FIELD_EXTERNAL(1, worker, CWorker);
V8_CHECK(worker, "Worker is invalid");

V8_CHECK(!worker->IsReady(), "Worker is already started");
worker->Start();
Expand All @@ -67,8 +70,8 @@ static void Destroy(const v8::FunctionCallbackInfo<v8::Value>& info)
{
V8_GET_ISOLATE_CONTEXT_RESOURCE();
V8_GET_THIS_INTERNAL_FIELD_EXTERNAL(1, worker, CWorker);
V8_CHECK(worker, "Worker is invalid");

V8_CHECK(worker, "This worker is already destroyed");
worker->Destroy();
info.This()->SetInternalField(0, v8::External::New(isolate, nullptr));
static_cast<CV8ResourceImpl*>(resource)->RemoveWorker(worker);
Expand All @@ -79,6 +82,7 @@ static void Emit(const v8::FunctionCallbackInfo<v8::Value>& info)
V8_GET_ISOLATE_CONTEXT();
V8_CHECK_ARGS_LEN_MIN(1);
V8_GET_THIS_INTERNAL_FIELD_EXTERNAL(1, worker, CWorker);
V8_CHECK(worker, "Worker is invalid");

V8_CHECK(worker->IsReady(), "The worker is not ready yet, wait for the 'load' event");

Expand All @@ -99,6 +103,7 @@ static void On(const v8::FunctionCallbackInfo<v8::Value>& info)
V8_GET_ISOLATE_CONTEXT();
V8_CHECK_ARGS_LEN(2);
V8_GET_THIS_INTERNAL_FIELD_EXTERNAL(1, worker, CWorker);
V8_CHECK(worker, "Worker is invalid");

V8_ARG_TO_STRING(1, eventName);
V8_ARG_TO_FUNCTION(2, callback);
Expand All @@ -111,6 +116,7 @@ static void Once(const v8::FunctionCallbackInfo<v8::Value>& info)
V8_GET_ISOLATE_CONTEXT();
V8_CHECK_ARGS_LEN(2);
V8_GET_THIS_INTERNAL_FIELD_EXTERNAL(1, worker, CWorker);
V8_CHECK(worker, "Worker is invalid");

V8_ARG_TO_STRING(1, eventName);
V8_ARG_TO_FUNCTION(2, callback);
Expand All @@ -122,6 +128,7 @@ static void IsPausedGetter(v8::Local<v8::String>, const v8::PropertyCallbackInfo
{
V8_GET_ISOLATE();
V8_GET_THIS_INTERNAL_FIELD_EXTERNAL(1, worker, CWorker);
V8_CHECK(worker, "Worker is invalid");

V8_RETURN_BOOLEAN(worker->IsPaused());
}
Expand All @@ -131,6 +138,7 @@ static void Pause(const v8::FunctionCallbackInfo<v8::Value>& info)
V8_GET_ISOLATE_CONTEXT();
V8_CHECK_ARGS_LEN(2);
V8_GET_THIS_INTERNAL_FIELD_EXTERNAL(1, worker, CWorker);
V8_CHECK(worker, "Worker is invalid");

V8_CHECK(!worker->IsPaused(), "The worker is already paused");
worker->Pause();
Expand All @@ -141,6 +149,7 @@ static void Resume(const v8::FunctionCallbackInfo<v8::Value>& info)
V8_GET_ISOLATE_CONTEXT();
V8_CHECK_ARGS_LEN(2);
V8_GET_THIS_INTERNAL_FIELD_EXTERNAL(1, worker, CWorker);
V8_CHECK(worker, "Worker is invalid");

V8_CHECK(worker->IsPaused(), "The worker is not paused");
worker->Resume();
Expand Down

0 comments on commit 8e1172e

Please sign in to comment.