Skip to content

Commit 8a73434

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. Closes gh-2627
1 parent 39cdb8c commit 8a73434

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
@@ -442,7 +442,7 @@ if ( typeof Symbol === "function" ) {
442442
/* jshint ignore: end */
443443

444444
// Populate the class2type map
445-
jQuery.each( "Boolean Number String Function Array Date RegExp Object Error".split( " " ),
445+
jQuery.each( "Boolean Number String Function Array Date RegExp Object Error Symbol".split( " " ),
446446
function( i, name ) {
447447
class2type[ "[object " + name + "]" ] = name.toLowerCase();
448448
} );

test/unit/core.js

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

275+
QUnit.test( "type for `Symbol`", function( assert ) {
276+
// Prevent reference errors
277+
if( typeof Symbol !== "function" ) {
278+
assert.expect( 0 );
279+
return
280+
}
281+
282+
assert.expect( 2 );
283+
284+
assert.equal( jQuery.type( Symbol() ), "symbol", "Symbol" );
285+
assert.equal( jQuery.type( Object( Symbol() ) ), "symbol", "Symbol" );
286+
});
287+
275288
QUnit.asyncTest( "isPlainObject", function( assert ) {
276289
assert.expect( 15 );
277290

0 commit comments

Comments
 (0)