Closed Bug 1039986 Opened 10 years ago Closed 8 years ago

Function.prototype.toString throws when called on Web IDL interface objects


(Core :: JavaScript Engine, defect)

30 Branch
Not set



Tracking Status
firefox44 --- fixed


(Reporter: fuweichin, Assigned: bzbarsky)


(Blocks 2 open bugs)



(2 files)

User Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/35.0.1916.153 Safari/537.36

Steps to reproduce:

Open a blank page, open the DevTool, then switch to Console, and do the following

< typeof EventSource
> "function"
< EventSource instanceof Function
> true
X TypeError: Function.prototype.toString called on incompatible object

Actual results:

as the output mentioned above

Expected results: should not throw any exception if foo a instance of Function, and so is to

I was doing a EventSource support detect and found this problem.
Component: Untriaged → Webapp Runtime
Group: core-security
This sounds similar to bug 638414.  In any case, it wouldn't be a webapp bug, it would be in the JS engine.
Component: Webapp Runtime → JavaScript Engine
OS: Windows 7 → All
Product: Firefox → Core
Hardware: x86_64 → All
> should not throw any exception if foo a instance of
> Function

That's not what the spec says.

Per spec, should not throw any exception if foo is a Function.  Being instanceof Function doesn't make something a Function.  Nor does having a typeof == "function".  Here's a trivial example:

  var obj = document.createElement("object");
  obj.__proto__ == Function.prototype;

now "obj instanceof Function" tests true and "typeof obj" is "function", but it's clearly not actually a Function and will throw.

As it happens, Web IDL interface objects are not actually Functions right now, because they need custom instanceof behavior.  And even if that were fixed it'd still need a custom class due to needing Xray behavior and whatnot.

Since those are implementation details, though, it would be ideal if Function.prototype.toString did in fact work on it.  I'm happy to do whatever I can on the binding end to help make this work, but I can't make obj->is<JSFunction>() test true, sadly.
Ever confirmed: true
Summary: Function.prototype.toString Throws A called_on_incompatible_object Exception → Function.prototype.toString throws when called on Web IDL interface objects
Eric, this is another SpiderMonkey issue relevant to DOM stuff.  Maybe we should have a tracker for these, because I'm clearly not keeping them very straight when you ask me about them.  :(
Flags: needinfo?(efaustbmo)
Blocks: 1213792
Jason, could you review the JS engine changes?   Peter, same thing for the bindings changes.
Attachment #8672684 - Flags: review?(peterv)
Attachment #8672684 - Flags: review?(jorendorff)
Assignee: nobody → bzbarsky
Flags: needinfo?(efaustbmo)
Comment on attachment 8672684 [details] [diff] [review]
Make Function.prototype.toString work on Web IDL interface objects

Review of attachment 8672684 [details] [diff] [review]:

r=me on the js/ parts.
Attachment #8672684 - Flags: review?(jorendorff) → review+
Attachment #8672684 - Flags: review?(peterv) → review+
Closed: 8 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla44
You need to log in before you can comment on or make changes to this bug.