Skip to content

Commit 9bfdebf

Browse files
committed
toLocalChecked
1 parent d760e46 commit 9bfdebf

File tree

1 file changed

+21
-18
lines changed

1 file changed

+21
-18
lines changed

src/module_wrap.cc

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#define V8_ENABLE_CHECKS 1
12
#include "module_wrap.h"
23

34
#include "env.h"
@@ -9,7 +10,6 @@
910
#include "node_watchdog.h"
1011
#include "node_process.h"
1112

12-
1313
#include <sys/stat.h> // S_IFDIR
1414

1515
#include <algorithm>
@@ -908,19 +908,22 @@ Maybe<URL> ResolveExportsTargetString(Environment* env,
908908
return Just(subpath_resolved);
909909
}
910910

911-
bool IsArrayIndex(Environment* env, Local<String> p) {
911+
bool IsArrayIndex(Environment* env, Local<Value> p) {
912912
Local<Context> context = env->context();
913-
double n_dbl = static_cast<double>(p->NumberValue(context).FromJust());
913+
Local<String> p_str = p->ToString(context).ToLocalChecked();
914+
double n_dbl = static_cast<double>(p_str->NumberValue(context).FromJust());
914915
Local<Number> n = Number::New(env->isolate(), n_dbl);
915-
Local<String> cmp_str;
916-
CHECK(n->ToString(context).ToLocal(&cmp_str));
917-
if (!p->Equals(context, cmp_str).FromJust())
916+
Local<String> cmp_str = n->ToString(context).ToLocalChecked();
917+
if (!p_str->Equals(context, cmp_str).FromJust()) {
918918
return false;
919-
if (n_dbl == 0 && std::signbit(n_dbl) == false)
919+
}
920+
if (n_dbl == 0 && std::signbit(n_dbl) == false) {
920921
return true;
922+
}
921923
Local<Integer> cmp_integer;
922-
if (!n->ToInteger(context).ToLocal(&cmp_integer))
924+
if (!n->ToInteger(context).ToLocal(&cmp_integer)) {
923925
return false;
926+
}
924927
return n_dbl > 0 && n_dbl < (2 ^ 32) - 1;
925928
}
926929

@@ -974,8 +977,8 @@ Maybe<URL> ResolveExportsTarget(Environment* env,
974977
Local<Value> conditionalTarget;
975978
bool matched = false;
976979
for (uint32_t i = 0; i < target_obj_keys->Length(); ++i) {
977-
Local<String> key =
978-
target_obj_keys->Get(context, i).ToLocalChecked().As<String>();
980+
Local<Value> key =
981+
target_obj_keys->Get(context, i).ToLocalChecked();
979982
if (IsArrayIndex(env, key)) {
980983
const std::string msg = "Invalid package config for " +
981984
pjson_url.ToFilePath() + ", \"exports\" cannot contain numeric " +
@@ -985,9 +988,9 @@ Maybe<URL> ResolveExportsTarget(Environment* env,
985988
}
986989
}
987990
for (uint32_t i = 0; i < target_obj_keys->Length(); ++i) {
988-
Local<String> key =
989-
target_obj_keys->Get(context, i).ToLocalChecked().As<String>();
990-
Utf8Value key_utf8(env->isolate(), key);
991+
Local<Value> key = target_obj_keys->Get(context, i).ToLocalChecked();
992+
Utf8Value key_utf8(env->isolate(),
993+
key->ToString(context).ToLocalChecked());
991994
std::string key_str(*key_utf8, key_utf8.length());
992995
if (key_str == "node" || key_str == "import") {
993996
if (!env->options()->experimental_conditional_exports) continue;
@@ -1035,8 +1038,8 @@ Maybe<bool> IsConditionalExportsMainSugar(Environment* env,
10351038
exports_obj->GetOwnPropertyNames(context).ToLocalChecked();
10361039
bool isConditionalSugar = false;
10371040
for (uint32_t i = 0; i < keys->Length(); ++i) {
1038-
Local<String> key = keys->Get(context, i).ToLocalChecked().As<String>();
1039-
Utf8Value key_utf8(env->isolate(), key);
1041+
Local<Value> key = keys->Get(context, i).ToLocalChecked();
1042+
Utf8Value key_utf8(env->isolate(), key->ToString(context).ToLocalChecked());
10401043
bool curIsConditionalSugar = key_utf8.length() == 0 || key_utf8[0] != '.';
10411044
if (i == 0) {
10421045
isConditionalSugar = curIsConditionalSugar;
@@ -1144,13 +1147,13 @@ Maybe<URL> PackageExportsResolve(Environment* env,
11441147
Local<Array> keys =
11451148
exports_obj->GetOwnPropertyNames(context).ToLocalChecked();
11461149
for (uint32_t i = 0; i < keys->Length(); ++i) {
1147-
Local<String> key = keys->Get(context, i).ToLocalChecked().As<String>();
1148-
Utf8Value key_utf8(isolate, key);
1150+
Local<Value> key = keys->Get(context, i).ToLocalChecked();
1151+
Utf8Value key_utf8(isolate, key->ToString(context).ToLocalChecked());
11491152
std::string key_str(*key_utf8, key_utf8.length());
11501153
if (key_str.back() != '/') continue;
11511154
if (pkg_subpath.substr(0, key_str.length()) == key_str &&
11521155
key_str.length() > best_match_str.length()) {
1153-
best_match = key;
1156+
best_match = key->ToString(context).ToLocalChecked();
11541157
best_match_str = key_str;
11551158
}
11561159
}

0 commit comments

Comments
 (0)