@@ -32,9 +32,7 @@ const {
3232 ContextifyScript,
3333 MicrotaskQueue,
3434 makeContext,
35- isContext : _isContext ,
3635 constants,
37- compileFunction : _compileFunction ,
3836 measureMemory : _measureMemory ,
3937} = internalBinding ( 'contextify' ) ;
4038const {
@@ -45,9 +43,7 @@ const {
4543 isArrayBufferView,
4644} = require ( 'internal/util/types' ) ;
4745const {
48- validateArray,
4946 validateBoolean,
50- validateBuffer,
5147 validateFunction,
5248 validateInt32,
5349 validateObject,
@@ -60,6 +56,10 @@ const {
6056 kEmptyObject,
6157 kVmBreakFirstLineSymbol,
6258} = require ( 'internal/util' ) ;
59+ const {
60+ internalCompileFunction,
61+ isContext,
62+ } = require ( 'internal/vm' ) ;
6363const kParsingContext = Symbol ( 'script parsing context' ) ;
6464
6565class Script extends ContextifyScript {
@@ -213,12 +213,6 @@ function getContextOptions(options) {
213213 return contextOptions ;
214214}
215215
216- function isContext ( object ) {
217- validateObject ( object , 'object' , { allowArray : true } ) ;
218-
219- return _isContext ( object ) ;
220- }
221-
222216let defaultContextNameIndex = 1 ;
223217function createContext ( contextObject = { } , options = kEmptyObject ) {
224218 if ( isContext ( contextObject ) ) {
@@ -314,83 +308,7 @@ function runInThisContext(code, options) {
314308}
315309
316310function compileFunction ( code , params , options = kEmptyObject ) {
317- validateString ( code , 'code' ) ;
318- if ( params !== undefined ) {
319- validateArray ( params , 'params' ) ;
320- ArrayPrototypeForEach ( params ,
321- ( param , i ) => validateString ( param , `params[${ i } ]` ) ) ;
322- }
323-
324- const {
325- filename = '' ,
326- columnOffset = 0 ,
327- lineOffset = 0 ,
328- cachedData = undefined ,
329- produceCachedData = false ,
330- parsingContext = undefined ,
331- contextExtensions = [ ] ,
332- importModuleDynamically,
333- } = options ;
334-
335- validateString ( filename , 'options.filename' ) ;
336- validateUint32 ( columnOffset , 'options.columnOffset' ) ;
337- validateUint32 ( lineOffset , 'options.lineOffset' ) ;
338- if ( cachedData !== undefined )
339- validateBuffer ( cachedData , 'options.cachedData' ) ;
340- validateBoolean ( produceCachedData , 'options.produceCachedData' ) ;
341- if ( parsingContext !== undefined ) {
342- if (
343- typeof parsingContext !== 'object' ||
344- parsingContext === null ||
345- ! isContext ( parsingContext )
346- ) {
347- throw new ERR_INVALID_ARG_TYPE (
348- 'options.parsingContext' ,
349- 'Context' ,
350- parsingContext
351- ) ;
352- }
353- }
354- validateArray ( contextExtensions , 'options.contextExtensions' ) ;
355- ArrayPrototypeForEach ( contextExtensions , ( extension , i ) => {
356- const name = `options.contextExtensions[${ i } ]` ;
357- validateObject ( extension , name , { nullable : true } ) ;
358- } ) ;
359-
360- const result = _compileFunction (
361- code ,
362- filename ,
363- lineOffset ,
364- columnOffset ,
365- cachedData ,
366- produceCachedData ,
367- parsingContext ,
368- contextExtensions ,
369- params
370- ) ;
371-
372- if ( produceCachedData ) {
373- result . function . cachedDataProduced = result . cachedDataProduced ;
374- }
375-
376- if ( result . cachedData ) {
377- result . function . cachedData = result . cachedData ;
378- }
379-
380- if ( importModuleDynamically !== undefined ) {
381- validateFunction ( importModuleDynamically ,
382- 'options.importModuleDynamically' ) ;
383- const { importModuleDynamicallyWrap } =
384- require ( 'internal/vm/module' ) ;
385- const { callbackMap } = internalBinding ( 'module_wrap' ) ;
386- const wrapped = importModuleDynamicallyWrap ( importModuleDynamically ) ;
387- const func = result . function ;
388- callbackMap . set ( result . cacheKey , {
389- importModuleDynamically : ( s , _k , i ) => wrapped ( s , func , i ) ,
390- } ) ;
391- }
392-
393- return result . function ;
311+ return internalCompileFunction ( code , params , options ) . function ;
394312}
395313
396314const measureMemoryModes = {
0 commit comments