json-value-object.js 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. // Copyright (C) 2021 the V8 project authors. All rights reserved.
  2. // This code is governed by the BSD license found in the LICENSE file.
  3. /*---
  4. esid: sec-parse-json-module
  5. description: Correctly parses the JSON representation of an ordinary object
  6. info: |
  7. # 1.4 ParseJSONModule ( source )
  8. The abstract operation ParseJSONModule takes a single argument source which
  9. is a String representing the contents of a module.
  10. 1. Let json be ? Call(%JSON.parse%, undefined, « source »).
  11. 2. Return CreateDefaultExportSyntheticModule(json).
  12. To more fully verify parsing correctness, the source text of the imported
  13. module record includes non-printable characters (specifically, all four forms
  14. of JSON's so-called "whitespace" token) both before and after the "value."
  15. flags: [module]
  16. includes: [propertyHelper.js]
  17. features: [import-assertions, json-modules]
  18. ---*/
  19. import value from './json-value-object_FIXTURE.json' assert { type: 'json' };
  20. assert.sameValue(Object.getPrototypeOf(value), Object.prototype);
  21. assert.sameValue(Object.getOwnPropertyNames(value).length, 6);
  22. verifyProperty(value, 'number', {
  23. value: -1.2345,
  24. writable: true,
  25. enumerable: true,
  26. configurable: true
  27. });
  28. verifyProperty(value, 'boolean', {
  29. value: true,
  30. writable: true,
  31. enumerable: true,
  32. configurable: true
  33. });
  34. verifyProperty(value, 'string', {
  35. value: 'a string value',
  36. writable: true,
  37. enumerable: true,
  38. configurable: true
  39. });
  40. verifyProperty(value, 'null', {
  41. value: null,
  42. writable: true,
  43. enumerable: true,
  44. configurable: true
  45. });
  46. assert.sameValue(Object.getPrototypeOf(value.object), Object.prototype);
  47. assert.sameValue(Object.getOwnPropertyNames(value.object).length, 0);
  48. assert(
  49. Array.isArray(value.array), 'the value of the "array" property is an array'
  50. );
  51. assert.sameValue(
  52. Object.getPrototypeOf(value.array),
  53. Array.prototype,
  54. 'the value of the "array" property is not a subclass of Array'
  55. );
  56. assert.sameValue(Object.getOwnPropertyNames(value.array).length, 1);