Make HTMLElement.prototype.constructor configurable and writable

This commit is contained in:
Justin Fagnani
2016-08-30 00:29:36 -07:00
parent 217e2dccf7
commit 983d7d34fe
3 changed files with 27 additions and 2 deletions

View File

@@ -639,8 +639,9 @@ var Deferred;
throw new Error('Unknown constructor. Did you call customElements.define()?');
}
win.HTMLElement = newHTMLElement;
win.HTMLElement.prototype = Object.create(origHTMLElement.prototype);
Object.defineProperty(win.HTMLElement.prototype, 'constructor', {value: win.HTMLElement});
win.HTMLElement.prototype = Object.create(origHTMLElement.prototype, {
constructor: {value: win.HTMLElement, configurable: true, writable: true},
});
// patch all built-in subclasses of HTMLElement to inherit from the new HTMLElement
// See https://html.spec.whatwg.org/multipage/indices.html#element-interfaces

View File

@@ -24,6 +24,7 @@
'js/closure.js',
'js/upgrade.js',
'js/shadow-dom.js',
'js/patching.js',
'html/imports.html',
]);
</script>

View File

@@ -0,0 +1,23 @@
/**
* @license
* Copyright (c) 2016 The Polymer Project Authors. All rights reserved.
* This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt
* The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt
* The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt
* Code distributed by Google as part of the polymer project is also
* subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
*/
suite('patching', function() {
suite('HTMLElement', function () {
test('constructor is configurable and writable', function() {
var descriptor = Object.getOwnPropertyDescriptor(HTMLElement.prototype, 'constructor');
assert.isTrue(descriptor.configurable);
assert.isTrue(descriptor.writable);
});
});
});