Skip to content
This repository was archived by the owner on Feb 26, 2024. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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'});
});

});