From a0add7b66c59a0ba3e28024bd284911152f71f25 Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Thu, 18 Aug 2016 14:02:59 +0200 Subject: [PATCH] Get rid of tab.run_js_blocking We had some trouble with it, and it's not actually needed. --- qutebrowser/browser/browsertab.py | 8 -------- qutebrowser/browser/webengine/webenginetab.py | 17 ----------------- qutebrowser/browser/webkit/webkittab.py | 5 +---- tests/unit/browser/test_tab.py | 8 -------- 4 files changed, 1 insertion(+), 37 deletions(-) diff --git a/qutebrowser/browser/browsertab.py b/qutebrowser/browser/browsertab.py index f43ff43f8..e33bd3049 100644 --- a/qutebrowser/browser/browsertab.py +++ b/qutebrowser/browser/browsertab.py @@ -698,14 +698,6 @@ class AbstractTab(QWidget): """ raise NotImplementedError - def run_js_blocking(self, code): - """Run javascript and block. - - This returns the result to the caller. Its use should be avoided when - possible as it runs a local event loop for QtWebEngine. - """ - raise NotImplementedError - def shutdown(self): raise NotImplementedError diff --git a/qutebrowser/browser/webengine/webenginetab.py b/qutebrowser/browser/webengine/webenginetab.py index 3b593d6a8..bb70e2291 100644 --- a/qutebrowser/browser/webengine/webenginetab.py +++ b/qutebrowser/browser/webengine/webenginetab.py @@ -448,23 +448,6 @@ class WebEngineTab(browsertab.AbstractTab): else: self._widget.page().runJavaScript(code, callback) - def run_js_blocking(self, code): - unset = object() - loop = qtutils.EventLoop() - js_ret = unset - - def js_cb(val): - """Handle return value from JS and stop blocking.""" - nonlocal js_ret - js_ret = val - loop.quit() - - self.run_js_async(code, js_cb) - loop.exec_() # blocks until loop.quit() in js_cb - assert js_ret is not unset - - return js_ret - def shutdown(self): log.stub() diff --git a/qutebrowser/browser/webkit/webkittab.py b/qutebrowser/browser/webkit/webkittab.py index 933a3b25e..b97cb88f1 100644 --- a/qutebrowser/browser/webkit/webkittab.py +++ b/qutebrowser/browser/webkit/webkittab.py @@ -606,13 +606,10 @@ class WebKitTab(browsertab.AbstractTab): callback(frame.toHtml()) def run_js_async(self, code, callback=None): - result = self.run_js_blocking(code) + result = self._widget.page().mainFrame().evaluateJavaScript(code) if callback is not None: callback(result) - def run_js_blocking(self, code): - return self._widget.page().mainFrame().evaluateJavaScript(code) - def icon(self): return self._widget.icon() diff --git a/tests/unit/browser/test_tab.py b/tests/unit/browser/test_tab.py index 72c3af599..fa76c8715 100644 --- a/tests/unit/browser/test_tab.py +++ b/tests/unit/browser/test_tab.py @@ -121,11 +121,3 @@ def test_tab(qtbot, view, config_stub, tab_registry, mode_manager): tab_w.show() qtbot.waitForWindowShown(tab_w) - - -class TestJs: - - @pytest.mark.parametrize('inp, expected', [('1+1', 2), - ('undefined', None)]) - def test_blocking(self, tab, inp, expected): - assert tab.run_js_blocking(inp) == expected