mirror of
https://github.com/nodejs/node.git
synced 2025-05-12 05:36:38 +00:00

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: https://github.com/nodejs/node/pull/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>
114 lines
2.8 KiB
JavaScript
114 lines
2.8 KiB
JavaScript
'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,
|
|
};
|