Skip to content

Commit

Permalink
fix non-deterministic V8 Object.assign property order
Browse files Browse the repository at this point in the history
  • Loading branch information
zloirock committed Sep 26, 2015
1 parent bd7eb29 commit 79d955b
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 10 deletions.
14 changes: 9 additions & 5 deletions library/modules/$.assign.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,16 @@ var toObject = require('./$.to-object')
, IObject = require('./$.iobject')
, enumKeys = require('./$.enum-keys');

// should work with symbols
// should work with symbols and should have deterministic property order (V8 bug)
module.exports = require('./$.fails')(function(){
var O = {}
, S = Symbol();
O[S] = 7;
return Object.assign({}, O)[S] != 7;
var a = Object.assign
, A = {}
, B = {}
, S = Symbol()
, K = 'abcdefghijklmnopqrst';
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
var T = toObject(target)
, l = arguments.length
Expand Down
14 changes: 9 additions & 5 deletions modules/$.assign.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,16 @@ var toObject = require('./$.to-object')
, IObject = require('./$.iobject')
, enumKeys = require('./$.enum-keys');

// should work with symbols
// should work with symbols and should have deterministic property order (V8 bug)
module.exports = require('./$.fails')(function(){
var O = {}
, S = Symbol();
O[S] = 7;
return Object.assign({}, O)[S] != 7;
var a = Object.assign
, A = {}
, B = {}
, S = Symbol()
, K = 'abcdefghijklmnopqrst';
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
var T = toObject(target)
, l = arguments.length
Expand Down

0 comments on commit 79d955b

Please sign in to comment.