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
//! §19.2.1 — `eval`, and the half of it that needs no scope of the caller's.
//!
//! # The two evals are two operations
//!
//! §13.3.6.1 makes a call a **direct** eval when its callee is a reference spelled `eval` that
//! turns out to be this very function. Anything else that reaches the same function — `(0, eval)`,
//! `globalThis.eval`, a variable it was assigned to, a callback it was passed as — is an
//! **indirect** eval, and §19.2.1.1 gives the two different scopes:
//!
//! - indirect: a fresh declarative scope over the *global* one, whatever the caller was doing.
//! - direct: a fresh declarative scope over the **caller's**, and the caller's variable scope.
//!
//! Only the first is here. The second is in [`crate::vm`] and not in this file at all, because a
//! native call has no handle on the environment its caller was running in — the interpreter has
//! already moved on to the callee's. [`crate::compile::Instruction::CallDirectEval`] is what keeps
//! the decision at the call site, where that handle still exists.
//!
//! # Why indirect eval needs nothing else
//!
//! Because a script's top-level `var` is *already* a property of the global object and its
//! top-level `let` is already a slot in the script's own environment — §16.1.7's split, which
//! ViperJS implements for ordinary scripts. §19.2.1.1's indirect mode asks for exactly that: `var`
//! into the global scope where it outlives the eval, `let` into a scope that is discarded with it.
//! So compiling the text as a Script and running it with a fresh environment *is* the semantics,
//! and there is no special case anywhere in the compiler.
use crate;
use crate;
use crateVm;
/// §19.2.1 `eval(x)`, reached indirectly.
///
/// A direct call never arrives here — the call site answers it itself — so this is the indirect
/// operation and does not ask which it is.
pub
/// §19.2.1.1 for a text that is certainly a String — the indirect mode's whole body.
/// Which of the two clauses is running this text — they differ in one argument.
pub
/// Parse, compile and run one piece of source in the global scope, under one of the two goals.
///
/// Split from the entry point above because the two errors it can answer with are the interesting
/// part, and both are **SyntaxError**: §19.2.1.1 step 8 says a text that is not a Script throws
/// one, and ViperJS decides some of §22.2.1's early errors in the compiler rather than the parser —
/// so a compile refusal has to arrive as the same error a parse refusal does, or a program could
/// tell where ViperJS happens to have put the check.
pub
/// A SyntaxError carrying what the parser or the compiler said.
///
/// Built as an *object* rather than raised by kind and message, because [`Abrupt::Raised`] carries
/// a `&'static str` and these messages are made from the source being evaluated. That is the
/// distinction that type draws, and this is a case on the other side of it.
///
/// Shared with the direct mode — [`crate::vm`] — so that the two report a text that will not parse
/// the same way. §19.2.1.1 step 8 makes no distinction between them and neither should ViperJS.
pub