Commit 445dbd9d authored by Dave Methvin's avatar Dave Methvin

Revert data.js rewrite.

Reverts the following commits:

commit f717226b
Author: Rick Waldron <waldron.rick@gmail.com>
Date:   Mon Dec 31 18:06:38 2012 -0500

Only splice from internal arrays when item actually exists.

commit b9cdc413
Author: Rick Waldron <waldron.rick@gmail.com>
Date:   Mon Dec 31 16:20:35 2012 -0500

Updates to data.js re-write to pass events and manipulation

commit d1de3000
Author: Rick Waldron <waldron.rick@gmail.com>
Date:   Mon Dec 31 15:09:45 2012 -0500

2.0: Rewrite data.js
parent 0d540c37
This diff is collapsed.
......@@ -16,7 +16,7 @@ jQuery.event = {
t = 0;
// Don't attach events to noData or text/comment nodes (allow plain objects tho)
if ( elem.nodeType === 3 || elem.nodeType === 8 || !types || !handler || !(elemData = data_priv.get( elem )) ) {
if ( elem.nodeType === 3 || elem.nodeType === 8 || !types || !handler || !(elemData = jQuery._data( elem )) ) {
return;
}
......@@ -124,7 +124,7 @@ jQuery.event = {
var tns, type, origType, namespaces, origCount,
j, events, special, eventType, handleObj,
t = 0,
elemData = data_priv.hasData( elem ) && data_priv.get( elem );
elemData = jQuery.hasData( elem ) && jQuery._data( elem );
if ( !elemData || !(events = elemData.events) ) {
return;
......
......@@ -327,7 +327,7 @@ jQuery.fn.extend({
for ( i = 0; i < hasScripts; i++ ) {
node = scripts[ i ];
if ( rscriptType.test( node.type || "" ) &&
!data_priv.access( node, "globalEval" ) && jQuery.contains( doc, node ) ) {
!jQuery._data( node, "globalEval" ) && jQuery.contains( doc, node ) ) {
if ( node.src ) {
// Hope ajax is available...
......@@ -514,16 +514,20 @@ jQuery.extend({
},
cleanData: function( elems, /* internal */ acceptData ) {
var data, elem, type,
var id, data, elem, type,
l = elems.length,
i = 0,
internalKey = jQuery.expando,
cache = jQuery.cache,
special = jQuery.event.special;
for ( ; i < l; i++ ) {
elem = elems[ i ];
if ( acceptData || jQuery.acceptData( elem ) ) {
data = data_priv.access( elem );
id = elem[ internalKey ];
data = id && cache[ id ];
if ( data ) {
for ( type in data.events ) {
......@@ -535,12 +539,14 @@ jQuery.extend({
jQuery.removeEvent( elem, type, data.handle );
}
}
// Remove cache only if it was not already removed by jQuery.event.remove
if ( cache[ id ] ) {
delete cache[ id ];
delete elem[ internalKey ];
}
}
}
// Discard any remaining `private` and `user` data
// (Splices the data objects out of the internal cache arrays)
data_discard( elem );
}
}
});
......@@ -574,45 +580,35 @@ function setGlobalEval( elems, refElements ) {
i = 0;
for ( ; i < l; i++ ) {
data_priv.set(
elems[ i ], "globalEval", !refElements || data_priv.get( refElements[ i ], "globalEval" )
);
jQuery._data( elems[ i ], "globalEval", !refElements || jQuery._data( refElements[ i ], "globalEval" ) );
}
}
function cloneCopyEvent( src, dest ) {
var i, l, type, pOld, pCur, uOld, uCur, events;
if ( dest.nodeType !== 1 ) {
if ( dest.nodeType !== 1 || !jQuery.hasData( src ) ) {
return;
}
// 1. Copy private data: events, handlers, etc.
if ( data_priv.hasData( src ) ) {
pOld = data_priv.access( src );
pCur = jQuery.extend( {}, pOld );
events = pOld.events;
var i, l, type,
oldData = jQuery._data( src ),
curData = jQuery._data( dest, oldData ),
events = oldData.events;
data_priv.set( dest, pCur );
if ( events ) {
delete curData.handle;
curData.events = {};
if ( events ) {
delete pCur.handle;
pCur.events = {};
for ( type in events ) {
for ( i = 0, l = events[ type ].length; i < l; i++ ) {
jQuery.event.add( dest, type, events[ type ][ i ] );
}
for ( type in events ) {
for ( i = 0, l = events[ type ].length; i < l; i++ ) {
jQuery.event.add( dest, type, events[ type ][ i ] );
}
}
}
// 2. Copy user data
if ( data_user.hasData( src ) ) {
uOld = data_user.access( src );
uCur = jQuery.extend( {}, uOld );
data_user.set( dest, uCur );
// make the cloned public data object a copy from the original
if ( curData.data ) {
curData.data = jQuery.extend( {}, curData.data );
}
}
......
......@@ -200,51 +200,47 @@ var Globals = (function() {
*/
QUnit.expectJqData = function( elems, key ) {
var i, elem, expando;
QUnit.current_testEnvironment.checkJqData = true;
if ( jQuery.cache ) {
QUnit.current_testEnvironment.checkJqData = true;
if ( elems.jquery && elems.toArray ) {
elems = elems.toArray();
}
if ( !jQuery.isArray( elems ) ) {
elems = [ elems ];
}
if ( elems.jquery && elems.toArray ) {
elems = elems.toArray();
}
if ( !jQuery.isArray( elems ) ) {
elems = [ elems ];
for ( i = 0; i < elems.length; i++ ) {
elem = elems[i];
// jQuery.data only stores data for nodes in jQuery.cache,
// for other data targets the data is stored in the object itself,
// in that case we can't test that target for memory leaks.
// But we don't have to since in that case the data will/must will
// be available as long as the object is not garbage collected by
// the js engine, and when it is, the data will be removed with it.
if ( !elem.nodeType ) {
// Fixes false positives for dataTests(window), dataTests({}).
continue;
}
for ( i = 0; i < elems.length; i++ ) {
elem = elems[i];
// jQuery.data only stores data for nodes in jQuery.cache,
// for other data targets the data is stored in the object itself,
// in that case we can't test that target for memory leaks.
// But we don't have to since in that case the data will/must will
// be available as long as the object is not garbage collected by
// the js engine, and when it is, the data will be removed with it.
if ( !elem.nodeType ) {
// Fixes false positives for dataTests(window), dataTests({}).
continue;
}
expando = elem[ jQuery.expando ];
if ( expando === undefined ) {
// In this case the element exists fine, but
// jQuery.data (or internal data) was never (in)directly
// called.
// Since this method was called it means some data was
// expected to be found, but since there is nothing, fail early
// (instead of in teardown).
notStrictEqual( expando, undefined, "Target for expectJqData must have an expando, for else there can be no data to expect." );
expando = elem[ jQuery.expando ];
if ( expando === undefined ) {
// In this case the element exists fine, but
// jQuery.data (or internal data) was never (in)directly
// called.
// Since this method was called it means some data was
// expected to be found, but since there is nothing, fail early
// (instead of in teardown).
notStrictEqual( expando, undefined, "Target for expectJqData must have an expando, for else there can be no data to expect." );
} else {
if ( expectedDataKeys[expando] ) {
expectedDataKeys[expando].push( key );
} else {
if ( expectedDataKeys[expando] ) {
expectedDataKeys[expando].push( key );
} else {
expectedDataKeys[expando] = [ key ];
}
expectedDataKeys[expando] = [ key ];
}
}
}
};
QUnit.config.urlConfig.push( {
id: "jqdata",
......@@ -262,38 +258,33 @@ var Globals = (function() {
fragmentsLength = 0,
cacheLength = 0;
if ( jQuery.cache ) {
// Only look for jQuery data problems if this test actually
// provided some information to compare against.
if ( QUnit.urlParams.jqdata || this.checkJqData ) {
for ( i in jQuery.cache ) {
expectedKeys = expectedDataKeys[i];
actualKeys = jQuery.cache[i] ? keys( jQuery.cache[i] ) : jQuery.cache[i];
if ( !QUnit.equiv( expectedKeys, actualKeys ) ) {
deepEqual( actualKeys, expectedKeys, "Expected keys exist in jQuery.cache" );
}
delete jQuery.cache[i];
delete expectedDataKeys[i];
}
// In case it was removed from cache before (or never there in the first place)
for ( i in expectedDataKeys ) {
deepEqual( expectedDataKeys[i], undefined, "No unexpected keys were left in jQuery.cache (#" + i + ")" );
delete expectedDataKeys[i];
// Only look for jQuery data problems if this test actually
// provided some information to compare against.
if ( QUnit.urlParams.jqdata || this.checkJqData ) {
for ( i in jQuery.cache ) {
expectedKeys = expectedDataKeys[i];
actualKeys = jQuery.cache[i] ? keys( jQuery.cache[i] ) : jQuery.cache[i];
if ( !QUnit.equiv( expectedKeys, actualKeys ) ) {
deepEqual( actualKeys, expectedKeys, "Expected keys exist in jQuery.cache" );
}
delete jQuery.cache[i];
delete expectedDataKeys[i];
}
// In case it was removed from cache before (or never there in the first place)
for ( i in expectedDataKeys ) {
deepEqual( expectedDataKeys[i], undefined, "No unexpected keys were left in jQuery.cache (#" + i + ")" );
delete expectedDataKeys[i];
}
// Reset data register
expectedDataKeys = {};
}
// Reset data register
expectedDataKeys = {};
// Allow QUnit.reset to clean up any attached elements before checking for leaks
QUnit.reset();
if ( jQuery.cache ) {
for ( i in jQuery.cache ) {
++cacheLength;
}
for ( i in jQuery.cache ) {
++cacheLength;
}
jQuery.fragments = {};
......@@ -343,7 +334,7 @@ var Globals = (function() {
} else {
delete jQuery.ajaxSettings;
}
// Cleanup globals
Globals.cleanup();
......
module( "data", { teardown: moduleTeardown });
module("data", { teardown: moduleTeardown });
test( "expando", function() {
test("expando", function(){
expect(1);
equal(jQuery.expando !== undefined, true, "jQuery is exposing the expando");
});
test( "jQuery.data & removeData, expected returns", function() {
expect(2);
equal(
jQuery.data( document.body, "hello", "world" ), "world",
"jjQuery.data( elem, key, value ) returns value"
);
equal(
jQuery.removeData( document.body, "hello" ), undefined,
"jjQuery.removeData( elem, key, value ) returns undefined"
);
});
test( "jQuery._data & _removeData, expected returns", function() {
expect(2);
equal(
jQuery._data( document.body, "hello", "world" ), "world",
"jjQuery.data( elem, key, value ) returns value"
);
equal(
jQuery._removeData( document.body, "hello" ), undefined,
"jjQuery.removeData( elem, key, value ) returns undefined"
);
});
function dataTests (elem) {
var oldCacheLength, dataObj, internalDataObj, expected, actual;
......@@ -126,7 +99,6 @@ test("jQuery.data(document)", 25, function() {
QUnit.expectJqData(document, "foo");
});
/*
test("Expando cleanup", 4, function() {
var expected, actual,
div = document.createElement("div");
......@@ -160,8 +132,7 @@ test("Expando cleanup", 4, function() {
// Clean up unattached element
jQuery(div).remove();
});
*/
/*
test("jQuery.acceptData", function() {
expect(7);
......@@ -179,7 +150,7 @@ test("jQuery.acceptData", function() {
applet.setAttribute("classid", "clsid:8AD9C840-044E-11D1-B3E9-00805F499D93");
ok( !jQuery.acceptData( applet ), "applet" );
});
*/
test(".data()", function() {
expect(5);
......@@ -494,8 +465,8 @@ test("jQuery.data should follow html5 specification regarding camel casing", fun
div.data("foo-bar", "d");
equal( div.data("fooBar"), "d", "Verify updated data-* key (fooBar)" );
equal( div.data("foo-bar"), "d", "Verify updated data-* key (foo-bar)" );
equal( div.data("fooBar"), "d", "Verify updated data-* key" );
equal( div.data("foo-bar"), "d", "Verify updated data-* key" );
div.remove();
});
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment