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 <info@bnoordhuis.nl> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: James M Snell <jasnell@gmail.com>
This commit is contained in:
parent
6f05de4d89
commit
f7842ad169
@ -125,15 +125,13 @@ class ContextifyContext {
|
|||||||
int length = names->Length();
|
int length = names->Length();
|
||||||
for (int i = 0; i < length; i++) {
|
for (int i = 0; i < length; i++) {
|
||||||
Local<String> key = names->Get(i)->ToString(env()->isolate());
|
Local<String> key = names->Get(i)->ToString(env()->isolate());
|
||||||
auto maybe_has = sandbox_obj->HasOwnProperty(context, key);
|
Maybe<bool> has = sandbox_obj->HasOwnProperty(context, key);
|
||||||
|
|
||||||
// Check for pending exceptions
|
// Check for pending exceptions
|
||||||
if (!maybe_has.IsJust())
|
if (has.IsNothing())
|
||||||
break;
|
return;
|
||||||
|
|
||||||
bool has = maybe_has.FromJust();
|
if (!has.FromJust()) {
|
||||||
|
|
||||||
if (!has) {
|
|
||||||
// Could also do this like so:
|
// Could also do this like so:
|
||||||
//
|
//
|
||||||
// PropertyAttribute att = global->GetPropertyAttributes(key_v);
|
// PropertyAttribute att = global->GetPropertyAttributes(key_v);
|
||||||
@ -316,7 +314,7 @@ class ContextifyContext {
|
|||||||
}
|
}
|
||||||
Local<Object> sandbox = args[0].As<Object>();
|
Local<Object> sandbox = args[0].As<Object>();
|
||||||
|
|
||||||
auto result =
|
Maybe<bool> result =
|
||||||
sandbox->HasPrivate(env->context(),
|
sandbox->HasPrivate(env->context(),
|
||||||
env->contextify_context_private_symbol());
|
env->contextify_context_private_symbol());
|
||||||
args.GetReturnValue().Set(result.FromJust());
|
args.GetReturnValue().Set(result.FromJust());
|
||||||
@ -332,7 +330,7 @@ class ContextifyContext {
|
|||||||
static ContextifyContext* ContextFromContextifiedSandbox(
|
static ContextifyContext* ContextFromContextifiedSandbox(
|
||||||
Environment* env,
|
Environment* env,
|
||||||
const Local<Object>& sandbox) {
|
const Local<Object>& sandbox) {
|
||||||
auto maybe_value =
|
MaybeLocal<Value> maybe_value =
|
||||||
sandbox->GetPrivate(env->context(),
|
sandbox->GetPrivate(env->context(),
|
||||||
env->contextify_context_private_symbol());
|
env->contextify_context_private_symbol());
|
||||||
Local<Value> context_external_v;
|
Local<Value> context_external_v;
|
||||||
@ -506,8 +504,8 @@ class ContextifyScript : public BaseObject {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ScriptCompiler::CachedData* cached_data = nullptr;
|
ScriptCompiler::CachedData* cached_data = nullptr;
|
||||||
if (!cached_data_buf.IsEmpty()) {
|
Local<Uint8Array> ui8;
|
||||||
Local<Uint8Array> ui8 = cached_data_buf.ToLocalChecked();
|
if (cached_data_buf.ToLocal(&ui8)) {
|
||||||
ArrayBuffer::Contents contents = ui8->Buffer()->GetContents();
|
ArrayBuffer::Contents contents = ui8->Buffer()->GetContents();
|
||||||
cached_data = new ScriptCompiler::CachedData(
|
cached_data = new ScriptCompiler::CachedData(
|
||||||
static_cast<uint8_t*>(contents.Data()) + ui8->ByteOffset(),
|
static_cast<uint8_t*>(contents.Data()) + ui8->ByteOffset(),
|
||||||
@ -655,7 +653,7 @@ class ContextifyScript : public BaseObject {
|
|||||||
|
|
||||||
AppendExceptionLine(env, exception, try_catch.Message(), CONTEXTIFY_ERROR);
|
AppendExceptionLine(env, exception, try_catch.Message(), CONTEXTIFY_ERROR);
|
||||||
Local<Value> stack = err_obj->Get(env->stack_string());
|
Local<Value> stack = err_obj->Get(env->stack_string());
|
||||||
auto maybe_value =
|
MaybeLocal<Value> maybe_value =
|
||||||
err_obj->GetPrivate(
|
err_obj->GetPrivate(
|
||||||
env->context(),
|
env->context(),
|
||||||
env->arrow_message_private_symbol());
|
env->arrow_message_private_symbol());
|
||||||
|
Loading…
x
Reference in New Issue
Block a user