mirror of
https://github.com/fluencelabs/wasm-bindgen
synced 2025-08-01 04:21:55 +00:00
Merge branch 'master' into js_date
This commit is contained in:
@@ -1,14 +1,14 @@
|
||||
//! This is mostly an internal module, no stability guarantees are provided. Use
|
||||
//! at your own risk.
|
||||
|
||||
use core::char;
|
||||
use core::mem::{self, ManuallyDrop};
|
||||
use core::ops::{Deref, DerefMut};
|
||||
use core::slice;
|
||||
use core::str;
|
||||
use core::char;
|
||||
|
||||
use {JsValue, throw};
|
||||
use describe::*;
|
||||
use {throw, JsValue};
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
use std::prelude::v1::*;
|
||||
@@ -59,7 +59,7 @@ pub trait RefFromWasmAbi: WasmDescribe {
|
||||
/// invocation of the function that has an `&Self` parameter. This is
|
||||
/// required to ensure that the lifetimes don't persist beyond one function
|
||||
/// call, and so that they remain anonymous.
|
||||
type Anchor: Deref<Target=Self>;
|
||||
type Anchor: Deref<Target = Self>;
|
||||
|
||||
/// Recover a `Self::Anchor` from `Self::Abi`.
|
||||
///
|
||||
@@ -71,7 +71,7 @@ pub trait RefFromWasmAbi: WasmDescribe {
|
||||
|
||||
pub trait RefMutFromWasmAbi: WasmDescribe {
|
||||
type Abi: WasmAbi;
|
||||
type Anchor: DerefMut<Target=Self>;
|
||||
type Anchor: DerefMut<Target = Self>;
|
||||
unsafe fn ref_mut_from_abi(js: Self::Abi, extra: &mut Stack) -> Self::Anchor;
|
||||
}
|
||||
|
||||
@@ -159,18 +159,24 @@ as_u32!(i8 u8 i16 u16 isize usize);
|
||||
impl IntoWasmAbi for bool {
|
||||
type Abi = u32;
|
||||
|
||||
fn into_abi(self, _extra: &mut Stack) -> u32 { self as u32 }
|
||||
fn into_abi(self, _extra: &mut Stack) -> u32 {
|
||||
self as u32
|
||||
}
|
||||
}
|
||||
|
||||
impl FromWasmAbi for bool {
|
||||
type Abi = u32;
|
||||
|
||||
unsafe fn from_abi(js: u32, _extra: &mut Stack) -> bool { js != 0 }
|
||||
unsafe fn from_abi(js: u32, _extra: &mut Stack) -> bool {
|
||||
js != 0
|
||||
}
|
||||
}
|
||||
|
||||
impl IntoWasmAbi for char {
|
||||
type Abi = u32;
|
||||
fn into_abi(self, _extra: &mut Stack) -> u32 { self as u32 }
|
||||
fn into_abi(self, _extra: &mut Stack) -> u32 {
|
||||
self as u32
|
||||
}
|
||||
}
|
||||
|
||||
impl FromWasmAbi for char {
|
||||
@@ -183,7 +189,9 @@ impl FromWasmAbi for char {
|
||||
impl<T> IntoWasmAbi for *const T {
|
||||
type Abi = u32;
|
||||
|
||||
fn into_abi(self, _extra: &mut Stack) -> u32 { self as u32 }
|
||||
fn into_abi(self, _extra: &mut Stack) -> u32 {
|
||||
self as u32
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> FromWasmAbi for *const T {
|
||||
@@ -197,7 +205,9 @@ impl<T> FromWasmAbi for *const T {
|
||||
impl<T> IntoWasmAbi for *mut T {
|
||||
type Abi = u32;
|
||||
|
||||
fn into_abi(self, _extra: &mut Stack) -> u32 { self as u32 }
|
||||
fn into_abi(self, _extra: &mut Stack) -> u32 {
|
||||
self as u32
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> FromWasmAbi for *mut T {
|
||||
@@ -343,7 +353,7 @@ impl IntoWasmAbi for JsValue {
|
||||
fn into_abi(self, _extra: &mut Stack) -> u32 {
|
||||
let ret = self.idx;
|
||||
mem::forget(self);
|
||||
return ret
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -397,7 +407,9 @@ if_std! {
|
||||
}
|
||||
}
|
||||
|
||||
pub struct GlobalStack { next: usize }
|
||||
pub struct GlobalStack {
|
||||
next: usize,
|
||||
}
|
||||
|
||||
const GLOBAL_STACK_CAP: usize = 16;
|
||||
static mut GLOBAL_STACK: [u32; GLOBAL_STACK_CAP] = [0; GLOBAL_STACK_CAP];
|
||||
@@ -429,7 +441,7 @@ impl Stack for GlobalStack {
|
||||
|
||||
#[doc(hidden)]
|
||||
#[no_mangle]
|
||||
pub unsafe extern fn __wbindgen_global_argument_ptr() -> *mut u32 {
|
||||
pub unsafe extern "C" fn __wbindgen_global_argument_ptr() -> *mut u32 {
|
||||
GLOBAL_STACK.as_mut_ptr()
|
||||
}
|
||||
|
||||
|
@@ -41,9 +41,7 @@ tys! {
|
||||
}
|
||||
|
||||
pub fn inform(a: u32) {
|
||||
unsafe {
|
||||
super::__wbindgen_describe(a)
|
||||
}
|
||||
unsafe { super::__wbindgen_describe(a) }
|
||||
}
|
||||
|
||||
pub trait WasmDescribe {
|
||||
@@ -78,11 +76,15 @@ simple! {
|
||||
}
|
||||
|
||||
impl<T> WasmDescribe for *const T {
|
||||
fn describe() { inform(I32) }
|
||||
fn describe() {
|
||||
inform(I32)
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> WasmDescribe for *mut T {
|
||||
fn describe() { inform(I32) }
|
||||
fn describe() {
|
||||
inform(I32)
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: WasmDescribe> WasmDescribe for [T] {
|
||||
@@ -127,7 +129,9 @@ if_std! {
|
||||
}
|
||||
}
|
||||
|
||||
fn _cnt<T: WasmDescribe>() -> u32 { 1 }
|
||||
fn _cnt<T: WasmDescribe>() -> u32 {
|
||||
1
|
||||
}
|
||||
|
||||
macro_rules! doit {
|
||||
($( ($($var:ident)*))*) => ($(
|
||||
|
507
src/js.rs
507
src/js.rs
@@ -35,12 +35,13 @@ if_std! {
|
||||
// * If a function or method can throw an exception, make it catchable by adding
|
||||
// `#[wasm_bindgen(catch)]`.
|
||||
//
|
||||
// * Add a new `#[test]` to the `tests/all/js_globals.rs` file. If the imported
|
||||
// function or method can throw an exception, make sure to also add test
|
||||
// coverage for that case.
|
||||
// * Add a new `#[test]` into the appropriate file in the
|
||||
// `tests/all/js_globals/` directory. If the imported function or
|
||||
// method can throw an exception, make sure to also add test coverage
|
||||
// for that case.
|
||||
|
||||
#[wasm_bindgen]
|
||||
extern {
|
||||
extern "C" {
|
||||
/// The `decodeURI()` function decodes a Uniform Resource Identifier (URI)
|
||||
/// previously created by `encodeURI` or by a similar routine.
|
||||
///
|
||||
@@ -48,6 +49,13 @@ extern {
|
||||
#[wasm_bindgen(catch, js_name = decodeURI)]
|
||||
pub fn decode_uri(encoded: &str) -> Result<JsString, JsValue>;
|
||||
|
||||
/// The decodeURIComponent() function decodes a Uniform Resource Identifier (URI) component
|
||||
/// previously created by encodeURIComponent or by a similar routine.
|
||||
///
|
||||
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/decodeURIComponent
|
||||
#[wasm_bindgen(catch, js_name = decodeURIComponent)]
|
||||
pub fn decode_uri_component(encoded: &str) -> Result<JsString, JsValue>;
|
||||
|
||||
/// The `encodeURI()` function encodes a Uniform Resource Identifier (URI)
|
||||
/// by replacing each instance of certain characters by one, two, three, or
|
||||
/// four escape sequences representing the UTF-8 encoding of the character
|
||||
@@ -58,6 +66,15 @@ extern {
|
||||
#[wasm_bindgen(js_name = encodeURI)]
|
||||
pub fn encode_uri(decoded: &str) -> JsString;
|
||||
|
||||
/// The encodeURIComponent() function encodes a Uniform Resource Identifier (URI) component
|
||||
/// by replacing each instance of certain characters by one, two, three, or four escape sequences
|
||||
/// representing the UTF-8 encoding of the character
|
||||
/// (will only be four escape sequences for characters composed of two "surrogate" characters).
|
||||
///
|
||||
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/encodeURIComponent
|
||||
#[wasm_bindgen(js_name = encodeURIComponent)]
|
||||
pub fn encode_uri_component(decoded: &str) -> JsString;
|
||||
|
||||
/// The `eval()` function evaluates JavaScript code represented as a string.
|
||||
///
|
||||
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/eval
|
||||
@@ -67,7 +84,7 @@ extern {
|
||||
|
||||
// UInt8Array
|
||||
#[wasm_bindgen]
|
||||
extern {
|
||||
extern "C" {
|
||||
pub type Uint8Array;
|
||||
|
||||
/// The `Uint8Array()` constructor creates an array of unsigned 8-bit integers.
|
||||
@@ -86,7 +103,7 @@ extern {
|
||||
|
||||
// Array
|
||||
#[wasm_bindgen]
|
||||
extern {
|
||||
extern "C" {
|
||||
pub type Array;
|
||||
|
||||
/// The copyWithin() method shallow copies part of an array to another
|
||||
@@ -103,6 +120,13 @@ extern {
|
||||
#[wasm_bindgen(method)]
|
||||
pub fn concat(this: &Array, array: &Array) -> Array;
|
||||
|
||||
/// The every() method tests whether all elements in the array pass the test
|
||||
/// implemented by the provided function.
|
||||
///
|
||||
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/every
|
||||
#[wasm_bindgen(method)]
|
||||
pub fn every(this: &Array, predicate: &mut FnMut(JsValue, u32, Array) -> bool) -> bool;
|
||||
|
||||
/// The fill() method fills all the elements of an array from a start index
|
||||
/// to an end index with a static value. The end index is not included.
|
||||
///
|
||||
@@ -197,6 +221,13 @@ extern {
|
||||
#[wasm_bindgen(method)]
|
||||
pub fn slice(this: &Array, start: u32, end: u32) -> Array;
|
||||
|
||||
/// The some() method tests whether at least one element in the array passes the test implemented
|
||||
/// by the provided function.
|
||||
/// Note: This method returns false for any condition put on an empty array.
|
||||
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/some
|
||||
#[wasm_bindgen(method)]
|
||||
pub fn some(this: &Array, predicate: &mut FnMut(JsValue) -> bool) -> bool;
|
||||
|
||||
/// The sort() method sorts the elements of an array in place and returns
|
||||
/// the array. The sort is not necessarily stable. The default sort
|
||||
/// order is according to string Unicode code points.
|
||||
@@ -225,7 +256,7 @@ extern {
|
||||
|
||||
// Array Iterator
|
||||
#[wasm_bindgen]
|
||||
extern {
|
||||
extern "C" {
|
||||
pub type ArrayIterator;
|
||||
|
||||
/// The keys() method returns a new Array Iterator object that contains the
|
||||
@@ -243,18 +274,80 @@ extern {
|
||||
pub fn entries(this: &Array) -> ArrayIterator;
|
||||
}
|
||||
|
||||
// Boolean
|
||||
#[wasm_bindgen]
|
||||
extern "C" {
|
||||
pub type Boolean;
|
||||
|
||||
/// The `Boolean()` constructor creates an object wrapper for a boolean value.
|
||||
///
|
||||
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean
|
||||
#[wasm_bindgen(constructor)]
|
||||
pub fn new(value: JsValue) -> Boolean;
|
||||
|
||||
/// The `valueOf()` method returns the primitive value of a `Boolean` object.
|
||||
///
|
||||
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean/valueOf
|
||||
#[wasm_bindgen(method, js_name = valueOf)]
|
||||
pub fn value_of(this: &Boolean) -> bool;
|
||||
}
|
||||
|
||||
// Error
|
||||
#[wasm_bindgen]
|
||||
extern "C" {
|
||||
pub type Error;
|
||||
|
||||
/// The Error constructor creates an error object.
|
||||
/// Instances of Error objects are thrown when runtime errors occur.
|
||||
/// The Error object can also be used as a base object for user-defined exceptions.
|
||||
/// See below for standard built-in error types.
|
||||
///
|
||||
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error
|
||||
#[wasm_bindgen(constructor)]
|
||||
pub fn new(message: &JsString) -> Error;
|
||||
|
||||
/// The message property is a human-readable description of the error.
|
||||
///
|
||||
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error/message
|
||||
#[wasm_bindgen(method, getter, structural)]
|
||||
pub fn message(this: &Error) -> JsString;
|
||||
#[wasm_bindgen(method, setter, structural)]
|
||||
pub fn set_message(this: &Error, message: &JsString);
|
||||
|
||||
/// The name property represents a name for the type of error. The initial value is "Error".
|
||||
///
|
||||
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error/name
|
||||
#[wasm_bindgen(method, getter, structural)]
|
||||
pub fn name(this: &Error) -> JsString;
|
||||
#[wasm_bindgen(method, setter, structural)]
|
||||
pub fn set_name(this: &Error, name: &JsString);
|
||||
|
||||
/// The toString() method returns a string representing the specified Error object
|
||||
///
|
||||
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error/toString
|
||||
#[wasm_bindgen(method, js_name = toString)]
|
||||
pub fn to_string(this: &Error) -> JsString;
|
||||
}
|
||||
|
||||
// Function
|
||||
#[wasm_bindgen]
|
||||
extern {
|
||||
extern "C" {
|
||||
pub type Function;
|
||||
|
||||
/// The apply() method calls a function with a given this value, and arguments provided as an array
|
||||
/// (or an array-like object).
|
||||
///
|
||||
///
|
||||
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/apply
|
||||
#[wasm_bindgen(method)]
|
||||
pub fn apply(this: &Function, context: &JsValue, args: &Array) -> Function;
|
||||
|
||||
/// The bind() method creates a new function that, when called, has its this keyword set to the provided value,
|
||||
/// with a given sequence of arguments preceding any provided when the new function is called.
|
||||
///
|
||||
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/bind
|
||||
#[wasm_bindgen(method)]
|
||||
pub fn bind(this: &Function, context: &JsValue) -> Function;
|
||||
|
||||
/// The length property indicates the number of arguments expected by the function.
|
||||
///
|
||||
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/length
|
||||
@@ -270,22 +363,103 @@ extern {
|
||||
pub fn name(this: &Function) -> JsString;
|
||||
|
||||
/// The toString() method returns a string representing the source code of the function.
|
||||
///
|
||||
///
|
||||
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/toString
|
||||
#[wasm_bindgen(method, js_name = toString)]
|
||||
pub fn to_string(this: &Function) -> JsString;
|
||||
}
|
||||
|
||||
// Math
|
||||
// Map
|
||||
#[wasm_bindgen]
|
||||
extern {
|
||||
pub type Map;
|
||||
|
||||
/// The clear() method removes all elements from a Map object.
|
||||
///
|
||||
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/clear
|
||||
#[wasm_bindgen(method)]
|
||||
pub fn clear(this: &Map);
|
||||
|
||||
/// The delete() method removes the specified element from a Map object.
|
||||
///
|
||||
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/delete
|
||||
#[wasm_bindgen(method)]
|
||||
pub fn delete(this: &Map, key: &str) -> bool;
|
||||
|
||||
/// The get() method returns a specified element from a Map object.
|
||||
///
|
||||
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/get
|
||||
#[wasm_bindgen(method)]
|
||||
pub fn get(this: &Map, key: &JsValue) -> JsValue;
|
||||
|
||||
/// The has() method returns a boolean indicating whether an element with
|
||||
/// the specified key exists or not.
|
||||
///
|
||||
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/has
|
||||
#[wasm_bindgen(method)]
|
||||
pub fn has(this: &Map, key: &JsValue) -> bool;
|
||||
|
||||
/// The Map object holds key-value pairs. Any value (both objects and
|
||||
/// primitive values) maybe used as either a key or a value.
|
||||
///
|
||||
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map
|
||||
#[wasm_bindgen(constructor)]
|
||||
pub fn new() -> Map;
|
||||
|
||||
/// The set() method adds or updates an element with a specified key
|
||||
/// and value to a Map object.
|
||||
///
|
||||
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/set
|
||||
#[wasm_bindgen(method)]
|
||||
pub fn set(this: &Map, key: &JsValue, value: &JsValue) -> Map;
|
||||
|
||||
/// The value of size is an integer representing how many entries
|
||||
/// the Map object has. A set accessor function for size is undefined;
|
||||
/// you can not change this property.
|
||||
///
|
||||
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/size
|
||||
#[wasm_bindgen(method, getter, structural)]
|
||||
pub fn size(this: &Map) -> Number;
|
||||
}
|
||||
|
||||
// Map Iterator
|
||||
#[wasm_bindgen]
|
||||
extern {
|
||||
pub type MapIterator;
|
||||
|
||||
/// The entries() method returns a new Iterator object that contains
|
||||
/// the [key, value] pairs for each element in the Map object in
|
||||
/// insertion order.
|
||||
///
|
||||
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/entries
|
||||
#[wasm_bindgen(method)]
|
||||
pub fn entries(this: &Map) -> MapIterator;
|
||||
|
||||
/// The keys() method returns a new Iterator object that contains the
|
||||
/// keys for each element in the Map object in insertion order.
|
||||
///
|
||||
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/keys
|
||||
#[wasm_bindgen(method)]
|
||||
pub fn keys(this: &Map) -> MapIterator;
|
||||
|
||||
/// The values() method returns a new Iterator object that contains the
|
||||
/// values for each element in the Map object in insertion order.
|
||||
///
|
||||
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/values
|
||||
#[wasm_bindgen(method)]
|
||||
pub fn values(this: &Map) -> MapIterator;
|
||||
}
|
||||
|
||||
// Math
|
||||
#[wasm_bindgen]
|
||||
extern "C" {
|
||||
pub type Math;
|
||||
/// The Math.abs() function returns the absolute value of a number, that is
|
||||
/// Math.abs(x) = |x|
|
||||
///
|
||||
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/abs
|
||||
#[wasm_bindgen(static_method_of = Math)]
|
||||
pub fn abs(number: i32) -> Number;
|
||||
pub fn abs(x: f64) -> Number;
|
||||
|
||||
/// The Math.acos() function returns the arccosine (in radians) of a
|
||||
/// number, that is ∀x∊[-1;1]
|
||||
@@ -293,7 +467,7 @@ extern {
|
||||
///
|
||||
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/acos
|
||||
#[wasm_bindgen(static_method_of = Math)]
|
||||
pub fn acos(adjacent: i32, hypotenuse: i32) -> Number;
|
||||
pub fn acos(x: f64) -> Number;
|
||||
|
||||
/// The Math.acosh() function returns the hyperbolic arc-cosine of a
|
||||
/// number, that is ∀x ≥ 1
|
||||
@@ -301,7 +475,7 @@ extern {
|
||||
///
|
||||
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/acosh
|
||||
#[wasm_bindgen(static_method_of = Math)]
|
||||
pub fn acosh(number: i32) -> Number;
|
||||
pub fn acosh(x: f64) -> Number;
|
||||
|
||||
/// The Math.asin() function returns the arcsine (in radians) of a
|
||||
/// number, that is ∀x ∊ [-1;1]
|
||||
@@ -309,27 +483,27 @@ extern {
|
||||
///
|
||||
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/asin
|
||||
#[wasm_bindgen(static_method_of = Math)]
|
||||
pub fn asin(number: i32) -> Number;
|
||||
pub fn asin(x: f64) -> Number;
|
||||
|
||||
/// The Math.asinh() function returns the hyperbolic arcsine of a
|
||||
/// number, that is Math.asinh(x) = arsinh(x) = the unique y such that sinh(y) = x
|
||||
///
|
||||
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/asinh
|
||||
#[wasm_bindgen(static_method_of = Math)]
|
||||
pub fn asinh(number: i32) -> Number;
|
||||
pub fn asinh(x: f64) -> Number;
|
||||
|
||||
/// The Math.atan() function returns the arctangent (in radians) of a
|
||||
/// number, that is Math.atan(x) = arctan(x) = the unique y ∊ [-π2;π2]such that
|
||||
/// tan(y) = x
|
||||
#[wasm_bindgen(static_method_of = Math)]
|
||||
pub fn atan(number: i32) -> Number;
|
||||
pub fn atan(x: f64) -> Number;
|
||||
|
||||
/// The Math.atan2() function returns the arctangent of the quotient of
|
||||
/// its arguments.
|
||||
///
|
||||
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/atan2
|
||||
#[wasm_bindgen(static_method_of = Math)]
|
||||
pub fn atan2(y: i32, x: i32) -> Number;
|
||||
pub fn atan2(y: f64, x: f64) -> Number;
|
||||
|
||||
/// The Math.atanh() function returns the hyperbolic arctangent of a number,
|
||||
/// that is ∀x ∊ (-1,1), Math.atanh(x) = arctanh(x) = the unique y such that
|
||||
@@ -337,22 +511,21 @@ extern {
|
||||
///
|
||||
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/atanh
|
||||
#[wasm_bindgen(static_method_of = Math)]
|
||||
pub fn atanh(x: i32) -> Number;
|
||||
|
||||
pub fn atanh(x: f64) -> Number;
|
||||
|
||||
/// The Math.cbrt() function returns the cube root of a number, that is
|
||||
/// Math.cbrt(x) = x^3 = the unique y such that y^3 = x
|
||||
///
|
||||
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/cbrt
|
||||
#[wasm_bindgen(static_method_of = Math)]
|
||||
pub fn cbrt(x: i32) -> Number;
|
||||
pub fn cbrt(x: f64) -> Number;
|
||||
|
||||
/// The Math.ceil() function returns the smallest integer greater than
|
||||
/// or equal to a given number.
|
||||
///
|
||||
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/ceil
|
||||
#[wasm_bindgen(static_method_of = Math)]
|
||||
pub fn ceil(x: f32) -> Number;
|
||||
pub fn ceil(x: f64) -> Number;
|
||||
|
||||
/// The Math.clz32() function returns the number of leading zero bits in
|
||||
/// the 32-bit binary representation of a number.
|
||||
@@ -360,11 +533,86 @@ extern {
|
||||
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/clz32
|
||||
#[wasm_bindgen(static_method_of = Math)]
|
||||
pub fn clz32(x: i32) -> Number;
|
||||
|
||||
/// The Math.cos() static function returns the cosine of the specified angle,
|
||||
/// which must be specified in radians. This value is length(adjacent)/length(hypotenuse).
|
||||
///
|
||||
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/cos
|
||||
#[wasm_bindgen(static_method_of = Math)]
|
||||
pub fn cos(x: f64) -> Number;
|
||||
|
||||
|
||||
/// The Math.cosh() function returns the hyperbolic cosine of a number,
|
||||
/// that can be expressed using the constant e.
|
||||
///
|
||||
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/cosh
|
||||
#[wasm_bindgen(static_method_of = Math)]
|
||||
pub fn cosh(x: f64) -> Number;
|
||||
|
||||
/// The Math.exp() function returns e^x, where x is the argument, and e is Euler's number
|
||||
/// (also known as Napier's constant), the base of the natural logarithms.
|
||||
///
|
||||
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/exp
|
||||
#[wasm_bindgen(static_method_of = Math)]
|
||||
pub fn exp(x: f64) -> Number;
|
||||
|
||||
/// The Math.expm1() function returns e^x - 1, where x is the argument, and e the base of the
|
||||
/// natural logarithms.
|
||||
///
|
||||
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/expm1
|
||||
#[wasm_bindgen(static_method_of = Math)]
|
||||
pub fn expm1(x: f64) -> Number;
|
||||
|
||||
/// The Math.floor() function returns the largest integer less than or
|
||||
/// equal to a given number.
|
||||
///
|
||||
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/floor
|
||||
#[wasm_bindgen(static_method_of = Math)]
|
||||
pub fn floor(x: f64) -> Number;
|
||||
|
||||
/// The Math.fround() function returns the nearest 32-bit single precision float representation
|
||||
/// of a Number.
|
||||
///
|
||||
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/fround
|
||||
#[wasm_bindgen(static_method_of = Math)]
|
||||
pub fn fround(x: f64) -> Number;
|
||||
|
||||
/// The Math.imul() function returns the result of the C-like 32-bit multiplication of the
|
||||
/// two parameters.
|
||||
///
|
||||
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/imul
|
||||
#[wasm_bindgen(static_method_of = Math)]
|
||||
pub fn imul(x: i32, y: i32) -> Number;
|
||||
|
||||
/// The Math.log() function returns the natural logarithm (base e) of a number.
|
||||
/// The JavaScript Math.log() function is equivalent to ln(x) in mathematics.
|
||||
///
|
||||
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/log
|
||||
#[wasm_bindgen(static_method_of = Math)]
|
||||
pub fn log(x: f64) -> Number;
|
||||
|
||||
/// The Math.log10() function returns the base 10 logarithm of a number.
|
||||
///
|
||||
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/log10
|
||||
#[wasm_bindgen(static_method_of = Math)]
|
||||
pub fn log10(x: f64) -> Number;
|
||||
|
||||
/// The Math.log1p() function returns the natural logarithm (base e) of 1 + a number.
|
||||
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/log1p
|
||||
#[wasm_bindgen(static_method_of = Math)]
|
||||
pub fn log1p(x: f64) -> Number;
|
||||
|
||||
/// The Math.log2() function returns the base 2 logarithm of a number.
|
||||
///
|
||||
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/log2
|
||||
#[wasm_bindgen(static_method_of = Math)]
|
||||
pub fn log2(x: f64) -> Number;
|
||||
|
||||
}
|
||||
|
||||
// Number.
|
||||
#[wasm_bindgen]
|
||||
extern {
|
||||
extern "C" {
|
||||
pub type Number;
|
||||
|
||||
/// The `Number` JavaScript object is a wrapper object allowing
|
||||
@@ -420,13 +668,13 @@ extern {
|
||||
|
||||
// Date.
|
||||
#[wasm_bindgen]
|
||||
extern {
|
||||
extern "C" {
|
||||
pub type Date;
|
||||
|
||||
/// Creates a JavaScript Date instance that represents
|
||||
/// a single moment in time. Date objects are based on a time value that is
|
||||
/// Creates a JavaScript Date instance that represents
|
||||
/// a single moment in time. Date objects are based on a time value that is
|
||||
/// the number of milliseconds since 1 January 1970 UTC.
|
||||
///
|
||||
///
|
||||
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date
|
||||
#[wasm_bindgen(constructor)]
|
||||
pub fn new() -> Date;
|
||||
@@ -440,22 +688,22 @@ extern {
|
||||
|
||||
/// The toDateString() method returns the date portion of a Date object
|
||||
/// in human readable form in American English.
|
||||
///
|
||||
///
|
||||
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toDateString
|
||||
#[wasm_bindgen(method, js_name = toDateString)]
|
||||
pub fn to_date_string(this: &Date) -> JsString;
|
||||
|
||||
/// The toISOString() method returns a string in simplified extended ISO format (ISO
|
||||
/// 8601), which is always 24 or 27 characters long (YYYY-MM-DDTHH:mm:ss.sssZ or
|
||||
/// ±YYYYYY-MM-DDTHH:mm:ss.sssZ, respectively). The timezone is always zero UTC offset,
|
||||
/// ±YYYYYY-MM-DDTHH:mm:ss.sssZ, respectively). The timezone is always zero UTC offset,
|
||||
/// as denoted by the suffix "Z"
|
||||
///
|
||||
///
|
||||
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toISOString
|
||||
#[wasm_bindgen(method, js_name = toISOString)]
|
||||
pub fn to_iso_string(this: &Date) -> JsString;
|
||||
|
||||
/// The toJSON() method returns a string representation of the Date object.
|
||||
///
|
||||
///
|
||||
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toJSON
|
||||
#[wasm_bindgen(method, js_name = toJSON)]
|
||||
pub fn to_json(this: &Date) -> JsString;
|
||||
@@ -467,17 +715,17 @@ extern {
|
||||
/// In older implementations, which ignore the locales and options arguments,
|
||||
/// the locale used and the form of the string
|
||||
/// returned are entirely implementation dependent.
|
||||
///
|
||||
///
|
||||
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toLocaleDateString
|
||||
#[wasm_bindgen(method, js_name = toLocaleDateString)]
|
||||
pub fn to_locale_date_string(this: &Date, locale: JsString, options: JsValue) -> JsString;
|
||||
|
||||
/// The toLocaleString() method returns a string with a language sensitive
|
||||
/// representation of this date. The new locales and options arguments
|
||||
/// let applications specify the language whose formatting conventions
|
||||
/// should be used and customize the behavior of the function.
|
||||
/// In older implementations, which ignore the locales
|
||||
/// and options arguments, the locale used and the form of the string
|
||||
/// The toLocaleString() method returns a string with a language sensitive
|
||||
/// representation of this date. The new locales and options arguments
|
||||
/// let applications specify the language whose formatting conventions
|
||||
/// should be used and customize the behavior of the function.
|
||||
/// In older implementations, which ignore the locales
|
||||
/// and options arguments, the locale used and the form of the string
|
||||
/// returned are entirely implementation dependent.
|
||||
///
|
||||
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toLocaleString
|
||||
@@ -535,7 +783,7 @@ extern {
|
||||
|
||||
// Object.
|
||||
#[wasm_bindgen]
|
||||
extern {
|
||||
extern "C" {
|
||||
pub type Object;
|
||||
|
||||
/// The `hasOwnProperty()` method returns a boolean indicating whether the
|
||||
@@ -546,6 +794,25 @@ extern {
|
||||
#[wasm_bindgen(method, js_name = hasOwnProperty)]
|
||||
pub fn has_own_property(this: &Object, property: &JsValue) -> bool;
|
||||
|
||||
/// The Object.isExtensible() method determines if an object is extensible
|
||||
/// (whether it can have new properties added to it).
|
||||
///
|
||||
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/isExtensible
|
||||
#[wasm_bindgen(static_method_of = Object, js_name = isExtensible)]
|
||||
pub fn is_extensible(object: &Object) -> bool;
|
||||
|
||||
/// The Object.isFrozen() determines if an object is frozen.
|
||||
///
|
||||
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/isFrozen
|
||||
#[wasm_bindgen(static_method_of = Object, js_name = isFrozen)]
|
||||
pub fn is_frozen(object: &Object) -> bool;
|
||||
|
||||
/// The Object.isSealed() method determines if an object is sealed.
|
||||
///
|
||||
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/isSealed
|
||||
#[wasm_bindgen(static_method_of = Object, js_name = isSealed)]
|
||||
pub fn is_sealed(object: &Object) -> bool;
|
||||
|
||||
/// The isPrototypeOf() method checks if an object exists in another
|
||||
/// object's prototype chain.
|
||||
///
|
||||
@@ -566,6 +833,14 @@ extern {
|
||||
#[wasm_bindgen(constructor)]
|
||||
pub fn new() -> Object;
|
||||
|
||||
/// The Object.preventExtensions() method prevents
|
||||
/// new properties from ever being added to an object
|
||||
/// (i.e. prevents future extensions to the object).
|
||||
///
|
||||
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/preventExtensions
|
||||
#[wasm_bindgen(static_method_of = Object, js_name = preventExtensions)]
|
||||
pub fn prevent_extensions(object: &Object);
|
||||
|
||||
/// The propertyIsEnumerable() method returns a Boolean indicating
|
||||
/// whether the specified property is enumerable.
|
||||
///
|
||||
@@ -576,11 +851,18 @@ extern {
|
||||
/// The Object.seal() method seals an object, preventing new properties
|
||||
/// from being added to it and marking all existing properties as non-configurable.
|
||||
/// Values of present properties can still be changed as long as they are writable.
|
||||
///
|
||||
///
|
||||
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/seal
|
||||
#[wasm_bindgen(static_method_of = Object)]
|
||||
pub fn seal(value: &JsValue) -> JsValue;
|
||||
|
||||
/// The Object.setPrototypeOf() method sets the prototype (i.e., the internal
|
||||
/// [[Prototype]] property) of a specified object to another object or null.
|
||||
///
|
||||
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/setPrototypeOf
|
||||
#[wasm_bindgen(static_method_of = Object, js_name = setPrototypeOf)]
|
||||
pub fn set_prototype_of(object: &Object, prototype: &Object) -> Object;
|
||||
|
||||
/// The toLocaleString() method returns a string representing the object.
|
||||
/// This method is meant to be overridden by derived objects for
|
||||
/// locale-specific purposes.
|
||||
@@ -601,11 +883,97 @@ extern {
|
||||
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/valueOf
|
||||
#[wasm_bindgen(method, js_name = valueOf)]
|
||||
pub fn value_of(this: &Object) -> Object;
|
||||
|
||||
/// The Object.values() method returns an array of a given object's
|
||||
/// own enumerable property values, in the same order as that provided
|
||||
/// by a for...in loop (the difference being that a for-in loop
|
||||
/// enumerates properties in the prototype chain as well).
|
||||
///
|
||||
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/values
|
||||
#[wasm_bindgen(static_method_of = Object)]
|
||||
pub fn values(object: &Object) -> Array;
|
||||
}
|
||||
|
||||
// Set
|
||||
#[wasm_bindgen]
|
||||
extern {
|
||||
pub type Set;
|
||||
|
||||
/// The add() method appends a new element with a specified value to the
|
||||
/// end of a Set object.
|
||||
///
|
||||
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/add
|
||||
#[wasm_bindgen(method)]
|
||||
pub fn add(this: &Set, value: &JsValue) -> Set;
|
||||
|
||||
/// The clear() method removes all elements from a Set object.
|
||||
///
|
||||
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/clear
|
||||
#[wasm_bindgen(method)]
|
||||
pub fn clear(this: &Set);
|
||||
|
||||
/// The delete() method removes the specified element from a Set object.
|
||||
///
|
||||
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/delete
|
||||
#[wasm_bindgen(method)]
|
||||
pub fn delete(this: &Set, value: &JsValue) -> bool;
|
||||
|
||||
/// The has() method returns a boolean indicating whether an element
|
||||
/// with the specified value exists in a Set object or not.
|
||||
///
|
||||
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/has
|
||||
#[wasm_bindgen(method)]
|
||||
pub fn has(this: &Set, value: &JsValue) -> bool;
|
||||
|
||||
/// The Set object lets you store unique values of any type, whether primitive
|
||||
/// values or object references.
|
||||
///
|
||||
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set
|
||||
#[wasm_bindgen(constructor)]
|
||||
pub fn new() -> Set;
|
||||
|
||||
/// The size accessor property returns the number of elements in a Set object.
|
||||
///
|
||||
/// https://developer.mozilla.org/de/docs/Web/JavaScript/Reference/Global_Objects/Set/size
|
||||
#[wasm_bindgen(method, getter, structural)]
|
||||
pub fn size(this: &Set) -> Number;
|
||||
}
|
||||
|
||||
// SetIterator
|
||||
#[wasm_bindgen]
|
||||
extern {
|
||||
pub type SetIterator;
|
||||
|
||||
/// The entries() method returns a new Iterator object that contains
|
||||
/// an array of [value, value] for each element in the Set object,
|
||||
/// in insertion order. For Set objects there is no key like in
|
||||
/// Map objects. However, to keep the API similar to the Map object,
|
||||
/// each entry has the same value for its key and value here, so that
|
||||
/// an array [value, value] is returned.
|
||||
///
|
||||
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/entries
|
||||
#[wasm_bindgen(method)]
|
||||
pub fn entries(set: &Set) -> SetIterator;
|
||||
|
||||
/// The keys() method is an alias for this method (for similarity with
|
||||
/// Map objects); it behaves exactly the same and returns values
|
||||
/// of Set elements.
|
||||
///
|
||||
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/values
|
||||
#[wasm_bindgen(method)]
|
||||
pub fn keys(set: &Set) -> SetIterator;
|
||||
|
||||
/// The values() method returns a new Iterator object that contains the
|
||||
/// values for each element in the Set object in insertion order.
|
||||
///
|
||||
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/values
|
||||
#[wasm_bindgen(method)]
|
||||
pub fn values(set: &Set) -> SetIterator;
|
||||
}
|
||||
|
||||
// WeakMap
|
||||
#[wasm_bindgen]
|
||||
extern {
|
||||
extern "C" {
|
||||
pub type WeakMap;
|
||||
|
||||
/// The WeakMap object is a collection of key/value pairs in which the keys are weakly referenced.
|
||||
@@ -615,21 +983,21 @@ extern {
|
||||
#[wasm_bindgen(constructor)]
|
||||
pub fn new() -> WeakMap;
|
||||
|
||||
/// The set() method sets the value for the key in the WeakMap object. Returns
|
||||
/// The set() method sets the value for the key in the WeakMap object. Returns
|
||||
/// the WeakMap object.
|
||||
///
|
||||
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakMap/set
|
||||
#[wasm_bindgen(method, js_class="WeakMap")]
|
||||
#[wasm_bindgen(method, js_class = "WeakMap")]
|
||||
pub fn set(this: &WeakMap, key: Object, value: JsValue) -> WeakMap;
|
||||
|
||||
/// The get() method returns a specified by key element
|
||||
/// The get() method returns a specified by key element
|
||||
/// from a WeakMap object.
|
||||
///
|
||||
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakMap/get
|
||||
#[wasm_bindgen(method)]
|
||||
pub fn get(this: &WeakMap, key: Object) -> JsValue;
|
||||
|
||||
/// The has() method returns a boolean indicating whether an element with
|
||||
/// The has() method returns a boolean indicating whether an element with
|
||||
/// the specified key exists in the WeakMap object or not.
|
||||
///
|
||||
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakMap/has
|
||||
@@ -643,9 +1011,39 @@ extern {
|
||||
pub fn delete(this: &WeakMap, key: Object) -> bool;
|
||||
}
|
||||
|
||||
// WeakSet
|
||||
#[wasm_bindgen]
|
||||
extern "C" {
|
||||
pub type WeakSet;
|
||||
|
||||
/// The WeakSet object lets you store weakly held objects in a collection.
|
||||
///
|
||||
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakSet
|
||||
#[wasm_bindgen(constructor)]
|
||||
pub fn new() -> WeakSet;
|
||||
|
||||
/// The has() method returns a boolean indicating whether an object exists in a WeakSet or not.
|
||||
///
|
||||
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakSet/has
|
||||
#[wasm_bindgen(method)]
|
||||
pub fn has(this: &WeakSet, value: Object) -> bool;
|
||||
|
||||
/// The add() method appends a new object to the end of a WeakSet object.
|
||||
///
|
||||
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakSet/add
|
||||
#[wasm_bindgen(method)]
|
||||
pub fn add(this: &WeakSet, value: Object) -> WeakSet;
|
||||
|
||||
/// The delete() method removes the specified element from a WeakSet object.
|
||||
///
|
||||
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakSet/delete
|
||||
#[wasm_bindgen(method)]
|
||||
pub fn delete(this: &WeakSet, value: Object) -> bool;
|
||||
}
|
||||
|
||||
// JsString
|
||||
#[wasm_bindgen]
|
||||
extern {
|
||||
extern "C" {
|
||||
#[wasm_bindgen(js_name = JsString)]
|
||||
pub type JsString;
|
||||
|
||||
@@ -698,7 +1096,7 @@ extern {
|
||||
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/indexOf
|
||||
#[wasm_bindgen(method, js_class = "String", js_name = indexOf)]
|
||||
pub fn index_of(this: &JsString, search_value: &JsString, from_index: i32) -> i32;
|
||||
|
||||
|
||||
/// The slice() method extracts a section of a string and returns it as a
|
||||
/// new string, without modifying the original string.
|
||||
///
|
||||
@@ -727,12 +1125,27 @@ extern {
|
||||
#[wasm_bindgen(method, js_class = "String")]
|
||||
pub fn substr(this: &JsString, start: i32, length: i32) -> JsString;
|
||||
|
||||
/// The toLowerCase() method returns the calling string value
|
||||
/// converted to lower case.
|
||||
///
|
||||
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/toLowerCase
|
||||
#[wasm_bindgen(method, js_class = "String", js_name = toLowerCase)]
|
||||
pub fn to_lower_case(this: &JsString) -> JsString;
|
||||
|
||||
/// The toString() method returns a string representing the specified object.
|
||||
///
|
||||
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/toString
|
||||
#[wasm_bindgen(method, js_class = "String", js_name = toString)]
|
||||
pub fn to_string(this: &JsString) -> JsString;
|
||||
|
||||
/// The toUpperCase() method returns the calling string value
|
||||
/// converted to uppercase (the value will be converted to a
|
||||
/// string if it isn't one).
|
||||
///
|
||||
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/toUpperCase
|
||||
#[wasm_bindgen(method, js_class = "String", js_name = toUpperCase)]
|
||||
pub fn to_upper_case(this: &JsString) -> JsString;
|
||||
|
||||
/// The trim() method removes whitespace from both ends of a string.
|
||||
/// Whitespace in this context is all the whitespace characters
|
||||
/// (space, tab, no-break space, etc.) and all the line terminator characters (LF, CR, etc.).
|
||||
|
76
src/lib.rs
76
src/lib.rs
@@ -76,16 +76,18 @@ const JSIDX_RESERVED: u32 = 8;
|
||||
|
||||
impl JsValue {
|
||||
/// The `null` JS value constant.
|
||||
pub const NULL: JsValue = JsValue { idx: JSIDX_NULL };
|
||||
pub const NULL: JsValue = JsValue { idx: JSIDX_NULL };
|
||||
|
||||
/// The `undefined` JS value constant.
|
||||
pub const UNDEFINED: JsValue = JsValue { idx: JSIDX_UNDEFINED };
|
||||
pub const UNDEFINED: JsValue = JsValue {
|
||||
idx: JSIDX_UNDEFINED,
|
||||
};
|
||||
|
||||
/// The `true` JS value constant.
|
||||
pub const TRUE: JsValue = JsValue { idx: JSIDX_TRUE };
|
||||
pub const TRUE: JsValue = JsValue { idx: JSIDX_TRUE };
|
||||
|
||||
/// The `false` JS value constant.
|
||||
pub const FALSE: JsValue = JsValue { idx: JSIDX_FALSE };
|
||||
pub const FALSE: JsValue = JsValue { idx: JSIDX_FALSE };
|
||||
|
||||
/// Creates a new JS value which is a string.
|
||||
///
|
||||
@@ -93,7 +95,9 @@ impl JsValue {
|
||||
/// be owned by the JS garbage collector.
|
||||
pub fn from_str(s: &str) -> JsValue {
|
||||
unsafe {
|
||||
JsValue { idx: __wbindgen_string_new(s.as_ptr(), s.len()) }
|
||||
JsValue {
|
||||
idx: __wbindgen_string_new(s.as_ptr(), s.len()),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -103,7 +107,9 @@ impl JsValue {
|
||||
/// allocated number) and returns a handle to the JS version of it.
|
||||
pub fn from_f64(n: f64) -> JsValue {
|
||||
unsafe {
|
||||
JsValue { idx: __wbindgen_number_new(n) }
|
||||
JsValue {
|
||||
idx: __wbindgen_number_new(n),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -112,12 +118,16 @@ impl JsValue {
|
||||
/// This function creates a JS object representing a boolean (a heap
|
||||
/// allocated boolean) and returns a handle to the JS version of it.
|
||||
pub fn from_bool(b: bool) -> JsValue {
|
||||
JsValue { idx: if b { JSIDX_TRUE } else { JSIDX_FALSE } }
|
||||
JsValue {
|
||||
idx: if b { JSIDX_TRUE } else { JSIDX_FALSE },
|
||||
}
|
||||
}
|
||||
|
||||
/// Creates a new JS value representing `undefined`.
|
||||
pub fn undefined() -> JsValue {
|
||||
JsValue { idx: JSIDX_UNDEFINED }
|
||||
JsValue {
|
||||
idx: JSIDX_UNDEFINED,
|
||||
}
|
||||
}
|
||||
|
||||
/// Creates a new JS value representing `null`.
|
||||
@@ -133,7 +143,9 @@ impl JsValue {
|
||||
unsafe {
|
||||
let ptr = description.map(|s| s.as_ptr()).unwrap_or(ptr::null());
|
||||
let len = description.map(|s| s.len()).unwrap_or(0);
|
||||
JsValue { idx: __wbindgen_symbol_new(ptr, len) }
|
||||
JsValue {
|
||||
idx: __wbindgen_symbol_new(ptr, len),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -154,7 +166,8 @@ impl JsValue {
|
||||
/// Returns any error encountered when serializing `T` into JSON.
|
||||
#[cfg(feature = "serde-serialize")]
|
||||
pub fn from_serde<T>(t: &T) -> serde_json::Result<JsValue>
|
||||
where T: serde::ser::Serialize + ?Sized,
|
||||
where
|
||||
T: serde::ser::Serialize + ?Sized,
|
||||
{
|
||||
let s = serde_json::to_string(t)?;
|
||||
unsafe {
|
||||
@@ -179,7 +192,8 @@ impl JsValue {
|
||||
/// Returns any error encountered when parsing the JSON into a `T`.
|
||||
#[cfg(feature = "serde-serialize")]
|
||||
pub fn into_serde<T>(&self) -> serde_json::Result<T>
|
||||
where T: for<'a> serde::de::Deserialize<'a>,
|
||||
where
|
||||
T: for<'a> serde::de::Deserialize<'a>,
|
||||
{
|
||||
unsafe {
|
||||
let mut ptr = ptr::null_mut();
|
||||
@@ -243,31 +257,23 @@ impl JsValue {
|
||||
|
||||
/// Tests whether this JS value is `null`
|
||||
pub fn is_null(&self) -> bool {
|
||||
unsafe {
|
||||
__wbindgen_is_null(self.idx) == 1
|
||||
}
|
||||
unsafe { __wbindgen_is_null(self.idx) == 1 }
|
||||
}
|
||||
|
||||
/// Tests whether this JS value is `undefined`
|
||||
pub fn is_undefined(&self) -> bool {
|
||||
unsafe {
|
||||
__wbindgen_is_undefined(self.idx) == 1
|
||||
}
|
||||
unsafe { __wbindgen_is_undefined(self.idx) == 1 }
|
||||
}
|
||||
|
||||
/// Tests whether the type of this JS value is `symbol`
|
||||
pub fn is_symbol(&self) -> bool {
|
||||
unsafe {
|
||||
__wbindgen_is_symbol(self.idx) == 1
|
||||
}
|
||||
unsafe { __wbindgen_is_symbol(self.idx) == 1 }
|
||||
}
|
||||
}
|
||||
|
||||
impl PartialEq for JsValue {
|
||||
fn eq(&self, other: &JsValue) -> bool {
|
||||
unsafe {
|
||||
__wbindgen_jsval_eq(self.idx, other.idx) != 0
|
||||
}
|
||||
unsafe { __wbindgen_jsval_eq(self.idx, other.idx) != 0 }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -421,7 +427,7 @@ impl<T: FromWasmAbi + 'static> Deref for JsStatic<T> {
|
||||
// `JsStatic` a bit as well.
|
||||
let ptr = self.__inner.get();
|
||||
if let Some(ref t) = *ptr {
|
||||
return t
|
||||
return t;
|
||||
}
|
||||
let init = Some((self.__init)());
|
||||
debug_assert!((*ptr).is_none());
|
||||
@@ -455,7 +461,7 @@ pub mod __rt {
|
||||
#[macro_export]
|
||||
#[cfg(feature = "std")]
|
||||
macro_rules! __wbindgen_if_not_std {
|
||||
($($i:item)*) => ()
|
||||
($($i:item)*) => {};
|
||||
}
|
||||
|
||||
#[macro_export]
|
||||
@@ -500,7 +506,10 @@ pub mod __rt {
|
||||
}
|
||||
|
||||
impl<T: ?Sized> WasmRefCell<T> {
|
||||
pub fn new(value: T) -> WasmRefCell<T> where T: Sized {
|
||||
pub fn new(value: T) -> WasmRefCell<T>
|
||||
where
|
||||
T: Sized,
|
||||
{
|
||||
WasmRefCell {
|
||||
value: UnsafeCell::new(value),
|
||||
borrow: Cell::new(0),
|
||||
@@ -508,9 +517,7 @@ pub mod __rt {
|
||||
}
|
||||
|
||||
pub fn get_mut(&mut self) -> &mut T {
|
||||
unsafe {
|
||||
&mut *self.value.get()
|
||||
}
|
||||
unsafe { &mut *self.value.get() }
|
||||
}
|
||||
|
||||
pub fn borrow(&self) -> Ref<T> {
|
||||
@@ -539,7 +546,10 @@ pub mod __rt {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn into_inner(self) -> T where T: Sized {
|
||||
pub fn into_inner(self) -> T
|
||||
where
|
||||
T: Sized,
|
||||
{
|
||||
self.value.into_inner()
|
||||
}
|
||||
}
|
||||
@@ -592,8 +602,10 @@ pub mod __rt {
|
||||
}
|
||||
|
||||
fn borrow_fail() -> ! {
|
||||
super::throw("recursive use of an object detected which would lead to \
|
||||
unsafe aliasing in rust");
|
||||
super::throw(
|
||||
"recursive use of an object detected which would lead to \
|
||||
unsafe aliasing in rust",
|
||||
);
|
||||
}
|
||||
|
||||
if_std! {
|
||||
|
Reference in New Issue
Block a user