summaryrefslogtreecommitdiffstats
path: root/vendor/js-sys/tests/headless.rs
blob: aafa6b0ae2ac4a174bf862b1cd5d28c0ddde63b7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#![cfg(target_arch = "wasm32")]

extern crate js_sys;
extern crate wasm_bindgen;
extern crate wasm_bindgen_test;

use js_sys::Array;
use wasm_bindgen::prelude::*;
use wasm_bindgen_test::*;

wasm_bindgen_test_configure!(run_in_browser);

#[wasm_bindgen(module = "/tests/headless.js")]
extern "C" {
    fn is_array_values_supported() -> bool;
}

#[wasm_bindgen]
extern "C" {
    type ValuesIterator;
    #[wasm_bindgen(method, structural)]
    fn next(this: &ValuesIterator) -> IterNext;

    type IterNext;

    #[wasm_bindgen(method, getter, structural)]
    fn value(this: &IterNext) -> JsValue;
    #[wasm_bindgen(method, getter, structural)]
    fn done(this: &IterNext) -> bool;
}

#[wasm_bindgen_test]
fn array_iterator_values() {
    if !is_array_values_supported() {
        return;
    }
    let array = Array::new();
    array.push(&8.into());
    array.push(&3.into());
    array.push(&2.into());
    let iter = ValuesIterator::from(JsValue::from(array.values()));

    assert_eq!(iter.next().value(), 8);
    assert_eq!(iter.next().value(), 3);
    assert_eq!(iter.next().value(), 2);
    assert!(iter.next().done());
}