Skip to content

Commit fd46f74

Browse files
committed
Add diagnostics messages and update Changelog related to changed DOM element lookup rules.
1 parent 59d5ca9 commit fd46f74

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

ChangeLog.md

+7
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,13 @@ full changeset diff at the end of each section.
1616
Current Trunk
1717
-------------
1818
- Remove deprecated Pointer_stringify (use UTF8ToString instead). See #8011
19+
- Added a new option -s DISABLE_DEPRECATED_FIND_EVENT_TARGET_BEHAVIOR=1 that
20+
changes the lookup semantics of DOM elements in html5.h event handler
21+
callback and WebGL context creation. New behavior is to use CSS selector
22+
strings to look up DOM elements over the old behavior, which was somewhat
23+
ad hoc constructed rules around default Emscripten uses. The old behavior
24+
will be deprecated and removed in the future. Build with -s ASSERTIONS=1
25+
to get diagnostics messages related to this transition.
1926

2027
v1.38.26: 02/04/2019
2128
--------------------

src/library_html5.js

+9-2
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,14 @@ var LibraryJSEvents = {
284284

285285
_findEventTarget__deps: ['_maybeCStringToJsString', '_specialEventTargets'],
286286
_findEventTarget: function(target) {
287-
return __specialEventTargets[target] || document.querySelector(__maybeCStringToJsString(target));
287+
var domElement = __specialEventTargets[target] || document.querySelector(__maybeCStringToJsString(target));
288+
#if ASSERTIONS
289+
// TODO: Remove this check in the future, or move it to some kind of debugging mode, because it may be perfectly fine behavior
290+
// for one to query an event target to test if any DOM element with given CSS selector exists. However for a migration period
291+
// from old lookup over to new, it is very useful to get diagnostics messages related to a lookup failing.
292+
if (!domElement) err('No DOM element was found with CSS selector "' + __maybeCStringToJsString(target) + '"');
293+
#endif
294+
return domElement;
288295
},
289296

290297
#if OFFSCREENCANVAS_SUPPORT
@@ -313,7 +320,7 @@ var LibraryJSEvents = {
313320
_findEventTarget__deps: ['_specialEventTargets'],
314321
_findEventTarget: function(target) {
315322
#if ASSERTIONS
316-
warnOnce('Rules for selecting event targets in HTML5 API are changing: instead of using document.getElementById() that only can refer to elements by their DOM ID, new event target selection mechanism uses the more flexible function document.querySelector() that can look up element names, classes, and complex CSS selectors. Build with -s DISABLE_DEPRECATED_FIND_EVENT_TARGET_BEHAVIOR=1 to change to the new lookup rules.');
323+
warnOnce('Rules for selecting event targets in HTML5 API are changing: instead of using document.getElementById() that only can refer to elements by their DOM ID, new event target selection mechanism uses the more flexible function document.querySelector() that can look up element names, classes, and complex CSS selectors. Build with -s DISABLE_DEPRECATED_FIND_EVENT_TARGET_BEHAVIOR=1 to change to the new lookup rules. See https://github.com/emscripten-core/emscripten/pull/7977 for more details.');
317324
#endif
318325
try {
319326
// The sensible "default" target varies between events, but use window as the default

0 commit comments

Comments
 (0)