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

Commit

Permalink
fix(browser): should not throw with frozen prototypes (#351)
Browse files Browse the repository at this point in the history
  • Loading branch information
marclaval authored and mhevery committed May 26, 2016
1 parent 2e93716 commit 27ca2a9
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
2 changes: 1 addition & 1 deletion lib/browser/define-property.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export function propertyPatch() {
};

Object.create = function (obj, proto) {
if (typeof proto === 'object') {
if (typeof proto === 'object' && !Object.isFrozen(proto)) {
Object.keys(proto).forEach(function (prop) {
proto[prop] = rewriteDescriptor(obj, prop, proto[prop]);
});
Expand Down
24 changes: 22 additions & 2 deletions test/browser/registerElement.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ describe('document.registerElement', ifEnvSupports(registerElement, function ()
var proto = Object.create(HTMLElement.prototype);

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

Object.defineProperties(proto, {
createdCallback: <any>{
writeable: false,
writable: false,
configurable: false,
value: checkZone
}
Expand All @@ -129,6 +129,26 @@ describe('document.registerElement', ifEnvSupports(registerElement, function ()
var elt = document.createElement('x-props-desc');
});

it('should not throw with frozen prototypes ', function () {
testZone.run(function() {

var proto = Object.create(HTMLElement.prototype, Object.freeze(<PropertyDescriptorMap>{createdCallback: <PropertyDescriptor>{
value: () => {},
writable: true,
configurable: true
}}));

Object.defineProperty(proto, 'createdCallback', <any>{
writable: false,
configurable: false
});

expect(function() {
(<any>document).registerElement('x-frozen-desc', { prototype: proto });
}).not.toThrow();
});
});


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

0 comments on commit 27ca2a9

Please sign in to comment.