-
Notifications
You must be signed in to change notification settings - Fork 7
fix: Incorrect function type breaking arg length and generators #70
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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,20 @@ | ||
| 'use strict' | ||
|
|
||
| // Two methods assigned to `this` inside a constructor that takes 2 arguments. | ||
| // The arrow function doesn't bind its own `arguments`, so `arguments.length` | ||
| // inside it refers to the constructor's argument count (2), not the call-site | ||
| // count (1). The regular function binds its own `arguments`, so it sees the | ||
| // call-site count (1). Instrumentation must not change either binding. | ||
| // Both functions declare extra parameters to ensure parameter count does not | ||
| // affect the reported arguments length. | ||
| function Connection (host, port) { | ||
| this.fetchArrow = async (sql, extra1, extra2) => { | ||
| return arguments.length | ||
| } | ||
|
|
||
| this.fetchFunction = async function (sql, extra1, extra2) { | ||
| return arguments.length | ||
| } | ||
| } | ||
|
|
||
| module.exports = { Connection } | ||
This file contains hidden or 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,22 @@ | ||
| 'use strict' | ||
|
|
||
| const { Connection } = require('./instrumented.js') | ||
| const { assert, getContext } = require('../common/preamble.js') | ||
|
|
||
| const contextArrow = getContext('orchestrion:undici:Connection_fetchArrow') | ||
| const contextFn = getContext('orchestrion:undici:Connection_fetchFunction') | ||
|
|
||
| ;(async () => { | ||
| const conn = new Connection('host', 'port') | ||
|
|
||
| // Arrow: arguments.length must still be 2 (constructor args), not 1 (call-site). | ||
| const arrowResult = await conn.fetchArrow('SELECT 1') | ||
| assert.strictEqual(arrowResult, 2) | ||
|
|
||
| // Regular function: arguments.length must be 1 (call-site args). | ||
| const fnResult = await conn.fetchFunction('SELECT 1') | ||
| assert.strictEqual(fnResult, 1) | ||
|
|
||
| assert.deepStrictEqual(contextArrow, { start: true, end: true, asyncStart: 2, asyncEnd: 2 }) | ||
| assert.deepStrictEqual(contextFn, { start: true, end: true, asyncStart: 1, asyncEnd: 1 }) | ||
| })() |
This file contains hidden or 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,11 @@ | ||
| 'use strict' | ||
|
|
||
| function Connection () { | ||
| this.generate = function * () { | ||
| yield 1 | ||
| yield 2 | ||
| yield 3 | ||
| } | ||
| } | ||
|
|
||
| module.exports = { Connection } |
This file contains hidden or 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,16 @@ | ||
| 'use strict' | ||
|
|
||
| const { Connection } = require('./instrumented.js') | ||
| const { assert, getContext } = require('../common/preamble.js') | ||
| const context = getContext('orchestrion:undici:Connection_generate') | ||
|
|
||
| const conn = new Connection() | ||
| const iter = conn.generate() | ||
|
|
||
| const results = [] | ||
| for (const val of iter) { | ||
| results.push(val) | ||
| } | ||
|
|
||
| assert.strictEqual(context.start, true) | ||
| assert.deepStrictEqual(results, [1, 2, 3]) |
This file contains hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't the count3?I see that the
1is from thetest.jsusage of the methods. Definitely confusing without knowing what the test file looks like.