|
16 | 16 | //! generating any JS glue. Any JS glue currently generated is also invalid if
|
17 | 17 | //! the module contains the wasm bindings section and it's actually respected.
|
18 | 18 |
|
19 |
| -// NB: Returning strings is weird |
20 |
| -// |
21 |
| -// This module has what is currently a pretty gross hack for dealing with |
22 |
| -// returning strings. One of the banner features of WebIDL bindings is not |
23 |
| -// requiring any language-specific glue to use wasm files and you get all sorts |
24 |
| -// of types like integers and strings by default. Note that strings are a huge |
25 |
| -// thing here. |
26 |
| -// |
27 |
| -// Dealing with *incoming* strings is easy enough in that the binding expression |
28 |
| -// has an allocator function to call and it's filled in and passed as two |
29 |
| -// pointers. Outgoing strings are a little harder, however, for two reasons: |
30 |
| -// |
31 |
| -// * One is that we need to return two values, which requires multi-value |
32 |
| -// * Another is that someone's got to free the string at some point |
33 |
| -// |
34 |
| -// Rust/wasm-bindgen don't support multi-value, and WebIDL bindings as literally |
35 |
| -// spec'd right this red hot second don't support freeing strings that we pass |
36 |
| -// out. These both have obvious fixes (supporting multi-value and extending the |
37 |
| -// bindings spec to support freeing) but we also want something working right |
38 |
| -// this red-hot second. |
39 |
| -// |
40 |
| -// To get things working we employ a terrible hack where the first bindign |
41 |
| -// expression of the result a function may indicate "use a thing that's way off |
42 |
| -// in the ether" and that's actually a sentinel for "oh ignore everything else |
43 |
| -// and the string is returned through an out-ptr as the first argument". This |
44 |
| -// manifests in all sorts of special hacks all over the place to handle this, |
45 |
| -// and it's a real bummer. |
46 |
| -// |
47 |
| -// This is in general just an explainer for the current state of things and |
48 |
| -// also a preemptive apology for writing the code to handle this in so many |
49 |
| -// places. I, like you, look forward to actually fixing this for real as the |
50 |
| -// spec continues to evolve and we implement more in wasm-bindgen. |
51 |
| - |
52 | 19 | use crate::descriptor::VectorKind;
|
53 | 20 | use crate::webidl::{AuxExportKind, AuxImport, AuxValue, JsImport, JsImportName};
|
54 | 21 | use crate::webidl::{NonstandardIncoming, NonstandardOutgoing};
|
@@ -240,26 +207,15 @@ pub fn add_section(
|
240 | 207 | name
|
241 | 208 | )
|
242 | 209 | })?;
|
243 |
| - let mut result = extract_outgoing(&binding.outgoing).with_context(|_| { |
| 210 | + let result = extract_outgoing(&binding.outgoing).with_context(|_| { |
244 | 211 | format!(
|
245 | 212 | "failed to map return value for export `{}` to standard \
|
246 | 213 | binding expressions",
|
247 | 214 | name
|
248 | 215 | )
|
249 | 216 | })?;
|
250 | 217 |
|
251 |
| - // see comment at top of this module about returning strings for what |
252 |
| - // this is doing and why it's weird |
253 |
| - if binding.return_via_outptr.is_some() { |
254 |
| - result.insert( |
255 |
| - 0, |
256 |
| - ast::OutgoingBindingExpressionAs { |
257 |
| - idx: u32::max_value(), |
258 |
| - ty: ast::WebidlScalarType::Long.into(), |
259 |
| - } |
260 |
| - .into(), |
261 |
| - ); |
262 |
| - } |
| 218 | + assert!(binding.return_via_outptr.is_none()); |
263 | 219 | let binding = section.bindings.insert(ast::ExportBinding {
|
264 | 220 | wasm_ty: binding.wasm_ty,
|
265 | 221 | webidl_ty: copy_ty(
|
@@ -293,24 +249,14 @@ pub fn add_section(
|
293 | 249 | module_name, name,
|
294 | 250 | )
|
295 | 251 | })?;
|
296 |
| - let mut result = extract_incoming(&binding.incoming).with_context(|_| { |
| 252 | + let result = extract_incoming(&binding.incoming).with_context(|_| { |
297 | 253 | format!(
|
298 | 254 | "failed to map return value of import `{}::{}` to standard \
|
299 | 255 | binding expressions",
|
300 | 256 | module_name, name,
|
301 | 257 | )
|
302 | 258 | })?;
|
303 |
| - // see comment at top of this module about returning strings for what |
304 |
| - // this is doing and why it's weird |
305 |
| - if binding.return_via_outptr.is_some() { |
306 |
| - result.insert( |
307 |
| - 0, |
308 |
| - ast::IncomingBindingExpressionGet { |
309 |
| - idx: u32::max_value(), |
310 |
| - } |
311 |
| - .into(), |
312 |
| - ); |
313 |
| - } |
| 259 | + assert!(binding.return_via_outptr.is_none()); |
314 | 260 | let binding = section.bindings.insert(ast::ImportBinding {
|
315 | 261 | wasm_ty: binding.wasm_ty,
|
316 | 262 | webidl_ty: copy_ty(
|
|
0 commit comments