Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix issue with worker_threads #4

Merged
merged 1 commit into from
Jan 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions src/Addon.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@
limitations under the License.
*/

#ifndef _ADDON_H_
#define _ADDON_H_
#include <napi.h>
#include "GSException.h"
#include "StoreFactory.h"
Expand All @@ -29,14 +27,16 @@
#include "Store.h"
#include "RowKeyPredicate.h"
#include "QueryAnalysisEntry.h"
#include "Util.h"

Napi::Object init(Napi::Env env, Napi::Object exports);

#endif // _ADDON_H_

using namespace griddb;

Napi::Object init(Napi::Env env, Napi::Object exports) {
#if NAPI_VERSION > 5
env.SetInstanceData<AddonData, Util::addonDataFinalizer>(new AddonData());
#endif
GSException::init(env, exports);
StoreFactory::init(env, exports);
Store::init(env, exports);
Expand All @@ -53,4 +53,3 @@ Napi::Object init(Napi::Env env, Napi::Object exports) {
}

NODE_API_MODULE(addon, init);

8 changes: 8 additions & 0 deletions src/AggregationResult.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,24 @@

namespace griddb {

#if NAPI_VERSION <= 5
Napi::FunctionReference AggregationResult::constructor;
#endif

Napi::Object AggregationResult::init(Napi::Env env, Napi::Object exports) {
Napi::HandleScope scope(env);

Napi::Function func = DefineClass(env, "AggregationResult", {
InstanceMethod("get", &AggregationResult::get) });

#if NAPI_VERSION > 5
Napi::FunctionReference* constructor = new Napi::FunctionReference();
*constructor = Napi::Persistent(func);
Util::setInstanceData(env, "AggregationResult", constructor);
#else
constructor = Napi::Persistent(func);
constructor.SuppressDestruct();
#endif
exports.Set("AggregationResult", func);
return exports;
}
Expand Down
2 changes: 2 additions & 0 deletions src/AggregationResult.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,10 @@ namespace griddb {

class AggregationResult : public Napi::ObjectWrap<AggregationResult> {
public:
#if NAPI_VERSION <= 5
// Constructor static variable
static Napi::FunctionReference constructor;
#endif
static Napi::Object init(Napi::Env env, Napi::Object exports);

explicit AggregationResult(const Napi::CallbackInfo &info);
Expand Down
18 changes: 18 additions & 0 deletions src/Container.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@

namespace griddb {

#if NAPI_VERSION <= 5
Napi::FunctionReference Container::constructor;
#endif

Napi::Object Container::init(Napi::Env env, Napi::Object exports) {
Napi::HandleScope scope(env);
Expand All @@ -41,8 +43,14 @@ Napi::Object Container::init(Napi::Env env, Napi::Object exports) {
InstanceAccessor("type", &Container::getType, nullptr)
});

#if NAPI_VERSION > 5
Napi::FunctionReference* constructor = new Napi::FunctionReference();
*constructor = Napi::Persistent(func);
Util::setInstanceData(env, "Container", constructor);
#else
constructor = Napi::Persistent(func);
constructor.SuppressDestruct();
#endif
exports.Set("Container", func);
return exports;
}
Expand Down Expand Up @@ -201,8 +209,13 @@ Napi::Value Container::query(const Napi::CallbackInfo &info) {
mContainerInfo);
auto gsRowPtr = Napi::External<GSRow>::New(env, mRow);

#if NAPI_VERSION > 5
return scope.Escape(Util::getInstanceData(env, "Query")->
New({queryPtr, containerInfoPtr, gsRowPtr})).ToObject();
#else
return scope.Escape(Query::constructor.New( { queryPtr, containerInfoPtr,
gsRowPtr })).ToObject();
#endif
}

Napi::Value Container::get(const Napi::CallbackInfo &info) {
Expand Down Expand Up @@ -329,8 +342,13 @@ Napi::Value Container::queryByTimeSeriesRange(const Napi::CallbackInfo &info) {
mContainerInfo);
auto gsRowPtr = Napi::External<GSRow>::New(env, mRow);

#if NAPI_VERSION > 5
return scope.Escape(Util::getInstanceData(env, "Query")->
New({queryPtr, containerInfoPtr, gsRowPtr})).ToObject();
#else
return scope.Escape(Query::constructor.New( { queryPtr, containerInfoPtr,
gsRowPtr })).ToObject();
#endif
}

Container::~Container() {
Expand Down
2 changes: 2 additions & 0 deletions src/Container.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,10 @@ namespace griddb {

class Container: public Napi::ObjectWrap<Container> {
public:
#if NAPI_VERSION <= 5
// Contructor static variable
static Napi::FunctionReference constructor;
#endif
static Napi::Object init(Napi::Env env, Napi::Object exports);

explicit Container(const Napi::CallbackInfo &info);
Expand Down
14 changes: 14 additions & 0 deletions src/ContainerInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@

namespace griddb {

#if NAPI_VERSION <= 5
Napi::FunctionReference ContainerInfo::constructor;
#endif

Napi::Object ContainerInfo::init(const Napi::Env env, Napi::Object exports) {
Napi::HandleScope scope(env);
Expand All @@ -42,8 +44,14 @@ Napi::Object ContainerInfo::init(const Napi::Env env, Napi::Object exports) {
&ContainerInfo::setExpiration),
});

#if NAPI_VERSION > 5
Napi::FunctionReference* constructor = new Napi::FunctionReference();
*constructor = Napi::Persistent(func);
Util::setInstanceData(env, "ContainerInfo", constructor);
#else
constructor = Napi::Persistent(func);
constructor.SuppressDestruct();
#endif
exports.Set("ContainerInfo", func);
return exports;
}
Expand Down Expand Up @@ -632,9 +640,15 @@ Napi::Value ContainerInfo::getExpiration(
mContainerInfo.timeSeriesProperties->expirationDivisionCount;
// Create new ExpirationInfo object
Napi::EscapableHandleScope scope(env);
#if NAPI_VERSION > 5
return scope.Escape(Util::getInstanceData(env, "ExpirationInfo")->New( {
Napi::Number::New(env, time), Napi::Number::New(env, unit),
Napi::Number::New(env, division_count) })).ToObject();
#else
return scope.Escape(ExpirationInfo::constructor.New( {
Napi::Number::New(env, time), Napi::Number::New(env, unit),
Napi::Number::New(env, division_count) })).ToObject();
#endif
} else {
return env.Null();
}
Expand Down
2 changes: 2 additions & 0 deletions src/ContainerInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,10 @@ namespace griddb {

class ContainerInfo: public Napi::ObjectWrap<ContainerInfo> {
public:
#if NAPI_VERSION <= 5
// Constructor
static Napi::FunctionReference constructor;
#endif
explicit ContainerInfo(const Napi::CallbackInfo &info);
static Napi::Object init(Napi::Env env, Napi::Object exports);

Expand Down
9 changes: 9 additions & 0 deletions src/ExpirationInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,13 @@
#include "ExpirationInfo.h"
#include "GSException.h"
#include "Macro.h"
#include "Util.h"

namespace griddb {

#if NAPI_VERSION <= 5
Napi::FunctionReference ExpirationInfo::constructor;
#endif

void ExpirationInfo::init(Napi::Env env, Napi::Object exports) {
Napi::Function func = DefineClass(env, "ExpirationInfo",
Expand All @@ -30,8 +33,14 @@ void ExpirationInfo::init(Napi::Env env, Napi::Object exports) {
ExpirationInfo::InstanceAccessor("divisionCount",
&ExpirationInfo::getDivisionCount,
&ExpirationInfo::setDivisionCount), });
#if NAPI_VERSION > 5
Napi::FunctionReference* constructor = new Napi::FunctionReference();
*constructor = Napi::Persistent(func);
Util::setInstanceData(env, "ExpirationInfo", constructor);
#else
constructor = Napi::Persistent(func);
constructor.SuppressDestruct();
#endif
exports.Set("ExpirationInfo", func);
}

Expand Down
2 changes: 2 additions & 0 deletions src/ExpirationInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,10 @@ namespace griddb {

class ExpirationInfo: public Napi::ObjectWrap<ExpirationInfo> {
public:
#if NAPI_VERSION <= 5
// Constructor
static Napi::FunctionReference constructor;
#endif
explicit ExpirationInfo(const Napi::CallbackInfo &info);
static void init(Napi::Env env, Napi::Object exports);

Expand Down
18 changes: 18 additions & 0 deletions src/GSException.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,12 @@

#include <string>
#include "GSException.h"
#include "Util.h"

namespace griddb {
#if NAPI_VERSION <= 5
Napi::FunctionReference GSException::constructor;
#endif
Napi::Object GSException::init(Napi::Env env, Napi::Object exports) {
Napi::HandleScope scope(env);
Napi::Function t = DefineClass(env, "GSException", {
Expand All @@ -29,8 +32,14 @@ Napi::Object GSException::init(Napi::Env env, Napi::Object exports) {
InstanceMethod("getMessage", &GSException::getMessage),
InstanceMethod("getLocation", &GSException::getLocation)
});
#if NAPI_VERSION > 5
Napi::FunctionReference* constructor = new Napi::FunctionReference();
*constructor = Napi::Persistent(t);
Util::setInstanceData(env, "GSException", constructor);
#else
constructor = Napi::Persistent(t);
constructor.SuppressDestruct();
#endif
exports.Set("GSException", t);
return exports;
}
Expand Down Expand Up @@ -74,12 +83,21 @@ Napi::Object GSException::New(Napi::Env env, std::string message,
}
Napi::Object GSException::New(Napi::Env env, GSResult code,
const char* message, const char* location, void* resource) {
#if NAPI_VERSION > 5
return Util::getInstanceData(env, "GSException")->New({
Napi::Number::New(env, code),
message ? Napi::String::New(env, message) : env.Null(),
location ? Napi::String::New(env, location) : env.Null(),
resource ? Napi::External<void>::New(env, resource) : env.Null()
});
#else
return constructor.New( {
Napi::Number::New(env, code),
message ? Napi::String::New(env, message) : env.Null(),
location ? Napi::String::New(env, location) : env.Null(),
resource ? Napi::External<void>::New(env, resource) : env.Null()
});
#endif
}
GSException::~GSException() {
}
Expand Down
2 changes: 2 additions & 0 deletions src/GSException.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@
namespace griddb {
class GSException : public Napi::ObjectWrap<GSException>{
public:
#if NAPI_VERSION <= 5
static Napi::FunctionReference constructor;
#endif
static Napi::Object init(Napi::Env env, Napi::Object exports);
static Napi::Object New(Napi::Env env, GSResult code,
void* resource = NULL);
Expand Down
8 changes: 8 additions & 0 deletions src/PartitionController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@

namespace griddb {

#if NAPI_VERSION <= 5
Napi::FunctionReference PartitionController::constructor;
#endif

Napi::Object PartitionController::init(Napi::Env env, Napi::Object exports) {
Napi::HandleScope scope(env);
Expand All @@ -36,8 +38,14 @@ Napi::Object PartitionController::init(Napi::Env env, Napi::Object exports) {
&PartitionController::getContainerNames)
});

#if NAPI_VERSION > 5
Napi::FunctionReference* constructor = new Napi::FunctionReference();
*constructor = Napi::Persistent(func);
Util::setInstanceData(env, "PartitionController", constructor);
#else
constructor = Napi::Persistent(func);
constructor.SuppressDestruct();
#endif
exports.Set("PartitionController", func);
return exports;
}
Expand Down
2 changes: 2 additions & 0 deletions src/PartitionController.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,10 @@ namespace griddb {

class PartitionController: public Napi::ObjectWrap<PartitionController> {
public:
#if NAPI_VERSION <= 5
// Constructor
static Napi::FunctionReference constructor;
#endif
static Napi::Object init(Napi::Env env, Napi::Object exports);
explicit PartitionController(const Napi::CallbackInfo &info);

Expand Down
19 changes: 19 additions & 0 deletions src/Query.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@

namespace griddb {

#if NAPI_VERSION <= 5
Napi::FunctionReference Query::constructor;
#endif

Napi::Object Query::init(Napi::Env env, Napi::Object exports) {
Napi::HandleScope scope(env);
Expand All @@ -29,8 +31,14 @@ Napi::Object Query::init(Napi::Env env, Napi::Object exports) {
InstanceMethod("getRowSet", &Query::getRowSet),
});

#if NAPI_VERSION > 5
Napi::FunctionReference* constructor = new Napi::FunctionReference();
*constructor = Napi::Persistent(func);
Util::setInstanceData(env, "Query", constructor);
#else
constructor = Napi::Persistent(func);
constructor.SuppressDestruct();
#endif
exports.Set("Query", func);
return exports;
}
Expand Down Expand Up @@ -69,8 +77,14 @@ Napi::Value Query::fetch(const Napi::CallbackInfo &info) {
auto gsContainerInfoPtr =
Napi::External<GSContainerInfo>::New(env, mContainerInfo);
auto gsRowPtr = Napi::External<GSRow>::New(env, mRow);
#if NAPI_VERSION > 5
Napi::Value rowsetWrapper = scope.Escape(
Util::getInstanceData(env, "RowSet")->New({
rowsetPtr, gsContainerInfoPtr, gsRowPtr })).ToObject();
#else
Napi::Value rowsetWrapper = scope.Escape(RowSet::constructor.New({
rowsetPtr, gsContainerInfoPtr, gsRowPtr })).ToObject();
#endif
deferred.Resolve(rowsetWrapper);
return deferred.Promise();
}
Expand Down Expand Up @@ -132,8 +146,13 @@ Napi::Value Query::getRowSet(const Napi::CallbackInfo &info) {
::New(env, mContainerInfo);
auto row_ptr = Napi::External<GSRow>::New(env, mRow);
Napi::EscapableHandleScope scope(env);
#if NAPI_VERSION > 5
return scope.Escape(Util::getInstanceData(env, "RowSet")->New({
rowset_ptr, containerInfo_ptr, row_ptr })).ToObject();
#else
return scope.Escape(RowSet::constructor.New({
rowset_ptr, containerInfo_ptr, row_ptr })).ToObject();
#endif
}

GSQuery* Query::gsPtr() {
Expand Down
2 changes: 2 additions & 0 deletions src/Query.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,10 @@ namespace griddb {

class Query: public Napi::ObjectWrap<Query> {
public:
#if NAPI_VERSION <= 5
// Constructor static variable
static Napi::FunctionReference constructor;
#endif
static Napi::Object init(Napi::Env env, Napi::Object exports);

explicit Query(const Napi::CallbackInfo &info);
Expand Down
Loading