Skip to content

Commit

Permalink
Merge pull request #2007 from montagejs/bugs/object-assign-shim
Browse files Browse the repository at this point in the history
Allow undefined arguments to be passed to Object.assign
  • Loading branch information
marchant authored Feb 5, 2019
2 parents 591e60e + a078d12 commit ad7e919
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
8 changes: 5 additions & 3 deletions core/shim/object.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,11 @@ if (!Object.assign) {
}
for (s = 1, ss = arguments.length; s < ss; ++s) {
source = arguments[s];
keys = Object.keys(source);
for (k = 0, kk = keys.length; k < kk; ++k) {
target[keys[k]] = source[keys[k]];
if (source) {
keys = Object.keys(source);
for (k = 0, kk = keys.length; k < kk; ++k) {
target[keys[k]] = source[keys[k]];
}
}
}
return target;
Expand Down
15 changes: 15 additions & 0 deletions test/spec/core/core-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -658,4 +658,19 @@ describe("core/core-spec", function () {
expect(delegate.methodToBeCalled).toHaveBeenCalled();
});
});

describe("Object shim", function () {

it("should accept undefined arguments to assign()", function () {
var object = {aProperty: 23},
error = null;
try {
Object.assign(object, undefined);
} catch (e) {
error = e;
}
expect(error).toBeNull();
});
});

});

0 comments on commit ad7e919

Please sign in to comment.