diff --git a/resources/rapydscript/compiler.js.xz b/resources/rapydscript/compiler.js.xz index 00f9ad252b..185d5e2e1d 100644 Binary files a/resources/rapydscript/compiler.js.xz and b/resources/rapydscript/compiler.js.xz differ diff --git a/resources/rapydscript/lib/aes.pyj b/resources/rapydscript/lib/aes.pyj index bb573635c7..666ed42e9b 100644 --- a/resources/rapydscript/lib/aes.pyj +++ b/resources/rapydscript/lib/aes.pyj @@ -14,9 +14,8 @@ def string_to_bytes_slow(string): return String.fromCharCode('0x' + p1) ) ua = Uint8Array(binstr.length) - Array.prototype.forEach.call(binstr, def(ch, i): + for i, ch in enumerate(binstr): ua[i] = ch.charCodeAt(0) - ) return ua def as_hex(array, sep=''): @@ -46,8 +45,8 @@ def bytes_to_string_slow(bytes, offset): i += 3 return ans.join('') -string_to_bytes = string_to_bytes_encoder if type(TextEncoder) is 'function' else string_to_bytes_slow -bytes_to_string = bytes_to_string_decoder if type(TextDecoder) is 'function' else bytes_to_string_slow +string_to_bytes = string_to_bytes_encoder if jstype(TextEncoder) is 'function' else string_to_bytes_slow +bytes_to_string = bytes_to_string_decoder if jstype(TextDecoder) is 'function' else bytes_to_string_slow def increment_counter(c): # c must be a Uint8Array of length 16 @@ -269,7 +268,7 @@ def random_bytes_secure(sz): crypto.getRandomValues(ans) return ans -random_bytes = random_bytes_secure if type(crypto) is not 'undefined' and type(crypto.getRandomValues) is 'function' else random_bytes_insecure +random_bytes = random_bytes_secure if jstype(crypto) is not 'undefined' and jstype(crypto.getRandomValues) is 'function' else random_bytes_insecure if random_bytes is random_bytes_insecure: try: noderandom = require('crypto').randomBytes @@ -293,7 +292,7 @@ class ModeOfOperation: # {{{ return tag if not tag: return Uint8Array(0) - if type(tag) is 'string': + if jstype(tag) is 'string': return string_to_bytes(tag) raise TypeError('Invalid tag, must be a string or a Uint8Array') # }}} diff --git a/resources/rapydscript/lib/elementmaker.pyj b/resources/rapydscript/lib/elementmaker.pyj index 65620f54f4..01f4828c8d 100644 --- a/resources/rapydscript/lib/elementmaker.pyj +++ b/resources/rapydscript/lib/elementmaker.pyj @@ -48,11 +48,11 @@ def _makeelement(tag, *args, **kwargs): ans.addEventListener(attr, val) elif val is True: ans.setAttribute(vattr, vattr) - elif type(val) is 'string': + elif jstype(val) is 'string': ans.setAttribute(vattr, val) for arg in args: - if type(arg) is 'string': + if jstype(arg) is 'string': arg = this.createTextNode(arg) ans.appendChild(arg) return ans @@ -64,7 +64,7 @@ def maker_for_document(document): Object.defineProperty(E, tag, {'value':_makeelement.bind(document, tag)}) return E -if type(document) is 'undefined': +if jstype(document) is 'undefined': E = maker_for_document({ 'createTextNode': def(value): return value;, 'createElement': def(name): diff --git a/resources/rapydscript/lib/encodings.pyj b/resources/rapydscript/lib/encodings.pyj index 3880a1338d..cd8da7041a 100644 --- a/resources/rapydscript/lib/encodings.pyj +++ b/resources/rapydscript/lib/encodings.pyj @@ -21,7 +21,7 @@ def base64encode(bytes): def base64decode(string): # convert the output of base64encode back into an array of bytes (Uint8Array) - if type(window) is not 'undefined': + if jstype(window) is not 'undefined': chars = window.atob(string) else: chars = new Buffer(string, 'base64').toString('binary') # noqa: undef @@ -106,7 +106,7 @@ def utf8_encode_js(string): ans.push(ch.charCodeAt(0)) return Uint8Array(ans) -if type(TextEncoder) is 'function': +if jstype(TextEncoder) is 'function': _u8enc = TextEncoder('utf-8') utf8_encode = _u8enc.encode.bind(_u8enc) _u8enc = undefined diff --git a/resources/rapydscript/lib/random.pyj b/resources/rapydscript/lib/random.pyj index d66c8523d4..3bad097155 100644 --- a/resources/rapydscript/lib/random.pyj +++ b/resources/rapydscript/lib/random.pyj @@ -30,10 +30,10 @@ ρσ_seed_state.key[ρσ_seed_state.key_j]) % 256] def seed(x=Date().getTime()): - if type(x) is 'number': + if jstype(x) is 'number': x = x.toString() - elif type(x) is not 'string': - raise TypeError("unhashable type: '" + type(x) + "'") + elif jstype(x) is not 'string': + raise TypeError("unhashable type: '" + jstype(x) + "'") for i in range(256): ρσ_seed_state.key[i] = i j = 0 diff --git a/resources/rapydscript/lib/re.pyj b/resources/rapydscript/lib/re.pyj index 193cc94284..181ce06101 100644 --- a/resources/rapydscript/lib/re.pyj +++ b/resources/rapydscript/lib/re.pyj @@ -74,7 +74,7 @@ def _expand(groups, repl, group_name_map): return String.fromCharCode(_ASCII_CONTROL_CHARS[q]) if '0' <= q <= '9': ans = read_digits(Number.MAX_VALUE, _NUM_PAT, 10, Number.MAX_VALUE, q) - if type(ans) is 'number': + if jstype(ans) is 'number': return groups[ans] or '' return '\\' + ans if q is 'g': @@ -89,17 +89,17 @@ def _expand(groups, repl, group_name_map): return groups[gn] or '' if q is 'x': code = read_digits(2, _HEX_PAT, 16, 0x10FFFF) - if type(code) is 'number': + if jstype(code) is 'number': return String.fromCharCode(code) return '\\x' + code if q is 'u': code = read_digits(4, _HEX_PAT, 16, 0x10FFFF) - if type(code) is 'number': + if jstype(code) is 'number': return String.fromCharCode(code) return '\\u' + code if q is 'U': code = read_digits(8, _HEX_PAT, 16, 0x10FFFF) - if type(code) is 'number': + if jstype(code) is 'number': if code <= 0xFFFF: return String.fromCharCode(code) code -= 0x10000 @@ -265,7 +265,7 @@ class MatchObject: return ans def _group_number(self, g): - if type(g) is 'number': + if jstype(g) is 'number': return g if has_prop(self.re.group_name_map, g): return self.re.group_name_map[g][-1] @@ -273,7 +273,7 @@ class MatchObject: def _group_val(self, q, defval): val = undefined - if type(q) is 'number' and -1 < q < self._groups.length: + if jstype(q) is 'number' and -1 < q < self._groups.length: val = self._groups[q] else: if has_prop(self.re.group_name_map, q): @@ -400,7 +400,7 @@ class RegexObject: def subn(self, repl, string, count=0): expand = _expand - if type(repl) is 'function': + if jstype(repl) is 'function': expand = def(m, repl, gnm): return '' + repl(MatchObject(self, m, 0, None)) this._pattern.lastIndex = 0 num = 0 diff --git a/src/pyj/book_list/prefs.pyj b/src/pyj/book_list/prefs.pyj index 33f0333afb..dc8c7f4cd5 100644 --- a/src/pyj/book_list/prefs.pyj +++ b/src/pyj/book_list/prefs.pyj @@ -223,7 +223,7 @@ class PrefsPanel: cls = Choices elif val is True or val is False: cls = CheckBox - elif type(val) is 'number': + elif jstype(val) is 'number': cls = SpinBox else: cls = LineEdit diff --git a/src/pyj/date.pyj b/src/pyj/date.pyj index 059647b434..2c267c215c 100644 --- a/src/pyj/date.pyj +++ b/src/pyj/date.pyj @@ -106,7 +106,7 @@ def test_fd(date, fmt, ans): def format_date(date=None, fmt='dd MMM yyyy', as_utc=False): fmt = fmt or 'dd MMM yyyy' ampm = 'ap' in fmt.toLowerCase() - if type(date) is 'string': + if jstype(date) is 'string': date = Date(date) date = date or Date() if is_date_undefined(date): diff --git a/src/pyj/dom.pyj b/src/pyj/dom.pyj index be926a2ca4..68dc471c01 100644 --- a/src/pyj/dom.pyj +++ b/src/pyj/dom.pyj @@ -25,7 +25,7 @@ simple_vendor_prefixes = { } def set_css(elem, **kw): - if type(elem) is 'string': + if jstype(elem) is 'string': elem = document.querySelector(elem) s = elem.style if s: diff --git a/src/pyj/popups.pyj b/src/pyj/popups.pyj index 1f78f13cf3..1fb62a0673 100644 --- a/src/pyj/popups.pyj +++ b/src/pyj/popups.pyj @@ -95,7 +95,7 @@ class CompletionPopup: self.applied_query = '' def add_associated_widget(self, widget_or_id): - if type(widget_or_id) is not 'string': + if jstype(widget_or_id) is not 'string': widget_or_id = ensure_id(widget_or_id) self.associated_widget_ids.add(widget_or_id) diff --git a/src/pyj/read_book/cfi.pyj b/src/pyj/read_book/cfi.pyj index ff2331e1e5..08a678f69c 100644 --- a/src/pyj/read_book/cfi.pyj +++ b/src/pyj/read_book/cfi.pyj @@ -134,7 +134,7 @@ def encode(doc, node, offset, tail): # {{{ # Handle the offset, if any if node.nodeType is Node.ELEMENT_NODE: - if type(offset) is 'number': + if jstype(offset) is 'number': node = node.childNodes.item(offset) elif Node.TEXT_NODE <= node.nodeType <= Node.ENTITY_NODE: offset = offset or 0 @@ -388,7 +388,7 @@ def point(cfi, doc): # {{{ y = None range_ = None - if type(r.offset) is "number": + if jstype(r.offset) is "number": # Character offset range_ = ndoc.createRange() if r.forward: @@ -435,7 +435,7 @@ def scroll_to(cfi, callback, doc): # {{{ if not point_: print("No point found for cfi: " + cfi) return - if type(point_.time) is 'number': + if jstype(point_.time) is 'number': set_current_time(point_.node, point_.time) if point_.range is not None: @@ -486,9 +486,9 @@ def scroll_to(cfi, callback, doc): # {{{ fn = def(): r = node.getBoundingClientRect() x, y = viewport_to_document(r.left, r.top, node.ownerDocument) - if type(point_.x) is 'number' and node.offsetWidth: + if jstype(point_.x) is 'number' and node.offsetWidth: x += (point_.x*node.offsetWidth)/100 - if type(point_.y) is 'number' and node.offsetHeight: + if jstype(point_.y) is 'number' and node.offsetHeight: y += (point_.y*node.offsetHeight)/100 window.scrollTo(x, y) if callback: @@ -526,9 +526,9 @@ def at_point(ox, oy): # {{{ node = p.node r = node.getBoundingClientRect() x, y = viewport_to_document(r.left, r.top, node.ownerDocument) - if type(p.x) is 'number' and node.offsetWidth: + if jstype(p.x) is 'number' and node.offsetWidth: x += (p.x*node.offsetWidth)/100 - if type(p.y) is 'number' and node.offsetHeight: + if jstype(p.y) is 'number' and node.offsetHeight: y += (p.y*node.offsetHeight)/100 if dist(viewport_to_document(ox, oy), v'[x, y]') > 50: diff --git a/src/pyj/read_book/mathjax.pyj b/src/pyj/read_book/mathjax.pyj index b5726bf504..9923e4d3f6 100644 --- a/src/pyj/read_book/mathjax.pyj +++ b/src/pyj/read_book/mathjax.pyj @@ -8,7 +8,7 @@ def get_url(mathjax_files, name): ans = mathjax_files[name] if not ans: return name - if type(ans) is not 'string': + if jstype(ans) is not 'string': ans = mathjax_files[name] = window.URL.createObjectURL(ans) return ans diff --git a/src/pyj/read_book/overlay.pyj b/src/pyj/read_book/overlay.pyj index da4419f395..c88cec3acd 100644 --- a/src/pyj/read_book/overlay.pyj +++ b/src/pyj/read_book/overlay.pyj @@ -282,7 +282,7 @@ class Overlay: return document.getElementById('book-overlay') def container_clicked(self, evt): - if self.panels.length and type(self.panels[-1].on_container_click) is 'function': + if self.panels.length and jstype(self.panels[-1].on_container_click) is 'function': self.panels[-1].on_container_click(evt) else: self.hide_current_panel() diff --git a/src/pyj/read_book/paged_mode.pyj b/src/pyj/read_book/paged_mode.pyj index 34fb7f154b..e69b43e629 100644 --- a/src/pyj/read_book/paged_mode.pyj +++ b/src/pyj/read_book/paged_mode.pyj @@ -224,7 +224,7 @@ def scroll_to_column(number, animated=False, notify=False, duration=1000): def scroll_to_xpos(xpos, animated=False, notify=False, duration=1000): # Scroll so that the column containing xpos is the left most column in # the viewport - if type(xpos) is not 'number': + if jstype(xpos) is not 'number': print(xpos, 'is not a number, cannot scroll to it!') return if is_full_screen_layout: diff --git a/src/pyj/read_book/resources.pyj b/src/pyj/read_book/resources.pyj index 8743ed9af3..64e4d350f3 100644 --- a/src/pyj/read_book/resources.pyj +++ b/src/pyj/read_book/resources.pyj @@ -34,7 +34,7 @@ def load_resources(db, book, root_name, previous_resources, proceed): return setTimeout(do_one, 0) if previous_resources[name]: ans[name] = data = previous_resources[name] - if type(data[0]) is 'string': + if jstype(data[0]) is 'string': find_virtualized_resources(data[0]) return setTimeout(do_one, 0) db.get_file(book, name, got_one) @@ -44,7 +44,7 @@ def load_resources(db, book, root_name, previous_resources, proceed): # Enable to have cover image not preserve aspect ratio data = data.replace('width: auto', 'width: 100%') ans[name] = v'[data, mimetype]' - if type(data) is 'string': + if jstype(data) is 'string': find_virtualized_resources(data) return setTimeout(do_one, 0) @@ -88,7 +88,7 @@ def finalize_resources(book, root_name, resource_data): # Resolve the non virtualized resources immediately for name in resource_data: data, mimetype = resource_data[name] - if type(data) is not 'string': + if jstype(data) is not 'string': blob_url_map[name] = window.URL.createObjectURL(data) for name in blob_url_map: v'delete resource_data[name]' diff --git a/src/pyj/read_book/ui.pyj b/src/pyj/read_book/ui.pyj index 05b9b18dd2..a2d66d672b 100644 --- a/src/pyj/read_book/ui.pyj +++ b/src/pyj/read_book/ui.pyj @@ -136,7 +136,7 @@ class ReadUI: self.current_metadata = metadata or {'title':_('Book id #') + book_id} get_boss().update_window_title() self.init_ui() - if type(self.db) is 'string': + if jstype(self.db) is 'string': self.show_error(_('Cannot read book'), self.db) return self.db.get_book(book_id, fmt, metadata, self.got_book.bind(self, force_reload)) diff --git a/src/pyj/read_book/view.pyj b/src/pyj/read_book/view.pyj index 083d194535..eae7d74766 100644 --- a/src/pyj/read_book/view.pyj +++ b/src/pyj/read_book/view.pyj @@ -242,7 +242,7 @@ class View: snum = int(snum) except Exception: print('Invalid spine number in CFI:', snum) - if type(snum) == 'number': + if jstype(snum) == 'number': name = book.manifest.spine[(int(snum) // 2) - 1] or name pos.type, pos.cfi = 'cfi', '/' + rest self.show_name(name, initial_position=pos) diff --git a/src/pyj/session.pyj b/src/pyj/session.pyj index bd0704ce4a..a0c9a300e5 100644 --- a/src/pyj/session.pyj +++ b/src/pyj/session.pyj @@ -66,7 +66,7 @@ class FakeStorage: return self.data[key] def setItem(self, key, value): - if type(value) is not 'string': + if jstype(value) is not 'string': value = JSON.stringify(value) self.data[key] = value