Skip to content

Commit

Permalink
change Object.{values, entries, assign} behavior with changing enum…
Browse files Browse the repository at this point in the history
…erability on iteration

tc39/proposal-object-values-entries#5
  • Loading branch information
zloirock committed Oct 6, 2015
1 parent c0209d5 commit 32bc134
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 24 deletions.
18 changes: 10 additions & 8 deletions library/modules/$.assign.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
// 19.1.2.1 Object.assign(target, source, ...)
var toObject = require('./$.to-object')
, IObject = require('./$.iobject')
, enumKeys = require('./$.enum-keys')
, has = require('./$.has');
var $ = require('./$')
, toObject = require('./$.to-object')
, IObject = require('./$.iobject');

// should work with symbols and should have deterministic property order (V8 bug)
module.exports = require('./$.fails')(function(){
Expand All @@ -14,17 +13,20 @@ module.exports = require('./$.fails')(function(){
A[S] = 7;
K.split('').forEach(function(k){ B[k] = k; });
return a({}, A)[S] != 7 || Object.keys(a({}, B)).join('') != K;
}) ? function assign(target, source){ // eslint-disable-line no-unused-vars
}) ? function assign(target, source){ // eslint-disable-line no-unused-vars
var T = toObject(target)
, l = arguments.length
, i = 1;
, i = 1
, getKeys = $.getKeys
, getSymbols = $.getSymbols
, isEnum = $.isEnum;
while(l > i){
var S = IObject(arguments[i++])
, keys = enumKeys(S)
, keys = getSymbols ? getKeys(S).concat(getSymbols(S)) : getKeys(S)
, length = keys.length
, j = 0
, key;
while(length > j)if(has(S, key = keys[j++]))T[key] = S[key];
while(length > j)if(isEnum.call(S, key = keys[j++]))T[key] = S[key];
}
return T;
} : Object.assign;
9 changes: 5 additions & 4 deletions library/modules/$.object-to-array.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
var $ = require('./$')
, has = require('./$.has')
, toIObject = require('./$.to-iobject');
, toIObject = require('./$.to-iobject')
, isEnum = $.isEnum;
module.exports = function(isEntries){
return function(it){
var O = toIObject(it)
Expand All @@ -9,7 +9,8 @@ module.exports = function(isEntries){
, i = 0
, result = []
, key;
while(length > i)has(O, key = keys[i++]) && result.push(isEntries ? [key, O[key]] : O[key]);
return result;
while(length > i)if(isEnum.call(O, key = keys[i++])){
result.push(isEntries ? [key, O[key]] : O[key]);
} return result;
};
};
18 changes: 10 additions & 8 deletions modules/$.assign.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
// 19.1.2.1 Object.assign(target, source, ...)
var toObject = require('./$.to-object')
, IObject = require('./$.iobject')
, enumKeys = require('./$.enum-keys')
, has = require('./$.has');
var $ = require('./$')
, toObject = require('./$.to-object')
, IObject = require('./$.iobject');

// should work with symbols and should have deterministic property order (V8 bug)
module.exports = require('./$.fails')(function(){
Expand All @@ -14,17 +13,20 @@ module.exports = require('./$.fails')(function(){
A[S] = 7;
K.split('').forEach(function(k){ B[k] = k; });
return a({}, A)[S] != 7 || Object.keys(a({}, B)).join('') != K;
}) ? function assign(target, source){ // eslint-disable-line no-unused-vars
}) ? function assign(target, source){ // eslint-disable-line no-unused-vars
var T = toObject(target)
, l = arguments.length
, i = 1;
, i = 1
, getKeys = $.getKeys
, getSymbols = $.getSymbols
, isEnum = $.isEnum;
while(l > i){
var S = IObject(arguments[i++])
, keys = enumKeys(S)
, keys = getSymbols ? getKeys(S).concat(getSymbols(S)) : getKeys(S)
, length = keys.length
, j = 0
, key;
while(length > j)if(has(S, key = keys[j++]))T[key] = S[key];
while(length > j)if(isEnum.call(S, key = keys[j++]))T[key] = S[key];
}
return T;
} : Object.assign;
9 changes: 5 additions & 4 deletions modules/$.object-to-array.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
var $ = require('./$')
, has = require('./$.has')
, toIObject = require('./$.to-iobject');
, toIObject = require('./$.to-iobject')
, isEnum = $.isEnum;
module.exports = function(isEntries){
return function(it){
var O = toIObject(it)
Expand All @@ -9,7 +9,8 @@ module.exports = function(isEntries){
, i = 0
, result = []
, key;
while(length > i)has(O, key = keys[i++]) && result.push(isEntries ? [key, O[key]] : O[key]);
return result;
while(length > i)if(isEnum.call(O, key = keys[i++])){
result.push(isEntries ? [key, O[key]] : O[key]);
} return result;
};
};

0 comments on commit 32bc134

Please sign in to comment.