Open Bug 878349 Opened 11 years ago Updated 2 years ago

nsEventListenerManager needs to pass the element and event name as a compile option to JSAPI

Categories

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

x86
macOS
defect

Tracking

()

People

(Reporter: ejpbruel, Unassigned)

Details

Attachments

(1 file)

To implement Debugger.Source.prototype.element, which returns a Debugger.Object instance to the element on which a script was defined, and Debugger.Source.prototype.elementProperty, which returns the name of the event for which a script was defined if it is an event handler, 
we need to pass the element and event name as compile options to JSAPI when the event handler script is compiled.
Attachment #756866 - Flags: review?(bugs)
Assignee: nobody → ejpbruel
Comment on attachment 756866 [details] [diff] [review]
Patch to be reviewed

Why the things are called element and elementProperty? That doesn't always make sense. eventTarget and eventTargetProperty perhaps?
<body onload="foo()"> adds onfoo property to window object.
Or maybe "element" doesn't refer to DOM element as such?

>diff --git a/content/events/src/nsEventListenerManager.cpp b/content/events/src/nsEventListenerManager.cpp
>--- a/content/events/src/nsEventListenerManager.cpp
>+++ b/content/events/src/nsEventListenerManager.cpp
>@@ -863,20 +863,36 @@ nsEventListenerManager::CompileEventHand
>     // the only thing with weird arg names and SVG doesn't map event
>     // listeners to the window.
>     nsContentUtils::GetEventArgNames(content ?
>                                        content->GetNameSpaceID() :
>                                        kNameSpaceID_None,
>                                      aListenerStruct->mTypeAtom,
>                                      &argCount, &argNames);
> 
>+    // Obtain the element for which this handler is being compiled
>+    JS::Rooted<JSObject*> global(cx, context->GetNativeGlobal());
>+    JS::Rooted<JS::Value> value(cx, JSVAL_NULL);
>+    nsresult rv = nsContentUtils::WrapNative(cx, global, mTarget, value.address());
>+    if (NS_FAILED(rv))
>+        return rv;
{} and 2 space indentation. Same also elsewhere.


>+    JS::Rooted<JSObject*> element(cx, &value.toObject());
>+
>+    // Obtain the event name/element property
>+    const jschar *chars = aListenerStruct->mTypeAtom->GetUTF16String();
const jschar* chars
>diff --git a/content/events/test/bug878349.png b/content/events/test/bug878349.png
Odd to see an image in a test for this kind of bug. But ok, I see the usecase, though you could have
used data: url

>+window.onload = function () {
>+    SimpleTest.waitForExplicitFinish();
>+
>+    var iframe = document.createElement("iframe");
>+    iframe.src = "http://mochi.test:8888/tests/content/events/test/nochrome_bug878349.html";
>+
>+    iframe.onload = function () {
>+        var dbg = new Debugger;
>+        ok(dbg, "Should be able to create debugger");
>+
>+        var windowDO = dbg.addDebuggee(iframe.contentWindow);
>+        ok(windowDO, "Should be able to obtain Debugger.Object instance for contentWindow");
>+
>+	var img = iframe.contentWindow.document.createElement("img");
>+    	img.src = "http://mochi.test:8888/tests/content/events/test/bug878349.png";
>+	img.setAttribute("onload", "2 * 3");
>+
>+        var imgDO = windowDO.makeDebuggeeValue(img);
>+        ok(imgDO, "Should be able to obtain Debugger.Object instance for img");
>+
>+	dbg.onNewScript = function (script) {
>+            is(typeof script.source.element, "object");
>+            is(script.source.element instanceof Debugger.Object, true);
>+            is(script.source.element === imgDO, true);
>+            is(script.source.elementProperty, "onload");
>+            SimpleTest.finish();
>+        };
>+
>+	iframe.contentWindow.document.body.appendChild(img);
>+    };
>+
>+    document.body.appendChild(iframe);
>+};
Please test also body elements onfoo attributes, which add the listener to window.
Attachment #756866 - Flags: review?(bugs) → review-
Assignee: ejpbruel → nobody
https://bugzilla.mozilla.org/show_bug.cgi?id=1472046

Move all DOM bugs that haven’t been updated in more than 3 years and has no one currently assigned to P5.

If you have questions, please contact :mdaly.
Priority: -- → P5
Component: DOM → DOM: Core & HTML
Severity: normal → S3
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: