Skip to content

Commit be65539

Browse files
committed
Fix event handler property generation to properly rely on runScripts
In particular, event handler properties are now generated from event handler attributes only when runScripts is set to "dangerously". This fixes #1848, by ensuring we don't generate (and then run!) event handler properties for <body>/Window when runScripts is left undefined. It also fixes #1828, by ensuring that we *do* allow the event handler property setter to work from the outside, even if runScripts is left undefined.
1 parent 38c430f commit be65539

File tree

3 files changed

+388
-6
lines changed

3 files changed

+388
-6
lines changed

lib/jsdom/living/events/EventTarget-impl.js

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -155,16 +155,12 @@ function invokeInlineListeners(object, event) {
155155
// Note: for Window, object is an EventTargetImpl
156156
const wrapper = idlUtils.wrapperForImpl(object);
157157
if ((wrapper.constructor.name === "Window" && wrapper._document) || GlobalEventHandlers.isImpl(object)) {
158-
return; // elements have been upgraded to use a better path
158+
return; // elements and Window have been upgraded to use a better path; this is left for things like XHR.
159159
}
160160

161161
const inlineListener = getListenerForInlineEventHandler(wrapper, event.type);
162162
if (inlineListener) {
163-
// Will be falsy for windows that have closed
164-
const document = object._ownerDocument;
165-
166-
const runScripts = document && document._defaultView && document._defaultView._runScripts === "dangerously";
167-
if (!object.nodeName || runScripts) {
163+
if (!object.nodeName) {
168164
invokeEventListeners([{
169165
callback: inlineListener,
170166
options: normalizeEventHandlerOptions(false, ["capture", "once"])

lib/jsdom/living/nodes/GlobalEventHandlers-impl.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,13 @@ class GlobalEventHandlersImpl {
7171
return;
7272
}
7373

74+
// Only translate attribute changes into properties when runScripts: "dangerously" is set.
75+
// Documents without a browsing context (i.e. without a _defaultView) never run scripts.
76+
const runScripts = "_runScripts" in this ? this._runScripts : (this._ownerDocument._defaultView || {})._runScripts;
77+
if (runScripts !== "dangerously") {
78+
return;
79+
}
80+
7481
const val = this.getAttribute(propName);
7582
const handler = val === null ? null : { body: val };
7683
this._setEventHandlerFor(event, handler);

0 commit comments

Comments
 (0)