mini_racer_rs 1.3.0 → 1.4.0
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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +9 -0
- data/COMPATIBILITY.md +9 -0
- data/Cargo.lock +5 -5
- data/Cargo.toml +1 -1
- data/README.md +42 -0
- data/crates/mini_racer_engine/src/context.rs +44 -16
- data/crates/mini_racer_engine/src/control.rs +70 -1
- data/crates/mini_racer_engine/src/error.rs +40 -0
- data/crates/mini_racer_engine/src/lib.rs +3 -2
- data/crates/mini_racer_engine/src/process/platform.rs +360 -2
- data/crates/mini_racer_engine/src/process/watchdog.rs +63 -14
- data/crates/mini_racer_engine/src/runner.rs +274 -50
- data/crates/mini_racer_engine/src/sys.rs +26 -0
- data/crates/mini_racer_sourcemap/src/map.rs +3 -2
- data/crates/mini_racer_sync/src/termination.rs +182 -44
- data/ext/mini_racer_rs/src/context.rs +41 -23
- data/ext/mini_racer_rs/src/errors.rs +21 -6
- data/ext/mini_racer_rs/src/gc_root.rs +31 -1
- data/ext/mini_racer_rs/src/heap_limit.rs +42 -0
- data/ext/mini_racer_rs/src/lib.rs +6 -0
- data/ext/mini_racer_rs/src/options.rs +89 -7
- data/ext/mini_racer_rs/src/pool.rs +811 -0
- data/ext/mini_racer_rs/src/rb_raw.rs +186 -1
- data/ext/mini_racer_rs/src/timeout.rs +132 -0
- data/lib/mini_racer_rs/heap_limit_error.rb +7 -0
- data/lib/mini_racer_rs/version.rb +1 -1
- data/lib/mini_racer_rs.rb +1 -0
- metadata +5 -1
|
@@ -65,6 +65,16 @@ fn within(
|
|
|
65
65
|
}
|
|
66
66
|
}
|
|
67
67
|
|
|
68
|
+
/// Milliseconds as `timeout:` takes them: an Integer up to 2**31 - 1, where 0
|
|
69
|
+
/// means no timeout. `MiniRacerRs.timeout` takes the same.
|
|
70
|
+
pub fn timeout(value: &OptionValue) -> Result<Option<Duration>, OptionError> {
|
|
71
|
+
let ms = within(value, "timeout", 0..=INT32_MAX)?;
|
|
72
|
+
Ok(u64::try_from(ms)
|
|
73
|
+
.ok()
|
|
74
|
+
.filter(|ms| *ms > 0)
|
|
75
|
+
.map(Duration::from_millis))
|
|
76
|
+
}
|
|
77
|
+
|
|
68
78
|
/// `Context.new` keywords in the order given; `mini_racer` 0.22.1 checks them
|
|
69
79
|
/// last to first and raises on the first bad one.
|
|
70
80
|
pub fn configure(
|
|
@@ -74,13 +84,7 @@ pub fn configure(
|
|
|
74
84
|
let mut refused = None;
|
|
75
85
|
for (key, value) in options.rev() {
|
|
76
86
|
match key.as_str() {
|
|
77
|
-
"timeout" =>
|
|
78
|
-
let ms = within(&value, "timeout", 0..=INT32_MAX)?;
|
|
79
|
-
config.timeout = u64::try_from(ms)
|
|
80
|
-
.ok()
|
|
81
|
-
.filter(|ms| *ms > 0)
|
|
82
|
-
.map(Duration::from_millis);
|
|
83
|
-
}
|
|
87
|
+
"timeout" => config.timeout = timeout(&value)?,
|
|
84
88
|
"marshal_stack_depth" => {
|
|
85
89
|
fixnum(&value)?;
|
|
86
90
|
}
|
|
@@ -117,10 +121,88 @@ pub fn configure(
|
|
|
117
121
|
})
|
|
118
122
|
}
|
|
119
123
|
|
|
124
|
+
/// The most contexts one `MiniRacerRs::Pool` holds. A pool builds every
|
|
125
|
+
/// context before `new` returns, each an isolate and a runner thread, so a
|
|
126
|
+
/// size near what `timeout:` allows would exhaust the process instead.
|
|
127
|
+
pub const MAX_POOL_SIZE: i64 = 1024;
|
|
128
|
+
|
|
129
|
+
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
|
130
|
+
pub struct PoolLimits {
|
|
131
|
+
pub size: usize,
|
|
132
|
+
pub max_uses: Option<u64>,
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
/// `MiniRacerRs::Pool.new`'s `size:` and `max_uses:` (nil for no limit),
|
|
136
|
+
/// checked as `Context.new` checks its integers.
|
|
137
|
+
pub fn pool(size: &OptionValue, max_uses: &OptionValue) -> Result<PoolLimits, OptionError> {
|
|
138
|
+
let size = within(size, "size", 1..=MAX_POOL_SIZE)?;
|
|
139
|
+
let max_uses = match max_uses {
|
|
140
|
+
OptionValue::Nil => None,
|
|
141
|
+
other => Some(within(other, "max_uses", 1..)?),
|
|
142
|
+
};
|
|
143
|
+
Ok(PoolLimits {
|
|
144
|
+
size: usize::try_from(size).map_err(|_| OptionError::Range("size"))?,
|
|
145
|
+
max_uses: max_uses
|
|
146
|
+
.map(u64::try_from)
|
|
147
|
+
.transpose()
|
|
148
|
+
.map_err(|_| OptionError::Range("max_uses"))?,
|
|
149
|
+
})
|
|
150
|
+
}
|
|
151
|
+
|
|
120
152
|
#[cfg(test)]
|
|
121
153
|
mod tests {
|
|
122
154
|
use super::*;
|
|
123
155
|
|
|
156
|
+
#[test]
|
|
157
|
+
fn a_pool_takes_one_to_max_contexts_and_any_positive_use_limit() {
|
|
158
|
+
let limits = pool(&OptionValue::Fixnum(4), &OptionValue::Nil);
|
|
159
|
+
assert_eq!(
|
|
160
|
+
limits,
|
|
161
|
+
Ok(PoolLimits {
|
|
162
|
+
size: 4,
|
|
163
|
+
max_uses: None
|
|
164
|
+
})
|
|
165
|
+
);
|
|
166
|
+
let limits = pool(
|
|
167
|
+
&OptionValue::Fixnum(MAX_POOL_SIZE),
|
|
168
|
+
&OptionValue::Fixnum(i64::MAX),
|
|
169
|
+
);
|
|
170
|
+
assert_eq!(
|
|
171
|
+
limits.map(|limits| (limits.size, limits.max_uses)),
|
|
172
|
+
Ok((1024, Some(i64::MAX.cast_unsigned())))
|
|
173
|
+
);
|
|
174
|
+
for size in [0, -1, MAX_POOL_SIZE + 1] {
|
|
175
|
+
assert_eq!(
|
|
176
|
+
pool(&OptionValue::Fixnum(size), &OptionValue::Nil),
|
|
177
|
+
Err(OptionError::Range("size"))
|
|
178
|
+
);
|
|
179
|
+
}
|
|
180
|
+
assert_eq!(
|
|
181
|
+
pool(&OptionValue::Fixnum(1), &OptionValue::Fixnum(0))
|
|
182
|
+
.map_err(|error| error.to_string()),
|
|
183
|
+
Err("bad max_uses".to_owned())
|
|
184
|
+
);
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
#[test]
|
|
188
|
+
fn a_pool_names_a_value_of_the_wrong_type_as_context_new_does() {
|
|
189
|
+
assert_eq!(
|
|
190
|
+
pool(&OptionValue::Nil, &OptionValue::Nil).map_err(|error| error.to_string()),
|
|
191
|
+
Err("wrong argument type nil (expected Integer)".to_owned())
|
|
192
|
+
);
|
|
193
|
+
assert_eq!(
|
|
194
|
+
pool(&OptionValue::Fixnum(2), &OptionValue::False).map_err(|error| error.to_string()),
|
|
195
|
+
Err("wrong argument type false (expected Integer)".to_owned())
|
|
196
|
+
);
|
|
197
|
+
assert_eq!(
|
|
198
|
+
pool(
|
|
199
|
+
&OptionValue::Other("String".to_owned()),
|
|
200
|
+
&OptionValue::Other("Float".to_owned())
|
|
201
|
+
),
|
|
202
|
+
Err(OptionError::Type("String".to_owned()))
|
|
203
|
+
);
|
|
204
|
+
}
|
|
205
|
+
|
|
124
206
|
fn configure_pairs(pairs: &[(&str, OptionValue)]) -> Result<ContextConfig, OptionError> {
|
|
125
207
|
configure(
|
|
126
208
|
pairs
|