~yolanda.robla/ubuntu/trusty/nodejs/add_distribution

« back to all changes in this revision

Viewing changes to src/fs_event_wrap.cc

  • Committer: Package Import Robot
  • Author(s): Jérémy Lal
  • Date: 2013-08-14 00:16:46 UTC
  • mfrom: (7.1.40 sid)
  • Revision ID: package-import@ubuntu.com-20130814001646-bzlysfh8sd6mukbo
Tags: 0.10.15~dfsg1-4
* Update 2005 patch, adding a handful of tests that can fail on
  slow platforms.
* Add 1004 patch to fix test failures when writing NaN to buffer
  on mipsel.

Show diffs side-by-side

added added

removed removed

Lines of Context:
19
19
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
20
20
// USE OR OTHER DEALINGS IN THE SOFTWARE.
21
21
 
22
 
#include <node.h>
23
 
#include <handle_wrap.h>
 
22
#include "node.h"
 
23
#include "handle_wrap.h"
24
24
 
25
25
#include <stdlib.h>
26
26
 
28
28
 
29
29
namespace node {
30
30
 
31
 
#define UNWRAP                                                              \
32
 
  assert(!args.Holder().IsEmpty());                                         \
33
 
  assert(args.Holder()->InternalFieldCount() > 0);                          \
34
 
  FSEventWrap* wrap =                                                       \
35
 
      static_cast<FSEventWrap*>(args.Holder()->GetPointerFromInternalField(0)); \
36
 
  if (!wrap) {                                                              \
37
 
    uv_err_t err;                                                           \
38
 
    err.code = UV_EBADF;                                                    \
39
 
    SetErrno(err);                                                          \
40
 
    return scope.Close(Integer::New(-1));                                   \
41
 
  }
 
31
static Persistent<String> onchange_sym;
42
32
 
43
33
class FSEventWrap: public HandleWrap {
44
34
public:
61
51
 
62
52
FSEventWrap::FSEventWrap(Handle<Object> object): HandleWrap(object,
63
53
                                                    (uv_handle_t*)&handle_) {
64
 
  handle_.data = reinterpret_cast<void*>(this);
 
54
  handle_.data = static_cast<void*>(this);
65
55
  initialized_ = false;
66
56
}
67
57
 
101
91
Handle<Value> FSEventWrap::Start(const Arguments& args) {
102
92
  HandleScope scope;
103
93
 
104
 
  UNWRAP
 
94
  UNWRAP(FSEventWrap)
105
95
 
106
96
  if (args.Length() < 1 || !args[0]->IsString()) {
107
97
    return ThrowException(Exception::TypeError(String::New("Bad arguments")));
108
98
  }
109
99
 
110
 
  String::Utf8Value path(args[0]->ToString());
 
100
  String::Utf8Value path(args[0]);
111
101
 
112
102
  int r = uv_fs_event_init(uv_default_loop(), &wrap->handle_, *path, OnEvent, 0);
113
103
  if (r == 0) {
114
104
    // Check for persistent argument
115
105
    if (!args[1]->IsTrue()) {
116
 
      uv_unref(uv_default_loop());
 
106
      uv_unref(reinterpret_cast<uv_handle_t*>(&wrap->handle_));
117
107
    }
118
108
    wrap->initialized_ = true;
119
109
  } else {
129
119
  HandleScope scope;
130
120
  Local<String> eventStr;
131
121
 
132
 
  FSEventWrap* wrap = reinterpret_cast<FSEventWrap*>(handle->data);
 
122
  FSEventWrap* wrap = static_cast<FSEventWrap*>(handle->data);
133
123
 
134
124
  assert(wrap->object_.IsEmpty() == false);
135
125
 
162
152
  Local<Value> argv[3] = {
163
153
    Integer::New(status),
164
154
    eventStr,
165
 
    filename ? (Local<Value>)String::New(filename) : Local<Value>::New(v8::Null())
 
155
    filename ? static_cast<Local<Value> >(String::New(filename))
 
156
             : Local<Value>::New(v8::Null())
166
157
  };
167
158
 
168
 
  MakeCallback(wrap->object_, "onchange", 3, argv);
 
159
  if (onchange_sym.IsEmpty()) {
 
160
    onchange_sym = NODE_PSYMBOL("onchange");
 
161
  }
 
162
 
 
163
  MakeCallback(wrap->object_, onchange_sym, ARRAY_SIZE(argv), argv);
169
164
}
170
165
 
171
166
 
172
167
Handle<Value> FSEventWrap::Close(const Arguments& args) {
173
168
  HandleScope scope;
174
169
 
175
 
  UNWRAP
 
170
  // Unwrap manually here. The UNWRAP() macro asserts that wrap != NULL.
 
171
  // That usually indicates an error but not here: double closes are possible
 
172
  // and legal, HandleWrap::Close() deals with them the same way.
 
173
  assert(!args.Holder().IsEmpty());
 
174
  assert(args.Holder()->InternalFieldCount() > 0);
 
175
  void* ptr = args.Holder()->GetPointerFromInternalField(0);
 
176
  FSEventWrap* wrap = static_cast<FSEventWrap*>(ptr);
176
177
 
177
 
  if (!wrap->initialized_)
 
178
  if (wrap == NULL || wrap->initialized_ == false) {
178
179
    return Undefined();
179
 
 
 
180
  }
180
181
  wrap->initialized_ = false;
 
182
 
181
183
  return HandleWrap::Close(args);
182
184
}
183
185