[Pkg-javascript-commits] [node-stack-utils] 33/67: Filter out all Node.js internals

Bastien Roucariès rouca at moszumanska.debian.org
Thu Sep 7 09:53:04 UTC 2017


This is an automated email from the git hooks/post-receive script.

rouca pushed a commit to branch master
in repository node-stack-utils.

commit 50c1ff89c00d9093ffc333f7b45b0a02af4108d5
Author: isaacs <i at izs.me>
Date:   Fri Jan 27 23:43:52 2017 -0800

    Filter out all Node.js internals
    
    This filters out all internals from the currently running version of
    Node.js by looking at the actual list of native modules in the current
    process.
    
    Adds a way to hard-code the list of natives, for testing across
    different versions of Node with different native modules.
---
 index.js     |  20 +++++------
 test/test.js | 110 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 120 insertions(+), 10 deletions(-)

diff --git a/index.js b/index.js
index bce9695..4a7af3d 100644
--- a/index.js
+++ b/index.js
@@ -12,17 +12,17 @@ function StackUtils(opts) {
 module.exports.nodeInternals = nodeInternals;
 
 function nodeInternals() {
-	return [
-		/\(native\)$/,
-		/\(domain.js:\d+:\d+\)$/,
-		/\(events.js:\d+:\d+\)$/,
-		/\(node.js:\d+:\d+\)$/,
-		/\(timers.js:\d+:\d+\)$/,
-		/\(module.js:\d+:\d+\)$/,
-		/\(internal\/[\w_-]+\.js:\d+:\d+\)$/,
-		/\s*at node\.js:\d+:\d+?$/,
+	if (!module.exports.natives) {
+		module.exports.natives = Object.keys(process.binding('natives'));
+		module.exports.natives.push('bootstrap_node', 'node');
+	}
+
+	return module.exports.natives.map(function (n) {
+		return new RegExp('\\(' + n + '\\.js:\\d+:\\d+\\)$');
+	}).concat([
+		/\s*at (bootstrap_)?node\.js:\d+:\d+?$/,
 		/\/\.node-spawn-wrap-\w+-\w+\/node:\d+:\d+\)?$/
-	];
+	]);
 }
 
 StackUtils.prototype.clean = function (stack) {
diff --git a/test/test.js b/test/test.js
index c13ce6d..74ed664 100644
--- a/test/test.js
+++ b/test/test.js
@@ -4,6 +4,98 @@ import StackUtils from '../';
 import CaptureFixture from './fixtures/capture-fixture';
 import {join, fixtureDir} from './_utils';
 
+// Use a fixed known set of native modules, since this changes
+// depending on the version of Node we're testing with.
+StackUtils.natives = [
+	'internal/bootstrap_node',
+	'_debug_agent',
+	'_debugger',
+	'assert',
+	'buffer',
+	'child_process',
+	'console',
+	'constants',
+	'crypto',
+	'cluster',
+	'dgram',
+	'dns',
+	'domain',
+	'events',
+	'fs',
+	'http',
+	'_http_agent',
+	'_http_client',
+	'_http_common',
+	'_http_incoming',
+	'_http_outgoing',
+	'_http_server',
+	'https',
+	'_linklist',
+	'module',
+	'net',
+	'os',
+	'path',
+	'process',
+	'punycode',
+	'querystring',
+	'readline',
+	'repl',
+	'stream',
+	'_stream_readable',
+	'_stream_writable',
+	'_stream_duplex',
+	'_stream_transform',
+	'_stream_passthrough',
+	'_stream_wrap',
+	'string_decoder',
+	'sys',
+	'timers',
+	'tls',
+	'_tls_common',
+	'_tls_legacy',
+	'_tls_wrap',
+	'tty',
+	'url',
+	'util',
+	'v8',
+	'vm',
+	'zlib',
+	'internal/buffer',
+	'internal/child_process',
+	'internal/cluster',
+	'internal/freelist',
+	'internal/fs',
+	'internal/linkedlist',
+	'internal/net',
+	'internal/module',
+	'internal/process/next_tick',
+	'internal/process/promises',
+	'internal/process/stdio',
+	'internal/process/warning',
+	'internal/process',
+	'internal/readline',
+	'internal/repl',
+	'internal/socket_list',
+	'internal/url',
+	'internal/util',
+	'internal/v8_prof_polyfill',
+	'internal/v8_prof_processor',
+	'internal/streams/lazy_transform',
+	'internal/streams/BufferList',
+	'v8/tools/splaytree',
+	'v8/tools/codemap',
+	'v8/tools/consarray',
+	'v8/tools/csvparser',
+	'v8/tools/profile',
+	'v8/tools/profile_view',
+	'v8/tools/logreader',
+	'v8/tools/tickprocessor',
+	'v8/tools/SourceMap',
+	'v8/tools/tickprocessor-driver',
+	'bootstrap_node',
+	'node'
+];
+
 const LinuxStack1 = join(linuxStack1(), internalStack());
 const WindowsStack1 = join(windowsStack1(), internalStack());
 
@@ -23,11 +115,20 @@ test('clean: truncates cwd', t => {
 		'bar (foo.js:7:2)',
 		'bar (bar.js:4:2)',
 		'Object.<anonymous> (bar.js:7:1)',
+		'ontimeout (timers.js:365:14)',
+		'tryOnTimeout (timers.js:237:5)',
+		'Timer.listOnTimeout (timers.js:207:5)',
+		'_combinedTickCallback (internal/process/next_tick.js:67:7)',
+		'process._tickCallback (internal/process/next_tick.js:98:9)',
+		'Module.runMain (module.js:645:11)',
 		'Module._compile (module.js:398:26)',
 		'Object.Module._extensions..js (module.js:405:10)',
 		'Module.load (module.js:344:32)',
 		'Function.Module._load (module.js:301:12)',
 		'Function.Module.runMain (module.js:430:10)',
+		'run (bootstrap_node.js:420:7)',
+		'startup (bootstrap_node.js:139:9)',
+		'bootstrap_node.js:535:3',
 		'startup (node.js:141:18)'
 	]);
 
@@ -315,11 +416,20 @@ function windowsStack1() {
 
 function internalStack() {
 	return [
+		'    at ontimeout (timers.js:365:14)',
+		'    at tryOnTimeout (timers.js:237:5)',
+		'    at Timer.listOnTimeout (timers.js:207:5)',
+		'    at _combinedTickCallback (internal/process/next_tick.js:67:7)',
+		'    at process._tickCallback (internal/process/next_tick.js:98:9)',
+		'    at Module.runMain (module.js:645:11)',
 		'    at Module._compile (module.js:398:26)',
 		'    at Object.Module._extensions..js (module.js:405:10)',
 		'    at Module.load (module.js:344:32)',
 		'    at Function.Module._load (module.js:301:12)',
 		'    at Function.Module.runMain (module.js:430:10)',
+		'    at run (bootstrap_node.js:420:7)',
+		'    at startup (bootstrap_node.js:139:9)',
+		'    at bootstrap_node.js:535:3',
 		'    at startup (node.js:141:18)'
 	];
 }

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/node-stack-utils.git



More information about the Pkg-javascript-commits mailing list