diff --git a/crates/cli-support/src/js/mod.rs b/crates/cli-support/src/js/mod.rs index ce055b36..6fcfcf47 100644 --- a/crates/cli-support/src/js/mod.rs +++ b/crates/cli-support/src/js/mod.rs @@ -1096,12 +1096,18 @@ impl<'a> Context<'a> { self.expose_get_object(); self.expose_get_string_from_wasm()?; + // This has support for both `&str` and `Option<&str>`. + // + // If `ptr` is not `0` then we know that it's a `&str` or `Some(&str)`, so we just decode it. + // + // If `ptr` is `0` then the `len` is a pointer to the cached `JsValue`, so we return that. + // + // If `ptr` and `len` are both `0` then that means it's `None`, in that case we rely upon + // the fact that `getObject(0)` is guaranteed to be `undefined`. self.global(" function getCachedStringFromWasm(ptr, len) { if (ptr === 0) { - if (len !== 0) { - return getObject(len); - } + return getObject(len); } else { return getStringFromWasm(ptr, len); }