Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add AbstractRange and StaticRange interfaces #4221

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@
* Added JSDoc type annotations to C-style enums.
[#4192](https://github.com/rustwasm/wasm-bindgen/pull/4192)

* Added bindings for `StaticRange`.
[#4221](https://github.com/rustwasm/wasm-bindgen/pull/4221)

* Added bindings for `AbstractRange`.
[#4221](https://github.com/rustwasm/wasm-bindgen/pull/4221)
Comment on lines +17 to +21
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lets combine those.


### Changed

* String enums now generate private TypeScript types but only if used.
Expand Down
5 changes: 4 additions & 1 deletion crates/web-sys/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ unexpected_cfgs = { level = "warn", check-cfg = ['cfg(web_sys_unstable_apis)'] }
[features]
AbortController = []
AbortSignal = ["EventTarget"]
AbstractRange = []
AddEventListenerOptions = []
AesCbcParams = []
AesCtrParams = []
Expand Down Expand Up @@ -1057,7 +1058,7 @@ QueryOptions = []
QueuingStrategy = []
QueuingStrategyInit = []
RadioNodeList = ["NodeList"]
Range = []
Range = ["AbstractRange"]
RcwnPerfStats = []
RcwnStatus = []
ReadableByteStreamController = []
Expand Down Expand Up @@ -1270,6 +1271,8 @@ SpeechSynthesisEvent = ["Event"]
SpeechSynthesisEventInit = []
SpeechSynthesisUtterance = ["EventTarget"]
SpeechSynthesisVoice = []
StaticRange = ["AbstractRange"]
StaticRangeInit = []
StereoPannerNode = ["AudioNode", "EventTarget"]
StereoPannerOptions = []
Storage = []
Expand Down
52 changes: 52 additions & 0 deletions crates/web-sys/src/features/gen_AbstractRange.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#![allow(unused_imports)]
#![allow(clippy::all)]
use super::*;
use wasm_bindgen::prelude::*;
#[wasm_bindgen]
extern "C" {
# [wasm_bindgen (extends = :: js_sys :: Object , js_name = AbstractRange , typescript_type = "AbstractRange")]
#[derive(Debug, Clone, PartialEq, Eq)]
#[doc = "The `AbstractRange` class."]
#[doc = ""]
#[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/AbstractRange)"]
#[doc = ""]
#[doc = "*This API requires the following crate features to be activated: `AbstractRange`*"]
pub type AbstractRange;
#[cfg(feature = "Node")]
# [wasm_bindgen (structural , catch , method , getter , js_class = "AbstractRange" , js_name = startContainer)]
#[doc = "Getter for the `startContainer` field of this object."]
#[doc = ""]
#[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/AbstractRange/startContainer)"]
#[doc = ""]
#[doc = "*This API requires the following crate features to be activated: `AbstractRange`, `Node`*"]
pub fn start_container(this: &AbstractRange) -> Result<Node, JsValue>;
# [wasm_bindgen (structural , catch , method , getter , js_class = "AbstractRange" , js_name = startOffset)]
#[doc = "Getter for the `startOffset` field of this object."]
#[doc = ""]
#[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/AbstractRange/startOffset)"]
#[doc = ""]
#[doc = "*This API requires the following crate features to be activated: `AbstractRange`*"]
pub fn start_offset(this: &AbstractRange) -> Result<u32, JsValue>;
#[cfg(feature = "Node")]
# [wasm_bindgen (structural , catch , method , getter , js_class = "AbstractRange" , js_name = endContainer)]
#[doc = "Getter for the `endContainer` field of this object."]
#[doc = ""]
#[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/AbstractRange/endContainer)"]
#[doc = ""]
#[doc = "*This API requires the following crate features to be activated: `AbstractRange`, `Node`*"]
pub fn end_container(this: &AbstractRange) -> Result<Node, JsValue>;
# [wasm_bindgen (structural , catch , method , getter , js_class = "AbstractRange" , js_name = endOffset)]
#[doc = "Getter for the `endOffset` field of this object."]
#[doc = ""]
#[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/AbstractRange/endOffset)"]
#[doc = ""]
#[doc = "*This API requires the following crate features to be activated: `AbstractRange`*"]
pub fn end_offset(this: &AbstractRange) -> Result<u32, JsValue>;
# [wasm_bindgen (structural , method , getter , js_class = "AbstractRange" , js_name = collapsed)]
#[doc = "Getter for the `collapsed` field of this object."]
#[doc = ""]
#[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/AbstractRange/collapsed)"]
#[doc = ""]
#[doc = "*This API requires the following crate features to be activated: `AbstractRange`*"]
pub fn collapsed(this: &AbstractRange) -> bool;
}
2 changes: 1 addition & 1 deletion crates/web-sys/src/features/gen_Range.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use super::*;
use wasm_bindgen::prelude::*;
#[wasm_bindgen]
extern "C" {
# [wasm_bindgen (extends = :: js_sys :: Object , js_name = Range , typescript_type = "Range")]
# [wasm_bindgen (extends = AbstractRange , extends = :: js_sys :: Object , js_name = Range , typescript_type = "Range")]
#[derive(Debug, Clone, PartialEq, Eq)]
#[doc = "The `Range` class."]
#[doc = ""]
Expand Down
23 changes: 23 additions & 0 deletions crates/web-sys/src/features/gen_StaticRange.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#![allow(unused_imports)]
#![allow(clippy::all)]
use super::*;
use wasm_bindgen::prelude::*;
#[wasm_bindgen]
extern "C" {
# [wasm_bindgen (extends = AbstractRange , extends = :: js_sys :: Object , js_name = StaticRange , typescript_type = "StaticRange")]
#[derive(Debug, Clone, PartialEq, Eq)]
#[doc = "The `StaticRange` class."]
#[doc = ""]
#[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/StaticRange)"]
#[doc = ""]
#[doc = "*This API requires the following crate features to be activated: `StaticRange`*"]
pub type StaticRange;
#[cfg(feature = "StaticRangeInit")]
#[wasm_bindgen(catch, constructor, js_class = "StaticRange")]
#[doc = "The `new StaticRange(..)` constructor, creating a new instance of `StaticRange`."]
#[doc = ""]
#[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/StaticRange/StaticRange)"]
#[doc = ""]
#[doc = "*This API requires the following crate features to be activated: `StaticRange`, `StaticRangeInit`*"]
pub fn new(init: &StaticRangeInit) -> Result<StaticRange, JsValue>;
}
99 changes: 99 additions & 0 deletions crates/web-sys/src/features/gen_StaticRangeInit.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
#![allow(unused_imports)]
#![allow(clippy::all)]
use super::*;
use wasm_bindgen::prelude::*;
#[wasm_bindgen]
extern "C" {
# [wasm_bindgen (extends = :: js_sys :: Object , js_name = StaticRangeInit)]
#[derive(Debug, Clone, PartialEq, Eq)]
#[doc = "The `StaticRangeInit` dictionary."]
#[doc = ""]
#[doc = "*This API requires the following crate features to be activated: `StaticRangeInit`*"]
pub type StaticRangeInit;
#[cfg(feature = "Node")]
#[doc = "Get the `endContainer` field of this object."]
#[doc = ""]
#[doc = "*This API requires the following crate features to be activated: `Node`, `StaticRangeInit`*"]
#[wasm_bindgen(method, getter = "endContainer")]
pub fn get_end_container(this: &StaticRangeInit) -> Node;
#[cfg(feature = "Node")]
#[doc = "Change the `endContainer` field of this object."]
#[doc = ""]
#[doc = "*This API requires the following crate features to be activated: `Node`, `StaticRangeInit`*"]
#[wasm_bindgen(method, setter = "endContainer")]
pub fn set_end_container(this: &StaticRangeInit, val: &Node);
#[doc = "Get the `endOffset` field of this object."]
#[doc = ""]
#[doc = "*This API requires the following crate features to be activated: `StaticRangeInit`*"]
#[wasm_bindgen(method, getter = "endOffset")]
pub fn get_end_offset(this: &StaticRangeInit) -> u32;
#[doc = "Change the `endOffset` field of this object."]
#[doc = ""]
#[doc = "*This API requires the following crate features to be activated: `StaticRangeInit`*"]
#[wasm_bindgen(method, setter = "endOffset")]
pub fn set_end_offset(this: &StaticRangeInit, val: u32);
#[cfg(feature = "Node")]
#[doc = "Get the `startContainer` field of this object."]
#[doc = ""]
#[doc = "*This API requires the following crate features to be activated: `Node`, `StaticRangeInit`*"]
#[wasm_bindgen(method, getter = "startContainer")]
pub fn get_start_container(this: &StaticRangeInit) -> Node;
#[cfg(feature = "Node")]
#[doc = "Change the `startContainer` field of this object."]
#[doc = ""]
#[doc = "*This API requires the following crate features to be activated: `Node`, `StaticRangeInit`*"]
#[wasm_bindgen(method, setter = "startContainer")]
pub fn set_start_container(this: &StaticRangeInit, val: &Node);
#[doc = "Get the `startOffset` field of this object."]
#[doc = ""]
#[doc = "*This API requires the following crate features to be activated: `StaticRangeInit`*"]
#[wasm_bindgen(method, getter = "startOffset")]
pub fn get_start_offset(this: &StaticRangeInit) -> u32;
#[doc = "Change the `startOffset` field of this object."]
#[doc = ""]
#[doc = "*This API requires the following crate features to be activated: `StaticRangeInit`*"]
#[wasm_bindgen(method, setter = "startOffset")]
pub fn set_start_offset(this: &StaticRangeInit, val: u32);
}
impl StaticRangeInit {
#[cfg(feature = "Node")]
#[doc = "Construct a new `StaticRangeInit`."]
#[doc = ""]
#[doc = "*This API requires the following crate features to be activated: `Node`, `StaticRangeInit`*"]
pub fn new(
end_container: &Node,
end_offset: u32,
start_container: &Node,
start_offset: u32,
) -> Self {
#[allow(unused_mut)]
let mut ret: Self = ::wasm_bindgen::JsCast::unchecked_into(::js_sys::Object::new());
ret.end_container(end_container);
ret.end_offset(end_offset);
ret.start_container(start_container);
ret.start_offset(start_offset);
ret
}
#[cfg(feature = "Node")]
#[deprecated = "Use `set_end_container()` instead."]
pub fn end_container(&mut self, val: &Node) -> &mut Self {
self.set_end_container(val);
self
}
#[deprecated = "Use `set_end_offset()` instead."]
pub fn end_offset(&mut self, val: u32) -> &mut Self {
self.set_end_offset(val);
self
}
#[cfg(feature = "Node")]
#[deprecated = "Use `set_start_container()` instead."]
pub fn start_container(&mut self, val: &Node) -> &mut Self {
self.set_start_container(val);
self
}
#[deprecated = "Use `set_start_offset()` instead."]
pub fn start_offset(&mut self, val: u32) -> &mut Self {
self.set_start_offset(val);
self
}
}
21 changes: 21 additions & 0 deletions crates/web-sys/src/features/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,13 @@ mod gen_AbortSignal;
#[allow(unused_imports)]
pub use gen_AbortSignal::*;

#[cfg(feature = "AbstractRange")]
#[allow(non_snake_case)]
mod gen_AbstractRange;
#[cfg(feature = "AbstractRange")]
#[allow(unused_imports)]
pub use gen_AbstractRange::*;

#[cfg(feature = "AddEventListenerOptions")]
#[allow(non_snake_case)]
mod gen_AddEventListenerOptions;
Expand Down Expand Up @@ -8636,6 +8643,20 @@ mod gen_SpeechSynthesisVoice;
#[allow(unused_imports)]
pub use gen_SpeechSynthesisVoice::*;

#[cfg(feature = "StaticRange")]
#[allow(non_snake_case)]
mod gen_StaticRange;
#[cfg(feature = "StaticRange")]
#[allow(unused_imports)]
pub use gen_StaticRange::*;

#[cfg(feature = "StaticRangeInit")]
#[allow(non_snake_case)]
mod gen_StaticRangeInit;
#[cfg(feature = "StaticRangeInit")]
#[allow(unused_imports)]
pub use gen_StaticRangeInit::*;

#[cfg(feature = "StereoPannerNode")]
#[allow(non_snake_case)]
mod gen_StereoPannerNode;
Expand Down
23 changes: 23 additions & 0 deletions crates/web-sys/webidls/enabled/AbstractRange.webidl
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

EOL missing.

Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/.
*
* The origin of this IDL file is
* https://dom.spec.whatwg.org/#abstractrange
*
* Copyright © 2012 W3C® (MIT, ERCIM, Keio), All Rights Reserved. W3C
* liability, trademark and document use rules apply.
*/


interface AbstractRange {
[Throws]
readonly attribute Node startContainer;
[Throws]
readonly attribute unsigned long startOffset;
[Throws]
readonly attribute Node endContainer;
[Throws]
readonly attribute unsigned long endOffset;
Comment on lines +14 to +21
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't find anything in the specification saying that this could throw.
I assume you simply copied this from the Firefox webidl directory, but we tend to follow the specification as close as possible.

Let me know if you have different information.

readonly attribute boolean collapsed;
};
4 changes: 2 additions & 2 deletions crates/web-sys/webidls/enabled/Range.webidl
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@
*
* Copyright © 2012 W3C® (MIT, ERCIM, Keio), All Rights Reserved. W3C
* liability, trademark and document use rules apply.
*/
*/
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
*/
*/


[Constructor]
interface Range {
interface Range : AbstractRange {
[Throws]
readonly attribute Node startContainer;
behrenle marked this conversation as resolved.
Show resolved Hide resolved
[Throws]
Expand Down
22 changes: 22 additions & 0 deletions crates/web-sys/webidls/enabled/StaticRange.webidl
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

EOL missing.

Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/.
*
* The origin of this IDL file is
* https://dom.spec.whatwg.org/#staticrange
*
* Copyright © 2012 W3C® (MIT, ERCIM, Keio), All Rights Reserved. W3C
* liability, trademark and document use rules apply.
*/

dictionary StaticRangeInit {
required Node startContainer;
required unsigned long startOffset;
required Node endContainer;
required unsigned long endOffset;
};

[Exposed=Window]
interface StaticRange : AbstractRange {
constructor(StaticRangeInit init);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
constructor(StaticRangeInit init);
[Throws] constructor(StaticRangeInit init);

Constructors are marked as throwing by default, but just in case we want to change this in the future.

};
Loading