Skip to content

Commit

Permalink
Remove Utilities.setPropertyUnchecked in preparation for conversion t…
Browse files Browse the repository at this point in the history
…o TypeScript.
  • Loading branch information
rictic committed Feb 7, 2020
1 parent 709cf2c commit 0681bc0
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 89 deletions.
18 changes: 6 additions & 12 deletions packages/custom-elements/src/Patch/Document.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,21 +20,17 @@ 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
* @return {!Element}
*/
function(localName) {
return internals.createAnElement(this, localName, null);
});
};

Utilities.setPropertyUnchecked(
Document.prototype,
'importNode',
Document.prototype.importNode =
/**
* @this {Document}
* @param {!Node} node
Expand All @@ -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
Expand All @@ -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,
Expand Down
45 changes: 17 additions & 28 deletions packages/custom-elements/src/Patch/Element.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -35,7 +33,7 @@ export default function(internals) {
internals.patchNode(shadowRoot);
this.__CE_shadowRoot = shadowRoot;
return shadowRoot;
});
};
}


Expand Down Expand Up @@ -136,9 +134,8 @@ export default function(internals) {
}


Utilities.setPropertyUnchecked(
Element.prototype,
'setAttribute',

Element.prototype.setAttribute =
/**
* @this {Element}
* @param {string} name
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -254,7 +245,7 @@ export default function(internals) {
internals.connectTree(element);
}
return insertedElement;
});
};
}

if (Native.HTMLElement_insertAdjacentElement) {
Expand Down Expand Up @@ -284,9 +275,7 @@ export default function(internals) {
}
}

Utilities.setPropertyUnchecked(
destination,
'insertAdjacentHTML',
destination.insertAdjacentHTML =
/**
* @this {Element}
* @param {string} position
Expand Down Expand Up @@ -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) {
Expand Down
18 changes: 6 additions & 12 deletions packages/custom-elements/src/Patch/Interface/ChildNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down Expand Up @@ -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);
Expand All @@ -161,6 +155,6 @@ export default function(internals, destination, builtIn) {
if (wasConnected) {
internals.disconnectTree(this);
}
});
};
}
};
6 changes: 2 additions & 4 deletions packages/custom-elements/src/Patch/Interface/ParentNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
};
30 changes: 10 additions & 20 deletions packages/custom-elements/src/Patch/Node.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -62,11 +60,9 @@ export default function(internals) {
}

return nativeResult;
});
};

Utilities.setPropertyUnchecked(
Node.prototype,
'appendChild',
Node.prototype.appendChild =
/**
* @this {Node}
* @param {!Node} node
Expand Down Expand Up @@ -103,11 +99,9 @@ export default function(internals) {
}

return nativeResult;
});
};

Utilities.setPropertyUnchecked(
Node.prototype,
'cloneNode',
Node.prototype.cloneNode =
/**
* @this {Node}
* @param {boolean=} deep
Expand All @@ -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
Expand All @@ -143,11 +135,9 @@ export default function(internals) {
}

return nativeResult;
});
};

Utilities.setPropertyUnchecked(
Node.prototype,
'replaceChild',
Node.prototype.replaceChild =
/**
* @this {Node}
* @param {!Node} nodeToInsert
Expand Down Expand Up @@ -194,7 +184,7 @@ export default function(internals) {
}

return nativeResult;
});
};


function patch_textContent(destination, baseDescriptor) {
Expand Down
13 changes: 0 additions & 13 deletions packages/custom-elements/src/Utilities.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

0 comments on commit 0681bc0

Please sign in to comment.