Skip to content

Commit b4ccad9

Browse files
src: promote v8 name spaces with using
there are several places where v8 artifacts appear with scope resolution operator inline with the source. Elevate them for improved readability as well as to follow the convention.
1 parent c8880ea commit b4ccad9

File tree

1 file changed

+45
-35
lines changed

1 file changed

+45
-35
lines changed

src/node.cc

Lines changed: 45 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -132,11 +132,14 @@ using v8::Array;
132132
using v8::ArrayBuffer;
133133
using v8::Boolean;
134134
using v8::Context;
135+
using v8::DEFAULT;
136+
using v8::DontEnum;
135137
using v8::EscapableHandleScope;
136138
using v8::Exception;
137139
using v8::Function;
138140
using v8::FunctionCallbackInfo;
139141
using v8::HandleScope;
142+
using v8::Int32;
140143
using v8::Integer;
141144
using v8::Isolate;
142145
using v8::Just;
@@ -145,19 +148,27 @@ using v8::Locker;
145148
using v8::Maybe;
146149
using v8::MaybeLocal;
147150
using v8::Message;
151+
using v8::MicrotasksPolicy;
148152
using v8::Name;
149153
using v8::NamedPropertyHandlerConfiguration;
154+
using v8::NewStringType;
155+
using v8::None;
150156
using v8::Nothing;
151157
using v8::Null;
152158
using v8::Number;
153159
using v8::Object;
154160
using v8::ObjectTemplate;
155161
using v8::Promise;
162+
using v8::PropertyAttribute;
156163
using v8::PropertyCallbackInfo;
164+
using v8::ReadOnly;
165+
using v8::Script;
166+
using v8::ScriptCompiler;
157167
using v8::ScriptOrigin;
158168
using v8::SealHandleScope;
159169
using v8::SideEffectType;
160170
using v8::String;
171+
using v8::TracingController;
161172
using v8::TryCatch;
162173
using v8::Undefined;
163174
using v8::V8;
@@ -190,12 +201,12 @@ std::shared_ptr<PerProcessOptions> per_process_opts {
190201
new PerProcessOptions() };
191202

192203
static Mutex node_isolate_mutex;
193-
static v8::Isolate* node_isolate;
204+
static Isolate* node_isolate;
194205

