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

Use ExtendableMessageEvent for messageerror in service workers #25241 #26607

Merged
merged 1 commit into from Jul 31, 2020

Conversation

@nosark
Copy link
Contributor

nosark commented May 21, 2020

added function dispatch_error to the ExtendableMessageEvent implmentation and replaced the MessageEvent dispatch error call with the ExtendableMessageEvent dispatch error call in serviceworkerglobalscope.rs


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

highfive commented May 21, 2020

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

@highfive
Copy link

highfive commented May 21, 2020

Heads up! This PR modifies the following files:

  • @asajeffrey: components/script/dom/extendablemessageevent.rs, components/script/dom/serviceworkerglobalscope.rs
  • @KiChjang: components/script/dom/extendablemessageevent.rs, components/script/dom/serviceworkerglobalscope.rs
@jdm
Copy link
Member

jdm commented May 21, 2020

@highfive highfive assigned gterzian and unassigned nox May 21, 2020
@nosark
Copy link
Contributor Author

nosark commented May 21, 2020

@jdm I followed the coding style in both files, but tidy didn't like, should I alter the format for the changes to please tidy, or leave it as is?

@jdm
Copy link
Member

jdm commented May 21, 2020

Please run ./mach fmt so it will automatically be adjusted to match the style that tidy checks for. Thanks!

@nosark
Copy link
Contributor Author

nosark commented May 21, 2020

Okay, I ran ./ mach fmt and everything should be good to go. If any other edits are needed please let me know!

@gterzian
Copy link
Member

gterzian commented May 22, 2020

Thank you, I will look at it. First question: are the webgl and taskcluster changes related?

Copy link
Member

gterzian left a comment

Looks good, and I think we can further leverage WebIDL to do some work for us.

It also looks to me like some unrelated changes slipped into the PR.

@@ -123,6 +123,21 @@ impl ExtendableMessageEvent {
);
Extendablemessageevent.upcast::<Event>().fire(target);
}

pub fn dispatch_error(target: &EventTarget, scope: &GlobalScope, message: HandleValue) {
let ExtendableMsgEvent = ExtendableMessageEvent::new(

This comment has been minimized.

Copy link
@gterzian

gterzian May 22, 2020

Member

We can do something similar to what is currently done in messageevent.rs, by:

  1. In ExtendableMessageEvent.webidl, un-comment the ports attribute of ExtendableMessageEventInit.
  2. Here, use let init = ExtendableMessageEvent::MessageEventInit::empty();
  3. then use the data from init when calling ExtendableMessageEvent::new.

This comment has been minimized.

Copy link
@nosark

nosark May 22, 2020

Author Contributor

Okay, I'll rewrite and cleanup the newlines. My bad. Thank you!

DOMString::new(),
Vec::<DomRoot<MessagePort>>::new(),
);

This comment has been minimized.

Copy link
@gterzian

gterzian May 22, 2020

Member

nit: I don't think we need the newline here(not something fmt will fix).

This comment has been minimized.

Copy link
@nosark

nosark May 22, 2020

Author Contributor

I'll clean it up. Thank you!

ExtendableMessageEvent::dispatch_error(
target,
scope.upcast(),
message.handle(),

This comment has been minimized.

Copy link
@gterzian

gterzian May 22, 2020

Member

When we will be using ExtendableMessageEvent::MessageEventInit::empty(), we don't need to pass the HandleValue anymore, since it will be part of the empty initialized value.

This comment has been minimized.

Copy link
@nosark

nosark May 22, 2020

Author Contributor

Okay, for some reason I thought we needed the data for the error handling. I apologize I'm newer to the code base. I'll get this fixed right away. Thank you for the input!

@gterzian
Copy link
Member

gterzian commented May 22, 2020

While we are at it, let's also add some spec links to https://github.com/servo/servo/pull/26607/files#diff-ee0d03fc9e0cdadcde40c50bd0f8369eL30

For the struct as a whole it would be https://w3c.github.io/ServiceWorker/#extendablemessageevent-interface

and you'll see below the links for the various members(not complete one to one match but you'll see), for example for data it would be https://w3c.github.io/ServiceWorker/#extendablemessage-event-data

The docs require a triple ///

@nosark
Copy link
Contributor Author

nosark commented May 22, 2020

@gterzian are the changes you're referencing already covered in the above comments? I didn't touch any other files other than manifest (with ./mach update-manifest), extendablemessageevent.rs, and serviceworkerglobalscope.rs. I did pull upstream to keep my fork synced, maybe that caused the unexpected changes?

@gterzian
Copy link
Member

gterzian commented May 22, 2020

I did pull upstream to keep my fork synced, maybe that caused the unexpected changes?

Yes maybe, how did you do it, with a git merge? What we usually do is a rebase, although it's unnecessary unless there are some actual merge conflicts(there is a guide here https://github.com/servo/servo/wiki/Beginner's-guide-to-rebasing-and-squashing).

