This is an archived snapshot of W3C's public bugzilla bug tracker, decommissioned in April 2019. Please see the home page for more details.

Bug 24248 - Inconsistency between WebIDL callback function default this and JS strict mode default this
Summary: Inconsistency between WebIDL callback function default this and JS strict mod...
Status: RESOLVED FIXED
Alias: None
Product: WebAppsWG
Classification: Unclassified
Component: WebIDL (show other bugs)
Version: unspecified
Hardware: PC Linux
: P2 normal
Target Milestone: ---
Assignee: Boris Zbarsky
QA Contact: public-webapps-bugzilla
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2014-01-09 05:15 UTC by Nikhil
Modified: 2014-01-10 05:37 UTC (History)
5 users (show)

See Also:


Attachments

Description Nikhil 2014-01-09 05:15:08 UTC
http://www.w3.org/TR/WebIDL/#es-invoking-callback-functions

When a JS callback is invoked, WebIDL specifies default `this` to be `null`, but JS strict mode functions require that `this` be `undefined`.
Comment 1 Allen Wirfs-Brock 2014-01-10 00:25:34 UTC
(In reply to Nikhil from comment #0)
> http://www.w3.org/TR/WebIDL/#es-invoking-callback-functions
> 
> When a JS callback is invoked, WebIDL specifies default `this` to be `null`,
> but JS strict mode functions require that `this` be `undefined`.

That isn't  exactly true. See step 1 of http://www.ecma-international.org/ecma-262/5.1/#sec-10.4.3 Strict mode functions accept whatever is passed to them as a thisValue without modifying it.

It's true that the function call operator http://www.ecma-international.org/ecma-262/5.1/#sec-11.2.3 passes undefined as the thisValue (step 7.a) but other means of function invocation (the call/apply functions) can pass null as the thisValue to a function.

BTW, I'm not arguing against the proposed change (I'm reserving judgement on that), just saying that it isn't an ES requirement one way or the other.
Comment 2 Cameron McCormack 2014-01-10 00:33:04 UTC
I think Nikhil is only referring to the cases where you don't explicitly provide a this value, e.g. by doing f() or f.call() or f.apply().
Comment 3 Boris Zbarsky 2014-01-10 00:44:26 UTC
Conceptually, this is meant for cases when no this value is being explicitly provided to a function call, which should act just like this:

  var f = theFunctionIWasGiven;
  f();

or

  f.call();
Comment 5 Garrett 2014-01-10 03:19:08 UTC
"When any callback is called, call the callback's internal [[Call]] method, passing undefined as the this value."

That takes care of bound functions, too.
Comment 6 Boris Zbarsky 2014-01-10 05:37:53 UTC
Some callbacks are in fact called with some other this value.  For example, event handlers and callable event listeners are called with the event target as the this value.  So always passing undefined wouldn't be correct either.

Of course if the callee is a bound function it'll just ignore the this value passed to [[Call]], so they work no matter what.