Skip to content

Commit

Permalink
src: update v0.10/v0.12 compatibility shim
Browse files Browse the repository at this point in the history
Update the compatibility shim to the latest version from
https://github.com/strongloop/strong-agent

Fixes a build error with VS 2013.  Credit goes to @lee-houghton
for coming up with an alternative solution to the SFINAE problem.

Fixes #44 - hopefully for good this time.
  • Loading branch information
bnoordhuis committed Dec 1, 2014
1 parent 2acee76 commit aad9f78
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 29 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "heapdump",
"main": "./lib/main",
"version": "0.3.2",
"version": "0.3.3",
"description": "Make a dump of the V8 heap for later inspection.",
"homepage": "https://github.com/bnoordhuis/node-heapdump",
"author": {
Expand Down
40 changes: 13 additions & 27 deletions src/compat-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#define COMPAT_INL_H_ // NOLINT(build/header_guard)

#include "compat.h"
#include "v8-debug.h" // v8::BreakForCommand

namespace compat {

Expand All @@ -32,32 +33,13 @@ namespace I {
template <typename T>
inline void Use(const T&) {}

template <typename T>
class HasGetConstructorMethod {
#if defined(_MSC_VER) && _MSC_VER < 1800
public:
// VS before 2013 doesn't handle SFINAE. Because V8 3.29 does not compile
// with older VS versions, if the compiler is not at least VS 2013, we know
// that we are building against V8 3.28 or older.
static const bool value = true;
#else
template <typename U>
static int16_t M(int (*)[sizeof(&U::GetConstructor)]);
template <typename U>
static int32_t M(...);

public:
static const bool value = (sizeof(M<T>(0)) == sizeof(int16_t));
#endif
};

// V8 doesn't export a version macro that we can #ifdef on so we apply some
// SFINAE magic to figure out with what V8 version we are dealing. In truth,
// Object::GetConstructor() was removed sometime during the 3.28 development
// cycle but we only have to discern between 3.26 and 3.29 because those are
// the V8 versions that joyent/node and node-forward/node ship respectively.
static const bool AT_LEAST_V8_3_29 =
(HasGetConstructorMethod<v8::Object>::value == false);
// V8 doesn't export a version macro that we can #ifdef on so we apply
// some SFINAE magic to figure out with what V8 version we are dealing.
// v8::BreakForCommand == 7 going back all the way to 3.0.0 until it
// was changed in 3.29 because of new microtask and promise debug APIs.
// We only have to discern between 3.26 and 3.30 because those are the
// V8 versions that joyent/node and node-forward/node ship respectively.
static const bool AT_LEAST_V8_3_29 = (v8::BreakForCommand >= 9);

template <bool AT_LEAST_V8_3_29, typename T, typename U>
void SetAddHistogramSampleFunction(U*, v8::AddHistogramSampleCallback callback,
Expand Down Expand Up @@ -176,7 +158,11 @@ ReturnType ReturnableHandleScope::Return(bool value) {
return Return(Boolean::New(isolate(), value));
}

ReturnType ReturnableHandleScope::Return(intptr_t value) {
ReturnType ReturnableHandleScope::Return(int32_t value) {
return Return(Integer::New(isolate(), value));
}

ReturnType ReturnableHandleScope::Return(uint32_t value) {
return Return(Integer::New(isolate(), value));
}

Expand Down
3 changes: 2 additions & 1 deletion src/compat.h
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,8 @@ class ReturnableHandleScope {
inline explicit ReturnableHandleScope(const ArgumentType& args);
inline ReturnType Return();
inline ReturnType Return(bool value);
inline ReturnType Return(intptr_t value);
inline ReturnType Return(int32_t value);
inline ReturnType Return(uint32_t value);
inline ReturnType Return(double value);
inline ReturnType Return(const char* value);
inline ReturnType Return(v8::Local<v8::Value> value);
Expand Down

0 comments on commit aad9f78

Please sign in to comment.