PromiseRejectionEventInit.js 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. "use strict";
  2. const conversions = require("webidl-conversions");
  3. const utils = require("./utils.js");
  4. const EventInit = require("./EventInit.js");
  5. exports._convertInherit = (globalObject, obj, ret, { context = "The provided value" } = {}) => {
  6. EventInit._convertInherit(globalObject, obj, ret, { context });
  7. {
  8. const key = "promise";
  9. let value = obj === undefined || obj === null ? undefined : obj[key];
  10. if (value !== undefined) {
  11. value = conversions["object"](value, { context: context + " has member 'promise' that", globals: globalObject });
  12. ret[key] = value;
  13. } else {
  14. throw new globalObject.TypeError("promise is required in 'PromiseRejectionEventInit'");
  15. }
  16. }
  17. {
  18. const key = "reason";
  19. let value = obj === undefined || obj === null ? undefined : obj[key];
  20. if (value !== undefined) {
  21. value = conversions["any"](value, { context: context + " has member 'reason' that", globals: globalObject });
  22. ret[key] = value;
  23. }
  24. }
  25. };
  26. exports.convert = (globalObject, obj, { context = "The provided value" } = {}) => {
  27. if (obj !== undefined && typeof obj !== "object" && typeof obj !== "function") {
  28. throw new globalObject.TypeError(`${context} is not an object.`);
  29. }
  30. const ret = Object.create(null);
  31. exports._convertInherit(globalObject, obj, ret, { context });
  32. return ret;
  33. };