From f7842ad1698984e978bc414bc359cb5268b953d9 Mon Sep 17 00:00:00 2001 From: Franziska Hinkelmann Date: Fri, 30 Sep 2016 20:35:17 +0200 Subject: [PATCH] src: refactor contextify Small refactoring to make contextify more readable. Remove auto and inline FromJust(). Simplify if statement. PR-URL: https://github.com/nodejs/node/pull/8909 Reviewed-By: Ben Noordhuis Reviewed-By: Anna Henningsen Reviewed-By: James M Snell --- src/node_contextify.cc | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/src/node_contextify.cc b/src/node_contextify.cc index 47d7d6194e..d74b01ea0d 100644 --- a/src/node_contextify.cc +++ b/src/node_contextify.cc @@ -125,15 +125,13 @@ class ContextifyContext { int length = names->Length(); for (int i = 0; i < length; i++) { Local key = names->Get(i)->ToString(env()->isolate()); - auto maybe_has = sandbox_obj->HasOwnProperty(context, key); + Maybe has = sandbox_obj->HasOwnProperty(context, key); // Check for pending exceptions - if (!maybe_has.IsJust()) - break; - - bool has = maybe_has.FromJust(); + if (has.IsNothing()) + return; - if (!has) { + if (!has.FromJust()) { // Could also do this like so: // // PropertyAttribute att = global->GetPropertyAttributes(key_v); @@ -316,7 +314,7 @@ class ContextifyContext { } Local sandbox = args[0].As(); - auto result = + Maybe result = sandbox->HasPrivate(env->context(), env->contextify_context_private_symbol()); args.GetReturnValue().Set(result.FromJust()); @@ -332,7 +330,7 @@ class ContextifyContext { static ContextifyContext* ContextFromContextifiedSandbox( Environment* env, const Local& sandbox) { - auto maybe_value = + MaybeLocal maybe_value = sandbox->GetPrivate(env->context(), env->contextify_context_private_symbol()); Local context_external_v; @@ -506,8 +504,8 @@ class ContextifyScript : public BaseObject { } ScriptCompiler::CachedData* cached_data = nullptr; - if (!cached_data_buf.IsEmpty()) { - Local ui8 = cached_data_buf.ToLocalChecked(); + Local ui8; + if (cached_data_buf.ToLocal(&ui8)) { ArrayBuffer::Contents contents = ui8->Buffer()->GetContents(); cached_data = new ScriptCompiler::CachedData( static_cast(contents.Data()) + ui8->ByteOffset(), @@ -655,7 +653,7 @@ class ContextifyScript : public BaseObject { AppendExceptionLine(env, exception, try_catch.Message(), CONTEXTIFY_ERROR); Local stack = err_obj->Get(env->stack_string()); - auto maybe_value = + MaybeLocal maybe_value = err_obj->GetPrivate( env->context(), env->arrow_message_private_symbol());