summaryrefslogtreecommitdiff
path: root/ext/webidl/benches/dict.js
diff options
context:
space:
mode:
authorDivy Srivastava <dj.srivastava23@gmail.com>2023-01-15 05:36:12 -0800
committerGitHub <noreply@github.com>2023-01-15 13:36:12 +0000
commit8f321a8a39b0926e00ff9e76c44bc687f3a3c8da (patch)
tree18ca86ba6e25dc074f5e8c0d39cf0219997743e4 /ext/webidl/benches/dict.js
parenta4c98e347215528d20e4891e4f0e54b2d8523c89 (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.js35
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;
+}