зеркало из https://github.com/electron/electron.git
fix: BrowserWindow.fromWebContents should work in browser-window-created (#33257)
This commit is contained in:
Родитель
b2c5623a13
Коммит
e904486076
|
@ -117,11 +117,11 @@ class TrackableObject : public TrackableObjectBase, public EventEmitter<T> {
|
|||
~TrackableObject() override { RemoveFromWeakMap(); }
|
||||
|
||||
void InitWith(v8::Isolate* isolate, v8::Local<v8::Object> wrapper) override {
|
||||
gin_helper::WrappableBase::InitWith(isolate, wrapper);
|
||||
if (!weak_map_) {
|
||||
weak_map_ = new electron::KeyWeakMap<int32_t>;
|
||||
}
|
||||
weak_map_->Set(isolate, weak_map_id_, wrapper);
|
||||
gin_helper::WrappableBase::InitWith(isolate, wrapper);
|
||||
}
|
||||
|
||||
private:
|
||||
|
|
|
@ -1816,6 +1816,18 @@ describe('BrowserWindow module', () => {
|
|||
expect(BrowserWindow.fromWebContents(webviewContents)!.id).to.equal(w.id);
|
||||
await p;
|
||||
});
|
||||
|
||||
it('is usable immediately on browser-window-created', async () => {
|
||||
const w = new BrowserWindow({ show: false });
|
||||
w.loadURL('about:blank');
|
||||
w.webContents.executeJavaScript('window.open(""); null');
|
||||
const [win, winFromWebContents] = await new Promise((resolve) => {
|
||||
app.once('browser-window-created', (e, win) => {
|
||||
resolve([win, BrowserWindow.fromWebContents(win.webContents)]);
|
||||
});
|
||||
});
|
||||
expect(winFromWebContents).to.equal(win);
|
||||
});
|
||||
});
|
||||
|
||||
describe('BrowserWindow.openDevTools()', () => {
|
||||
|
|
Загрузка…
Ссылка в новой задаче