src: fix function name lookup for inferred names · nodejs/llnode@8068cda · GitHub
Skip to content

Commit 8068cda

Browse files
committed
src: fix function name lookup for inferred names
Apparently, sometimes the FunctionName slot on ScopeInfo is filled with the empty string instead of not existing. This commit changes our heuristic to search for the first non-empty string on the first 3 slots after the last context info slot on the ScopeInfo. This should be enough to cover most (all?) cases. Also updated frame-test to add frames to the stack which V8 will infer the name instead of storing it directly, and changed this particular test to use Promises instead of callbacks. We should be able to upgrade tests to primise-based API gradually with this approach. When all tests are promisified, we can change the api on test/common.js to be promise-based instead of callback-based. PR-URL: #311 Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
1 parent 82d28c5 commit 8068cda

3 files changed

Lines changed: 131 additions & 80 deletions

File tree

src/llv8-inl.h

Lines changed: 11 additions & 2 deletions

test/fixtures/frame-scenario.js

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,29 @@ const common = require('../common');
33

44
function crasher(unused) {
55
'use strict';
6-
process.abort(); // Creates an exit frame.
7-
return this; // Force definition of |this|.
6+
this.foo = arguments; // Force adaptor frame on Node.js v12+
7+
process.abort(); // Creates an exit frame.
8+
return this; // Force definition of |this|.
89
}
910

10-
function eyecatcher() {
11+
// Force V8 to use an inferred name instead of saving the variable name as
12+
// FunctionName.
13+
let fnInferredName;
14+
fnInferredName = (() => function () {
1115
crasher(); // # args < # formal parameters inserts an adaptor frame.
16+
})();
17+
18+
function Module() {
19+
this.foo = "bar";
20+
}
21+
22+
Module.prototype.fnInferredNamePrototype = function() {
23+
fnInferredName();
24+
}
25+
26+
function fnFunctionName() {
27+
(new Module()).fnInferredNamePrototype();
1228
return this; // Force definition of |this|.
1329
}
1430

15-
eyecatcher();
31+
fnFunctionName();

test/plugin/frame-test.js

Lines changed: 100 additions & 74 deletions

0 commit comments

Comments
 (0)