diff options
author | mrkutly <mark.sauer.utley@gmail.com> | 2022-06-04 19:31:27 -0400 |
---|---|---|
committer | Louis Pilfold <louis@lpil.uk> | 2022-06-11 18:39:10 +0100 |
commit | 454ef1bac35407ca38eb1f3b2348091eb05fb385 (patch) | |
tree | 31a35b936de6788797cac214105bc804a37a7ddf | |
parent | d984c047c771ec6c89ce23b2f29128a2a931b9db (diff) | |
download | gleam_json-454ef1bac35407ca38eb1f3b2348091eb05fb385.tar.gz gleam_json-454ef1bac35407ca38eb1f3b2348091eb05fb385.zip |
improve comments
-rw-r--r-- | src/gleam_json_ffi.mjs | 20 |
1 files changed, 17 insertions, 3 deletions
diff --git a/src/gleam_json_ffi.mjs b/src/gleam_json_ffi.mjs index 0116ab3..ef952e5 100644 --- a/src/gleam_json_ffi.mjs +++ b/src/gleam_json_ffi.mjs @@ -66,9 +66,6 @@ function getJsonDecodeError(stdErr, json) { * * JSON.parse('{"a"') * // => Unexpected end of JSON input - * - * // in Chromium (correct) - * */ const unexpectedEndOfInputRegex = /((unexpected (end|eof))|(end of data)|(unterminated string)|(json( parse error|\.parse)\: expected '(\:|\}|\])'))/i @@ -108,6 +105,23 @@ function getUnexpectedByteRuntime(err) { return null } +/** + * Converts a SyntaxError to an UnexpectedByte error based on the JS runtime. + * + * For Chromium, the unexpected byte and position are reported by the runtime. + * + * For JavascriptCore, only the unexpected byte is reported by the runtime, so + * there is no way to know which position that character is in unless we then + * parse the string again ourselves. So instead, the position is reported as 0. + * + * For Spidermonkey, the position is reported by the runtime as a line and column number + * and the unexpected byte is found using those coordinates. + * + * @param {'chromium' | 'spidermonkey' | 'jscore'} runtime + * @param {SyntaxError} err + * @param {string} json + * @returns {UnexpectedByte} + */ function toUnexpectedByteError(runtime, err, json) { switch (runtime) { case Runtime.chromium: |