@@ -84,14 +84,36 @@ function validateString(prop, propName) {
84
84
throw new ERR_INVALID_ARG_TYPE ( propName , 'string' , prop ) ;
85
85
}
86
86
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
+
87
97
function getContextOptions ( options ) {
88
98
if ( options ) {
99
+ validateObject ( options . contextCodeGeneration ,
100
+ 'options.contextCodeGeneration' ) ;
89
101
const contextOptions = {
90
102
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 ,
92
108
} ;
93
109
validateString ( contextOptions . name , 'options.contextName' ) ;
94
110
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
+ }
95
117
return contextOptions ;
96
118
}
97
119
return { } ;
@@ -109,10 +131,21 @@ function createContext(sandbox, options) {
109
131
if ( typeof options !== 'object' || options === null ) {
110
132
throw new ERR_INVALID_ARG_TYPE ( 'options' , 'object' , options ) ;
111
133
}
134
+ validateObject ( options . codeGeneration , 'options.codeGeneration' ) ;
112
135
options = {
113
136
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 ,
115
142
} ;
143
+ if ( options . codeGeneration !== undefined ) {
144
+ validateBool ( options . codeGeneration . strings ,
145
+ 'options.codeGeneration.strings' ) ;
146
+ validateBool ( options . codeGeneration . wasm ,
147
+ 'options.codeGeneration.wasm' ) ;
148
+ }
116
149
if ( options . name === undefined ) {
117
150
options . name = `VM Context ${ defaultContextNameIndex ++ } ` ;
118
151
} else if ( typeof options . name !== 'string' ) {
0 commit comments