So the files I am referring to are:

etc/taskcluster/macos/Brewfile-build.lock.json
etc/taskcluster/macos/Brewfile.lock.json
tests/wpt/webgl/tests/resources/npot-video.theora.ogv
tests/wpt/webgl/tests/resources/red-green.theora.ogv

and I think those changes should be removed from the PR(some might have been generated by ./mach update-manifest, which is also unnecessary here since your change did not change any tests).

@nosark
Copy link
Contributor Author

nosark commented May 22, 2020

etc/taskcluster/macos/Brewfile-build.lock.json
etc/taskcluster/macos/Brewfile.lock.json
tests/wpt/webgl/tests/resources/npot-video.theora.ogv
tests/wpt/webgl/tests/resources/red-green.theora.ogv

the test files were changed on the pull from upstream. The etc/... files changed only upon setting up the fork to build in the readme for my environment. Weird.... I run git pull upstream master and I accept any incoming merges if conflicts arise but this last pull I didn't have to resolve any conflicts. I'll read the reabase and squashing doc

@gterzian
Copy link
Member

gterzian commented May 22, 2020

Ok, I think if you rebase those change might go away, if they are already on master? Otherwise It think you can also manually undo them. Let me know if you run into some issues.

I run git pull upstream master and I accept any incoming merges

What I usually do is git fetch upstream(not pull), and then git rebase upstream/master and I only do it if I really want a fix from master, or if there is a merge conflict(which will show up on the PR).

@nosark
Copy link
Contributor Author

nosark commented May 22, 2020

@gterzian I'm not sure I'm following you in regards to the spec links and docs. Could you please elaborate? Should I be adding the spec link above the struct and any other respectively?

@gterzian
Copy link
Member

gterzian commented May 22, 2020

Yes I'm referring to the ExtendableMessageEvent struct, so you could add a doc link for that, in the format

/// <https://w3c.github.io/ServiceWorker/#extendablemessageevent-interface>
#[dom_struct]
#[allow(non_snake_case)]
pub struct ExtendableMessageEvent {}

and then if you look at the members of the struct, you will see some match the IDL definition and have their own link in the spec, and could be separately documented like for example:

/// <https://w3c.github.io/ServiceWorker/#extendablemessage-event-origin>
#[ignore_malloc_size_of = "mozjs"]
data: Heap<JSVal>,
@nosark
Copy link
Contributor Author

nosark commented May 26, 2020

@gterzian I'll add the docs and get my branch rebased. Thank you!

@servo-wpt-sync
Copy link
Collaborator

servo-wpt-sync commented May 26, 2020

Error syncing changes upstream. Logs saved in error-snapshot-1590517887990.

@servo-wpt-sync
Copy link
Collaborator

servo-wpt-sync commented May 26, 2020

Error syncing changes upstream. Logs saved in error-snapshot-1590518520183.

@gterzian
Copy link
Member

gterzian commented May 27, 2020

Great, the actual changes look good, and it looks like some extra commits slipped in as well.

I can't tell exactly what happened, my guess is a git rebase -i HEAD~97, followed by commenting out with # all the commits that are not for this PR, could help.

And then also you can squash your commits into one.

@nosark
Copy link
Contributor Author

nosark commented May 27, 2020

Yeah, I'm not sure. I'll try the rebase and then squash everything into one commit. Thanks @gterzian!

@nosark
Copy link
Contributor Author

nosark commented Jun 1, 2020

I believe everything should be good to go. If any changes need to be made, don't hesitate to ask!
Thanks for all of the help @jdm @gterzian

@nosark nosark force-pushed the nosark:master branch from 0e39654 to ac20509 Jun 2, 2020
Copy link
Member

gterzian left a comment

Ok, thanks for adding the docs and using the empty init. One comment left, and we also need to remove those unrelated changes, I think this can simply be done manually?

