Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upWebIDL HTMLConstructor support #17224
Conversation
highfive
commented
Jun 8, 2017
|
Heads up! This PR modifies the following files:
|
highfive
commented
Jun 8, 2017
|
This is getting close to done. I am new to a lot of the jsapi stuff and codegen, so any feedback there would be very helpful! cc @jdm |
| return Err(Error::Type("Active function object is not HTMLElement".to_owned())); | ||
| } | ||
| } else { | ||
| // TODO: Step 5 |
This comment has been minimized.
This comment has been minimized.
cbrewster
Jun 8, 2017
Author
Member
I'm not quite sure how to do step 5. I think there are two potential options:
- Get a list of local names from the callee. I am not even sure if this is possible.
- Get a
ConstructorObjectfrom the definition's local name and compare it to thecallee. But we don't generateGetConstructorObjectfor most of the HTML interfaces.
This comment has been minimized.
This comment has been minimized.
jdm
Jun 12, 2017
Member
Given the commit that adds HTMLConstructor to the HTML interfaces, do we not generate GetConstructorObjects for them now?
This comment has been minimized.
This comment has been minimized.
cbrewster
Jun 12, 2017
Author
Member
We only generate GetConstructorObject for interfaces that are a namespace, callback, or have descendants.
Configuration.py#L397-L401
This comment has been minimized.
This comment has been minimized.
jdm
Jun 12, 2017
Member
Gecko is much more liberal; we can follow their lead: https://dxr.mozilla.org/mozilla-central/source/dom/bindings/Codegen.py#12826-12828
This comment has been minimized.
This comment has been minimized.
nox
Jun 13, 2017
Member
Yeah, not generating GetConstructorObject for leaf interfaces was just me trimming a bit of unneeded codegen, but if it's not unneeded anymore, just make it generate the function again.
5ca7cca
to
ccd5acf
|
Changes to |
|
|
|
Good start! |
| let registry = window.CustomElements(); | ||
| let document = window.Document(); | ||
|
|
||
| // Step 2 in codegen |
This comment has been minimized.
This comment has been minimized.
| // Step 2 https://html.spec.whatwg.org/multipage/#htmlconstructor | ||
| // The custom element definition cannot use an element interface as its constructor | ||
| rooted!(in(cx) let new_target = UnwrapObject(args.new_target().to_object(), 1)); |
This comment has been minimized.
This comment has been minimized.
jdm
Jun 12, 2017
Member
Add this from Gecko's implementation:
// The new_target might be a cross-compartment wrapper. Get the underlying object
// so we can do the spec's object-identity checks.
| throw_dom_exception(cx, global.upcast::<GlobalScope>(), Error::Type("new.target is null".to_owned())); | ||
| } | ||
| { |
This comment has been minimized.
This comment has been minimized.
jdm
Jun 12, 2017
Member
Add this from Gecko:
// Step 2 of https://html.spec.whatwg.org/multipage/dom.html#htmlconstructor.
// Enter the compartment of our underlying new_target object, so we end
// up comparing to the constructor object for our interface from that global.
| prefix: Option<Prefix>, | ||
| document: &Document, | ||
| creator: ElementCreator) | ||
| -> Root<Element> { |
This comment has been minimized.
This comment has been minimized.
| @@ -63,6 +63,12 @@ impl CustomElementRegistry { | |||
| self.when_defined.borrow_mut().clear() | |||
| } | |||
|
|
|||
| pub fn lookup_definition_by_constructor(&self, constructor: HandleObject) -> Option<CustomElementDefinition> { | |||
This comment has been minimized.
This comment has been minimized.
| // Step 7 | ||
| rooted!(in(cx) let global_object = CurrentGlobalOrNull(cx)); | ||
| GetProtoObject(cx, global_object.handle(), prototype.handle_mut()); | ||
| if prototype.is_null() { |
This comment has been minimized.
This comment has been minimized.
| } | ||
| if !proto_val.is_object() { | ||
| // Step 7 |
This comment has been minimized.
This comment has been minimized.
jdm
Jun 12, 2017
Member
Please add the comment from https://dxr.mozilla.org/mozilla-central/source/dom/bindings/Codegen.py#1832-1839.
| @@ -158,6 +167,26 @@ pub unsafe fn create_global_object( | |||
| JS_FireOnNewGlobalObject(cx, rval.handle()); | |||
| } | |||
|
|
|||
| // https://html.spec.whatwg.org/multipage/dom.html#htmlconstructor | |||
| pub fn create_html_element(window: &Window, call_args: CallArgs) -> Fallible<Root<HTMLElement>> { | |||
This comment has been minimized.
This comment has been minimized.
| @@ -228,27 +233,42 @@ impl CustomElementRegistryMethods for CustomElementRegistry { | |||
| } | |||
| } | |||
|
|
|||
| #[derive(HeapSizeOf, JSTraceable, PartialEq, Clone)] | |||
| pub enum ConstructionEntry { | |||
| Element(Root<HTMLElement>), | |||
This comment has been minimized.
This comment has been minimized.
| Some(entry) => { | ||
| let result = match *entry { | ||
| ConstructionEntry::AlreadyConstructed => return Err(Error::InvalidState), | ||
| ConstructionEntry::Element(ref mut element) => { |
This comment has been minimized.
This comment has been minimized.
|
17d6364
to
5cfbc5f
e6c2025
to
6c0b6c3
|
r=me once the function is moved. |
|
|
||
| /// Returns the constructor object for the element associated with the given local name. | ||
| /// This list should only include elements marked with the [HTMLConstructor] extended attribute. | ||
| pub fn get_constructor_object_from_local_name(name: LocalName, |
This comment has been minimized.
This comment has been minimized.
|
@bors-servo r=jdm |
|
|
WebIDL HTMLConstructor support <!-- Please describe your changes on the following line: --> spec: https://html.spec.whatwg.org/multipage/#htmlconstructor --- <!-- 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 #17194 (github issue number if applicable). <!-- Either: --> - [X] There are tests for these changes OR - [ ] These changes do not require tests because _____ <!-- 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/17224) <!-- Reviewable:end -->
|
|
Upstreamed from servo/servo#17224 [ci skip]
cbrewster commentedJun 8, 2017
•
edited by larsbergstrom
spec: https://html.spec.whatwg.org/multipage/#htmlconstructor
./mach build -ddoes not report any errors./mach test-tidydoes not report any errorsThis change is