Skip to content
Toggle navigation
Toggle navigation
This project
Loading...
Sign in
John McEleney
/
casperjs
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Network
Create a new issue
Builds
Commits
Issue Boards
Files
Commits
Network
Compare
Branches
Tags
Commit
2c8ee5d6
...
2c8ee5d60d1c0ade6896333aad19e419401547ea
authored
2013-02-07 12:47:13 -0800
by
Nicolas Perriault
Browse Files
Options
Browse Files
Tag
Download
Plain Diff
Merge pull request #370 from ThomasR/master
Fix for util.mergeObjects({}, foo);
2 parents
01395ab9
05931919
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
15 additions
and
6 deletions
modules/utils.js
tests/suites/utils.js
modules/utils.js
View file @
2c8ee5d
...
...
@@ -545,14 +545,14 @@ exports.isWebPage = isWebPage;
function
mergeObjects
(
origin
,
add
)
{
"use strict"
;
for
(
var
p
in
add
)
{
try
{
if
(
add
[
p
].
constructor
===
Object
)
{
if
(
add
[
p
]
&&
add
[
p
].
constructor
===
Object
)
{
if
(
origin
[
p
]
&&
origin
[
p
].
constructor
===
Object
)
{
origin
[
p
]
=
mergeObjects
(
origin
[
p
],
add
[
p
]);
}
else
{
origin
[
p
]
=
add
[
p
]
;
origin
[
p
]
=
clone
(
add
[
p
])
;
}
}
catch
(
e
)
{
origin
[
p
]
=
add
[
p
];
}
else
{
origin
[
p
]
=
add
[
p
];
}
}
return
origin
;
...
...
tests/suites/utils.js
View file @
2c8ee5d
...
...
@@ -264,7 +264,7 @@ casper.test.begin('isJsFile() tests', 5, function(test) {
test
.
done
();
});
casper
.
test
.
begin
(
'mergeObjects() tests'
,
5
,
function
(
test
)
{
casper
.
test
.
begin
(
'mergeObjects() tests'
,
7
,
function
(
test
)
{
var
testCases
=
[
{
obj1
:
{
a
:
1
},
obj2
:
{
b
:
2
},
merged
:
{
a
:
1
,
b
:
2
}
...
...
@@ -273,6 +273,9 @@ casper.test.begin('mergeObjects() tests', 5, function(test) {
obj1
:
{},
obj2
:
{
a
:
1
},
merged
:
{
a
:
1
}
},
{
obj1
:
{},
obj2
:
{
a
:
{
b
:
2
}},
merged
:
{
a
:
{
b
:
2
}}
},
{
obj1
:
{
a
:
1
},
obj2
:
{},
merged
:
{
a
:
1
}
},
{
...
...
@@ -295,6 +298,12 @@ casper.test.begin('mergeObjects() tests', 5, function(test) {
'mergeObjects() can merge objects'
);
});
var
obj
=
{
x
:
1
};
var
merged1
=
utils
.
mergeObjects
({},
{
a
:
obj
});
var
merged2
=
utils
.
mergeObjects
({
a
:
{}},
{
a
:
obj
});
merged1
.
a
.
x
=
2
;
merged2
.
a
.
x
=
2
;
test
.
assertEquals
(
obj
.
x
,
1
,
'mergeObjects() creates deep clones'
);
test
.
done
();
});
...
...
Please
register
or
sign in
to post a comment