src: fix v8 compiler warnings in src

This commit changes the code to use the maybe version.

PR-URL: https://github.com/nodejs/node/pull/24246
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Refael Ackermann <refack@gmail.com>
This commit is contained in:
Daniel Bevenius 2018-11-08 07:22:13 +01:00
parent 19e5e78e9c
commit 344d33eef1
34 changed files with 414 additions and 213 deletions

View File

@ -1851,7 +1851,7 @@ void AfterGetAddrInfo(uv_getaddrinfo_t* req, int status, struct addrinfo* res) {
continue;
Local<String> s = OneByteString(env->isolate(), ip);
results->Set(n, s);
results->Set(env->context(), n, s).FromJust();
n++;
}
};
@ -2053,10 +2053,12 @@ void GetServers(const FunctionCallbackInfo<Value>& args) {
CHECK_EQ(err, 0);
Local<Array> ret = Array::New(env->isolate(), 2);
ret->Set(0, OneByteString(env->isolate(), ip));
ret->Set(1, Integer::New(env->isolate(), cur->udp_port));
ret->Set(env->context(), 0, OneByteString(env->isolate(), ip)).FromJust();
ret->Set(env->context(),
1,
Integer::New(env->isolate(), cur->udp_port)).FromJust();
server_array->Set(i, ret);
server_array->Set(env->context(), i, ret).FromJust();
}
ares_free_data(servers);
@ -2179,16 +2181,19 @@ void Initialize(Local<Object> target,
env->SetMethod(target, "strerror", StrError);
target->Set(FIXED_ONE_BYTE_STRING(env->isolate(), "AF_INET"),
Integer::New(env->isolate(), AF_INET));
target->Set(FIXED_ONE_BYTE_STRING(env->isolate(), "AF_INET6"),
Integer::New(env->isolate(), AF_INET6));
target->Set(FIXED_ONE_BYTE_STRING(env->isolate(), "AF_UNSPEC"),
Integer::New(env->isolate(), AF_UNSPEC));
target->Set(FIXED_ONE_BYTE_STRING(env->isolate(), "AI_ADDRCONFIG"),
Integer::New(env->isolate(), AI_ADDRCONFIG));
target->Set(FIXED_ONE_BYTE_STRING(env->isolate(), "AI_V4MAPPED"),
Integer::New(env->isolate(), AI_V4MAPPED));
target->Set(env->context(), FIXED_ONE_BYTE_STRING(env->isolate(), "AF_INET"),
Integer::New(env->isolate(), AF_INET)).FromJust();
target->Set(env->context(), FIXED_ONE_BYTE_STRING(env->isolate(), "AF_INET6"),
Integer::New(env->isolate(), AF_INET6)).FromJust();
target->Set(env->context(), FIXED_ONE_BYTE_STRING(env->isolate(),
"AF_UNSPEC"),
Integer::New(env->isolate(), AF_UNSPEC)).FromJust();
target->Set(env->context(), FIXED_ONE_BYTE_STRING(env->isolate(),
"AI_ADDRCONFIG"),
Integer::New(env->isolate(), AI_ADDRCONFIG)).FromJust();
target->Set(env->context(), FIXED_ONE_BYTE_STRING(env->isolate(),
"AI_V4MAPPED"),
Integer::New(env->isolate(), AI_V4MAPPED)).FromJust();
Local<FunctionTemplate> aiw =
BaseObject::MakeLazilyInitializedJSTemplate(env);
@ -2196,7 +2201,9 @@ void Initialize(Local<Object> target,
Local<String> addrInfoWrapString =
FIXED_ONE_BYTE_STRING(env->isolate(), "GetAddrInfoReqWrap");
aiw->SetClassName(addrInfoWrapString);
target->Set(addrInfoWrapString, aiw->GetFunction(context).ToLocalChecked());
target->Set(env->context(),
addrInfoWrapString,
aiw->GetFunction(context).ToLocalChecked()).FromJust();
Local<FunctionTemplate> niw =
BaseObject::MakeLazilyInitializedJSTemplate(env);
@ -2204,7 +2211,9 @@ void Initialize(Local<Object> target,
Local<String> nameInfoWrapString =
FIXED_ONE_BYTE_STRING(env->isolate(), "GetNameInfoReqWrap");
niw->SetClassName(nameInfoWrapString);
target->Set(nameInfoWrapString, niw->GetFunction(context).ToLocalChecked());
target->Set(env->context(),
nameInfoWrapString,
niw->GetFunction(context).ToLocalChecked()).FromJust();
Local<FunctionTemplate> qrw =
BaseObject::MakeLazilyInitializedJSTemplate(env);
@ -2212,7 +2221,9 @@ void Initialize(Local<Object> target,
Local<String> queryWrapString =
FIXED_ONE_BYTE_STRING(env->isolate(), "QueryReqWrap");
qrw->SetClassName(queryWrapString);
target->Set(queryWrapString, qrw->GetFunction(context).ToLocalChecked());
target->Set(env->context(),
queryWrapString,
qrw->GetFunction(context).ToLocalChecked()).FromJust();
Local<FunctionTemplate> channel_wrap =
env->NewFunctionTemplate(ChannelWrap::New);
@ -2239,8 +2250,8 @@ void Initialize(Local<Object> target,
Local<String> channelWrapString =
FIXED_ONE_BYTE_STRING(env->isolate(), "ChannelWrap");
channel_wrap->SetClassName(channelWrapString);
target->Set(channelWrapString,
channel_wrap->GetFunction(context).ToLocalChecked());
target->Set(env->context(), channelWrapString,
channel_wrap->GetFunction(context).ToLocalChecked()).FromJust();
}
} // anonymous namespace

View File

@ -755,7 +755,9 @@ void CollectExceptionInfo(Environment* env,
const char* message,
const char* path,
const char* dest) {
obj->Set(env->errno_string(), v8::Integer::New(env->isolate(), errorno));
obj->Set(env->context(),
env->errno_string(),
v8::Integer::New(env->isolate(), errorno)).FromJust();
obj->Set(env->context(), env->code_string(),
OneByteString(env->isolate(), err_string)).FromJust();

View File

@ -51,15 +51,19 @@ Local<Value> ErrnoException(Isolate* isolate,
e = Exception::Error(cons);
Local<Object> obj = e.As<Object>();
obj->Set(env->errno_string(), Integer::New(isolate, errorno));
obj->Set(env->code_string(), estring);
obj->Set(env->context(),
env->errno_string(),
Integer::New(isolate, errorno)).FromJust();
obj->Set(env->context(), env->code_string(), estring).FromJust();
if (path_string.IsEmpty() == false) {
obj->Set(env->path_string(), path_string);
obj->Set(env->context(), env->path_string(), path_string).FromJust();
}
if (syscall != nullptr) {
obj->Set(env->syscall_string(), OneByteString(isolate, syscall));
obj->Set(env->context(),
env->syscall_string(),
OneByteString(isolate, syscall)).FromJust();
}
return e;
@ -132,13 +136,15 @@ Local<Value> UVException(Isolate* isolate,
Exception::Error(js_msg)->ToObject(isolate->GetCurrentContext())
.ToLocalChecked();
e->Set(env->errno_string(), Integer::New(isolate, errorno));
e->Set(env->code_string(), js_code);
e->Set(env->syscall_string(), js_syscall);
e->Set(env->context(),
env->errno_string(),
Integer::New(isolate, errorno)).FromJust();
e->Set(env->context(), env->code_string(), js_code).FromJust();
e->Set(env->context(), env->syscall_string(), js_syscall).FromJust();
if (!js_path.IsEmpty())
e->Set(env->path_string(), js_path);
e->Set(env->context(), env->path_string(), js_path).FromJust();
if (!js_dest.IsEmpty())
e->Set(env->dest_string(), js_dest);
e->Set(env->context(), env->dest_string(), js_dest).FromJust();
return e;
}

View File

@ -119,7 +119,9 @@ void FSEventWrap::Initialize(Local<Object> target,
Local<FunctionTemplate>(),
static_cast<PropertyAttribute>(ReadOnly | DontDelete | v8::DontEnum));
target->Set(fsevent_string, t->GetFunction(context).ToLocalChecked());
target->Set(env->context(),
fsevent_string,
t->GetFunction(context).ToLocalChecked()).FromJust();
}

View File

@ -118,7 +118,7 @@ int JSStream::DoWrite(WriteWrap* w,
Local<Object> buf;
for (size_t i = 0; i < count; i++) {
buf = Buffer::Copy(env(), bufs[i].base, bufs[i].len).ToLocalChecked();
bufs_arr->Set(i, buf);
bufs_arr->Set(env()->context(), i, buf).FromJust();
}
Local<Value> argv[] = {
@ -210,7 +210,9 @@ void JSStream::Initialize(Local<Object> target,
env->SetProtoMethod(t, "emitEOF", EmitEOF);
StreamBase::AddMethods<JSStream>(env, t);
target->Set(jsStreamString, t->GetFunction(context).ToLocalChecked());
target->Set(env->context(),
jsStreamString,
t->GetFunction(context).ToLocalChecked()).FromJust();
}
} // namespace node

View File

@ -837,8 +837,8 @@ void ModuleWrap::Initialize(Local<Object> target,
env->SetProtoMethodNoSideEffect(tpl, "getStaticDependencySpecifiers",
GetStaticDependencySpecifiers);
target->Set(FIXED_ONE_BYTE_STRING(isolate, "ModuleWrap"),
tpl->GetFunction(context).ToLocalChecked());
target->Set(env->context(), FIXED_ONE_BYTE_STRING(isolate, "ModuleWrap"),
tpl->GetFunction(context).ToLocalChecked()).FromJust();
env->SetMethod(target, "resolve", Resolve);
env->SetMethod(target,
"setImportModuleDynamicallyCallback",

View File

@ -690,7 +690,8 @@ MaybeLocal<Value> MakeCallback(Isolate* isolate,
int argc,
Local<Value> argv[],
async_context asyncContext) {
Local<Value> callback_v = recv->Get(symbol);
Local<Value> callback_v = recv->Get(isolate->GetCurrentContext(),
symbol).ToLocalChecked();
if (callback_v.IsEmpty()) return Local<Value>();
if (!callback_v->IsFunction()) return Local<Value>();
Local<Function> callback = callback_v.As<Function>();
@ -1264,7 +1265,7 @@ static void GetLinkedBinding(const FunctionCallbackInfo<Value>& args) {
Local<Object> exports = Object::New(env->isolate());
Local<String> exports_prop = String::NewFromUtf8(env->isolate(), "exports",
NewStringType::kNormal).ToLocalChecked();
module->Set(exports_prop, exports);
module->Set(env->context(), exports_prop, exports).FromJust();
if (mod->nm_context_register_func != nullptr) {
mod->nm_context_register_func(exports,
@ -1277,7 +1278,8 @@ static void GetLinkedBinding(const FunctionCallbackInfo<Value>& args) {
return env->ThrowError("Linked module has no declared entry point.");
}
auto effective_exports = module->Get(exports_prop);
auto effective_exports = module->Get(env->context(),
exports_prop).ToLocalChecked();
args.GetReturnValue().Set(effective_exports);
}
@ -1292,10 +1294,16 @@ static Local<Object> GetFeatures(Environment* env) {
Local<Value> debug = False(env->isolate());
#endif // defined(DEBUG) && DEBUG
obj->Set(FIXED_ONE_BYTE_STRING(env->isolate(), "debug"), debug);
obj->Set(FIXED_ONE_BYTE_STRING(env->isolate(), "uv"), True(env->isolate()));
obj->Set(env->context(),
FIXED_ONE_BYTE_STRING(env->isolate(), "debug"),
debug).FromJust();
obj->Set(env->context(),
FIXED_ONE_BYTE_STRING(env->isolate(), "uv"),
True(env->isolate())).FromJust();
// TODO(bnoordhuis) ping libuv
obj->Set(FIXED_ONE_BYTE_STRING(env->isolate(), "ipv6"), True(env->isolate()));
obj->Set(env->context(),
FIXED_ONE_BYTE_STRING(env->isolate(), "ipv6"),
True(env->isolate())).FromJust();
#ifdef HAVE_OPENSSL
Local<Boolean> have_openssl = True(env->isolate());
@ -1303,10 +1311,18 @@ static Local<Object> GetFeatures(Environment* env) {
Local<Boolean> have_openssl = False(env->isolate());
#endif
obj->Set(FIXED_ONE_BYTE_STRING(env->isolate(), "tls_alpn"), have_openssl);
obj->Set(FIXED_ONE_BYTE_STRING(env->isolate(), "tls_sni"), have_openssl);
obj->Set(FIXED_ONE_BYTE_STRING(env->isolate(), "tls_ocsp"), have_openssl);
obj->Set(FIXED_ONE_BYTE_STRING(env->isolate(), "tls"), have_openssl);
obj->Set(env->context(),
FIXED_ONE_BYTE_STRING(env->isolate(), "tls_alpn"),
have_openssl).FromJust();
obj->Set(env->context(),
FIXED_ONE_BYTE_STRING(env->isolate(), "tls_sni"),
have_openssl).FromJust();
obj->Set(env->context(),
FIXED_ONE_BYTE_STRING(env->isolate(), "tls_ocsp"),
have_openssl).FromJust();
obj->Set(env->context(),
FIXED_ONE_BYTE_STRING(env->isolate(), "tls"),
have_openssl).FromJust();
return scope.Escape(obj);
}
@ -1468,7 +1484,9 @@ void SetupProcessObject(Environment* env,
NewStringType::kNormal).ToLocalChecked())
.FromJust();
}
process->Set(FIXED_ONE_BYTE_STRING(env->isolate(), "argv"), arguments);
process->Set(env->context(),
FIXED_ONE_BYTE_STRING(env->isolate(), "argv"),
arguments).FromJust();
// process.execArgv
Local<Array> exec_arguments = Array::New(env->isolate(), exec_args.size());
@ -1478,8 +1496,9 @@ void SetupProcessObject(Environment* env,
NewStringType::kNormal).ToLocalChecked())
.FromJust();
}
process->Set(FIXED_ONE_BYTE_STRING(env->isolate(), "execArgv"),
exec_arguments);
process->Set(env->context(),
FIXED_ONE_BYTE_STRING(env->isolate(), "execArgv"),
exec_arguments).FromJust();
// create process.env
Local<ObjectTemplate> process_env_template =
@ -1494,7 +1513,9 @@ void SetupProcessObject(Environment* env,
Local<Object> process_env =
process_env_template->NewInstance(env->context()).ToLocalChecked();
process->Set(FIXED_ONE_BYTE_STRING(env->isolate(), "env"), process_env);
process->Set(env->context(),
FIXED_ONE_BYTE_STRING(env->isolate(), "env"),
process_env).FromJust();
READONLY_PROPERTY(process, "pid",
Integer::New(env->isolate(), uv_os_getpid()));
@ -1539,7 +1560,7 @@ void SetupProcessObject(Environment* env,
preload_modules[i].c_str(),
NewStringType::kNormal)
.ToLocalChecked();
array->Set(i, module);
array->Set(env->context(), i, module).FromJust();
}
READONLY_PROPERTY(process,
"_preload_modules",
@ -1629,8 +1650,9 @@ void SetupProcessObject(Environment* env,
exec_path_value = String::NewFromUtf8(env->isolate(), args[0].c_str(),
NewStringType::kInternalized).ToLocalChecked();
}
process->Set(FIXED_ONE_BYTE_STRING(env->isolate(), "execPath"),
exec_path_value);
process->Set(env->context(),
FIXED_ONE_BYTE_STRING(env->isolate(), "execPath"),
exec_path_value).FromJust();
delete[] exec_path;
auto debug_port_string = FIXED_ONE_BYTE_STRING(env->isolate(), "debugPort");
@ -1783,7 +1805,9 @@ void LoadEnvironment(Environment* env) {
// Expose the global object as a property on itself
// (Allows you to set stuff on `global` from anywhere in JavaScript.)
global->Set(FIXED_ONE_BYTE_STRING(env->isolate(), "global"), global);
global->Set(env->context(),
FIXED_ONE_BYTE_STRING(env->isolate(), "global"),
global).FromJust();
// Create binding loaders
Local<Function> get_binding_fn =
@ -2344,8 +2368,9 @@ int EmitExit(Environment* env) {
HandleScope handle_scope(env->isolate());
Context::Scope context_scope(env->context());
Local<Object> process_object = env->process_object();
process_object->Set(FIXED_ONE_BYTE_STRING(env->isolate(), "_exiting"),
True(env->isolate()));
process_object->Set(env->context(),
FIXED_ONE_BYTE_STRING(env->isolate(), "_exiting"),
True(env->isolate())).FromJust();
Local<String> exit_code = env->exit_code_string();
int code = process_object->Get(env->context(), exit_code).ToLocalChecked()

View File

@ -1347,15 +1347,33 @@ void DefineConstants(v8::Isolate* isolate, Local<Object> target) {
// Define libuv constants.
NODE_DEFINE_CONSTANT(os_constants, UV_UDP_REUSEADDR);
os_constants->Set(OneByteString(isolate, "dlopen"), dlopen_constants);
os_constants->Set(OneByteString(isolate, "errno"), err_constants);
os_constants->Set(OneByteString(isolate, "signals"), sig_constants);
os_constants->Set(OneByteString(isolate, "priority"), priority_constants);
target->Set(OneByteString(isolate, "os"), os_constants);
target->Set(OneByteString(isolate, "fs"), fs_constants);
target->Set(OneByteString(isolate, "crypto"), crypto_constants);
target->Set(OneByteString(isolate, "zlib"), zlib_constants);
target->Set(OneByteString(isolate, "trace"), trace_constants);
os_constants->Set(env->context(),
OneByteString(isolate, "dlopen"),
dlopen_constants).FromJust();
os_constants->Set(env->context(),
OneByteString(isolate, "errno"),
err_constants).FromJust();
os_constants->Set(env->context(),
OneByteString(isolate, "signals"),
sig_constants).FromJust();
os_constants->Set(env->context(),
OneByteString(isolate, "priority"),
priority_constants).FromJust();
target->Set(env->context(),
OneByteString(isolate, "os"),
os_constants).FromJust();
target->Set(env->context(),
OneByteString(isolate, "fs"),
fs_constants).FromJust();
target->Set(env->context(),
OneByteString(isolate, "crypto"),
crypto_constants).FromJust();
target->Set(env->context(),
OneByteString(isolate, "zlib"),
zlib_constants).FromJust();
target->Set(env->context(),
OneByteString(isolate, "trace"),
trace_constants).FromJust();
}
} // namespace node

View File

@ -392,7 +392,7 @@ void ContextifyContext::PropertySetterCallback(
args.GetReturnValue().Set(false);
}
ctx->sandbox()->Set(property, value);
ctx->sandbox()->Set(ctx->context(), property, value).FromJust();
}
// static
@ -606,8 +606,8 @@ void ContextifyScript::Init(Environment* env, Local<Object> target) {
env->SetProtoMethod(script_tmpl, "runInContext", RunInContext);
env->SetProtoMethod(script_tmpl, "runInThisContext", RunInThisContext);
target->Set(class_name,
script_tmpl->GetFunction(env->context()).ToLocalChecked());
target->Set(env->context(), class_name,
script_tmpl->GetFunction(env->context()).ToLocalChecked()).FromJust();
env->set_script_context_constructor_template(script_tmpl);
}
@ -728,8 +728,9 @@ void ContextifyScript::New(const FunctionCallbackInfo<Value>& args) {
if (compile_options == ScriptCompiler::kConsumeCodeCache) {
args.This()->Set(
env->context(),
env->cached_data_rejected_string(),
Boolean::New(isolate, source.GetCachedData()->rejected));
Boolean::New(isolate, source.GetCachedData()->rejected)).FromJust();
} else if (produce_cached_data) {
const ScriptCompiler::CachedData* cached_data =
ScriptCompiler::CreateCodeCache(v8_script.ToLocalChecked());
@ -739,11 +740,14 @@ void ContextifyScript::New(const FunctionCallbackInfo<Value>& args) {
env,
reinterpret_cast<const char*>(cached_data->data),
cached_data->length);
args.This()->Set(env->cached_data_string(), buf.ToLocalChecked());
args.This()->Set(env->context(),
env->cached_data_string(),
buf.ToLocalChecked()).FromJust();
}
args.This()->Set(
env->context(),
env->cached_data_produced_string(),
Boolean::New(isolate, cached_data_produced));
Boolean::New(isolate, cached_data_produced)).FromJust();
}
TRACE_EVENT_NESTABLE_ASYNC_END0(
TRACING_CATEGORY_NODE2(vm, script),

View File

@ -379,8 +379,8 @@ void SecureContext::Initialize(Environment* env, Local<Object> target) {
Local<FunctionTemplate>(),
static_cast<PropertyAttribute>(ReadOnly | DontDelete));
target->Set(secureContextString,
t->GetFunction(env->context()).ToLocalChecked());
target->Set(env->context(), secureContextString,
t->GetFunction(env->context()).ToLocalChecked()).FromJust();
env->set_secure_context_constructor_template(t);
}
@ -1276,18 +1276,24 @@ int SecureContext::TicketKeyCallback(SSL* ssl,
Local<Array> arr = ret.As<Array>();
int r =
arr->Get(kTicketKeyReturnIndex)->Int32Value(env->context()).FromJust();
arr->Get(env->context(),
kTicketKeyReturnIndex).ToLocalChecked()
->Int32Value(env->context()).FromJust();
if (r < 0)
return r;
Local<Value> hmac = arr->Get(kTicketKeyHMACIndex);
Local<Value> aes = arr->Get(kTicketKeyAESIndex);
Local<Value> hmac = arr->Get(env->context(),
kTicketKeyHMACIndex).ToLocalChecked();
Local<Value> aes = arr->Get(env->context(),
kTicketKeyAESIndex).ToLocalChecked();
if (Buffer::Length(aes) != kTicketPartSize)
return -1;
if (enc) {
Local<Value> name_val = arr->Get(kTicketKeyNameIndex);
Local<Value> iv_val = arr->Get(kTicketKeyIVIndex);
Local<Value> name_val = arr->Get(env->context(),
kTicketKeyNameIndex).ToLocalChecked();
Local<Value> iv_val = arr->Get(env->context(),
kTicketKeyIVIndex).ToLocalChecked();
if (Buffer::Length(name_val) != kTicketPartSize ||
Buffer::Length(iv_val) != kTicketPartSize) {
@ -1667,7 +1673,7 @@ static Local<Object> X509ToObject(Environment* env, X509* cert) {
unsigned char* pubserialized =
reinterpret_cast<unsigned char*>(Buffer::Data(pubbuff));
i2d_RSA_PUBKEY(rsa.get(), &pubserialized);
info->Set(env->pubkey_string(), pubbuff);
info->Set(env->context(), env->pubkey_string(), pubbuff).FromJust();
}
pkey.reset();
@ -2422,7 +2428,8 @@ void SSLWrap<Base>::CertCbDone(const FunctionCallbackInfo<Value>& args) {
CHECK(w->is_waiting_cert_cb() && w->cert_cb_running_);
Local<Object> object = w->object();
Local<Value> ctx = object->Get(env->sni_context_string());
Local<Value> ctx = object->Get(env->context(),
env->sni_context_string()).ToLocalChecked();
Local<FunctionTemplate> cons = env->secure_context_constructor_template();
// Not an object, probably undefined or null
@ -2586,8 +2593,9 @@ void CipherBase::Initialize(Environment* env, Local<Object> target) {
env->SetProtoMethod(t, "setAuthTag", SetAuthTag);
env->SetProtoMethod(t, "setAAD", SetAAD);
target->Set(FIXED_ONE_BYTE_STRING(env->isolate(), "CipherBase"),
t->GetFunction(env->context()).ToLocalChecked());
target->Set(env->context(),
FIXED_ONE_BYTE_STRING(env->isolate(), "CipherBase"),
t->GetFunction(env->context()).ToLocalChecked()).FromJust();
}
@ -3191,8 +3199,9 @@ void Hmac::Initialize(Environment* env, v8::Local<Object> target) {
env->SetProtoMethod(t, "update", HmacUpdate);
env->SetProtoMethod(t, "digest", HmacDigest);
target->Set(FIXED_ONE_BYTE_STRING(env->isolate(), "Hmac"),
t->GetFunction(env->context()).ToLocalChecked());
target->Set(env->context(),
FIXED_ONE_BYTE_STRING(env->isolate(), "Hmac"),
t->GetFunction(env->context()).ToLocalChecked()).FromJust();
}
@ -3311,8 +3320,9 @@ void Hash::Initialize(Environment* env, v8::Local<Object> target) {
env->SetProtoMethod(t, "update", HashUpdate);
env->SetProtoMethod(t, "digest", HashDigest);
target->Set(FIXED_ONE_BYTE_STRING(env->isolate(), "Hash"),
t->GetFunction(env->context()).ToLocalChecked());
target->Set(env->context(),
FIXED_ONE_BYTE_STRING(env->isolate(), "Hash"),
t->GetFunction(env->context()).ToLocalChecked()).FromJust();
}
@ -3506,8 +3516,9 @@ void Sign::Initialize(Environment* env, v8::Local<Object> target) {
env->SetProtoMethod(t, "update", SignUpdate);
env->SetProtoMethod(t, "sign", SignFinal);
target->Set(FIXED_ONE_BYTE_STRING(env->isolate(), "Sign"),
t->GetFunction(env->context()).ToLocalChecked());
target->Set(env->context(),
FIXED_ONE_BYTE_STRING(env->isolate(), "Sign"),
t->GetFunction(env->context()).ToLocalChecked()).FromJust();
}
@ -3737,8 +3748,9 @@ void Verify::Initialize(Environment* env, v8::Local<Object> target) {
env->SetProtoMethod(t, "update", VerifyUpdate);
env->SetProtoMethod(t, "verify", VerifyFinal);
target->Set(FIXED_ONE_BYTE_STRING(env->isolate(), "Verify"),
t->GetFunction(env->context()).ToLocalChecked());
target->Set(env->context(),
FIXED_ONE_BYTE_STRING(env->isolate(), "Verify"),
t->GetFunction(env->context()).ToLocalChecked()).FromJust();
}
@ -3974,7 +3986,9 @@ void DiffieHellman::Initialize(Environment* env, Local<Object> target) {
Local<FunctionTemplate>(),
attributes);
target->Set(name, t->GetFunction(env->context()).ToLocalChecked());
target->Set(env->context(),
name,
t->GetFunction(env->context()).ToLocalChecked()).FromJust();
};
make(FIXED_ONE_BYTE_STRING(env->isolate(), "DiffieHellman"), New);
@ -4301,8 +4315,9 @@ void ECDH::Initialize(Environment* env, Local<Object> target) {
env->SetProtoMethod(t, "setPublicKey", SetPublicKey);
env->SetProtoMethod(t, "setPrivateKey", SetPrivateKey);
target->Set(FIXED_ONE_BYTE_STRING(env->isolate(), "ECDH"),
t->GetFunction(env->context()).ToLocalChecked());
target->Set(env->context(),
FIXED_ONE_BYTE_STRING(env->isolate(), "ECDH"),
t->GetFunction(env->context()).ToLocalChecked()).FromJust();
}
@ -5309,7 +5324,9 @@ static void array_push_back(const TypeName* md,
const char* to,
void* arg) {
CipherPushContext* ctx = static_cast<CipherPushContext*>(arg);
ctx->arr->Set(ctx->arr->Length(), OneByteString(ctx->env()->isolate(), from));
ctx->arr->Set(ctx->env()->context(),
ctx->arr->Length(),
OneByteString(ctx->env()->isolate(), from)).FromJust();
}

View File

@ -65,7 +65,8 @@ using v8::Value;
"expected object for " #obj " to contain string member " #member); \
} \
node::Utf8Value _##member(env->isolate(), \
obj->Get(OneByteString(env->isolate(), #member))); \
obj->Get(env->context(), \
OneByteString(env->isolate(), #member)).ToLocalChecked()); \
if ((*(const char **)valp = *_##member) == nullptr) \
*(const char **)valp = "<unknown>";
@ -75,7 +76,8 @@ using v8::Value;
env, \
"expected object for " #obj " to contain integer member " #member); \
} \
*valp = obj->Get(OneByteString(env->isolate(), #member)) \
*valp = obj->Get(env->context(), \
OneByteString(env->isolate(), #member)).ToLocalChecked() \
->Int32Value(env->context()) \
.FromJust();
@ -84,7 +86,8 @@ using v8::Value;
return node::THROW_ERR_INVALID_ARG_TYPE(env, \
"expected object for " #obj " to contain object member " #member); \
} \
*valp = Local<Object>::Cast(obj->Get(OneByteString(env->isolate(), #member)));
*valp = Local<Object>::Cast(obj->Get(env->context(), \
OneByteString(env->isolate(), #member)).ToLocalChecked());
#define SLURP_CONNECTION(arg, conn) \
if (!(arg)->IsObject()) { \
@ -94,7 +97,9 @@ using v8::Value;
node_dtrace_connection_t conn; \
Local<Object> _##conn = Local<Object>::Cast(arg); \
Local<Value> _handle = \
(_##conn)->Get(FIXED_ONE_BYTE_STRING(env->isolate(), "_handle")); \
(_##conn)->Get(env->context(), \
FIXED_ONE_BYTE_STRING(env->isolate(), "_handle")) \
.ToLocalChecked(); \
if (_handle->IsObject()) { \
SLURP_INT(_handle.As<Object>(), fd, &conn.fd); \
} else { \
@ -173,7 +178,8 @@ void DTRACE_HTTP_SERVER_REQUEST(const FunctionCallbackInfo<Value>& args) {
"expected object for request to contain string member headers");
}
Local<Value> strfwdfor = headers->Get(env->x_forwarded_string());
Local<Value> strfwdfor = headers->Get(
env->context(), env->x_forwarded_string()).ToLocalChecked();
node::Utf8Value fwdfor(env->isolate(), strfwdfor);
if (!strfwdfor->IsString() || (req.forwardedFor = *fwdfor) == nullptr)
@ -279,7 +285,7 @@ void InitDTrace(Environment* env, Local<Object> target) {
Local<Value> val = env->NewFunctionTemplate(tab[i].func)
->GetFunction(env->context())
.ToLocalChecked();
target->Set(key, val);
target->Set(env->context(), key, val).FromJust();
}
#ifdef HAVE_ETW

View File

@ -198,7 +198,8 @@ void ReportException(Environment* env,
} else {
Local<Object> err_obj = er->ToObject(env->context()).ToLocalChecked();
trace_value = err_obj->Get(env->stack_string());
trace_value = err_obj->Get(env->context(),
env->stack_string()).ToLocalChecked();
arrow =
err_obj->GetPrivate(env->context(), env->arrow_message_private_symbol())
.ToLocalChecked();
@ -223,8 +224,10 @@ void ReportException(Environment* env,
if (er->IsObject()) {
Local<Object> err_obj = er.As<Object>();
message = err_obj->Get(env->message_string());
name = err_obj->Get(FIXED_ONE_BYTE_STRING(env->isolate(), "name"));
message = err_obj->Get(env->context(),
env->message_string()).ToLocalChecked();
name = err_obj->Get(env->context(),
FIXED_ONE_BYTE_STRING(env->isolate(), "name")).ToLocalChecked();
}
if (message.IsEmpty() || message->IsUndefined() || name.IsEmpty() ||
@ -269,7 +272,8 @@ void DecorateErrorStack(Environment* env, const TryCatch& try_catch) {
if (IsExceptionDecorated(env, err_obj)) return;
AppendExceptionLine(env, exception, try_catch.Message(), CONTEXTIFY_ERROR);
Local<Value> stack = err_obj->Get(env->stack_string());
Local<Value> stack = err_obj->Get(env->context(),
env->stack_string()).ToLocalChecked();
MaybeLocal<Value> maybe_value =
err_obj->GetPrivate(env->context(), env->arrow_message_private_symbol());
@ -288,7 +292,7 @@ void DecorateErrorStack(Environment* env, const TryCatch& try_catch) {
arrow.As<String>(),
FIXED_ONE_BYTE_STRING(env->isolate(), "\n")),
stack.As<String>());
err_obj->Set(env->stack_string(), decorated_stack);
err_obj->Set(env->context(), env->stack_string(), decorated_stack).FromJust();
err_obj->SetPrivate(
env->context(), env->decorated_private_symbol(), True(env->isolate()));
}
@ -361,7 +365,8 @@ void FatalException(Isolate* isolate,
Local<Object> process_object = env->process_object();
Local<String> fatal_exception_string = env->fatal_exception_string();
Local<Value> fatal_exception_function =
process_object->Get(fatal_exception_string);
process_object->Get(env->context(),
fatal_exception_string).ToLocalChecked();
if (!fatal_exception_function->IsFunction()) {
// Failed before the process._fatalException function was added!

View File

@ -640,8 +640,14 @@ void AfterScanDirWithTypes(uv_fs_t* req) {
}
Local<Array> result = Array::New(isolate, 2);
result->Set(0, Array::New(isolate, name_v.data(), name_v.size()));
result->Set(1, Array::New(isolate, type_v.data(), type_v.size()));
result->Set(env->context(),
0,
Array::New(isolate, name_v.data(),
name_v.size())).FromJust();
result->Set(env->context(),
1,
Array::New(isolate, type_v.data(),
type_v.size())).FromJust();
req_wrap->Resolve(result);
}
@ -1482,8 +1488,11 @@ static void ReadDir(const FunctionCallbackInfo<Value>& args) {
Local<Array> names = Array::New(isolate, name_v.data(), name_v.size());
if (with_types) {
Local<Array> result = Array::New(isolate, 2);
result->Set(0, names);
result->Set(1, Array::New(isolate, type_v.data(), type_v.size()));
result->Set(env->context(), 0, names).FromJust();
result->Set(env->context(),
1,
Array::New(isolate, type_v.data(),
type_v.size())).FromJust();
args.GetReturnValue().Set(result);
} else {
args.GetReturnValue().Set(names);
@ -1667,7 +1676,7 @@ static void WriteBuffers(const FunctionCallbackInfo<Value>& args) {
MaybeStackBuffer<uv_buf_t> iovs(chunks->Length());
for (uint32_t i = 0; i < iovs.length(); i++) {
Local<Value> chunk = chunks->Get(i);
Local<Value> chunk = chunks->Get(env->context(), i).ToLocalChecked();
CHECK(Buffer::HasInstance(chunk));
iovs[i] = uv_buf_init(Buffer::Data(chunk), Buffer::Length(chunk));
}

View File

@ -3057,8 +3057,10 @@ void Initialize(Local<Object> target,
#define V(name) \
NODE_DEFINE_CONSTANT(constants, name); \
name_for_error_code->Set(static_cast<int>(name), \
FIXED_ONE_BYTE_STRING(isolate, #name));
name_for_error_code->Set(env->context(), \
static_cast<int>(name), \
FIXED_ONE_BYTE_STRING(isolate, \
#name)).FromJust();
NODE_NGHTTP2_ERROR_CODES(V)
#undef V

View File

@ -265,7 +265,8 @@ class Parser : public AsyncWrap, public StreamListener {
Local<Value> argv[A_MAX];
Local<Object> obj = object();
Local<Value> cb = obj->Get(kOnHeadersComplete);
Local<Value> cb = obj->Get(env()->context(),
kOnHeadersComplete).ToLocalChecked();
if (!cb->IsFunction())
return 0;
@ -338,7 +339,7 @@ class Parser : public AsyncWrap, public StreamListener {
EscapableHandleScope scope(env()->isolate());
Local<Object> obj = object();
Local<Value> cb = obj->Get(kOnBody);
Local<Value> cb = obj->Get(env()->context(), kOnBody).ToLocalChecked();
if (!cb->IsFunction())
return 0;
@ -381,7 +382,8 @@ class Parser : public AsyncWrap, public StreamListener {
Flush(); // Flush trailing HTTP headers.
Local<Object> obj = object();
Local<Value> cb = obj->Get(kOnMessageComplete);
Local<Value> cb = obj->Get(env()->context(),
kOnMessageComplete).ToLocalChecked();
if (!cb->IsFunction())
return 0;
@ -705,17 +707,23 @@ class Parser : public AsyncWrap, public StreamListener {
Local<Value> e = Exception::Error(env()->parse_error_string());
Local<Object> obj = e->ToObject(env()->isolate()->GetCurrentContext())
.ToLocalChecked();
obj->Set(env()->bytes_parsed_string(), nread_obj);
obj->Set(env()->context(),
env()->bytes_parsed_string(),
nread_obj).FromJust();
#ifdef NODE_EXPERIMENTAL_HTTP
obj->Set(env()->code_string(),
OneByteString(env()->isolate(), llhttp_errno_name(err)));
obj->Set(env()->reason_string(),
OneByteString(env()->isolate(), parser_.reason));
obj->Set(env()->context(),
env()->code_string(),
OneByteString(env()->isolate(),
llhttp_errno_name(err))).FromJust();
obj->Set(env()->context(),
env()->reason_string(),
OneByteString(env()->isolate(), parser_.reason)).FromJust();
#else /* !NODE_EXPERIMENTAL_HTTP */
obj->Set(env()->code_string(),
OneByteString(env()->isolate(), http_errno_name(err)));
obj->Set(env()->context(),
env()->code_string(),
OneByteString(env()->isolate(),
http_errno_name(err))).FromJust();
#endif /* NODE_EXPERIMENTAL_HTTP */
return scope.Escape(e);
}
@ -750,7 +758,7 @@ class Parser : public AsyncWrap, public StreamListener {
HandleScope scope(env()->isolate());
Local<Object> obj = object();
Local<Value> cb = obj->Get(kOnHeaders);
Local<Value> cb = obj->Get(env()->context(), kOnHeaders).ToLocalChecked();
if (!cb->IsFunction())
return;
@ -902,10 +910,13 @@ void Initialize(Local<Object> target,
Local<Array> methods = Array::New(env->isolate());
#define V(num, name, string) \
methods->Set(num, FIXED_ONE_BYTE_STRING(env->isolate(), #string));
methods->Set(env->context(), \
num, FIXED_ONE_BYTE_STRING(env->isolate(), #string)).FromJust();
HTTP_METHOD_MAP(V)
#undef V
target->Set(FIXED_ONE_BYTE_STRING(env->isolate(), "methods"), methods);
target->Set(env->context(),
FIXED_ONE_BYTE_STRING(env->isolate(), "methods"),
methods).FromJust();
t->Inherit(AsyncWrap::GetConstructorTemplate(env));
env->SetProtoMethod(t, "close", Parser::Close);
@ -919,8 +930,9 @@ void Initialize(Local<Object> target,
env->SetProtoMethod(t, "unconsume", Parser::Unconsume);
env->SetProtoMethod(t, "getCurrentBuffer", Parser::GetCurrentBuffer);
target->Set(FIXED_ONE_BYTE_STRING(env->isolate(), "HTTPParser"),
t->GetFunction(env->context()).ToLocalChecked());
target->Set(env->context(),
FIXED_ONE_BYTE_STRING(env->isolate(), "HTTPParser"),
t->GetFunction(env->context()).ToLocalChecked()).FromJust();
}
} // anonymous namespace

View File

@ -267,10 +267,11 @@ static void GetInterfaceAddresses(const FunctionCallbackInfo<Value>& args) {
v8::NewStringType::kNormal).ToLocalChecked();
if (ret->Has(env->context(), name).FromJust()) {
ifarr = Local<Array>::Cast(ret->Get(name));
ifarr = Local<Array>::Cast(ret->Get(env->context(),
name).ToLocalChecked());
} else {
ifarr = Array::New(env->isolate());
ret->Set(name, ifarr);
ret->Set(env->context(), name, ifarr).FromJust();
}
snprintf(mac,
@ -297,22 +298,29 @@ static void GetInterfaceAddresses(const FunctionCallbackInfo<Value>& args) {
}
o = Object::New(env->isolate());
o->Set(env->address_string(), OneByteString(env->isolate(), ip));
o->Set(env->netmask_string(), OneByteString(env->isolate(), netmask));
o->Set(env->family_string(), family);
o->Set(env->mac_string(), FIXED_ONE_BYTE_STRING(env->isolate(), mac));
o->Set(env->context(),
env->address_string(),
OneByteString(env->isolate(), ip)).FromJust();
o->Set(env->context(),
env->netmask_string(),
OneByteString(env->isolate(), netmask)).FromJust();
o->Set(env->context(),
env->family_string(), family).FromJust();
o->Set(env->context(),
env->mac_string(),
FIXED_ONE_BYTE_STRING(env->isolate(), mac)).FromJust();
if (interfaces[i].address.address4.sin_family == AF_INET6) {
uint32_t scopeid = interfaces[i].address.address6.sin6_scope_id;
o->Set(env->scopeid_string(),
Integer::NewFromUnsigned(env->isolate(), scopeid));
o->Set(env->context(), env->scopeid_string(),
Integer::NewFromUnsigned(env->isolate(), scopeid)).FromJust();
}
const bool internal = interfaces[i].is_internal;
o->Set(env->internal_string(),
internal ? True(env->isolate()) : False(env->isolate()));
o->Set(env->context(), env->internal_string(),
internal ? True(env->isolate()) : False(env->isolate())).FromJust();
ifarr->Set(ifarr->Length(), o);
ifarr->Set(env->context(), ifarr->Length(), o).FromJust();
}
uv_free_interface_addresses(interfaces, count);
@ -397,11 +405,17 @@ static void GetUserInfo(const FunctionCallbackInfo<Value>& args) {
Local<Object> entry = Object::New(env->isolate());
entry->Set(env->uid_string(), uid);
entry->Set(env->gid_string(), gid);
entry->Set(env->username_string(), username.ToLocalChecked());
entry->Set(env->homedir_string(), homedir.ToLocalChecked());
entry->Set(env->shell_string(), shell.ToLocalChecked());
entry->Set(env->context(), env->uid_string(), uid).FromJust();
entry->Set(env->context(), env->gid_string(), gid).FromJust();
entry->Set(env->context(),
env->username_string(),
username.ToLocalChecked()).FromJust();
entry->Set(env->context(),
env->homedir_string(),
homedir.ToLocalChecked()).FromJust();
entry->Set(env->context(),
env->shell_string(),
shell.ToLocalChecked()).FromJust();
args.GetReturnValue().Set(entry);
}
@ -464,8 +478,9 @@ void Initialize(Local<Object> target,
env->SetMethod(target, "getUserInfo", GetUserInfo);
env->SetMethod(target, "setPriority", SetPriority);
env->SetMethod(target, "getPriority", GetPriority);
target->Set(FIXED_ONE_BYTE_STRING(env->isolate(), "isBigEndian"),
Boolean::New(env->isolate(), IsBigEndian()));
target->Set(env->context(),
FIXED_ONE_BYTE_STRING(env->isolate(), "isBigEndian"),
Boolean::New(env->isolate(), IsBigEndian())).FromJust();
}
} // namespace os

View File

@ -488,7 +488,8 @@ void GetGroups(const FunctionCallbackInfo<Value>& args) {
gid_t egid = getegid();
for (int i = 0; i < ngroups; i++) {
groups_list->Set(i, Integer::New(env->isolate(), groups[i]));
groups_list->Set(env->context(),
i, Integer::New(env->isolate(), groups[i])).FromJust();
if (groups[i] == egid)
seen_egid = true;
}
@ -496,7 +497,9 @@ void GetGroups(const FunctionCallbackInfo<Value>& args) {
delete[] groups;
if (seen_egid == false)
groups_list->Set(ngroups, Integer::New(env->isolate(), egid));
groups_list->Set(env->context(),
ngroups,
Integer::New(env->isolate(), egid)).FromJust();
args.GetReturnValue().Set(groups_list);
}
@ -513,7 +516,9 @@ void SetGroups(const FunctionCallbackInfo<Value>& args) {
gid_t* groups = new gid_t[size];
for (size_t i = 0; i < size; i++) {
gid_t gid = gid_by_name(env->isolate(), groups_list->Get(i));
gid_t gid = gid_by_name(env->isolate(),
groups_list->Get(env->context(),
i).ToLocalChecked());
if (gid == gid_not_found) {
delete[] groups;

View File

@ -54,8 +54,8 @@ void StatWatcher::Initialize(Environment* env, Local<Object> target) {
env->SetProtoMethod(t, "start", StatWatcher::Start);
target->Set(statWatcherString,
t->GetFunction(env->context()).ToLocalChecked());
target->Set(env->context(), statWatcherString,
t->GetFunction(env->context()).ToLocalChecked()).FromJust();
}

View File

@ -110,8 +110,10 @@ void Initialize(Local<Object> target,
env->SetProtoMethod(category_set, "enable", NodeCategorySet::Enable);
env->SetProtoMethod(category_set, "disable", NodeCategorySet::Disable);
target->Set(FIXED_ONE_BYTE_STRING(env->isolate(), "CategorySet"),
category_set->GetFunction(env->context()).ToLocalChecked());
target->Set(env->context(),
FIXED_ONE_BYTE_STRING(env->isolate(), "CategorySet"),
category_set->GetFunction(env->context()).ToLocalChecked())
.FromJust();
Local<String> isTraceCategoryEnabled =
FIXED_ONE_BYTE_STRING(env->isolate(), "isTraceCategoryEnabled");

View File

@ -57,6 +57,7 @@ static void GetOwnNonIndexProperties(
}
static void GetPromiseDetails(const FunctionCallbackInfo<Value>& args) {
Environment* env = Environment::GetCurrent(args);
// Return undefined if it's not a Promise.
if (!args[0]->IsPromise())
return;
@ -67,14 +68,15 @@ static void GetPromiseDetails(const FunctionCallbackInfo<Value>& args) {
Local<Array> ret = Array::New(isolate, 2);
int state = promise->State();
ret->Set(0, Integer::New(isolate, state));
ret->Set(env->context(), 0, Integer::New(isolate, state)).FromJust();
if (state != Promise::PromiseState::kPending)
ret->Set(1, promise->Result());
ret->Set(env->context(), 1, promise->Result()).FromJust();
args.GetReturnValue().Set(ret);
}
static void GetProxyDetails(const FunctionCallbackInfo<Value>& args) {
Environment* env = Environment::GetCurrent(args);
// Return undefined if it's not a proxy.
if (!args[0]->IsProxy())
return;
@ -82,8 +84,8 @@ static void GetProxyDetails(const FunctionCallbackInfo<Value>& args) {
Local<Proxy> proxy = args[0].As<Proxy>();
Local<Array> ret = Array::New(args.GetIsolate(), 2);
ret->Set(0, proxy->GetTarget());
ret->Set(1, proxy->GetHandler());
ret->Set(env->context(), 0, proxy->GetTarget()).FromJust();
ret->Set(env->context(), 1, proxy->GetHandler()).FromJust();
args.GetReturnValue().Set(ret);
}

View File

@ -134,23 +134,27 @@ void Initialize(Local<Object> target,
const size_t heap_statistics_buffer_byte_length =
sizeof(*env->heap_statistics_buffer()) * kHeapStatisticsPropertiesCount;
target->Set(FIXED_ONE_BYTE_STRING(env->isolate(),
target->Set(env->context(),
FIXED_ONE_BYTE_STRING(env->isolate(),
"heapStatisticsArrayBuffer"),
ArrayBuffer::New(env->isolate(),
env->heap_statistics_buffer(),
heap_statistics_buffer_byte_length));
heap_statistics_buffer_byte_length)).FromJust();
#define V(i, _, name) \
target->Set(FIXED_ONE_BYTE_STRING(env->isolate(), #name), \
Uint32::NewFromUnsigned(env->isolate(), i));
target->Set(env->context(), \
FIXED_ONE_BYTE_STRING(env->isolate(), #name), \
Uint32::NewFromUnsigned(env->isolate(), i)).FromJust();
HEAP_STATISTICS_PROPERTIES(V)
#undef V
target->Set(FIXED_ONE_BYTE_STRING(env->isolate(),
target->Set(env->context(),
FIXED_ONE_BYTE_STRING(env->isolate(),
"kHeapSpaceStatisticsPropertiesCount"),
Uint32::NewFromUnsigned(env->isolate(),
kHeapSpaceStatisticsPropertiesCount));
kHeapSpaceStatisticsPropertiesCount))
.FromJust();
size_t number_of_heap_spaces = env->isolate()->NumberOfHeapSpaces();
@ -165,10 +169,11 @@ void Initialize(Local<Object> target,
s.space_name(),
NewStringType::kNormal)
.ToLocalChecked();
heap_spaces->Set(i, heap_space_name);
heap_spaces->Set(env->context(), i, heap_space_name).FromJust();
}
target->Set(FIXED_ONE_BYTE_STRING(env->isolate(), "kHeapSpaces"),
heap_spaces);
target->Set(env->context(),
FIXED_ONE_BYTE_STRING(env->isolate(), "kHeapSpaces"),
heap_spaces).FromJust();
env->SetMethod(target,
"updateHeapSpaceStatisticsArrayBuffer",
@ -182,15 +187,18 @@ void Initialize(Local<Object> target,
kHeapSpaceStatisticsPropertiesCount *
number_of_heap_spaces;
target->Set(FIXED_ONE_BYTE_STRING(env->isolate(),
target->Set(env->context(),
FIXED_ONE_BYTE_STRING(env->isolate(),
"heapSpaceStatisticsArrayBuffer"),
ArrayBuffer::New(env->isolate(),
env->heap_space_statistics_buffer(),
heap_space_statistics_buffer_byte_length));
heap_space_statistics_buffer_byte_length))
.FromJust();
#define V(i, _, name) \
target->Set(FIXED_ONE_BYTE_STRING(env->isolate(), #name), \
Uint32::NewFromUnsigned(env->isolate(), i));
target->Set(env->context(), \
FIXED_ONE_BYTE_STRING(env->isolate(), #name), \
Uint32::NewFromUnsigned(env->isolate(), i)).FromJust();
HEAP_SPACE_STATISTICS_PROPERTIES(V)
#undef V

View File

@ -490,7 +490,9 @@ void InitWorker(Local<Object> target,
Local<String> workerString =
FIXED_ONE_BYTE_STRING(env->isolate(), "Worker");
w->SetClassName(workerString);
target->Set(workerString, w->GetFunction(env->context()).ToLocalChecked());
target->Set(env->context(),
workerString,
w->GetFunction(env->context()).ToLocalChecked()).FromJust();
}
env->SetMethod(target, "getEnvMessagePort", GetEnvMessagePort);

View File

@ -896,10 +896,13 @@ void Initialize(Local<Object> target,
Local<String> zlibString = FIXED_ONE_BYTE_STRING(env->isolate(), "Zlib");
z->SetClassName(zlibString);
target->Set(zlibString, z->GetFunction(env->context()).ToLocalChecked());
target->Set(env->context(),
zlibString,
z->GetFunction(env->context()).ToLocalChecked()).FromJust();
target->Set(FIXED_ONE_BYTE_STRING(env->isolate(), "ZLIB_VERSION"),
FIXED_ONE_BYTE_STRING(env->isolate(), ZLIB_VERSION));
target->Set(env->context(),
FIXED_ONE_BYTE_STRING(env->isolate(), "ZLIB_VERSION"),
FIXED_ONE_BYTE_STRING(env->isolate(), ZLIB_VERSION)).FromJust();
}
} // anonymous namespace

View File

@ -90,7 +90,9 @@ void PipeWrap::Initialize(Local<Object> target,
env->SetProtoMethod(t, "fchmod", Fchmod);
target->Set(pipeString, t->GetFunction(env->context()).ToLocalChecked());
target->Set(env->context(),
pipeString,
t->GetFunction(env->context()).ToLocalChecked()).FromJust();
env->set_pipe_constructor_template(t);
// Create FunctionTemplate for PipeConnectWrap.
@ -99,7 +101,9 @@ void PipeWrap::Initialize(Local<Object> target,
Local<String> wrapString =
FIXED_ONE_BYTE_STRING(env->isolate(), "PipeConnectWrap");
cwt->SetClassName(wrapString);
target->Set(wrapString, cwt->GetFunction(env->context()).ToLocalChecked());
target->Set(env->context(),
wrapString,
cwt->GetFunction(env->context()).ToLocalChecked()).FromJust();
// Define constants
Local<Object> constants = Object::New(env->isolate());

View File

@ -62,8 +62,9 @@ class ProcessWrap : public HandleWrap {
env->SetProtoMethod(constructor, "spawn", Spawn);
env->SetProtoMethod(constructor, "kill", Kill);
target->Set(processString,
constructor->GetFunction(context).ToLocalChecked());
target->Set(env->context(),
processString,
constructor->GetFunction(context).ToLocalChecked()).FromJust();
}
SET_NO_MEMORY_INFO()

View File

@ -55,8 +55,9 @@ class SignalWrap : public HandleWrap {
env->SetProtoMethod(constructor, "start", Start);
env->SetProtoMethod(constructor, "stop", Stop);
target->Set(signalString,
constructor->GetFunction(env->context()).ToLocalChecked());
target->Set(env->context(), signalString,
constructor->GetFunction(env->context()).ToLocalChecked())
.FromJust();
}
SET_NO_MEMORY_INFO()

View File

@ -179,7 +179,9 @@ inline int StreamBase::Shutdown(v8::Local<v8::Object> req_wrap_obj) {
const char* msg = Error();
if (msg != nullptr) {
req_wrap_obj->Set(env->error_string(), OneByteString(env->isolate(), msg));
req_wrap_obj->Set(
env->context(),
env->error_string(), OneByteString(env->isolate(), msg)).FromJust();
ClearError();
}
@ -228,7 +230,9 @@ inline StreamWriteResult StreamBase::Write(
const char* msg = Error();
if (msg != nullptr) {
req_wrap_obj->Set(env->error_string(), OneByteString(env->isolate(), msg));
req_wrap_obj->Set(env->context(),
env->error_string(),
OneByteString(env->isolate(), msg)).FromJust();
ClearError();
}
@ -434,8 +438,10 @@ inline void StreamReq::Done(int status, const char* error_str) {
AsyncWrap* async_wrap = GetAsyncWrap();
Environment* env = async_wrap->env();
if (error_str != nullptr) {
async_wrap->object()->Set(env->error_string(),
OneByteString(env->isolate(), error_str));
async_wrap->object()->Set(env->context(),
env->error_string(),
OneByteString(env->isolate(), error_str))
.FromJust();
}
OnDone(status);

View File

@ -83,7 +83,7 @@ int StreamBase::Writev(const FunctionCallbackInfo<Value>& args) {
if (!all_buffers) {
// Determine storage size first
for (size_t i = 0; i < count; i++) {
Local<Value> chunk = chunks->Get(i * 2);
Local<Value> chunk = chunks->Get(env->context(), i * 2).ToLocalChecked();
if (Buffer::HasInstance(chunk))
continue;
@ -92,7 +92,7 @@ int StreamBase::Writev(const FunctionCallbackInfo<Value>& args) {
// String chunk
Local<String> string = chunk->ToString(env->context()).ToLocalChecked();
enum encoding encoding = ParseEncoding(env->isolate(),
chunks->Get(i * 2 + 1));
chunks->Get(env->context(), i * 2 + 1).ToLocalChecked());
size_t chunk_size;
if (encoding == UTF8 && string->Length() > 65535 &&
!StringBytes::Size(env->isolate(), string, encoding).To(&chunk_size))
@ -107,7 +107,7 @@ int StreamBase::Writev(const FunctionCallbackInfo<Value>& args) {
return UV_ENOBUFS;
} else {
for (size_t i = 0; i < count; i++) {
Local<Value> chunk = chunks->Get(i);
Local<Value> chunk = chunks->Get(env->context(), i).ToLocalChecked();
bufs[i].base = Buffer::Data(chunk);
bufs[i].len = Buffer::Length(chunk);
}
@ -120,7 +120,7 @@ int StreamBase::Writev(const FunctionCallbackInfo<Value>& args) {
offset = 0;
if (!all_buffers) {
for (size_t i = 0; i < count; i++) {
Local<Value> chunk = chunks->Get(i * 2);
Local<Value> chunk = chunks->Get(env->context(), i * 2).ToLocalChecked();
// Write buffer
if (Buffer::HasInstance(chunk)) {
@ -136,7 +136,7 @@ int StreamBase::Writev(const FunctionCallbackInfo<Value>& args) {
Local<String> string = chunk->ToString(env->context()).ToLocalChecked();
enum encoding encoding = ParseEncoding(env->isolate(),
chunks->Get(i * 2 + 1));
chunks->Get(env->context(), i * 2 + 1).ToLocalChecked());
str_size = StringBytes::Write(env->isolate(),
str_storage,
str_size,
@ -270,7 +270,9 @@ int StreamBase::WriteString(const FunctionCallbackInfo<Value>& args) {
send_handle = reinterpret_cast<uv_stream_t*>(wrap->GetHandle());
// Reference LibuvStreamWrap instance to prevent it from being garbage
// collected before `AfterWrite` is called.
req_wrap_obj->Set(env->handle_string(), send_handle_obj);
req_wrap_obj->Set(env->context(),
env->handle_string(),
send_handle_obj).FromJust();
}
StreamWriteResult res = Write(&buf, 1, send_handle, req_wrap_obj);

View File

@ -67,7 +67,9 @@ void LibuvStreamWrap::Initialize(Local<Object> target,
FIXED_ONE_BYTE_STRING(env->isolate(), "ShutdownWrap");
sw->SetClassName(wrapString);
sw->Inherit(AsyncWrap::GetConstructorTemplate(env));
target->Set(wrapString, sw->GetFunction(env->context()).ToLocalChecked());
target->Set(env->context(),
wrapString,
sw->GetFunction(env->context()).ToLocalChecked()).FromJust();
env->set_shutdown_wrap_template(sw->InstanceTemplate());
Local<FunctionTemplate> ww =
@ -77,8 +79,9 @@ void LibuvStreamWrap::Initialize(Local<Object> target,
FIXED_ONE_BYTE_STRING(env->isolate(), "WriteWrap");
ww->SetClassName(writeWrapString);
ww->Inherit(AsyncWrap::GetConstructorTemplate(env));
target->Set(writeWrapString,
ww->GetFunction(env->context()).ToLocalChecked());
target->Set(env->context(),
writeWrapString,
ww->GetFunction(env->context()).ToLocalChecked()).FromJust();
env->set_write_wrap_template(ww->InstanceTemplate());
NODE_DEFINE_CONSTANT(target, kReadBytesOrError);

View File

@ -107,7 +107,9 @@ void TCPWrap::Initialize(Local<Object> target,
env->SetProtoMethod(t, "setSimultaneousAccepts", SetSimultaneousAccepts);
#endif
target->Set(tcpString, t->GetFunction(env->context()).ToLocalChecked());
target->Set(env->context(),
tcpString,
t->GetFunction(env->context()).ToLocalChecked()).FromJust();
env->set_tcp_constructor_template(t);
// Create FunctionTemplate for TCPConnectWrap.
@ -117,7 +119,9 @@ void TCPWrap::Initialize(Local<Object> target,
Local<String> wrapString =
FIXED_ONE_BYTE_STRING(env->isolate(), "TCPConnectWrap");
cwt->SetClassName(wrapString);
target->Set(wrapString, cwt->GetFunction(env->context()).ToLocalChecked());
target->Set(env->context(),
wrapString,
cwt->GetFunction(env->context()).ToLocalChecked()).FromJust();
// Define constants
Local<Object> constants = Object::New(env->isolate());
@ -349,22 +353,36 @@ Local<Object> AddressToJS(Environment* env,
a6 = reinterpret_cast<const sockaddr_in6*>(addr);
uv_inet_ntop(AF_INET6, &a6->sin6_addr, ip, sizeof ip);
port = ntohs(a6->sin6_port);
info->Set(env->address_string(), OneByteString(env->isolate(), ip));
info->Set(env->family_string(), env->ipv6_string());
info->Set(env->port_string(), Integer::New(env->isolate(), port));
info->Set(env->context(),
env->address_string(),
OneByteString(env->isolate(), ip)).FromJust();
info->Set(env->context(),
env->family_string(),
env->ipv6_string()).FromJust();
info->Set(env->context(),
env->port_string(),
Integer::New(env->isolate(), port)).FromJust();
break;
case AF_INET:
a4 = reinterpret_cast<const sockaddr_in*>(addr);
uv_inet_ntop(AF_INET, &a4->sin_addr, ip, sizeof ip);
port = ntohs(a4->sin_port);
info->Set(env->address_string(), OneByteString(env->isolate(), ip));
info->Set(env->family_string(), env->ipv4_string());
info->Set(env->port_string(), Integer::New(env->isolate(), port));
info->Set(env->context(),
env->address_string(),
OneByteString(env->isolate(), ip)).FromJust();
info->Set(env->context(),
env->family_string(),
env->ipv4_string()).FromJust();
info->Set(env->context(),
env->port_string(),
Integer::New(env->isolate(), port)).FromJust();
break;
default:
info->Set(env->address_string(), String::Empty(env->isolate()));
info->Set(env->context(),
env->address_string(),
String::Empty(env->isolate())).FromJust();
}
return scope.Escape(info);

View File

@ -909,7 +909,9 @@ void TLSWrap::Initialize(Local<Object> target,
env->set_tls_wrap_constructor_function(
t->GetFunction(env->context()).ToLocalChecked());
target->Set(tlsWrapString, t->GetFunction(env->context()).ToLocalChecked());
target->Set(env->context(),
tlsWrapString,
t->GetFunction(env->context()).ToLocalChecked()).FromJust();
}
} // namespace node

View File

@ -59,7 +59,9 @@ void TTYWrap::Initialize(Local<Object> target,
env->SetMethodNoSideEffect(target, "isTTY", IsTTY);
env->SetMethodNoSideEffect(target, "guessHandleType", GuessHandleType);
target->Set(ttyString, t->GetFunction(env->context()).ToLocalChecked());
target->Set(env->context(),
ttyString,
t->GetFunction(env->context()).ToLocalChecked()).FromJust();
env->set_tty_constructor_template(t);
}
@ -112,8 +114,8 @@ void TTYWrap::GetWindowSize(const FunctionCallbackInfo<Value>& args) {
if (err == 0) {
Local<v8::Array> a = args[0].As<Array>();
a->Set(0, Integer::New(env->isolate(), width));
a->Set(1, Integer::New(env->isolate(), height));
a->Set(env->context(), 0, Integer::New(env->isolate(), width)).FromJust();
a->Set(env->context(), 1, Integer::New(env->isolate(), height)).FromJust();
}
args.GetReturnValue().Set(err);

View File

@ -133,7 +133,9 @@ void UDPWrap::Initialize(Local<Object> target,
t->Inherit(HandleWrap::GetConstructorTemplate(env));
target->Set(udpString, t->GetFunction(env->context()).ToLocalChecked());
target->Set(env->context(),
udpString,
t->GetFunction(env->context()).ToLocalChecked()).FromJust();
env->set_udp_constructor_function(
t->GetFunction(env->context()).ToLocalChecked());
@ -144,8 +146,9 @@ void UDPWrap::Initialize(Local<Object> target,
Local<String> sendWrapString =
FIXED_ONE_BYTE_STRING(env->isolate(), "SendWrap");
swt->SetClassName(sendWrapString);
target->Set(sendWrapString,
swt->GetFunction(env->context()).ToLocalChecked());
target->Set(env->context(),
sendWrapString,
swt->GetFunction(env->context()).ToLocalChecked()).FromJust();
}
@ -373,7 +376,7 @@ void UDPWrap::DoSend(const FunctionCallbackInfo<Value>& args, int family) {
// construct uv_buf_t array
for (size_t i = 0; i < count; i++) {
Local<Value> chunk = chunks->Get(i);
Local<Value> chunk = chunks->Get(env->context(), i).ToLocalChecked();
size_t length = Buffer::Length(chunk);

View File

@ -63,10 +63,11 @@ void Initialize(Local<Object> target,
Local<Context> context) {
Environment* env = Environment::GetCurrent(context);
Isolate* isolate = env->isolate();
target->Set(FIXED_ONE_BYTE_STRING(isolate, "errname"),
target->Set(env->context(),
FIXED_ONE_BYTE_STRING(isolate, "errname"),
env->NewFunctionTemplate(ErrName)
->GetFunction(env->context())
.ToLocalChecked());
.ToLocalChecked()).FromJust();
#define V(name, _) NODE_DEFINE_CONSTANT(target, UV_##name);
UV_ERRNO_MAP(V)
@ -76,8 +77,8 @@ void Initialize(Local<Object> target,
#define V(name, msg) do { \
Local<Array> arr = Array::New(isolate, 2); \
arr->Set(0, OneByteString(isolate, #name)); \
arr->Set(1, OneByteString(isolate, msg)); \
arr->Set(env->context(), 0, OneByteString(isolate, #name)).FromJust(); \
arr->Set(env->context(), 1, OneByteString(isolate, msg)).FromJust(); \
err_map->Set(context, \
Integer::New(isolate, UV_##name), \
arr).ToLocalChecked(); \