From af3dbce840d0d0956663ffb20012329a4c22d5dd Mon Sep 17 00:00:00 2001 From: bptato Date: Tue, 1 Aug 2023 19:05:45 +0200 Subject: Fixes & workarounds to compile on Nim 2.0.0 * Import punycode, as it has been removed from stdlib. * Fix some syntax errors * Apparently you can no longer compare distinct pointers with nil. Add explicit comparisons with typeof(nil) instead. * htmlparser: rename _ to other, as semantics of _ have changed. (Quite a shame, it looked better with _. Oh well.) * Explicitly specify mm:refc, as the browser OOMs with orc for some reason. Confirmed to compile & run on 2.0.0, 1.6.14, 1.6.12, 1.6.10 and 1.6.8. (<1.6.8 it's broken & wontfix.) --- src/bindings/curl.nim | 2 ++ src/bindings/quickjs.nim | 3 ++- src/config/toml.nim | 2 +- src/css/cssparser.nim | 5 +++-- src/css/match.nim | 2 +- src/html/dom.nim | 12 ++++++------ src/html/htmlparser.nim | 42 +++++++++++++++++++++--------------------- src/io/promise.nim | 3 +++ src/io/response.nim | 2 +- src/js/javascript.nim | 2 +- src/utils/twtstr.nim | 6 ++++-- 11 files changed, 45 insertions(+), 36 deletions(-) (limited to 'src') diff --git a/src/bindings/curl.nim b/src/bindings/curl.nim index 07395b65..ed2057eb 100644 --- a/src/bindings/curl.nim +++ b/src/bindings/curl.nim @@ -286,7 +286,9 @@ type CURLMSG_LAST # last, not used proc `==`*(a: CURL, b: CURL): bool {.borrow.} +proc `==`*(a: CURL, b: typeof(nil)): bool {.borrow.} proc `==`*(a: CURLM, b: CURLM): bool {.borrow.} +proc `==`*(a: CURLM, b: typeof(nil)): bool {.borrow.} {.push importc.} diff --git a/src/bindings/quickjs.nim b/src/bindings/quickjs.nim index 7ff8fd0f..d415c17e 100644 --- a/src/bindings/quickjs.nim +++ b/src/bindings/quickjs.nim @@ -281,7 +281,8 @@ template JS_CGETSET_DEF*(n: string, fgetter, fsetter: untyped): JSCFunctionListE get: JSCFunctionType(getter: fgetter), set: JSCFunctionType(setter: fsetter)))) -template JS_CGETSET_MAGIC_DEF*(n: string, fgetter, fsetter: untyped, m: cint): JSCFunctionListEntry = +template JS_CGETSET_MAGIC_DEF*(n: string, fgetter, fsetter: untyped, + m: int16): JSCFunctionListEntry = JSCFunctionListEntry(name: cstring(n), prop_flags: JS_PROP_CONFIGURABLE, def_type: JS_DEF_CGETSET_MAGIC, diff --git a/src/config/toml.nim b/src/config/toml.nim index fc066048..66f8335f 100644 --- a/src/config/toml.nim +++ b/src/config/toml.nim @@ -124,7 +124,7 @@ proc consumeEscape(state: var TomlParser, c: char): Result[Rune, TomlError] = if i != len - 1: return state.err("invalid escaped length (" & $i & ", needs " & $len & ")") - if num > 0x10FFFF or num in {0xD800..0xDFFF}: + if num > 0x10FFFF or num in 0xD800..0xDFFF: return state.err("invalid escaped codepoint: " & $num) else: return ok(cast[Rune](num)) diff --git a/src/css/cssparser.nim b/src/css/cssparser.nim index fb8b0cfa..c5448599 100644 --- a/src/css/cssparser.nim +++ b/src/css/cssparser.nim @@ -195,7 +195,8 @@ proc next3startsWithIdentSequence(state: var CSSTokenizerState): bool = case state.peek() of '-': - return state.has(1) and state.peek(1) in IdentStart + {'-'} or state.has(2) and isValidEscape(state.peek(1), state.peek(2)): + return state.has(1) and state.peek(1) in IdentStart + {'-'} or + state.has(2) and isValidEscape(state.peek(1), state.peek(2)) of IdentStart: return true of '\\': @@ -239,7 +240,7 @@ proc consumeEscape(state: var CSSTokenizerState): string = inc i if state.peek().isWhitespace(): discard state.consume() - if num == 0 or num > 0x10FFFF or num in {0xD800..0xDFFF}: + if num == 0 or num > 0x10FFFF or num in 0xD800..0xDFFF: return $Rune(0xFFFD) else: return $Rune(num) diff --git a/src/css/match.nim b/src/css/match.nim index 6f684e8b..810cdbe4 100644 --- a/src/css/match.nim +++ b/src/css/match.nim @@ -142,7 +142,7 @@ func complexSelectorMatches[T: Element|StyledNode](elem: T, cxsel: ComplexSelect var match = false case sels.ct of NO_COMBINATOR: - match = e.selectorsMatch(sels, felem): + match = e.selectorsMatch(sels, felem) of DESCENDANT_COMBINATOR: e = e.parentElement while e != nil: diff --git a/src/html/dom.nim b/src/html/dom.nim index 4318c517..11254c56 100644 --- a/src/html/dom.nim +++ b/src/html/dom.nim @@ -2872,9 +2872,9 @@ proc querySelector*(node: Node, q: string): Element {.jsfunc.} = const (ReflectTable, TagReflectMap, ReflectAllStartIndex) = (func(): ( seq[ReflectEntry], - Table[TagType, seq[uint16]], - uint16) = - var i: uint16 = 0 + Table[TagType, seq[int16]], + int16) = + var i: int16 = 0 while i < ReflectTable0.len: let x = ReflectTable0[i] result[0].add(x) @@ -2882,7 +2882,7 @@ const (ReflectTable, TagReflectMap, ReflectAllStartIndex) = (func(): ( break for tag in result[0][i].tags: if tag notin result[1]: - result[1][tag] = newSeq[uint16]() + result[1][tag] = newSeq[int16]() result[1][tag].add(i) assert result[0][i].tags.len != 0 inc i @@ -2967,8 +2967,8 @@ func getReflectFunctions(tags: set[TagType]): seq[TabGetSet] = return result func getElementReflectFunctions(): seq[TabGetSet] = - var i: uint16 = ReflectAllStartIndex - while i < uint16(ReflectTable.len): + var i: int16 = ReflectAllStartIndex + while i < int16(ReflectTable.len): let entry = ReflectTable[i] assert entry.tags == AllTagTypes result.add(TabGetSet(name: ReflectTable[i].funcname, get: jsReflectGet, set: jsReflectSet, magic: i)) diff --git a/src/html/htmlparser.nim b/src/html/htmlparser.nim index 05e830fb..2192ccf8 100644 --- a/src/html/htmlparser.nim +++ b/src/html/htmlparser.nim @@ -1152,7 +1152,7 @@ proc closeP(parser: var HTML5Parser) = # ("

", "", "") => (block: echo "p, a or closing div") # ("

", "

") => (block: anything_else) # (TokenType.START_TAG, TokenType.END_TAG) => (block: assert false, "invalid") -# _ => (block: echo "anything else") +# other => (block: echo "anything else") # # (effectively) generates this: # @@ -1322,7 +1322,7 @@ proc processInHTMLContent[Handle](parser: var HTML5Parser[Handle], quote do: discard (`v`, proc() = `body`) - template _ = discard + template other = discard template reprocess(tok: Token) = parser.processInHTMLContent(tok, parser.insertionMode) @@ -1362,7 +1362,7 @@ proc processInHTMLContent[Handle](parser: var HTML5Parser[Handle], parser.setQuirksMode(LIMITED_QUIRKS) parser.insertionMode = BEFORE_HTML ) - _ => (block: + other => (block: if not parser.opts.isIframeSrcdoc: parse_error UNEXPECTED_INITIAL_TOKEN parser.setQuirksMode(QUIRKS) @@ -1386,7 +1386,7 @@ proc processInHTMLContent[Handle](parser: var HTML5Parser[Handle], ) ("", "", "", "
") => (block: anything_else) TokenType.END_TAG => (block: parse_error UNEXPECTED_END_TAG) - _ => (block: + other => (block: let element = parser.createElement(TAG_HTML, Namespace.HTML) parser.append(parser.document, element) parser.pushElement(element) @@ -1406,7 +1406,7 @@ proc processInHTMLContent[Handle](parser: var HTML5Parser[Handle], ) ("", "", "", "
") => (block: anything_else) TokenType.END_TAG => (block: parse_error UNEXPECTED_END_TAG) - _ => (block: + other => (block: let head = Token(t: START_TAG, tagtype: TAG_HEAD) parser.head = some(parser.insertHTMLElement(head)) parser.insertionMode = IN_HEAD @@ -1481,7 +1481,7 @@ proc processInHTMLContent[Handle](parser: var HTML5Parser[Handle], parser.resetInsertionMode() ) ("", TokenType.END_TAG) => (block: parse_error UNEXPECTED_END_TAG) - _ => (block: + other => (block: pop_current_node parser.insertionMode = AFTER_HEAD reprocess token @@ -1503,7 +1503,7 @@ proc processInHTMLContent[Handle](parser: var HTML5Parser[Handle], "
" => (block: anything_else) ("", "