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
332a4905
Commit
332a4905
authored
Apr 01, 2013
by
Rick Waldron
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Avoid side-effects when calling jQuery.hasData
Signed-off-by:
Rick Waldron
<
waldron.rick@gmail.com
>
parent
1f530e28
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
19 additions
and
2 deletions
+19
-2
data.js
src/data.js
+8
-2
data.js
test/unit/data.js
+11
-0
No files found.
src/data.js
View file @
332a4905
...
@@ -21,11 +21,17 @@ function Data() {
...
@@ -21,11 +21,17 @@ function Data() {
Data
.
uid
=
1
;
Data
.
uid
=
1
;
Data
.
prototype
=
{
Data
.
prototype
=
{
key
:
function
(
owner
)
{
key
:
function
(
owner
,
options
)
{
var
descriptor
=
{},
var
descriptor
=
{},
// Check if the owner object already has a cache key
// Check if the owner object already has a cache key
unlock
=
owner
[
this
.
expando
];
unlock
=
owner
[
this
.
expando
];
// `readonly` calls from hasData, on owners with no key
// should not create new/empty cache records
if
(
!
unlock
&&
(
options
&&
options
.
readonly
)
)
{
return
null
;
}
// If not, create one
// If not, create one
if
(
!
unlock
)
{
if
(
!
unlock
)
{
unlock
=
Data
.
uid
++
;
unlock
=
Data
.
uid
++
;
...
@@ -158,7 +164,7 @@ Data.prototype = {
...
@@ -158,7 +164,7 @@ Data.prototype = {
},
},
hasData
:
function
(
owner
)
{
hasData
:
function
(
owner
)
{
return
!
jQuery
.
isEmptyObject
(
return
!
jQuery
.
isEmptyObject
(
this
.
cache
[
this
.
key
(
owner
)
]
this
.
cache
[
this
.
key
(
owner
,
{
readonly
:
true
})
]
||
{}
);
);
},
},
discard
:
function
(
owner
)
{
discard
:
function
(
owner
)
{
...
...
test/unit/data.js
View file @
332a4905
...
@@ -51,6 +51,17 @@ test( "jQuery._data & _removeData, expected returns", function() {
...
@@ -51,6 +51,17 @@ test( "jQuery._data & _removeData, expected returns", function() {
);
);
});
});
test
(
"jQuery.hasData no side effects"
,
function
()
{
expect
(
1
);
var
obj
=
{};
jQuery
.
hasData
(
obj
);
equal
(
Object
.
getOwnPropertyNames
(
obj
).
length
,
0
,
"No data expandos where added when calling jQuery.hasData(o)"
);
});
function
dataTests
(
elem
)
{
function
dataTests
(
elem
)
{
var
oldCacheLength
,
dataObj
,
internalDataObj
,
expected
,
actual
;
var
oldCacheLength
,
dataObj
,
internalDataObj
,
expected
,
actual
;
...
...
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