195206
// Ensures that __metadata trace events are only emitted
196207
// when tracing is enabled.
197208
class NodeTraceStateObserver :
198-
public v8::TracingController::TraceStateObserver {
209+
public TracingController::TraceStateObserver {
199210
public:
200211
void OnTraceEnabled() override {
201212
char name_buffer[512];
@@ -278,12 +289,12 @@ class NodeTraceStateObserver :
278289
UNREACHABLE();
279290
}
280291

281-
explicit NodeTraceStateObserver(v8::TracingController* controller) :
292+
explicit NodeTraceStateObserver(TracingController* controller) :
282293
controller_(controller) {}
283294
~NodeTraceStateObserver() override {}
284295

285296
private:
286-
v8::TracingController* controller_;
297+
TracingController* controller_;
287298
};
288299

289300
static struct {
@@ -692,20 +703,20 @@ bool ShouldAbortOnUncaughtException(Isolate* isolate) {
692703
} // anonymous namespace
693704

694705

695-
void AddPromiseHook(v8::Isolate* isolate, promise_hook_func fn, void* arg) {
706+
void AddPromiseHook(Isolate* isolate, promise_hook_func fn, void* arg) {
696707
Environment* env = Environment::GetCurrent(isolate);
697708
env->AddPromiseHook(fn, arg);
698709
}
699710

700-
void AddEnvironmentCleanupHook(v8::Isolate* isolate,
711+
void AddEnvironmentCleanupHook(Isolate* isolate,
701712
void (*fun)(void* arg),
702713
void* arg) {
703714
Environment* env = Environment::GetCurrent(isolate);
704715
env->AddCleanupHook(fun, arg);
705716
}
706717

707718

708-
void RemoveEnvironmentCleanupHook(v8::Isolate* isolate,
719+
void RemoveEnvironmentCleanupHook(Isolate* isolate,
709720
void (*fun)(void* arg),
710721
void* arg) {
711722
Environment* env = Environment::GetCurrent(isolate);
@@ -759,7 +770,7 @@ MaybeLocal<Value> MakeCallback(Isolate* isolate,
759770
Local<Value> argv[],
760771
async_context asyncContext) {
761772
Local<String> method_string =
762-
String::NewFromUtf8(isolate, method, v8::NewStringType::kNormal)
773+
String::NewFromUtf8(isolate, method, NewStringType::kNormal)
763774
.ToLocalChecked();
764775
return MakeCallback(isolate, recv, method_string, argc, argv, asyncContext);
765776
}
@@ -945,7 +956,7 @@ void AppendExceptionLine(Environment* env,
945956
arrow[off + 1] = '\0';
946957

947958
Local<String> arrow_str = String::NewFromUtf8(env->isolate(), arrow,
948-
v8::NewStringType::kNormal).ToLocalChecked();
959+
NewStringType::kNormal).ToLocalChecked();
949960

950961
const bool can_set_arrow = !arrow_str.IsEmpty() && !err_obj.IsEmpty();
951962
// If allocating arrow_str failed, print it out. There's not much else to do.
@@ -1071,8 +1082,8 @@ static MaybeLocal<Value> ExecuteString(Environment* env,
10711082
try_catch.SetVerbose(false);
10721083

10731084
ScriptOrigin origin(filename);
1074-
MaybeLocal<v8::Script> script =
1075-
v8::Script::Compile(env->context(), source, &origin);
1085+
MaybeLocal<Script> script =
1086+
Script::Compile(env->context(), source, &origin);
10761087
if (script.IsEmpty()) {
10771088
ReportException(env, try_catch);
10781089
env->Exit(3);
@@ -1524,7 +1535,7 @@ void FatalException(Isolate* isolate,
15241535
!code->IsInt32()) {
15251536
exit(1);
15261537
}
1527-
exit(code.As<v8::Int32>()->Value());
1538+
exit(code.As<Int32>()->Value());
15281539
}
15291540
}
15301541
}
@@ -1573,20 +1584,20 @@ static Maybe<bool> ProcessEmitWarningGeneric(Environment* env,
15731584
// do proper error checking for string creation.
15741585
if (!String::NewFromUtf8(env->isolate(),
15751586
warning,
1576-
v8::NewStringType::kNormal).ToLocal(&args[argc++])) {
1587+
NewStringType::kNormal).ToLocal(&args[argc++])) {
15771588
return Nothing<bool>();
15781589
}
15791590
if (type != nullptr) {
15801591
if (!String::NewFromOneByte(env->isolate(),
15811592
reinterpret_cast<const uint8_t*>(type),
1582-
v8::NewStringType::kNormal)
1593+
NewStringType::kNormal)
15831594
.ToLocal(&args[argc++])) {
15841595
return Nothing<bool>();
15851596
}
15861597
if (code != nullptr &&
15871598
!String::NewFromOneByte(env->isolate(),
15881599
reinterpret_cast<const uint8_t*>(code),
1589-
v8::NewStringType::kNormal)
1600+
NewStringType::kNormal)
15901601
.ToLocal(&args[argc++])) {
15911602
return Nothing<bool>();
15921603
}
@@ -1731,7 +1742,7 @@ static void GetLinkedBinding(const FunctionCallbackInfo<Value>& args) {
17311742
Local<Object> module = Object::New(env->isolate());
17321743
Local<Object> exports = Object::New(env->isolate());
17331744
Local<String> exports_prop = String::NewFromUtf8(env->isolate(), "exports",
1734-
v8::NewStringType::kNormal).ToLocalChecked();
1745+
NewStringType::kNormal).ToLocalChecked();
17351746
module->Set(exports_prop, exports);
17361747

17371748
if (mod->nm_context_register_func != nullptr) {
@@ -1815,16 +1826,15 @@ namespace {
18151826
obj->DefineOwnProperty(env->context(), \
18161827
OneByteString(env->isolate(), str), \
18171828
var, \
1818-
v8::ReadOnly).FromJust(); \
1829+
ReadOnly).FromJust(); \
18191830
} while (0)
18201831

18211832
#define READONLY_DONT_ENUM_PROPERTY(obj, str, var) \
18221833
do { \
18231834
obj->DefineOwnProperty(env->context(), \
18241835
OneByteString(env->isolate(), str), \
18251836
var, \
1826-
static_cast<v8::PropertyAttribute>(v8::ReadOnly | \
1827-
v8::DontEnum)) \
1837+
static_cast<PropertyAttribute>(ReadOnly|DontEnum)) \
18281838
.FromJust(); \
18291839
} while (0)
18301840

@@ -1844,8 +1854,8 @@ void SetupProcessObject(Environment* env,
18441854
ProcessTitleGetter,
18451855
env->is_main_thread() ? ProcessTitleSetter : nullptr,
18461856
env->as_external(),
1847-
v8::DEFAULT,
1848-
v8::None,
1857+
DEFAULT,
1858+
None,
18491859
SideEffectType::kHasNoSideEffect).FromJust());
18501860

18511861
// process.version
@@ -1974,7 +1984,7 @@ void SetupProcessObject(Environment* env,
19741984
for (size_t i = 0; i < args.size(); ++i) {
19751985
arguments->Set(env->context(), i,
19761986
String::NewFromUtf8(env->isolate(), args[i].c_str(),
1977-
v8::NewStringType::kNormal).ToLocalChecked())
1987+
NewStringType::kNormal).ToLocalChecked())
19781988
.FromJust();
19791989
}
19801990
process->Set(FIXED_ONE_BYTE_STRING(env->isolate(), "argv"), arguments);
@@ -1984,7 +1994,7 @@ void SetupProcessObject(Environment* env,
19841994
for (size_t i = 0; i < exec_args.size(); ++i) {
19851995
exec_arguments->Set(env->context(), i,
19861996
String::NewFromUtf8(env->isolate(), exec_args[i].c_str(),
1987-
v8::NewStringType::kNormal).ToLocalChecked())
1997+
NewStringType::kNormal).ToLocalChecked())
19881998
.FromJust();
19891999
}
19902000
process->Set(FIXED_ONE_BYTE_STRING(env->isolate(), "execArgv"),
@@ -2020,7 +2030,7 @@ void SetupProcessObject(Environment* env,
20202030
String::NewFromUtf8(
20212031
env->isolate(),
20222032
env->options()->eval_string.c_str(),
2023-
v8::NewStringType::kNormal).ToLocalChecked());
2033+
NewStringType::kNormal).ToLocalChecked());
20242034
}
20252035

