1 use webcore::value::Reference;
2 use webcore::try_from::TryInto;
3 use private::TODO;
4 
5 /// The `TokenList` represents a set of space-separated tokens.
6 ///
7 /// [(JavaScript docs)](https://developer.mozilla.org/en-US/docs/Web/API/DOMTokenList)
8 // https://dom.spec.whatwg.org/#domtokenlist
9 #[derive(Clone, Debug, PartialEq, Eq, ReferenceType)]
10 #[reference(instance_of = "DOMTokenList")]
11 pub struct TokenList( Reference );
12 
13 impl TokenList {
14     /// Gets the number of tokens in the list.
15     ///
16     /// [(JavaScript docs)](https://developer.mozilla.org/en-US/docs/Web/API/DOMTokenList/length)
17     // https://dom.spec.whatwg.org/#ref-for-dom-domtokenlist-length
len( &self ) -> u3218     pub fn len( &self ) -> u32 {
19         js!( return @{self}.length; ).try_into().unwrap()
20     }
21 
22     /// Adds token to the underlying string.
23     ///
24     /// [(JavaScript docs)](https://developer.mozilla.org/en-US/docs/Web/API/DOMTokenList/add)
25     // https://dom.spec.whatwg.org/#ref-for-dom-domtokenlist-add
add( &self, token: &str ) -> Result< (), TODO >26     pub fn add( &self, token: &str ) -> Result< (), TODO > {
27         js! { @(no_return)
28             @{self}.add( @{token} );
29         }
30 
31         Ok(())
32     }
33 
34     /// Removes token from the underlying string.
35     ///
36     /// [(JavaScript docs)](https://developer.mozilla.org/en-US/docs/Web/API/DOMTokenList/remove)
37     // https://dom.spec.whatwg.org/#ref-for-dom-domtokenlist-remove
remove( &self, token: &str ) -> Result< (), TODO >38     pub fn remove( &self, token: &str ) -> Result< (), TODO > {
39         js! { @(no_return)
40             @{self}.remove( @{token} );
41         }
42 
43         Ok(())
44     }
45 
46     /// Returns `true` if the underlying string contains token, otherwise `false`.
47     ///
48     /// [(JavaScript docs)](https://developer.mozilla.org/en-US/docs/Web/API/DOMTokenList/contains)
49     // https://dom.spec.whatwg.org/#ref-for-dom-domtokenlist-contains
contains( &self, token: &str ) -> bool50     pub fn contains( &self, token: &str ) -> bool {
51         js!( return @{self}.contains( @{token} ); ).try_into().unwrap()
52     }
53 }
54