Bug fix for deep process.mixin array handling
process.mixin was throwing an exception when trying to do a deep copy of an object that included an array. This bug was introduced in: 3bb7ad6fea42545e9d84ba5cbef8b48e470790fc
This commit is contained in:
parent
6034701f57
commit
55ab9b4541
@ -126,7 +126,7 @@ process.mixin = function() {
|
||||
if ( (source = arguments[i]) != null ) {
|
||||
// Extend the base object
|
||||
Object.getOwnPropertyNames(source).forEach(function(k){
|
||||
var d = Object.getOwnPropertyDescriptor(source, k);
|
||||
var d = Object.getOwnPropertyDescriptor(source, k) || {value: source[k]};
|
||||
if (d.get) {
|
||||
target.__defineGetter__(k, d.get);
|
||||
if (d.set) {
|
||||
|
@ -28,10 +28,19 @@ var source = {
|
||||
get foo(){ return this._foo; },
|
||||
set foo(value){ this._foo = "did set to "+value; }
|
||||
};
|
||||
var target = {};
|
||||
target = {};
|
||||
process.mixin(target, source);
|
||||
target._foo = 'b';
|
||||
assert.equal(source.foo, 'a');
|
||||
assert.equal('b', target.foo, 'target.foo != "b" -- value/result was copied instead of getter function');
|
||||
source.foo = 'c';
|
||||
assert.equal('did set to c', source.foo, 'source.foo != "c" -- value was set instead of calling setter function');
|
||||
|
||||
// Test that nested arrays are handled properly
|
||||
target = {};
|
||||
process.mixin(true, target, {
|
||||
foo: ['bar'],
|
||||
});
|
||||
|
||||
assert.notStrictEqual(['bar'], target.foo);
|
||||
assert.deepEqual(['bar'], target.foo);
|
Loading…
x
Reference in New Issue
Block a user