Skip to content

Commit b2be04a

Browse files
fhinkeljasnell
authored andcommitted
src: refactor contextify
Small refactoring to make contextify more readable. Remove auto and inline FromJust(). Simplify if statement. PR-URL: #8909 Reviewed-By: Ben Noordhuis <[email protected]> Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: James M Snell <[email protected]>
1 parent 72f1c41 commit b2be04a

File tree

1 file changed

+9
-11
lines changed

1 file changed

+9
-11
lines changed

src/node_contextify.cc

+9-11
Original file line numberDiff line numberDiff line change
@@ -125,15 +125,13 @@ class ContextifyContext {
125125
int length = names->Length();
126126
for (int i = 0; i < length; i++) {
127127
Local<String> key = names->Get(i)->ToString(env()->isolate());
128-
auto maybe_has = sandbox_obj->HasOwnProperty(context, key);
128+
Maybe<bool> has = sandbox_obj->HasOwnProperty(context, key);
129129

130130
// Check for pending exceptions
131-
if (!maybe_has.IsJust())
132-
break;
133-
134-
bool has = maybe_has.FromJust();
131+
if (has.IsNothing())
132+
return;
135133

136-
if (!has) {
134+
if (!has.FromJust()) {
137135
// Could also do this like so:
138136
//
139137
// PropertyAttribute att = global->GetPropertyAttributes(key_v);
@@ -316,7 +314,7 @@ class ContextifyContext {
316314
}
317315
Local<Object> sandbox = args[0].As<Object>();
318316

319-
auto result =
317+
Maybe<bool> result =
320318
sandbox->HasPrivate(env->context(),
321319
env->contextify_context_private_symbol());
322320
args.GetReturnValue().Set(result.FromJust());
@@ -332,7 +330,7 @@ class ContextifyContext {
332330
static ContextifyContext* ContextFromContextifiedSandbox(
333331
Environment* env,
334332
const Local<Object>& sandbox) {
335-
auto maybe_value =
333+
MaybeLocal<Value> maybe_value =
336334
sandbox->GetPrivate(env->context(),
337335
env->contextify_context_private_symbol());
338336
Local<Value> context_external_v;
@@ -506,8 +504,8 @@ class ContextifyScript : public BaseObject {
506504
}
507505

508506
ScriptCompiler::CachedData* cached_data = nullptr;
509-
if (!cached_data_buf.IsEmpty()) {
510-
Local<Uint8Array> ui8 = cached_data_buf.ToLocalChecked();
507+
Local<Uint8Array> ui8;
508+
if (cached_data_buf.ToLocal(&ui8)) {
511509
ArrayBuffer::Contents contents = ui8->Buffer()->GetContents();
512510
cached_data = new ScriptCompiler::CachedData(
513511
static_cast<uint8_t*>(contents.Data()) + ui8->ByteOffset(),
@@ -655,7 +653,7 @@ class ContextifyScript : public BaseObject {
655653

656654
AppendExceptionLine(env, exception, try_catch.Message(), CONTEXTIFY_ERROR);
657655
Local<Value> stack = err_obj->Get(env->stack_string());
658-
auto maybe_value =
656+
MaybeLocal<Value> maybe_value =
659657
err_obj->GetPrivate(
660658
env->context(),
661659
env->arrow_message_private_symbol());

0 commit comments

Comments
 (0)