Skip to content

Commit 0bba590

Browse files
trevnorrisbnoordhuis
authored andcommitted
bindings: update api
All compile time warnings about using deprecated APIs have been suppressed by updating node's API. Though there are still many function calls that can accept Isolate, and still need to be updated. node_isolate had to be added as an extern variable in node.h and node_object_wrap.h Also a couple small fixes for Error handling. Before v8 3.16.6 the error stack message was lazily written when it was needed, which allowed you to change the message after instantiation. Then the stack would be written with the new message the first time it was accessed. Though that has changed. Now it creates the stack message on instantiation. So setting a different message afterwards won't be displayed. This is not a complete fix for the problem. Getting error without any message isn't very useful.
1 parent 06bec0e commit 0bba590

29 files changed

Lines changed: 139 additions & 118 deletions

lib/fs.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,8 @@ function rethrow() {
6363
var backtrace = new Error;
6464
return function(err) {
6565
if (err) {
66-
backtrace.message = err.message;
66+
backtrace.stack = err.name + ': ' + err.message +
67+
backtrace.stack.substr(backtrace.name.length);
6768
err = backtrace;
6869
throw err;
6970
}

src/cares_wrap.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -272,15 +272,15 @@ class QueryWrap {
272272
QueryWrap() {
273273
HandleScope scope;
274274

275-
object_ = Persistent<Object>::New(Object::New());
275+
object_ = Persistent<Object>::New(node_isolate, Object::New());
276276
}
277277

278278
virtual ~QueryWrap() {
279279
assert(!object_.IsEmpty());
280280

281281
object_->Delete(oncomplete_sym);
282282

283-
object_.Dispose();
283+
object_.Dispose(node_isolate);
284284
object_.Clear();
285285
}
286286

src/fs_event_wrap.cc

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,8 @@ void FSEventWrap::Initialize(Handle<Object> target) {
7474
NODE_SET_PROTOTYPE_METHOD(t, "close", Close);
7575

7676
target->Set(String::NewSymbol("FSEvent"),
77-
Persistent<FunctionTemplate>::New(t)->GetFunction());
77+
Persistent<FunctionTemplate>::New(node_isolate,
78+
t)->GetFunction());
7879
}
7980

8081

@@ -172,7 +173,7 @@ Handle<Value> FSEventWrap::Close(const Arguments& args) {
172173
// and legal, HandleWrap::Close() deals with them the same way.
173174
assert(!args.Holder().IsEmpty());
174175
assert(args.Holder()->InternalFieldCount() > 0);
175-
void* ptr = args.Holder()->GetPointerFromInternalField(0);
176+
void* ptr = args.Holder()->GetAlignedPointerFromInternalField(0);
176177
FSEventWrap* wrap = static_cast<FSEventWrap*>(ptr);
177178

178179
if (wrap == NULL || wrap->initialized_ == false) {

src/handle_wrap.cc

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ Handle<Value> HandleWrap::Close(const Arguments& args) {
8484
HandleScope scope;
8585

8686
HandleWrap *wrap = static_cast<HandleWrap*>(
87-
args.Holder()->GetPointerFromInternalField(0));
87+
args.Holder()->GetAlignedPointerFromInternalField(0));
8888

8989
// guard against uninitialized handle or double close
9090
if (wrap == NULL || wrap->handle__ == NULL) {
@@ -115,8 +115,8 @@ HandleWrap::HandleWrap(Handle<Object> object, uv_handle_t* h) {
115115
HandleScope scope;
116116
assert(object_.IsEmpty());
117117
assert(object->InternalFieldCount() > 0);
118-
object_ = v8::Persistent<v8::Object>::New(object);
119-
object_->SetPointerInInternalField(0, this);
118+
object_ = v8::Persistent<v8::Object>::New(node_isolate, object);
119+
object_->SetAlignedPointerInInternalField(0, this);
120120
ngx_queue_insert_tail(&handle_wrap_queue, &handle_wrap_queue_);
121121
}
122122

@@ -147,8 +147,8 @@ void HandleWrap::OnClose(uv_handle_t* handle) {
147147
MakeCallback(wrap->object_, close_sym, 0, NULL);
148148
}
149149

150-
wrap->object_->SetPointerInInternalField(0, NULL);
151-
wrap->object_.Dispose();
150+
wrap->object_->SetAlignedPointerInInternalField(0, NULL);
151+
wrap->object_.Dispose(node_isolate);
152152
wrap->object_.Clear();
153153

154154
delete wrap;

src/handle_wrap.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ namespace node {
5050
assert(!args.Holder().IsEmpty()); \
5151
assert(args.Holder()->InternalFieldCount() > 0); \
5252
type* wrap = static_cast<type*>( \
53-
args.Holder()->GetPointerFromInternalField(0));
53+
args.Holder()->GetAlignedPointerFromInternalField(0));
5454

5555
class HandleWrap {
5656
public:

src/node.cc

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ static void Spin(uv_idle_t* handle, int status) {
195195
abort();
196196
}
197197
Local<Function> cb = cb_v.As<Function>();
198-
process_tickFromSpinner = Persistent<Function>::New(cb);
198+
process_tickFromSpinner = Persistent<Function>::New(node_isolate, cb);
199199
}
200200

201201
TryCatch try_catch;
@@ -912,7 +912,7 @@ MakeDomainCallback(const Handle<Object> object,
912912
abort();
913913
}
914914
Local<Function> cb = cb_v.As<Function>();
915-
process_tickDomainCallback = Persistent<Function>::New(cb);
915+
process_tickDomainCallback = Persistent<Function>::New(node_isolate, cb);
916916
}
917917

918918
// lazy load domain specific symbols
@@ -1002,7 +1002,7 @@ MakeCallback(const Handle<Object> object,
10021002
abort();
10031003
}
10041004
Local<Function> cb = cb_v.As<Function>();
1005-
process_tickCallback = Persistent<Function>::New(cb);
1005+
process_tickCallback = Persistent<Function>::New(node_isolate, cb);
10061006
}
10071007

10081008
TryCatch try_catch;
@@ -1802,7 +1802,7 @@ v8::Handle<v8::Value> MemoryUsage(const v8::Arguments& args) {
18021802

18031803
// V8 memory usage
18041804
HeapStatistics v8_heap_stats;
1805-
V8::GetHeapStatistics(&v8_heap_stats);
1805+
node_isolate->GetHeapStatistics(&v8_heap_stats);
18061806
info->Set(heap_total_symbol,
18071807
Integer::NewFromUnsigned(v8_heap_stats.total_heap_size()));
18081808
info->Set(heap_used_symbol,
@@ -2021,7 +2021,7 @@ static Handle<Value> Binding(const Arguments& args) {
20212021
node_module_struct* modp;
20222022

20232023
if (binding_cache.IsEmpty()) {
2024-
binding_cache = Persistent<Object>::New(Object::New());
2024+
binding_cache = Persistent<Object>::New(node_isolate, Object::New());
20252025
}
20262026

20272027
Local<Object> exports;
@@ -2307,7 +2307,8 @@ Handle<Object> SetupProcessObject(int argc, char *argv[]) {
23072307

23082308
process_template->SetClassName(String::NewSymbol("process"));
23092309

2310-
process = Persistent<Object>::New(process_template->GetFunction()->NewInstance());
2310+
process = Persistent<Object>::New(node_isolate,
2311+
process_template->GetFunction()->NewInstance());
23112312

23122313
process->SetAccessor(String::New("title"),
23132314
ProcessTitleGetter,
@@ -2317,7 +2318,7 @@ Handle<Object> SetupProcessObject(int argc, char *argv[]) {
23172318
process->Set(String::NewSymbol("version"), String::New(NODE_VERSION));
23182319

23192320
// process.moduleLoadList
2320-
module_load_list = Persistent<Array>::New(Array::New());
2321+
module_load_list = Persistent<Array>::New(node_isolate, Array::New());
23212322
process->Set(String::NewSymbol("moduleLoadList"), module_load_list);
23222323

23232324
// process.versions
@@ -2984,6 +2985,10 @@ char** Init(int argc, char *argv[]) {
29842985
}
29852986
V8::SetFlagsFromCommandLine(&v8argc, v8argv, false);
29862987

2988+
// Fetch a reference to the main isolate, so we have a reference to it
2989+
// even when we need it to access it from another (debugger) thread.
2990+
node_isolate = Isolate::GetCurrent();
2991+
29872992
#ifdef __POSIX__
29882993
// Ignore SIGPIPE
29892994
RegisterSignalHandler(SIGPIPE, SIG_IGN);
@@ -2999,10 +3004,6 @@ char** Init(int argc, char *argv[]) {
29993004

30003005
V8::SetFatalErrorHandler(node::OnFatalError);
30013006

3002-
// Fetch a reference to the main isolate, so we have a reference to it
3003-
// even when we need it to access it from another (debugger) thread.
3004-
node_isolate = Isolate::GetCurrent();
3005-
30063007
// If the --debug flag was specified then initialize the debug thread.
30073008
if (use_debug_agent) {
30083009
EnableDebug(debug_wait_connect);
@@ -3111,7 +3112,7 @@ int Start(int argc, char *argv[]) {
31113112

31123113
V8::Initialize();
31133114
{
3114-
Locker locker;
3115+
Locker locker(node_isolate);
31153116
HandleScope handle_scope;
31163117

31173118
// Create the one and only Context.
@@ -3137,7 +3138,7 @@ int Start(int argc, char *argv[]) {
31373138
RunAtExit();
31383139

31393140
#ifndef NDEBUG
3140-
context.Dispose();
3141+
context.Dispose(node_isolate);
31413142
#endif
31423143
}
31433144

src/node.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,8 @@
8686

8787
namespace node {
8888

89+
extern v8::Isolate* node_isolate;
90+
8991
NODE_EXTERN extern bool no_deprecation;
9092

9193
NODE_EXTERN int Start(int argc, char *argv[]);
@@ -96,7 +98,7 @@ void Load(v8::Handle<v8::Object> process);
9698
void EmitExit(v8::Handle<v8::Object> process);
9799

98100
#define NODE_PSYMBOL(s) \
99-
v8::Persistent<v8::String>::New(v8::String::NewSymbol(s))
101+
v8::Persistent<v8::String>::New(node_isolate, v8::String::NewSymbol(s))
100102

101103
/* Converts a unixtime to V8 Date */
102104
#define NODE_UNIXTIME_V8(t) v8::Date::New(1000*static_cast<double>(t))
@@ -153,7 +155,7 @@ v8::Local<v8::Object> BuildStatsObject(const uv_statbuf_t* s);
153155
static inline v8::Persistent<v8::Function>* cb_persist(
154156
const v8::Local<v8::Value> &v) {
155157
v8::Persistent<v8::Function> *fn = new v8::Persistent<v8::Function>();
156-
*fn = v8::Persistent<v8::Function>::New(v8::Local<v8::Function>::Cast(v));
158+
*fn = v8::Persistent<v8::Function>::New(node_isolate, v8::Local<v8::Function>::Cast(v));
157159
return fn;
158160
}
159161

@@ -165,7 +167,7 @@ static inline v8::Persistent<v8::Function>* cb_unwrap(void *data) {
165167
}
166168

167169
static inline void cb_destroy(v8::Persistent<v8::Function> * cb) {
168-
cb->Dispose();
170+
cb->Dispose(node_isolate);
169171
delete cb;
170172
}
171173

src/node_buffer.cc

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ Buffer::Buffer(Handle<Object> wrapper, size_t length) : ObjectWrap() {
187187

188188
length_ = 0;
189189
callback_ = NULL;
190-
handle_.SetWrapperClassId(BUFFER_CLASS_ID);
190+
handle_.SetWrapperClassId(node_isolate, BUFFER_CLASS_ID);
191191

192192
Replace(NULL, length, NULL, NULL);
193193
}
@@ -208,7 +208,7 @@ void Buffer::Replace(char *data, size_t length,
208208
callback_(data_, callback_hint_);
209209
} else if (length_) {
210210
delete [] data_;
211-
V8::AdjustAmountOfExternalAllocatedMemory(
211+
node_isolate->AdjustAmountOfExternalAllocatedMemory(
212212
-static_cast<intptr_t>(sizeof(Buffer) + length_));
213213
}
214214

@@ -222,7 +222,8 @@ void Buffer::Replace(char *data, size_t length,
222222
data_ = new char[length_];
223223
if (data)
224224
memcpy(data_, data, length_);
225-
V8::AdjustAmountOfExternalAllocatedMemory(sizeof(Buffer) + length_);
225+
node_isolate->AdjustAmountOfExternalAllocatedMemory(sizeof(Buffer) +
226+
length_);
226227
} else {
227228
data_ = NULL;
228229
}
@@ -1039,7 +1040,8 @@ bool Buffer::HasInstance(Handle<Value> val) {
10391040

10401041
Handle<Value> SetFastBufferConstructor(const Arguments& args) {
10411042
assert(args[0]->IsFunction());
1042-
fast_buffer_constructor = Persistent<Function>::New(args[0].As<Function>());
1043+
fast_buffer_constructor = Persistent<Function>::New(node_isolate,
1044+
args[0].As<Function>());
10431045
return Undefined();
10441046
}
10451047

@@ -1117,7 +1119,7 @@ void Buffer::Initialize(Handle<Object> target) {
11171119
chars_written_sym = NODE_PSYMBOL("_charsWritten");
11181120

11191121
Local<FunctionTemplate> t = FunctionTemplate::New(Buffer::New);
1120-
constructor_template = Persistent<FunctionTemplate>::New(t);
1122+
constructor_template = Persistent<FunctionTemplate>::New(node_isolate, t);
11211123
constructor_template->InstanceTemplate()->SetInternalFieldCount(1);
11221124
constructor_template->SetClassName(String::NewSymbol("SlowBuffer"));
11231125

src/node_counters.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ void InitPerfCounters(Handle<Object> target) {
122122
};
123123

124124
for (int i = 0; i < ARRAY_SIZE(tab); i++) {
125-
tab[i].templ = Persistent<FunctionTemplate>::New(
125+
tab[i].templ = Persistent<FunctionTemplate>::New(node_isolate,
126126
FunctionTemplate::New(tab[i].func));
127127
target->Set(String::NewSymbol(tab[i].name), tab[i].templ->GetFunction());
128128
}

0 commit comments

Comments
 (0)