Join GitHub today
GitHub is home to over 20 million developers working together to host and review code, manage projects, and build software together.
Deferred: behavior different from ECMAScript Promise for objects with [[Call]] #3596
Comments
akihikodaki
referenced this issue
Mar 31, 2017
Closed
Deferred: Use typeof instead of isFunction #3597
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
Show comment Hide comment
gibson042
Mar 31, 2017
Member
Confirmed, but I would classify this as a bug in jQuery.isFunction rather than Deferreds, and consider improper detection of async functions to be an even bigger flaw. I'd love to switch to typeof, but doubt we actually can, especially in a minor release... even lodash still goes by toStringTag.
|
Confirmed, but I would classify this as a bug in |
gibson042
added
Bug
Core
Needs review
labels
Mar 31, 2017
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
Show comment Hide comment
akihikodaki
Apr 1, 2017
lodash says:
Checks if
valueis classified as aFunctionobject.
However, the standard requires the callbacks are functions (objects implementing [[Call]]). jQuery.isFunction and _.isFunction is inappropriate for the purpose.
akihikodaki
commented
Apr 1, 2017
|
lodash says:
However, the standard requires the callbacks are functions (objects implementing |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
Show comment Hide comment
gibson042
Apr 1, 2017
Member
It can be rather difficult to perfectly determine if an object has a [[Call]] internal method, and there are some tough edge cases (none of which we properly detect now):
- In IE9, which we still support, XML host objects have callable properties like
getElementsByTagNamefor which typeof returns "unknown". - In modern browsers,
document.allis callable but has typeof "undefined".
The intent of jQuery.isFunction is to serve as a reasonable approximation of ECMAScript IsCallable, and we're not going out of our way to catch every possible trick but I for one want it to recognize generators and async functions. So maybe we are at the point where typeof makes the most sense. @jquery/core would anyone else like to weigh in?
|
It can be rather difficult to perfectly determine if an object has a [[Call]] internal method, and there are some tough edge cases (none of which we properly detect now):
The intent of |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
Show comment Hide comment
akihikodaki
Apr 1, 2017
It can be rather difficult to perfectly determine if an object has a [[Call]] internal method, and there are some tough edge cases (none of which we properly detect now):
I was not aware of these cases. By the way, I tested the second case. document.all was not callable on Firefox 52. It was callable on Chromium 57, but jQuery.isFunction(document.all) returned false. I'm still investigating those cases.
The intent of jQuery.isFunction is to serve as a reasonable approximation of ECMAScript IsCallable
A test suggests it is different from ECMAScript IsCallable.
obj = document.createElement( "object" );
// Firefox says this is a function
assert.ok( !jQuery.isFunction( obj ), "Object Element" );Line 442 in ac9e301
It is callable. We may need to clarify the expected behavior of jQuery.isFunction. I have opened an issue. jquery/api.jquery.com#1034
akihikodaki
commented
Apr 1, 2017
I was not aware of these cases. By the way, I tested the second case.
A test suggests it is different from ECMAScript IsCallable. obj = document.createElement( "object" );
// Firefox says this is a function
assert.ok( !jQuery.isFunction( obj ), "Object Element" );Line 442 in ac9e301 It is callable. We may need to clarify the expected behavior of |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
Show comment Hide comment
akihikodaki
Apr 1, 2017
So maybe we are at the point where
typeofmakes the most sense. @jquery/core would anyone else like to weigh in?
Opened #3601.
akihikodaki
commented
Apr 1, 2017
Opened #3601. |
|
If we pursue a fix for #3600 (which I'd like to do), then the only requirement to resolve this issue will be new unit tests. |
akihikodaki commentedMar 31, 2017
•
edited
Edited 1 time
-
akihikodaki
edited Mar 31, 2017
Description
jQuery's
Deferredis expected to be a close approximation toPromiseof ECMAScript 2016 Language Specification.Promisedefined in ECMAScript 2016 testsonFulfilled, onRejected and then are objects with[[Call]].However,
isFunction, used in theDeferred, teststoStringTag, which is irrelevant from the definition. As the result,Deferredshows different behaviors for some objects such asGeneratorFunction.Link to test case
https://jsbin.com/civabuxabe/1/edit?js,console
Expected
[object Generator] { ... }, but results in0.