From 27ca2a94c4d31b82fe78338b085bf3ab90bee98b Mon Sep 17 00:00:00 2001 From: Marc Laval Date: Thu, 26 May 2016 18:30:05 +0200 Subject: [PATCH] fix(browser): should not throw with frozen prototypes (#351) --- lib/browser/define-property.ts | 2 +- test/browser/registerElement.spec.ts | 24 ++++++++++++++++++++++-- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/lib/browser/define-property.ts b/lib/browser/define-property.ts index 75f29296f..178eca5c6 100644 --- a/lib/browser/define-property.ts +++ b/lib/browser/define-property.ts @@ -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]); }); diff --git a/test/browser/registerElement.spec.ts b/test/browser/registerElement.spec.ts index 8533c841e..222530cb2 100644 --- a/test/browser/registerElement.spec.ts +++ b/test/browser/registerElement.spec.ts @@ -89,7 +89,7 @@ describe('document.registerElement', ifEnvSupports(registerElement, function () var proto = Object.create(HTMLElement.prototype); Object.defineProperty(proto, 'createdCallback', { - writeable: false, + writable: false, configurable: false, value: checkZone }); @@ -112,7 +112,7 @@ describe('document.registerElement', ifEnvSupports(registerElement, function () Object.defineProperties(proto, { createdCallback: { - writeable: false, + writable: false, configurable: false, value: checkZone } @@ -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({createdCallback: { + value: () => {}, + writable: true, + configurable: true + }})); + + Object.defineProperty(proto, 'createdCallback', { + writable: false, + configurable: false + }); + + expect(function() { + (document).registerElement('x-frozen-desc', { prototype: proto }); + }).not.toThrow(); + }); + }); + it('should check bind callback if not own property', function (done) { testZone.run(function() {