<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE bugzilla SYSTEM "https://www.w3.org/Bugs/Public/page.cgi?id=bugzilla.dtd">

<bugzilla version="5.0.4"
          urlbase="https://www.w3.org/Bugs/Public/"
          
          maintainer="sysbot+bugzilla@w3.org"
>

    <bug>
          <bug_id>19211</bug_id>
          
          <creation_ts>2012-10-02 15:20:55 +0000</creation_ts>
          <short_desc>The event handler processing algorithm talk about jumping to a code entry-point</short_desc>
          <delta_ts>2013-11-11 18:46:08 +0000</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>1</classification_id>
          <classification>Unclassified</classification>
          <product>WHATWG</product>
          <component>HTML</component>
          <version>unspecified</version>
          <rep_platform>Other</rep_platform>
          <op_sys>other</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>DUPLICATE</resolution>
          <dup_id>23744</dup_id>
          
          <bug_file_loc>http://www.whatwg.org/specs/web-apps/current-work/#events</bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords></keywords>
          <priority>P2</priority>
          <bug_severity>critical</bug_severity>
          <target_milestone>Unsorted</target_milestone>
          
          <blocked>23780</blocked>
          <everconfirmed>1</everconfirmed>
          <reporter>contributor</reporter>
          <assigned_to name="Ian &apos;Hixie&apos; Hickson">ian</assigned_to>
          <cc>bzbarsky</cc>
    
    <cc>cam</cc>
    
    <cc>ian</cc>
    
    <cc>mike</cc>
          
          <qa_contact>contributor</qa_contact>

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>75061</commentid>
    <comment_count>0</comment_count>
    <who name="">contributor</who>
    <bug_when>2012-10-02 15:20:55 +0000</bug_when>
    <thetext>Specification: http://www.whatwg.org/specs/web-apps/current-work/multipage/webappapis.html
Multipage: http://www.whatwg.org/C#events
Complete: http://www.whatwg.org/c#events

Comment:
Should the event handler processing algorithm talk about jumping to a code
entry point?

Posted from: 173.48.30.113 by bzbarsky@mit.edu
User agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:18.0) Gecko/18.0 Firefox/18.0</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>75062</commentid>
    <comment_count>1</comment_count>
    <who name="Boris Zbarsky">bzbarsky</who>
    <bug_when>2012-10-02 15:22:01 +0000</bug_when>
    <thetext>Right now it does not, and I believe it should.

In fact, perhaps WebIDL should talk about it when calling callback functions?  Not sure on that one....</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>80699</commentid>
    <comment_count>2</comment_count>
    <who name="Ian &apos;Hixie&apos; Hickson">ian</who>
    <bug_when>2012-12-30 03:46:19 +0000</bug_when>
    <thetext>Yeah, WebIDL probably needs to do something here too.

heycam, is this something that&apos;s possible to do? Should you provide me a hook I can do, or something? Or maybe move a bunch of this scripting infrastructure to WebIDL?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>84907</commentid>
    <comment_count>3</comment_count>
    <who name="Cameron McCormack">cam</who>
    <bug_when>2013-03-25 04:57:11 +0000</bug_when>
    <thetext>I would prefer it if we could avoid moving much of this scripting infrastructure to Web IDL. :)

What difference is there between using the ECMAScript spec terminology for invoking a Function object when invoking callback functions and &quot;jumping to a code entry point&quot;?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>88483</commentid>
    <comment_count>4</comment_count>
    <who name="Ian &apos;Hixie&apos; Hickson">ian</who>
    <bug_when>2013-05-30 22:29:00 +0000</bug_when>
    <thetext>See also bug 18242.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>89525</commentid>
    <comment_count>5</comment_count>
    <who name="Ian &apos;Hixie&apos; Hickson">ian</who>
    <bug_when>2013-06-18 23:43:48 +0000</bug_when>
    <thetext>heycam: The main differences are that the &quot;entry script&quot; gets set up, script isn&apos;t run if the page isn&apos;t active, it checks if scripting is disabled, and it does microtask-like stuff afterwards.

