Skip to content

Commit c7cf286

Browse files
ChristianGretemarkelog
authored andcommitted
Core: Support Symbol wrapper objects in jQuery.type
In ECMAScript 2015 (ES6), the native typeof operator returns "symbol" for Symbol primitives. As it is possible to wrap symbols using the Object constructor, symbols can be objects as well as any other primitive type in JavaScript and should be determined by jQuery.type. Cherry-picked from 8a73434 Closes gh-2627
1 parent 905ab09 commit c7cf286

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

src/core.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -498,7 +498,7 @@ if ( typeof Symbol === "function" ) {
498498
/* jshint ignore: end */
499499

500500
// Populate the class2type map
501-
jQuery.each( "Boolean Number String Function Array Date RegExp Object Error".split( " " ),
501+
jQuery.each( "Boolean Number String Function Array Date RegExp Object Error Symbol".split( " " ),
502502
function( i, name ) {
503503
class2type[ "[object " + name + "]" ] = name.toLowerCase();
504504
} );

test/unit/core.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,19 @@ QUnit.test( "type", function( assert ) {
264264
assert.equal( jQuery.type( new MyObject() ), "object", "Object" );
265265
} );
266266

267+
QUnit.test( "type for `Symbol`", function( assert ) {
268+
// Prevent reference errors
269+
if( typeof Symbol !== "function" ) {
270+
assert.expect( 0 );
271+
return
272+
}
273+
274+
assert.expect( 2 );
275+
276+
assert.equal( jQuery.type( Symbol() ), "symbol", "Symbol" );
277+
assert.equal( jQuery.type( Object( Symbol() ) ), "symbol", "Symbol" );
278+
});
279+
267280
QUnit.asyncTest( "isPlainObject", function( assert ) {
268281
assert.expect( 16 );
269282

0 commit comments

Comments
 (0)