json-value-array.js 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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 array
  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. features: [import-assertions, json-modules]
  17. ---*/
  18. import value from './json-value-array_FIXTURE.json' assert { type: 'json' };
  19. assert(Array.isArray(value), 'the exported value is an array');
  20. assert.sameValue(
  21. Object.getPrototypeOf(value),
  22. Array.prototype,
  23. 'the exported value is not a subclass of Array'
  24. );
  25. assert.sameValue(Object.getOwnPropertyNames(value).length, 7);
  26. assert.sameValue(value.length, 6);
  27. assert.sameValue(value[0], -1.2345);
  28. assert.sameValue(value[1], true);
  29. assert.sameValue(value[2], 'a string value');
  30. assert.sameValue(value[3], null);
  31. assert.sameValue(Object.getPrototypeOf(value[4]), Object.prototype);
  32. assert.sameValue(Object.getOwnPropertyNames(value[4]).length, 0);
  33. assert(Array.isArray(value[5]), 'the fifth element is an array');
  34. assert.sameValue(
  35. Object.getPrototypeOf(value[5]),
  36. Array.prototype,
  37. 'the fifth element is not a subclass of Array'
  38. );
  39. assert.sameValue(Object.getOwnPropertyNames(value[5]).length, 1);