@@ -75,6 +75,11 @@ Script.prototype.runInContext = function(contextifiedSandbox, options) {
7575} ;
7676
7777Script . prototype . runInNewContext = function ( sandbox , options ) {
78+ const context = createContext ( sandbox , getContextOptions ( options ) ) ;
79+ return this . runInContext ( context , options ) ;
80+ } ;
81+
82+ function getContextOptions ( options ) {
7883 const contextOptions = options ? {
7984 name : options . contextName ,
8085 origin : options . contextOrigin
@@ -89,9 +94,8 @@ Script.prototype.runInNewContext = function(sandbox, options) {
8994 throw new errors . TypeError ( 'ERR_INVALID_ARG_TYPE' , 'options.contextOrigin' ,
9095 'string' , contextOptions . origin ) ;
9196 }
92- const context = createContext ( sandbox , contextOptions ) ;
93- return this . runInContext ( context , options ) ;
94- } ;
97+ return contextOptions ;
98+ }
9599
96100let defaultContextNameIndex = 1 ;
97101function createContext ( sandbox , options ) {
@@ -170,21 +174,7 @@ function runInNewContext(code, sandbox, options) {
170174 if ( typeof options === 'string' ) {
171175 options = { filename : options } ;
172176 }
173- const contextOptions = options ? {
174- name : options . contextName ,
175- origin : options . contextOrigin
176- } : { } ;
177- if ( contextOptions . name !== undefined &&
178- typeof contextOptions . name !== 'string' ) {
179- throw new errors . TypeError ( 'ERR_INVALID_ARG_TYPE' , 'options.contextName' ,
180- 'string' , contextOptions . name ) ;
181- }
182- if ( contextOptions . origin !== undefined &&
183- typeof contextOptions . origin !== 'string' ) {
184- throw new errors . TypeError ( 'ERR_INVALID_ARG_TYPE' , 'options.contextOrigin' ,
185- 'string' , contextOptions . origin ) ;
186- }
187- sandbox = createContext ( sandbox , contextOptions ) ;
177+ sandbox = createContext ( sandbox , getContextOptions ( options ) ) ;
188178 options = Object . assign ( { } , options , {
189179 [ kParsingContext ] : sandbox
190180 } ) ;
0 commit comments