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 trait DomObjectWrap to provide WRAP function #25624

Merged
merged 1 commit into from Mar 21, 2020

Conversation

@lyuyuan
Copy link
Contributor

lyuyuan commented Jan 27, 2020


  • ./mach build -d does not report any errors
  • ./mach test-tidy does not report any errors
  • These changes fix #8576 (GitHub issue number if applicable)
  • There are tests for these changes OR
  • These changes do not require tests because ___
@highfive
Copy link

highfive commented Jan 27, 2020

Thanks for the pull request, and welcome! The Servo team is excited to review your changes, and you should hear from @paulrouget (or someone else) soon.

@highfive
Copy link

highfive commented Jan 27, 2020

Heads up! This PR modifies the following files:

  • @asajeffrey: components/script/dom/webgl_extensions/ext/angleinstancedarrays.rs, components/script/dom/bindings/reflector.rs
  • @KiChjang: components/script/dom/webgl_extensions/ext/angleinstancedarrays.rs, components/script/dom/bindings/reflector.rs
@highfive
Copy link

highfive commented Jan 27, 2020

warning Warning warning

  • These commits modify unsafe code. Please review it carefully!
  • These commits modify script code, but no tests are modified. Please consider adding a test!
@lyuyuan lyuyuan force-pushed the lyuyuan:issue-8576 branch 4 times, most recently from 140775b to 205e619 Jan 28, 2020
@lyuyuan
Copy link
Contributor Author

lyuyuan commented Jan 31, 2020

@jdm I have tried adding the DomObjectWrap trait implementation in the derive macro. But there are some interface do not provide the Wrap function. And WindowProxy doesn't have a generated binding. The build errors can be found here.

@jdm
Copy link
Member

jdm commented Feb 1, 2020

Ok, there's an interesting mixture here:

  • some interfaces (eg. GlobalScope, CSS, CharacterData) are marked [Abstract] in the WebIDL, meaning there is no way to create a reflector that has that particular concrete type (but interfaces that inherit from those interfaces are fine). This is why there's no Wrap method present.
  • other interfaces (eg. Headers, FormData) come from WebIDL files that contain multiple types like an interface with an iterator. This means the exported names are in the form {$name}Wrap instead (ie. FormDataWrap).
  • some interfaces (eg. Promise, WindowProxy) have the [NoInterfaceObject] marking in the WebIDL, so there is no way to create a reflector for those types, so there is no Wrap method present.

I think a reasonable choice here is:

  • change the code generation to always export the ${name}Wrap form for all interfaces, and use that form in the dom_struct plugin
  • define a invalid_wrap_function_do_not_use function in components/script/dom/bindings/reflector.rs that panics
  • for interfaces that do not generate a Wrap method, change the code generation to add a pub use crate::dom::bindings::reflector::invalid_wrap_function_do_not_use as Wrap
@lyuyuan lyuyuan force-pushed the lyuyuan:issue-8576 branch from 205e619 to ef1661c Feb 10, 2020
@lyuyuan
Copy link
Contributor Author

lyuyuan commented Feb 20, 2020

Hi @jdm

change the code generation to always export the ${name}Wrap form for all interfaces, and use that form in the dom_struct plugin

This seems to break the code in htmlconstructor, as it makes all HTML element bindings reexport the GetConstructorObject method in the form of ${name}GetConstructorObject.

I am modifying the get_constructor macro to adapt this change. Does it sound right?

@jdm
Copy link
Member

jdm commented Feb 20, 2020

That sounds reasonable for now.

@lyuyuan lyuyuan force-pushed the lyuyuan:issue-8576 branch from ef1661c to 0f3bc97 Feb 21, 2020
@lyuyuan lyuyuan changed the title WIP: Add WRAP function pointer to DomObject trait WIP: Add trait DomObjectWrap to provide WRAP function Feb 21, 2020
@bors-servo
Copy link
Contributor

bors-servo commented Feb 21, 2020

