mirror of
https://github.com/fluencelabs/wasm-bindgen
synced 2025-04-11 22:56:06 +00:00
More simplifications
This commit is contained in:
parent
1e4cac9c95
commit
1723e9d024
@ -60,7 +60,11 @@ pub enum NonstandardOutgoing {
|
|||||||
kind: VectorKind,
|
kind: VectorKind,
|
||||||
},
|
},
|
||||||
|
|
||||||
|
/// A Rust String (or &str) which might be cached, and might be `None`.
|
||||||
///
|
///
|
||||||
|
/// If `offset` is 0 then it is cached, and the cached JsValue's index is in `length`.
|
||||||
|
///
|
||||||
|
/// If `offset` and `length` are both 0, then it is `None`.
|
||||||
CachedString {
|
CachedString {
|
||||||
offset: u32,
|
offset: u32,
|
||||||
length: u32,
|
length: u32,
|
||||||
@ -247,16 +251,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 => {
|
Descriptor::CachedString => self.cached_string(true),
|
||||||
let offset = self.push_wasm(ValType::I32);
|
|
||||||
let length = self.push_wasm(ValType::I32);
|
|
||||||
self.webidl.push(ast::WebidlScalarType::Any);
|
|
||||||
self.bindings.push(NonstandardOutgoing::CachedString {
|
|
||||||
offset,
|
|
||||||
length,
|
|
||||||
owned: 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(|| {
|
||||||
@ -299,16 +294,7 @@ impl OutgoingBuilder<'_> {
|
|||||||
self.bindings
|
self.bindings
|
||||||
.push(NonstandardOutgoing::BorrowedAnyref { idx });
|
.push(NonstandardOutgoing::BorrowedAnyref { idx });
|
||||||
}
|
}
|
||||||
Descriptor::CachedString => {
|
Descriptor::CachedString => self.cached_string(false),
|
||||||
let offset = self.push_wasm(ValType::I32);
|
|
||||||
let length = self.push_wasm(ValType::I32);
|
|
||||||
self.webidl.push(ast::WebidlScalarType::DomString);
|
|
||||||
self.bindings.push(NonstandardOutgoing::CachedString {
|
|
||||||
offset,
|
|
||||||
length,
|
|
||||||
owned: false,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
Descriptor::Slice(_) | Descriptor::String => {
|
Descriptor::Slice(_) | Descriptor::String => {
|
||||||
use wasm_webidl_bindings::ast::WebidlScalarType::*;
|
use wasm_webidl_bindings::ast::WebidlScalarType::*;
|
||||||
|
|
||||||
@ -451,16 +437,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 => {
|
Descriptor::CachedString => self.cached_string(true),
|
||||||
let offset = self.push_wasm(ValType::I32);
|
|
||||||
let length = self.push_wasm(ValType::I32);
|
|
||||||
self.webidl.push(ast::WebidlScalarType::DomString);
|
|
||||||
self.bindings.push(NonstandardOutgoing::CachedString {
|
|
||||||
offset,
|
|
||||||
length,
|
|
||||||
owned: 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(|| {
|
||||||
@ -495,16 +472,7 @@ impl OutgoingBuilder<'_> {
|
|||||||
self.bindings
|
self.bindings
|
||||||
.push(NonstandardOutgoing::BorrowedAnyref { idx });
|
.push(NonstandardOutgoing::BorrowedAnyref { idx });
|
||||||
}
|
}
|
||||||
Descriptor::CachedString => {
|
Descriptor::CachedString => self.cached_string(false),
|
||||||
let offset = self.push_wasm(ValType::I32);
|
|
||||||
let length = self.push_wasm(ValType::I32);
|
|
||||||
self.webidl.push(ast::WebidlScalarType::DomString);
|
|
||||||
self.bindings.push(NonstandardOutgoing::CachedString {
|
|
||||||
offset,
|
|
||||||
length,
|
|
||||||
owned: 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!(
|
||||||
@ -555,6 +523,17 @@ impl OutgoingBuilder<'_> {
|
|||||||
.push(NonstandardOutgoing::Standard(binding.into()));
|
.push(NonstandardOutgoing::Standard(binding.into()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn cached_string(&mut self, owned: bool) {
|
||||||
|
let offset = self.push_wasm(ValType::I32);
|
||||||
|
let length = self.push_wasm(ValType::I32);
|
||||||
|
self.webidl.push(ast::WebidlScalarType::DomString);
|
||||||
|
self.bindings.push(NonstandardOutgoing::CachedString {
|
||||||
|
offset,
|
||||||
|
length,
|
||||||
|
owned,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
fn option_native(&mut self, signed: bool, ty: ValType) {
|
fn option_native(&mut self, signed: bool, ty: ValType) {
|
||||||
let present = self.push_wasm(ValType::I32);
|
let present = self.push_wasm(ValType::I32);
|
||||||
let val = self.push_wasm(ty);
|
let val = self.push_wasm(ty);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user