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

Implement ExtendableEvent as base type for ServiceWorker events #13292

Merged
merged 1 commit into from Sep 17, 2016

Conversation

@creativcoder
Copy link
Contributor

creativcoder commented Sep 16, 2016

r? @jdm


  • ./mach build -d does not report any errors
  • ./mach test-tidy does not report any errors
  • These changes fix #__ (github issue number if applicable).
  • These changes do not require tests because refactor

This change is Reviewable

@highfive
Copy link

highfive commented Sep 16, 2016

Heads up! This PR modifies the following files:

  • @KiChjang: components/script/dom/webidls/ExtendableEvent.webidl, components/script/dom/mod.rs, components/script/dom/webidls/ExtendableMessageEvent.webidl, components/script/dom/extendablemessageevent.rs, components/script/dom/extendableevent.rs, components/script/dom/serviceworkerglobalscope.rs
@highfive
Copy link

highfive commented Sep 16, 2016

warning Warning warning

  • These commits modify script code, but no tests are modified. Please consider adding a test!
@creativcoder creativcoder force-pushed the creativcoder:extendable branch from 69e6765 to 1b7e0ae Sep 16, 2016

fn dispatch_activate(&self) {
let event = ExtendableEvent::new(GlobalRef::Worker(self.upcast::<WorkerGlobalScope>()),
atom!("activate"),

This comment has been minimized.

@jdm

jdm Sep 16, 2016

Member

nit: indentation

[Constructor(DOMString type,
optional ExtendableEventInit eventInitDict),
Exposed=ServiceWorker,
Pref="dom.serviceworker.enabled" ]

This comment has been minimized.

@jdm

jdm Sep 16, 2016

Member

nit: remove the extra space before ]


[ Constructor(DOMString type, optional ExtendableMessageEventInit eventInitDict),
Exposed=ServiceWorker,
Pref="dom.serviceworker.enabled" ]

This comment has been minimized.

@jdm

jdm Sep 16, 2016

Member

nit: remove the extra space after [ and before ]

impl ExtendableMessageEvent {
pub fn new_uninitialized(global: GlobalRef) -> Root<ExtendableMessageEvent> {
ExtendableMessageEvent::new_initialized(global,
HandleValue::undefined(),

This comment has been minimized.

@jdm

jdm Sep 16, 2016

Member

nit: indentation

extensions_allowed: true
}
}
pub fn new_uninitialized(global: GlobalRef) -> Root<ExtendableEvent> {

This comment has been minimized.

@jdm

jdm Sep 16, 2016

Member

I don't see any need to have the split between initialized/uninitialized. That's only for older event types that can be created in an uninitialized states.

init.parent.cancelable))
}

fn init_extendable_event(&self,

This comment has been minimized.

@jdm

jdm Sep 16, 2016

Member

Let's move the initialization into new directly.

DOMString::new())
}

