mirror of
https://github.com/fluencelabs/wasm-bindgen
synced 2025-04-15 00:46:04 +00:00
Split symbol intrinsics into two
This allows using WebIDL bindings types to describe both of them instead of having a custom ABI, allowing for more direct and rich bindings eventually!
This commit is contained in:
parent
6f727d7c13
commit
cfd3e0406f
@ -103,9 +103,12 @@ intrinsics! {
|
|||||||
#[symbol = "__wbindgen_string_new"]
|
#[symbol = "__wbindgen_string_new"]
|
||||||
#[signature = fn(ref_string()) -> Anyref]
|
#[signature = fn(ref_string()) -> Anyref]
|
||||||
StringNew,
|
StringNew,
|
||||||
#[symbol = "__wbindgen_symbol_new"]
|
#[symbol = "__wbindgen_symbol_anonymous_new"]
|
||||||
#[signature = fn(I32, I32) -> Anyref]
|
#[signature = fn() -> Anyref]
|
||||||
SymbolNew,
|
SymbolAnonymousNew,
|
||||||
|
#[symbol = "__wbindgen_symbol_named_new"]
|
||||||
|
#[signature = fn(ref_string()) -> Anyref]
|
||||||
|
SymbolNamedNew,
|
||||||
#[symbol = "__wbindgen_number_get"]
|
#[symbol = "__wbindgen_number_get"]
|
||||||
#[signature = fn(ref_anyref(), F64) -> F64]
|
#[signature = fn(ref_anyref(), F64) -> F64]
|
||||||
NumberGet,
|
NumberGet,
|
||||||
|
@ -1080,15 +1080,14 @@ impl<'a, 'b> Rust2Js<'a, 'b> {
|
|||||||
self.js_arguments[0].clone()
|
self.js_arguments[0].clone()
|
||||||
}
|
}
|
||||||
|
|
||||||
Intrinsic::SymbolNew => {
|
Intrinsic::SymbolNamedNew => {
|
||||||
// FIXME: should probably have two intrinsics, one for a
|
assert_eq!(self.js_arguments.len(), 1);
|
||||||
// new anonymous symbol and one for a symbol with a string
|
format!("Symbol({})", self.js_arguments[0])
|
||||||
assert_eq!(self.js_arguments.len(), 2);
|
}
|
||||||
self.cx.expose_get_string_from_wasm()?;
|
|
||||||
format!(
|
Intrinsic::SymbolAnonymousNew => {
|
||||||
"{} === 0 ? Symbol() : Symbol(getStringFromWasm({0}, {}))",
|
assert_eq!(self.js_arguments.len(), 0);
|
||||||
self.js_arguments[0], self.js_arguments[1]
|
"Symbol()".to_string()
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Intrinsic::NumberGet => {
|
Intrinsic::NumberGet => {
|
||||||
|
14
src/lib.rs
14
src/lib.rs
@ -13,7 +13,6 @@ use core::fmt;
|
|||||||
use core::marker;
|
use core::marker;
|
||||||
use core::mem;
|
use core::mem;
|
||||||
use core::ops::{Deref, DerefMut};
|
use core::ops::{Deref, DerefMut};
|
||||||
use core::ptr;
|
|
||||||
|
|
||||||
use crate::convert::FromWasmAbi;
|
use crate::convert::FromWasmAbi;
|
||||||
|
|
||||||
@ -171,9 +170,13 @@ impl JsValue {
|
|||||||
/// JS object corresponding to the symbol created.
|
/// JS object corresponding to the symbol created.
|
||||||
pub fn symbol(description: Option<&str>) -> JsValue {
|
pub fn symbol(description: Option<&str>) -> JsValue {
|
||||||
unsafe {
|
unsafe {
|
||||||
let ptr = description.map(|s| s.as_ptr()).unwrap_or(ptr::null());
|
match description {
|
||||||
let len = description.map(|s| s.len()).unwrap_or(0);
|
Some(description) => JsValue::_new(__wbindgen_symbol_named_new(
|
||||||
JsValue::_new(__wbindgen_symbol_new(ptr, len))
|
description.as_ptr(),
|
||||||
|
description.len(),
|
||||||
|
)),
|
||||||
|
None => JsValue::_new(__wbindgen_symbol_anonymous_new()),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -488,7 +491,8 @@ externs! {
|
|||||||
|
|
||||||
fn __wbindgen_string_new(ptr: *const u8, len: usize) -> u32;
|
fn __wbindgen_string_new(ptr: *const u8, len: usize) -> u32;
|
||||||
fn __wbindgen_number_new(f: f64) -> u32;
|
fn __wbindgen_number_new(f: f64) -> u32;
|
||||||
fn __wbindgen_symbol_new(ptr: *const u8, len: usize) -> u32;
|
fn __wbindgen_symbol_named_new(ptr: *const u8, len: usize) -> u32;
|
||||||
|
fn __wbindgen_symbol_anonymous_new() -> u32;
|
||||||
|
|
||||||
fn __wbindgen_anyref_heap_live_count() -> u32;
|
fn __wbindgen_anyref_heap_live_count() -> u32;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user