Permalink
Browse files

Add _qutebrowser_ prefix for custom JS functions

With QtWebKit or QtWebEngine with Qt < 5.7, the functions end up in the
page's namespace. We can't easily avoid this, but at least we can name
them in a way which reduces conflicts.
  • Loading branch information...
The-Compiler committed Aug 5, 2016
1 parent ab0d9ca commit 0169f3a24f32e35a7701ef9f83807dc9c1946aa0
Showing with 5 additions and 5 deletions.
  1. +3 −3 qutebrowser/javascript/scroll.js
  2. +1 −1 qutebrowser/utils/javascript.py
  3. +1 −1 tests/unit/utils/test_javascript.py
@@ -17,7 +17,7 @@
* along with qutebrowser. If not, see <http://www.gnu.org/licenses/>.
*/
-function scroll_to_perc(x, y) {
+function _qutebrowser_scroll_to_perc(x, y) {
var elem = document.documentElement;
var x_px = window.scrollX;
var y_px = window.scrollY;
@@ -33,13 +33,13 @@ function scroll_to_perc(x, y) {
window.scroll(x_px, y_px);
}
-function scroll_delta_page(x, y) {
+function _qutebrowser_scroll_delta_page(x, y) {
var dx = document.documentElement.clientWidth * x;
var dy = document.documentElement.clientHeight * y;
window.scrollBy(dx, dy);
}
-function scroll_pos() {
+function _qutebrowser_scroll_pos() {
var elem = document.documentElement;
var dx = (elem.scrollWidth - elem.clientWidth);
var dy = (elem.scrollHeight - elem.clientHeight);
@@ -64,7 +64,7 @@ def _convert_js_arg(arg):
def assemble(name, function, *args):
"""Assemble a javascript file and a function call."""
- code = "{code}\n{function}({args});".format(
+ code = "{code}\n_qutebrowser_{function}({args});".format(
code=utils.read_file('javascript/{}.js'.format(name)),
function=function,
args=', '.join(_convert_js_arg(arg) for arg in args),
@@ -140,5 +140,5 @@ def test_convert_js_arg(arg, expected):
def test_assemble(monkeypatch):
monkeypatch.setattr(javascript.utils, 'read_file',
'<code from {}>'.format)
- expected = '<code from javascript/foo.js>\nfunc(23);'
+ expected = '<code from javascript/foo.js>\n_qutebrowser_func(23);'
assert javascript.assemble('foo', 'func', 23) == expected

0 comments on commit 0169f3a

Please sign in to comment.