mirror of
https://github.com/nodejs/node.git
synced 2026-11-24 21:50:36 -05:00
SourceMap kept one six-element array per mapping segment. Bundled applications have millions of segments, and with --enable-source-maps a parsed map lives for the life of the process: a 63 MB source map with 2.9 million segments retained about 290 MiB of heap. Store the segments in a single Int32Array, six fields per segment, and resolve source URLs and names through per-map tables. Segments are counted before parsing so storage is allocated once, and sorting is skipped when the mappings are already in order. The public API and the objects returned by findEntry() and findOrigin() are unchanged. Signed-off-by: Jacky Zhao <j.zhao2k19@gmail.com> PR-URL: https://github.com/nodejs/node/pull/66261 Reviewed-By: Chengzhong Wu <legendecas@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
43 lines
1.0 KiB
JavaScript
43 lines
1.0 KiB
JavaScript
'use strict';
|
|
require('../common');
|
|
const assert = require('assert');
|
|
const { SourceMap } = require('node:module');
|
|
|
|
// Section offsets are stored in an Int32Array, so they must be validated
|
|
// instead of being implicitly coerced.
|
|
function sectionedMap(offset) {
|
|
return {
|
|
version: 3,
|
|
sections: [{
|
|
offset,
|
|
map: {
|
|
version: 3,
|
|
sources: ['a.js'],
|
|
names: [],
|
|
mappings: 'AAAA',
|
|
},
|
|
}],
|
|
};
|
|
}
|
|
|
|
{
|
|
const sm = new SourceMap(sectionedMap({ line: 1, column: 2 }));
|
|
assert.deepStrictEqual(sm.findEntry(1, 2), {
|
|
generatedLine: 1,
|
|
generatedColumn: 2,
|
|
originalSource: 'a.js',
|
|
originalLine: 0,
|
|
originalColumn: 0,
|
|
name: undefined,
|
|
});
|
|
}
|
|
|
|
for (const value of ['1', 1.5, 2 ** 31, null, {}]) {
|
|
assert.throws(() => new SourceMap(sectionedMap({ line: value, column: 0 })), {
|
|
code: /^ERR_(INVALID_ARG_TYPE|OUT_OF_RANGE)$/,
|
|
});
|
|
assert.throws(() => new SourceMap(sectionedMap({ line: 0, column: value })), {
|
|
code: /^ERR_(INVALID_ARG_TYPE|OUT_OF_RANGE)$/,
|
|
});
|
|
}
|