Skip to content

Commit ffbdfb9

Browse files
committed
fix wasm crash
1 parent 1c34a9a commit ffbdfb9

File tree

5 files changed

+11
-3
lines changed

5 files changed

+11
-3
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ wasm-bindgen = { version = "0.2", optional = true }
2727
tsify = { version='0.5', features = ["js"], optional = true}
2828
# we need this to enable the js feature
2929
getrandom = { version = "*", features = ["wasm_js"], optional = true }
30+
log = "0.4.27"
3031

3132
[dev-dependencies]
3233
assert_cmd = "2"

src/config.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,10 +79,11 @@ pub struct InstrumentationConfig {
7979
pub channel_name: String,
8080
pub module: ModuleMatcher,
8181
pub function_query: FunctionQuery,
82+
#[tsify(optional)]
83+
#[serde(default = "InstrumentationConfig::empty_callback_config")]
8284
pub callback_config: CallbackConfig,
8385
}
8486

85-
#[allow(clippy::needless_return)]
8687
impl InstrumentationConfig {
8788
#[must_use]
8889
pub fn new(channel_name: &str, module: ModuleMatcher, function_query: FunctionQuery) -> Self {
@@ -149,4 +150,9 @@ impl InstrumentationConfig {
149150
pub fn matches(&self, module_name: &str, version: &str, file_path: &PathBuf) -> bool {
150151
self.module.matches(module_name, version, file_path)
151152
}
153+
154+
#[must_use]
155+
pub fn empty_callback_config() -> CallbackConfig {
156+
return CallbackConfig{ position: -1 }
157+
}
152158
}

src/instrumentation.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -395,8 +395,6 @@ pub fn get_script_start_index(script: &Script) -> usize {
395395
/// ```js
396396
/// return tr_ch_amp$myChannel.traceSync(__apm$traced, { arguments, self: this, moduleVersion: "1.0.0" })
397397
/// ```
398-
#[allow(clippy::bool_comparison)]
399-
#[allow(clippy::needless_return)]
400398
#[rustfmt::skip]
401399
fn construct_trace_statement(config: &InstrumentationConfig, channel_name: &str, mod_version: &str) -> Stmt {
402400
let mut ctx = "{ arguments, self: this }".to_string();

src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
#![deny(clippy::complexity)]
1414
#![deny(clippy::correctness)]
1515
#![deny(clippy::unwrap_used)]
16+
#![allow(clippy::bool_comparison)]
17+
#![allow(clippy::needless_return)]
1618

1719
/**
1820
* Unless explicitly stated otherwise all files in this repository are licensed under the Apache-2.0 License.

0 commit comments

Comments
 (0)