The latest upstream changes (presumably #25784) made this pull request unmergeable. Please resolve the merge conflicts.

@jdm
Copy link
Member

jdm commented Feb 21, 2020

This looks like a nice improvement so far! Is this PR still WIP, or is the next step to review the code?

@lyuyuan
Copy link
Contributor Author

lyuyuan commented Feb 21, 2020

Hi @jdm I am still working on some build errors caused by my change. I will switch it ready-for-review once I fix them. Thanks!

@jdm jdm assigned jdm and unassigned paulrouget Feb 21, 2020
@lyuyuan lyuyuan force-pushed the lyuyuan:issue-8576 branch from 0f3bc97 to 3c320c1 Mar 1, 2020
@lyuyuan lyuyuan force-pushed the lyuyuan:issue-8576 branch from 3c320c1 to 86251b9 Mar 2, 2020
@lyuyuan
Copy link
Contributor Author

lyuyuan commented Mar 2, 2020

Hi @jdm , sorry to bother you again. How to get Wrap function implemented in IterableIteratorBinding? I have added this in CodegenRust.py, but the iterable interface still misses it.
Edit: I figured it out. IterableIterator has zero descriptor, so it won't hit the code that generates Wrap.

@bors-servo
Copy link
Contributor

bors-servo commented Mar 2, 2020

The latest upstream changes (presumably #25781) made this pull request unmergeable. Please resolve the merge conflicts.

@@ -119,6 +117,11 @@ impl<T: DomObject + JSTraceable + Iterable> IterableIterator<T> {
}
}

impl<T: DomObject + DomObjectWrap + JSTraceable + Iterable> DomObjectWrap for IterableIterator<T> {
const WRAP: unsafe fn(JSContext, &GlobalScope, Box<Self>) -> Root<Dom<Self>> =

This comment has been minimized.

Copy link
@jdm

jdm Mar 19, 2020

Member

What is the code that requires a DomObjectWrap implementation for IterableIterator? It's hard for me to figure out if this WRAP will be called anywhere - it looks like it will be used by IterableIterator::new, which doesn't seem like it will work.

This comment has been minimized.

Copy link
@lyuyuan

lyuyuan Mar 19, 2020

Author Contributor

You are right. WPT crashed when executing IterableIterator::new 😢.

This comment has been minimized.

Copy link
@lyuyuan

lyuyuan Mar 21, 2020

Author Contributor

IterableIterator::new calls reflect_dom_object<T, U> which requires T implements DomObjectWrap. This requires IterableIterator implements the trait.

@@ -6286,6 +6309,8 @@ def reexportedName(name):
cgThings.append(CGWrapGlobalMethod(descriptor, properties))
else:
cgThings.append(CGWrapMethod(descriptor))
if not descriptor.interface.isIteratorInterface():

This comment has been minimized.

Copy link
@jdm

jdm Mar 19, 2020

Member

Why can we not generate a DomObjectWrap implementation for iterator interfaces?

This comment has been minimized.

Copy link
@lyuyuan

lyuyuan Mar 21, 2020

Author Contributor

Sorry for making this mistake. For interfaces that provides Wrap function for both itself and IterableIterator (FormData, Header...), I introduced another trait DomObjectIteratorWrap which provides a const ITER_WRAP that points to the iterator Wrap function. Then, IterableIterator<T>::WRAP could point to T::ITER_WRAP, therefore, implements the DomObjectWrap trait.

@jdm
Copy link
Member

jdm commented Mar 19, 2020

Overall I'm really excited about these changes!
@bors-servo try=wpt

@bors-servo
Copy link
Contributor

bors-servo commented Mar 19, 2020

Trying commit 24c90ac with merge 554f14c...

bors-servo added a commit that referenced this pull request Mar 19, 2020
Add trait DomObjectWrap to provide WRAP function

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

---
<!-- 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
- [ ] These changes fix #8576 (GitHub issue number if applicable)

<!-- Either: -->
- [ ] 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. -->
@bors-servo
Copy link
Contributor

bors-servo commented Mar 19, 2020

💔 Test failed - status-taskcluster

@jdm
Copy link
Member

jdm commented Mar 19, 2020

Indeed:

  ▶ CRASH [expected OK] /fetch/api/redirect/redirect-location.any.worker.html
  │ 
  │ 
  │ 
  │ 
  │ Invalid wrap function, do not use (thread WebWorker for http://web-platform.test:8000/fetch/api/redirect/redirect-location.any.worker.js, at components/script/dom/bindings/reflector.rs:121)
  │ stack backtrace:
  │    0: servo::backtrace::print
  │    1: servo::main::{{closure}}
  │    2: std::panicking::rust_panic_with_hook
  │              at src/libstd/panicking.rs:513
  │    3: std::panicking::begin_panic
  │    4: script::dom::bindings::iterable::IterableIterator<T>::new
  │    5: <std::panic::AssertUnwindSafe<F> as core::ops::function::FnOnce<()>>::call_once
  │    6: script::dom::bindings::codegen::Bindings::HeadersBinding::HeadersBinding::entries
  │    7: CallJitMethodOp
  │    8: script::dom::bindings::utils::generic_call

  ▶ CRASH [expected OK] /WebIDL/ecmascript-binding/default-iterator-object.html
  │ 
  │ 
  │ 
  │ 
  │ Invalid wrap function, do not use (thread ScriptThread PipelineId { namespace_id: PipelineNamespaceId(1), index: PipelineIndex(1) }, at components/script/dom/bindings/reflector.rs:121)
  │ stack backtrace:
  │    0: servo::backtrace::print
  │    1: servo::main::{{closure}}
  │    2: std::panicking::rust_panic_with_hook
  │              at src/libstd/panicking.rs:513
  │    3: std::panicking::begin_panic
  │    4: script::dom::bindings::iterable::IterableIterator<T>::new
  │    5: <std::panic::AssertUnwindSafe<F> as core::ops::function::FnOnce<()>>::call_once
  │    6: script::dom::bindings::codegen::Bindings::URLSearchParamsBinding::URLSearchParamsBinding::entries
  │    7: CallJitMethodOp
  │    8: script::dom::bindings::utils::generic_call
@lyuyuan lyuyuan force-pushed the lyuyuan:issue-8576 branch from 24c90ac to 3ea6d87 Mar 21, 2020
@jdm
Copy link
Member

jdm commented Mar 21, 2020

Great solution!
@bors-servo r+

@bors-servo
Copy link
Contributor

bors-servo commented Mar 21, 2020

📌 Commit 3ea6d87 has been approved by jdm

@bors-servo
Copy link
Contributor

bors-servo commented Mar 21, 2020

Testing commit 3ea6d87 with merge 0a272c2...

bors-servo added a commit that referenced this pull request Mar 21, 2020
Add trait DomObjectWrap to provide WRAP function

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

---
<!-- 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
- [ ] These changes fix #8576 (GitHub issue number if applicable)

<!-- Either: -->
- [ ] 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. -->
@bors-servo
Copy link
Contributor

bors-servo commented Mar 21, 2020

💔 Test failed - status-taskcluster

@jdm
Copy link
Member

jdm commented Mar 21, 2020

@bors-servo
Copy link
Contributor

bors-servo commented Mar 21, 2020

Testing commit 3ea6d87 with merge 67b4336...

@bors-servo
Copy link
Contributor

bors-servo commented Mar 21, 2020

☀️ Test successful - status-taskcluster
Approved by: jdm
Pushing 67b4336 to master...

@bors-servo bors-servo merged commit 67b4336 into servo:master Mar 21, 2020
2 checks passed
2 checks passed
Community-TC (pull_request) TaskGroup: success
Details
homu Test successful
Details
@bors-servo bors-servo mentioned this pull request Mar 21, 2020
0 of 5 tasks complete
@lyuyuan lyuyuan deleted the lyuyuan:issue-8576 branch Mar 21, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

6 participants
You can’t perform that action at this time.