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

src: guard CallbackScope with N-API v3 #395

Closed
wants to merge 1 commit into from
Closed
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
3 changes: 3 additions & 0 deletions napi-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -3404,6 +3404,8 @@ inline Value EscapableHandleScope::Escape(napi_value escapee) {
return Value(_env, result);
}


#if (NAPI_VERSION > 2)
////////////////////////////////////////////////////////////////////////////////
// CallbackScope class
////////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -3431,6 +3433,7 @@ inline CallbackScope::operator napi_callback_scope() const {
inline Napi::Env CallbackScope::Env() const {
return Napi::Env(_env);
}
#endif

////////////////////////////////////////////////////////////////////////////////
// AsyncContext class
Expand Down
2 changes: 2 additions & 0 deletions napi.h
Original file line number Diff line number Diff line change
Expand Up @@ -1671,6 +1671,7 @@ namespace Napi {
napi_escapable_handle_scope _scope;
};

#if (NAPI_VERSION > 2)
class CallbackScope {
public:
CallbackScope(napi_env env, napi_callback_scope scope);
Expand All @@ -1686,6 +1687,7 @@ namespace Napi {
napi_async_context _async_context;
napi_callback_scope _scope;
};
#endif

class AsyncContext {
public:
Expand Down
4 changes: 4 additions & 0 deletions test/binding.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ Object InitBasicTypesValue(Env env);
Object InitBigInt(Env env);
#endif
Object InitBuffer(Env env);
#if (NAPI_VERSION > 2)
Object InitCallbackScope(Env env);
#endif
Object InitDataView(Env env);
Object InitDataViewReadWrite(Env env);
Object InitError(Env env);
Expand Down Expand Up @@ -50,7 +52,9 @@ Object Init(Env env, Object exports) {
exports.Set("bigint", InitBigInt(env));
#endif
exports.Set("buffer", InitBuffer(env));
#if (NAPI_VERSION > 2)
exports.Set("callbackscope", InitCallbackScope(env));
#endif
exports.Set("dataview", InitDataView(env));
exports.Set("dataview_read_write", InitDataView(env));
exports.Set("dataview_read_write", InitDataViewReadWrite(env));
Expand Down
2 changes: 2 additions & 0 deletions test/callbackscope.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

using namespace Napi;

#if (NAPI_VERSION > 2)
namespace {

static void RunInCallbackScope(const CallbackInfo& info) {
Expand All @@ -18,3 +19,4 @@ Object InitCallbackScope(Env env) {
exports["runInCallbackScope"] = Function::New(env, RunInCallbackScope);
return exports;
}
#endif
6 changes: 6 additions & 0 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,12 @@ if ((process.env.npm_config_NAPI_VERSION !== undefined) &&
testModules.splice(testModules.indexOf('typedarray-bigint'), 1);
}

if ((process.env.npm_config_NAPI_VERSION !== undefined) &&
(process.env.npm_config_NAPI_VERSION < 3)) {
testModules.splice(testModules.indexOf('callbackscope'), 1);
testModules.splice(testModules.indexOf('version_management'), 1);
}

if (typeof global.gc === 'function') {
console.log('Starting test suite\n');

Expand Down