Skip to content

Data: Make the data object a regular object again #4666

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 20, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/data/Data.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ Data.prototype = {

// If not, create one
if ( !value ) {
value = Object.create( null );
value = {};

// We can accept data for non-element nodes in modern browsers,
// but we should not, see #8335.
Expand Down
21 changes: 12 additions & 9 deletions test/unit/data.js
Original file line number Diff line number Diff line change
Expand Up @@ -990,17 +990,20 @@ QUnit.test( ".data(prop) does not create expando", function( assert ) {
}
} );

QUnit.test( "keys matching Object.prototype properties (gh-3256)", function( assert ) {
assert.expect( 2 );
QUnit.test( ".data() returns a regular object (jQuery <4 only, gh-4665)", function( assert ) {
assert.expect( 4 );

var div = jQuery( "<div></div>" );
function verifyRegularObject( assert, object ) {
assert.strictEqual( object.hasOwnProperty, Object.prototype.hasOwnProperty,
"Data object has the hasOwnProperty method" );
assert.strictEqual( object + "", "[object Object]",
"Data object can be stringified" );
}

assert.strictEqual( div.data( "hasOwnProperty" ), undefined,
"hasOwnProperty not matched (before forced data creation)" );
var elem = jQuery( "<div></div>" );

// Force the creation of a data object for this element.
div.data( { foo: "bar" } );
verifyRegularObject( assert, elem.data() );

assert.strictEqual( div.data( "hasOwnProperty" ), undefined,
"hasOwnProperty not matched (after forced data creation)" );
elem.data( "foo", "bar" );
verifyRegularObject( assert, elem.data() );
} );
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy