summaryrefslogtreecommitdiff
path: root/ext/webidl/benches/dict.js
blob: 353a630eb9b49e3efdfaf493459013e34ddc39ca (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
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;
}