pub fn new_initialized(global: GlobalRef,

This comment has been minimized.

@jdm

jdm Sep 16, 2016

Member

No need for the initialized/uninitialized split.

pub fn WaitUntil(&self, _cx: *mut JSContext, val: HandleValue) {
// Step 1
if !self.extensions_allowed {
// TODO throw invalid state error, but this does not return a `Fallible` ?

This comment has been minimized.

@jdm

jdm Sep 16, 2016

Member

Add [Throws] to the webidl method.

type_: DOMString,
init: &ExtendableEventBinding::ExtendableEventInit) -> Fallible<Root<ExtendableEvent>> {
Ok(ExtendableEvent::new(global,
Atom::from(type_),

This comment has been minimized.

@jdm

jdm Sep 16, 2016

Member

nit: indentation.

@creativcoder creativcoder force-pushed the creativcoder:extendable branch from 1b7e0ae to 55ee2db Sep 16, 2016
@jdm jdm assigned jdm and unassigned larsbergstrom Sep 16, 2016
@creativcoder creativcoder force-pushed the creativcoder:extendable branch from 58a9301 to c06c2b4 Sep 16, 2016
Copy link
Member

jdm left a comment

The indentation in dispatch_activate is still incorrect.

let ev = reflect_dom_object(box ExtendableEvent::new_inherited(), global, ExtendableEventBinding::Wrap);
{
let ev = ev.upcast::<Event>();
if !ev.dispatching() {

This comment has been minimized.

@jdm

jdm Sep 16, 2016

Member

No need for this; we can't be dispatching in the constructor.

DOMString::new(),
DOMString::new())
}

pub fn new_initialized(global: GlobalRef,

This comment has been minimized.

@jdm

jdm Sep 16, 2016

Member

This can be called new.

Copy link
Member

jdm left a comment

We can include the update to string_cache now, since it's been published.

reflect_dom_object(box ExtendableEvent::new_inherited(),
global,
ExtendableEventBinding::Wrap)
}
pub fn new(global: GlobalRef,
type_: Atom,
bubbles: bool,
cancelable: bool)

This comment has been minimized.

@jdm

jdm Sep 16, 2016

Member

These aren't used now, are they?

This comment has been minimized.

@creativcoder

creativcoder Sep 17, 2016

Author Contributor

Yes, in event.init_event(). Made changes.

let ev = ExtendableEvent::new_uninitialized(global);
ev.init_extendable_event(type_, bubbles, cancelable);
ev
reflect_dom_object(box ExtendableEvent::new_inherited(), global, ExtendableEventBinding::Wrap)
}

pub fn Constructor(global: GlobalRef,
type_: DOMString,
init: &ExtendableEventBinding::ExtendableEventInit) -> Fallible<Root<ExtendableEvent>> {

This comment has been minimized.

@jdm

jdm Sep 16, 2016

Member

nit: indentation.

}

// https://w3c.github.io/ServiceWorker/#wait-until-method
pub fn WaitUntil(&self, _cx: *mut JSContext, val: HandleValue) {
pub fn WaitUntil(&self, _cx: *mut JSContext, val: HandleValue) -> Fallible<()> {

This comment has been minimized.

@jdm

jdm Sep 16, 2016

Member

We can use ErrorResult instead of Fallible<()>.

{
let event = ev.upcast::<Event>();
event.init_event(type_, bubbles, cancelable);
}
ev
reflect_dom_object(ev, global, ExtendableMessageEventBinding::Wrap)

This comment has been minimized.

@jdm

jdm Sep 16, 2016

Member

We should reflect the object as soon as possible after creating it, otherwise we risk GC-unsafety.

@creativcoder creativcoder force-pushed the creativcoder:extendable branch from bddb13a to 1533d3e Sep 17, 2016
@creativcoder creativcoder force-pushed the creativcoder:extendable branch from 1533d3e to 10d43c6 Sep 17, 2016
@@ -38,11 +38,12 @@ impl ExtendableMessageEvent {
lastEventId: lastEventId,
};
ev.data.set(data.get());
let ev = reflect_dom_object(ev, global, ExtendableMessageEventBinding::Wrap);
{

This comment has been minimized.

@creativcoder

creativcoder Sep 17, 2016

Author Contributor

@jdm Will this be safe place of invocation for reflect_dom_object ?

This comment has been minimized.

@jdm

jdm Sep 17, 2016

Member

Yes.

@jdm
jdm approved these changes Sep 17, 2016
@jdm jdm added the S-needs-squash label Sep 17, 2016
@jdm jdm removed the S-awaiting-review label Sep 17, 2016
@jdm
Copy link
Member

jdm commented Sep 17, 2016

@bors-servo: delegate+
Please squash them all into one commit, then you can merge with r=jdm.

@bors-servo
Copy link
Contributor

bors-servo commented Sep 17, 2016

✌️ @creativcoder can now approve this pull request

@creativcoder creativcoder force-pushed the creativcoder:extendable branch from 10d43c6 to 8b10cca Sep 17, 2016
@creativcoder
Copy link
Contributor Author

creativcoder commented Sep 17, 2016

@bors-servo r=jdm

@bors-servo
Copy link
Contributor

bors-servo commented Sep 17, 2016

📌 Commit 8b10cca has been approved by jdm

@bors-servo
Copy link
Contributor

bors-servo commented Sep 17, 2016

Testing commit 8b10cca with merge 83f687a...

bors-servo added a commit that referenced this pull request Sep 17, 2016
Implement ExtendableEvent as base type for ServiceWorker events

<!-- Please describe your changes on the following line: -->
r? @jdm

---
<!-- 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 #__ (github issue number if applicable).

<!-- Either: -->
- [X] These changes do not require tests because refactor

<!-- 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/13292)
<!-- Reviewable:end -->
@bors-servo
Copy link
Contributor

bors-servo commented Sep 17, 2016

@bors-servo bors-servo merged commit 8b10cca into servo:master Sep 17, 2016
3 checks passed
3 checks passed
continuous-integration/appveyor/pr AppVeyor build succeeded
Details
continuous-integration/travis-ci/pr The Travis CI build passed
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.

None yet

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