Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
J
jquery
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
夏彬
jquery
Commits
55e319aa
Commit
55e319aa
authored
Apr 24, 2013
by
Corey Frang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixes #13815: Ensure each element has its own private data object - Tests by @rwldrn
parent
3a619407
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
16 additions
and
9 deletions
+16
-9
data.js
src/data.js
+3
-6
manipulation.js
src/manipulation.js
+1
-3
data.js
test/unit/data.js
+12
-0
No files found.
src/data.js
View file @
55e319aa
...
...
@@ -90,13 +90,9 @@ Data.prototype = {
// Handle: [ owner, { properties } ] args
}
else
{
// Support an expectation from the old data system where plain
// objects used to initialize would be set to the cache by
// reference, instead of having properties and values copied.
// Note, this will kill the connection between
// "this.cache[ unlock ]" and "cache"
// Fresh assignments by object are shallow copied
if
(
jQuery
.
isEmptyObject
(
cache
)
)
{
this
.
cache
[
unlock
]
=
data
;
jQuery
.
extend
(
this
.
cache
[
unlock
],
data
)
;
// Otherwise, copy the properties one-by-one to the cache object
}
else
{
for
(
prop
in
data
)
{
...
...
@@ -104,6 +100,7 @@ Data.prototype = {
}
}
}
return
cache
;
},
get
:
function
(
owner
,
key
)
{
// Either a valid cache is found, or will be created.
...
...
src/manipulation.js
View file @
55e319aa
...
...
@@ -527,11 +527,9 @@ function cloneCopyEvent( src, dest ) {
// 1. Copy private data: events, handlers, etc.
if
(
data_priv
.
hasData
(
src
)
)
{
pdataOld
=
data_priv
.
access
(
src
);
pdataCur
=
jQuery
.
extend
(
{}
,
pdataOld
);
pdataCur
=
data_priv
.
set
(
dest
,
pdataOld
);
events
=
pdataOld
.
events
;
data_priv
.
set
(
dest
,
pdataCur
);
if
(
events
)
{
delete
pdataCur
.
handle
;
pdataCur
.
events
=
{};
...
...
test/unit/data.js
View file @
55e319aa
...
...
@@ -244,6 +244,18 @@ test("jQuery(plain Object).data(String, Object).data(String)", function() {
deepEqual
(
$obj
[
0
],
{
exists
:
true
},
"removeData does not clear the object"
);
});
test
(
".data(object) does not retain references. #13815"
,
function
()
{
expect
(
2
);
var
$divs
=
jQuery
(
"<div></div><div></div>"
).
appendTo
(
"#qunit-fixture"
);
$divs
.
data
({
"type"
:
"foo"
});
$divs
.
eq
(
0
).
data
(
"type"
,
"bar"
);
equal
(
$divs
.
eq
(
0
).
data
(
"type"
),
"bar"
,
"Correct updated value"
);
equal
(
$divs
.
eq
(
1
).
data
(
"type"
),
"foo"
,
"Original value retained"
);
});
test
(
"data-* attributes"
,
function
()
{
expect
(
40
);
var
prop
,
i
,
l
,
metadata
,
elem
,
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment