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
/*
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
//! Port of `include/hermes/Runtime/Libhermes.h:13-72`: the list of built-in
//! symbols declared by the HermesVM runtime, as a JS source string.
//!
//! **Stability: advanced / port-internal.** This module is `pub` because
//! `tools`' `sema-dump` bin parses [`LIBHERMES`] itself to reproduce
//! CompilerDriver's ambient-declaration setup; the crate-root
//! [`crate::resolve_for_compile`] already does that for you. The contents
//! track the C++ header and change whenever HermesVM's built-in list does,
//! so this may change, or be demoted to `pub(crate)`, in a 0.x release. See
//! the crate doc for the stable surface.
//!
//! The C++ side is a single `const char libhermes[]` built from adjacent
//! string literals, with the twelve typed-array constructors spliced in by
//! `#include "hermes/VM/TypedArrays.def"` under a local `TYPED_ARRAY(name,
//! type)` macro expanding to `"function " #name "Array() {}"`. Rust has no
//! preprocessor, so the include is expanded by hand below: the twelve lines
//! from `function Uint8Array() {}` through `function BigInt64Array() {}`,
//! in `TypedArrays.def`'s order (`TYPED_ARRAY_NO_CLAMP` is NOT defined at
//! the include site, so `Uint8Clamped` is included). The empty `""`
//! literals in the C++ source are pure formatting (they separate logical
//! groups and concatenate to nothing) and appear here as blank lines in the
//! string.
//!
//! Two spellings are load-bearing and deliberately preserved verbatim:
//! - `"function escape() {}"` / `"function unescape() {}"` have TWO
//! spaces before the brace in the C++ source.
//! - the whole constant is a single line in C++ (no separators at all
//! between the concatenated literals); here it is one statement per line.
//! Both parse to the same AST, and only the declared *names* reach the
//! dump, so the layout difference is not observable. It is a difference
//! in the constant's bytes, though, hence this note.
//!
//! This string is parsed by the `sema-dump` bin exactly like CompilerDriver's
//! `loadGlobalDefinition` (CompilerDriver.cpp:773-785, called at :2028-2035)
//! does, and the resulting `Program` becomes the single ambient-declaration
//! file passed to `resolve::resolve_ast`. The 63 `UndeclaredGlobalProperty`
//! decls the empty-input dump contains are exactly this list, deduplicated
//! (`Error` appears both as a `var` and as a `function`), and the
//! `sema_differential` test enforces that byte-for-byte against
//! `hermesc -dump-sema`.
/// The HermesVM runtime's built-in symbol declarations, as JS source. Port
/// of `hermes::libhermes` (`include/hermes/Runtime/Libhermes.h:13-72`); see
/// the module doc for the two spellings that are preserved verbatim and for
/// how the C++ `TYPED_ARRAY` include was expanded by hand.
pub const LIBHERMES: &str = "\
var Array;
var BigInt;
var Boolean;
var Date;
var Error;
var Function;
var HermesInternal;
var HermesAsyncIteratorsInternal;
var JSON;
var Map;
var Math;
var Number;
var Object;
var Proxy;
var Reflect;
var RegExp;
var Set;
var String;
var Symbol;
var WeakMap;
var WeakSet;
var $SHBuiltin;
var Hermes;
var Infinity;
var NaN;
var globalThis;
var undefined;
function Error() {}
function AggregateError() {}
function EvalError() {}
function RangeError() {}
function ReferenceError() {}
function SyntaxError() {}
function TypeError() {}
function URIError() {}
function ArrayBuffer() {}
function DataView() {}
function TextEncoder() {}
function Worker() {}
function Uint8Array() {}
function Int8Array() {}
function Uint8ClampedArray() {}
function Uint16Array() {}
function Int16Array() {}
function Uint32Array() {}
function Int32Array() {}
function Float16Array() {}
function Float32Array() {}
function Float64Array() {}
function BigUint64Array() {}
function BigInt64Array() {}
function print() {}
function eval() {}
function parseInt() {}
function parseFloat() {}
function isNaN() {}
function isFinite() {}
function escape() {}
function unescape() {}
function decodeURI() {}
function decodeURIComponent() {}
function encodeURI() {}
function encodeURIComponent() {}
function gc() {}";