diff options
author | Luca Casonato <hello@lcas.dev> | 2022-05-13 14:28:05 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-05-13 14:28:05 +0200 |
commit | a5b50d0915a666c54e8668d6f8bc1b8f5d7e121a (patch) | |
tree | a15b4feae4300d53a37ba0c3bcb27d2c3038dd0a /ext/web/00_infra.js | |
parent | 42fec5150ecbd80f110d2bb32f1dcd2b2a344dd3 (diff) |
feat(ext/web): implement static `Response.json` (#14566)
This commit adds support for the static `Response.json` method.
Diffstat (limited to 'ext/web/00_infra.js')
-rw-r--r-- | ext/web/00_infra.js | 34 |
1 files changed, 24 insertions, 10 deletions
diff --git a/ext/web/00_infra.js b/ext/web/00_infra.js index f46316bfe..bf931f8c7 100644 --- a/ext/web/00_infra.js +++ b/ext/web/00_infra.js @@ -11,23 +11,24 @@ ((window) => { const core = Deno.core; const { - Error, - RegExp, + ArrayPrototypeJoin, ArrayPrototypeMap, - StringPrototypeCharCodeAt, + Error, + JSONStringify, NumberPrototypeToString, - StringPrototypePadStart, - TypeError, - ArrayPrototypeJoin, + RegExp, SafeArrayIterator, + String, StringPrototypeCharAt, + StringPrototypeCharCodeAt, StringPrototypeMatch, - StringPrototypeSlice, - String, + StringPrototypePadStart, StringPrototypeReplace, - StringPrototypeToUpperCase, - StringPrototypeToLowerCase, + StringPrototypeSlice, StringPrototypeSubstring, + StringPrototypeToLowerCase, + StringPrototypeToUpperCase, + TypeError, } = window.__bootstrap.primordials; const ASCII_DIGIT = ["\u0030-\u0039"]; @@ -294,6 +295,18 @@ } } + /** + * @param {unknown} value + * @returns {string} + */ + function serializeJSValueToJSONString(value) { + const result = JSONStringify(value); + if (result === undefined) { + throw new TypeError("Value is not JSON serializable."); + } + return result; + } + window.__bootstrap.infra = { collectSequenceOfCodepoints, ASCII_DIGIT, @@ -320,5 +333,6 @@ forgivingBase64Decode, AssertionError, assert, + serializeJSValueToJSONString, }; })(globalThis); |