Get rid of tab.run_js_blocking

We had some trouble with it, and it's not actually needed.
This commit is contained in:
Florian Bruhin 2016-08-18 14:02:59 +02:00
parent d3084dd690
commit a0add7b66c
4 changed files with 1 additions and 37 deletions

View File

@ -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

View File

@ -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()

View File

@ -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()

View File

@ -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