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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
//! §10.4.4 — the arguments exotic object, and the mapping that makes it exotic.
//!
//! # What is exotic about it
//!
//! Nothing about its shape. It is an ordinary object with an ordinary prototype, a `length`, a
//! `callee`, and a property per argument. What is exotic is that some of those properties are
//! *the same variable* as the parameter of the same position: in
//!
//! ```text
//! function f(a) { arguments[0] = 2; return a; }
//! ```
//!
//! `f(1)` answers `2`. Nothing was copied — `arguments[0]` and `a` are one binding seen through
//! two names, and §10.4.4 calls the link between them the *parameter map*.
//!
//! # Why the map is per index, and one-way
//!
//! Because a program can break it, one index at a time. §10.4.4.2 removes an index's mapping when
//! it is redefined as an accessor or made non-writable, and §10.4.4.5 removes it when the property
//! is deleted. Afterwards the two names are two variables and nothing joins them again — so this
//! is a slot per index rather than a count of how many are still mapped.
//!
//! # What is deliberately not here
//!
//! An *unmapped* arguments object. §10.4.4 makes one for a strict function, or one whose parameter
//! list is not simple, and ViperJS has neither: the interpreter tracks no strictness yet, and
//! default, rest and destructuring parameters are refused. Every arguments object it can build is
//! a mapped one, so there is one path here rather than two.
use crate;
use crateValue;
/// What a call knows that its arguments object needs — §10.4.4.4 and §10.4.4.6's inputs.
///
/// A struct rather than six more parameters, because six of them in a row is a call whose
/// arguments can be silently swapped. Two are `ObjectId`s and two are `bool`s: the compiler could
/// not tell `callee` from `thrower`, nor `mapped` from anything else.
/// Which parameter each argument index is the same variable as — §10.4.4's parameter map.
/// The index a key names, if it names one at all.
///
/// Not §10.4.2's array index: an arguments object is not an Array, and §10.4.4 joins the keys
/// `"0"`, `"1"` and so on and nothing else.
///
/// Written back and compared rather than merely parsed, because `"01"` parses as 1 and is not the
/// key `"1"` — a map found by parsing alone would make `arguments["01"]` an alias of the first
/// parameter, which is a property the object does not even have.
///
/// Two allocations per call, and it is called once per property an arguments object is asked for.
/// Reading the digits out of the UTF-16 units directly would need none, and is the sort of thing
/// M8 measures before it changes: the callers all check for a parameter map first, so no ordinary
/// object pays this.
pub