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