Skip to content

Commit f6d4dac

Browse files
committed
fixup local checks
1 parent 61c5de0 commit f6d4dac

File tree

1 file changed

+24
-10
lines changed

1 file changed

+24
-10
lines changed

src/module_wrap.cc

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -997,11 +997,18 @@ Maybe<URL> ResolveExportsTarget(Environment* env,
997997
Maybe<URL> resolved = ResolveExportsTarget(env, pjson_url,
998998
target_item, subpath, pkg_subpath, base);
999999
if (resolved.IsNothing()) {
1000-
CHECK(try_catch.HasCaught() && !try_catch.Exception().IsEmpty());
1001-
auto e = try_catch.Exception()->ToObject(context).ToLocalChecked();
1002-
auto code = e->Get(context, env->code_string()).ToLocalChecked();
1003-
Utf8Value code_utf8(env->isolate(),
1004-
code->ToString(context).ToLocalChecked());
1000+
CHECK(try_catch.HasCaught());
1001+
if (try_catch.Exception().IsEmpty()) return Nothing<URL>();
1002+
Local<Object> e;
1003+
if (!try_catch.Exception()->ToObject(context).ToLocal(&e))
1004+
return Nothing<URL>();
1005+
Local<Value> code;
1006+
if (!e->Get(context, env->code_string()).ToLocal(&code))
1007+
return Nothing<URL>();
1008+
Local<String> code_string;
1009+
if (!code->ToString(context).ToLocal(&code_string))
1010+
return Nothing<URL>();
1011+
Utf8Value code_utf8(env->isolate(), code_string);
10051012
if (strcmp(*code_utf8, "ERR_PACKAGE_PATH_NOT_EXPORTED") == 0 ||
10061013
strcmp(*code_utf8, "ERR_INVALID_PACKAGE_TARGET") == 0) {
10071014
continue;
@@ -1046,11 +1053,18 @@ Maybe<URL> ResolveExportsTarget(Environment* env,
10461053
Maybe<URL> resolved = ResolveExportsTarget(env, pjson_url,
10471054
conditionalTarget, subpath, pkg_subpath, base);
10481055
if (resolved.IsNothing()) {
1049-
CHECK(try_catch.HasCaught() && !try_catch.Exception().IsEmpty());
1050-
auto e = try_catch.Exception()->ToObject(context).ToLocalChecked();
1051-
auto code = e->Get(context, env->code_string()).ToLocalChecked();
1052-
Utf8Value code_utf8(env->isolate(),
1053-
code->ToString(context).ToLocalChecked());
1056+
CHECK(try_catch.HasCaught());
1057+
if (try_catch.Exception().IsEmpty()) return Nothing<URL>();
1058+
Local<Object> e;
1059+
if (!try_catch.Exception()->ToObject(context).ToLocal(&e))
1060+
return Nothing<URL>();
1061+
Local<Value> code;
1062+
if (!e->Get(context, env->code_string()).ToLocal(&code))
1063+
return Nothing<URL>();
1064+
Local<String> code_string;
1065+
if (!code->ToString(context).ToLocal(&code_string))
1066+
return Nothing<URL>();
1067+
Utf8Value code_utf8(env->isolate(), code_string);
10541068
if (strcmp(*code_utf8, "ERR_PACKAGE_PATH_NOT_EXPORTED") == 0)
10551069
continue;
10561070
try_catch.ReThrow();

0 commit comments

Comments
 (0)