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 12635 - calling Functions corresponding to IDL operations/attributes on unexpected objects should throw
Summary: calling Functions corresponding to IDL operations/attributes on unexpected ob...
Status: RESOLVED FIXED
Alias: None
Product: WebAppsWG
Classification: Unclassified
Component: WebIDL (show other bugs)
Version: unspecified
Hardware: All All
: P2 normal
Target Milestone: ---
Assignee: Cameron McCormack
QA Contact: public-webapps-bugzilla
URL:
Whiteboard:
Keywords:
Depends on: 12320
Blocks:
  Show dependency treegraph
 
Reported: 2011-05-08 23:56 UTC by Cameron McCormack
Modified: 2011-06-28 04:59 UTC (History)
5 users (show)

See Also:


Attachments

Description Cameron McCormack 2011-05-08 23:56:11 UTC
Bug 11857 comment 6 brings up the cases like `window.alert.call(document, 'Do you see this alert?')`.  We should make this throw a TypeError.

Another case is getters/setters for IDL attributes, like `Object.getOwnPropertyDescriptor(document, "nodeType").get.call(window)`.
Comment 1 Hallvord R. M. Steen 2011-05-09 00:29:15 UTC
(Was the summary supposed to say "*un*expected objects" - or is it just me not understanding WebIDL terminology yet? :-))
Comment 2 Cameron McCormack 2011-05-09 00:34:11 UTC
I do try to keep the terminology as confusing as possible. :)
Comment 3 Hallvord R. M. Steen 2011-05-09 00:43:29 UTC
Another way to hit the same problem is of course to do 

document.alert=window.alert;
document.alert('If a document pops up an alert and nobody sees it, does it still pop up?');
Comment 4 Boris Zbarsky 2011-05-09 01:12:41 UTC
The other case where this come up is this:

  function f() {
  }
  f.prototype = document;
  var d = new f();
  d.write("What happens here?");

Some UAs throw in this situation; some actually invoke the native write function on the document.  I would prefer throwing, as the represetative of one of the UAs which currently does NOT throw here but would like to change that behavior.
Comment 5 Cameron McCormack 2011-05-09 03:06:59 UTC
I've added back the check (which I am sure used to be in there) for calling Functions that correspond to IDL operations so that it throws a TypeError if the 'this' object is not an object that implements the relevant interface.  (This check was already present for most of the other Function cases, like getter/setter Functions.)  Whether an object "implements" a given interface is still kinda hand-wavey, but the intention is to throw for cases like comment 4.  I'll try to come up with a rigorous definition of "implements" as part of bug 12320.
Comment 6 Hallvord R. M. Steen 2011-05-11 05:19:05 UTC
Noticed 

apf.setZeroTimeout=(apf.isIE&&apf.isIE<9)||apf.isO3||apf.isAIR?setTimeout:(function(){ . .

in cloud9ide's source. Now, this might simply be breaking browsers they don't bother testing in..but if this is actually tested code, it seems having a pointer to setTimeout on another object will work in some browsers.
Comment 7 Cameron McCormack 2011-06-28 03:40:11 UTC
(In reply to comment #6)
> Noticed 
> 
> apf.setZeroTimeout=(apf.isIE&&apf.isIE<9)||apf.isO3||apf.isAIR?setTimeout:(function(){
> . .
> 
> in cloud9ide's source. Now, this might simply be breaking browsers they don't
> bother testing in..but if this is actually tested code, it seems having a
> pointer to setTimeout on another object will work in some browsers.

That doesn't appear to work today:
http://people.mozilla.org/~cmccormack/tests/settimeout-this.html
Comment 8 Hallvord R. M. Steen 2011-06-28 04:59:46 UTC
I've reached the same conclusion - site is probably simply broken..