diff options
-rw-r--r-- | lib/fs.js | 15 | ||||
-rw-r--r-- | src/node_stat_watcher.cc | 30 | ||||
-rw-r--r-- | src/node_stat_watcher.h | 3 |
3 files changed, 14 insertions, 34 deletions
diff --git a/lib/fs.js b/lib/fs.js index 8b3b6b233e8..48724272062 100644 --- a/lib/fs.js +++ b/lib/fs.js @@ -912,14 +912,20 @@ function inStatWatchers(filename) { fs.watchFile = function(filename) { var stat; - var options; var listener; + var options = { + // Poll interval in milliseconds. 5007 is what libev used to use. It's + // a little on the slow side but let's stick with it for now to keep + // behavioral changes to a minimum. + interval: 5007, + persistent: true, + }; + if ('object' == typeof arguments[1]) { - options = arguments[1]; + options = util._extend(options, arguments[1]); listener = arguments[2]; } else { - options = {}; listener = arguments[1]; } @@ -927,9 +933,6 @@ fs.watchFile = function(filename) { throw new Error('watchFile requires a listener function'); } - if (options.persistent === undefined) options.persistent = true; - if (options.interval === undefined) options.interval = 0; - if (inStatWatchers(filename)) { stat = statWatchers[filename]; } else { diff --git a/src/node_stat_watcher.cc b/src/node_stat_watcher.cc index 33190895a9d..8f38033d1a2 100644 --- a/src/node_stat_watcher.cc +++ b/src/node_stat_watcher.cc @@ -25,11 +25,6 @@ #include <string.h> #include <stdlib.h> -// Poll interval in milliseconds. 5007 is what libev used to use. It's a little -// on the slow side but let's stick with it for now, keep behavioral changes to -// a minimum. -#define DEFAULT_POLL_INTERVAL 5007 - namespace node { using namespace v8; @@ -76,10 +71,7 @@ void StatWatcher::Callback(uv_fs_poll_t* handle, Handle<Value> StatWatcher::New(const Arguments& args) { - if (!args.IsConstructCall()) { - return FromConstructorTemplate(constructor_template, args); - } - + assert(args.IsConstructCall()); HandleScope scope; StatWatcher* s = new StatWatcher(); s->Wrap(args.Holder()); @@ -88,28 +80,16 @@ Handle<Value> StatWatcher::New(const Arguments& args) { Handle<Value> StatWatcher::Start(const Arguments& args) { + assert(args.Length() == 3); HandleScope scope; - if (args.Length() < 1 || !args[0]->IsString()) { - return ThrowException(Exception::TypeError(String::New("Bad arguments"))); - } - StatWatcher* wrap = ObjectWrap::Unwrap<StatWatcher>(args.Holder()); String::Utf8Value path(args[0]); + const bool persistent = args[1]->BooleanValue(); + const uint32_t interval = args[2]->Uint32Value(); - uint32_t interval = DEFAULT_POLL_INTERVAL; - if (args[2]->IsUint32()) { - 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->persistent_ = args[1]->IsTrue(); - - if (!wrap->persistent_) { - uv_unref(reinterpret_cast<uv_handle_t*>(&wrap->watcher_)); - } - wrap->Ref(); return Undefined(); diff --git a/src/node_stat_watcher.h b/src/node_stat_watcher.h index 5b09d2f04c3..62bbce0fc82 100644 --- a/src/node_stat_watcher.h +++ b/src/node_stat_watcher.h @@ -35,7 +35,6 @@ class StatWatcher : ObjectWrap { static v8::Persistent<v8::FunctionTemplate> constructor_template; StatWatcher() : ObjectWrap() { - persistent_ = false; uv_fs_poll_init(uv_default_loop(), &watcher_); } @@ -52,11 +51,9 @@ class StatWatcher : ObjectWrap { int status, const uv_statbuf_t* prev, const uv_statbuf_t* curr); - void Stop(); uv_fs_poll_t watcher_; - bool persistent_; }; } // namespace node |