Skip to content

Commit

Permalink
Two bug fixes for process.mixin
Browse files Browse the repository at this point in the history
Bug nodejs#1 occurred when trying to use process.mixin on a function and
produced a fatal exception.

Bug nodejs#2 occurred when trying to do a deep merge with an object containing
one or more objects with a nodeType property. In those cases the deep
copy for this part of the object was not performed and a shallow one was
performed instead.

Both of these bugs were artifacts of the jQuery.extend port.
  • Loading branch information
felixge authored and ry committed Dec 6, 2009
1 parent f8ba9c3 commit f080de5
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/node.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ process.mixin = function() {
}

// Handle case when target is a string or something (possible in deep copy)
if ( typeof target !== "object" && !process.isFunction(target) )
if ( typeof target !== "object" && !(typeof target === 'function') )
target = {};

// mixin process itself if only one argument is passed
Expand All @@ -130,7 +130,7 @@ process.mixin = function() {
continue;

// Recurse if we're merging object values
if ( deep && copy && typeof copy === "object" && !copy.nodeType )
if ( deep && copy && typeof copy === "object" )
target[ name ] = process.mixin( deep,
// Never move original objects, clone them
src || ( copy.length != null ? [ ] : { } )
Expand Down
16 changes: 16 additions & 0 deletions test/mjsunit/test-process-mixin.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
process.mixin(require("./common"));

var target = function() {};
process.mixin(target, {
foo: 'bar'
});

assert.equal('bar', target.foo);

// This test verifies there are no DOM-related aspects to process.mixin which
// originally had been in there due to its jQuery origin.
var fakeDomElement = {deep: {nodeType: 4}};
target = {};
process.mixin(true, target, fakeDomElement);

assert.notStrictEqual(target.deep, fakeDomElement.deep);

0 comments on commit f080de5

Please sign in to comment.