From 1071457c3d2ce0711c48e347244f3d54341806bb Mon Sep 17 00:00:00 2001 From: ibaryshnikov Date: Tue, 16 Apr 2019 06:35:52 +0900 Subject: [PATCH 1/6] added SharedArrayBuffer and Atomics to js-sys --- crates/js-sys/src/lib.rs | 169 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 169 insertions(+) diff --git a/crates/js-sys/src/lib.rs b/crates/js-sys/src/lib.rs index 7593aa0f822..d5ec0b39e90 100644 --- a/crates/js-sys/src/lib.rs +++ b/crates/js-sys/src/lib.rs @@ -438,6 +438,47 @@ extern "C" { pub fn slice_with_end(this: &ArrayBuffer, begin: u32, end: u32) -> ArrayBuffer; } + +// SharedArrayBuffer +#[wasm_bindgen] +extern "C" { + #[wasm_bindgen(extends = Object)] + #[derive(Clone, Debug)] + pub type SharedArrayBuffer; + + /// The `SharedArrayBuffer` object is used to represent a generic, + /// fixed-length raw binary data buffer, similar to the `ArrayBuffer` + /// object, but in a way that they can be used to create views + /// on shared memory. Unlike an `ArrayBuffer`, a `SharedArrayBuffer` + /// cannot become detached. + /// + /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SharedArrayBuffer) + #[wasm_bindgen(constructor)] + pub fn new(length: u32) -> SharedArrayBuffer; + + /// The byteLength accessor property represents the length of + /// an `SharedArrayBuffer` in bytes. This is established when + /// the `SharedArrayBuffer` is constructed and cannot be changed. + /// + /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SharedArrayBuffer/byteLength) + #[wasm_bindgen(method, getter, js_name = byteLength)] + pub fn byte_length(this: &SharedArrayBuffer) -> u32; + + /// The `slice()` method returns a new `SharedArrayBuffer` whose contents + /// are a copy of this `SharedArrayBuffer`'s bytes from begin, inclusive, + /// up to end, exclusive. + /// + /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SharedArrayBuffer/slice) + #[wasm_bindgen(method)] + pub fn slice(this: &SharedArrayBuffer, begin: u32) -> SharedArrayBuffer; + + /// Like `slice()` but with the `end` argument. + /// + /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SharedArrayBuffer/slice) + #[wasm_bindgen(method, js_name = slice)] + pub fn slice_with_end(this: &SharedArrayBuffer, begin: u32, end: u32) -> SharedArrayBuffer; +} + // Array Iterator #[wasm_bindgen] extern "C" { @@ -463,6 +504,134 @@ extern "C" { pub fn values(this: &Array) -> Iterator; } +// Atomics +#[wasm_bindge] +extern "C" { + #[derive(Clone, Debug)] + #[wasm_bindgen(extends = Object)] + pub type Atomics; + + /// The static `Atomics.add()` method adds a given value at a given + /// position in the array and returns the old value at that position. + /// This atomic operation guarantees that no other write happens + /// until the modified value is written back. + /// + /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/add) + #[wasm_bindgen(static_method_of = Atomics, catch)] + pub fn add(typed_array: &JsValue, index: u32, value: JsValue) -> Result; + + /// The static `Atomics.and()` method computes a bitwise AND with a given + /// value at a given position in the array, and returns the old value + /// at that position. + /// This atomic operation guarantees that no other write happens + /// until the modified value is written back. + /// + /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/and) + #[wasm_bindgen(static_method_of = Atomics, catch)] + pub fn and(typed_array: &JsValue, index: u32, value: JsValue) -> Result; + + /// The static `Atomics.compareExchange()` method exchanges a given + /// replacement value at a given position in the array, if a given expected + /// value equals the old value. It returns the old value at that position + /// whether it was equal to the expected value or not. + /// This atomic operation guarantees that no other write happens + /// until the modified value is written back. + /// + /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/compareExchange) + #[wasm_bindgen(static_method_of = Atomics, catch, js_name = compareExchange)] + pub fn compare_exchange( + typed_array: &JsValue, + index: u32, + expected_value: &JsValue, + replacement_value: &JsValue, + ) -> Result; + + /// The static `Atomics.exchange()` method stores a given value at a given + /// position in the array and returns the old value at that position. + /// This atomic operation guarantees that no other write happens + /// until the modified value is written back. + /// + /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/exchange) + #[wasm_bindgen(static_method_of = Atomics, catch)] + pub fn exchange(typed_array: &JsValue, index: u32, value: JsValue) -> Result; + + /// The static `Atomics.isLockFree()` method is used to determine + /// whether to use locks or atomic operations. It returns true, + /// if the given size is one of the `BYTES_PER_ELEMENT` property + /// of integer `TypedArray` types. + /// + /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/isLockFree) + #[wasm_bindgen(static_method_of = Atomics, js_name = isLockFree)] + pub fn is_lock_free(size: u32) -> bool; + + /// The static `Atomics.load()` method returns a value at a given + /// position in the array. + /// + /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/load) + #[wasm_bindgen(static_method_of = Atomics, catch)] + pub fn load(typed_array: &JsValue, index: u32) -> Result; + + /// The static `Atomics.notify()` method notifies up some agents that + /// are sleeping in the wait queue. + /// Note: This operation works with a shared `Int32Array` only. + /// + /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/notify) + #[wasm_bindgen(static_method_of = Atomics, catch)] + pub fn notify(typed_array: &JsValue, index: u32, count: u32) -> Result; + + /// The static `Atomics.or()` method computes a bitwise OR with a given value + /// at a given position in the array, and returns the old value at that position. + /// This atomic operation guarantees that no other write happens + /// until the modified value is written back. + /// + /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/or) + #[wasm_bindgen(static_method_of = Atomics, catch)] + pub fn or(typed_array: &JsValue, index: u32, value: JsValue) -> Result; + + /// The static `Atomics.store()` method stores a given value at the given + /// position in the array and returns that value. + /// + /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/store) + #[wasm_bindgen(static_method_of = Atomics, catch)] + pub fn store(typed_array: &JsValue, index: u32, value: JsValue) -> Result; + + /// The static `Atomics.sub()` method substracts a given value at a + /// given position in the array and returns the old value at that position. + /// This atomic operation guarantees that no other write happens + /// until the modified value is written back. + /// + /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/sub) + #[wasm_bindgen(static_method_of = Atomics, catch)] + pub fn sub(typed_array: &JsValue, index: u32, value: JsValue) -> Result; + + /// The static `Atomics.wait()` method verifies that a given + /// position in an `Int32Array` still contains a given value + /// and if so sleeps, awaiting a wakeup or a timeout. + /// It returns a string which is either "ok", "not-equal", or "timed-out". + /// Note: This operation only works with a shared `Int32Array` + /// and may not be allowed on the main thread. + /// + /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/wait) + #[wasm_bindgen(static_method_of = Atomics, catch)] + pub fn wait(typed_array: &JsValue, index: u32, value: JsValue) -> Result; + + /// Like `wait()`, but with timeout + /// + /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/wait) + #[wasm_bindgen(static_method_of = Atomics, catch)] + pub fn wait_with_timeout(typed_array: &JsValue, index: u32, value: JsValue, timeout: u32) -> Result; + + /// The static `Atomics.xor()` method computes a bitwise XOR + /// with a given value at a given position in the array, + /// and returns the old value at that position. + /// This atomic operation guarantees that no other write happens + /// until the modified value is written back. + /// + /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/xor) + #[wasm_bindgen(static_method_of = Atomics, catch)] + pub fn xor(typed_array: &JsValue, index: u32, value: JsValue) -> Result; +} + // Boolean #[wasm_bindgen] extern "C" { From f1eaefdf0daf8edfac487d201fe71996a07da01b Mon Sep 17 00:00:00 2001 From: ibaryshnikov Date: Wed, 24 Apr 2019 00:25:25 +0800 Subject: [PATCH 2/6] fixed value types in Atomics methods --- crates/js-sys/src/lib.rs | 269 +++++++++++++++++++++------------------ 1 file changed, 143 insertions(+), 126 deletions(-) diff --git a/crates/js-sys/src/lib.rs b/crates/js-sys/src/lib.rs index d5ec0b39e90..4432c5154c4 100644 --- a/crates/js-sys/src/lib.rs +++ b/crates/js-sys/src/lib.rs @@ -438,7 +438,6 @@ extern "C" { pub fn slice_with_end(this: &ArrayBuffer, begin: u32, end: u32) -> ArrayBuffer; } - // SharedArrayBuffer #[wasm_bindgen] extern "C" { @@ -504,132 +503,150 @@ extern "C" { pub fn values(this: &Array) -> Iterator; } -// Atomics -#[wasm_bindge] -extern "C" { - #[derive(Clone, Debug)] - #[wasm_bindgen(extends = Object)] - pub type Atomics; - - /// The static `Atomics.add()` method adds a given value at a given - /// position in the array and returns the old value at that position. - /// This atomic operation guarantees that no other write happens - /// until the modified value is written back. - /// - /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/add) - #[wasm_bindgen(static_method_of = Atomics, catch)] - pub fn add(typed_array: &JsValue, index: u32, value: JsValue) -> Result; - - /// The static `Atomics.and()` method computes a bitwise AND with a given - /// value at a given position in the array, and returns the old value - /// at that position. - /// This atomic operation guarantees that no other write happens - /// until the modified value is written back. - /// - /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/and) - #[wasm_bindgen(static_method_of = Atomics, catch)] - pub fn and(typed_array: &JsValue, index: u32, value: JsValue) -> Result; - - /// The static `Atomics.compareExchange()` method exchanges a given - /// replacement value at a given position in the array, if a given expected - /// value equals the old value. It returns the old value at that position - /// whether it was equal to the expected value or not. - /// This atomic operation guarantees that no other write happens - /// until the modified value is written back. - /// - /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/compareExchange) - #[wasm_bindgen(static_method_of = Atomics, catch, js_name = compareExchange)] - pub fn compare_exchange( - typed_array: &JsValue, - index: u32, - expected_value: &JsValue, - replacement_value: &JsValue, - ) -> Result; +/// The `Atomics` object provides atomic operations as static methods. +/// They are used with `SharedArrayBuffer` objects. +/// +/// The Atomic operations are installed on an `Atomics` module. Unlike +/// the other global objects, Atomics is not a constructor. You cannot +/// use it with a new operator or invoke the `Atomics` object as a +/// function. All properties and methods of `Atomics` are static +/// (as is the case with the Math object, for example). +/// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics) +#[allow(non_snake_case)] +pub mod Atomics { + use super::*; + + #[wasm_bindgen] + extern "C" { + #[derive(Clone, Debug)] + #[wasm_bindgen(extends = Object)] + pub type Atomics; + + /// The static `Atomics.add()` method adds a given value at a given + /// position in the array and returns the old value at that position. + /// This atomic operation guarantees that no other write happens + /// until the modified value is written back. + /// + /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/add) + #[wasm_bindgen(static_method_of = Atomics, catch)] + pub fn add(typed_array: &JsValue, index: u32, value: f32) -> Result; + + /// The static `Atomics.and()` method computes a bitwise AND with a given + /// value at a given position in the array, and returns the old value + /// at that position. + /// This atomic operation guarantees that no other write happens + /// until the modified value is written back. + /// + /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/and) + #[wasm_bindgen(static_method_of = Atomics, catch)] + pub fn and(typed_array: &JsValue, index: u32, value: f32) -> Result; + + /// The static `Atomics.compareExchange()` method exchanges a given + /// replacement value at a given position in the array, if a given expected + /// value equals the old value. It returns the old value at that position + /// whether it was equal to the expected value or not. + /// This atomic operation guarantees that no other write happens + /// until the modified value is written back. + /// + /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/compareExchange) + #[wasm_bindgen(static_method_of = Atomics, catch, js_name = compareExchange)] + pub fn compare_exchange( + typed_array: &JsValue, + index: u32, + expected_value: f32, + replacement_value: f32, + ) -> Result; + + /// The static `Atomics.exchange()` method stores a given value at a given + /// position in the array and returns the old value at that position. + /// This atomic operation guarantees that no other write happens + /// until the modified value is written back. + /// + /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/exchange) + #[wasm_bindgen(static_method_of = Atomics, catch)] + pub fn exchange(typed_array: &JsValue, index: u32, value: f32) -> Result; + + /// The static `Atomics.isLockFree()` method is used to determine + /// whether to use locks or atomic operations. It returns true, + /// if the given size is one of the `BYTES_PER_ELEMENT` property + /// of integer `TypedArray` types. + /// + /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/isLockFree) + #[wasm_bindgen(static_method_of = Atomics, js_name = isLockFree)] + pub fn is_lock_free(size: u32) -> bool; + + /// The static `Atomics.load()` method returns a value at a given + /// position in the array. + /// + /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/load) + #[wasm_bindgen(static_method_of = Atomics, catch)] + pub fn load(typed_array: &JsValue, index: u32) -> Result; + + /// The static `Atomics.notify()` method notifies up some agents that + /// are sleeping in the wait queue. + /// Note: This operation works with a shared `Int32Array` only. + /// + /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/notify) + #[wasm_bindgen(static_method_of = Atomics, catch)] + pub fn notify(typed_array: &JsValue, index: u32, count: u32) -> Result; + + /// The static `Atomics.or()` method computes a bitwise OR with a given value + /// at a given position in the array, and returns the old value at that position. + /// This atomic operation guarantees that no other write happens + /// until the modified value is written back. + /// + /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/or) + #[wasm_bindgen(static_method_of = Atomics, catch)] + pub fn or(typed_array: &JsValue, index: u32, value: f32) -> Result; + + /// The static `Atomics.store()` method stores a given value at the given + /// position in the array and returns that value. + /// + /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/store) + #[wasm_bindgen(static_method_of = Atomics, catch)] + pub fn store(typed_array: &JsValue, index: u32, value: f32) -> Result; + + /// The static `Atomics.sub()` method substracts a given value at a + /// given position in the array and returns the old value at that position. + /// This atomic operation guarantees that no other write happens + /// until the modified value is written back. + /// + /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/sub) + #[wasm_bindgen(static_method_of = Atomics, catch)] + pub fn sub(typed_array: &JsValue, index: u32, value: f32) -> Result; + + /// The static `Atomics.wait()` method verifies that a given + /// position in an `Int32Array` still contains a given value + /// and if so sleeps, awaiting a wakeup or a timeout. + /// It returns a string which is either "ok", "not-equal", or "timed-out". + /// Note: This operation only works with a shared `Int32Array` + /// and may not be allowed on the main thread. + /// + /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/wait) + #[wasm_bindgen(static_method_of = Atomics, catch)] + pub fn wait(typed_array: &JsValue, index: u32, value: i32) -> Result; + + /// Like `wait()`, but with timeout + /// + /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/wait) + #[wasm_bindgen(static_method_of = Atomics, catch)] + pub fn wait_with_timeout( + typed_array: &JsValue, + index: u32, + value: i32, + timeout: f32, + ) -> Result; - /// The static `Atomics.exchange()` method stores a given value at a given - /// position in the array and returns the old value at that position. - /// This atomic operation guarantees that no other write happens - /// until the modified value is written back. - /// - /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/exchange) - #[wasm_bindgen(static_method_of = Atomics, catch)] - pub fn exchange(typed_array: &JsValue, index: u32, value: JsValue) -> Result; - - /// The static `Atomics.isLockFree()` method is used to determine - /// whether to use locks or atomic operations. It returns true, - /// if the given size is one of the `BYTES_PER_ELEMENT` property - /// of integer `TypedArray` types. - /// - /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/isLockFree) - #[wasm_bindgen(static_method_of = Atomics, js_name = isLockFree)] - pub fn is_lock_free(size: u32) -> bool; - - /// The static `Atomics.load()` method returns a value at a given - /// position in the array. - /// - /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/load) - #[wasm_bindgen(static_method_of = Atomics, catch)] - pub fn load(typed_array: &JsValue, index: u32) -> Result; - - /// The static `Atomics.notify()` method notifies up some agents that - /// are sleeping in the wait queue. - /// Note: This operation works with a shared `Int32Array` only. - /// - /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/notify) - #[wasm_bindgen(static_method_of = Atomics, catch)] - pub fn notify(typed_array: &JsValue, index: u32, count: u32) -> Result; - - /// The static `Atomics.or()` method computes a bitwise OR with a given value - /// at a given position in the array, and returns the old value at that position. - /// This atomic operation guarantees that no other write happens - /// until the modified value is written back. - /// - /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/or) - #[wasm_bindgen(static_method_of = Atomics, catch)] - pub fn or(typed_array: &JsValue, index: u32, value: JsValue) -> Result; - - /// The static `Atomics.store()` method stores a given value at the given - /// position in the array and returns that value. - /// - /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/store) - #[wasm_bindgen(static_method_of = Atomics, catch)] - pub fn store(typed_array: &JsValue, index: u32, value: JsValue) -> Result; - - /// The static `Atomics.sub()` method substracts a given value at a - /// given position in the array and returns the old value at that position. - /// This atomic operation guarantees that no other write happens - /// until the modified value is written back. - /// - /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/sub) - #[wasm_bindgen(static_method_of = Atomics, catch)] - pub fn sub(typed_array: &JsValue, index: u32, value: JsValue) -> Result; - - /// The static `Atomics.wait()` method verifies that a given - /// position in an `Int32Array` still contains a given value - /// and if so sleeps, awaiting a wakeup or a timeout. - /// It returns a string which is either "ok", "not-equal", or "timed-out". - /// Note: This operation only works with a shared `Int32Array` - /// and may not be allowed on the main thread. - /// - /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/wait) - #[wasm_bindgen(static_method_of = Atomics, catch)] - pub fn wait(typed_array: &JsValue, index: u32, value: JsValue) -> Result; - - /// Like `wait()`, but with timeout - /// - /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/wait) - #[wasm_bindgen(static_method_of = Atomics, catch)] - pub fn wait_with_timeout(typed_array: &JsValue, index: u32, value: JsValue, timeout: u32) -> Result; - - /// The static `Atomics.xor()` method computes a bitwise XOR - /// with a given value at a given position in the array, - /// and returns the old value at that position. - /// This atomic operation guarantees that no other write happens - /// until the modified value is written back. - /// - /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/xor) - #[wasm_bindgen(static_method_of = Atomics, catch)] - pub fn xor(typed_array: &JsValue, index: u32, value: JsValue) -> Result; + /// The static `Atomics.xor()` method computes a bitwise XOR + /// with a given value at a given position in the array, + /// and returns the old value at that position. + /// This atomic operation guarantees that no other write happens + /// until the modified value is written back. + /// + /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/xor) + #[wasm_bindgen(static_method_of = Atomics, catch)] + pub fn xor(typed_array: &JsValue, index: u32, value: f32) -> Result; + } } // Boolean From 0759bfa7e231b7e94e2708cd8107331a866faa0c Mon Sep 17 00:00:00 2001 From: ibaryshnikov Date: Wed, 24 Apr 2019 00:27:15 +0800 Subject: [PATCH 3/6] f32 changed to f64 in Atomics --- crates/js-sys/src/lib.rs | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/crates/js-sys/src/lib.rs b/crates/js-sys/src/lib.rs index 4432c5154c4..abad770a039 100644 --- a/crates/js-sys/src/lib.rs +++ b/crates/js-sys/src/lib.rs @@ -529,7 +529,7 @@ pub mod Atomics { /// /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/add) #[wasm_bindgen(static_method_of = Atomics, catch)] - pub fn add(typed_array: &JsValue, index: u32, value: f32) -> Result; + pub fn add(typed_array: &JsValue, index: u32, value: f64) -> Result; /// The static `Atomics.and()` method computes a bitwise AND with a given /// value at a given position in the array, and returns the old value @@ -539,7 +539,7 @@ pub mod Atomics { /// /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/and) #[wasm_bindgen(static_method_of = Atomics, catch)] - pub fn and(typed_array: &JsValue, index: u32, value: f32) -> Result; + pub fn and(typed_array: &JsValue, index: u32, value: f64) -> Result; /// The static `Atomics.compareExchange()` method exchanges a given /// replacement value at a given position in the array, if a given expected @@ -553,9 +553,9 @@ pub mod Atomics { pub fn compare_exchange( typed_array: &JsValue, index: u32, - expected_value: f32, - replacement_value: f32, - ) -> Result; + expected_value: f64, + replacement_value: f64, + ) -> Result; /// The static `Atomics.exchange()` method stores a given value at a given /// position in the array and returns the old value at that position. @@ -564,7 +564,7 @@ pub mod Atomics { /// /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/exchange) #[wasm_bindgen(static_method_of = Atomics, catch)] - pub fn exchange(typed_array: &JsValue, index: u32, value: f32) -> Result; + pub fn exchange(typed_array: &JsValue, index: u32, value: f64) -> Result; /// The static `Atomics.isLockFree()` method is used to determine /// whether to use locks or atomic operations. It returns true, @@ -580,7 +580,7 @@ pub mod Atomics { /// /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/load) #[wasm_bindgen(static_method_of = Atomics, catch)] - pub fn load(typed_array: &JsValue, index: u32) -> Result; + pub fn load(typed_array: &JsValue, index: u32) -> Result; /// The static `Atomics.notify()` method notifies up some agents that /// are sleeping in the wait queue. @@ -597,14 +597,14 @@ pub mod Atomics { /// /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/or) #[wasm_bindgen(static_method_of = Atomics, catch)] - pub fn or(typed_array: &JsValue, index: u32, value: f32) -> Result; + pub fn or(typed_array: &JsValue, index: u32, value: f64) -> Result; /// The static `Atomics.store()` method stores a given value at the given /// position in the array and returns that value. /// /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/store) #[wasm_bindgen(static_method_of = Atomics, catch)] - pub fn store(typed_array: &JsValue, index: u32, value: f32) -> Result; + pub fn store(typed_array: &JsValue, index: u32, value: f64) -> Result; /// The static `Atomics.sub()` method substracts a given value at a /// given position in the array and returns the old value at that position. @@ -613,7 +613,7 @@ pub mod Atomics { /// /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/sub) #[wasm_bindgen(static_method_of = Atomics, catch)] - pub fn sub(typed_array: &JsValue, index: u32, value: f32) -> Result; + pub fn sub(typed_array: &JsValue, index: u32, value: f64) -> Result; /// The static `Atomics.wait()` method verifies that a given /// position in an `Int32Array` still contains a given value @@ -634,7 +634,7 @@ pub mod Atomics { typed_array: &JsValue, index: u32, value: i32, - timeout: f32, + timeout: f64, ) -> Result; /// The static `Atomics.xor()` method computes a bitwise XOR @@ -645,7 +645,7 @@ pub mod Atomics { /// /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/xor) #[wasm_bindgen(static_method_of = Atomics, catch)] - pub fn xor(typed_array: &JsValue, index: u32, value: f32) -> Result; + pub fn xor(typed_array: &JsValue, index: u32, value: f64) -> Result; } } From de2c2cf26c15efa595d5c76b8f2d43fbd0d20607 Mon Sep 17 00:00:00 2001 From: ibaryshnikov Date: Thu, 25 Apr 2019 19:18:31 +0800 Subject: [PATCH 4/6] fixed Atomics::wait and Atomics::wait_with_timeout return type --- crates/js-sys/src/lib.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/crates/js-sys/src/lib.rs b/crates/js-sys/src/lib.rs index abad770a039..7c5f46f17c6 100644 --- a/crates/js-sys/src/lib.rs +++ b/crates/js-sys/src/lib.rs @@ -624,18 +624,18 @@ pub mod Atomics { /// /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/wait) #[wasm_bindgen(static_method_of = Atomics, catch)] - pub fn wait(typed_array: &JsValue, index: u32, value: i32) -> Result; + pub fn wait(typed_array: &JsValue, index: u32, value: i32) -> Result; /// Like `wait()`, but with timeout /// /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/wait) - #[wasm_bindgen(static_method_of = Atomics, catch)] + #[wasm_bindgen(static_method_of = Atomics, catch, js_name = wait)] pub fn wait_with_timeout( typed_array: &JsValue, index: u32, value: i32, timeout: f64, - ) -> Result; + ) -> Result; /// The static `Atomics.xor()` method computes a bitwise XOR /// with a given value at a given position in the array, From 58245b0587b9f7fa942db704b32636e0ff71fa3a Mon Sep 17 00:00:00 2001 From: ibaryshnikov Date: Fri, 26 Apr 2019 00:02:19 +0800 Subject: [PATCH 5/6] changed String to JsString in Atomics::wait --- crates/js-sys/src/lib.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/js-sys/src/lib.rs b/crates/js-sys/src/lib.rs index 7c5f46f17c6..ef8e7607bdd 100644 --- a/crates/js-sys/src/lib.rs +++ b/crates/js-sys/src/lib.rs @@ -624,7 +624,7 @@ pub mod Atomics { /// /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/wait) #[wasm_bindgen(static_method_of = Atomics, catch)] - pub fn wait(typed_array: &JsValue, index: u32, value: i32) -> Result; + pub fn wait(typed_array: &JsValue, index: u32, value: i32) -> Result; /// Like `wait()`, but with timeout /// @@ -635,7 +635,7 @@ pub mod Atomics { index: u32, value: i32, timeout: f64, - ) -> Result; + ) -> Result; /// The static `Atomics.xor()` method computes a bitwise XOR /// with a given value at a given position in the array, From b05ae44a8c8352423a02b25656b82f6c3e86baee Mon Sep 17 00:00:00 2001 From: ibaryshnikov Date: Fri, 26 Apr 2019 01:56:58 +0800 Subject: [PATCH 6/6] changed f64 to i32 in static methods of Atomics, changed static_method_of to js_namespace, set typed_array type to Int32Array in notify and wait methods --- crates/js-sys/src/lib.rs | 60 +++++++++++++++++++--------------------- 1 file changed, 28 insertions(+), 32 deletions(-) diff --git a/crates/js-sys/src/lib.rs b/crates/js-sys/src/lib.rs index ef8e7607bdd..d7124932ef0 100644 --- a/crates/js-sys/src/lib.rs +++ b/crates/js-sys/src/lib.rs @@ -507,7 +507,7 @@ extern "C" { /// They are used with `SharedArrayBuffer` objects. /// /// The Atomic operations are installed on an `Atomics` module. Unlike -/// the other global objects, Atomics is not a constructor. You cannot +/// the other global objects, `Atomics` is not a constructor. You cannot /// use it with a new operator or invoke the `Atomics` object as a /// function. All properties and methods of `Atomics` are static /// (as is the case with the Math object, for example). @@ -518,18 +518,14 @@ pub mod Atomics { #[wasm_bindgen] extern "C" { - #[derive(Clone, Debug)] - #[wasm_bindgen(extends = Object)] - pub type Atomics; - /// The static `Atomics.add()` method adds a given value at a given /// position in the array and returns the old value at that position. /// This atomic operation guarantees that no other write happens /// until the modified value is written back. /// /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/add) - #[wasm_bindgen(static_method_of = Atomics, catch)] - pub fn add(typed_array: &JsValue, index: u32, value: f64) -> Result; + #[wasm_bindgen(js_namespace = Atomics, catch)] + pub fn add(typed_array: &JsValue, index: u32, value: i32) -> Result; /// The static `Atomics.and()` method computes a bitwise AND with a given /// value at a given position in the array, and returns the old value @@ -538,8 +534,8 @@ pub mod Atomics { /// until the modified value is written back. /// /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/and) - #[wasm_bindgen(static_method_of = Atomics, catch)] - pub fn and(typed_array: &JsValue, index: u32, value: f64) -> Result; + #[wasm_bindgen(js_namespace = Atomics, catch)] + pub fn and(typed_array: &JsValue, index: u32, value: i32) -> Result; /// The static `Atomics.compareExchange()` method exchanges a given /// replacement value at a given position in the array, if a given expected @@ -549,13 +545,13 @@ pub mod Atomics { /// until the modified value is written back. /// /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/compareExchange) - #[wasm_bindgen(static_method_of = Atomics, catch, js_name = compareExchange)] + #[wasm_bindgen(js_namespace = Atomics, catch, js_name = compareExchange)] pub fn compare_exchange( typed_array: &JsValue, index: u32, - expected_value: f64, - replacement_value: f64, - ) -> Result; + expected_value: i32, + replacement_value: i32, + ) -> Result; /// The static `Atomics.exchange()` method stores a given value at a given /// position in the array and returns the old value at that position. @@ -563,8 +559,8 @@ pub mod Atomics { /// until the modified value is written back. /// /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/exchange) - #[wasm_bindgen(static_method_of = Atomics, catch)] - pub fn exchange(typed_array: &JsValue, index: u32, value: f64) -> Result; + #[wasm_bindgen(js_namespace = Atomics, catch)] + pub fn exchange(typed_array: &JsValue, index: u32, value: i32) -> Result; /// The static `Atomics.isLockFree()` method is used to determine /// whether to use locks or atomic operations. It returns true, @@ -572,23 +568,23 @@ pub mod Atomics { /// of integer `TypedArray` types. /// /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/isLockFree) - #[wasm_bindgen(static_method_of = Atomics, js_name = isLockFree)] + #[wasm_bindgen(js_namespace = Atomics, js_name = isLockFree)] pub fn is_lock_free(size: u32) -> bool; /// The static `Atomics.load()` method returns a value at a given /// position in the array. /// /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/load) - #[wasm_bindgen(static_method_of = Atomics, catch)] - pub fn load(typed_array: &JsValue, index: u32) -> Result; + #[wasm_bindgen(js_namespace = Atomics, catch)] + pub fn load(typed_array: &JsValue, index: u32) -> Result; /// The static `Atomics.notify()` method notifies up some agents that /// are sleeping in the wait queue. /// Note: This operation works with a shared `Int32Array` only. /// /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/notify) - #[wasm_bindgen(static_method_of = Atomics, catch)] - pub fn notify(typed_array: &JsValue, index: u32, count: u32) -> Result; + #[wasm_bindgen(js_namespace = Atomics, catch)] + pub fn notify(typed_array: &Int32Array, index: u32, count: u32) -> Result; /// The static `Atomics.or()` method computes a bitwise OR with a given value /// at a given position in the array, and returns the old value at that position. @@ -596,15 +592,15 @@ pub mod Atomics { /// until the modified value is written back. /// /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/or) - #[wasm_bindgen(static_method_of = Atomics, catch)] - pub fn or(typed_array: &JsValue, index: u32, value: f64) -> Result; + #[wasm_bindgen(js_namespace = Atomics, catch)] + pub fn or(typed_array: &JsValue, index: u32, value: i32) -> Result; /// The static `Atomics.store()` method stores a given value at the given /// position in the array and returns that value. /// /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/store) - #[wasm_bindgen(static_method_of = Atomics, catch)] - pub fn store(typed_array: &JsValue, index: u32, value: f64) -> Result; + #[wasm_bindgen(js_namespace = Atomics, catch)] + pub fn store(typed_array: &JsValue, index: u32, value: i32) -> Result; /// The static `Atomics.sub()` method substracts a given value at a /// given position in the array and returns the old value at that position. @@ -612,8 +608,8 @@ pub mod Atomics { /// until the modified value is written back. /// /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/sub) - #[wasm_bindgen(static_method_of = Atomics, catch)] - pub fn sub(typed_array: &JsValue, index: u32, value: f64) -> Result; + #[wasm_bindgen(js_namespace = Atomics, catch)] + pub fn sub(typed_array: &JsValue, index: u32, value: i32) -> Result; /// The static `Atomics.wait()` method verifies that a given /// position in an `Int32Array` still contains a given value @@ -623,15 +619,15 @@ pub mod Atomics { /// and may not be allowed on the main thread. /// /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/wait) - #[wasm_bindgen(static_method_of = Atomics, catch)] - pub fn wait(typed_array: &JsValue, index: u32, value: i32) -> Result; + #[wasm_bindgen(js_namespace = Atomics, catch)] + pub fn wait(typed_array: &Int32Array, index: u32, value: i32) -> Result; /// Like `wait()`, but with timeout /// /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/wait) - #[wasm_bindgen(static_method_of = Atomics, catch, js_name = wait)] + #[wasm_bindgen(js_namespace = Atomics, catch, js_name = wait)] pub fn wait_with_timeout( - typed_array: &JsValue, + typed_array: &Int32Array, index: u32, value: i32, timeout: f64, @@ -644,8 +640,8 @@ pub mod Atomics { /// until the modified value is written back. /// /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/xor) - #[wasm_bindgen(static_method_of = Atomics, catch)] - pub fn xor(typed_array: &JsValue, index: u32, value: f64) -> Result; + #[wasm_bindgen(js_namespace = Atomics, catch)] + pub fn xor(typed_array: &JsValue, index: u32, value: i32) -> Result; } }