Closed Bug 1039986 Opened 7 years ago Closed 6 years ago
.prototype .to String throws when called on Web IDL interface objects
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 < Function.prototype.toString.call(EventSource) X TypeError: Function.prototype.toString called on incompatible object Actual results: as the output mentioned above Expected results: Function.prototype.toString.call(foo) should not throw any exception if foo a instance of Function, and so is to Function.prototype.toSource.call(foo) I was doing a EventSource support detect and found this problem.
This sounds similar to bug 638414. In any case, it wouldn't be a webapp bug, it would be in the JS engine.
OS: Windows 7 → All
Product: Firefox → Core
Hardware: x86_64 → All
> Function.prototype.toString.call(foo) should not throw any exception if foo a instance of > Function That's not what the spec says. Per spec, Function.prototype.toString.call(foo) 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 Function.prototype.toString.call(obj) 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.
Status: UNCONFIRMED → NEW
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. :(
Jason, could you review the JS engine changes? Peter, same thing for the bindings changes.
Assignee: nobody → bzbarsky
Status: NEW → ASSIGNED
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+
You need to log in before you can comment on or make changes to this bug.