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
eb7e9950
...
eb7e995014bc7c0e89874dbd189acfcaff0858c8
authored
2013-10-05 23:03:48 -0700
by
Matt DuVall
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
Change mergeObject to have option to keep references
1 parent
67163080
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
27 additions
and
2 deletions
modules/utils.js
modules/utils.js
View file @
eb7e995
...
...
@@ -622,15 +622,31 @@ function isPlainObject(obj) {
return
(
type
===
'object'
);
}
function
mergeObjectsInSlimerjs
(
origin
,
add
)
{
/**
* Object recursive merging utility for use in the SlimerJS environment
*
* @param Object origin the origin object
* @param Object add the object to merge data into origin
* @param Object opts optional options to be passed in
* @return Object
*/
function
mergeObjectsInSlimerjs
(
origin
,
add
,
opts
)
{
"use strict"
;
var
options
=
opts
||
{},
keepReferences
=
options
.
keepReferences
;
for
(
var
p
in
add
)
{
if
(
isPlainObject
(
add
[
p
]))
{
if
(
isPlainObject
(
origin
[
p
]))
{
origin
[
p
]
=
mergeObjects
(
origin
[
p
],
add
[
p
]);
}
else
{
if
(
keepReferences
)
{
origin
[
p
]
=
add
[
p
];
}
else
{
origin
[
p
]
=
clone
(
add
[
p
]);
}
}
}
else
{
origin
[
p
]
=
add
[
p
];
}
...
...
@@ -643,24 +659,33 @@ function mergeObjectsInSlimerjs(origin, add) {
*
* @param Object origin the origin object
* @param Object add the object to merge data into origin
* @param Object opts optional options to be passed in
* @return Object
*/
function
mergeObjects
(
origin
,
add
)
{
function
mergeObjects
(
origin
,
add
,
opts
)
{
"use strict"
;
var
options
=
opts
||
{},
keepReferences
=
options
.
keepReferences
;
if
(
phantom
.
casperEngine
===
'slimerjs'
)
{
// Because of an issue in the module system of slimerjs (security membranes?)
// constructor is undefined.
// let's use an other algorithm
return
mergeObjectsInSlimerjs
(
origin
,
add
);
}
for
(
var
p
in
add
)
{
if
(
add
[
p
]
&&
add
[
p
].
constructor
===
Object
)
{
if
(
origin
[
p
]
&&
origin
[
p
].
constructor
===
Object
)
{
origin
[
p
]
=
mergeObjects
(
origin
[
p
],
add
[
p
]);
}
else
{
if
(
keepReferences
)
{
origin
[
p
]
=
add
[
p
];
}
else
{
origin
[
p
]
=
clone
(
add
[
p
]);
}
}
}
else
{
origin
[
p
]
=
add
[
p
];
}
...
...
Please
register
or
sign in
to post a comment