Skip to content

Commit

Permalink
Core: Warn and fill jQuery.isArray
Browse files Browse the repository at this point in the history
  • Loading branch information
dmethvin committed Jun 9, 2019
1 parent 18618af commit b9d93ca
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 1 deletion.
17 changes: 17 additions & 0 deletions src/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,23 @@ jQuery.parseJSON = function() {
return JSON.parse.apply( null, arguments );
};

if ( jQueryVersionSince( "3.3.0" ) ) {

migrateWarnFunc( jQuery, "isWindow",
function( obj ) {
return obj != null && obj === obj.window;
},
"jQuery.isWindow() is deprecated"
);

migrateWarnFunc( jQuery, "isArray",
function( a ) {
return Array.isArray( a );
},
"jQuery.isArray is deprecated; use Array.isArray"
);
}

migrateWarnFunc( jQuery, "holdReady", jQuery.holdReady,
"jQuery.holdReady is deprecated" );

Expand Down
13 changes: 12 additions & 1 deletion test/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -430,9 +430,20 @@ QUnit[ jQueryVersionSince( "3.3.0" ) ? "test" : "skip" ]( "jQuery.type (warn)",

} );

QUnit[ jQueryVersionSince( "3.3.0" ) ? "test" : "skip" ]( "jQuery.isArray", function( assert ) {
assert.expect( 4 );

expectWarning( assert, "isArray", 1, function() {
assert.equal( jQuery.isArray( [] ), true, "empty array" );
assert.equal( jQuery.isArray( "" ), false, "empty string" );
assert.equal( jQuery.isArray( jQuery().toArray() ), true, "toArray" );
} );

} );

TestManager.runIframeTest( "old pre-3.0 jQuery", "core-jquery2.html",
function( assert, jQuery, window, document, log ) {
assert.expect( 1 );

assert.ok( /jQuery 3/.test( log ), "logged: " + log );
} );
} );
5 changes: 5 additions & 0 deletions warnings.md
Original file line number Diff line number Diff line change
Expand Up @@ -241,3 +241,8 @@ See jQuery-ui [commit](https://github.com/jquery/jquery-ui/commit/c0093b599fcd58
**Cause:** The `jQuery.cssProps` property is a public but undocumented object that allows CSS properties with one name to be mapped into another name. It was used for legacy browsers like IE8 that used non-standard names. This object is no longer used inside jQuery since all supported browsers now use the standard CSS property names.

**Solution:** Remove any uses of `jQuery.cssProps` in application code.

#### JQMIGRATE: jQuery.isArray is deprecated; use Array.isArray
**Cause:** Older versions of JavaScript made it difficult to determine if a particular object was a true Array, so jQuery provided a cross-browser function to do the work. The browsers supported by jQuery 3.0 all provide a standard method for this purpose.

**Solution:** Replace any calls to `jQuery.isArray` with `Array.isArray`.

0 comments on commit b9d93ca

Please sign in to comment.