mustardscript 0.1.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +62 -20
- package/SECURITY.md +1 -1
- package/dist/index.js +2 -0
- package/dist/lib/executor.js +16 -1
- package/dist/lib/policy.js +301 -22
- package/dist/lib/progress.js +499 -113
- package/dist/lib/runtime.js +109 -40
- package/dist/lib/structured.js +327 -11
- package/dist/native-loader.js +11 -12
- package/index.d.ts +54 -6
- package/mustard.d.ts +23 -1
- package/package.json +34 -25
- package/Cargo.lock +0 -1579
- package/Cargo.toml +0 -40
- package/crates/mustard/Cargo.toml +0 -31
- package/crates/mustard/src/cancellation.rs +0 -28
- package/crates/mustard/src/diagnostic.rs +0 -145
- package/crates/mustard/src/ir.rs +0 -435
- package/crates/mustard/src/lib.rs +0 -21
- package/crates/mustard/src/limits.rs +0 -22
- package/crates/mustard/src/parser/expressions.rs +0 -723
- package/crates/mustard/src/parser/mod.rs +0 -115
- package/crates/mustard/src/parser/operators.rs +0 -105
- package/crates/mustard/src/parser/patterns.rs +0 -123
- package/crates/mustard/src/parser/scope.rs +0 -107
- package/crates/mustard/src/parser/statements.rs +0 -298
- package/crates/mustard/src/parser/tests/acceptance.rs +0 -339
- package/crates/mustard/src/parser/tests/mod.rs +0 -2
- package/crates/mustard/src/parser/tests/rejections.rs +0 -107
- package/crates/mustard/src/runtime/accounting.rs +0 -613
- package/crates/mustard/src/runtime/api.rs +0 -192
- package/crates/mustard/src/runtime/async_runtime/mod.rs +0 -5
- package/crates/mustard/src/runtime/async_runtime/promises.rs +0 -246
- package/crates/mustard/src/runtime/async_runtime/reactions.rs +0 -400
- package/crates/mustard/src/runtime/async_runtime/scheduler.rs +0 -224
- package/crates/mustard/src/runtime/builtins/arrays.rs +0 -1205
- package/crates/mustard/src/runtime/builtins/collections.rs +0 -573
- package/crates/mustard/src/runtime/builtins/install.rs +0 -501
- package/crates/mustard/src/runtime/builtins/intl.rs +0 -553
- package/crates/mustard/src/runtime/builtins/mod.rs +0 -25
- package/crates/mustard/src/runtime/builtins/objects.rs +0 -405
- package/crates/mustard/src/runtime/builtins/primitives.rs +0 -859
- package/crates/mustard/src/runtime/builtins/promises.rs +0 -335
- package/crates/mustard/src/runtime/builtins/regexp.rs +0 -356
- package/crates/mustard/src/runtime/builtins/strings.rs +0 -803
- package/crates/mustard/src/runtime/builtins/support.rs +0 -561
- package/crates/mustard/src/runtime/bytecode.rs +0 -123
- package/crates/mustard/src/runtime/compiler/assignments.rs +0 -690
- package/crates/mustard/src/runtime/compiler/bindings.rs +0 -92
- package/crates/mustard/src/runtime/compiler/context.rs +0 -46
- package/crates/mustard/src/runtime/compiler/control.rs +0 -342
- package/crates/mustard/src/runtime/compiler/expressions.rs +0 -372
- package/crates/mustard/src/runtime/compiler/mod.rs +0 -173
- package/crates/mustard/src/runtime/compiler/statements.rs +0 -459
- package/crates/mustard/src/runtime/conversions/boundary.rs +0 -293
- package/crates/mustard/src/runtime/conversions/coercions.rs +0 -217
- package/crates/mustard/src/runtime/conversions/errors.rs +0 -118
- package/crates/mustard/src/runtime/conversions/mod.rs +0 -14
- package/crates/mustard/src/runtime/conversions/operators.rs +0 -334
- package/crates/mustard/src/runtime/env.rs +0 -355
- package/crates/mustard/src/runtime/exceptions.rs +0 -377
- package/crates/mustard/src/runtime/gc.rs +0 -595
- package/crates/mustard/src/runtime/mod.rs +0 -318
- package/crates/mustard/src/runtime/properties.rs +0 -1762
- package/crates/mustard/src/runtime/serialization.rs +0 -127
- package/crates/mustard/src/runtime/shared.rs +0 -108
- package/crates/mustard/src/runtime/snapshot_validation_tests.rs +0 -93
- package/crates/mustard/src/runtime/state.rs +0 -652
- package/crates/mustard/src/runtime/tests/async_host.rs +0 -104
- package/crates/mustard/src/runtime/tests/collections.rs +0 -50
- package/crates/mustard/src/runtime/tests/diagnostics.rs +0 -36
- package/crates/mustard/src/runtime/tests/exceptions.rs +0 -122
- package/crates/mustard/src/runtime/tests/execution.rs +0 -553
- package/crates/mustard/src/runtime/tests/gc.rs +0 -533
- package/crates/mustard/src/runtime/tests/mod.rs +0 -56
- package/crates/mustard/src/runtime/tests/serialization.rs +0 -170
- package/crates/mustard/src/runtime/validation/bytecode.rs +0 -484
- package/crates/mustard/src/runtime/validation/mod.rs +0 -14
- package/crates/mustard/src/runtime/validation/policy.rs +0 -94
- package/crates/mustard/src/runtime/validation/snapshot.rs +0 -406
- package/crates/mustard/src/runtime/validation/walk.rs +0 -206
- package/crates/mustard/src/runtime/vm.rs +0 -1016
- package/crates/mustard/src/span.rs +0 -22
- package/crates/mustard/src/structured.rs +0 -107
- package/crates/mustard-bridge/Cargo.toml +0 -17
- package/crates/mustard-bridge/src/codec.rs +0 -46
- package/crates/mustard-bridge/src/dto.rs +0 -99
- package/crates/mustard-bridge/src/lib.rs +0 -12
- package/crates/mustard-bridge/src/operations.rs +0 -142
- package/crates/mustard-node/Cargo.toml +0 -24
- package/crates/mustard-node/build.rs +0 -3
- package/crates/mustard-node/src/lib.rs +0 -236
- package/crates/mustard-sidecar/Cargo.toml +0 -21
- package/crates/mustard-sidecar/src/lib.rs +0 -134
- package/crates/mustard-sidecar/src/main.rs +0 -36
- package/dist/install.js +0 -117
|
@@ -1,501 +0,0 @@
|
|
|
1
|
-
use super::*;
|
|
2
|
-
|
|
3
|
-
impl Runtime {
|
|
4
|
-
pub(crate) fn call_builtin(
|
|
5
|
-
&mut self,
|
|
6
|
-
function: BuiltinFunction,
|
|
7
|
-
this_value: Value,
|
|
8
|
-
args: &[Value],
|
|
9
|
-
) -> MustardResult<Value> {
|
|
10
|
-
match function {
|
|
11
|
-
BuiltinFunction::FunctionCtor => Err(MustardError::runtime(
|
|
12
|
-
"TypeError: Function constructor is unavailable in the supported surface",
|
|
13
|
-
)),
|
|
14
|
-
BuiltinFunction::FunctionCall
|
|
15
|
-
| BuiltinFunction::FunctionApply
|
|
16
|
-
| BuiltinFunction::FunctionBind => Err(MustardError::runtime(
|
|
17
|
-
"internal function helper should be dispatched through call semantics",
|
|
18
|
-
)),
|
|
19
|
-
BuiltinFunction::ArrayCtor => self.call_array_ctor(args),
|
|
20
|
-
BuiltinFunction::ArrayFrom => self.call_array_from(args),
|
|
21
|
-
BuiltinFunction::ArrayOf => self.call_array_of(args),
|
|
22
|
-
BuiltinFunction::ArrayIsArray => {
|
|
23
|
-
Ok(Value::Bool(matches!(args.first(), Some(Value::Array(_)))))
|
|
24
|
-
}
|
|
25
|
-
BuiltinFunction::ArrayPush => self.call_array_push(this_value, args),
|
|
26
|
-
BuiltinFunction::ArrayPop => self.call_array_pop(this_value),
|
|
27
|
-
BuiltinFunction::ArraySlice => self.call_array_slice(this_value, args),
|
|
28
|
-
BuiltinFunction::ArraySplice => self.call_array_splice(this_value, args),
|
|
29
|
-
BuiltinFunction::ArrayConcat => self.call_array_concat(this_value, args),
|
|
30
|
-
BuiltinFunction::ArrayAt => self.call_array_at(this_value, args),
|
|
31
|
-
BuiltinFunction::ArrayJoin => self.call_array_join(this_value, args),
|
|
32
|
-
BuiltinFunction::ArrayIncludes => self.call_array_includes(this_value, args),
|
|
33
|
-
BuiltinFunction::ArrayIndexOf => self.call_array_index_of(this_value, args),
|
|
34
|
-
BuiltinFunction::ArrayLastIndexOf => self.call_array_last_index_of(this_value, args),
|
|
35
|
-
BuiltinFunction::ArrayReverse => self.call_array_reverse(this_value),
|
|
36
|
-
BuiltinFunction::ArrayFill => self.call_array_fill(this_value, args),
|
|
37
|
-
BuiltinFunction::ArraySort => self.call_array_sort(this_value, args),
|
|
38
|
-
BuiltinFunction::ArrayValues => self.call_array_values(this_value),
|
|
39
|
-
BuiltinFunction::ArrayKeys => self.call_array_keys(this_value),
|
|
40
|
-
BuiltinFunction::ArrayEntries => self.call_array_entries(this_value),
|
|
41
|
-
BuiltinFunction::ArrayForEach => self.call_array_for_each(this_value, args),
|
|
42
|
-
BuiltinFunction::ArrayMap => self.call_array_map(this_value, args),
|
|
43
|
-
BuiltinFunction::ArrayFilter => self.call_array_filter(this_value, args),
|
|
44
|
-
BuiltinFunction::ArrayFind => self.call_array_find(this_value, args),
|
|
45
|
-
BuiltinFunction::ArrayFindIndex => self.call_array_find_index(this_value, args),
|
|
46
|
-
BuiltinFunction::ArraySome => self.call_array_some(this_value, args),
|
|
47
|
-
BuiltinFunction::ArrayEvery => self.call_array_every(this_value, args),
|
|
48
|
-
BuiltinFunction::ArrayFlat => self.call_array_flat(this_value, args),
|
|
49
|
-
BuiltinFunction::ArrayFlatMap => self.call_array_flat_map(this_value, args),
|
|
50
|
-
BuiltinFunction::ArrayReduce => self.call_array_reduce(this_value, args),
|
|
51
|
-
BuiltinFunction::ArrayReduceRight => self.call_array_reduce_right(this_value, args),
|
|
52
|
-
BuiltinFunction::ArrayFindLast => self.call_array_find_last(this_value, args),
|
|
53
|
-
BuiltinFunction::ArrayFindLastIndex => {
|
|
54
|
-
self.call_array_find_last_index(this_value, args)
|
|
55
|
-
}
|
|
56
|
-
BuiltinFunction::ObjectCtor => self.call_object_ctor(args),
|
|
57
|
-
BuiltinFunction::ObjectAssign => self.call_object_assign(args),
|
|
58
|
-
BuiltinFunction::ObjectCreate => self.reject_object_create(),
|
|
59
|
-
BuiltinFunction::ObjectFreeze => self.reject_object_freeze(),
|
|
60
|
-
BuiltinFunction::ObjectSeal => self.reject_object_seal(),
|
|
61
|
-
BuiltinFunction::ObjectFromEntries => self.call_object_from_entries(args),
|
|
62
|
-
BuiltinFunction::ObjectKeys => self.call_object_keys(args),
|
|
63
|
-
BuiltinFunction::ObjectValues => self.call_object_values(args),
|
|
64
|
-
BuiltinFunction::ObjectEntries => self.call_object_entries(args),
|
|
65
|
-
BuiltinFunction::ObjectHasOwn => self.call_object_has_own(args),
|
|
66
|
-
BuiltinFunction::MapCtor => Err(MustardError::runtime(
|
|
67
|
-
"TypeError: Map constructor must be called with new",
|
|
68
|
-
)),
|
|
69
|
-
BuiltinFunction::MapGet => self.call_map_get(this_value, args),
|
|
70
|
-
BuiltinFunction::MapSet => self.call_map_set(this_value, args),
|
|
71
|
-
BuiltinFunction::MapHas => self.call_map_has(this_value, args),
|
|
72
|
-
BuiltinFunction::MapDelete => self.call_map_delete(this_value, args),
|
|
73
|
-
BuiltinFunction::MapClear => self.call_map_clear(this_value),
|
|
74
|
-
BuiltinFunction::MapEntries => self.call_map_entries(this_value),
|
|
75
|
-
BuiltinFunction::MapKeys => self.call_map_keys(this_value),
|
|
76
|
-
BuiltinFunction::MapValues => self.call_map_values(this_value),
|
|
77
|
-
BuiltinFunction::MapForEach => self.call_map_for_each(this_value, args),
|
|
78
|
-
BuiltinFunction::SetCtor => Err(MustardError::runtime(
|
|
79
|
-
"TypeError: Set constructor must be called with new",
|
|
80
|
-
)),
|
|
81
|
-
BuiltinFunction::SetAdd => self.call_set_add(this_value, args),
|
|
82
|
-
BuiltinFunction::SetHas => self.call_set_has(this_value, args),
|
|
83
|
-
BuiltinFunction::SetDelete => self.call_set_delete(this_value, args),
|
|
84
|
-
BuiltinFunction::SetClear => self.call_set_clear(this_value),
|
|
85
|
-
BuiltinFunction::SetEntries => self.call_set_entries(this_value),
|
|
86
|
-
BuiltinFunction::SetKeys => self.call_set_keys(this_value),
|
|
87
|
-
BuiltinFunction::SetValues => self.call_set_values(this_value),
|
|
88
|
-
BuiltinFunction::SetForEach => self.call_set_for_each(this_value, args),
|
|
89
|
-
BuiltinFunction::IteratorNext => self.call_iterator_next(this_value),
|
|
90
|
-
BuiltinFunction::PromiseCtor => Err(MustardError::runtime(
|
|
91
|
-
"TypeError: Promise constructor must be called with new",
|
|
92
|
-
)),
|
|
93
|
-
BuiltinFunction::PromiseResolve => {
|
|
94
|
-
let value = args.first().cloned().unwrap_or(Value::Undefined);
|
|
95
|
-
Ok(Value::Promise(self.coerce_to_promise(value)?))
|
|
96
|
-
}
|
|
97
|
-
BuiltinFunction::PromiseReject => {
|
|
98
|
-
let value = args.first().cloned().unwrap_or(Value::Undefined);
|
|
99
|
-
Ok(Value::Promise(self.insert_promise(
|
|
100
|
-
PromiseState::Rejected(PromiseRejection {
|
|
101
|
-
value,
|
|
102
|
-
span: None,
|
|
103
|
-
traceback: self.traceback_snapshots(),
|
|
104
|
-
}),
|
|
105
|
-
)?))
|
|
106
|
-
}
|
|
107
|
-
BuiltinFunction::PromiseResolveFunction(target) => {
|
|
108
|
-
let value = args.first().cloned().unwrap_or(Value::Undefined);
|
|
109
|
-
self.resolve_promise(target, value)?;
|
|
110
|
-
Ok(Value::Undefined)
|
|
111
|
-
}
|
|
112
|
-
BuiltinFunction::PromiseRejectFunction(target) => {
|
|
113
|
-
let value = args.first().cloned().unwrap_or(Value::Undefined);
|
|
114
|
-
self.reject_promise(
|
|
115
|
-
target,
|
|
116
|
-
PromiseRejection {
|
|
117
|
-
value,
|
|
118
|
-
span: None,
|
|
119
|
-
traceback: self.traceback_snapshots(),
|
|
120
|
-
},
|
|
121
|
-
)?;
|
|
122
|
-
Ok(Value::Undefined)
|
|
123
|
-
}
|
|
124
|
-
BuiltinFunction::PromiseThen => self.call_promise_then(this_value, args),
|
|
125
|
-
BuiltinFunction::PromiseCatch => self.call_promise_catch(this_value, args),
|
|
126
|
-
BuiltinFunction::PromiseFinally => self.call_promise_finally(this_value, args),
|
|
127
|
-
BuiltinFunction::PromiseAll => self.call_promise_all(args),
|
|
128
|
-
BuiltinFunction::PromiseRace => self.call_promise_race(args),
|
|
129
|
-
BuiltinFunction::PromiseAny => self.call_promise_any(args),
|
|
130
|
-
BuiltinFunction::PromiseAllSettled => self.call_promise_all_settled(args),
|
|
131
|
-
BuiltinFunction::RegExpCtor => self.construct_regexp(args),
|
|
132
|
-
BuiltinFunction::RegExpExec => self.call_regexp_exec(this_value, args),
|
|
133
|
-
BuiltinFunction::RegExpTest => self.call_regexp_test(this_value, args),
|
|
134
|
-
BuiltinFunction::ErrorCtor => self.call_error_ctor(args, "Error"),
|
|
135
|
-
BuiltinFunction::TypeErrorCtor => self.call_error_ctor(args, "TypeError"),
|
|
136
|
-
BuiltinFunction::ReferenceErrorCtor => self.call_error_ctor(args, "ReferenceError"),
|
|
137
|
-
BuiltinFunction::RangeErrorCtor => self.call_error_ctor(args, "RangeError"),
|
|
138
|
-
BuiltinFunction::SyntaxErrorCtor => self.call_error_ctor(args, "SyntaxError"),
|
|
139
|
-
BuiltinFunction::NumberCtor => self.call_number_ctor(args),
|
|
140
|
-
BuiltinFunction::NumberParseInt => self.call_number_parse_int(args),
|
|
141
|
-
BuiltinFunction::NumberParseFloat => self.call_number_parse_float(args),
|
|
142
|
-
BuiltinFunction::NumberIsNaN => Ok(self.call_number_is_nan(args)),
|
|
143
|
-
BuiltinFunction::NumberIsFinite => Ok(self.call_number_is_finite(args)),
|
|
144
|
-
BuiltinFunction::NumberIsInteger => Ok(self.call_number_is_integer(args)),
|
|
145
|
-
BuiltinFunction::NumberIsSafeInteger => Ok(self.call_number_is_safe_integer(args)),
|
|
146
|
-
BuiltinFunction::DateCtor => Err(MustardError::runtime(
|
|
147
|
-
"TypeError: Date constructor must be called with new",
|
|
148
|
-
)),
|
|
149
|
-
BuiltinFunction::DateNow => Ok(Value::Number(current_time_millis())),
|
|
150
|
-
BuiltinFunction::DateGetTime => self.call_date_get_time(this_value),
|
|
151
|
-
BuiltinFunction::DateValueOf => self.call_date_value_of(this_value),
|
|
152
|
-
BuiltinFunction::DateToISOString => self.call_date_to_iso_string(this_value),
|
|
153
|
-
BuiltinFunction::DateToJSON => self.call_date_to_json(this_value),
|
|
154
|
-
BuiltinFunction::DateGetUTCFullYear => self.call_date_get_utc_full_year(this_value),
|
|
155
|
-
BuiltinFunction::DateGetUTCMonth => self.call_date_get_utc_month(this_value),
|
|
156
|
-
BuiltinFunction::DateGetUTCDate => self.call_date_get_utc_date(this_value),
|
|
157
|
-
BuiltinFunction::DateGetUTCHours => self.call_date_get_utc_hours(this_value),
|
|
158
|
-
BuiltinFunction::DateGetUTCMinutes => self.call_date_get_utc_minutes(this_value),
|
|
159
|
-
BuiltinFunction::DateGetUTCSeconds => self.call_date_get_utc_seconds(this_value),
|
|
160
|
-
BuiltinFunction::IntlDateTimeFormatCtor => self.construct_intl_date_time_format(args),
|
|
161
|
-
BuiltinFunction::IntlNumberFormatCtor => self.construct_intl_number_format(args),
|
|
162
|
-
BuiltinFunction::IntlDateTimeFormatFormat => {
|
|
163
|
-
self.call_intl_date_time_format_format(this_value, args)
|
|
164
|
-
}
|
|
165
|
-
BuiltinFunction::IntlDateTimeFormatResolvedOptions => {
|
|
166
|
-
self.call_intl_date_time_format_resolved_options(this_value)
|
|
167
|
-
}
|
|
168
|
-
BuiltinFunction::IntlNumberFormatFormat => {
|
|
169
|
-
self.call_intl_number_format_format(this_value, args)
|
|
170
|
-
}
|
|
171
|
-
BuiltinFunction::IntlNumberFormatResolvedOptions => {
|
|
172
|
-
self.call_intl_number_format_resolved_options(this_value)
|
|
173
|
-
}
|
|
174
|
-
BuiltinFunction::StringCtor => self.call_string_ctor(args),
|
|
175
|
-
BuiltinFunction::StringTrim => self.call_string_trim(this_value),
|
|
176
|
-
BuiltinFunction::StringTrimStart => self.call_string_trim_start(this_value),
|
|
177
|
-
BuiltinFunction::StringTrimEnd => self.call_string_trim_end(this_value),
|
|
178
|
-
BuiltinFunction::StringIncludes => self.call_string_includes(this_value, args),
|
|
179
|
-
BuiltinFunction::StringStartsWith => self.call_string_starts_with(this_value, args),
|
|
180
|
-
BuiltinFunction::StringEndsWith => self.call_string_ends_with(this_value, args),
|
|
181
|
-
BuiltinFunction::StringIndexOf => self.call_string_index_of(this_value, args),
|
|
182
|
-
BuiltinFunction::StringLastIndexOf => self.call_string_last_index_of(this_value, args),
|
|
183
|
-
BuiltinFunction::StringCharAt => self.call_string_char_at(this_value, args),
|
|
184
|
-
BuiltinFunction::StringAt => self.call_string_at(this_value, args),
|
|
185
|
-
BuiltinFunction::StringSlice => self.call_string_slice(this_value, args),
|
|
186
|
-
BuiltinFunction::StringSubstring => self.call_string_substring(this_value, args),
|
|
187
|
-
BuiltinFunction::StringToLowerCase => self.call_string_to_lower_case(this_value),
|
|
188
|
-
BuiltinFunction::StringToUpperCase => self.call_string_to_upper_case(this_value),
|
|
189
|
-
BuiltinFunction::StringRepeat => self.call_string_repeat(this_value, args),
|
|
190
|
-
BuiltinFunction::StringConcat => self.call_string_concat(this_value, args),
|
|
191
|
-
BuiltinFunction::StringPadStart => self.call_string_pad_start(this_value, args),
|
|
192
|
-
BuiltinFunction::StringPadEnd => self.call_string_pad_end(this_value, args),
|
|
193
|
-
BuiltinFunction::StringSplit => self.call_string_split(this_value, args),
|
|
194
|
-
BuiltinFunction::StringReplace => self.call_string_replace(this_value, args),
|
|
195
|
-
BuiltinFunction::StringReplaceAll => self.call_string_replace_all(this_value, args),
|
|
196
|
-
BuiltinFunction::StringSearch => self.call_string_search(this_value, args),
|
|
197
|
-
BuiltinFunction::StringMatch => self.call_string_match(this_value, args),
|
|
198
|
-
BuiltinFunction::StringMatchAll => self.call_string_match_all(this_value, args),
|
|
199
|
-
BuiltinFunction::StringToString => self.call_string_to_string(this_value),
|
|
200
|
-
BuiltinFunction::StringValueOf => self.call_string_value_of(this_value),
|
|
201
|
-
BuiltinFunction::BooleanCtor => self.call_boolean_ctor(args),
|
|
202
|
-
BuiltinFunction::BooleanToString => self.call_boolean_to_string(this_value),
|
|
203
|
-
BuiltinFunction::BooleanValueOf => self.call_boolean_value_of(this_value),
|
|
204
|
-
BuiltinFunction::NumberToString => self.call_number_to_string(this_value),
|
|
205
|
-
BuiltinFunction::NumberValueOf => self.call_number_value_of(this_value),
|
|
206
|
-
BuiltinFunction::MathAbs => self.call_math_abs(args),
|
|
207
|
-
BuiltinFunction::MathMax => self.call_math_max(args),
|
|
208
|
-
BuiltinFunction::MathMin => self.call_math_min(args),
|
|
209
|
-
BuiltinFunction::MathFloor => self.call_math_floor(args),
|
|
210
|
-
BuiltinFunction::MathCeil => self.call_math_ceil(args),
|
|
211
|
-
BuiltinFunction::MathRound => self.call_math_round(args),
|
|
212
|
-
BuiltinFunction::MathPow => self.call_math_pow(args),
|
|
213
|
-
BuiltinFunction::MathSqrt => self.call_math_sqrt(args),
|
|
214
|
-
BuiltinFunction::MathTrunc => self.call_math_trunc(args),
|
|
215
|
-
BuiltinFunction::MathSign => self.call_math_sign(args),
|
|
216
|
-
BuiltinFunction::MathLog => self.call_math_log(args),
|
|
217
|
-
BuiltinFunction::MathExp => self.call_math_exp(args),
|
|
218
|
-
BuiltinFunction::MathLog2 => self.call_math_log2(args),
|
|
219
|
-
BuiltinFunction::MathLog10 => self.call_math_log10(args),
|
|
220
|
-
BuiltinFunction::MathSin => self.call_math_sin(args),
|
|
221
|
-
BuiltinFunction::MathCos => self.call_math_cos(args),
|
|
222
|
-
BuiltinFunction::MathAtan2 => self.call_math_atan2(args),
|
|
223
|
-
BuiltinFunction::MathHypot => self.call_math_hypot(args),
|
|
224
|
-
BuiltinFunction::MathCbrt => self.call_math_cbrt(args),
|
|
225
|
-
BuiltinFunction::MathRandom => Ok(self.call_math_random()),
|
|
226
|
-
BuiltinFunction::JsonStringify => self.call_json_stringify(args),
|
|
227
|
-
BuiltinFunction::JsonParse => self.call_json_parse(args),
|
|
228
|
-
}
|
|
229
|
-
}
|
|
230
|
-
|
|
231
|
-
pub(crate) fn install_builtins(&mut self) -> MustardResult<()> {
|
|
232
|
-
let global_object = self.insert_object(IndexMap::new(), ObjectKind::Global)?;
|
|
233
|
-
for function in [
|
|
234
|
-
BuiltinFunction::FunctionCtor,
|
|
235
|
-
BuiltinFunction::ObjectCtor,
|
|
236
|
-
BuiltinFunction::MapCtor,
|
|
237
|
-
BuiltinFunction::SetCtor,
|
|
238
|
-
BuiltinFunction::ArrayCtor,
|
|
239
|
-
BuiltinFunction::DateCtor,
|
|
240
|
-
BuiltinFunction::PromiseCtor,
|
|
241
|
-
BuiltinFunction::RegExpCtor,
|
|
242
|
-
BuiltinFunction::StringCtor,
|
|
243
|
-
BuiltinFunction::ErrorCtor,
|
|
244
|
-
BuiltinFunction::TypeErrorCtor,
|
|
245
|
-
BuiltinFunction::ReferenceErrorCtor,
|
|
246
|
-
BuiltinFunction::RangeErrorCtor,
|
|
247
|
-
BuiltinFunction::SyntaxErrorCtor,
|
|
248
|
-
BuiltinFunction::NumberCtor,
|
|
249
|
-
BuiltinFunction::BooleanCtor,
|
|
250
|
-
BuiltinFunction::IntlDateTimeFormatCtor,
|
|
251
|
-
BuiltinFunction::IntlNumberFormatCtor,
|
|
252
|
-
] {
|
|
253
|
-
self.register_builtin_prototype(function)?;
|
|
254
|
-
}
|
|
255
|
-
self.define_global(
|
|
256
|
-
"globalThis".to_string(),
|
|
257
|
-
Value::Object(global_object),
|
|
258
|
-
false,
|
|
259
|
-
)?;
|
|
260
|
-
self.define_global(
|
|
261
|
-
"Object".to_string(),
|
|
262
|
-
Value::BuiltinFunction(BuiltinFunction::ObjectCtor),
|
|
263
|
-
false,
|
|
264
|
-
)?;
|
|
265
|
-
self.define_global(
|
|
266
|
-
"Map".to_string(),
|
|
267
|
-
Value::BuiltinFunction(BuiltinFunction::MapCtor),
|
|
268
|
-
false,
|
|
269
|
-
)?;
|
|
270
|
-
self.define_global(
|
|
271
|
-
"Set".to_string(),
|
|
272
|
-
Value::BuiltinFunction(BuiltinFunction::SetCtor),
|
|
273
|
-
false,
|
|
274
|
-
)?;
|
|
275
|
-
self.define_global(
|
|
276
|
-
"Array".to_string(),
|
|
277
|
-
Value::BuiltinFunction(BuiltinFunction::ArrayCtor),
|
|
278
|
-
false,
|
|
279
|
-
)?;
|
|
280
|
-
self.define_global(
|
|
281
|
-
"Date".to_string(),
|
|
282
|
-
Value::BuiltinFunction(BuiltinFunction::DateCtor),
|
|
283
|
-
false,
|
|
284
|
-
)?;
|
|
285
|
-
self.define_global(
|
|
286
|
-
"Promise".to_string(),
|
|
287
|
-
Value::BuiltinFunction(BuiltinFunction::PromiseCtor),
|
|
288
|
-
false,
|
|
289
|
-
)?;
|
|
290
|
-
self.define_global(
|
|
291
|
-
"RegExp".to_string(),
|
|
292
|
-
Value::BuiltinFunction(BuiltinFunction::RegExpCtor),
|
|
293
|
-
false,
|
|
294
|
-
)?;
|
|
295
|
-
self.define_global(
|
|
296
|
-
"String".to_string(),
|
|
297
|
-
Value::BuiltinFunction(BuiltinFunction::StringCtor),
|
|
298
|
-
false,
|
|
299
|
-
)?;
|
|
300
|
-
self.define_global(
|
|
301
|
-
"Error".to_string(),
|
|
302
|
-
Value::BuiltinFunction(BuiltinFunction::ErrorCtor),
|
|
303
|
-
false,
|
|
304
|
-
)?;
|
|
305
|
-
self.define_global(
|
|
306
|
-
"TypeError".to_string(),
|
|
307
|
-
Value::BuiltinFunction(BuiltinFunction::TypeErrorCtor),
|
|
308
|
-
false,
|
|
309
|
-
)?;
|
|
310
|
-
self.define_global(
|
|
311
|
-
"ReferenceError".to_string(),
|
|
312
|
-
Value::BuiltinFunction(BuiltinFunction::ReferenceErrorCtor),
|
|
313
|
-
false,
|
|
314
|
-
)?;
|
|
315
|
-
self.define_global(
|
|
316
|
-
"RangeError".to_string(),
|
|
317
|
-
Value::BuiltinFunction(BuiltinFunction::RangeErrorCtor),
|
|
318
|
-
false,
|
|
319
|
-
)?;
|
|
320
|
-
self.define_global(
|
|
321
|
-
"SyntaxError".to_string(),
|
|
322
|
-
Value::BuiltinFunction(BuiltinFunction::SyntaxErrorCtor),
|
|
323
|
-
false,
|
|
324
|
-
)?;
|
|
325
|
-
self.define_global(
|
|
326
|
-
"Number".to_string(),
|
|
327
|
-
Value::BuiltinFunction(BuiltinFunction::NumberCtor),
|
|
328
|
-
false,
|
|
329
|
-
)?;
|
|
330
|
-
self.define_global("NaN".to_string(), Value::Number(f64::NAN), false)?;
|
|
331
|
-
self.define_global("Infinity".to_string(), Value::Number(f64::INFINITY), false)?;
|
|
332
|
-
self.define_global(
|
|
333
|
-
"parseInt".to_string(),
|
|
334
|
-
Value::BuiltinFunction(BuiltinFunction::NumberParseInt),
|
|
335
|
-
false,
|
|
336
|
-
)?;
|
|
337
|
-
self.define_global(
|
|
338
|
-
"parseFloat".to_string(),
|
|
339
|
-
Value::BuiltinFunction(BuiltinFunction::NumberParseFloat),
|
|
340
|
-
false,
|
|
341
|
-
)?;
|
|
342
|
-
self.define_global(
|
|
343
|
-
"isNaN".to_string(),
|
|
344
|
-
Value::BuiltinFunction(BuiltinFunction::NumberIsNaN),
|
|
345
|
-
false,
|
|
346
|
-
)?;
|
|
347
|
-
self.define_global(
|
|
348
|
-
"isFinite".to_string(),
|
|
349
|
-
Value::BuiltinFunction(BuiltinFunction::NumberIsFinite),
|
|
350
|
-
false,
|
|
351
|
-
)?;
|
|
352
|
-
self.define_global(
|
|
353
|
-
"Boolean".to_string(),
|
|
354
|
-
Value::BuiltinFunction(BuiltinFunction::BooleanCtor),
|
|
355
|
-
false,
|
|
356
|
-
)?;
|
|
357
|
-
let intl = self.insert_object(
|
|
358
|
-
IndexMap::from([
|
|
359
|
-
(
|
|
360
|
-
"DateTimeFormat".to_string(),
|
|
361
|
-
Value::BuiltinFunction(BuiltinFunction::IntlDateTimeFormatCtor),
|
|
362
|
-
),
|
|
363
|
-
(
|
|
364
|
-
"NumberFormat".to_string(),
|
|
365
|
-
Value::BuiltinFunction(BuiltinFunction::IntlNumberFormatCtor),
|
|
366
|
-
),
|
|
367
|
-
]),
|
|
368
|
-
ObjectKind::Intl,
|
|
369
|
-
)?;
|
|
370
|
-
self.define_global("Intl".to_string(), Value::Object(intl), false)?;
|
|
371
|
-
|
|
372
|
-
let math = self.insert_object(
|
|
373
|
-
IndexMap::from([
|
|
374
|
-
("E".to_string(), Value::Number(std::f64::consts::E)),
|
|
375
|
-
("LN2".to_string(), Value::Number(std::f64::consts::LN_2)),
|
|
376
|
-
("LN10".to_string(), Value::Number(std::f64::consts::LN_10)),
|
|
377
|
-
("LOG2E".to_string(), Value::Number(std::f64::consts::LOG2_E)),
|
|
378
|
-
(
|
|
379
|
-
"LOG10E".to_string(),
|
|
380
|
-
Value::Number(std::f64::consts::LOG10_E),
|
|
381
|
-
),
|
|
382
|
-
("PI".to_string(), Value::Number(std::f64::consts::PI)),
|
|
383
|
-
("SQRT2".to_string(), Value::Number(std::f64::consts::SQRT_2)),
|
|
384
|
-
(
|
|
385
|
-
"SQRT1_2".to_string(),
|
|
386
|
-
Value::Number(std::f64::consts::FRAC_1_SQRT_2),
|
|
387
|
-
),
|
|
388
|
-
(
|
|
389
|
-
"abs".to_string(),
|
|
390
|
-
Value::BuiltinFunction(BuiltinFunction::MathAbs),
|
|
391
|
-
),
|
|
392
|
-
(
|
|
393
|
-
"max".to_string(),
|
|
394
|
-
Value::BuiltinFunction(BuiltinFunction::MathMax),
|
|
395
|
-
),
|
|
396
|
-
(
|
|
397
|
-
"min".to_string(),
|
|
398
|
-
Value::BuiltinFunction(BuiltinFunction::MathMin),
|
|
399
|
-
),
|
|
400
|
-
(
|
|
401
|
-
"floor".to_string(),
|
|
402
|
-
Value::BuiltinFunction(BuiltinFunction::MathFloor),
|
|
403
|
-
),
|
|
404
|
-
(
|
|
405
|
-
"ceil".to_string(),
|
|
406
|
-
Value::BuiltinFunction(BuiltinFunction::MathCeil),
|
|
407
|
-
),
|
|
408
|
-
(
|
|
409
|
-
"round".to_string(),
|
|
410
|
-
Value::BuiltinFunction(BuiltinFunction::MathRound),
|
|
411
|
-
),
|
|
412
|
-
(
|
|
413
|
-
"pow".to_string(),
|
|
414
|
-
Value::BuiltinFunction(BuiltinFunction::MathPow),
|
|
415
|
-
),
|
|
416
|
-
(
|
|
417
|
-
"sqrt".to_string(),
|
|
418
|
-
Value::BuiltinFunction(BuiltinFunction::MathSqrt),
|
|
419
|
-
),
|
|
420
|
-
(
|
|
421
|
-
"trunc".to_string(),
|
|
422
|
-
Value::BuiltinFunction(BuiltinFunction::MathTrunc),
|
|
423
|
-
),
|
|
424
|
-
(
|
|
425
|
-
"sign".to_string(),
|
|
426
|
-
Value::BuiltinFunction(BuiltinFunction::MathSign),
|
|
427
|
-
),
|
|
428
|
-
(
|
|
429
|
-
"log".to_string(),
|
|
430
|
-
Value::BuiltinFunction(BuiltinFunction::MathLog),
|
|
431
|
-
),
|
|
432
|
-
(
|
|
433
|
-
"exp".to_string(),
|
|
434
|
-
Value::BuiltinFunction(BuiltinFunction::MathExp),
|
|
435
|
-
),
|
|
436
|
-
(
|
|
437
|
-
"log2".to_string(),
|
|
438
|
-
Value::BuiltinFunction(BuiltinFunction::MathLog2),
|
|
439
|
-
),
|
|
440
|
-
(
|
|
441
|
-
"log10".to_string(),
|
|
442
|
-
Value::BuiltinFunction(BuiltinFunction::MathLog10),
|
|
443
|
-
),
|
|
444
|
-
(
|
|
445
|
-
"sin".to_string(),
|
|
446
|
-
Value::BuiltinFunction(BuiltinFunction::MathSin),
|
|
447
|
-
),
|
|
448
|
-
(
|
|
449
|
-
"cos".to_string(),
|
|
450
|
-
Value::BuiltinFunction(BuiltinFunction::MathCos),
|
|
451
|
-
),
|
|
452
|
-
(
|
|
453
|
-
"atan2".to_string(),
|
|
454
|
-
Value::BuiltinFunction(BuiltinFunction::MathAtan2),
|
|
455
|
-
),
|
|
456
|
-
(
|
|
457
|
-
"hypot".to_string(),
|
|
458
|
-
Value::BuiltinFunction(BuiltinFunction::MathHypot),
|
|
459
|
-
),
|
|
460
|
-
(
|
|
461
|
-
"cbrt".to_string(),
|
|
462
|
-
Value::BuiltinFunction(BuiltinFunction::MathCbrt),
|
|
463
|
-
),
|
|
464
|
-
(
|
|
465
|
-
"random".to_string(),
|
|
466
|
-
Value::BuiltinFunction(BuiltinFunction::MathRandom),
|
|
467
|
-
),
|
|
468
|
-
]),
|
|
469
|
-
ObjectKind::Math,
|
|
470
|
-
)?;
|
|
471
|
-
self.define_global("Math".to_string(), Value::Object(math), false)?;
|
|
472
|
-
|
|
473
|
-
let json = self.insert_object(
|
|
474
|
-
IndexMap::from([
|
|
475
|
-
(
|
|
476
|
-
"stringify".to_string(),
|
|
477
|
-
Value::BuiltinFunction(BuiltinFunction::JsonStringify),
|
|
478
|
-
),
|
|
479
|
-
(
|
|
480
|
-
"parse".to_string(),
|
|
481
|
-
Value::BuiltinFunction(BuiltinFunction::JsonParse),
|
|
482
|
-
),
|
|
483
|
-
]),
|
|
484
|
-
ObjectKind::Json,
|
|
485
|
-
)?;
|
|
486
|
-
self.define_global("JSON".to_string(), Value::Object(json), false)?;
|
|
487
|
-
|
|
488
|
-
let console = self.insert_object(IndexMap::new(), ObjectKind::Console)?;
|
|
489
|
-
self.define_global("console".to_string(), Value::Object(console), false)?;
|
|
490
|
-
Ok(())
|
|
491
|
-
}
|
|
492
|
-
|
|
493
|
-
fn register_builtin_prototype(&mut self, function: BuiltinFunction) -> MustardResult<()> {
|
|
494
|
-
let prototype = self.insert_object(
|
|
495
|
-
IndexMap::new(),
|
|
496
|
-
ObjectKind::FunctionPrototype(Value::BuiltinFunction(function)),
|
|
497
|
-
)?;
|
|
498
|
-
self.builtin_prototypes.insert(function, prototype);
|
|
499
|
-
Ok(())
|
|
500
|
-
}
|
|
501
|
-
}
|