@@ -84,14 +84,36 @@ function validateString(prop, propName) {
8484 throw new ERR_INVALID_ARG_TYPE ( propName , 'string' , prop ) ;
8585}
8686
87+ function validateBool ( prop , propName ) {
88+ if ( prop !== undefined && typeof prop !== 'boolean' )
89+ throw new ERR_INVALID_ARG_TYPE ( propName , 'boolean' , prop ) ;
90+ }
91+
92+ function validateObject ( prop , propName ) {
93+ if ( prop !== undefined && ( typeof prop !== 'object' || prop === null ) )
94+ throw new ERR_INVALID_ARG_TYPE ( propName , 'Object' , prop ) ;
95+ }
96+
8797function getContextOptions ( options ) {
8898 if ( options ) {
99+ validateObject ( options . contextCodeGeneration ,
100+ 'options.contextCodeGeneration' ) ;
89101 const contextOptions = {
90102 name : options . contextName ,
91- origin : options . contextOrigin
103+ origin : options . contextOrigin ,
104+ codeGeneration : typeof options . contextCodeGeneration === 'object' ? {
105+ strings : options . contextCodeGeneration . strings ,
106+ wasm : options . contextCodeGeneration . wasm ,
107+ } : undefined ,
92108 } ;
93109 validateString ( contextOptions . name , 'options.contextName' ) ;
94110 validateString ( contextOptions . origin , 'options.contextOrigin' ) ;
111+ if ( contextOptions . codeGeneration ) {
112+ validateBool ( contextOptions . codeGeneration . strings ,
113+ 'options.contextCodeGeneration.strings' ) ;
114+ validateBool ( contextOptions . codeGeneration . wasm ,
115+ 'options.contextCodeGeneration.wasm' ) ;
116+ }
95117 return contextOptions ;
96118 }
97119 return { } ;
@@ -109,10 +131,21 @@ function createContext(sandbox, options) {
109131 if ( typeof options !== 'object' || options === null ) {
110132 throw new ERR_INVALID_ARG_TYPE ( 'options' , 'object' , options ) ;
111133 }
134+ validateObject ( options . codeGeneration , 'options.codeGeneration' ) ;
112135 options = {
113136 name : options . name ,
114- origin : options . origin
137+ origin : options . origin ,
138+ codeGeneration : typeof options . codeGeneration === 'object' ? {
139+ strings : options . codeGeneration . strings ,
140+ wasm : options . codeGeneration . wasm ,
141+ } : undefined ,
115142 } ;
143+ if ( options . codeGeneration !== undefined ) {
144+ validateBool ( options . codeGeneration . strings ,
145+ 'options.codeGeneration.strings' ) ;
146+ validateBool ( options . codeGeneration . wasm ,
147+ 'options.codeGeneration.wasm' ) ;
148+ }
116149 if ( options . name === undefined ) {
117150 options . name = `VM Context ${ defaultContextNameIndex ++ } ` ;
118151 } else if ( typeof options . name !== 'string' ) {
0 commit comments