Skip to content

Commit 0ec91b9

Browse files
committed
src: replace Environment::GetCurrent with args.GetIsolate
1 parent 4984b15 commit 0ec91b9

File tree

2 files changed

+32
-45
lines changed

2 files changed

+32
-45
lines changed

src/node_util.cc

Lines changed: 23 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,9 @@ CHAR_TEST(16, IsUnicodeSurrogate, (ch & 0xF800) == 0xD800)
5151
// If a UTF-16 surrogate is a low/trailing one.
5252
CHAR_TEST(16, IsUnicodeSurrogateTrail, (ch & 0x400) != 0)
5353

54-
static void GetOwnNonIndexProperties(
55-
const FunctionCallbackInfo<Value>& args) {
56-
Environment* env = Environment::GetCurrent(args);
57-
Local<Context> context = env->context();
54+
static void GetOwnNonIndexProperties(const FunctionCallbackInfo<Value>& args) {
55+
Isolate* isolate = args.GetIsolate();
56+
Local<Context> context = isolate->GetCurrentContext();
5857

5958
CHECK(args[0]->IsObject());
6059
CHECK(args[1]->IsUint32());
@@ -65,18 +64,18 @@ static void GetOwnNonIndexProperties(
6564

6665
PropertyFilter filter = FromV8Value<PropertyFilter>(args[1]);
6766

68-
if (!object->GetPropertyNames(
69-
context, KeyCollectionMode::kOwnOnly,
70-
filter,
71-
IndexFilter::kSkipIndices)
72-
.ToLocal(&properties)) {
67+
if (!object
68+
->GetPropertyNames(context,
69+
KeyCollectionMode::kOwnOnly,
70+
filter,
71+
IndexFilter::kSkipIndices)
72+
.ToLocal(&properties)) {
7373
return;
7474
}
7575
args.GetReturnValue().Set(properties);
7676
}
7777

78-
static void GetConstructorName(
79-
const FunctionCallbackInfo<Value>& args) {
78+
static void GetConstructorName(const FunctionCallbackInfo<Value>& args) {
8079
CHECK(args[0]->IsObject());
8180

8281
Local<Object> object = args[0].As<Object>();
@@ -85,8 +84,7 @@ static void GetConstructorName(
8584
args.GetReturnValue().Set(name);
8685
}
8786

88-
static void GetExternalValue(
89-
const FunctionCallbackInfo<Value>& args) {
87+
static void GetExternalValue(const FunctionCallbackInfo<Value>& args) {
9088
CHECK(args[0]->IsExternal());
9189
Isolate* isolate = args.GetIsolate();
9290
Local<External> external = args[0].As<External>();
@@ -99,15 +97,14 @@ static void GetExternalValue(
9997

10098
static void GetPromiseDetails(const FunctionCallbackInfo<Value>& args) {
10199
// Return undefined if it's not a Promise.
102-
if (!args[0]->IsPromise())
103-
return;
100+
if (!args[0]->IsPromise()) return;
104101

105102
auto isolate = args.GetIsolate();
106103

107104
Local<Promise> promise = args[0].As<Promise>();
108105

109106
int state = promise->State();
110-
Local<Value> values[2] = { Integer::New(isolate, state) };
107+
Local<Value> values[2] = {Integer::New(isolate, state)};
111108
size_t number_of_values = 1;
112109
if (state != Promise::PromiseState::kPending)
113110
values[number_of_values++] = promise->Result();
@@ -117,19 +114,15 @@ static void GetPromiseDetails(const FunctionCallbackInfo<Value>& args) {
117114

118115
static void GetProxyDetails(const FunctionCallbackInfo<Value>& args) {
119116
// Return undefined if it's not a proxy.
120-
if (!args[0]->IsProxy())
121-
return;
117+
if (!args[0]->IsProxy()) return;
122118

123119
Local<Proxy> proxy = args[0].As<Proxy>();
124120

125121
// TODO(BridgeAR): Remove the length check as soon as we prohibit access to
126122
// the util binding layer. It's accessed in the wild and `esm` would break in
127123
// case the check is removed.
128124
if (args.Length() == 1 || args[1]->IsTrue()) {
129-
Local<Value> ret[] = {
130-
proxy->GetTarget(),
131-
proxy->GetHandler()
132-
};
125+
Local<Value> ret[] = {proxy->GetTarget(), proxy->GetHandler()};
133126

134127
args.GetReturnValue().Set(
135128
Array::New(args.GetIsolate(), ret, arraysize(ret)));
@@ -165,24 +158,18 @@ static void GetCallerLocation(const FunctionCallbackInfo<Value>& args) {
165158
}
166159

167160
static void PreviewEntries(const FunctionCallbackInfo<Value>& args) {
168-
if (!args[0]->IsObject())
169-
return;
161+
if (!args[0]->IsObject()) return;
170162

171-
Environment* env = Environment::GetCurrent(args);
163+
Isolate* isolate = args.GetIsolate();
172164
bool is_key_value;
173165
Local<Array> entries;
174166
if (!args[0].As<Object>()->PreviewEntries(&is_key_value).ToLocal(&entries))
175167
return;
176168
// Fast path for WeakMap and WeakSet.
177-
if (args.Length() == 1)
178-
return args.GetReturnValue().Set(entries);
179-
180-
Local<Value> ret[] = {
181-
entries,
182-
Boolean::New(env->isolate(), is_key_value)
183-
};
184-
return args.GetReturnValue().Set(
185-
Array::New(env->isolate(), ret, arraysize(ret)));
169+
if (args.Length() == 1) return args.GetReturnValue().Set(entries);
170+
171+
Local<Value> ret[] = {entries, Boolean::New(isolate, is_key_value)};
172+
return args.GetReturnValue().Set(Array::New(isolate, ret, arraysize(ret)));
186173
}
187174

188175
static void Sleep(const FunctionCallbackInfo<Value>& args) {
@@ -222,9 +209,9 @@ static uint32_t GetUVHandleTypeCode(const uv_handle_type type) {
222209
}
223210

224211
static void GuessHandleType(const FunctionCallbackInfo<Value>& args) {
225-
Environment* env = Environment::GetCurrent(args);
226212
int fd;
227-
if (!args[0]->Int32Value(env->context()).To(&fd)) return;
213+
if (!args[0]->Int32Value(args.GetIsolate()->GetCurrentContext()).To(&fd))
214+
return;
228215
CHECK_GE(fd, 0);
229216

230217
uv_handle_type t = uv_guess_handle(fd);

src/uv.cc

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -71,12 +71,13 @@ void ErrName(const FunctionCallbackInfo<Value>& args) {
7171
Environment* env = Environment::GetCurrent(args);
7272
if (env->options()->pending_deprecation && env->EmitErrNameWarning()) {
7373
if (ProcessEmitDeprecationWarning(
74-
env,
75-
"Directly calling process.binding('uv').errname(<val>) is being"
76-
" deprecated. "
77-
"Please make sure to use util.getSystemErrorName() instead.",
78-
"DEP0119").IsNothing())
79-
return;
74+
env,
75+
"Directly calling process.binding('uv').errname(<val>) is being"
76+
" deprecated. "
77+
"Please make sure to use util.getSystemErrorName() instead.",
78+
"DEP0119")
79+
.IsNothing())
80+
return;
8081
}
8182
int err = args[0].As<v8::Int32>()->Value();
8283
CHECK_LT(err, 0);
@@ -86,9 +87,8 @@ void ErrName(const FunctionCallbackInfo<Value>& args) {
8687
}
8788

8889
void GetErrMap(const FunctionCallbackInfo<Value>& args) {
89-
Environment* env = Environment::GetCurrent(args);
90-
Isolate* isolate = env->isolate();
91-
Local<Context> context = env->context();
90+
Isolate* isolate = args.GetIsolate();
91+
Local<Context> context = isolate->GetCurrentContext();
9292

9393
// This can't return a SafeMap, because the uv binding can be referenced
9494
// by user code by using `process.binding('uv').getErrorMap()`:

0 commit comments

Comments
 (0)