Implement Event constructors

RESOLVED FIXED

Status

()

Core
DOM: Events
RESOLVED FIXED
6 years ago
3 years ago

People

(Reporter: annevk, Assigned: smaug)

Tracking

({dev-doc-complete})

Firefox Tracking Flags

(Not tracked)

Details

Attachments

(2 attachments, 1 obsolete attachment)

(Reporter)

Description

6 years ago
DOM Core introduces a constructor syntax for Events.

http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#dom-event

Please implement it so init*Event() can die in a fire.

Updated

6 years ago
OS: Mac OS X → All
Hardware: x86 → All
(Assignee)

Updated

6 years ago
Assignee: nobody → bugs
(Assignee)

Comment 1

6 years ago
Patch coming soon for Event and CustomEvent.
I don't know specs defining other event ctors.
(Assignee)

Comment 2

6 years ago
Ah, there are other specs for other event ctors.

But I'll start from Event and CustomEvent.
(Assignee)

Comment 3

6 years ago
Created attachment 580075 [details] [diff] [review]
patch

This adds the basic stuff (Event and CustomEvent and ctors are defined in DOM4).
After this adding support for new event ctors is easy:
- Create FooEventInit interface
- Add NS_DEFINE_EVENT_CTOR(Foo) and NS_DEFINE_EVENT_CONSTRUCTOR_FUNC_DATA(Foo)
  to nsDOMClassInfo.cpp
- virtual const nsIID& EventInitIID() { return NS_GET_IID(nsIFooEventInit); } 
  to the nsDOMFooEvent.h
- Implement
  virtual nsresult InitFromCtor(const nsAString& aType, nsISupports* aDict);
Attachment #580075 - Flags: review?(jst)
(Assignee)

Comment 4

6 years ago
https://tbpl.mozilla.org/?tree=Try&rev=109e5fb30913
Can you check the expected behaviour for { bubbles: get () { throw foo } } and add a test?

Also, \o/
(Assignee)

Comment 6

6 years ago
Created attachment 580086 [details] [diff] [review]
patch

Handle exceptions per WebIDL
Attachment #580075 - Attachment is obsolete: true
Attachment #580075 - Flags: review?(jst)
Attachment #580086 - Flags: review?(jst)
(Assignee)

Updated

6 years ago
Blocks: 708701
Comment on attachment 580086 [details] [diff] [review]
patch

>--- a/content/events/src/nsDOMEvent.cpp
>+++ b/content/events/src/nsDOMEvent.cpp
>+nsDOMEvent::Initialize(nsISupports* aOwner, JSContext* aCx, JSObject* aObj,
>+                       PRUint32 aArgc, jsval* aArgv)
>+{
>+  JSAutoRequest ar(aCx);
>+  JSString* jsstr = JS_ValueToString(aCx, aArgv[0]);
>+  if (!jsstr) {
>+    return NS_ERROR_DOM_SYNTAX_ERR;
>+  }
>+
>+  JS::Anchor<JSString*> deleteProtector(jsstr);
>+  size_t length;
>+  const jschar* chars = JS_GetStringCharsAndLength(aCx, jsstr, &length);
>+  if (!chars) {
>+    return NS_ERROR_OUT_OF_MEMORY;
>+  }
>+
>+  nsAutoString type;
>+  type.Assign(chars, length);
>+  deleteProtector.clear();

Can this use nsDependentJSString?
(Assignee)

Comment 8

6 years ago
I don't know why nsDependentJSString is ever safe to use.
(Assignee)

Comment 9

6 years ago
I'm trying to write a code generator for event ctors.

But feel free to review the current patches.
(Assignee)

Comment 10

6 years ago
I filed Bug 709569 to get a tool for generic dictionary handling.
(Assignee)

Comment 11

6 years ago
Created attachment 580731 [details] [diff] [review]
using nsDependentJSString

I'll file a followup bug to get better nsDependentJSString <-> JS::Anchor 
handling. nsDependentJSString could just do the right thing with JSString, or at 
least  enforce that JS::Anchor is used.
Attachment #580086 - Attachment is obsolete: true
Attachment #580086 - Flags: review?(jst)
Attachment #580731 - Flags: review?(jst)
(Assignee)

Comment 12

6 years ago
Comment on attachment 580086 [details] [diff] [review]
patch

er, the previous patch is on top of this.
Attachment #580086 - Attachment is obsolete: false
Attachment #580086 - Flags: review?(jst)

Updated

6 years ago
Attachment #580086 - Flags: review?(jst) → review+

Updated

6 years ago
Attachment #580731 - Flags: review?(jst) → review+
(Assignee)

Comment 13

6 years ago
https://hg.mozilla.org/mozilla-central/rev/01a26239462a
https://hg.mozilla.org/mozilla-central/rev/1ab5ed4f93bf
Status: NEW → RESOLVED
Last Resolved: 6 years ago
Resolution: --- → FIXED
Keywords: dev-doc-needed
We really need serious documentation for this...
Documentation updated:
Constructor:
https://developer.mozilla.org/en-US/docs/Web/API/Event.Event
https://developer.mozilla.org/en-US/docs/Web/API/CustomEvent.CustomEvent
Interface pages updated:
https://developer.mozilla.org/en-US/docs/Web/API/Event
https://developer.mozilla.org/en-US/docs/Web/API/CustomEvent
init*Event pages deprecated:
https://developer.mozilla.org/en-US/docs/Web/API/Event.initEvent
https://developer.mozilla.org/en-US/docs/Web/API/CustomEvent.initCustomEvent

and
https://developer.mozilla.org/en-US/Firefox/Releases/11#DOM updated
Keywords: dev-doc-needed → dev-doc-complete
You need to log in before you can comment on or make changes to this bug.