mirror of
https://github.com/fluencelabs/wasm-bindgen
synced 2025-04-01 18:01:06 +00:00
Fixing TypeScript types for cached strings
This commit is contained in:
parent
554ef90035
commit
10ab4cbc18
@ -134,12 +134,18 @@ impl<'a, 'b> Outgoing<'a, 'b> {
|
|||||||
offset,
|
offset,
|
||||||
length,
|
length,
|
||||||
owned,
|
owned,
|
||||||
|
optional,
|
||||||
} => {
|
} => {
|
||||||
let ptr = self.arg(*offset);
|
let ptr = self.arg(*offset);
|
||||||
let len = self.arg(*length);
|
let len = self.arg(*length);
|
||||||
let tmp = self.js.tmp();
|
let tmp = self.js.tmp();
|
||||||
|
|
||||||
self.js.typescript_optional("string");
|
if *optional {
|
||||||
|
self.js.typescript_optional("string");
|
||||||
|
} else {
|
||||||
|
self.js.typescript_required("string");
|
||||||
|
}
|
||||||
|
|
||||||
self.cx.expose_get_cached_string_from_wasm()?;
|
self.cx.expose_get_cached_string_from_wasm()?;
|
||||||
|
|
||||||
self.js.prelude(&format!("const v{} = getCachedStringFromWasm({}, {});", tmp, ptr, len));
|
self.js.prelude(&format!("const v{} = getCachedStringFromWasm({}, {});", tmp, ptr, len));
|
||||||
|
@ -69,6 +69,7 @@ pub enum NonstandardOutgoing {
|
|||||||
offset: u32,
|
offset: u32,
|
||||||
length: u32,
|
length: u32,
|
||||||
owned: bool,
|
owned: bool,
|
||||||
|
optional: bool,
|
||||||
},
|
},
|
||||||
|
|
||||||
/// A `&[u64]` or `&[i64]` is being passed to JS, and the 64-bit sizes here
|
/// A `&[u64]` or `&[i64]` is being passed to JS, and the 64-bit sizes here
|
||||||
@ -251,7 +252,7 @@ impl OutgoingBuilder<'_> {
|
|||||||
Descriptor::Ref(d) => self.process_ref(false, d)?,
|
Descriptor::Ref(d) => self.process_ref(false, d)?,
|
||||||
Descriptor::RefMut(d) => self.process_ref(true, d)?,
|
Descriptor::RefMut(d) => self.process_ref(true, d)?,
|
||||||
|
|
||||||
Descriptor::CachedString => self.cached_string(true),
|
Descriptor::CachedString => self.cached_string(false, true),
|
||||||
|
|
||||||
Descriptor::Vector(_) | Descriptor::String => {
|
Descriptor::Vector(_) | Descriptor::String => {
|
||||||
let kind = arg.vector_kind().ok_or_else(|| {
|
let kind = arg.vector_kind().ok_or_else(|| {
|
||||||
@ -294,7 +295,7 @@ impl OutgoingBuilder<'_> {
|
|||||||
self.bindings
|
self.bindings
|
||||||
.push(NonstandardOutgoing::BorrowedAnyref { idx });
|
.push(NonstandardOutgoing::BorrowedAnyref { idx });
|
||||||
}
|
}
|
||||||
Descriptor::CachedString => self.cached_string(false),
|
Descriptor::CachedString => self.cached_string(false, false),
|
||||||
Descriptor::Slice(_) | Descriptor::String => {
|
Descriptor::Slice(_) | Descriptor::String => {
|
||||||
use wasm_webidl_bindings::ast::WebidlScalarType::*;
|
use wasm_webidl_bindings::ast::WebidlScalarType::*;
|
||||||
|
|
||||||
@ -437,7 +438,7 @@ impl OutgoingBuilder<'_> {
|
|||||||
Descriptor::Ref(d) => self.process_option_ref(false, d)?,
|
Descriptor::Ref(d) => self.process_option_ref(false, d)?,
|
||||||
Descriptor::RefMut(d) => self.process_option_ref(true, d)?,
|
Descriptor::RefMut(d) => self.process_option_ref(true, d)?,
|
||||||
|
|
||||||
Descriptor::CachedString => self.cached_string(true),
|
Descriptor::CachedString => self.cached_string(true, true),
|
||||||
|
|
||||||
Descriptor::String | Descriptor::Vector(_) => {
|
Descriptor::String | Descriptor::Vector(_) => {
|
||||||
let kind = arg.vector_kind().ok_or_else(|| {
|
let kind = arg.vector_kind().ok_or_else(|| {
|
||||||
@ -472,7 +473,7 @@ impl OutgoingBuilder<'_> {
|
|||||||
self.bindings
|
self.bindings
|
||||||
.push(NonstandardOutgoing::BorrowedAnyref { idx });
|
.push(NonstandardOutgoing::BorrowedAnyref { idx });
|
||||||
}
|
}
|
||||||
Descriptor::CachedString => self.cached_string(false),
|
Descriptor::CachedString => self.cached_string(true, false),
|
||||||
Descriptor::String | Descriptor::Slice(_) => {
|
Descriptor::String | Descriptor::Slice(_) => {
|
||||||
let kind = arg.vector_kind().ok_or_else(|| {
|
let kind = arg.vector_kind().ok_or_else(|| {
|
||||||
format_err!(
|
format_err!(
|
||||||
@ -523,7 +524,7 @@ impl OutgoingBuilder<'_> {
|
|||||||
.push(NonstandardOutgoing::Standard(binding.into()));
|
.push(NonstandardOutgoing::Standard(binding.into()));
|
||||||
}
|
}
|
||||||
|
|
||||||
fn cached_string(&mut self, owned: bool) {
|
fn cached_string(&mut self, optional: bool, owned: bool) {
|
||||||
let offset = self.push_wasm(ValType::I32);
|
let offset = self.push_wasm(ValType::I32);
|
||||||
let length = self.push_wasm(ValType::I32);
|
let length = self.push_wasm(ValType::I32);
|
||||||
self.webidl.push(ast::WebidlScalarType::DomString);
|
self.webidl.push(ast::WebidlScalarType::DomString);
|
||||||
@ -531,6 +532,7 @@ impl OutgoingBuilder<'_> {
|
|||||||
offset,
|
offset,
|
||||||
length,
|
length,
|
||||||
owned,
|
owned,
|
||||||
|
optional,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user