Closed Bug 807226 Opened 12 years ago Closed 12 years ago

Convert nsJSEventListener to EventHandlerNonNull and company

Categories

(Core :: DOM: Core & HTML, defect)

x86
macOS
defect
Not set
normal

Tracking

()

RESOLVED FIXED
mozilla19

People

(Reporter: bzbarsky, Assigned: bzbarsky)

References

(Blocks 1 open bug)

Details

Attachments

(8 files)

(deleted), patch
smaug
: review+
Details | Diff | Splinter Review
(deleted), patch
smaug
: review+
Details | Diff | Splinter Review
(deleted), patch
smaug
: review+
Details | Diff | Splinter Review
(deleted), patch
smaug
: review+
Details | Diff | Splinter Review
(deleted), patch
smaug
: review+
Details | Diff | Splinter Review
(deleted), patch
smaug
: review+
Details | Diff | Splinter Review
(deleted), patch
smaug
: review+
Details | Diff | Splinter Review
(deleted), patch
smaug
: review+
Details | Diff | Splinter Review
We can do this once bug 779048 lands and we have native-to-JS conversions for unions done in bug 807224 (needed for onerror).
Blocks: 807369
Depends on: 807371
Blocks: 807371
No longer depends on: 807371
Please pay particular attention to the changes in nsJSEventListener::IsBlackForCC and nsEventListenerManager::MarkForCC.
Attachment #678049 - Flags: review?(bugs)
Please pay special attention to nsJSEventListener::IsBlackForCC
Attachment #678051 - Flags: review?(bugs)
automatically get the callback objects passed in from binding code.
Attachment #678056 - Flags: review?(bugs)
Assignee: nobody → bzbarsky
Whiteboard: [need review]
Mn is not happy. (I don't really know what Marionette tests do.)
Oh, it is just "Summary is empty"
Mn is not happy on vanillay pushes too, so I'm ignoring it.
Attachment #678048 - Flags: review?(bugs) → review+
Attachment #678055 - Flags: review?(bugs) → review+
Comment on attachment 678049 [details] [diff] [review] part 2. Change event handlers to store WebIDL callback functions. >@@ -830,17 +835,53 @@ nsEventListenerManager::CompileEventHand > NS_ENSURE_SUCCESS(result, result); > } > > if (handler) { > // Bind it > nsScriptObjectHolder<JSObject> boundHandler(context); > context->BindCompiledEventHandler(mTarget, listener->GetEventScope(), > handler.get(), boundHandler); >- listener->SetHandler(boundHandler.get()); >+ if (listener->EventName() == nsGkAtoms::onerror && win) { >+ bool ok; >+ JSAutoRequest ar(context->GetNativeContext()); >+ nsRefPtr<OnErrorEventHandlerNonNull> handlerCallback = >+ new OnErrorEventHandlerNonNull(context->GetNativeContext(), >+ listener->GetEventScope(), >+ boundHandler.get(), &ok); >+ if (!ok) { >+ return NS_ERROR_OUT_OF_MEMORY; >+ } This looks odd. Could you add some comment about possible causes of OOM >+ } else if (listener->EventName() == nsGkAtoms::onbeforeunload) { >+ // XXXbz Should we really do the special beforeunload handler on >+ // non-Window objects? Per spec, we shouldn't even be compiling >+ // the beforeunload content attribute on random elements! Could you file a followup and add the bug number here. >+ if (aEventName == nsGkAtoms::onerror && win) { >+ bool ok; >+ nsRefPtr<OnErrorEventHandlerNonNull> handlerCallback = >+ new OnErrorEventHandlerNonNull(cx, aScope, callable, &ok); >+ if (!ok) { >+ return NS_ERROR_OUT_OF_MEMORY; >+ } >+ handler.SetHandler(handlerCallback); >+ } else if (aEventName == nsGkAtoms::onbeforeunload) { >+ MOZ_ASSERT(win, >+ "Should not have onbeforeunload handlers on non-Window objects"); >+ bool ok; >+ nsRefPtr<BeforeUnloadEventHandlerNonNull> handlerCallback = >+ new BeforeUnloadEventHandlerNonNull(cx, aScope, callable, &ok); >+ if (!ok) { >+ return NS_ERROR_OUT_OF_MEMORY; >+ } >+ handler.SetHandler(handlerCallback); >+ } else { >+ bool ok; >+ nsRefPtr<EventHandlerNonNull> handlerCallback = >+ new EventHandlerNonNull(cx, aScope, callable, &ok); >+ if (!ok) { >+ return NS_ERROR_OUT_OF_MEMORY; >+ } >+ handler.SetHandler(handlerCallback); Hmm, code duplication. Could you have a helper method which is called in this method and in nsEventListenerManager::CompileEventHandler >- // Set a handler for this event listener. Must not be called if >- // there is already a handler! The handler must already be bound to >- // the right target. >- virtual void SetHandler(JSObject *aHandler) = 0; >+ nsIAtom *EventName() const nsIAtom* >+ void SetHandler(const nsEventHandler& aHandler) { >+ mHandler.SetHandler(aHandler); >+ } >+ void SetHandler(mozilla::dom::EventHandlerNonNull* aHandler) { >+ mHandler.SetHandler(aHandler); >+ } >+ void SetHandler(mozilla::dom::BeforeUnloadEventHandlerNonNull* aHandler) { >+ mHandler.SetHandler(aHandler); >+ } >+ void SetHandler(mozilla::dom::OnErrorEventHandlerNonNull* aHandler) { >+ mHandler.SetHandler(aHandler); >+ } { goes to next line >+ bool HasGrayCallable() const >+ { >+ return xpc_IsGrayGCThing(mCallable); >+ } return mCallable && xpc_IsGrayGCThing(mCallable); I think I could take another look after the code duplication is fixed.
Attachment #678049 - Flags: review?(bugs) → review-
Comment on attachment 678050 [details] [diff] [review] part 3. Change event handlers to call their WebIDL callbacks directly. >+ errorMsg = scriptEvent->errorMsg; >+ msgOrEvent.SetAsString() = static_cast<nsAString*>(&errorMsg); This is somewhat odd looking. Would it be possible to change SetAsString to take a parameter? Though, I guess SetAsString() is consistent with Optional<...>.Value() So, no need to change.
Attachment #678050 - Flags: review?(bugs) → review+
Comment on attachment 678051 [details] [diff] [review] part 4. Allow event handlers to have a null nsIScriptContext if they won't have to compile from a string. Looking good.
Attachment #678051 - Flags: review?(bugs) → review+
Attachment #678053 - Flags: review?(bugs) → review+
Comment on attachment 678049 [details] [diff] [review] part 2. Change event handlers to store WebIDL callback functions. Ah, the code duplication is fixed in another patch.
Attachment #678049 - Flags: review- → review+
Attachment #678056 - Flags: review?(bugs) → review+
Comment on attachment 678057 [details] [diff] [review] part 8. Remove the exceptions for EventHandler in WebIDL codegen. This is all great :) Hopefully I haven't missed anything important.
Attachment #678057 - Flags: review?(bugs) → review+
> return mCallable && xpc_IsGrayGCThing(mCallable); mCallable is only null if we've been unlinked (well, of if the constructor returns a false "ok", but people better not be doing anything with the object then)... Will we end up having HasGrayCallable() called after we have been unlinked? > This is somewhat odd looking. Yeah, I'll file a followup on giving unions better ergonomics. Thanks for the reviews!
(In reply to Boris Zbarsky (:bz) from comment #17) > > return mCallable && xpc_IsGrayGCThing(mCallable); > > mCallable is only null if we've been unlinked (well, of if the constructor > returns a false "ok", but people better not be doing anything with the > object then)... Will we end up having HasGrayCallable() called after we > have been unlinked? As of now no, but if we add more skippability, yet have some missing unlinking elsewhere, we might. So I think adding null check would be good there.
Blocks: 809765
Blocks: 809767
Depends on: 811226
Depends on: 811394
Depends on: 812137
Depends on: 812744
Depends on: 817284
Depends on: CVE-2013-5601
Component: DOM → DOM: Core & HTML
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: