refactor: use WeakMap instead of hidden V8 properties to store WebViewImpl (#29049)

This commit is contained in:
Milan Burda 2021-05-08 02:56:22 +02:00 committed by GitHub
parent de55bf8459
commit 49ef1fe342
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 23 additions and 21 deletions

View file

@ -64,6 +64,7 @@ export class WebViewImpl {
iframeElement.style.flex = '1 1 auto';
iframeElement.style.width = '100%';
iframeElement.style.border = '0';
// used by RendererClientBase::IsWebViewFrame
v8Util.setHiddenValue(iframeElement, 'internal', this);
return iframeElement;
}
@ -210,14 +211,6 @@ export class WebViewImpl {
// I wish eslint wasn't so stupid, but it is
// eslint-disable-next-line
export const setupMethods = (WebViewElement: typeof ElectronInternal.WebViewElement) => {
WebViewElement.prototype.getWebContentsId = function () {
const internal = v8Util.getHiddenValue<WebViewImpl>(this, 'internal');
if (!internal.guestInstanceId) {
throw new Error('The WebView must be attached to the DOM and the dom-ready event emitted before this method can be called.');
}
return internal.guestInstanceId;
};
// Focusing the webview should move page focus to the underlying iframe.
WebViewElement.prototype.focus = function () {
this.contentWindow.focus();