Auto merge of #23711 - saschanaz:frompoint, r=Manishearth

Implement DOMPoint.fromPoint

<!-- Please describe your changes on the following line: -->

Implements DOMPoint.fromPoint and fixes codegen to use default value when an optional dictionary member got `undefined`.

PS: The codegen change is about:

```webidl
dictionary MyDictionary {
  optional short myMember = 0;
  short anotherMember;
}

[Exposed=Window, Constructor]
interface MyInterface {
  void myMethod(optional MyDictionary myDict);
};
```

```js
// The following two must behave same
new MyInterface().myMethod({ myMember: undefined, anotherMember = 0 });
new MyInterface().myMethod({ anotherMember = 0 });
```

---
<!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `___` with appropriate data: -->
- [x] `./mach build -d` does not report any errors
- [x] `./mach test-tidy` does not report any errors
- [x] These changes fix #23710

<!-- Either: -->
- [x] There are tests for these changes

<!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.-->

<!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/23711)
<!-- Reviewable:end -->
This commit is contained in:
bors-servo 2019-07-05 15:01:31 -04:00 committed by GitHub
commit aa752e4d45
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
19 changed files with 30 additions and 133 deletions

View file

@ -6414,7 +6414,8 @@ class CGDictionary(CGThing):
conversion = (
"{\n"
" rooted!(in(cx) let mut rval = UndefinedValue());\n"
" if r#try!(get_dictionary_property(cx, object.handle(), \"%s\", rval.handle_mut())) {\n"
" if r#try!(get_dictionary_property(cx, object.handle(), \"%s\", rval.handle_mut()))"
" && !rval.is_undefined() {\n"
"%s\n"
" } else {\n"
"%s\n"

View file

@ -40,6 +40,11 @@ impl DOMPoint {
Ok(DOMPoint::new(global, x, y, z, w))
}
// https://drafts.fxtf.org/geometry/#dom-dompoint-frompoint
pub fn FromPoint(global: &GlobalScope, init: &DOMPointInit) -> DomRoot<Self> {
Self::new_from_init(global, init)
}
pub fn new_from_init(global: &GlobalScope, p: &DOMPointInit) -> DomRoot<DOMPoint> {
DOMPoint::new(global, p.x, p.y, p.z, p.w)
}

View file

@ -2,6 +2,7 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
use crate::dom::bindings::codegen::Bindings::DOMPointBinding::DOMPointInit;
use crate::dom::bindings::codegen::Bindings::DOMPointReadOnlyBinding::{
DOMPointReadOnlyMethods, Wrap,
};
@ -50,6 +51,11 @@ impl DOMPointReadOnly {
) -> Fallible<DomRoot<DOMPointReadOnly>> {
Ok(DOMPointReadOnly::new(global, x, y, z, w))
}
// https://drafts.fxtf.org/geometry/#dom-dompointreadonly-frompoint
pub fn FromPoint(global: &GlobalScope, init: &DOMPointInit) -> DomRoot<Self> {
Self::new(global, init.x, init.y, init.z, init.w)
}
}
impl DOMPointReadOnlyMethods for DOMPointReadOnly {

View file

@ -14,6 +14,8 @@
optional unrestricted double z = 0, optional unrestricted double w = 1),
Exposed=(Window,Worker)]
interface DOMPoint : DOMPointReadOnly {
[NewObject] static DOMPoint fromPoint(optional DOMPointInit other = null);
inherit attribute unrestricted double x;
inherit attribute unrestricted double y;
inherit attribute unrestricted double z;

View file

@ -14,6 +14,8 @@
optional unrestricted double z = 0, optional unrestricted double w = 1),
Exposed=(Window,Worker)]
interface DOMPointReadOnly {
[NewObject] static DOMPointReadOnly fromPoint(optional DOMPointInit other = null);
readonly attribute unrestricted double x;
readonly attribute unrestricted double y;
readonly attribute unrestricted double z;