summaryrefslogtreecommitdiffstats
path: root/third_party/rust/jsparagus-stencil/src/gcthings.rs
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 00:47:55 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 00:47:55 +0000
commit26a029d407be480d791972afb5975cf62c9360a6 (patch)
treef435a8308119effd964b339f76abb83a57c29483 /third_party/rust/jsparagus-stencil/src/gcthings.rs
parentInitial commit. (diff)
downloadfirefox-26a029d407be480d791972afb5975cf62c9360a6.tar.xz
firefox-26a029d407be480d791972afb5975cf62c9360a6.zip
Adding upstream version 124.0.1.upstream/124.0.1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'third_party/rust/jsparagus-stencil/src/gcthings.rs')
-rw-r--r--third_party/rust/jsparagus-stencil/src/gcthings.rs77
1 files changed, 77 insertions, 0 deletions
diff --git a/third_party/rust/jsparagus-stencil/src/gcthings.rs b/third_party/rust/jsparagus-stencil/src/gcthings.rs
new file mode 100644
index 0000000000..bbe18fd20f
--- /dev/null
+++ b/third_party/rust/jsparagus-stencil/src/gcthings.rs
@@ -0,0 +1,77 @@
+use crate::regexp::RegExpIndex;
+use crate::scope::ScopeIndex;
+use crate::script::ScriptStencilIndex;
+use ast::source_atom_set::SourceAtomSetIndex;
+
+/// Corresponds to js::frontend::GCThingList::ListType
+/// in m-c/js/src/frontend/BytecodeSection.h.
+#[derive(Debug)]
+pub enum GCThing {
+ Null,
+ Atom(SourceAtomSetIndex),
+ Function(ScriptStencilIndex),
+ RegExp(RegExpIndex),
+ Scope(ScopeIndex),
+}
+
+/// Index into GCThingList.things.
+#[derive(Debug, Clone, Copy, PartialEq)]
+pub struct GCThingIndex {
+ index: usize,
+}
+
+impl GCThingIndex {
+ fn new(index: usize) -> Self {
+ Self { index }
+ }
+}
+
+impl From<GCThingIndex> for usize {
+ fn from(index: GCThingIndex) -> usize {
+ index.index
+ }
+}
+
+/// List of GC things.
+///
+/// Maps to JSScript::gcthings() in js/src/vm/JSScript.h.
+#[derive(Debug)]
+pub struct GCThingList {
+ things: Vec<GCThing>,
+}
+
+impl GCThingList {
+ pub fn new() -> Self {
+ Self { things: Vec::new() }
+ }
+
+ pub fn push_atom(&mut self, atom_index: SourceAtomSetIndex) -> GCThingIndex {
+ let index = self.things.len();
+ self.things.push(GCThing::Atom(atom_index));
+ GCThingIndex::new(index)
+ }
+
+ pub fn push_function(&mut self, fun_index: ScriptStencilIndex) -> GCThingIndex {
+ let index = self.things.len();
+ self.things.push(GCThing::Function(fun_index));
+ GCThingIndex::new(index)
+ }
+
+ pub fn push_regexp(&mut self, regexp_index: RegExpIndex) -> GCThingIndex {
+ let index = self.things.len();
+ self.things.push(GCThing::RegExp(regexp_index));
+ GCThingIndex::new(index)
+ }
+
+ pub fn push_scope(&mut self, scope_index: ScopeIndex) -> GCThingIndex {
+ let index = self.things.len();
+ self.things.push(GCThing::Scope(scope_index));
+ GCThingIndex::new(index)
+ }
+}
+
+impl From<GCThingList> for Vec<GCThing> {
+ fn from(list: GCThingList) -> Vec<GCThing> {
+ list.things
+ }
+}