mustardscript 0.1.0 → 0.1.2
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 +65 -22
- 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,104 +0,0 @@
|
|
|
1
|
-
use super::*;
|
|
2
|
-
|
|
3
|
-
#[test]
|
|
4
|
-
fn suspends_and_resumes_host_capability_calls() {
|
|
5
|
-
let suspension = suspend(
|
|
6
|
-
r#"
|
|
7
|
-
const value = fetch_data(41);
|
|
8
|
-
value + 1;
|
|
9
|
-
"#,
|
|
10
|
-
&["fetch_data"],
|
|
11
|
-
);
|
|
12
|
-
assert_eq!(suspension.capability, "fetch_data");
|
|
13
|
-
assert_eq!(
|
|
14
|
-
suspension.args,
|
|
15
|
-
vec![number(41.0)]
|
|
16
|
-
);
|
|
17
|
-
|
|
18
|
-
let resumed = resume(
|
|
19
|
-
suspension.snapshot,
|
|
20
|
-
ResumePayload::Value(number(41.0)),
|
|
21
|
-
)
|
|
22
|
-
.expect("resume should succeed");
|
|
23
|
-
|
|
24
|
-
match resumed {
|
|
25
|
-
ExecutionStep::Completed(value) => {
|
|
26
|
-
assert_eq!(value, number(42.0));
|
|
27
|
-
}
|
|
28
|
-
other => panic!("expected completion, got {other:?}"),
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
#[test]
|
|
33
|
-
fn console_callbacks_resume_with_undefined_guest_results() {
|
|
34
|
-
let suspension = suspend(
|
|
35
|
-
r#"
|
|
36
|
-
const logged = console.log(41);
|
|
37
|
-
logged === undefined ? 2 : 0;
|
|
38
|
-
"#,
|
|
39
|
-
&["console.log"],
|
|
40
|
-
);
|
|
41
|
-
assert_eq!(suspension.capability, "console.log");
|
|
42
|
-
assert_eq!(
|
|
43
|
-
suspension.args,
|
|
44
|
-
vec![number(41.0)]
|
|
45
|
-
);
|
|
46
|
-
|
|
47
|
-
let resumed = resume(
|
|
48
|
-
suspension.snapshot,
|
|
49
|
-
ResumePayload::Value(StructuredValue::String("ignored".to_string())),
|
|
50
|
-
)
|
|
51
|
-
.expect("resume should ignore host return values for console callbacks");
|
|
52
|
-
|
|
53
|
-
match resumed {
|
|
54
|
-
ExecutionStep::Completed(value) => {
|
|
55
|
-
assert_eq!(value, number(2.0));
|
|
56
|
-
}
|
|
57
|
-
other => panic!("expected completion, got {other:?}"),
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
#[test]
|
|
62
|
-
fn catches_host_errors_after_resume() {
|
|
63
|
-
let suspension = suspend(
|
|
64
|
-
r#"
|
|
65
|
-
let captured;
|
|
66
|
-
try {
|
|
67
|
-
fetch_data(1);
|
|
68
|
-
} catch (error) {
|
|
69
|
-
captured = [error.name, error.message, error.code, error.details.status];
|
|
70
|
-
}
|
|
71
|
-
captured;
|
|
72
|
-
"#,
|
|
73
|
-
&["fetch_data"],
|
|
74
|
-
);
|
|
75
|
-
|
|
76
|
-
let resumed = resume(
|
|
77
|
-
suspension.snapshot,
|
|
78
|
-
ResumePayload::Error(HostError {
|
|
79
|
-
name: "CapabilityError".to_string(),
|
|
80
|
-
message: "upstream failed".to_string(),
|
|
81
|
-
code: Some("E_UPSTREAM".to_string()),
|
|
82
|
-
details: Some(StructuredValue::Object(IndexMap::from([(
|
|
83
|
-
"status".to_string(),
|
|
84
|
-
number(503.0),
|
|
85
|
-
)]))),
|
|
86
|
-
}),
|
|
87
|
-
)
|
|
88
|
-
.expect("guest catch should handle resumed host errors");
|
|
89
|
-
|
|
90
|
-
match resumed {
|
|
91
|
-
ExecutionStep::Completed(value) => {
|
|
92
|
-
assert_eq!(
|
|
93
|
-
value,
|
|
94
|
-
StructuredValue::Array(vec![
|
|
95
|
-
StructuredValue::String("CapabilityError".to_string()),
|
|
96
|
-
StructuredValue::String("upstream failed".to_string()),
|
|
97
|
-
StructuredValue::String("E_UPSTREAM".to_string()),
|
|
98
|
-
number(503.0),
|
|
99
|
-
])
|
|
100
|
-
);
|
|
101
|
-
}
|
|
102
|
-
other => panic!("expected completion, got {other:?}"),
|
|
103
|
-
}
|
|
104
|
-
}
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
use super::*;
|
|
2
|
-
|
|
3
|
-
#[test]
|
|
4
|
-
fn maps_preserve_insertion_order_and_same_value_zero_updates() {
|
|
5
|
-
let program = lower_to_bytecode(&compile("0;").expect("source should compile"))
|
|
6
|
-
.expect("lowering should succeed");
|
|
7
|
-
let mut runtime = Runtime::new(program, ExecutionOptions::default()).expect("runtime init");
|
|
8
|
-
let map = runtime.insert_map(Vec::new()).expect("map should allocate");
|
|
9
|
-
let object = runtime
|
|
10
|
-
.insert_object(IndexMap::new(), ObjectKind::Plain)
|
|
11
|
-
.expect("object should allocate");
|
|
12
|
-
|
|
13
|
-
runtime
|
|
14
|
-
.map_set(map, Value::String("alpha".to_string()), Value::Number(1.0))
|
|
15
|
-
.expect("alpha insert should succeed");
|
|
16
|
-
runtime
|
|
17
|
-
.map_set(
|
|
18
|
-
map,
|
|
19
|
-
Value::Number(f64::NAN),
|
|
20
|
-
Value::String("nan".to_string()),
|
|
21
|
-
)
|
|
22
|
-
.expect("nan insert should succeed");
|
|
23
|
-
runtime
|
|
24
|
-
.map_set(map, Value::Number(-0.0), Value::String("zero".to_string()))
|
|
25
|
-
.expect("negative zero insert should succeed");
|
|
26
|
-
runtime
|
|
27
|
-
.map_set(map, Value::Object(object), Value::Bool(true))
|
|
28
|
-
.expect("object key insert should succeed");
|
|
29
|
-
runtime
|
|
30
|
-
.map_set(map, Value::String("alpha".to_string()), Value::Number(2.0))
|
|
31
|
-
.expect("alpha update should keep insertion order");
|
|
32
|
-
runtime
|
|
33
|
-
.map_set(
|
|
34
|
-
map,
|
|
35
|
-
Value::Number(0.0),
|
|
36
|
-
Value::String("zero-updated".to_string()),
|
|
37
|
-
)
|
|
38
|
-
.expect("positive zero update should reuse the existing entry");
|
|
39
|
-
|
|
40
|
-
let entries = &runtime.maps.get(map).expect("map should exist").entries;
|
|
41
|
-
assert_eq!(entries.len(), 4);
|
|
42
|
-
assert!(matches!(entries[0].key, Value::String(ref value) if value == "alpha"));
|
|
43
|
-
assert!(matches!(entries[0].value, Value::Number(value) if value == 2.0));
|
|
44
|
-
assert!(matches!(entries[1].key, Value::Number(value) if value.is_nan()));
|
|
45
|
-
assert!(matches!(entries[1].value, Value::String(ref value) if value == "nan"));
|
|
46
|
-
assert!(matches!(entries[2].key, Value::Number(value) if value == 0.0));
|
|
47
|
-
assert!(matches!(entries[2].value, Value::String(ref value) if value == "zero-updated"));
|
|
48
|
-
assert!(matches!(entries[3].key, Value::Object(key) if key == object));
|
|
49
|
-
assert!(matches!(entries[3].value, Value::Bool(true)));
|
|
50
|
-
}
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
use super::*;
|
|
2
|
-
|
|
3
|
-
#[test]
|
|
4
|
-
fn lowering_errors_preserve_source_spans() {
|
|
5
|
-
let program = compile("continue;").expect("source should compile");
|
|
6
|
-
let error =
|
|
7
|
-
lower_to_bytecode(&program).expect_err("continue outside a loop should fail lowering");
|
|
8
|
-
let rendered = error.to_string();
|
|
9
|
-
assert!(rendered.contains("`continue` used outside of a loop"));
|
|
10
|
-
assert!(rendered.contains("[0..9]"));
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
#[test]
|
|
14
|
-
fn runtime_errors_include_guest_tracebacks() {
|
|
15
|
-
let program = compile(
|
|
16
|
-
r#"
|
|
17
|
-
function outer() {
|
|
18
|
-
return inner();
|
|
19
|
-
}
|
|
20
|
-
function inner() {
|
|
21
|
-
const value = null;
|
|
22
|
-
return value.answer;
|
|
23
|
-
}
|
|
24
|
-
outer();
|
|
25
|
-
"#,
|
|
26
|
-
)
|
|
27
|
-
.expect("source should compile");
|
|
28
|
-
let error = execute(&program, ExecutionOptions::default())
|
|
29
|
-
.expect_err("nullish property access should fail");
|
|
30
|
-
let rendered = error.to_string();
|
|
31
|
-
assert!(rendered.contains("TypeError: cannot read properties of nullish value"));
|
|
32
|
-
assert!(rendered.contains("at inner ["));
|
|
33
|
-
assert!(rendered.contains("at outer ["));
|
|
34
|
-
assert!(rendered.contains("at <script> ["));
|
|
35
|
-
assert!(!rendered.contains(".rs"));
|
|
36
|
-
}
|
|
@@ -1,122 +0,0 @@
|
|
|
1
|
-
use super::*;
|
|
2
|
-
|
|
3
|
-
#[test]
|
|
4
|
-
fn runs_throw_try_catch_and_finally() {
|
|
5
|
-
let value = run(r#"
|
|
6
|
-
let log = [];
|
|
7
|
-
try {
|
|
8
|
-
log[log.length] = "body";
|
|
9
|
-
throw new Error("boom");
|
|
10
|
-
} catch (error) {
|
|
11
|
-
log[log.length] = error.name;
|
|
12
|
-
log[log.length] = error.message;
|
|
13
|
-
} finally {
|
|
14
|
-
log[log.length] = "finally";
|
|
15
|
-
}
|
|
16
|
-
log;
|
|
17
|
-
"#);
|
|
18
|
-
assert_eq!(
|
|
19
|
-
value,
|
|
20
|
-
StructuredValue::Array(vec![
|
|
21
|
-
StructuredValue::String("body".to_string()),
|
|
22
|
-
StructuredValue::String("Error".to_string()),
|
|
23
|
-
StructuredValue::String("boom".to_string()),
|
|
24
|
-
StructuredValue::String("finally".to_string()),
|
|
25
|
-
])
|
|
26
|
-
);
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
#[test]
|
|
30
|
-
fn catches_runtime_type_errors_as_guest_errors() {
|
|
31
|
-
let value = run(r#"
|
|
32
|
-
let captured;
|
|
33
|
-
try {
|
|
34
|
-
const value = null;
|
|
35
|
-
value.answer;
|
|
36
|
-
} catch (error) {
|
|
37
|
-
captured = [error.name, error.message];
|
|
38
|
-
}
|
|
39
|
-
captured;
|
|
40
|
-
"#);
|
|
41
|
-
assert_eq!(
|
|
42
|
-
value,
|
|
43
|
-
StructuredValue::Array(vec![
|
|
44
|
-
StructuredValue::String("TypeError".to_string()),
|
|
45
|
-
StructuredValue::String("cannot read properties of nullish value".to_string()),
|
|
46
|
-
])
|
|
47
|
-
);
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
#[test]
|
|
51
|
-
fn finally_runs_for_return_break_and_continue() {
|
|
52
|
-
let value = run(r#"
|
|
53
|
-
let events = [];
|
|
54
|
-
function earlyReturn() {
|
|
55
|
-
try {
|
|
56
|
-
return "body";
|
|
57
|
-
} finally {
|
|
58
|
-
events[events.length] = "return";
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
let index = 0;
|
|
62
|
-
while (index < 2) {
|
|
63
|
-
index += 1;
|
|
64
|
-
try {
|
|
65
|
-
if (index === 1) {
|
|
66
|
-
continue;
|
|
67
|
-
}
|
|
68
|
-
break;
|
|
69
|
-
} finally {
|
|
70
|
-
events[events.length] = index;
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
[earlyReturn(), events];
|
|
74
|
-
"#);
|
|
75
|
-
assert_eq!(
|
|
76
|
-
value,
|
|
77
|
-
StructuredValue::Array(vec![
|
|
78
|
-
StructuredValue::String("body".to_string()),
|
|
79
|
-
StructuredValue::Array(vec![
|
|
80
|
-
StructuredValue::Number(StructuredNumber::Finite(1.0)),
|
|
81
|
-
StructuredValue::Number(StructuredNumber::Finite(2.0)),
|
|
82
|
-
StructuredValue::String("return".to_string()),
|
|
83
|
-
]),
|
|
84
|
-
])
|
|
85
|
-
);
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
#[test]
|
|
89
|
-
fn nested_exception_unwind_preserves_finally_order() {
|
|
90
|
-
let value = run(r#"
|
|
91
|
-
let events = [];
|
|
92
|
-
function nested() {
|
|
93
|
-
try {
|
|
94
|
-
try {
|
|
95
|
-
events[events.length] = "inner-body";
|
|
96
|
-
throw new Error("boom");
|
|
97
|
-
} catch (error) {
|
|
98
|
-
events[events.length] = error.message;
|
|
99
|
-
throw new TypeError("wrapped");
|
|
100
|
-
} finally {
|
|
101
|
-
events[events.length] = "inner-finally";
|
|
102
|
-
}
|
|
103
|
-
} catch (error) {
|
|
104
|
-
events[events.length] = error.name;
|
|
105
|
-
} finally {
|
|
106
|
-
events[events.length] = "outer-finally";
|
|
107
|
-
}
|
|
108
|
-
return events;
|
|
109
|
-
}
|
|
110
|
-
nested();
|
|
111
|
-
"#);
|
|
112
|
-
assert_eq!(
|
|
113
|
-
value,
|
|
114
|
-
StructuredValue::Array(vec![
|
|
115
|
-
StructuredValue::String("inner-body".to_string()),
|
|
116
|
-
StructuredValue::String("boom".to_string()),
|
|
117
|
-
StructuredValue::String("inner-finally".to_string()),
|
|
118
|
-
StructuredValue::String("TypeError".to_string()),
|
|
119
|
-
StructuredValue::String("outer-finally".to_string()),
|
|
120
|
-
])
|
|
121
|
-
);
|
|
122
|
-
}
|