From c3676bc6f94dad04151830ed82eff8314f5fca32 Mon Sep 17 00:00:00 2001 From: Pauan Date: Thu, 18 Jul 2019 00:11:40 +0200 Subject: [PATCH] Removing unneeded if statement --- crates/cli-support/src/js/mod.rs | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) 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); }