From 0681bc0dd2569910fa292f8135b937494a253a07 Mon Sep 17 00:00:00 2001 From: Peter Burns Date: Thu, 19 Dec 2019 22:52:37 -0800 Subject: [PATCH] Remove Utilities.setPropertyUnchecked in preparation for conversion to TypeScript. --- .../custom-elements/src/Patch/Document.js | 18 +++----- packages/custom-elements/src/Patch/Element.js | 45 +++++++------------ .../src/Patch/Interface/ChildNode.js | 18 +++----- .../src/Patch/Interface/ParentNode.js | 6 +-- packages/custom-elements/src/Patch/Node.js | 30 +++++-------- packages/custom-elements/src/Utilities.js | 13 ------ 6 files changed, 41 insertions(+), 89 deletions(-) diff --git a/packages/custom-elements/src/Patch/Document.js b/packages/custom-elements/src/Patch/Document.js index a35d92539..7286c7312 100644 --- a/packages/custom-elements/src/Patch/Document.js +++ b/packages/custom-elements/src/Patch/Document.js @@ -20,9 +20,7 @@ import Native from './Native.js'; * @param {!CustomElementInternals} internals */ export default function(internals) { - Utilities.setPropertyUnchecked( - Document.prototype, - 'createElement', + Document.prototype.createElement = /** * @this {Document} * @param {string} localName @@ -30,11 +28,9 @@ export default function(internals) { */ function(localName) { return internals.createAnElement(this, localName, null); - }); + }; - Utilities.setPropertyUnchecked( - Document.prototype, - 'importNode', + Document.prototype.importNode = /** * @this {Document} * @param {!Node} node @@ -52,11 +48,9 @@ export default function(internals) { internals.patchAndUpgradeTree(clone); } return clone; - }); + }; - Utilities.setPropertyUnchecked( - Document.prototype, - 'createElementNS', + Document.prototype.createElementNS = /** * @this {Document} * @param {?string} namespace @@ -65,7 +59,7 @@ export default function(internals) { */ function(namespace, localName) { return internals.createAnElement(this, localName, namespace); - }); + }; PatchParentNode(internals, Document.prototype, { prepend: Native.Document_prepend, diff --git a/packages/custom-elements/src/Patch/Element.js b/packages/custom-elements/src/Patch/Element.js index 26e30d5d3..f9be8564c 100644 --- a/packages/custom-elements/src/Patch/Element.js +++ b/packages/custom-elements/src/Patch/Element.js @@ -22,9 +22,7 @@ import Native from './Native.js'; */ export default function(internals) { if (Native.Element_attachShadow) { - Utilities.setPropertyUnchecked( - Element.prototype, - 'attachShadow', + Element.prototype.attachShadow = /** * @this {Element} * @param {!{mode: string}} init @@ -35,7 +33,7 @@ export default function(internals) { internals.patchNode(shadowRoot); this.__CE_shadowRoot = shadowRoot; return shadowRoot; - }); + }; } @@ -136,9 +134,8 @@ export default function(internals) { } - Utilities.setPropertyUnchecked( - Element.prototype, - 'setAttribute', + + Element.prototype.setAttribute = /** * @this {Element} * @param {string} name @@ -155,11 +152,10 @@ export default function(internals) { newValue = Native.Element_getAttribute.call(this, name); internals.attributeChangedCallback( this, name, oldValue, newValue, null); - }); + }; - Utilities.setPropertyUnchecked( - Element.prototype, - 'setAttributeNS', + + Element.prototype.setAttributeNS = /** * @this {Element} * @param {?string} namespace @@ -179,11 +175,10 @@ export default function(internals) { newValue = Native.Element_getAttributeNS.call(this, namespace, name); internals.attributeChangedCallback( this, name, oldValue, newValue, namespace); - }); + }; - Utilities.setPropertyUnchecked( - Element.prototype, - 'removeAttribute', + + Element.prototype.removeAttribute = /** * @this {Element} * @param {string} name @@ -199,11 +194,9 @@ export default function(internals) { if (oldValue !== null) { internals.attributeChangedCallback(this, name, oldValue, null, null); } - }); + }; - Utilities.setPropertyUnchecked( - Element.prototype, - 'removeAttributeNS', + Element.prototype.removeAttributeNS = /** * @this {Element} * @param {?string} namespace @@ -228,13 +221,11 @@ export default function(internals) { internals.attributeChangedCallback( this, name, oldValue, newValue, namespace); } - }); + }; function patch_insertAdjacentElement(destination, baseMethod) { - Utilities.setPropertyUnchecked( - destination, - 'insertAdjacentElement', + destination.insertAdjacentElement = /** * @this {Element} * @param {string} position @@ -254,7 +245,7 @@ export default function(internals) { internals.connectTree(element); } return insertedElement; - }); + }; } if (Native.HTMLElement_insertAdjacentElement) { @@ -284,9 +275,7 @@ export default function(internals) { } } - Utilities.setPropertyUnchecked( - destination, - 'insertAdjacentHTML', + destination.insertAdjacentHTML = /** * @this {Element} * @param {string} position @@ -320,7 +309,7 @@ export default function(internals) { `The value provided (${String(position)}) is ` + 'not one of \'beforebegin\', \'afterbegin\', \'beforeend\', or \'afterend\'.'); } - }); + }; } if (Native.HTMLElement_insertAdjacentHTML) { diff --git a/packages/custom-elements/src/Patch/Interface/ChildNode.js b/packages/custom-elements/src/Patch/Interface/ChildNode.js index 8c699eb6a..2d41385d7 100644 --- a/packages/custom-elements/src/Patch/Interface/ChildNode.js +++ b/packages/custom-elements/src/Patch/Interface/ChildNode.js @@ -80,19 +80,15 @@ export default function(internals, destination, builtIn) { } if (builtIn.before !== undefined) { - Utilities.setPropertyUnchecked( - destination, 'before', beforeAfterPatch(builtIn.before)); + destination.before = beforeAfterPatch(builtIn.before); } if (builtIn.after !== undefined) { - Utilities.setPropertyUnchecked( - destination, 'after', beforeAfterPatch(builtIn.after)); + destination.after = beforeAfterPatch(builtIn.after); } if (builtIn.replaceWith !== undefined) { - Utilities.setPropertyUnchecked( - destination, - 'replaceWith', + destination.replaceWith = /** * @param {...(!Node|string)} nodes * @this {!Node} @@ -145,13 +141,11 @@ export default function(internals, destination, builtIn) { } } } - }); + }; } if (builtIn.remove !== undefined) { - Utilities.setPropertyUnchecked( - destination, - 'remove', + destination.remove = /** @this {!Node} */ function() { const wasConnected = Utilities.isConnected(this); @@ -161,6 +155,6 @@ export default function(internals, destination, builtIn) { if (wasConnected) { internals.disconnectTree(this); } - }); + }; } }; diff --git a/packages/custom-elements/src/Patch/Interface/ParentNode.js b/packages/custom-elements/src/Patch/Interface/ParentNode.js index 721b8e00d..66d8b5282 100644 --- a/packages/custom-elements/src/Patch/Interface/ParentNode.js +++ b/packages/custom-elements/src/Patch/Interface/ParentNode.js @@ -78,12 +78,10 @@ export default function(internals, destination, builtIn) { } if (builtIn.prepend !== undefined) { - Utilities.setPropertyUnchecked( - destination, 'prepend', appendPrependPatch(builtIn.prepend)); + destination.prepend = appendPrependPatch(builtIn.prepend); } if (builtIn.append !== undefined) { - Utilities.setPropertyUnchecked( - destination, 'append', appendPrependPatch(builtIn.append)); + destination.append = appendPrependPatch(builtIn.append); } }; diff --git a/packages/custom-elements/src/Patch/Node.js b/packages/custom-elements/src/Patch/Node.js index da873b0bc..9497a04ce 100644 --- a/packages/custom-elements/src/Patch/Node.js +++ b/packages/custom-elements/src/Patch/Node.js @@ -21,9 +21,7 @@ export default function(internals) { // `Node#nodeValue` is implemented on `Attr`. // `Node#textContent` is implemented on `Attr`, `Element`. - Utilities.setPropertyUnchecked( - Node.prototype, - 'insertBefore', + Node.prototype.insertBefore = /** * @this {Node} * @param {!Node} node @@ -62,11 +60,9 @@ export default function(internals) { } return nativeResult; - }); + }; - Utilities.setPropertyUnchecked( - Node.prototype, - 'appendChild', + Node.prototype.appendChild = /** * @this {Node} * @param {!Node} node @@ -103,11 +99,9 @@ export default function(internals) { } return nativeResult; - }); + }; - Utilities.setPropertyUnchecked( - Node.prototype, - 'cloneNode', + Node.prototype.cloneNode = /** * @this {Node} * @param {boolean=} deep @@ -123,11 +117,9 @@ export default function(internals) { internals.patchAndUpgradeTree(clone); } return clone; - }); + }; - Utilities.setPropertyUnchecked( - Node.prototype, - 'removeChild', + Node.prototype.removeChild = /** * @this {Node} * @param {!Node} node @@ -143,11 +135,9 @@ export default function(internals) { } return nativeResult; - }); + }; - Utilities.setPropertyUnchecked( - Node.prototype, - 'replaceChild', + Node.prototype.replaceChild = /** * @this {Node} * @param {!Node} nodeToInsert @@ -194,7 +184,7 @@ export default function(internals) { } return nativeResult; - }); + }; function patch_textContent(destination, baseDescriptor) { diff --git a/packages/custom-elements/src/Utilities.js b/packages/custom-elements/src/Utilities.js index 09691d7b8..e89362eee 100644 --- a/packages/custom-elements/src/Utilities.js +++ b/packages/custom-elements/src/Utilities.js @@ -165,16 +165,3 @@ export function walkDeepDescendantElements(root, callback, visitedImports) { node = nextNode(root, node); } } - -/** - * Used to suppress Closure's "Modifying the prototype is only allowed if the - * constructor is in the same scope" warning without using - * `@suppress {newCheckTypes, duplicate}` because `newCheckTypes` is too broad. - * - * @param {!Object} destination - * @param {string} name - * @param {*} value - */ -export function setPropertyUnchecked(destination, name, value) { - destination[name] = value; -}