diff --git a/public/javascripts/core/collections/hash_table.js b/public/javascripts/core/collections/hash_table.js index 13456d0..6c9b134 100644 --- a/public/javascripts/core/collections/hash_table.js +++ b/public/javascripts/core/collections/hash_table.js @@ -167,14 +167,14 @@ thisModule.addSlots(avocado.hashTable, function(add) { }, {category: ['accessing']}); add.method('_each', function (iterator) { - for (var h in this._buckets) { - if (this._buckets.hasOwnProperty(h)) { - var b = this._buckets[h]; - if (b instanceof Array) { - for (var i = 0, n = b.length; i < n; ++i) { - var entry = b[i]; - iterator(entry); - } + var keys = Object.native_keys(this._buckets); + var length = keys.length; + for (var i = 0; i < length; i++) { + var b = this._buckets[keys[i]]; + if(b && b instanceof Array) { + for (var j = 0, n = b.length; j < n; ++j) { + var entry = b[j]; + iterator(entry); } } } diff --git a/public/javascripts/core/deep_copy.js b/public/javascripts/core/deep_copy.js index d4a31cb..9e77e01 100644 --- a/public/javascripts/core/deep_copy.js +++ b/public/javascripts/core/deep_copy.js @@ -42,20 +42,21 @@ thisModule.addSlots(avocado.deepCopier, function(add) { var isArray = isObj && (o instanceof Array); c = isObj ? (isArray ? [] : Object.create(o['__proto__'])) : eval("(" + o.toString() + ")"); var thisCopier = this; - for (var n in o) { - if (o.hasOwnProperty(n)) { - var contents = o[n]; - if (n === '__annotation__') { - c[n] = contents.copy(); + var keys = Object.native_keys(o); + var length = keys.length; + for (var j = 0; j < length; ++j){ + var n = keys[j]; + var contents = o[n]; + if (n === '__annotation__') { + c[n] = contents.copy(); + } else if (contents) { + var contentsType = typeof(contents); + var contentsCreatorSlot = (contentsType === 'object' || contentsType === 'function') && avocado.annotator.theCreatorSlotOf(contents); + if (contentsCreatorSlot && contentsCreatorSlot.name === n && contentsCreatorSlot.holder === o) { + c[n] = thisCopier.createCopyOf(contents); + avocado.annotator.annotationOf(c[n]).setCreatorSlot(n, c); } else { - var contentsType = typeof(contents); - var contentsCreatorSlot = (contentsType === 'object' || contentsType === 'function') && avocado.annotator.theCreatorSlotOf(contents); - if (contentsCreatorSlot && contentsCreatorSlot.name === n && contentsCreatorSlot.holder === o) { - c[n] = thisCopier.createCopyOf(contents); - avocado.annotator.annotationOf(c[n]).setCreatorSlot(n, c); - } else { - c[n] = contents; - } + c[n] = contents; } } } @@ -87,12 +88,15 @@ thisModule.addSlots(avocado.deepCopier, function(add) { var thisCopier = this; var originalsAndCopies = this._originalsAndCopies; var originalsAndCopiesCount = originalsAndCopies.length; - for (var n in c) { - if (c.hasOwnProperty(n)) { + var keys = Object.native_keys(c); + var length = keys.length; + for (var j = 0; j < length; ++j){ + var n = keys[j]; + var contents = c[n]; + if (contents) { if (n === '__annotation__') { // just ignore it, no refs to fix up, I think - oh, actually, could do the creator slot, but we've already done it up above - } else { - var contents = c[n]; + } else { var contentsType = typeof(contents); if (contentsType === 'object' || contentsType === 'function') { var wasInternalRef = false; diff --git a/public/javascripts/lk/Base.js b/public/javascripts/lk/Base.js index 5964d25..d2c0199 100644 --- a/public/javascripts/lk/Base.js +++ b/public/javascripts/lk/Base.js @@ -47,7 +47,8 @@ Object.defineProperties = function(object, descriptorSet) { } return object; } - + +Object.native_keys = Object.keys; Object.defineProperties(Object, { // I like mine better. -- Adam /* @@ -62,12 +63,15 @@ Object.defineProperties(Object, { */ keys: { - value: function(object, optFast) { - if (typeof object !== 'object') throw new TypeError('not an object'); - var names = []; // check behavior wrt arrays - for (var name in object) { - if (object.hasOwnProperty(name)) - names.push(name); + value: function(object, optFast) { + if (typeof object !== 'object' && typeof object !== 'function') throw new TypeError('not an object'); + var names = []; // check behavior wrt arrays + var keys = Object.native_keys(object); + var length = keys.length; + for (var i = 0; i < length; ++i) { + var name = keys[i]; + if (object[name]) + names.push(name); } if (!optFast) names.sort(); return names;