-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
lib,src: add source map support for global eval
Dynamic sources with FunctionConstructor is not supported yet as V8 prepends lines to the sources which makes the stack line number incorrect. PR-URL: nodejs/node#43428 Refs: nodejs/node#43047 Reviewed-By: Ben Coe <bencoe@gmail.com>
- Loading branch information
1 parent
0b126a6
commit 710c66d
Showing
11 changed files
with
193 additions
and
19 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
'use strict'; | ||
|
||
const common = require('../common.js'); | ||
|
||
const bench = common.createBenchmark(main, { | ||
method: ['without-sourcemap', 'sourcemap'], | ||
n: [1e6], | ||
}); | ||
|
||
const sourceWithoutSourceMap = ` | ||
'use strict'; | ||
(function() { | ||
let a = 1; | ||
for (let i = 0; i < 1000; i++) { | ||
a++; | ||
} | ||
return a; | ||
})(); | ||
`; | ||
const sourceWithSourceMap = ` | ||
${sourceWithoutSourceMap} | ||
//# sourceMappingURL=https://ci.nodejs.org/405 | ||
`; | ||
|
||
function evalN(n, source) { | ||
bench.start(); | ||
for (let i = 0; i < n; i++) { | ||
eval(source); | ||
} | ||
bench.end(n); | ||
} | ||
|
||
function main({ n, method }) { | ||
switch (method) { | ||
case 'without-sourcemap': | ||
process.setSourceMapsEnabled(false); | ||
evalN(n, sourceWithoutSourceMap); | ||
break; | ||
case 'sourcemap': | ||
process.setSourceMapsEnabled(true); | ||
evalN(n, sourceWithSourceMap); | ||
break; | ||
default: | ||
throw new Error(`Unexpected method "${method}"`); | ||
} | ||
} |
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
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,8 @@ | ||
// Flags: --enable-source-maps | ||
|
||
'use strict'; | ||
require('../common'); | ||
const fs = require('fs'); | ||
|
||
const content = fs.readFileSync(require.resolve('../fixtures/source-map/tabs.js'), 'utf8'); | ||
eval(content); |
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,10 @@ | ||
ReferenceError: alert is not defined | ||
at Object.eval (*tabs.coffee:26:2) | ||
at eval (*tabs.coffee:1:14) | ||
at Object.<anonymous> (*source_map_eval.js:8:1) | ||
at Module._compile (node:internal/modules/cjs/loader:*) | ||
at Object.Module._extensions..js (node:internal/modules/cjs/loader:*) | ||
at Module.load (node:internal/modules/cjs/loader:*) | ||
at Function.Module._load (node:internal/modules/cjs/loader:*) | ||
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:*) | ||
at node:internal/main/run_main_module:* |