Skip to content

Commit

Permalink
fix(patch): fix angular#927, shoud not throw error when definePropert…
Browse files Browse the repository at this point in the history
…y with frozen desc (angular#929)
  • Loading branch information
JiaLiPassion authored and mhevery committed Dec 27, 2017
1 parent 2e5d482 commit 5a7a2af
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
12 changes: 9 additions & 3 deletions lib/browser/define-property.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,18 @@ function isUnconfigurable(obj: any, prop: any) {
}

function rewriteDescriptor(obj: any, prop: string, desc: any) {
desc.configurable = true;
// issue-927, if the desc is frozen, don't try to change the desc
if (!Object.isFrozen(desc)) {
desc.configurable = true;
}
if (!desc.configurable) {
if (!obj[unconfigurablesKey]) {
// issue-927, if the obj is frozen, don't try to set the desc to obj
if (!obj[unconfigurablesKey] && !Object.isFrozen(obj)) {
_defineProperty(obj, unconfigurablesKey, {writable: true, value: {}});
}
obj[unconfigurablesKey][prop] = true;
if (obj[unconfigurablesKey]) {
obj[unconfigurablesKey][prop] = true;
}
}
return desc;
}
Expand Down
12 changes: 12 additions & 0 deletions test/browser/define-property.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,16 @@ describe('defineProperty', function() {
.not.toThrow();
});

it('should not throw error when try to defineProperty with a frozen desc', function() {
const obj = {};
const desc = Object.freeze({value: null, writable: true});
Object.defineProperty(obj, 'prop', desc);
});

it('should not throw error when try to defineProperty with a frozen obj', function() {
const obj = {};
Object.freeze(obj);
Object.defineProperty(obj, 'prop', {configurable: true, writable: true, value: 'value'});
});

});

0 comments on commit 5a7a2af

Please sign in to comment.