summaryrefslogtreecommitdiffstats
path: root/third_party/rust/jsparagus-scope/src/data.rs
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 01:47:29 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 01:47:29 +0000
commit0ebf5bdf043a27fd3dfb7f92e0cb63d88954c44d (patch)
treea31f07c9bcca9d56ce61e9a1ffd30ef350d513aa /third_party/rust/jsparagus-scope/src/data.rs
parentInitial commit. (diff)
downloadfirefox-esr-0ebf5bdf043a27fd3dfb7f92e0cb63d88954c44d.tar.xz
firefox-esr-0ebf5bdf043a27fd3dfb7f92e0cb63d88954c44d.zip
Adding upstream version 115.8.0esr.upstream/115.8.0esr
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'third_party/rust/jsparagus-scope/src/data.rs')
-rw-r--r--third_party/rust/jsparagus-scope/src/data.rs65
1 files changed, 65 insertions, 0 deletions
diff --git a/third_party/rust/jsparagus-scope/src/data.rs b/third_party/rust/jsparagus-scope/src/data.rs
new file mode 100644
index 0000000000..1baeffe097
--- /dev/null
+++ b/third_party/rust/jsparagus-scope/src/data.rs
@@ -0,0 +1,65 @@
+//! Data generated by scope analysis, and consumed only by emitter
+
+use std::collections::HashMap;
+use stencil::script::ScriptStencilIndex;
+
+/// Data associated to a function.
+#[derive(Debug)]
+pub struct FunctionProperty {
+ is_annex_b: bool,
+}
+
+impl FunctionProperty {
+ fn is_annex_b_default() -> bool {
+ false
+ }
+
+ pub fn new() -> Self {
+ Self {
+ is_annex_b: Self::is_annex_b_default(),
+ }
+ }
+
+ pub fn mark_annex_b(&mut self) {
+ self.is_annex_b = true;
+ }
+
+ pub fn is_annex_b(&self) -> bool {
+ self.is_annex_b
+ }
+}
+
+/// Map from function to associated data.
+#[derive(Debug)]
+pub struct FunctionDeclarationPropertyMap {
+ /// This map is populated lazily, only for functions with non-default
+ /// property.
+ props: HashMap<ScriptStencilIndex, FunctionProperty>,
+}
+
+impl FunctionDeclarationPropertyMap {
+ pub fn new() -> Self {
+ Self {
+ props: HashMap::new(),
+ }
+ }
+
+ pub fn mark_annex_b(&mut self, index: ScriptStencilIndex) {
+ if !self.props.contains_key(&index) {
+ self.props.insert(index, FunctionProperty::new());
+ }
+
+ self.props
+ .get_mut(&index)
+ .expect("Should exist")
+ .mark_annex_b();
+ }
+
+ pub fn is_annex_b(&self, index: ScriptStencilIndex) -> bool {
+ if !self.props.contains_key(&index) {
+ return FunctionProperty::is_annex_b_default();
+ }
+
+ self.props.get(&index).expect("Should exist").is_annex_b()
+ }
+}