Skip to content

Commit c3676bc

Browse files
committed
Removing unneeded if statement
1 parent 8572255 commit c3676bc

File tree

1 file changed

+9
-3
lines changed
  • crates/cli-support/src/js

1 file changed

+9
-3
lines changed

crates/cli-support/src/js/mod.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1096,12 +1096,18 @@ impl<'a> Context<'a> {
10961096
self.expose_get_object();
10971097
self.expose_get_string_from_wasm()?;
10981098

1099+
// This has support for both `&str` and `Option<&str>`.
1100+
//
1101+
// If `ptr` is not `0` then we know that it's a `&str` or `Some(&str)`, so we just decode it.
1102+
//
1103+
// If `ptr` is `0` then the `len` is a pointer to the cached `JsValue`, so we return that.
1104+
//
1105+
// If `ptr` and `len` are both `0` then that means it's `None`, in that case we rely upon
1106+
// the fact that `getObject(0)` is guaranteed to be `undefined`.
10991107
self.global("
11001108
function getCachedStringFromWasm(ptr, len) {
11011109
if (ptr === 0) {
1102-
if (len !== 0) {
1103-
return getObject(len);
1104-
}
1110+
return getObject(len);
11051111
} else {
11061112
return getStringFromWasm(ptr, len);
11071113
}

0 commit comments

Comments
 (0)