File tree Expand file tree Collapse file tree 1 file changed +9
-3
lines changed
crates/cli-support/src/js Expand file tree Collapse file tree 1 file changed +9
-3
lines changed Original file line number Diff line number Diff line change @@ -1096,12 +1096,18 @@ impl<'a> Context<'a> {
1096
1096
self . expose_get_object ( ) ;
1097
1097
self . expose_get_string_from_wasm ( ) ?;
1098
1098
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`.
1099
1107
self . global ( "
1100
1108
function getCachedStringFromWasm(ptr, len) {
1101
1109
if (ptr === 0) {
1102
- if (len !== 0) {
1103
- return getObject(len);
1104
- }
1110
+ return getObject(len);
1105
1111
} else {
1106
1112
return getStringFromWasm(ptr, len);
1107
1113
}
You can’t perform that action at this time.
0 commit comments