Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

src: replace some deprecated uses of Get() and Set() #24060

Merged
merged 4 commits into from
Nov 7, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/async_wrap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -347,8 +347,13 @@ void AsyncWrap::WeakCallback(const v8::WeakCallbackInfo<DestroyParam>& info) {

std::unique_ptr<DestroyParam> p{info.GetParameter()};
Local<Object> prop_bag = PersistentToLocal(info.GetIsolate(), p->propBag);
Local<Value> val;

if (!prop_bag->Get(p->env->context(), p->env->destroyed_string())
.ToLocal(&val)) {
return;
}

Local<Value> val = prop_bag->Get(p->env->destroyed_string());
if (val->IsFalse()) {
AsyncWrap::EmitDestroy(p->env, p->asyncId);
}
Expand Down
4 changes: 2 additions & 2 deletions src/env-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -736,7 +736,7 @@ inline void Environment::SetMethod(v8::Local<v8::Object> that,
const v8::NewStringType type = v8::NewStringType::kInternalized;
v8::Local<v8::String> name_string =
v8::String::NewFromUtf8(isolate(), name, type).ToLocalChecked();
that->Set(name_string, function);
that->Set(context, name_string, function).FromJust();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this return if it's empty? Also other FromJust below

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@joyeecheung I'm not sure that it matters in these two cases.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don’t think we can really signal an error here without making SetMethod() itself return a Maybe<>

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@addaleax hmm, yeah, the caller can handle that as well, but this is mostly used in Initialize anyways

function->SetName(name_string); // NODE_SET_METHOD() compatibility.
}

Expand All @@ -756,7 +756,7 @@ inline void Environment::SetMethodNoSideEffect(v8::Local<v8::Object> that,
const v8::NewStringType type = v8::NewStringType::kInternalized;
v8::Local<v8::String> name_string =
v8::String::NewFromUtf8(isolate(), name, type).ToLocalChecked();
that->Set(name_string, function);
that->Set(context, name_string, function).FromJust();
function->SetName(name_string); // NODE_SET_METHOD() compatibility.
}

Expand Down
2 changes: 1 addition & 1 deletion src/node.h
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@ inline void NODE_SET_METHOD(v8::Local<v8::Object> recv,
v8::Local<v8::String> fn_name = v8::String::NewFromUtf8(isolate, name,
v8::NewStringType::kInternalized).ToLocalChecked();
fn->SetName(fn_name);
recv->Set(fn_name, fn);
recv->Set(context, fn_name, fn).FromJust();
}
#define NODE_SET_METHOD node::NODE_SET_METHOD

Expand Down
18 changes: 13 additions & 5 deletions src/tls_wrap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -213,17 +213,22 @@ void TLSWrap::SSLInfoCallback(const SSL* ssl_, int where, int ret) {
Local<Object> object = c->object();

if (where & SSL_CB_HANDSHAKE_START) {
Local<Value> callback = object->Get(env->onhandshakestart_string());
if (callback->IsFunction()) {
Local<Value> callback;

if (object->Get(env->context(), env->onhandshakestart_string())
.ToLocal(&callback) && callback->IsFunction()) {
Local<Value> argv[] = { env->GetNow() };
c->MakeCallback(callback.As<Function>(), arraysize(argv), argv);
}
}

if (where & SSL_CB_HANDSHAKE_DONE) {
Local<Value> callback;

c->established_ = true;
Local<Value> callback = object->Get(env->onhandshakedone_string());
if (callback->IsFunction()) {

if (object->Get(env->context(), env->onhandshakedone_string())
.ToLocal(&callback) && callback->IsFunction()) {
c->MakeCallback(callback.As<Function>(), 0, nullptr);
}
}
Expand Down Expand Up @@ -814,7 +819,10 @@ int TLSWrap::SelectSNIContextCallback(SSL* s, int* ad, void* arg) {

// Call the SNI callback and use its return value as context
Local<Object> object = p->object();
Local<Value> ctx = object->Get(env->sni_context_string());
Local<Value> ctx;

if (!object->Get(env->context(), env->sni_context_string()).ToLocal(&ctx))
return SSL_TLSEXT_ERR_NOACK;

// Not an object, probably undefined or null
if (!ctx->IsObject())
Expand Down