Switch to new event constructors

RESOLVED FIXED in seamonkey2.17

Status

SeaMonkey
General
--
enhancement
RESOLVED FIXED
6 years ago
4 years ago

People

(Reporter: neil@parkwaycc.co.uk, Assigned: ewong)

Tracking

({helpwanted})

unspecified
seamonkey2.17
helpwanted

Firefox Tracking Flags

(Not tracked)

Details

(Whiteboard: [good first bug][lang=js][mentor=Neil])

Attachments

(2 attachments, 2 obsolete attachments)

(Reporter)

Description

6 years ago
The traditional way of creating events was as follows:
var event = document.createEvent("CustomEvent");
event.initSomeEvent("media-showStatistics", aBubbles, aCancelable, aDetail);
element.dispatchEvent(event);

The new HTML5 way is as follows:
element.dispatchEvent(new CustomEvent("media-showStatistics",
  { bubbles: aBubbles, cancelable: aCancelable, detail: aDetail }));

Note that the number of parameters depends on the event type. See initXXXEvent and XXXEventInit in nsIDOMXXXEvent.idl for the list.

Updated

6 years ago
Whiteboard: [lang=js][mentor=Neil] → [good first bug][lang=js][mentor=Neil]
(Assignee)

Comment 1

6 years ago
Created attachment 686478 [details] [diff] [review]
Switch to new even constructors (v1)
Assignee: nobody → ewong
Status: NEW → ASSIGNED
Attachment #686478 - Flags: review?(neil)
Comment on attachment 686478 [details] [diff] [review]
Switch to new even constructors (v1)

Review of attachment 686478 [details] [diff] [review]:
-----------------------------------------------------------------

::: suite/browser/test/browser/browser_pluginplaypreview.js
@@ +209,5 @@
>    ok(rect.width == 200, "Test 1a, Plugin with id=" + plugin.id + " overlay rect should have 200px width before being replaced by actual plugin");
>    ok(rect.height == 200, "Test 1a, Plugin with id=" + plugin.id + " overlay rect should have 200px height before being replaced by actual plugin");
>  
> +  overlay.dispatchEvent(new CustomEvent("MozPlayPlugin", 
> +    { bubbles: true, cancelable: true, detail: null}));

Trailing whitespace

