From 1967e1c4c08096210003b523945f8ba905ce0423 Mon Sep 17 00:00:00 2001 From: Darshan Sen Date: Sat, 2 Oct 2021 19:21:40 +0530 Subject: [PATCH] src: use `As()` instead of `Cast()` for conversions We mostly use `As()` instead of `Cast()` in our code, so this change replaces the remaining calls to `Cast()` with calls to `As()` to maintain the consistency. Refs: https://github.com/nodejs/node/pull/39921/files#r702293529 Signed-off-by: Darshan Sen --- src/cares_wrap.cc | 5 ++--- src/js_native_api_v8.cc | 7 +++---- src/module_wrap.cc | 4 ++-- src/node_contextify.h | 4 ++-- src/node_dtrace.cc | 16 ++++++++-------- src/process_wrap.cc | 4 ++-- 6 files changed, 19 insertions(+), 21 deletions(-) diff --git a/src/cares_wrap.cc b/src/cares_wrap.cc index edc86761876224..30e27ecf70a837 100644 --- a/src/cares_wrap.cc +++ b/src/cares_wrap.cc @@ -1701,7 +1701,7 @@ void SetServers(const FunctionCallbackInfo& args) { CHECK(args[0]->IsArray()); - Local arr = Local::Cast(args[0]); + Local arr = args[0].As(); uint32_t len = arr->Length(); @@ -1718,8 +1718,7 @@ void SetServers(const FunctionCallbackInfo& args) { for (uint32_t i = 0; i < len; i++) { CHECK(arr->Get(env->context(), i).ToLocalChecked()->IsArray()); - Local elm = - Local::Cast(arr->Get(env->context(), i).ToLocalChecked()); + Local elm = arr->Get(env->context(), i).ToLocalChecked().As(); CHECK(elm->Get(env->context(), 0).ToLocalChecked()->Int32Value(env->context()).FromJust()); diff --git a/src/js_native_api_v8.cc b/src/js_native_api_v8.cc index 754d71f51d6ac6..26ec837ffdcb43 100644 --- a/src/js_native_api_v8.cc +++ b/src/js_native_api_v8.cc @@ -175,7 +175,7 @@ inline static napi_status ConcludeDeferred(napi_env env, v8::Local v8_deferred = v8::Local::New(env->isolate, *deferred_ref); - auto v8_resolver = v8::Local::Cast(v8_deferred); + auto v8_resolver = v8_deferred.As(); v8::Maybe success = is_resolved ? v8_resolver->Resolve(context, v8impl::V8LocalValueFromJsValue(result)) : @@ -293,7 +293,7 @@ class CallbackWrapperBase : public CallbackWrapper { nullptr), _cbinfo(cbinfo) { _bundle = reinterpret_cast( - v8::Local::Cast(cbinfo.Data())->Value()); + cbinfo.Data().As()->Value()); _data = _bundle->cb_data; } @@ -3131,8 +3131,7 @@ napi_status napi_run_script(napi_env env, v8::Local context = env->context(); - auto maybe_script = v8::Script::Compile(context, - v8::Local::Cast(v8_script)); + auto maybe_script = v8::Script::Compile(context, v8_script.As()); CHECK_MAYBE_EMPTY(env, maybe_script, napi_generic_failure); auto script_result = diff --git a/src/module_wrap.cc b/src/module_wrap.cc index f45ee7627b0a9b..6a564b4257ebd2 100644 --- a/src/module_wrap.cc +++ b/src/module_wrap.cc @@ -292,8 +292,8 @@ void ModuleWrap::Link(const FunctionCallbackInfo& args) { for (int i = 0; i < raw_assertions->Length(); i += 3) { assertions ->Set(env->context(), - Local::Cast(raw_assertions->Get(env->context(), i)), - Local::Cast(raw_assertions->Get(env->context(), i + 1))) + raw_assertions->Get(env->context(), i).As(), + raw_assertions->Get(env->context(), i + 1).As()) .ToChecked(); } diff --git a/src/node_contextify.h b/src/node_contextify.h index 08ee97df777a90..c9ba78b8a5e185 100644 --- a/src/node_contextify.h +++ b/src/node_contextify.h @@ -74,8 +74,8 @@ class ContextifyContext { } inline v8::Local sandbox() const { - return v8::Local::Cast( - context()->GetEmbedderData(ContextEmbedderIndex::kSandboxObject)); + return context()->GetEmbedderData(ContextEmbedderIndex::kSandboxObject) + .As(); } inline std::shared_ptr microtask_queue() const { diff --git a/src/node_dtrace.cc b/src/node_dtrace.cc index 7808a649a4a088..52e63992833c38 100644 --- a/src/node_dtrace.cc +++ b/src/node_dtrace.cc @@ -87,8 +87,8 @@ using v8::Value; return node::THROW_ERR_INVALID_ARG_TYPE(env, \ "expected object for " #obj " to contain object member " #member); \ } \ - *valp = Local::Cast(obj->Get(env->context(), \ - OneByteString(env->isolate(), #member)).ToLocalChecked()); + *valp = obj->Get(env->context(), \ + OneByteString(env->isolate(), #member)).ToLocalChecked().As(); #define SLURP_CONNECTION(arg, conn) \ if (!(arg)->IsObject()) { \ @@ -96,7 +96,7 @@ using v8::Value; "expected argument " #arg " to be a connection object"); \ } \ node_dtrace_connection_t conn; \ - Local _##conn = Local::Cast(arg); \ + Local _##conn = arg.As(); \ Local _handle = \ (_##conn)->Get(env->context(), \ FIXED_ONE_BYTE_STRING(env->isolate(), "_handle")) \ @@ -116,7 +116,7 @@ using v8::Value; "expected argument " #arg " to be a connection object"); \ } \ node_dtrace_connection_t conn; \ - Local _##conn = Local::Cast(arg); \ + Local _##conn = arg.As(); \ SLURP_INT(_##conn, fd, &conn.fd); \ SLURP_STRING(_##conn, host, &conn.remote); \ SLURP_INT(_##conn, port, &conn.port); \ @@ -132,10 +132,10 @@ using v8::Value; "expected argument " #arg1 " to be a connection object"); \ } \ node_dtrace_connection_t conn; \ - Local _##conn = Local::Cast(arg0); \ + Local _##conn = arg0.As(); \ SLURP_INT(_##conn, fd, &conn.fd); \ SLURP_INT(_##conn, bufferSize, &conn.buffered); \ - _##conn = Local::Cast(arg1); \ + _##conn = arg1.As(); \ SLURP_STRING(_##conn, host, &conn.remote); \ SLURP_INT(_##conn, port, &conn.port); @@ -165,7 +165,7 @@ void DTRACE_HTTP_SERVER_REQUEST(const FunctionCallbackInfo& args) { Environment* env = Environment::GetCurrent(args); HandleScope scope(env->isolate()); - Local arg0 = Local::Cast(args[0]); + Local arg0 = args[0].As(); Local headers; memset(&req, 0, sizeof(req)); @@ -217,7 +217,7 @@ void DTRACE_HTTP_CLIENT_REQUEST(const FunctionCallbackInfo& args) { * caller here to retain their method and URL until the time at which * DTRACE_HTTP_CLIENT_REQUEST can be called. */ - Local arg0 = Local::Cast(args[0]); + Local arg0 = args[0].As(); SLURP_STRING(arg0, _header, &header); req.method = header; diff --git a/src/process_wrap.cc b/src/process_wrap.cc index 679429286b8907..6905cacb1c8193 100644 --- a/src/process_wrap.cc +++ b/src/process_wrap.cc @@ -186,7 +186,7 @@ class ProcessWrap : public HandleWrap { Local argv_v = js_options->Get(context, env->args_string()).ToLocalChecked(); if (!argv_v.IsEmpty() && argv_v->IsArray()) { - Local js_argv = Local::Cast(argv_v); + Local js_argv = argv_v.As(); int argc = js_argv->Length(); CHECK_GT(argc + 1, 0); // Check for overflow. @@ -214,7 +214,7 @@ class ProcessWrap : public HandleWrap { Local env_v = js_options->Get(context, env->env_pairs_string()).ToLocalChecked(); if (!env_v.IsEmpty() && env_v->IsArray()) { - Local env_opt = Local::Cast(env_v); + Local env_opt = env_v.As(); int envc = env_opt->Length(); CHECK_GT(envc + 1, 0); // Check for overflow. options.env = new char*[envc + 1]; // Heap allocated to detect errors.