Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upEvent handlers compiled from inline attributes aren't seeing properties of their current target as variables #25517
Comments
|
It's not about exposing properties; it's that the |
|
That's not what
In firefox the above code logs the object, then logs 5 once, then reports an exception that |
|
Also, the |
|
This is a special behavior of inline handlers defined in on* attributes, and it happens when they are compiled, as specified under "Scope" in step 3.9 of https://html.spec.whatwg.org/#internal-raw-uncompiled-handler . The same function body assigned into onclick using a Javascript function() block instead of a string does not see value in Firefox. |
|
servo/components/script/dom/eventtarget.rs Lines 504 to 507 in b52ddc5 This is the missing piece; step numbers have changed, but looking for a scope in the document, form owner, and element is what 3.9 of https://html.spec.whatwg.org/#internal-raw-uncompiled-handler is saying to do. Someone with more Spidermonkey knowledge than I have might want to jump in here. |
|
It looks like we need to turn the document, the form owner if it exists, and the target if it's an element into |
|
We can get the JSObject pointer for any DOM object by calling |
|
Ok, I'll try it! |
|
https://github.com/pshaughn/servo/tree/compiledeventscope fixes this, but won't pass any of the existing tests until #25488 lands because the existing tests also involve capture/bubble behavior. Pushing a new test just for this would be redundant since the larger tests are already covering it thoroughly. Is this the kind of thing that the _mozilla tests are for? |
|
Yep! Those don't get upstreamed by default, so they cover browser-specific behaviour or non-standard extensions. |
Put target element, form owner, and element document on scope chain of compiled events Event listeners that are created from a function object just get whatever closure the function object had, but event listeners created from a string need a special closure that acts like they were defined inside a series of `with` statements. This now happens. The existing WPT test for it, html/webappapis/scripting/events/compile-event-handler-lexical-scopes.html, also relies on other behavior we don't have, so I added an easier version of the test that doesn't involve bubbling or capturing and doesn't check any IDL properties we don't have. This new test will eventually be redundant when we have everything else the upstream test expects. --- <!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `___` with appropriate data: --> - [X] `./mach build -d` does not report any errors - [X] `./mach test-tidy` does not report any errors - [X] These changes fix #25517 <!-- Either: --> - [X] There are tests for these changes <!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.--> <!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->
After #25488, the first subtest in html/webappapis/scripting/events/compile-event-handler-lexical-scopes.html does what it's supposed to do far enough to find an actual problem. A more minimal case to focus on the one problem is:
In Firefox, this puts 4 in the div. In Servo, this logs nothing and reports an exception that value is not defined.
I need to look at specifications more to figure out what mechanism should be exposing the properties in this way and what part of it Servo is missing; prior to this test, I was unaware this behavior existed at all.