diff options
author | Divy Srivastava <dj.srivastava23@gmail.com> | 2023-01-15 05:36:12 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-01-15 13:36:12 +0000 |
commit | 8f321a8a39b0926e00ff9e76c44bc687f3a3c8da (patch) | |
tree | 18ca86ba6e25dc074f5e8c0d39cf0219997743e4 /ext/webidl/benches/dict.js | |
parent | a4c98e347215528d20e4891e4f0e54b2d8523c89 (diff) |
chore(ext/webidl): Add dictionary converter microbenchmark (#17435)
This commits add a `webidl.createDictionaryConverter` converter
microbenchmark.
There are 2 PRs currently open that need a microbenchmark for webidl
dictionary converter. See https://github.com/denoland/deno/pull/16594
and https://github.com/denoland/deno/pull/16407
Closes https://github.com/denoland/deno/issues/17436
Diffstat (limited to 'ext/webidl/benches/dict.js')
-rw-r--r-- | ext/webidl/benches/dict.js | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/ext/webidl/benches/dict.js b/ext/webidl/benches/dict.js new file mode 100644 index 000000000..353a630eb --- /dev/null +++ b/ext/webidl/benches/dict.js @@ -0,0 +1,35 @@ +// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. + +// deno-lint-ignore-file + +const { createDictionaryConverter, converters } = globalThis.__bootstrap.webidl; + +const TextDecodeOptions = createDictionaryConverter( + "TextDecodeOptions", + [ + { + key: "stream", + converter: converters.boolean, + defaultValue: false, + }, + ], +); + +// Sanity check +{ + const o = TextDecodeOptions(undefined); + if (o.stream !== false) { + throw new Error("Unexpected stream value"); + } +} + +function handwrittenConverter(V) { + const defaultValue = { stream: false }; + if (V === undefined || V === null) { + return defaultValue; + } + if (V.stream !== undefined) { + defaultValue.stream = !!V.stream; + } + return defaultValue; +} |