summaryrefslogtreecommitdiff
path: root/core/runtime/error_builder_test.js
blob: f442819cbca5e4f0e5c12a9b986e0e0d67ad38b9 (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
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
const { core } = Deno;
const { ops } = core;

class DOMException {
  constructor(message, code) {
    this.msg = message;
    this.code = code;
  }
}

core.registerErrorBuilder(
  "DOMExceptionOperationError",
  function DOMExceptionOperationError(msg) {
    return new DOMException(msg, "OperationError");
  },
);

try {
  ops.op_err();
  throw new Error("op_err didn't throw!");
} catch (err) {
  if (!(err instanceof DOMException)) {
    throw new Error("err not DOMException");
  }
  if (err.msg !== "abc") {
    throw new Error("err.message is incorrect");
  }
  if (err.code !== "OperationError") {
    throw new Error("err.code is incorrect");
  }
}