|
@@ -7,19 +7,25 @@ const hasProp = {}.hasOwnProperty
|
|
|
const frameToGuest = {}
|
|
|
|
|
|
// Copy attribute of |parent| to |child| if it is not defined in |child|.
|
|
|
-const mergeOptions = function (child, parent) {
|
|
|
- let key, value
|
|
|
- for (key in parent) {
|
|
|
+const mergeOptions = function (child, parent, visited) {
|
|
|
+ // Check for circular reference.
|
|
|
+ if (visited == null) visited = new Set()
|
|
|
+ if (visited.has(parent)) return
|
|
|
+
|
|
|
+ visited.add(parent)
|
|
|
+ for (const key in parent) {
|
|
|
if (!hasProp.call(parent, key)) continue
|
|
|
- value = parent[key]
|
|
|
- if (!(key in child)) {
|
|
|
- if (typeof value === 'object') {
|
|
|
- child[key] = mergeOptions({}, value)
|
|
|
- } else {
|
|
|
- child[key] = value
|
|
|
- }
|
|
|
+ if (key in child) continue
|
|
|
+
|
|
|
+ const value = parent[key]
|
|
|
+ if (typeof value === 'object') {
|
|
|
+ child[key] = mergeOptions({}, value, visited)
|
|
|
+ } else {
|
|
|
+ child[key] = value
|
|
|
}
|
|
|
}
|
|
|
+ visited.delete(parent)
|
|
|
+
|
|
|
return child
|
|
|
}
|
|
|
|