Skip to content

Commit

Permalink
Merge pull request #315 from yiminghe/definePropertyFix
Browse files Browse the repository at this point in the history
Shimmed `Object.defineProperty` should not throw for an empty descriptor
  • Loading branch information
ljharb committed Jun 24, 2015
2 parents 373d629 + 3680962 commit 0b903e9
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 1 addition & 1 deletion es5-sham.js
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,7 @@ if (!Object.defineProperty || definePropertyFallback) {
object[property] = descriptor.value;
}
} else {
if (!supportsAccessors) {
if (!supportsAccessors && (('get' in descriptor) || ('set' in descriptor))) {
throw new TypeError(ERR_ACCESSORS_NOT_SUPPORTED);
}
// If we got that far then getters and setters can be defined !!
Expand Down
6 changes: 6 additions & 0 deletions tests/spec/s-object.js
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,12 @@ describe('Object', function () {
Object.defineProperty(42, 'name', {});
}).toThrow();
});

it('should not throw error for empty descriptor', function () {
expect(function () {
Object.defineProperty({}, 'name', {});
}).not.toThrow();
});
});

describe('Object.getOwnPropertyDescriptor', function () {
Expand Down

0 comments on commit 0b903e9

Please sign in to comment.