20262036
// -p, --print
@@ -2046,7 +2056,7 @@ void SetupProcessObject(Environment* env,
20462056
for (unsigned int i = 0; i < preload_modules.size(); ++i) {
20472057
Local<String> module = String::NewFromUtf8(env->isolate(),
20482058
preload_modules[i].c_str(),
2049-
v8::NewStringType::kNormal)
2059+
NewStringType::kNormal)
20502060
.ToLocalChecked();
20512061
array->Set(i, module);
20522062
}
@@ -2133,11 +2143,11 @@ void SetupProcessObject(Environment* env,
21332143
if (uv_exepath(exec_path, &exec_path_len) == 0) {
21342144
exec_path_value = String::NewFromUtf8(env->isolate(),
21352145
exec_path,
2136-
v8::NewStringType::kInternalized,
2146+
NewStringType::kInternalized,
21372147
exec_path_len).ToLocalChecked();
21382148
} else {
21392149
exec_path_value = String::NewFromUtf8(env->isolate(), args[0].c_str(),
2140-
v8::NewStringType::kInternalized).ToLocalChecked();
2150+
NewStringType::kInternalized).ToLocalChecked();
21412151
}
21422152
process->Set(FIXED_ONE_BYTE_STRING(env->isolate(), "execPath"),
21432153
exec_path_value);
@@ -2301,15 +2311,15 @@ void LoadEnvironment(Environment* env) {
23012311
global->Set(FIXED_ONE_BYTE_STRING(env->isolate(), "global"), global);
23022312

23032313
// Create binding loaders
2304-
v8::Local<v8::Function> get_binding_fn =
2314+
Local<Function> get_binding_fn =
23052315
env->NewFunctionTemplate(GetBinding)->GetFunction(env->context())
23062316
.ToLocalChecked();
23072317

2308-
v8::Local<v8::Function> get_linked_binding_fn =
2318+
Local<Function> get_linked_binding_fn =
23092319
env->NewFunctionTemplate(GetLinkedBinding)->GetFunction(env->context())
23102320
.ToLocalChecked();
23112321

2312-
v8::Local<v8::Function> get_internal_binding_fn =
2322+
Local<Function> get_internal_binding_fn =
23132323
env->NewFunctionTemplate(GetInternalBinding)->GetFunction(env->context())
23142324
.ToLocalChecked();
23152325

@@ -2841,7 +2851,7 @@ void RunAtExit(Environment* env) {
28412851
}
28422852

28432853

2844-
uv_loop_t* GetCurrentEventLoop(v8::Isolate* isolate) {
2854+
uv_loop_t* GetCurrentEventLoop(Isolate* isolate) {
28452855
HandleScope handle_scope(isolate);
28462856
auto context = isolate->GetCurrentContext();
28472857
if (context.IsEmpty())
@@ -2974,7 +2984,7 @@ MultiIsolatePlatform* GetMainThreadMultiIsolatePlatform() {
29742984

29752985
MultiIsolatePlatform* CreatePlatform(
29762986
int thread_pool_size,
2977-
v8::TracingController* tracing_controller) {
2987+
TracingController* tracing_controller) {
29782988
return new NodePlatform(thread_pool_size, tracing_controller);
29792989
}
29802990

@@ -2997,8 +3007,8 @@ Local<Context> NewContext(Isolate* isolate,
29973007
// Run lib/internal/per_context.js
29983008
Context::Scope context_scope(context);
29993009
Local<String> per_context = NodePerContextSource(isolate);
3000-
v8::ScriptCompiler::Source per_context_src(per_context, nullptr);
3001-
Local<v8::Script> s = v8::ScriptCompiler::Compile(
3010+
ScriptCompiler::Source per_context_src(per_context, nullptr);
3011+
Local<Script> s = ScriptCompiler::Compile(
30023012
context,
30033013
&per_context_src).ToLocalChecked();
30043014
s->Run(context).ToLocalChecked();
@@ -3107,7 +3117,7 @@ Isolate* NewIsolate(ArrayBufferAllocator* allocator) {
31073117

31083118
isolate->AddMessageListener(OnMessage);
31093119
isolate->SetAbortOnUncaughtExceptionCallback(ShouldAbortOnUncaughtException);
3110-
isolate->SetMicrotasksPolicy(v8::MicrotasksPolicy::kExplicit);
3120+
isolate->SetMicrotasksPolicy(MicrotasksPolicy::kExplicit);
31113121
isolate->SetFatalErrorHandler(OnFatalError);
31123122
isolate->SetAllowWasmCodeGenerationCallback(AllowWasmCodeGenerationCallback);
31133123

0 commit comments

Comments
 (0)