Skip to content

Commit 336902a

Browse files
trevnorrisandrewdeandrade
authored andcommitted
core: set PROVIDER type as Persistent class id
Pass along the PROVIDER type, that is already passed to AsyncWrap, along to BaseObject to set the handle_'s class id. This will allow all Persistents to be transversed and uniquely identified by what type they are using APIs such as v8::PersistentHandleVisitor. PR-URL: nodejs/node#1730 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
1 parent 5be0f78 commit 336902a

File tree

3 files changed

+11
-3
lines changed

3 files changed

+11
-3
lines changed

src/async-wrap-inl.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ inline AsyncWrap::AsyncWrap(Environment* env,
1717
v8::Handle<v8::Object> object,
1818
ProviderType provider,
1919
AsyncWrap* parent)
20-
: BaseObject(env, object), bits_(static_cast<uint32_t>(provider) << 1) {
20+
: BaseObject(env, object, provider),
21+
bits_(static_cast<uint32_t>(provider) << 1) {
2122
// Check user controlled flag to see if the init callback should run.
2223
if (!env->using_asyncwrap())
2324
return;

src/base-object-inl.h

+6-1
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,15 @@
1010

1111
namespace node {
1212

13-
inline BaseObject::BaseObject(Environment* env, v8::Local<v8::Object> handle)
13+
inline BaseObject::BaseObject(Environment* env,
14+
v8::Local<v8::Object> handle,
15+
const uint16_t class_id)
1416
: handle_(env->isolate(), handle),
1517
env_(env) {
1618
CHECK_EQ(false, handle.IsEmpty());
19+
// Shift value 8 bits over to try avoiding conflict with anything else.
20+
if (class_id != 0)
21+
handle_.SetWrapperClassId(class_id << 8);
1722
}
1823

1924

src/base-object.h

+3-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@ class Environment;
99

1010
class BaseObject {
1111
public:
12-
BaseObject(Environment* env, v8::Local<v8::Object> handle);
12+
BaseObject(Environment* env,
13+
v8::Local<v8::Object> handle,
14+
const uint16_t class_id = 0);
1315
virtual ~BaseObject();
1416

1517
// Returns the wrapped object. Returns an empty handle when

0 commit comments

Comments
 (0)