Browse Source

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: 3bb7ad6fea
v0.7.4-release
Felix Geisendörfer 15 years ago
committed by Ryan Dahl
parent
commit
55ab9b4541
  1. 2
      src/node.js
  2. 11
      test/simple/test-process-mixin.js

2
src/node.js

@ -126,7 +126,7 @@ process.mixin = function() {
if ( (source = arguments[i]) != null ) { if ( (source = arguments[i]) != null ) {
// Extend the base object // Extend the base object
Object.getOwnPropertyNames(source).forEach(function(k){ Object.getOwnPropertyNames(source).forEach(function(k){
var d = Object.getOwnPropertyDescriptor(source, k); var d = Object.getOwnPropertyDescriptor(source, k) || {value: source[k]};
if (d.get) { if (d.get) {
target.__defineGetter__(k, d.get); target.__defineGetter__(k, d.get);
if (d.set) { if (d.set) {

11
test/simple/test-process-mixin.js

@ -28,10 +28,19 @@ var source = {
get foo(){ return this._foo; }, get foo(){ return this._foo; },
set foo(value){ this._foo = "did set to "+value; } set foo(value){ this._foo = "did set to "+value; }
}; };
var target = {}; target = {};
process.mixin(target, source); process.mixin(target, source);
target._foo = 'b'; target._foo = 'b';
assert.equal(source.foo, 'a'); assert.equal(source.foo, 'a');
assert.equal('b', target.foo, 'target.foo != "b" -- value/result was copied instead of getter function'); assert.equal('b', target.foo, 'target.foo != "b" -- value/result was copied instead of getter function');
source.foo = 'c'; source.foo = 'c';
assert.equal('did set to c', source.foo, 'source.foo != "c" -- value was set instead of calling setter function'); 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…
Cancel
Save