-
Notifications
You must be signed in to change notification settings - Fork 30k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
src,lib: retrieve parsed source map url from v8
V8 already parses the source map magic comments. Currently, only scripts and functions expose the parsed source map URLs. It is unnecessary to parse the source map magic comments again when the parsed information is available. PR-URL: #44798 Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com> Reviewed-By: Jan Krems <jan.krems@gmail.com>
- Loading branch information
1 parent
c23e023
commit 7a31ae8
Showing
10 changed files
with
282 additions
and
143 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
'use strict'; | ||
|
||
const { | ||
ArrayPrototypeForEach, | ||
} = primordials; | ||
|
||
const { | ||
compileFunction, | ||
isContext: _isContext, | ||
} = internalBinding('contextify'); | ||
const { | ||
validateArray, | ||
validateBoolean, | ||
validateBuffer, | ||
validateFunction, | ||
validateObject, | ||
validateString, | ||
validateUint32, | ||
} = require('internal/validators'); | ||
const { | ||
ERR_INVALID_ARG_TYPE, | ||
} = require('internal/errors').codes; | ||
|
||
function isContext(object) { | ||
validateObject(object, 'object', { __proto__: null, allowArray: true }); | ||
|
||
return _isContext(object); | ||
} | ||
|
||
function internalCompileFunction(code, params, options) { | ||
validateString(code, 'code'); | ||
if (params !== undefined) { | ||
validateArray(params, 'params'); | ||
ArrayPrototypeForEach(params, | ||
(param, i) => validateString(param, `params[${i}]`)); | ||
} | ||
|
||
const { | ||
filename = '', | ||
columnOffset = 0, | ||
lineOffset = 0, | ||
cachedData = undefined, | ||
produceCachedData = false, | ||
parsingContext = undefined, | ||
contextExtensions = [], | ||
importModuleDynamically, | ||
} = options; | ||
|
||
validateString(filename, 'options.filename'); | ||
validateUint32(columnOffset, 'options.columnOffset'); | ||
validateUint32(lineOffset, 'options.lineOffset'); | ||
if (cachedData !== undefined) | ||
validateBuffer(cachedData, 'options.cachedData'); | ||
validateBoolean(produceCachedData, 'options.produceCachedData'); | ||
if (parsingContext !== undefined) { | ||
if ( | ||
typeof parsingContext !== 'object' || | ||
parsingContext === null || | ||
!isContext(parsingContext) | ||
) { | ||
throw new ERR_INVALID_ARG_TYPE( | ||
'options.parsingContext', | ||
'Context', | ||
parsingContext | ||
); | ||
} | ||
} | ||
validateArray(contextExtensions, 'options.contextExtensions'); | ||
ArrayPrototypeForEach(contextExtensions, (extension, i) => { | ||
const name = `options.contextExtensions[${i}]`; | ||
validateObject(extension, name, { __proto__: null, nullable: true }); | ||
}); | ||
|
||
const result = compileFunction( | ||
code, | ||
filename, | ||
lineOffset, | ||
columnOffset, | ||
cachedData, | ||
produceCachedData, | ||
parsingContext, | ||
contextExtensions, | ||
params | ||
); | ||
|
||
if (produceCachedData) { | ||
result.function.cachedDataProduced = result.cachedDataProduced; | ||
} | ||
|
||
if (result.cachedData) { | ||
result.function.cachedData = result.cachedData; | ||
} | ||
|
||
if (importModuleDynamically !== undefined) { | ||
validateFunction(importModuleDynamically, | ||
'options.importModuleDynamically'); | ||
const { importModuleDynamicallyWrap } = | ||
require('internal/vm/module'); | ||
const { callbackMap } = internalBinding('module_wrap'); | ||
const wrapped = importModuleDynamicallyWrap(importModuleDynamically); | ||
const func = result.function; | ||
callbackMap.set(result.cacheKey, { | ||
importModuleDynamically: (s, _k, i) => wrapped(s, func, i), | ||
}); | ||
} | ||
|
||
return result; | ||
} | ||
|
||
module.exports = { | ||
internalCompileFunction, | ||
isContext, | ||
}; |
Oops, something went wrong.