Title: Fix method for getting function name for stack frames · Issue #40 · cspotcode/node-source-map-support · GitHub
Open Graph Title: Fix method for getting function name for stack frames · Issue #40 · cspotcode/node-source-map-support
X Title: Fix method for getting function name for stack frames · Issue #40 · cspotcode/node-source-map-support
Description: From jestjs/jest#12786 (comment) // hubba.test.js function BadCode() { throw new Error('noo'); } function run(fn) { fn(); } run(BadCode); compiled to: "use strict"; function BadCode() { throw new Error('noo'); } function run(fn) { fn(); ...
Open Graph Description: From jestjs/jest#12786 (comment) // hubba.test.js function BadCode() { throw new Error('noo'); } function run(fn) { fn(); } run(BadCode); compiled to: "use strict"; function BadCode() { throw new E...
X Description: From jestjs/jest#12786 (comment) // hubba.test.js function BadCode() { throw new Error('noo'); } function run(fn) { fn(); } run(BadCode); compiled to: "use strict"; function BadCo...
Opengraph URL: https://github.com/cspotcode/node-source-map-support/issues/40
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Fix method for getting function name for stack frames","articleBody":"From https://github.com/facebook/jest/pull/12786#issuecomment-1114869813\r\n\r\n```\r\n// hubba.test.js\r\nfunction BadCode() {\r\n throw new Error('noo');\r\n}\r\n\r\nfunction run(fn) {\r\n fn();\r\n}\r\n\r\nrun(BadCode);\r\n```\r\ncompiled to:\r\n```\r\n\"use strict\";\r\n\r\nfunction BadCode() {\r\n throw new Error('noo');\r\n}\r\n\r\nfunction run(fn) {\r\n fn();\r\n}\r\n\r\nrun(BadCode);\r\n//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJuYW1lcyI6WyJCYWRDb2RlIiwiRXJyb3IiLCJydW4iLCJmbiJdLCJzb3VyY2VzIjpbImh1YmJhLnRlc3QuanMiXSwic291cmNlc0NvbnRlbnQiOlsiZnVuY3Rpb24gQmFkQ29kZSgpIHtcbiAgdGhyb3cgbmV3IEVycm9yKCdub28nKTtcbn1cblxuZnVuY3Rpb24gcnVuKGZuKSB7XG4gIGZuKCk7XG59XG5cbnJ1bihCYWRDb2RlKTtcbiJdLCJtYXBwaW5ncyI6Ijs7QUFBQSxTQUFTQSxPQUFULEdBQW1CO0VBQ2pCLE1BQU0sSUFBSUMsS0FBSixDQUFVLEtBQVYsQ0FBTjtBQUNEOztBQUVELFNBQVNDLEdBQVQsQ0FBYUMsRUFBYixFQUFpQjtFQUNmQSxFQUFFO0FBQ0g7O0FBRURELEdBQUcsQ0FBQ0YsT0FBRCxDQUFIIn0=\r\n```\r\n\r\nStack trace with source-mapping is wrong:\r\n```\r\nError: noo\r\n at fn (/Users/simen/repos/jest/hubba.test.js:2:9) \u003c----- this stack frame should say `BadCode`\r\n at run (/Users/simen/repos/jest/hubba.test.js:6:3)\r\n at Object.\u003canonymous> (/Users/simen/repos/jest/hubba.test.js:9:1)\r\n```\r\n\r\nsource-map-support's algorithm for getting the name of a stack frame: it checks the location of the *next* stack frame. That is why the bug is showing us `at fn` when it should be showing us `at BadCode`. The stack frame happens within `BadCode`, but the location of the *next* stack frame is the invocation site: `fn()`\r\n\r\nWe would see the same issue with the second stack frame if we did `const runIt = run; runIt(BadCode)` Because it's checking the name at the callsite, it's not checking the invokee's name.\r\n\r\nPretty sure this is not correct and stack frames actually expose additional information we can use to get the correct answer.\r\n\r\nIn addition to `frame.getLineNumber()` and `frame.getColumnNumber()`, we have `frame.getEnclosingLineNumber()` and `frame.getEnclosingColumnNumber()` which are the location of the invoked function. For example:\r\n\r\n```\r\n// getEnclosing*Number() gives us location A\r\n// get*Number() gives us location B\r\n/*A*/function run() {}\r\n/*B*/run()\r\n```\r\n","author":{"url":"https://github.com/cspotcode","@type":"Person","name":"cspotcode"},"datePublished":"2022-05-02T18:09:12Z","url":"https://github.com/cspotcode/node-source-map-support/issues/40"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react-reconciler,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@d5750093facf |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:82720273-0251-086e-a43f-878f0d33e2b9 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | BD6C:D16D6:1217912:18E0EEE:6AFB719F |
| html-safe-nonce | 8a9dd6d17014c63c8ad5fb8b804cd94a45f4d284abad82bd9927443c898a634a |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCRDZDOkQxNkQ2OjEyMTc5MTI6MThFMEVFRTo2QUZCNzE5RiIsInZpc2l0b3JfaWQiOiIzNDg3Njg4NDM1OTk5NDA0NDQ3IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | 2a4e1333ac5a38df68542badcc9ea51477d9f983c72150ea807b0f1b4e81b495 |
| hovercard-subject-tag | issue:1223183150 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/cspotcode/node-source-map-support/40/issue_layout |
| twitter:image | https://opengraph.githubassets.com/1f61015ff32f46f9fd8c2d8a02c80360611515413a4efdf3b5118b719edefad7/cspotcode/node-source-map-support/issues/40 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/1f61015ff32f46f9fd8c2d8a02c80360611515413a4efdf3b5118b719edefad7/cspotcode/node-source-map-support/issues/40 |
| og:image:alt | From jestjs/jest#12786 (comment) // hubba.test.js function BadCode() { throw new Error('noo'); } function run(fn) { fn(); } run(BadCode); compiled to: "use strict"; function BadCode() { throw new E... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | cspotcode |
| hostname | github.com |
| expected-hostname | github.com |
| None | 0e29e7974fdda2feeaf5c891efd4b23b0734b23480232b62c7bdef13f40b5b48 |
| turbo-cache-control | no-preview |
| go-import | github.com/cspotcode/node-source-map-support git https://github.com/cspotcode/node-source-map-support.git |
| octolytics-dimension-user_id | 376504 |
| octolytics-dimension-user_login | cspotcode |
| octolytics-dimension-repository_id | 310942201 |
| octolytics-dimension-repository_nwo | cspotcode/node-source-map-support |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 310942201 |
| octolytics-dimension-repository_network_root_nwo | cspotcode/node-source-map-support |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 2e8872b770cc4d5d0cc1f2026afab747a268e2ce |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width