diff options
| author | Igor Minar | 2011-11-30 14:06:04 -0500 | 
|---|---|---|
| committer | Igor Minar | 2011-11-30 14:49:36 -0500 | 
| commit | f43c226c67ab64ee056615567e51f976c7637127 (patch) | |
| tree | 8a53c1e853447f28269b23c1b81a3d1113f55e03 /src | |
| parent | 0e1fa2aefe34fe9ba5c957efde9ae4a82df54e11 (diff) | |
| download | angular.js-f43c226c67ab64ee056615567e51f976c7637127.tar.bz2 | |
fix(copy,equals): prevent browser crashes with Scope or Window
Scope and Window instances are special and when copied can crash browser. For this reason
it makes sense to compare them only by identity.
Diffstat (limited to 'src')
| -rw-r--r-- | src/Angular.js | 11 | 
1 files changed, 9 insertions, 2 deletions
| diff --git a/src/Angular.js b/src/Angular.js index e5f35bba..9a4470eb 100644 --- a/src/Angular.js +++ b/src/Angular.js @@ -413,6 +413,12 @@ function isWindow(obj) {    return obj && obj.document && obj.location && obj.alert && obj.setInterval;  } + +function isScope(obj) { +  return obj && obj.$evalAsync && obj.$watch; +} + +  function isBoolean(value) {return typeof value == $boolean;}  function isTextNode(node) {return nodeName_(node) == '#text';} @@ -580,6 +586,7 @@ function isLeafNode (node) {   * @returns {*} The copy or updated `destination`, if `destination` was specified.   */  function copy(source, destination){ +  if (isWindow(source) || isScope(source)) throw Error("Can't copy Window or Scope");    if (!destination) {      destination = source;      if (source) { @@ -629,8 +636,7 @@ function copy(source, destination){   * During a property comparision, properties of `function` type and properties with names   * that begin with `$` are ignored.   * - * Note: This function is used to augment the Object type in Angular expressions. See - * {@link angular.module.ng.$filter} for more information about Angular arrays. + * Scope and DOMWindow objects are being compared only be identify (`===`).   *   * @param {*} o1 Object or value to compare.   * @param {*} o2 Object or value to compare. @@ -650,6 +656,7 @@ function equals(o1, o2) {          return true;        }      } else { +      if (isScope(o1) || isScope(o2) || isWindow(o1) || isWindow(o2)) return false;        keySet = {};        for(key in o1) {          if (key.charAt(0) !== '$' && !isFunction(o1[key]) && !equals(o1[key], o2[key])) { | 
