-
Notifications
You must be signed in to change notification settings - Fork 3
Add support for argument mutation in complex argument functions #22
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
Open
simon-id
wants to merge
7
commits into
main
Choose a base branch
from
simon-id/fix_arguments_mutation
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+118
−10
Open
Changes from 4 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
449e1ea
add test for arguments mutation
simon-id 3714811
fix test
simon-id 7f7e3e0
add double wrapping for argument mutation in subscriber
simon-id a92f7ad
lint
simon-id f6253c4
lint
simon-id c91fd52
use borrow instead of clone
simon-id 427bf8a
change into_iter() to iter()
simon-id 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,30 @@ | ||
| /** | ||
| * Unless explicitly stated otherwise all files in this repository are licensed under the Apache-2.0 License. | ||
| * This product includes software developed at Datadog (https://www.datadoghq.com/). Copyright 2025 Datadog, Inc. | ||
| **/ | ||
| const assert = require('assert'); | ||
|
|
||
| function fetch_simple (url, cb) { | ||
| assert.strictEqual(this.this, 'this'); | ||
| assert.strictEqual(url, 'https://example.com'); | ||
| assert.strictEqual(cb.length, 2); | ||
| const result = cb.apply(this, ['arg1', 'arg2']); | ||
| assert.strictEqual(result, 'result'); | ||
| return 'return'; | ||
| } | ||
|
|
||
| function fetch_complex ({ url, tuple: [a = 'a', b = 'b'] }, cb, optional = 'default', ...rest) { | ||
| assert.strictEqual(this.this, 'this'); | ||
| assert.strictEqual(url, 'https://example.com'); | ||
| assert.strictEqual(a, 'a'); | ||
| assert.strictEqual(b, 'b'); | ||
| assert.strictEqual(cb.length, 2); | ||
| assert.strictEqual(optional, 'default'); | ||
| assert.deepStrictEqual(rest, []); | ||
| const result = cb.apply(this, ['arg1', 'arg2']); | ||
| assert.strictEqual(result, 'result'); | ||
| return 'return'; | ||
| } | ||
|
|
||
|
|
||
| module.exports = { fetch_simple, fetch_complex }; |
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,25 @@ | ||
| use crate::common::*; | ||
| use orchestrion_js::*; | ||
|
|
||
| #[test] | ||
| fn arguments_mutation() { | ||
| transpile_and_test( | ||
| file!(), | ||
| false, | ||
| Config::new( | ||
| vec![ | ||
| InstrumentationConfig::new( | ||
| "fetch_simple", | ||
| test_module_matcher(), | ||
| FunctionQuery::function_declaration("fetch_simple", FunctionKind::Sync), | ||
| ), | ||
| InstrumentationConfig::new( | ||
| "fetch_complex", | ||
| test_module_matcher(), | ||
| FunctionQuery::function_declaration("fetch_complex", FunctionKind::Sync), | ||
| ), | ||
| ], | ||
| None, | ||
| ), | ||
| ); | ||
| } |
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,38 @@ | ||
| /** | ||
| * Unless explicitly stated otherwise all files in this repository are licensed under the Apache-2.0 License. | ||
| * This product includes software developed at Datadog (https://www.datadoghq.com/). Copyright 2025 Datadog, Inc. | ||
| **/ | ||
| const { fetch_simple, fetch_complex } = require('./instrumented.js'); | ||
| const assert = require('assert'); | ||
| const { tracingChannel } = require('diagnostics_channel'); | ||
|
|
||
| const handler = { | ||
| start (message) { | ||
| const originalCb = message.arguments[1]; | ||
| const wrappedCb = function (a, b) { | ||
| assert.strictEqual(this.this, 'this'); | ||
| assert.strictEqual(a, 'arg1'); | ||
| assert.strictEqual(b, 'arg2'); | ||
| arguments[1] = 'arg2_mutated'; | ||
| return originalCb.apply(this, arguments); | ||
| } | ||
|
|
||
| message.arguments[1] = wrappedCb; | ||
| } | ||
| }; | ||
|
|
||
| tracingChannel('orchestrion:undici:fetch_simple').subscribe(handler); | ||
| tracingChannel('orchestrion:undici:fetch_complex').subscribe(handler); | ||
|
|
||
| assert.strictEqual(fetch_simple.length, 2); | ||
| assert.strictEqual(fetch_complex.length, 2); | ||
|
|
||
| const cb = function (a, b) { | ||
| assert.strictEqual(this.this, 'this'); | ||
| assert.strictEqual(a, 'arg1'); | ||
| assert.strictEqual(b, 'arg2_mutated'); | ||
| return 'result'; | ||
| }; | ||
|
|
||
| assert.strictEqual(fetch_simple.apply({ this: 'this' }, ['https://example.com', cb]), 'return'); | ||
| assert.strictEqual(fetch_complex.apply({ this: 'this' }, [{ url: 'https://example.com', tuple: [] }, cb]), 'return'); |
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.