/* This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
"use strict";
/** * * @param {String} groupID * @param {String} eventType * @param {Function} condition: Optional function that takes a Window as parameter. When * passed, the event will only be included if the result of the function * call is `true` (See `getAvailableEventBreakpoints`). * @returns {Object}
*/ function generalEvent(groupID, eventType, condition) { return {
id: `event.${groupID}.${eventType}`,
type: "event",
name: eventType,
message: `DOM '${eventType}' event`,
eventType, // DOM Events which may fire on the global object, or on DOM Elements
targetTypes: ["global", "node"],
condition,
};
} function nodeEvent(groupID, eventType) { return {
...generalEvent(groupID, eventType),
targetTypes: ["node"],
};
} function mediaNodeEvent(groupID, eventType) { return {
...generalEvent(groupID, eventType),
targetTypes: ["node"],
// Media events need some specific handling in `eventBreakpointForNotification()` // to ensure that the event is fired on either <video> or <audio> tags.
isMediaEvent: true,
};
} function globalEvent(groupID, eventType) { return {
...generalEvent(groupID, eventType),
message: `Global '${eventType}' event`, // DOM Events which are only fired on the global object
targetTypes: ["global"],
};
} function xhrEvent(groupID, eventType) { return {
...generalEvent(groupID, eventType),
message: `XHR '${eventType}' event`,
targetTypes: ["xhr"],
};
}
if (!Array.isArray(targetTypes) || !targetTypes.length) { thrownew Error("Expect a targetTypes array for each event definition");
}
for (const targetType of targetTypes) {
let byEventType = DOM_EVENTS[targetType]; if (!byEventType) {
byEventType = {};
DOM_EVENTS[targetType] = byEventType;
}
if (notification.type === "domEvent") { const domEventNotification = DOM_EVENTS[notification.targetType]; if (!domEventNotification) { returnnull;
}
// The 'event' value is a cross-compartment wrapper for the DOM Event object. // While we could use that directly in the main thread as an Xray wrapper, // when debugging workers we can't, because it is an opaque wrapper. // To make things work, we have to always interact with the Event object via // the Debugger.Object interface. const evt = dbg
.makeGlobalObjectReference(notification.global)
.makeDebuggeeValue(notification.event);
const eventType = evt.getProperty("type").return; const id = domEventNotification[eventType]; if (!id) { returnnull;
} const eventBreakpoint = EVENTS_BY_ID[id];
// Does some additional checks for media events to ensure the DOM Event // was fired on either <audio> or <video> tags. if (eventBreakpoint.isMediaEvent) { const currentTarget = evt.getProperty("currentTarget").return; if (!currentTarget) { returnnull;
}
exports.makeEventBreakpointMessage = makeEventBreakpointMessage; function makeEventBreakpointMessage(id) { return EVENTS_BY_ID[id].message;
}
exports.firstStatementBreakpointId = firstStatementBreakpointId; function firstStatementBreakpointId() { return SCRIPT_FIRST_STATEMENT_BREAKPOINT.id;
}
exports.eventsRequireNotifications = eventsRequireNotifications; function eventsRequireNotifications(ids) { for (const id of ids) { const eventBreakpoint = EVENTS_BY_ID[id];
// Script events are implemented directly in the server and do not require // notifications from Gecko, so there is no need to watch for them. if (eventBreakpoint && eventBreakpoint.type !== "script") { returntrue;
}
} returnfalse;
}
exports.getAvailableEventBreakpoints = getAvailableEventBreakpoints; /** * Get all available event breakpoints * * @param {Window|WorkerGlobalScope} global * @returns {Array<Object>} An array containing object with a few properties : * - {String} id: unique identifier * - {String} name: Description for the event to be displayed in UI (no translated) * - {String} type: Either "simple" or "event" * Only for type="simple": * - {String} notificationType: platform name of the event * Only for type="event": * - {String} eventType: platform name of the event * - {Array<String>} targetTypes: List of potential target on which the event is fired. * Can be "global", "node", "xhr", "worker",...
*/ function getAvailableEventBreakpoints(global) { const available = []; for (const { name, items } of AVAILABLE_BREAKPOINTS) {
available.push({
name,
events: items
.filter(item => !item.condition || item.condition(global))
.map(item => ({
id: item.id,
// The name to be displayed in UI
name: item.name,
// The type of event: either simple or event
type: item.type,
// For type=simple
notificationType: item.notificationType,
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.