Function.prototype.toString called on incompatible object

RESOLVED DUPLICATE of bug 1039986

Status

()

RESOLVED DUPLICATE of bug 1039986
3 years ago
3 years ago

People

(Reporter: steve111, Unassigned)

Tracking

40 Branch
x86_64
Mac OS X
Points:
---

Firefox Tracking Flags

(Not tracked)

Details

(Reporter)

Description

3 years ago
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] }"
(Reporter)

Updated

3 years ago
OS: Unspecified → Mac OS X
Hardware: Unspecified → x86_64

Updated

3 years ago
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>.
(Reporter)

Comment 2

3 years ago
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;
}

Updated

3 years ago
See Also: → bug 1082262
Status: UNCONFIRMED → RESOLVED
Last Resolved: 3 years ago
Resolution: --- → DUPLICATE
Duplicate of bug: 1039986
You need to log in before you can comment on or make changes to this bug.