Permalink
Browse files

Data: Don't expose jQuery.acceptData

jQuery.acceptData is an undocumented internal API that shouldn't be exposed.

Fixes gh-2555
  • Loading branch information...
jbedard authored and mgol committed Aug 25, 2015
1 parent 02e1008 commit 224271982eb9cd351d7db1b38c740b4e927e6f97
Showing with 27 additions and 33 deletions.
  1. +3 −4 src/data/Data.js
  2. +2 −6 src/data/{accepts.js → var/acceptData.js}
  3. +5 −5 src/event.js
  4. +3 −3 src/manipulation.js
  5. +14 −15 test/unit/data.js
View
@@ -1,15 +1,14 @@
define( [
"../core",
"../var/rnotwhite",
"./accepts"
], function( jQuery, rnotwhite ) {
"./var/acceptData"
], function( jQuery, rnotwhite, acceptData ) {
function Data() {
this.expando = jQuery.expando + Data.uid++;
}
Data.uid = 1;
Data.accepts = jQuery.acceptData;
Data.prototype = {
@@ -38,7 +37,7 @@ Data.prototype = {
// We can accept data for non-element nodes in modern browsers,
// but we should not, see #8335.
// Always return an empty object.
if ( !Data.accepts( owner ) ) {
if ( !acceptData( owner ) ) {
return {};
}
@@ -1,12 +1,9 @@
define( [
"../core"
], function( jQuery ) {
define( function() {
/**
* Determines whether an object can have data
*/
jQuery.acceptData = function( owner ) {
return function( owner ) {
// Accepts only:
// - Node
// - Node.ELEMENT_NODE
@@ -17,5 +14,4 @@ jQuery.acceptData = function( owner ) {
return owner.nodeType === 1 || owner.nodeType === 9 || !( +owner.nodeType );
};
return jQuery.acceptData;
} );
View
@@ -6,11 +6,11 @@ define( [
"./var/slice",
"./event/support",
"./data/var/dataPriv",
"./data/var/acceptData",
"./core/init",
"./data/accepts",
"./selector"
], function( jQuery, document, rnotwhite, hasOwn, slice, support, dataPriv ) {
], function( jQuery, document, rnotwhite, hasOwn, slice, support, dataPriv, acceptData ) {
var
rkeyEvent = /^key/,
@@ -376,7 +376,7 @@ jQuery.event = {
// Native handler
handle = ontype && cur[ ontype ];
if ( handle && handle.apply && jQuery.acceptData( cur ) ) {
if ( handle && handle.apply && acceptData( cur ) ) {
event.result = handle.apply( cur, data );
if ( event.result === false ) {
event.preventDefault();
@@ -389,8 +389,8 @@ jQuery.event = {
if ( !onlyHandlers && !event.isDefaultPrevented() ) {
if ( ( !special._default ||
special._default.apply( eventPath.pop(), data ) === false ) &&
jQuery.acceptData( elem ) ) {
special._default.apply( eventPath.pop(), data ) === false ) &&
acceptData( elem ) ) {
// Call a native DOM method on the target with the same name name as the event.
// Don't do default actions on window, that's where global variables be (#6170)
View
@@ -14,16 +14,16 @@ define( [
"./data/var/dataPriv",
"./data/var/dataUser",
"./data/var/acceptData",
"./core/init",
"./data/accepts",
"./traversing",
"./selector",
"./event"
], function( jQuery, concat, push, access,
rcheckableType, rtagName, rscriptType,
wrapMap, getAll, setGlobalEval, buildFragment, support,
dataPriv, dataUser ) {
dataPriv, dataUser, acceptData ) {
var
rxhtmlTag = /<(?!area|br|col|embed|hr|img|input|link|meta|param)(([\w:-]+)[^>]*)\/>/gi,
@@ -273,7 +273,7 @@ jQuery.extend( {
i = 0;
for ( ; ( elem = elems[ i ] ) !== undefined; i++ ) {
if ( jQuery.acceptData( elem ) ) {
if ( acceptData( elem ) ) {
if ( ( data = elem[ dataPriv.expando ] ) ) {
if ( data.events ) {
for ( type in data.events ) {
View
@@ -819,32 +819,31 @@ QUnit.test( ".data doesn't throw when calling selection is empty. #13551", funct
}
} );
QUnit.test( "jQuery.acceptData", function( assert ) {
QUnit.test( "acceptData", function( assert ) {
assert.expect( 10 );
var flash, pdf;
var flash, pdf, form;
assert.ok( jQuery.acceptData( document ), "document" );
assert.ok( jQuery.acceptData( document.documentElement ), "documentElement" );
assert.ok( jQuery.acceptData( {} ), "object" );
assert.ok( jQuery.acceptData( document.createElement( "embed" ) ), "embed" );
assert.equal( 42, jQuery( document ).data( "test", 42 ).data( "test" ), "document" );
assert.equal( 42, jQuery( document.documentElement ).data( "test", 42 ).data( "test" ), "documentElement" );
assert.equal( 42, jQuery( {} ).data( "test", 42 ).data( "test" ), "object" );
assert.equal( 42, jQuery( document.createElement( "embed" ) ).data( "test", 42 ).data( "test" ), "embed" );
flash = document.createElement( "object" );
flash.setAttribute( "classid", "clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" );
assert.ok( jQuery.acceptData( flash ), "flash" );
assert.equal( 42, jQuery( flash ).data( "test", 42 ).data( "test" ), "flash" );
pdf = document.createElement( "object" );
pdf.setAttribute( "classid", "clsid:CA8A9780-280D-11CF-A24D-444553540000" );
assert.ok( jQuery.acceptData( pdf ), "pdf" );
assert.equal( 42, jQuery( pdf ).data( "test", 42 ).data( "test" ), "pdf" );
assert.ok( !jQuery.acceptData( document.createComment( "" ) ), "comment" );
assert.ok( !jQuery.acceptData( document.createTextNode( "" ) ), "text" );
assert.ok( !jQuery.acceptData( document.createDocumentFragment() ), "documentFragment" );
assert.equal( undefined, jQuery( document.createComment( "" ) ).data( "test", 42 ).data( "test" ), "comment" );
assert.equal( undefined, jQuery( document.createTextNode( "" ) ).data( "test", 42 ).data( "test" ), "text" );
assert.equal( undefined, jQuery( document.createDocumentFragment() ).data( "test", 42 ).data( "test" ), "documentFragment" );
assert.ok( jQuery.acceptData(
jQuery( "#form" ).append( "<input id='nodeType'/><input id='nodeName'/>" )[ 0 ] ),
"form with aliased DOM properties" );
} );
form = jQuery( "#form" ).append( "<input id='nodeType'/><input id='nodeName'/>" )[ 0 ];
assert.equal( 42, jQuery( form ) .data( "test", 42 ).data( "test" ), "form with aliased DOM properties" );
});
QUnit.test( "Check proper data removal of non-element descendants nodes (#8335)", function( assert ) {
assert.expect( 1 );

0 comments on commit 2242719

Please sign in to comment.