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