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