diff options
author | Christian Grete <webmaster@christiangrete.com> | 2015-10-03 00:28:34 +0200 |
---|---|---|
committer | Oleg Gaidarenko <markelog@gmail.com> | 2015-10-13 01:18:39 +0300 |
commit | c7cf28681eeb2a7f6d71e5e17b293c252900bda7 (patch) | |
tree | d29f76e6ac6da06258cb019017f6ed0495301e45 | |
parent | 905ab09afcead6498c1ffc2f82218c51b55352a0 (diff) | |
download | jquery-c7cf28681eeb2a7f6d71e5e17b293c252900bda7.tar.gz jquery-c7cf28681eeb2a7f6d71e5e17b293c252900bda7.zip |
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 8a734344f2566dab5b8d34ecd79ae81ebd8843c5
Closes gh-2627
-rw-r--r-- | src/core.js | 2 | ||||
-rw-r--r-- | test/unit/core.js | 13 |
2 files changed, 14 insertions, 1 deletions
diff --git a/src/core.js b/src/core.js index 0bab1a80c..5e0037f19 100644 --- a/src/core.js +++ b/src/core.js @@ -498,7 +498,7 @@ if ( typeof Symbol === "function" ) { /* jshint ignore: end */ // Populate the class2type map -jQuery.each( "Boolean Number String Function Array Date RegExp Object Error".split( " " ), +jQuery.each( "Boolean Number String Function Array Date RegExp Object Error Symbol".split( " " ), function( i, name ) { class2type[ "[object " + name + "]" ] = name.toLowerCase(); } ); diff --git a/test/unit/core.js b/test/unit/core.js index f8fb1c7cd..c6d68df2d 100644 --- a/test/unit/core.js +++ b/test/unit/core.js @@ -264,6 +264,19 @@ QUnit.test( "type", function( assert ) { assert.equal( jQuery.type( new MyObject() ), "object", "Object" ); } ); +QUnit.test( "type for `Symbol`", function( assert ) { + // Prevent reference errors + if( typeof Symbol !== "function" ) { + assert.expect( 0 ); + return + } + + assert.expect( 2 ); + + assert.equal( jQuery.type( Symbol() ), "symbol", "Symbol" ); + assert.equal( jQuery.type( Object( Symbol() ) ), "symbol", "Symbol" ); +}); + QUnit.asyncTest( "isPlainObject", function( assert ) { assert.expect( 16 ); |