And then finally, it will also require a rebase, like:

  1. git fetch upstream(If you haven't added an upstream origin pointing to the main repo, see https://help.github.com/en/github/using-git/adding-a-remote).
  2. git rebase upstream/master.
  3. Fix the conflicts and do git add .(or filename)(make sure there are no other files that will be added, best to first do git status to check for that).
  4. git rebase --continue.

Then it should be good to do.

init.data.handle(),
init.origin.clone().unwrap(),
init.lastEventId.clone().unwrap(),
Vec::<DomRoot<MessagePort>>::new(),

This comment has been minimized.

Copy link
@gterzian

gterzian Jun 2, 2020

Member

init.ports will be available, if you uncomment

This comment has been minimized.

Copy link
@nosark

nosark Jun 4, 2020

Author Contributor

Okay, I'll uncomment this and replace the initialized MessagePort vec with the parents port property.

@@ -0,0 +1,202 @@
{

This comment has been minimized.

Copy link
@gterzian

gterzian Jun 2, 2020

Member

Let's also find a way to remove this file addition from the changes.

This comment has been minimized.

Copy link
@nosark

nosark Jun 4, 2020

Author Contributor

Got it!

@@ -0,0 +1,169 @@
{

This comment has been minimized.

Copy link
@gterzian

gterzian Jun 2, 2020

Member

same for this file.

This comment has been minimized.

Copy link
@nosark

nosark Jun 4, 2020

Author Contributor

Got it!

@@ -8719,7 +8719,7 @@
[]
],
"npot-video.theora.ogv": [
"4458678fbfd81997ee5eff54f8b5e7fbd855264a",
"e2e7a25177072b19cb21be65c57d3b60c48cc9ce",

This comment has been minimized.

Copy link
@gterzian

gterzian Jun 2, 2020

Member

Also this should be undone, I would suggest just manually re-adding the old hashes. And then we need to re-add the binary files that have been removed below.

This comment has been minimized.

Copy link
@nosark

nosark Jun 4, 2020

Author Contributor

Okay, I'll diff the changes to the Manifest.json and copy the old hashes in to replace the changed hashes.

@nosark
Copy link
Contributor Author

nosark commented Jun 26, 2020

@gterzian I'm running into an interesting error. It's the side effect of uncommenting the message port related line in the ExtendableMessageEvent web IDL. Any ideas as to where I should be focusing my effort? Thanks in advance!

error[E0412]: cannot find type `MessagePort` in this scope
   --> /Users/kylenosar/rust-projects/servo/servo/target/debug/build/script-afd592f7b933938c/out/Bindings/ExtendableMessageEventBinding.rs:275:42
    |
275 |     pub ports: Option<Option<Vec<DomRoot<MessagePort>> >>,
    |                                          ^^^^^^^^^^^ not found in this scope
    |
help: possible candidate is found in another module, you can import it into scope
    |
4   | use crate::dom::messageport::MessagePort;
    |
help: you might be missing a type parameter
    |
270 | pub struct ExtendableMessageEventInit<MessagePort> {
    |                                      ^^^^^^^^^^^^^

error[E0283]: type annotations needed
   --> /Users/kylenosar/rust-projects/servo/servo/target/debug/build/script-afd592f7b933938c/out/Bindings/ExtendableMessageEventBinding.rs:275:5
    |
275 |     pub ports: Option<Option<Vec<DomRoot<MessagePort>> >>,
    |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ cannot infer type
    |
    = note: cannot satisfy `_: std::default::Default`
    = note: required by `std::default::Default::default`
    = note: this error originates in a derive macro (in Nightly builds, run with -Z macro-backtrace for more info)

error: aborting due to 2 previous errors
@gterzian
Copy link
Member

gterzian commented Jun 26, 2020

Ok, the solution is the replace the un-commented line with sequence<MessagePort> ports = [];, see the equivalent in MessageEvent.webidl.

@jdm
Copy link
Member

jdm commented Jun 26, 2020

That probably won't be enough - I think our codegen is missing logic for importing types that are only specific in dictionaries. You can work around for right now by adding 'crate::dom::messageport::MessagePort' to

'crate::dom::windowproxy::WindowProxy',
.

@nosark nosark reopened this Jul 19, 2020
@@ -20,5 +20,5 @@ dictionary ExtendableMessageEventInit : ExtendableEventInit {
DOMString origin;
DOMString lastEventId;
// (Client or ServiceWorker /*or MessagePort*/)? source;
// sequence<MessagePort>? ports;
sequence<MessagePort> ports;

This comment has been minimized.

Copy link
@gterzian

gterzian Jul 20, 2020

Member

We can add a bunch of default values to the init, so that it matches https://w3c.github.io/ServiceWorker/#extendablemessageevent

For example:

  • sequence<MessagePort> ports = [];
  • DOMString origin = "";

You can look at MessageEvent.webidl which does the same thing.

That way you can remove the various unwrap following the call to init above.

Copy link
Member

gterzian left a comment

Thanks for sticking through with this, looks like we've almost reached the finish line!

@nosark
Copy link
Contributor Author

nosark commented Jul 21, 2020

@gterzian No problem! we'll get there, so close lol

@nosark
Copy link
Contributor Author

nosark commented Jul 29, 2020

@gterzian @jdm I've added all of the defaults from the ExtendableMessageEvent.webidl and everything is good until I come acrossed the source attribute. It looks like we need to implement GetSource for ExtendableMessageEventMethods and a similar SrcObject enum like

but for a ClientOrServiceWorkerOrMessagePort type similar to
impl From<&WindowProxyOrMessagePortOrServiceWorker> for SrcObject {
to implement GetSource(). Should I implement these as well to finish off extendablemessageevent.rs for now, or should I leave the source commented out in the ExtendableMessageEvent.webidl and commit? Thoughts? Thanks in advance!

@gterzian
Copy link
Member

gterzian commented Jul 30, 2020

Thanks for looking into it, we can leave source commented-out in this PR, that work is tracked over at #24659

@nosark
Copy link
Contributor Author

nosark commented Jul 30, 2020

Okay cool. Thanks @gterzian !

Copy link
Member

gterzian left a comment

I think it would be good to go following a squash of the two commits into one.

@nosark nosark force-pushed the nosark:master branch from 2f5b73a to 95ddcf5 Jul 30, 2020
@nosark
Copy link
Contributor Author

nosark commented Jul 30, 2020

@gterzian Done! Thanks for all of your help!

@gterzian
Copy link
Member

gterzian commented Jul 31, 2020

Great work!

@bors-servo r+

@bors-servo
Copy link
Contributor

bors-servo commented Jul 31, 2020

📌 Commit 95ddcf5 has been approved by gterzian

@bors-servo
Copy link
Contributor

bors-servo commented Jul 31, 2020

Testing commit 95ddcf5 with merge edc7ca7...

bors-servo added a commit that referenced this pull request Jul 31, 2020
Use ExtendableMessageEvent for messageerror in service workers #25241

<!-- Please describe your changes on the following line: -->
added function dispatch_error to the ExtendableMessageEvent implmentation and replaced the MessageEvent dispatch error call with the ExtendableMessageEvent dispatch error call in serviceworkerglobalscope.rs

---
<!-- 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 #25241 (GitHub issue number if applicable)

<!-- Either: -->
- [x] There are tests for these changes OR
- [x] 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. -->
@nosark
Copy link
Contributor Author

nosark commented Jul 31, 2020

@gterzian thanks!

@bors-servo
Copy link
Contributor

bors-servo commented Jul 31, 2020

💔 Test failed - status-taskcluster

@gterzian
Copy link
Member

gterzian commented Jul 31, 2020

@bors-servo retry

0 matches
1 unexpected results that are NOT known-intermittents:
  ▶ FAIL [expected PASS] /css/css-text/text-align/text-align-end-010.html
  │   → /css/css-text/text-align/text-align-end-010.html ['f391d36b6f045c5cf9c439e0086f5fab5194f0c0']
  └   → /css/css-text/text-align/reference/text-align-end-ref-010.html ['b8cc0962b8e55a9684b327cddb76f385328b328d']

I think this is #23290

@bors-servo
Copy link
Contributor

bors-servo commented Jul 31, 2020

Testing commit 95ddcf5 with merge 9b6b793...

@nosark
Copy link
Contributor Author

nosark commented Jul 31, 2020

@gterzian Okay, I saw the failure and was about to ask. If it isn't related to #23290, let me know and I'll take a look in the morning!

@bors-servo
Copy link
Contributor

bors-servo commented Jul 31, 2020

☀️ Test successful - status-taskcluster
Approved by: gterzian
Pushing 9b6b793 to master...

@bors-servo bors-servo merged commit 9b6b793 into servo:master Jul 31, 2020
2 checks passed
2 checks passed
Community-TC (pull_request) TaskGroup: success
Details
homu Test successful
Details
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.

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