rusty_racer 0.2.8 → 0.2.9
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 +54 -0
- data/README.md +48 -1
- data/ext/rusty_racer/Cargo.toml +1 -1
- data/ext/rusty_racer/src/lib.rs +857 -201
- data/ext/rusty_racer/src/ops.rs +375 -14
- data/lib/rusty_racer/version.rb +1 -1
- data/lib/rusty_racer.rb +111 -19
- metadata +2 -2
data/ext/rusty_racer/src/ops.rs
CHANGED
|
@@ -148,6 +148,35 @@ pub(crate) enum Request {
|
|
|
148
148
|
// instead of V8's default lazy top-level-only compile. Ignored when
|
|
149
149
|
// cached_data is set (V8 forbids ConsumeCodeCache + EagerCompile).
|
|
150
150
|
eager: bool,
|
|
151
|
+
// A primitive its ScriptOrigin carries as host-defined options, which V8
|
|
152
|
+
// hands the dynamic-import hook of an import() it makes.
|
|
153
|
+
host_defined: Option<JsVal>,
|
|
154
|
+
},
|
|
155
|
+
// A synthetic module (v8::Module::CreateSyntheticModule) exporting
|
|
156
|
+
// `default` alone, of the value `export` makes, in the context.
|
|
157
|
+
CreateSyntheticModule {
|
|
158
|
+
context_id: i32,
|
|
159
|
+
filename: String,
|
|
160
|
+
export: SyntheticExport,
|
|
161
|
+
timeout_ms: u64,
|
|
162
|
+
},
|
|
163
|
+
// The module's script id (v8::Module::ScriptId): what a stack frame of its
|
|
164
|
+
// code names it by (StackFrame::GetScriptId); none for a synthetic module
|
|
165
|
+
// or an errored one.
|
|
166
|
+
ModuleScriptId {
|
|
167
|
+
module_id: i32,
|
|
168
|
+
},
|
|
169
|
+
// The module's requests (v8::Module::GetModuleRequests): each specifier and
|
|
170
|
+
// its import attributes, in source order.
|
|
171
|
+
ModuleRequests {
|
|
172
|
+
module_id: i32,
|
|
173
|
+
},
|
|
174
|
+
// Settle a waiting import() (ImportReg) with `settle`; replies whether it
|
|
175
|
+
// was still waiting.
|
|
176
|
+
SettleImport {
|
|
177
|
+
import_id: u64,
|
|
178
|
+
settle: Settle,
|
|
179
|
+
timeout_ms: u64,
|
|
151
180
|
},
|
|
152
181
|
// instantiate: V8 walks imports, calling back to the Ruby resolve block
|
|
153
182
|
// (parked in the slot for the op) per edge via resolve_imported.
|
|
@@ -185,6 +214,7 @@ pub(crate) enum Request {
|
|
|
185
214
|
cached_data: Option<Vec<u8>>,
|
|
186
215
|
produce_cache: bool,
|
|
187
216
|
eager: bool,
|
|
217
|
+
host_defined: Option<JsVal>,
|
|
188
218
|
},
|
|
189
219
|
// Bind the script to its context and run it; returns the completion value
|
|
190
220
|
// (unless |void| — see Eval).
|
|
@@ -201,6 +231,11 @@ pub(crate) enum Request {
|
|
|
201
231
|
ScriptCodeCache {
|
|
202
232
|
script_id: i32,
|
|
203
233
|
},
|
|
234
|
+
// The script's V8 script id (v8::UnboundScript::GetId): what a stack frame
|
|
235
|
+
// of its code names it by (StackFrame::GetScriptId).
|
|
236
|
+
UnboundScriptId {
|
|
237
|
+
script_id: i32,
|
|
238
|
+
},
|
|
204
239
|
ModuleCodeCache {
|
|
205
240
|
module_id: i32,
|
|
206
241
|
},
|
|
@@ -225,6 +260,25 @@ pub(crate) enum Request {
|
|
|
225
260
|
},
|
|
226
261
|
}
|
|
227
262
|
|
|
263
|
+
// What a synthetic module's default export is: a value marshalled from Ruby, the
|
|
264
|
+
// value %JSON.parse% makes of a JSON text (ECMA-262 ParseJSONModule), or what
|
|
265
|
+
// the function at a path (as Context#call names one) returns, called with args.
|
|
266
|
+
pub(crate) enum SyntheticExport {
|
|
267
|
+
Value(JsVal),
|
|
268
|
+
Json(String),
|
|
269
|
+
Call { path: String, args: Vec<JsVal> },
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
// How a waiting import() is settled: with a module (linked by the block
|
|
273
|
+
// DynamicImport#resolve parked, and evaluated), rejected with a value
|
|
274
|
+
// marshalled from Ruby, or rejected with what the function at a path returns
|
|
275
|
+
// (or throws), called with args.
|
|
276
|
+
pub(crate) enum Settle {
|
|
277
|
+
Module(i32),
|
|
278
|
+
Reject(JsVal),
|
|
279
|
+
RejectWith { path: String, args: Vec<JsVal> },
|
|
280
|
+
}
|
|
281
|
+
|
|
228
282
|
// compile_module result: the module's id plus any produced bytecode cache and
|
|
229
283
|
// whether a supplied cache was rejected.
|
|
230
284
|
pub(crate) struct Compiled {
|
|
@@ -274,7 +328,7 @@ pub(crate) fn run_source(
|
|
|
274
328
|
let Some(code) = v8::String::new(tc, source) else {
|
|
275
329
|
return Err(VmError::Parse("source too large".into(), None));
|
|
276
330
|
};
|
|
277
|
-
let origin = script_origin(tc, filename);
|
|
331
|
+
let origin = script_origin(tc, filename, None);
|
|
278
332
|
let script = match v8::Script::compile(tc, code, Some(&origin)) {
|
|
279
333
|
Some(script) => script,
|
|
280
334
|
None if tc.has_terminated() => return Err(VmError::Terminated),
|
|
@@ -464,7 +518,11 @@ fn request_realm(state: &IsolateState, request: &Request) -> Option<i32> {
|
|
|
464
518
|
| Request::Attach { context_id, .. }
|
|
465
519
|
| Request::AttachMany { context_id, .. }
|
|
466
520
|
| Request::CompileModule { context_id, .. }
|
|
521
|
+
| Request::CreateSyntheticModule { context_id, .. }
|
|
467
522
|
| Request::CompileScript { context_id, .. } => Some(*context_id),
|
|
523
|
+
Request::SettleImport { import_id, .. } => {
|
|
524
|
+
state.imports.by_id.get(import_id).map(|(_, cid)| *cid)
|
|
525
|
+
}
|
|
468
526
|
Request::DrainMicrotasks { .. } => Some(0),
|
|
469
527
|
Request::InstantiateModule { module_id, .. }
|
|
470
528
|
| Request::EvaluateModule { module_id, .. }
|
|
@@ -478,8 +536,11 @@ fn request_realm(state: &IsolateState, request: &Request) -> Option<i32> {
|
|
|
478
536
|
| Request::CreateContext
|
|
479
537
|
| Request::DisposeContext { .. }
|
|
480
538
|
| Request::ModuleStatus { .. }
|
|
539
|
+
| Request::ModuleRequests { .. }
|
|
540
|
+
| Request::ModuleScriptId { .. }
|
|
481
541
|
| Request::ModuleGraphAsync { .. }
|
|
482
542
|
| Request::ScriptCodeCache { .. }
|
|
543
|
+
| Request::UnboundScriptId { .. }
|
|
483
544
|
| Request::ModuleCodeCache { .. }
|
|
484
545
|
| Request::HeapStatistics
|
|
485
546
|
| Request::LowMemoryNotification
|
|
@@ -554,6 +615,7 @@ fn dispatch_one(
|
|
|
554
615
|
cached_data,
|
|
555
616
|
produce_cache,
|
|
556
617
|
eager,
|
|
618
|
+
host_defined,
|
|
557
619
|
} => op_compile_module(
|
|
558
620
|
scope,
|
|
559
621
|
context_id,
|
|
@@ -562,7 +624,21 @@ fn dispatch_one(
|
|
|
562
624
|
cached_data,
|
|
563
625
|
produce_cache,
|
|
564
626
|
eager,
|
|
627
|
+
host_defined,
|
|
565
628
|
),
|
|
629
|
+
Request::CreateSyntheticModule {
|
|
630
|
+
context_id,
|
|
631
|
+
filename,
|
|
632
|
+
export,
|
|
633
|
+
timeout_ms,
|
|
634
|
+
} => op_create_synthetic_module(scope, context_id, filename, export, timeout_ms, outermost),
|
|
635
|
+
Request::ModuleRequests { module_id } => op_module_requests(scope, module_id),
|
|
636
|
+
Request::ModuleScriptId { module_id } => op_module_script_id(scope, module_id),
|
|
637
|
+
Request::SettleImport {
|
|
638
|
+
import_id,
|
|
639
|
+
settle,
|
|
640
|
+
timeout_ms,
|
|
641
|
+
} => op_settle_import(scope, import_id, settle, timeout_ms, outermost),
|
|
566
642
|
Request::InstantiateModule { module_id } => op_instantiate_module(scope, module_id),
|
|
567
643
|
Request::EvaluateModule {
|
|
568
644
|
module_id,
|
|
@@ -579,6 +655,7 @@ fn dispatch_one(
|
|
|
579
655
|
cached_data,
|
|
580
656
|
produce_cache,
|
|
581
657
|
eager,
|
|
658
|
+
host_defined,
|
|
582
659
|
} => op_compile_script(
|
|
583
660
|
scope,
|
|
584
661
|
context_id,
|
|
@@ -587,6 +664,7 @@ fn dispatch_one(
|
|
|
587
664
|
cached_data,
|
|
588
665
|
produce_cache,
|
|
589
666
|
eager,
|
|
667
|
+
host_defined,
|
|
590
668
|
),
|
|
591
669
|
Request::RunScript {
|
|
592
670
|
script_id,
|
|
@@ -600,6 +678,7 @@ fn dispatch_one(
|
|
|
600
678
|
// can't serialize, or when the realm was reset/disposed out from under
|
|
601
679
|
// the script (its handle is gone): produce nil, not an error.
|
|
602
680
|
Request::ScriptCodeCache { script_id } => op_script_code_cache(scope, script_id),
|
|
681
|
+
Request::UnboundScriptId { script_id } => op_unbound_script_id(scope, script_id),
|
|
603
682
|
// Same, for a module: get_unbound_module_script gives the shared
|
|
604
683
|
// compiled script, which evaluate() fills with inner-function bytecode.
|
|
605
684
|
// It needs the module's context entered (unlike UnboundScript), so
|
|
@@ -812,6 +891,9 @@ fn forget_released_handles(scope: &mut v8::PinScope<'_, '_, ()>) {
|
|
|
812
891
|
Released::Script(id) => {
|
|
813
892
|
state.scripts.by_id.remove(&id);
|
|
814
893
|
}
|
|
894
|
+
Released::Import(id) => {
|
|
895
|
+
state.imports.by_id.remove(&id);
|
|
896
|
+
}
|
|
815
897
|
}
|
|
816
898
|
}
|
|
817
899
|
}
|
|
@@ -1079,6 +1161,7 @@ fn op_compile_module(
|
|
|
1079
1161
|
cached_data: Option<Vec<u8>>,
|
|
1080
1162
|
produce_cache: bool,
|
|
1081
1163
|
eager: bool,
|
|
1164
|
+
host_defined: Option<JsVal>,
|
|
1082
1165
|
) -> VmReply {
|
|
1083
1166
|
let ctx = context_for(istate!(scope), context_id);
|
|
1084
1167
|
let outcome = match ctx {
|
|
@@ -1090,7 +1173,8 @@ fn op_compile_module(
|
|
|
1090
1173
|
match v8::String::new(tc, &source) {
|
|
1091
1174
|
None => Err(VmError::Runtime("module source too large".into())),
|
|
1092
1175
|
Some(code) => {
|
|
1093
|
-
let
|
|
1176
|
+
let options = host_defined_options(tc, host_defined.as_ref());
|
|
1177
|
+
let origin = module_origin(tc, &filename, options);
|
|
1094
1178
|
// Consume a supplied bytecode cache (skip reparse),
|
|
1095
1179
|
// eager-compile every function, or compile fresh
|
|
1096
1180
|
// (lazy). cached_data wins: V8 forbids combining
|
|
@@ -1117,17 +1201,19 @@ fn op_compile_module(
|
|
|
1117
1201
|
} else {
|
|
1118
1202
|
None
|
|
1119
1203
|
};
|
|
1120
|
-
let
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1204
|
+
let host_defined = host_defined.map(|value| {
|
|
1205
|
+
let value = jsval_to_js(tc, value);
|
|
1206
|
+
v8::Global::new(tc, value)
|
|
1207
|
+
});
|
|
1208
|
+
let id = register_module(
|
|
1209
|
+
tc,
|
|
1210
|
+
module,
|
|
1211
|
+
context_id,
|
|
1212
|
+
ModuleOrigin {
|
|
1213
|
+
url: filename.clone(),
|
|
1214
|
+
host_defined,
|
|
1215
|
+
},
|
|
1216
|
+
);
|
|
1131
1217
|
Ok(Compiled {
|
|
1132
1218
|
id,
|
|
1133
1219
|
cached_data: produced,
|
|
@@ -1456,6 +1542,7 @@ fn op_compile_script(
|
|
|
1456
1542
|
cached_data: Option<Vec<u8>>,
|
|
1457
1543
|
produce_cache: bool,
|
|
1458
1544
|
eager: bool,
|
|
1545
|
+
host_defined: Option<JsVal>,
|
|
1459
1546
|
) -> VmReply {
|
|
1460
1547
|
let ctx = context_for(istate!(scope), context_id);
|
|
1461
1548
|
let outcome = match ctx {
|
|
@@ -1467,7 +1554,8 @@ fn op_compile_script(
|
|
|
1467
1554
|
match v8::String::new(tc, &source) {
|
|
1468
1555
|
None => Err(VmError::Runtime("script source too large".into())),
|
|
1469
1556
|
Some(code) => {
|
|
1470
|
-
let
|
|
1557
|
+
let options = host_defined_options(tc, host_defined.as_ref());
|
|
1558
|
+
let origin = script_origin(tc, &filename, options);
|
|
1471
1559
|
let (mut src, opts) = compile_source(code, &origin, &cached_data, eager);
|
|
1472
1560
|
match v8::script_compiler::compile_unbound_script(
|
|
1473
1561
|
tc,
|
|
@@ -1573,6 +1661,24 @@ fn op_script_code_cache(scope: &mut v8::PinScope<'_, '_, ()>, script_id: i32) ->
|
|
|
1573
1661
|
VmReply::CodeCache(outcome)
|
|
1574
1662
|
}
|
|
1575
1663
|
|
|
1664
|
+
// rusty_v8 doesn't wrap v8::UnboundScript::GetId, so link V8's exported member
|
|
1665
|
+
// function directly (`this` is the first argument), as stack.rs does its own.
|
|
1666
|
+
unsafe extern "C" {
|
|
1667
|
+
#[link_name = "_ZNK2v813UnboundScript5GetIdEv"]
|
|
1668
|
+
fn v8__UnboundScript__GetId(script: *const v8::UnboundScript) -> i32;
|
|
1669
|
+
}
|
|
1670
|
+
|
|
1671
|
+
// Script#script_id: the script's V8 script id. No context is entered: it reads
|
|
1672
|
+
// the unbound script.
|
|
1673
|
+
fn op_unbound_script_id(scope: &mut v8::PinScope<'_, '_, ()>, script_id: i32) -> VmReply {
|
|
1674
|
+
let Some((g, _)) = script_handle(istate!(scope), script_id) else {
|
|
1675
|
+
return VmReply::Done(Err(VmError::Runtime("unknown script".into())));
|
|
1676
|
+
};
|
|
1677
|
+
let unbound = v8::Local::new(scope, &g);
|
|
1678
|
+
let id = unsafe { v8__UnboundScript__GetId(&*unbound) };
|
|
1679
|
+
VmReply::Done(Ok(JsVal::Int(i64::from(id))))
|
|
1680
|
+
}
|
|
1681
|
+
|
|
1576
1682
|
fn op_module_code_cache(scope: &mut v8::PinScope<'_, '_, ()>, module_id: i32) -> VmReply {
|
|
1577
1683
|
let mh = module_handle(istate!(scope), module_id);
|
|
1578
1684
|
let handle = mh.and_then(|(g, cid)| context_for(istate!(scope), cid).map(|cx| (g, cx)));
|
|
@@ -1588,3 +1694,258 @@ fn op_module_code_cache(scope: &mut v8::PinScope<'_, '_, ()>, module_id: i32) ->
|
|
|
1588
1694
|
};
|
|
1589
1695
|
VmReply::CodeCache(outcome)
|
|
1590
1696
|
}
|
|
1697
|
+
|
|
1698
|
+
// Context#synthetic_module: a module exporting `default` alone (v8::Module::
|
|
1699
|
+
// CreateSyntheticModule — what HTML makes of a JSON, CSS or text module script),
|
|
1700
|
+
// filed as a compiled one is, under |filename|; its value made now — JSON
|
|
1701
|
+
// parsed (a JSON text that is none: a parse error, as a module's SyntaxError
|
|
1702
|
+
// is), a function called — and set as the module evaluates
|
|
1703
|
+
// (synthetic_evaluation_steps).
|
|
1704
|
+
fn op_create_synthetic_module(
|
|
1705
|
+
scope: &mut v8::PinScope<'_, '_, ()>,
|
|
1706
|
+
context_id: i32,
|
|
1707
|
+
filename: String,
|
|
1708
|
+
export: SyntheticExport,
|
|
1709
|
+
timeout_ms: u64,
|
|
1710
|
+
outermost: bool,
|
|
1711
|
+
) -> VmReply {
|
|
1712
|
+
// (…the id it was filed under, taken back where the op ends terminated after all — a watchdog firing once the
|
|
1713
|
+
// function returned — as no wrapper will ever let go of it: op_resolve_function's `registered`)
|
|
1714
|
+
let mut registered = None;
|
|
1715
|
+
let outcome = run_js_bracketed(
|
|
1716
|
+
scope,
|
|
1717
|
+
outermost,
|
|
1718
|
+
timeout_ms,
|
|
1719
|
+
"synthetic_module",
|
|
1720
|
+
|scope, outermost| {
|
|
1721
|
+
let Some(cx) = context_for(istate!(scope), context_id) else {
|
|
1722
|
+
return (
|
|
1723
|
+
false,
|
|
1724
|
+
Err(VmError::Runtime("context disposed or unknown".into())),
|
|
1725
|
+
);
|
|
1726
|
+
};
|
|
1727
|
+
let context = v8::Local::new(scope, &cx);
|
|
1728
|
+
let scope = &mut v8::ContextScope::new(scope, context);
|
|
1729
|
+
v8::tc_scope!(let tc, scope);
|
|
1730
|
+
let (ran_js, value) = match export {
|
|
1731
|
+
SyntheticExport::Value(value) => (false, Ok(jsval_to_js(tc, value))),
|
|
1732
|
+
SyntheticExport::Json(text) => match v8::String::new(tc, &text) {
|
|
1733
|
+
None => (false, Err(VmError::Runtime("JSON source too large".into()))),
|
|
1734
|
+
Some(text) => match v8::json::parse(tc, text) {
|
|
1735
|
+
Some(value) => (true, Ok(value)),
|
|
1736
|
+
None if tc.has_terminated() => (true, Err(VmError::Terminated)),
|
|
1737
|
+
None => {
|
|
1738
|
+
let exception = tc.exception();
|
|
1739
|
+
(
|
|
1740
|
+
true,
|
|
1741
|
+
Err(parse_error(
|
|
1742
|
+
tc,
|
|
1743
|
+
exception,
|
|
1744
|
+
None,
|
|
1745
|
+
&filename,
|
|
1746
|
+
"JSON parse error",
|
|
1747
|
+
)),
|
|
1748
|
+
)
|
|
1749
|
+
}
|
|
1750
|
+
},
|
|
1751
|
+
},
|
|
1752
|
+
SyntheticExport::Call { path, args } => match resolve_function(tc, &path) {
|
|
1753
|
+
Err(failure) => (true, Err(failure.unwrap_or_else(|| caught!(&mut *tc)))),
|
|
1754
|
+
Ok((function, receiver)) => {
|
|
1755
|
+
let argv: Vec<v8::Local<v8::Value>> =
|
|
1756
|
+
args.into_iter().map(|a| jsval_to_js(tc, a)).collect();
|
|
1757
|
+
match function.call(tc, receiver, &argv) {
|
|
1758
|
+
Some(value) => (true, Ok(value)),
|
|
1759
|
+
None => (true, Err(caught!(&mut *tc))),
|
|
1760
|
+
}
|
|
1761
|
+
}
|
|
1762
|
+
},
|
|
1763
|
+
};
|
|
1764
|
+
let value = match value {
|
|
1765
|
+
Ok(value) => value,
|
|
1766
|
+
Err(e) => return (ran_js, Err(e)),
|
|
1767
|
+
};
|
|
1768
|
+
let (Some(name), Some(default)) = (
|
|
1769
|
+
v8::String::new(tc, &filename),
|
|
1770
|
+
v8::String::new(tc, "default"),
|
|
1771
|
+
) else {
|
|
1772
|
+
return (
|
|
1773
|
+
ran_js,
|
|
1774
|
+
Err(VmError::Runtime("module name too large".into())),
|
|
1775
|
+
);
|
|
1776
|
+
};
|
|
1777
|
+
let module = v8::Module::create_synthetic_module(
|
|
1778
|
+
tc,
|
|
1779
|
+
name,
|
|
1780
|
+
&[default],
|
|
1781
|
+
synthetic_evaluation_steps,
|
|
1782
|
+
);
|
|
1783
|
+
let hash = module.get_identity_hash().get();
|
|
1784
|
+
let (weak, kept) = (v8::Weak::new(tc, module), v8::Global::new(tc, value));
|
|
1785
|
+
istate!(tc).synthetic.add(hash, weak, kept, context_id);
|
|
1786
|
+
let origin = ModuleOrigin {
|
|
1787
|
+
url: filename.clone(),
|
|
1788
|
+
host_defined: None,
|
|
1789
|
+
};
|
|
1790
|
+
let id = register_module(tc, module, context_id, origin);
|
|
1791
|
+
registered = Some(id);
|
|
1792
|
+
// (…what the function queued drained, as any op's at the outermost)
|
|
1793
|
+
auto_drain(tc, outermost);
|
|
1794
|
+
(ran_js, Ok(JsVal::Int(id as i64)))
|
|
1795
|
+
},
|
|
1796
|
+
);
|
|
1797
|
+
if let (Err(_), Some(id)) = (&outcome, registered) {
|
|
1798
|
+
istate!(scope).modules.by_id.remove(&id);
|
|
1799
|
+
}
|
|
1800
|
+
VmReply::Done(outcome)
|
|
1801
|
+
}
|
|
1802
|
+
|
|
1803
|
+
// Module#script_id: the module's script id, nil where it has none (a synthetic
|
|
1804
|
+
// or an errored module). No context is entered: it reads the module's script.
|
|
1805
|
+
fn op_module_script_id(scope: &mut v8::PinScope<'_, '_, ()>, module_id: i32) -> VmReply {
|
|
1806
|
+
let Some((g, _)) = module_handle(istate!(scope), module_id) else {
|
|
1807
|
+
return VmReply::Done(Err(VmError::Runtime("unknown module".into())));
|
|
1808
|
+
};
|
|
1809
|
+
let module = v8::Local::new(scope, &g);
|
|
1810
|
+
VmReply::Done(Ok(module
|
|
1811
|
+
.script_id()
|
|
1812
|
+
.map_or(JsVal::Null, |id| JsVal::Int(i64::from(id)))))
|
|
1813
|
+
}
|
|
1814
|
+
|
|
1815
|
+
// Module#requests: [[specifier, {key => value, …}], …] — V8's module requests,
|
|
1816
|
+
// each with its import attributes, as the source has them.
|
|
1817
|
+
fn op_module_requests(scope: &mut v8::PinScope<'_, '_, ()>, module_id: i32) -> VmReply {
|
|
1818
|
+
let Some((g, cid)) = module_handle(istate!(scope), module_id) else {
|
|
1819
|
+
return VmReply::Done(Err(VmError::Runtime("unknown module".into())));
|
|
1820
|
+
};
|
|
1821
|
+
let Some(cx) = context_for(istate!(scope), cid) else {
|
|
1822
|
+
return VmReply::Done(Err(VmError::Runtime("module's context is gone".into())));
|
|
1823
|
+
};
|
|
1824
|
+
let context = v8::Local::new(scope, &cx);
|
|
1825
|
+
let scope = &mut v8::ContextScope::new(scope, context);
|
|
1826
|
+
let module = v8::Local::new(scope, &g);
|
|
1827
|
+
let requests = module.get_module_requests();
|
|
1828
|
+
let mut ids = 0u32..;
|
|
1829
|
+
let mut items = Vec::with_capacity(requests.length());
|
|
1830
|
+
for i in 0..requests.length() {
|
|
1831
|
+
let Some(request) = requests
|
|
1832
|
+
.get(scope, i)
|
|
1833
|
+
.and_then(|r| v8::Local::<v8::ModuleRequest>::try_from(r).ok())
|
|
1834
|
+
else {
|
|
1835
|
+
continue;
|
|
1836
|
+
};
|
|
1837
|
+
let specifier = request.get_specifier().to_rust_string_lossy(scope);
|
|
1838
|
+
let attributes = request.get_import_attributes();
|
|
1839
|
+
let entries = import_attributes_of(scope, attributes, 3)
|
|
1840
|
+
.into_iter()
|
|
1841
|
+
.map(|(key, value)| (key, JsVal::Str(value)))
|
|
1842
|
+
.collect();
|
|
1843
|
+
let attributes = JsVal::Obj {
|
|
1844
|
+
id: ids.next().unwrap_or(0),
|
|
1845
|
+
entries,
|
|
1846
|
+
};
|
|
1847
|
+
items.push(JsVal::Array {
|
|
1848
|
+
id: ids.next().unwrap_or(0),
|
|
1849
|
+
items: vec![JsVal::Str(specifier), attributes],
|
|
1850
|
+
});
|
|
1851
|
+
}
|
|
1852
|
+
VmReply::Done(Ok(JsVal::Array {
|
|
1853
|
+
id: ids.next().unwrap_or(0),
|
|
1854
|
+
items,
|
|
1855
|
+
}))
|
|
1856
|
+
}
|
|
1857
|
+
|
|
1858
|
+
// DynamicImport#resolve / #reject / #reject_with: the waiting import() |import_id|
|
|
1859
|
+
// settled — replying whether it was still waiting (its realm reset or disposed,
|
|
1860
|
+
// or settled already: it is not). Linking a module runs the resolve block
|
|
1861
|
+
// DynamicImport#resolve parked; evaluating it, and a reject_with function, run
|
|
1862
|
+
// JS, so this is bracketed as an evaluation is.
|
|
1863
|
+
fn op_settle_import(
|
|
1864
|
+
scope: &mut v8::PinScope<'_, '_, ()>,
|
|
1865
|
+
import_id: u64,
|
|
1866
|
+
settle: Settle,
|
|
1867
|
+
timeout_ms: u64,
|
|
1868
|
+
outermost: bool,
|
|
1869
|
+
) -> VmReply {
|
|
1870
|
+
let outcome = run_js_bracketed(
|
|
1871
|
+
scope,
|
|
1872
|
+
outermost,
|
|
1873
|
+
timeout_ms,
|
|
1874
|
+
"import",
|
|
1875
|
+
|scope, outermost| {
|
|
1876
|
+
let Some((resolver, cid)) = istate!(scope).imports.by_id.remove(&import_id) else {
|
|
1877
|
+
return (false, Ok(JsVal::Bool(false)));
|
|
1878
|
+
};
|
|
1879
|
+
let Some(cx) = context_for(istate!(scope), cid) else {
|
|
1880
|
+
return (false, Ok(JsVal::Bool(false)));
|
|
1881
|
+
};
|
|
1882
|
+
let context = v8::Local::new(scope, &cx);
|
|
1883
|
+
let scope = &mut v8::ContextScope::new(scope, context);
|
|
1884
|
+
let resolver = v8::Local::new(scope, resolver);
|
|
1885
|
+
match settle {
|
|
1886
|
+
Settle::Module(module_id) => match module_handle(istate!(scope), module_id) {
|
|
1887
|
+
Some((g, mcid)) if mcid == cid => {
|
|
1888
|
+
let module = v8::Local::new(scope, &g);
|
|
1889
|
+
let settling = std::mem::replace(&mut istate!(scope).settling_import, true);
|
|
1890
|
+
finish_dynamic_import(scope, module, resolver);
|
|
1891
|
+
istate!(scope).settling_import = settling;
|
|
1892
|
+
}
|
|
1893
|
+
Some(_) => reject_with_error(
|
|
1894
|
+
scope,
|
|
1895
|
+
resolver,
|
|
1896
|
+
"import() settled with a module of another realm",
|
|
1897
|
+
),
|
|
1898
|
+
None => reject_with_error(
|
|
1899
|
+
scope,
|
|
1900
|
+
resolver,
|
|
1901
|
+
"import() settled with an unknown module",
|
|
1902
|
+
),
|
|
1903
|
+
},
|
|
1904
|
+
Settle::Reject(value) => {
|
|
1905
|
+
let value = jsval_to_js(scope, value);
|
|
1906
|
+
resolver.reject(scope, value);
|
|
1907
|
+
}
|
|
1908
|
+
Settle::RejectWith { path, args } => {
|
|
1909
|
+
v8::tc_scope!(let tc, scope);
|
|
1910
|
+
let made = match resolve_function(tc, &path) {
|
|
1911
|
+
Ok((function, receiver)) => {
|
|
1912
|
+
let argv: Vec<v8::Local<v8::Value>> =
|
|
1913
|
+
args.into_iter().map(|a| jsval_to_js(tc, a)).collect();
|
|
1914
|
+
function.call(tc, receiver, &argv)
|
|
1915
|
+
}
|
|
1916
|
+
Err(Some(e)) => {
|
|
1917
|
+
let message = match e {
|
|
1918
|
+
VmError::Runtime(m) => m,
|
|
1919
|
+
_ => format!("`{path}` could not be called"),
|
|
1920
|
+
};
|
|
1921
|
+
if let Some(message) = v8::String::new(tc, &message) {
|
|
1922
|
+
let error = v8::Exception::error(tc, message);
|
|
1923
|
+
tc.throw_exception(error);
|
|
1924
|
+
}
|
|
1925
|
+
None
|
|
1926
|
+
}
|
|
1927
|
+
Err(None) => None,
|
|
1928
|
+
};
|
|
1929
|
+
// (…what the function throws rejects it as well, its value)
|
|
1930
|
+
match made {
|
|
1931
|
+
Some(value) => {
|
|
1932
|
+
resolver.reject(tc, value);
|
|
1933
|
+
}
|
|
1934
|
+
None if tc.has_terminated() => {}
|
|
1935
|
+
None => {
|
|
1936
|
+
if let Some(exception) = tc.exception() {
|
|
1937
|
+
resolver.reject(tc, exception);
|
|
1938
|
+
}
|
|
1939
|
+
}
|
|
1940
|
+
}
|
|
1941
|
+
}
|
|
1942
|
+
}
|
|
1943
|
+
if scope.is_execution_terminating() {
|
|
1944
|
+
return (true, Err(VmError::Terminated));
|
|
1945
|
+
}
|
|
1946
|
+
auto_drain(scope, outermost);
|
|
1947
|
+
(true, Ok(JsVal::Bool(true)))
|
|
1948
|
+
},
|
|
1949
|
+
);
|
|
1950
|
+
VmReply::Done(outcome)
|
|
1951
|
+
}
|
data/lib/rusty_racer/version.rb
CHANGED