1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
//! §10.4.3 — the String exotic object, and the properties it has without storing any.
//!
//! # What is exotic about it
//!
//! `new String("abc")` has four own properties — `0`, `1`, `2` and `length` — and only one of them
//! is written down. The three indices are answered from the characters every time they are asked
//! for, which is why
//!
//! ```text
//! var s = new String("abc"); s[0] = "z"; s[0]
//! ```
//!
//! still answers `"a"`. There is nowhere to put the `"z"`: §10.4.3.5 gives every index a property
//! that is not writable and not configurable, so the assignment is refused and the character stands.
//!
//! # Why they are computed and not stored
//!
//! Because they cannot change and there can be a great many of them. A String object's characters
//! are fixed when it is made — nothing in the language can alter one — so a stored property could
//! only ever hold what this function computes. Storing them would make `new String(s)` cost a
//! property per character of `s`, which for a string near [`crate::heap::MAX_STRING_LENGTH`] is an
//! allocation the program did not ask for.
//!
//! # Where else this is used
//!
//! §7.3.2 says a property read from a *primitive* string reads it from the object the primitive
//! stands for. Rather than build that object and throw it away on every `"abc".length`, the reader
//! in [`crate::vm`] asks these same two functions about the characters directly. One definition of
//! what a String has, consulted from both sides, is what keeps `"abc"[0]` and `new String("abc")[0]`
//! from being able to disagree.
use crate;
use crateValue;
/// §10.4.3.5 `StringGetOwnProperty` — the property a string's characters give a key, if any.
///
/// `None` for `length`, which is an ordinary stored property put there when the object is made, and
/// for every key that is not an index inside the string. An index *outside* it is `None` too, which
/// is how `"ab"[5]` becomes `undefined` by the ordinary route of finding nothing anywhere.
pub
/// The one-character string at `index`, made if this heap has not got one already.
///
/// Separate from [`character`] because that answers a question and this changes the heap: a reader
/// holding a shared borrow can ask what a character *is* only if the answer already exists, and
/// this is what makes sure it does.
pub
/// How many characters a String object's data has.
pub
/// Whether a define at a character's key is allowed — §10.4.3.3, and nothing is ever stored.
///
/// §10.1.6.3 `ValidateAndApplyPropertyDescriptor` in the one shape it can take here. The current
/// property is fixed: a data property, not writable, enumerable, not configurable. Everything that
/// rule does with a *configurable* current property is unreachable, so what is left is the short
/// list of ways to describe the property that is already there — and a define that describes it is
/// allowed and changes nothing, which is why there is no branch here that writes.
pub