Sha256: 7897339ea22e046ed1766da026f62cc7cfa0026011c08775f771bc12e778e84c

Contents?: true

Size: 1.42 KB

Versions: 3

Compression:

Stored size: 1.42 KB

Contents

"use strict";
const addConstants = require("../utils").addConstants;
const table = require("./dom-exception-table.json"); // https://heycam.github.io/webidl/#idl-DOMException-error-names

// Precompute some stuff. Mostly unnecessary once we take care of the TODO below.
const namesWithCodes = Object.keys(table).filter(name => "legacyCodeValue" in table[name]);

const codesToNames = Object.create(null);
for (const name of namesWithCodes) {
  codesToNames[table[name].legacyCodeValue] = name;
}

module.exports = DOMException;

// TODO: update constructor signature to match WebIDL spec
// See also https://github.com/heycam/webidl/pull/22 which isn't merged as of yet
function DOMException(code, message) {
  const name = codesToNames[code];

  if (message === undefined) {
    message = table[name].description;
  }
  Error.call(this, message);

  Object.defineProperty(this, "name", { value: name, writable: true, configurable: true, enumerable: false });
  Object.defineProperty(this, "code", { value: code, writable: true, configurable: true, enumerable: false });

  if (Error.captureStackTrace) {
    Error.captureStackTrace(this, DOMException);
  }
}

Object.setPrototypeOf(DOMException, Error);
Object.setPrototypeOf(DOMException.prototype, Error.prototype);

const constants = Object.create(null);
for (const name of namesWithCodes) {
  constants[table[name].legacyCodeName] = table[name].legacyCodeValue;
}

addConstants(DOMException, constants);

Version data entries

3 entries across 3 versions & 3 rubygems

Version Path
learn_create-0.0.22 lib/templates/javascript_lab_template/node_modules/jsdom/lib/jsdom/web-idl/DOMException.js
lanes-0.8.0 node_modules/jsdom/lib/jsdom/web-idl/DOMException.js
select_all-rails-0.3.1 node_modules/jsdom/lib/jsdom/web-idl/DOMException.js