Maybe, though, we should define &quot;entry script&quot; in terms of JS terms, so that it just hooks in automatically to everything. Maybe something about &quot;When evaluating a &apos;SourceElements&apos; JS production&quot;?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>89537</commentid>
    <comment_count>6</comment_count>
    <who name="Boris Zbarsky">bzbarsky</who>
    <bug_when>2013-06-19 01:44:39 +0000</bug_when>
    <thetext>What happens when I add a function that has no SourceElements involved (say Array.prototype.sort) as an event listener?

Seriously, you can&apos;t talk about JS objects and functions in syntactic terms.  It just doesn&apos;t work.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>90150</commentid>
    <comment_count>7</comment_count>
    <who name="Ian &apos;Hixie&apos; Hickson">ian</who>
    <bug_when>2013-07-02 22:00:00 +0000</bug_when>
    <thetext>bz: So what _does_ work?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>90158</commentid>
    <comment_count>8</comment_count>
    <who name="Boris Zbarsky">bzbarsky</who>
    <bug_when>2013-07-02 22:09:51 +0000</bug_when>
    <thetext>Talking about them as objects.  There&apos;s an actual ES object here, a callable one.  

Of course then you run into issues with callable objects not necessarily having a &quot;script&quot; associated with them.  To the extent that what you care about is a global, not a script, this is not a problem since they do always have an associated global...  but if you want a &quot;script&quot;, then you have a problem.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>90271</commentid>
    <comment_count>9</comment_count>
    <who name="Ian &apos;Hixie&apos; Hickson">ian</who>
    <bug_when>2013-07-03 21:59:18 +0000</bug_when>
    <thetext>So how do I refer to the &quot;object&quot; that&apos;s at the top of the &quot;stack&quot;, in ES terms?

(Note that ES talks about code execution in syntactic terms. Code execution is the result of evaluating syntactic components.)</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>90319</commentid>
    <comment_count>10</comment_count>
    <who name="Boris Zbarsky">bzbarsky</who>
    <bug_when>2013-07-04 03:15:17 +0000</bug_when>
    <thetext>&gt; So how do I refer to the &quot;object&quot; that&apos;s at the top of the &quot;stack&quot;, in ES terms?

That&apos;s a good question for public-script-coord.

&gt; Note that ES talks about code execution in syntactic terms.

Not for things like the callback to Array.prototype.sort and whatnot... those are just objects with a [[Call]].</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>95903</commentid>
    <comment_count>11</comment_count>
    <who name="Ian &apos;Hixie&apos; Hickson">ian</who>
    <bug_when>2013-11-06 22:31:22 +0000</bug_when>
    <thetext>Looks like this got fixed. bz, is the spec sufficient now?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>95982</commentid>
    <comment_count>12</comment_count>
    <who name="Ian &apos;Hixie&apos; Hickson">ian</who>
    <bug_when>2013-11-07 22:21:43 +0000</bug_when>
    <thetext>(Note that this will actually need to change a bit, because right now the entry script gets set to the handler&apos;s script, but all browsers actually use the context of the element on which the event handler was invoked to do this. But they do this for addEventListener() too, which will probably require DOM changes... maybe I should file a new bug for this.)

http://www.hixie.ch/tests/adhoc/html/script/callbacks/001.html</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>96014</commentid>
    <comment_count>13</comment_count>
    <who name="Boris Zbarsky">bzbarsky</who>
    <bug_when>2013-11-08 03:03:17 +0000</bug_when>
    <thetext>&gt; but all browsers actually use the context of the element on which the event
&gt; handler was invoked to do this.

