Skip to content

Commit c79d516

Browse files
committed
src: remove ObjectWrap dependency from core
Drop the ObjectWrap dependency in favor of an internal WeakObject class. Let's us stop worrying about API and ABI compatibility when making changes to the way node.js deals with weakly persistent handles internally.
1 parent 42af62f commit c79d516

12 files changed

Lines changed: 297 additions & 155 deletions

node.gyp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,8 @@
144144
'src/tree.h',
145145
'src/util.h',
146146
'src/util-inl.h',
147+
'src/weak-object.h',
148+
'src/weak-object-inl.h',
147149
'deps/http_parser/http_parser.h',
148150
'<(SHARED_INTERMEDIATE_DIR)/node_natives.h',
149151
# javascript files to make for an even more pleasant IDE experience

src/node_contextify.cc

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
#include "node_watchdog.h"
2525
#include "env.h"
2626
#include "env-inl.h"
27+
#include "weak-object.h"
28+
#include "weak-object-inl.h"
2729

2830
namespace node {
2931

@@ -304,7 +306,7 @@ class ContextifyContext {
304306
}
305307
};
306308

307-
class ContextifyScript : public ObjectWrap {
309+
class ContextifyScript : public WeakObject {
308310
private:
309311
Persistent<Script> script_;
310312

@@ -335,8 +337,8 @@ class ContextifyScript : public ObjectWrap {
335337
return ThrowError("Must call vm.Script as a constructor.");
336338
}
337339

338-
ContextifyScript *contextify_script = new ContextifyScript();
339-
contextify_script->Wrap(args.Holder());
340+
ContextifyScript* contextify_script =
341+
new ContextifyScript(args.GetIsolate(), args.This());
340342

341343
TryCatch try_catch;
342344
Local<String> code = args[0]->ToString();
@@ -497,7 +499,7 @@ class ContextifyScript : public ObjectWrap {
497499
}
498500

499501
ContextifyScript* wrapped_script =
500-
ObjectWrap::Unwrap<ContextifyScript>(args.This());
502+
WeakObject::Unwrap<ContextifyScript>(args.This());
501503
Local<Script> script = PersistentToLocal(node_isolate,
502504
wrapped_script->script_);
503505

@@ -527,6 +529,11 @@ class ContextifyScript : public ObjectWrap {
527529
}
528530

529531

532+
ContextifyScript(Isolate* isolate, Local<Object> object)
533+
: WeakObject(isolate, object) {
534+
}
535+
536+
530537
~ContextifyScript() {
531538
script_.Dispose();
532539
}

0 commit comments

Comments
 (0)