utils.js 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. /* This Source Code Form is subject to the terms of the Mozilla Public
  2. * License, v. 2.0. If a copy of the MPL was not distributed with this
  3. * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
  4. "use strict";
  5. var ERR_CONFLICT = "Remaining conflicting property: ";
  6. var ERR_REQUIRED = "Missing required property: ";
  7. exports.Data = function Data(value, enumerable, configurable, writable) {
  8. return ({
  9. value: value,
  10. enumerable: enumerable !== false,
  11. configurable: configurable !== false,
  12. writable: writable !== false
  13. });
  14. };
  15. exports.Method = function Method(method, enumerable, configurable, writable) {
  16. return ({
  17. value: method,
  18. enumerable: enumerable !== false,
  19. configurable: configurable !== false,
  20. writable: writable !== false
  21. });
  22. };
  23. exports.Accessor = function Accessor(get, set, enumerable, configurable) {
  24. return ({
  25. get: get,
  26. set: set,
  27. enumerable: enumerable !== false,
  28. configurable: configurable !== false
  29. });
  30. };
  31. exports.Required = function Required(name) {
  32. function required() { throw new Error(ERR_REQUIRED + name) }
  33. return ({
  34. get: required,
  35. set: required,
  36. required: true
  37. });
  38. };
  39. exports.Conflict = function Conflict(name) {
  40. function conflict() { throw new Error(ERR_CONFLICT + name) }
  41. return ({
  42. get: conflict,
  43. set: conflict,
  44. conflict: true
  45. });
  46. };