Skip to content

Commit

Permalink
src: use PersistentToLocal() in a few more places
Browse files Browse the repository at this point in the history
Update a few more `Local<T>::New(isolate, persistent)` call sites to
`PersistentToLocal(isolate, persistent)` - the latter has a fast path
for non-weak persistent references.
  • Loading branch information
bnoordhuis committed Aug 3, 2013
1 parent e5791f7 commit d4cc30f
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/handle_wrap.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ class HandleWrap {
virtual ~HandleWrap();

inline v8::Local<v8::Object> object() {
return v8::Local<v8::Object>::New(node_isolate, persistent());
return PersistentToLocal(node_isolate, persistent());
}

inline v8::Persistent<v8::Object>& persistent() {
Expand Down
3 changes: 3 additions & 0 deletions src/node_crypto.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3315,6 +3315,9 @@ void EIO_PBKDF2After(uv_work_t* work_req, int status) {
assert(status == 0);
pbkdf2_req* req = container_of(work_req, pbkdf2_req, work_req);
HandleScope scope(node_isolate);
// Create a new Local that's associated with the current HandleScope.
// PersistentToLocal() returns a handle that gets zeroed when we call
// Dispose() so don't use that.
Local<Object> obj = Local<Object>::New(node_isolate, req->obj);
req->obj.Dispose();
Local<Value> argv[2];
Expand Down
4 changes: 2 additions & 2 deletions src/node_script.cc
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ Local<Object> WrappedContext::NewInstance() {


Local<Context> WrappedContext::GetV8Context() {
return Local<Context>::New(node_isolate, context_);
return PersistentToLocal(node_isolate, context_);
}


Expand Down Expand Up @@ -404,7 +404,7 @@ void WrappedScript::EvalMachine(const FunctionCallbackInfo<Value>& args) {
"'this' must be a result of previous new Script(code) call.");
}

script = Local<Script>::New(node_isolate, n_script->script_);
script = PersistentToLocal(node_isolate, n_script->script_);
}

if (output_flag == returnResult) {
Expand Down
3 changes: 2 additions & 1 deletion src/req_wrap.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#ifndef SRC_REQ_WRAP_H_
#define SRC_REQ_WRAP_H_

#include "node.h"
#include "queue.h"

namespace node {
Expand Down Expand Up @@ -69,7 +70,7 @@ class ReqWrap {
}

inline v8::Local<v8::Object> object() {
return v8::Local<v8::Object>::New(node_isolate, persistent());
return PersistentToLocal(node_isolate, persistent());
}

inline v8::Persistent<v8::Object>& persistent() {
Expand Down
7 changes: 4 additions & 3 deletions src/tls_wrap.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,10 @@
#ifndef SRC_TLS_WRAP_H_
#define SRC_TLS_WRAP_H_

#include "v8.h"
#include "stream_wrap.h"
#include "node.h"
#include "queue.h"
#include "stream_wrap.h"
#include "v8.h"

#include <openssl/ssl.h>

Expand Down Expand Up @@ -162,7 +163,7 @@ class TLSCallbacks : public StreamWrapCallbacks {
#endif // SSL_CTRL_SET_TLSEXT_SERVERNAME_CB

inline v8::Local<v8::Object> object() {
return v8::Local<v8::Object>::New(node_isolate, persistent());
return PersistentToLocal(node_isolate, persistent());
}

inline v8::Persistent<v8::Object>& persistent() {
Expand Down

0 comments on commit d4cc30f

Please sign in to comment.