diff --git a/src/node_contextify.cc b/src/node_contextify.cc index 8933946ff1b425..47d7d6194e6a9d 100644 --- a/src/node_contextify.cc +++ b/src/node_contextify.cc @@ -492,12 +492,14 @@ class ContextifyScript : public BaseObject { TryCatch try_catch(env->isolate()); Local code = args[0]->ToString(env->isolate()); - Local filename = GetFilenameArg(env, args, 1); - Local lineOffset = GetLineOffsetArg(args, 1); - Local columnOffset = GetColumnOffsetArg(args, 1); - bool display_errors = GetDisplayErrorsArg(env, args, 1); - MaybeLocal cached_data_buf = GetCachedData(env, args, 1); - bool produce_cached_data = GetProduceCachedData(env, args, 1); + + Local options = args[1]; + Local filename = GetFilenameArg(env, options); + Local lineOffset = GetLineOffsetArg(env, options); + Local columnOffset = GetColumnOffsetArg(env, options); + bool display_errors = GetDisplayErrorsArg(env, options); + MaybeLocal cached_data_buf = GetCachedData(env, options); + bool produce_cached_data = GetProduceCachedData(env, options); if (try_catch.HasCaught()) { try_catch.ReThrow(); return; @@ -570,9 +572,9 @@ class ContextifyScript : public BaseObject { // Assemble arguments TryCatch try_catch(args.GetIsolate()); - uint64_t timeout = GetTimeoutArg(env, args, 0); - bool display_errors = GetDisplayErrorsArg(env, args, 0); - bool break_on_sigint = GetBreakOnSigintArg(env, args, 0); + uint64_t timeout = GetTimeoutArg(env, args[0]); + bool display_errors = GetDisplayErrorsArg(env, args[0]); + bool break_on_sigint = GetBreakOnSigintArg(env, args[0]); if (try_catch.HasCaught()) { try_catch.ReThrow(); return; @@ -600,9 +602,9 @@ class ContextifyScript : public BaseObject { Local sandbox = args[0].As(); { TryCatch try_catch(env->isolate()); - timeout = GetTimeoutArg(env, args, 1); - display_errors = GetDisplayErrorsArg(env, args, 1); - break_on_sigint = GetBreakOnSigintArg(env, args, 1); + timeout = GetTimeoutArg(env, args[1]); + display_errors = GetDisplayErrorsArg(env, args[1]); + break_on_sigint = GetBreakOnSigintArg(env, args[1]); if (try_catch.HasCaught()) { try_catch.ReThrow(); return; @@ -676,36 +678,31 @@ class ContextifyScript : public BaseObject { True(env->isolate())); } - static bool GetBreakOnSigintArg(Environment* env, - const FunctionCallbackInfo& args, - const int i) { - if (args[i]->IsUndefined() || args[i]->IsString()) { + static bool GetBreakOnSigintArg(Environment* env, Local options) { + if (options->IsUndefined() || options->IsString()) { return false; } - if (!args[i]->IsObject()) { + if (!options->IsObject()) { env->ThrowTypeError("options must be an object"); return false; } - Local key = FIXED_ONE_BYTE_STRING(args.GetIsolate(), - "breakOnSigint"); - Local value = args[i].As()->Get(key); + Local key = FIXED_ONE_BYTE_STRING(env->isolate(), "breakOnSigint"); + Local value = options.As()->Get(key); return value->IsTrue(); } - static int64_t GetTimeoutArg(Environment* env, - const FunctionCallbackInfo& args, - const int i) { - if (args[i]->IsUndefined() || args[i]->IsString()) { + static int64_t GetTimeoutArg(Environment* env, Local options) { + if (options->IsUndefined() || options->IsString()) { return -1; } - if (!args[i]->IsObject()) { + if (!options->IsObject()) { env->ThrowTypeError("options must be an object"); return -1; } - Local key = FIXED_ONE_BYTE_STRING(args.GetIsolate(), "timeout"); - Local value = args[i].As()->Get(key); + Local key = FIXED_ONE_BYTE_STRING(env->isolate(), "timeout"); + Local value = options.As()->Get(key); if (value->IsUndefined()) { return -1; } @@ -719,59 +716,52 @@ class ContextifyScript : public BaseObject { } - static bool GetDisplayErrorsArg(Environment* env, - const FunctionCallbackInfo& args, - const int i) { - if (args[i]->IsUndefined() || args[i]->IsString()) { + static bool GetDisplayErrorsArg(Environment* env, Local options) { + if (options->IsUndefined() || options->IsString()) { return true; } - if (!args[i]->IsObject()) { + if (!options->IsObject()) { env->ThrowTypeError("options must be an object"); return false; } - Local key = FIXED_ONE_BYTE_STRING(args.GetIsolate(), - "displayErrors"); - Local value = args[i].As()->Get(key); + Local key = FIXED_ONE_BYTE_STRING(env->isolate(), "displayErrors"); + Local value = options.As()->Get(key); return value->IsUndefined() ? true : value->BooleanValue(); } - static Local GetFilenameArg(Environment* env, - const FunctionCallbackInfo& args, - const int i) { + static Local GetFilenameArg(Environment* env, Local options) { Local defaultFilename = - FIXED_ONE_BYTE_STRING(args.GetIsolate(), "evalmachine."); + FIXED_ONE_BYTE_STRING(env->isolate(), "evalmachine."); - if (args[i]->IsUndefined()) { + if (options->IsUndefined()) { return defaultFilename; } - if (args[i]->IsString()) { - return args[i].As(); + if (options->IsString()) { + return options.As(); } - if (!args[i]->IsObject()) { + if (!options->IsObject()) { env->ThrowTypeError("options must be an object"); return Local(); } - Local key = FIXED_ONE_BYTE_STRING(args.GetIsolate(), "filename"); - Local value = args[i].As()->Get(key); + Local key = FIXED_ONE_BYTE_STRING(env->isolate(), "filename"); + Local value = options.As()->Get(key); if (value->IsUndefined()) return defaultFilename; - return value->ToString(args.GetIsolate()); + return value->ToString(env->isolate()); } - static MaybeLocal GetCachedData( - Environment* env, - const FunctionCallbackInfo& args, - const int i) { - if (!args[i]->IsObject()) { + static MaybeLocal GetCachedData(Environment* env, + Local options) { + if (!options->IsObject()) { return MaybeLocal(); } - Local value = args[i].As()->Get(env->cached_data_string()); + Local value = options.As()->Get(env->cached_data_string()); if (value->IsUndefined()) { return MaybeLocal(); } @@ -785,48 +775,42 @@ class ContextifyScript : public BaseObject { } - static bool GetProduceCachedData( - Environment* env, - const FunctionCallbackInfo& args, - const int i) { - if (!args[i]->IsObject()) { + static bool GetProduceCachedData(Environment* env, Local options) { + if (!options->IsObject()) { return false; } Local value = - args[i].As()->Get(env->produce_cached_data_string()); + options.As()->Get(env->produce_cached_data_string()); return value->IsTrue(); } - static Local GetLineOffsetArg( - const FunctionCallbackInfo& args, - const int i) { - Local defaultLineOffset = Integer::New(args.GetIsolate(), 0); + static Local GetLineOffsetArg(Environment* env, + Local options) { + Local defaultLineOffset = Integer::New(env->isolate(), 0); - if (!args[i]->IsObject()) { + if (!options->IsObject()) { return defaultLineOffset; } - Local key = FIXED_ONE_BYTE_STRING(args.GetIsolate(), "lineOffset"); - Local value = args[i].As()->Get(key); + Local key = FIXED_ONE_BYTE_STRING(env->isolate(), "lineOffset"); + Local value = options.As()->Get(key); return value->IsUndefined() ? defaultLineOffset : value->ToInteger(); } - static Local GetColumnOffsetArg( - const FunctionCallbackInfo& args, - const int i) { - Local defaultColumnOffset = Integer::New(args.GetIsolate(), 0); + static Local GetColumnOffsetArg(Environment* env, + Local options) { + Local defaultColumnOffset = Integer::New(env->isolate(), 0); - if (!args[i]->IsObject()) { + if (!options->IsObject()) { return defaultColumnOffset; } - Local key = FIXED_ONE_BYTE_STRING(args.GetIsolate(), - "columnOffset"); - Local value = args[i].As()->Get(key); + Local key = FIXED_ONE_BYTE_STRING(env->isolate(), "columnOffset"); + Local value = options.As()->Get(key); return value->IsUndefined() ? defaultColumnOffset : value->ToInteger(); }