Skip to content
This repository was archived by the owner on Feb 26, 2024. It is now read-only.

Commit 27ca2a9

Browse files
marclavalmhevery
authored andcommitted
fix(browser): should not throw with frozen prototypes (#351)
1 parent 2e93716 commit 27ca2a9

File tree

2 files changed

+23
-3
lines changed

2 files changed

+23
-3
lines changed

lib/browser/define-property.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export function propertyPatch() {
2828
};
2929

3030
Object.create = function (obj, proto) {
31-
if (typeof proto === 'object') {
31+
if (typeof proto === 'object' && !Object.isFrozen(proto)) {
3232
Object.keys(proto).forEach(function (prop) {
3333
proto[prop] = rewriteDescriptor(obj, prop, proto[prop]);
3434
});

test/browser/registerElement.spec.ts

+22-2
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ describe('document.registerElement', ifEnvSupports(registerElement, function ()
8989
var proto = Object.create(HTMLElement.prototype);
9090

9191
Object.defineProperty(proto, 'createdCallback', <any>{
92-
writeable: false,
92+
writable: false,
9393
configurable: false,
9494
value: checkZone
9595
});
@@ -112,7 +112,7 @@ describe('document.registerElement', ifEnvSupports(registerElement, function ()
112112

113113
Object.defineProperties(proto, {
114114
createdCallback: <any>{
115-
writeable: false,
115+
writable: false,
116116
configurable: false,
117117
value: checkZone
118118
}
@@ -129,6 +129,26 @@ describe('document.registerElement', ifEnvSupports(registerElement, function ()
129129
var elt = document.createElement('x-props-desc');
130130
});
131131

132+
it('should not throw with frozen prototypes ', function () {
133+
testZone.run(function() {
134+
135+
var proto = Object.create(HTMLElement.prototype, Object.freeze(<PropertyDescriptorMap>{createdCallback: <PropertyDescriptor>{
136+
value: () => {},
137+
writable: true,
138+
configurable: true
139+
}}));
140+
141+
Object.defineProperty(proto, 'createdCallback', <any>{
142+
writable: false,
143+
configurable: false
144+
});
145+
146+
expect(function() {
147+
(<any>document).registerElement('x-frozen-desc', { prototype: proto });
148+
}).not.toThrow();
149+
});
150+
});
151+
132152

133153
it('should check bind callback if not own property', function (done) {
134154
testZone.run(function() {

0 commit comments

Comments
 (0)