Do which this?  Event handlers in Firefox should use the &quot;script settings object&quot; based on the callable being invoked, I would think.  Unless you&apos;re testing in a super-ancient version of Firefox, of course...  I can&apos;t tell which part of your big testcase is trying to test this part and how it&apos;s going about it.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>96058</commentid>
    <comment_count>14</comment_count>
    <who name="Ian &apos;Hixie&apos; Hickson">ian</who>
    <bug_when>2013-11-08 23:18:13 +0000</bug_when>
    <thetext>Hm, interesting. Further testing actually shows that Firefox is actually
inconsistent about this, acting one way for .onclick and another for
addEventListener(&apos;click&apos;). Also, browsers don&apos;t like event handlers being
set to window.open at all. I wonder why it works for setTimeout but not
event listeners.

http://www.hixie.ch/tests/adhoc/html/script/callbacks/002.html

RESULTS:
Firefox:
   local:                                        outer
   .onclick from iframe:                         iframe
   addEventListener from iframe:                 outer
   .onclick and addEventListener to window.open: exception

Chrome:
   local:                                        outer
   .onclick from iframe:                         outer
   addEventListener from iframe:                 outer
   .onclick and addEventListener to window.open: exception

Safari:
   local:                                        outer
   .onclick from iframe:                         outer
   addEventListener from iframe:                 outer
   .onclick and addEventListener to window.open: exception</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>96066</commentid>
    <comment_count>15</comment_count>
    <who name="Ian &apos;Hixie&apos; Hickson">ian</who>
    <bug_when>2013-11-08 23:52:32 +0000</bug_when>
    <thetext>IE10 (thanks Anne):
   local:                                        outer
   .onclick from iframe:                         inner
   addEventListener from iframe:                 inner
   .onclick and addEventListener to window.open: exception

On the 001 test, it&apos;s the third batch of tests (the ones with the event listeners in the iframe) that checks this. They&apos;re only testing addEventListener, though, not a straight event handler. And for some reason they don&apos;t work in IE9.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>96068</commentid>
    <comment_count>16</comment_count>
    <who name="Ian &apos;Hixie&apos; Hickson">ian</who>
    <bug_when>2013-11-09 00:24:22 +0000</bug_when>
    <thetext>I should try adjusting that test to use .bind() on the method i&apos;m passing in, in case addEventListener is doing something like setting &apos;this&apos; to the element or something like that.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>96074</commentid>
    <comment_count>17</comment_count>
    <who name="Boris Zbarsky">bzbarsky</who>
    <bug_when>2013-11-09 01:53:51 +0000</bug_when>
    <thetext>Thanks for the smaller testcase!  addEventListener definitely sets &quot;this&quot; to the element when the listener is invoked.  So for the window.open test you need to bind(), indeed.

I also see now what the issue you&apos;re running into with Firefox is: you&apos;re testing in a release build, where addEventListener isn&apos;t using a WebIDL callback yet.  A nightly or Aurora build, where that&apos;s on WebIDL would give you:

  Firefox:
    local:                                        outer
    .onclick from iframe:                         iframe
    addEventListener from iframe:                 iframe

which matches IE10 and imo general sanity (but not our old behavior before we started converting things to WebIDL).</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>96135</commentid>
    <comment_count>18</comment_count>
    <who name="Ian &apos;Hixie&apos; Hickson">ian</who>
    <bug_when>2013-11-11 18:46:08 +0000</bug_when>
    <thetext>I was on an old nightly, heh. Now updated, I agree that it says outer for the first one, and inner for the other four.

I&apos;ve updated the test:
   http://www.hixie.ch/tests/adhoc/html/script/callbacks/002.html

Firefox uses the settings object of the script of the callback, or the global of the object used in the callback, in the case it&apos;s not a script. (So, outer, inner 4 times, outer 4 times.) Chrome uses the settings object of the element the event handler fired on (so outer 9 times).

This seems to be consistent with what we want to do in bug 18242, so what I need to do here is the same as in bug 23744.

*** This bug has been marked as a duplicate of bug 23744 ***</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>