Преглед изворни кода

improve mergeData for edge cases (fix #4191)

Evan You пре 9 година
родитељ
комит
79cc7bc97a
1 измењених фајлова са 5 додато и 2 уклоњено
  1. 5 2
      src/core/util/options.js

+ 5 - 2
src/core/util/options.js

@@ -40,13 +40,16 @@ if (process.env.NODE_ENV !== 'production') {
  * Helper that recursively merges two data objects together.
  */
 function mergeData (to: Object, from: ?Object): Object {
+  if (!from) return to
   let key, toVal, fromVal
-  for (key in from) {
+  const keys = Object.keys(from)
+  for (let i = 0; i < keys.length; i++) {
+    key = keys[i]
     toVal = to[key]
     fromVal = from[key]
     if (!hasOwn(to, key)) {
       set(to, key, fromVal)
-    } else if (isObject(toVal) && isObject(fromVal)) {
+    } else if (isPlainObject(toVal) && isPlainObject(fromVal)) {
       mergeData(toVal, fromVal)
     }
   }