Skip to content
This repository has been archived by the owner on Jun 13, 2024. It is now read-only.

Commit

Permalink
work around to make it pass build with node.js v10.2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
helloshuangzi authored May 24, 2018
1 parent 30e49bd commit 229a4de
Show file tree
Hide file tree
Showing 7 changed files with 175 additions and 3 deletions.
1 change: 1 addition & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ set_target_properties(${TARGET_NAME} PROPERTIES
# Include directories
target_include_directories(${TARGET_NAME} PRIVATE
${CMAKE_JS_INC}
${PROJECT_SOURCE_DIR}/third-party/node
${PROJECT_SOURCE_DIR}/src
${PROJECT_SOURCE_DIR}/src/module/core-modules/napa
${PROJECT_SOURCE_DIR}/third-party
Expand Down
4 changes: 3 additions & 1 deletion src/v8-extensions/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ endif()
if(CMAKE_JS_VERSION)
# Building Napa as an npm package for node usage (using exported v8 from node.exe)

target_include_directories(${TARGET_NAME} PRIVATE ${CMAKE_JS_INC})
target_include_directories(${TARGET_NAME} PRIVATE
${CMAKE_JS_INC}
${PROJECT_SOURCE_DIR}/third-party/node)
else()
# Building Napa for embed scenarios (static linking with v8)
if (NOT DEFINED NODE_ROOT)
Expand Down
3 changes: 2 additions & 1 deletion test/module/addon/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ set_target_properties(${TARGET_NAME} PROPERTIES
target_include_directories(${TARGET_NAME}
PRIVATE
${NAPA_ROOT}/inc
${CMAKE_JS_INC})
${CMAKE_JS_INC}
${NAPA_ROOT}/third-party/node)

# Link with napa shared library
if (WIN32)
Expand Down
47 changes: 47 additions & 0 deletions third-party/node/callback_scope.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#ifndef SRC_CALLBACK_SCOPE_H_
#define SRC_CALLBACK_SCOPE_H_

#include "core.h"
#include "v8.h"

namespace node {

typedef double async_id;
struct async_context {
::node::async_id async_id;
::node::async_id trigger_async_id;
};

class InternalCallbackScope;

/* This class works like `MakeCallback()` in that it sets up a specific
* asyncContext as the current one and informs the async_hooks and domains
* modules that this context is currently active.
*
* `MakeCallback()` is a wrapper around this class as well as
* `Function::Call()`. Either one of these mechanisms needs to be used for
* top-level calls into JavaScript (i.e. without any existing JS stack).
*
* This object should be stack-allocated to ensure that it is contained in a
* valid HandleScope.
*/
class NODE_EXTERN CallbackScope {
public:
CallbackScope(v8::Isolate* isolate,
v8::Local<v8::Object> resource,
async_context asyncContext);
~CallbackScope();

private:
InternalCallbackScope* private_;
v8::TryCatch try_catch_;

void operator=(const CallbackScope&) = delete;
void operator=(CallbackScope&&) = delete;
CallbackScope(const CallbackScope&) = delete;
CallbackScope(CallbackScope&&) = delete;
};

} // namespace node

#endif // SRC_CALLBACK_SCOPE_H_
44 changes: 44 additions & 0 deletions third-party/node/core.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#ifndef SRC_CORE_H_
#define SRC_CORE_H_

#ifdef _WIN32
# ifndef BUILDING_NODE_EXTENSION
# define NODE_EXTERN __declspec(dllexport)
# else
# define NODE_EXTERN __declspec(dllimport)
# endif
#else
# define NODE_EXTERN /* nothing */
#endif

#define NODE_MAKE_VERSION(major, minor, patch) \
((major) * 0x1000 + (minor) * 0x100 + (patch))

#ifdef __clang__
# define NODE_CLANG_AT_LEAST(major, minor, patch) \
(NODE_MAKE_VERSION(major, minor, patch) <= \
NODE_MAKE_VERSION(__clang_major__, __clang_minor__, __clang_patchlevel__))
#else
# define NODE_CLANG_AT_LEAST(major, minor, patch) (0)
#endif

#ifdef __GNUC__
# define NODE_GNUC_AT_LEAST(major, minor, patch) \
(NODE_MAKE_VERSION(major, minor, patch) <= \
NODE_MAKE_VERSION(__GNUC__, __GNUC_MINOR__, __GNUC_PATCHLEVEL__))
#else
# define NODE_GNUC_AT_LEAST(major, minor, patch) (0)
#endif

#if NODE_CLANG_AT_LEAST(2, 9, 0) || NODE_GNUC_AT_LEAST(4, 5, 0)
# define NODE_DEPRECATED(message, declarator) \
__attribute__((deprecated(message))) declarator
#elif defined(_MSC_VER)
# define NODE_DEPRECATED(message, declarator) \
__declspec(deprecated) declarator
#else
# define NODE_DEPRECATED(message, declarator) \
declarator
#endif

#endif // SRC_CORE_H_
76 changes: 76 additions & 0 deletions third-party/node/exceptions.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
#ifndef SRC_EXCEPTIONS_H_
#define SRC_EXCEPTIONS_H_

#include "core.h"
#include "v8.h"

namespace node {

NODE_EXTERN v8::Local<v8::Value> ErrnoException(v8::Isolate* isolate,
int errorno,
const char* syscall = nullptr,
const char* message = nullptr,
const char* path = nullptr);
NODE_EXTERN v8::Local<v8::Value> UVException(v8::Isolate* isolate,
int errorno,
const char* syscall = nullptr,
const char* message = nullptr,
const char* path = nullptr);
NODE_EXTERN v8::Local<v8::Value> UVException(v8::Isolate* isolate,
int errorno,
const char* syscall,
const char* message,
const char* path,
const char* dest);

NODE_DEPRECATED(
"Use ErrnoException(isolate, ...)",
inline v8::Local<v8::Value> ErrnoException(
int errorno,
const char* syscall = nullptr,
const char* message = nullptr,
const char* path = nullptr) {
return ErrnoException(v8::Isolate::GetCurrent(),
errorno,
syscall,
message,
path);
})

inline v8::Local<v8::Value> UVException(int errorno,
const char* syscall = nullptr,
const char* message = nullptr,
const char* path = nullptr) {
return UVException(v8::Isolate::GetCurrent(),
errorno,
syscall,
message,
path);
}

#ifdef _WIN32
NODE_EXTERN v8::Local<v8::Value> WinapiErrnoException(
v8::Isolate* isolate,
int errorno,
const char *syscall = nullptr,
const char *msg = "",
const char *path = nullptr);

NODE_DEPRECATED(
"Use WinapiErrnoException(isolate, ...)",
inline v8::Local<v8::Value> WinapiErrnoException(
int errorno,
const char *syscall = nullptr,
const char *msg = "",
const char *path = nullptr) {
return WinapiErrnoException(v8::Isolate::GetCurrent(),
errorno,
syscall,
msg,
path);
})
#endif

} // namespace node

#endif // SRC_EXCEPTIONS_H_
3 changes: 2 additions & 1 deletion unittest/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ target_include_directories(${TARGET_NAME}
${NAPA_ROOT}/inc
${NAPA_ROOT}/src
${NAPA_ROOT}/third-party
${CMAKE_JS_INC})
${CMAKE_JS_INC}
${NAPA_ROOT}/third-party/node)

# Set output directory for dll/libs
set_target_properties(${TARGET_NAME} PROPERTIES
Expand Down

0 comments on commit 229a4de

Please sign in to comment.