Closed Bug 1194694 Opened 4 years ago Closed 4 years ago

Function.prototype.toString called on incompatible object

Categories

(Core :: DOM: Core & HTML, defect)

40 Branch
x86_64
macOS
defect
Not set

Tracking

()

RESOLVED DUPLICATE of bug 1039986

People

(Reporter: steve111, Unassigned)

References

Details

User Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.10; rv:40.0) Gecko/20100101 Firefox/40.0
Build ID: 20150812163655

Steps to reproduce:

Function.prototype.toString.call(window.Event)


Actual results:

TypeError: Function.prototype.toString called on incompatible object


Expected results:

"function Event() { [native code] }"
OS: Unspecified → Mac OS X
Hardware: Unspecified → x86_64
Component: Untriaged → DOM
Product: Firefox → Core
Relevant specs are
https://heycam.github.io/webidl/#interface-object
https://people.mozilla.org/~jorendorff/es6-draft.html#sec-function.prototype.tostring

I think we can assume that window.Event is not "a Bound Function exotic object" and it doesn't have "an [[ECMAScriptCode]] internal slot". I can't tell from either spec whether it's supposed to be "a built-in function object" or what that even means.

Chrome logs "function Event() { [native code] }" on <http://software.hixie.ch/utilities/js/live-dom-viewer/saved/3598>.
I write some third-party script that webmasters put on their sites.

My goal is to trigger custom event on document.

code:

if (typeof window.Event === 'function') {
    event = new Event(eventName);
} else if (document.createEvent) {
    event = document.createEvent('Event');
    event.initEvent(eventName, true, true);
} else if (document.createEventObject) {
    event = document.createEventObject();
    event.eventType = eventName;
}
// then dispatching

But many sites still use MooTools lib, that overrides standard functions (including window.Event).
So I need some test to know that function is not native, like:
try {
    return Utils.isFunction(fn) && Function.prototype.toString.call(fn).indexOf('[native code]') !== -1;
} catch (e) {
    return false;
}
See Also: → 1082262
Status: UNCONFIRMED → RESOLVED
Closed: 4 years ago
Resolution: --- → DUPLICATE
Duplicate of bug: 1039986
Component: DOM → DOM: Core & HTML
You need to log in before you can comment on or make changes to this bug.