@@ +290,5 @@
>  
>    var overlay = doc.getAnonymousElementByAttribute(plugin, "class", "previewPluginContent");
>    ok(overlay, "Test 5a, the overlay div is expected");
>  
> +  overlay.dispatchEvent(new CustomEvent("MozPlayPlugin", 

And here

::: suite/common/tests/browser/browser_447951.js
@@ +26,5 @@
>        is(tabState.entries[0].url, baseURL + 0, "... but not more");
>        
>        // visit yet another anchor (appending it to session history)
>        let doc = tab.linkedBrowser.contentDocument;
> +      let event = new MouseEvent("click", 

and here

@@ +30,5 @@
> +      let event = new MouseEvent("click", 
> +        { bubbles: true, cancelable: true, view: doc.defaultView,
> +          detail: 1, screenX: 0, screenY: 0, clientX: 0, clientY: 0,
> +          ctrlKey: false, altKey: false, shiftKey: false, metaKey: false,
> +          button: 0, relatedTarget: null });

You probably don't need to add all those

::: suite/common/tests/browser/browser_522545.js
@@ +204,5 @@
>        is(browser.userTypedValue, null, "userTypedValue is empty to start");
>        is(browser.userTypedClear, 0, "userTypedClear is 0 to start");
>  
>        gURLBar.value = "example.org";
> +      gURLBar.dispatchEvent(new Event("input", 

Again

::: suite/mailnews/mailWidgets.xml
@@ +114,5 @@
>  
>        <method name="_fireOnSelect">
>          <body><![CDATA[
>            if (!this._suppressOnSelect && !this.suppressOnSelect) {
> +            this.dispatchEvent(new Event("select", 

.

::: suite/mailnews/msgHdrViewOverlay.js
@@ +250,5 @@
>    if (initialCollapsedSetting == "true")
>      gCollapsedHeaderViewMode = true;   
>  
>    // dispatch an event letting any listeners know that we have loaded the message pane
> +  toggleHeaderView.dispatchEvent(new Event('messagepane-loaded', 

.

::: suite/mailnews/tabmail.js
@@ +836,5 @@
>      gDBView.loadMessageByUrl("about:blank");
>      gDBView.selectionChanged();
>    }
> +
> +  var event = new Event( "messagepane-"+ (hidden ? "hide" : "unhide"),

Space before +, but not after (
(Assignee)

Comment 3

6 years ago
(In reply to :Ms2ger from comment #2)
> @@ +30,5 @@
> > +      let event = new MouseEvent("click", 
> > +        { bubbles: true, cancelable: true, view: doc.defaultView,
> > +          detail: 1, screenX: 0, screenY: 0, clientX: 0, clientY: 0,
> > +          ctrlKey: false, altKey: false, shiftKey: false, metaKey: false,
> > +          button: 0, relatedTarget: null });
> 
> You probably don't need to add all those
> 

How do I determine which fields are needed?  I've learnt that 
bubbles, cancelable, view and detail are the ones that are needed
for MouseEvent.  The rest are new to me (though I cannot conclude
they shouldn't be included).
(Reporter)

Comment 4

6 years ago
(In reply to Edmund Wong from comment #3)
> (In reply to Ms2ger from comment #2)
> > (From update of attachment 686478 [details] [diff] [review])
> > > @@ +30,5 @@
> > > +      let event = new MouseEvent("click", 
> > > +        { bubbles: true, cancelable: true, view: doc.defaultView,
> > > +          detail: 1, screenX: 0, screenY: 0, clientX: 0, clientY: 0,
> > > +          ctrlKey: false, altKey: false, shiftKey: false, metaKey: false,
> > > +          button: 0, relatedTarget: null });
> > You probably don't need to add all those
> How do I determine which fields are needed?
As far as I can tell, you only need the fields which differ from the default value. Most dictionaries don't override the default default values of false, zero or null as appropriate (ArchiveReader and CameraSelector are the only two that do and they aren't even event types).
(Reporter)

Comment 5

6 years ago
Comment on attachment 686478 [details] [diff] [review]
Switch to new even constructors (v1)

>diff --git a/suite/browser/test/browser/browser_pluginplaypreview.js b/suite/browser/test/browser/browser_pluginplaypreview.js
>--- a/suite/browser/test/browser/browser_pluginplaypreview.js
>+++ b/suite/browser/test/browser/browser_pluginplaypreview.js
Probably best to avoid ported tests as it makes it harder to keep them in sync.

>diff --git a/suite/common/src/nsSessionStore.js b/suite/common/src/nsSessionStore.js
>--- a/suite/common/src/nsSessionStore.js
>+++ b/suite/common/src/nsSessionStore.js
Does new Event actually work here?
Attachment #686478 - Flags: review?(neil) → feedback+
(Assignee)

Comment 6

6 years ago
Created attachment 690069 [details] [diff] [review]
Switch to new event constructors (v2)
Attachment #686478 - Attachment is obsolete: true
Attachment #690069 - Flags: review?(neil)
(Reporter)

Comment 7

6 years ago
Comment on attachment 690069 [details] [diff] [review]
Switch to new event constructors (v2)

>+            t.dispatchEvent(new Event("TabOpen",
>+              { bubbles: true, cancelable: false}));
Nit: space before }

>+            aTab.dispatchEvent(new UIEvent("TabClose",
>+              { bubbles: true, cancelable: false, view: window,
>+                detail: !!aParams.disableUndo}));
Nit: space before }

>+            tab.dispatchEvent(new UIEvent("TabMove",
>+              { bubbles: true, cancelable: false, view: window,
>+                detail: aSrcIndex}));
Nit: space before }

>diff --git a/suite/common/src/nsSessionStore.js b/suite/common/src/nsSessionStore.js
These changes definitely don't work, my session won't restore with the patch applied. r=me with them removed.

>diff --git a/suite/common/tests/browser/*
These are all ported tests, I'm afraid, so you'll have to remove these changes too. Maybe you can persuade Firefox to update tests to use new event constructors, and then you can port the changes over.

>+      aTextField.dispatchEvent(new UIEvent("input",
>+        { bubbles: true, cancelable: true,
>+          view: aTextField.ownerDocument.defaultView,
>+          detail: 0 }));
[Nit: don't need to provide detail here.]

>+      gURLBar.dispatchEvent(new Event("input", 
>+        { bubbles: true, cancelable: false }));
[Eek! This test is wrong, input is a UIEvent...]
Attachment #690069 - Flags: review?(neil) → review+
(Assignee)

Comment 8

6 years ago
Created attachment 690859 [details] [diff] [review]
Switch to new event constructors (v3)
Attachment #690069 - Attachment is obsolete: true
Attachment #690859 - Flags: review?(neil)
(Reporter)

Updated

6 years ago
Attachment #690859 - Flags: review?(neil) → review+
(Assignee)

Comment 9

6 years ago
Pushed to comm-central:
http://hg.mozilla.org/comm-central/rev/48e23cbddfa8
Status: ASSIGNED → RESOLVED
Last Resolved: 6 years ago
Resolution: --- → FIXED
Target Milestone: --- → seamonkey2.17

Comment 10

6 years ago
I'm getting these error messages:
Wed Dec 19 2012 22:05:38
Error: An error occurred updating the cmd_delete command: [Exception... "Component returned failure code: 0x8000ffff (NS_ERROR_UNEXPECTED) [nsIMsgDBView.hdrForFirstSelectedMessage]"  nsresult: "0x8000ffff (NS_ERROR_UNEXPECTED)"  location: "JS frame :: chrome://messenger/content/folderDisplay.js :: gFolderDisplay.selectedMessage :: line 18"  data: no]
Source file: chrome://global/content/globalOverlay.js
Line: 81
 ----------
Wed Dec 19 2012 22:05:38
Error: An error occurred updating the button_junk command: [Exception... "Component returned failure code: 0x8000ffff (NS_ERROR_UNEXPECTED) [nsIMsgDBView.hdrForFirstSelectedMessage]"  nsresult: "0x8000ffff (NS_ERROR_UNEXPECTED)"  location: "JS frame :: chrome://messenger/content/folderDisplay.js :: gFolderDisplay.selectedMessage :: line 18"  data: no]
Source file: chrome://global/content/globalOverlay.js
Line: 81
 ----------
Wed Dec 19 2012 22:05:38
Error: An error occurred updating the button_delete command: [Exception... "Component returned failure code: 0x8000ffff (NS_ERROR_UNEXPECTED) [nsIMsgDBView.hdrForFirstSelectedMessage]"  nsresult: "0x8000ffff (NS_ERROR_UNEXPECTED)"  location: "JS frame :: chrome://messenger/content/folderDisplay.js :: gFolderDisplay.selectedMessage :: line 18"  data: no]
Source file: chrome://global/content/globalOverlay.js
Line: 81

Backing out this patch fixes the errors.

Possibly this bit is to blame:
http://hg.mozilla.org/comm-central/rev/48e23cbddfa8#l6.12
Status: RESOLVED → REOPENED
Resolution: FIXED → ---
(Assignee)

Updated

6 years ago
Status: REOPENED → ASSIGNED

Comment 11

6 years ago
So it turns out the problem is somewhere else. Re-closing. Sorry for the bug spam.
Status: ASSIGNED → RESOLVED
Last Resolved: 6 years ago6 years ago
Resolution: --- → FIXED
(Assignee)

Comment 12

6 years ago
Created attachment 695075 [details] [diff] [review]
Trailing whitespace fix.
Attachment #695075 - Flags: review+
(Assignee)

Comment 13

6 years ago
Pushed to comm-central:
http://hg.mozilla.org/comm-central/rev/1b28d5e4b9bb
(Reporter)

Comment 14

4 years ago
Hmm, did we overlook the 5 events in MsgComposeCommands.js?

Updated

4 years ago
Blocks: 1099068
You need to log in before you can comment on or make changes to this bug.