From 55ab9b4541b2507f4e5491dd07437fab10867425 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20Geisend=C3=B6rfer?= Date: Mon, 1 Mar 2010 16:05:28 +0100 Subject: [PATCH] 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 --- src/node.js | 2 +- test/simple/test-process-mixin.js | 11 ++++++++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/node.js b/src/node.js index a1054206c8..221a5a2657 100644 --- a/src/node.js +++ b/src/node.js @@ -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) { diff --git a/test/simple/test-process-mixin.js b/test/simple/test-process-mixin.js index 18d21f53ef..ca7bf9545b 100644 --- a/test/simple/test-process-mixin.js +++ b/test/simple/test-process-mixin.js @@ -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); \ No newline at end of file