Skip to content

Commit d4cc30f

Browse files
committed
src: use PersistentToLocal() in a few more places
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.
1 parent e5791f7 commit d4cc30f

5 files changed

Lines changed: 12 additions & 7 deletions

File tree

src/handle_wrap.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ class HandleWrap {
6969
virtual ~HandleWrap();
7070

7171
inline v8::Local<v8::Object> object() {
72-
return v8::Local<v8::Object>::New(node_isolate, persistent());
72+
return PersistentToLocal(node_isolate, persistent());
7373
}
7474

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

src/node_crypto.cc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3315,6 +3315,9 @@ void EIO_PBKDF2After(uv_work_t* work_req, int status) {
33153315
assert(status == 0);
33163316
pbkdf2_req* req = container_of(work_req, pbkdf2_req, work_req);
33173317
HandleScope scope(node_isolate);
3318+
// Create a new Local that's associated with the current HandleScope.
3319+
// PersistentToLocal() returns a handle that gets zeroed when we call
3320+
// Dispose() so don't use that.
33183321
Local<Object> obj = Local<Object>::New(node_isolate, req->obj);
33193322
req->obj.Dispose();
33203323
Local<Value> argv[2];

src/node_script.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ Local<Object> WrappedContext::NewInstance() {
174174

175175

176176
Local<Context> WrappedContext::GetV8Context() {
177-
return Local<Context>::New(node_isolate, context_);
177+
return PersistentToLocal(node_isolate, context_);
178178
}
179179

180180

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

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

410410
if (output_flag == returnResult) {

src/req_wrap.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#ifndef SRC_REQ_WRAP_H_
2323
#define SRC_REQ_WRAP_H_
2424

25+
#include "node.h"
2526
#include "queue.h"
2627

2728
namespace node {
@@ -69,7 +70,7 @@ class ReqWrap {
6970
}
7071

7172
inline v8::Local<v8::Object> object() {
72-
return v8::Local<v8::Object>::New(node_isolate, persistent());
73+
return PersistentToLocal(node_isolate, persistent());
7374
}
7475

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

src/tls_wrap.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,10 @@
2222
#ifndef SRC_TLS_WRAP_H_
2323
#define SRC_TLS_WRAP_H_
2424

25-
#include "v8.h"
26-
#include "stream_wrap.h"
25+
#include "node.h"
2726
#include "queue.h"
27+
#include "stream_wrap.h"
28+
#include "v8.h"
2829

2930
#include <openssl/ssl.h>
3031

@@ -162,7 +163,7 @@ class TLSCallbacks : public StreamWrapCallbacks {
162163
#endif // SSL_CTRL_SET_TLSEXT_SERVERNAME_CB
163164

164165
inline v8::Local<v8::Object> object() {
165-
return v8::Local<v8::Object>::New(node_isolate, persistent());
166+
return PersistentToLocal(node_isolate, persistent());
166167
}
167168

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

0 commit comments

Comments
 (0)