summaryrefslogtreecommitdiff
path: root/src/node_stat_watcher.cc
diff options
context:
space:
mode:
authorBen Noordhuis <info@bnoordhuis.nl>2013-09-25 12:57:03 +0200
committerBen Noordhuis <info@bnoordhuis.nl>2013-09-25 19:44:53 +0200
commitc79d5163e530892c62b08d8b814b588220c26ec8 (patch)
tree771823ddf0dac11efe378f8ddc6ddcd0e756a0f0 /src/node_stat_watcher.cc
parent42af62f33adda57d8913768d939c1f4d0f8fe5a3 (diff)
downloadandroid-node-v8-c79d5163e530892c62b08d8b814b588220c26ec8.tar.gz
android-node-v8-c79d5163e530892c62b08d8b814b588220c26ec8.tar.bz2
android-node-v8-c79d5163e530892c62b08d8b814b588220c26ec8.zip
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.
Diffstat (limited to 'src/node_stat_watcher.cc')
-rw-r--r--src/node_stat_watcher.cc21
1 files changed, 11 insertions, 10 deletions
diff --git a/src/node_stat_watcher.cc b/src/node_stat_watcher.cc
index 1cd13c0847..892ccac0e8 100644
--- a/src/node_stat_watcher.cc
+++ b/src/node_stat_watcher.cc
@@ -22,6 +22,8 @@
#include "node_stat_watcher.h"
#include "env.h"
#include "env-inl.h"
+#include "weak-object.h"
+#include "weak-object-inl.h"
#include <assert.h>
#include <string.h>
@@ -61,8 +63,8 @@ static void Delete(uv_handle_t* handle) {
}
-StatWatcher::StatWatcher(Environment* env)
- : ObjectWrap()
+StatWatcher::StatWatcher(Environment* env, Local<Object> wrap)
+ : WeakObject(env->isolate(), wrap)
, watcher_(new uv_fs_poll_t)
, env_(env) {
uv_fs_poll_init(env->event_loop(), watcher_);
@@ -91,7 +93,7 @@ void StatWatcher::Callback(uv_fs_poll_t* handle,
Integer::New(status, node_isolate)
};
MakeCallback(env,
- wrap->handle(node_isolate),
+ wrap->weak_object(node_isolate),
env->onchange_string(),
ARRAY_SIZE(argv),
argv);
@@ -102,8 +104,7 @@ void StatWatcher::New(const FunctionCallbackInfo<Value>& args) {
assert(args.IsConstructCall());
Environment* env = Environment::GetCurrent(args.GetIsolate());
HandleScope handle_scope(args.GetIsolate());
- StatWatcher* s = new StatWatcher(env);
- s->Wrap(args.This());
+ new StatWatcher(env, args.This());
}
@@ -111,23 +112,23 @@ void StatWatcher::Start(const FunctionCallbackInfo<Value>& args) {
assert(args.Length() == 3);
HandleScope scope(node_isolate);
- StatWatcher* wrap = ObjectWrap::Unwrap<StatWatcher>(args.This());
+ StatWatcher* wrap = WeakObject::Unwrap<StatWatcher>(args.This());
String::Utf8Value path(args[0]);
const bool persistent = args[1]->BooleanValue();
const uint32_t interval = args[2]->Uint32Value();
if (!persistent) uv_unref(reinterpret_cast<uv_handle_t*>(wrap->watcher_));
uv_fs_poll_start(wrap->watcher_, Callback, *path, interval);
- wrap->Ref();
+ wrap->ClearWeak();
}
void StatWatcher::Stop(const FunctionCallbackInfo<Value>& args) {
- StatWatcher* wrap = ObjectWrap::Unwrap<StatWatcher>(args.This());
+ StatWatcher* wrap = WeakObject::Unwrap<StatWatcher>(args.This());
Environment* env = wrap->env();
Context::Scope context_scope(env->context());
HandleScope handle_scope(env->isolate());
- MakeCallback(env, wrap->handle(node_isolate), env->onstop_string());
+ MakeCallback(env, wrap->weak_object(node_isolate), env->onstop_string());
wrap->Stop();
}
@@ -135,7 +136,7 @@ void StatWatcher::Stop(const FunctionCallbackInfo<Value>& args) {
void StatWatcher::Stop() {
if (!uv_is_active(reinterpret_cast<uv_handle_t*>(watcher_))) return;
uv_fs_poll_stop(watcher_);
- Unref();
+ MakeWeak();
}