TextEncoderEncodeIntoResult.js 1.2 KB

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