Skip to content

Commit

Permalink
fix a bunch of more things
Browse files Browse the repository at this point in the history
  • Loading branch information
Sharktheone committed May 19, 2024
1 parent 51bfcf5 commit f2686a4
Show file tree
Hide file tree
Showing 20 changed files with 122 additions and 92 deletions.
2 changes: 1 addition & 1 deletion benches/tokenizer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ fn criterion_benchmark(c: &mut Criterion) {
test.tokenize();
}
}
})
});
});

group.finish();
Expand Down
4 changes: 2 additions & 2 deletions benches/tree_iterator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ fn wikipedia_main_page(c: &mut Criterion) {
b.iter(|| {
let tree_iterator = TreeIterator::new(&main_document);
let _ = tree_iterator.collect::<Vec<NodeId>>();
})
});
});

group.finish();
Expand All @@ -53,7 +53,7 @@ fn stackoverflow_home(c: &mut Criterion) {
b.iter(|| {
let tree_iterator = TreeIterator::new(&main_document);
let _ = tree_iterator.collect::<Vec<NodeId>>();
})
});
});

group.finish();
Expand Down
19 changes: 12 additions & 7 deletions crates/gosub_config/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use anyhow::anyhow;
use std::collections::HashMap;
use std::mem;
use std::str::FromStr;
use std::sync::RwLock;

use anyhow::anyhow;
use lazy_static::lazy_static;
use log::warn;
use serde_derive::Deserialize;
Expand Down Expand Up @@ -176,9 +176,14 @@ impl ConfigStore {
// Find all keys, and add them to the configuration store
if let Ok(all_settings) = self.storage.all() {
for (key, value) in all_settings {
self.settings
if self
.settings
.lock()
.and_then(|x| Ok(x.borrow_mut().insert(key, value)));
.map(|x| x.borrow_mut().insert(key.clone(), value))
.is_err()
{
warn!("config: Failed to set setting {key}");
}
}
}
}
Expand Down Expand Up @@ -258,12 +263,12 @@ impl ConfigStore {
return;
}

let e = self
if self
.settings
.lock()
.map(|x| x.borrow_mut().insert(key.to_owned(), value.clone()));

if e.is_err() {
.map(|x| x.borrow_mut().insert(key.to_owned(), value.clone()))
.is_err()
{
warn!("config: Failed to set setting {key}");
return;
}
Expand Down
2 changes: 1 addition & 1 deletion crates/gosub_css3/src/parser/at_rule.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ impl Css3<'_> {

// if we did a block, we need to close it
if node.is_some() {
self.consume(TokenType::RCurly)?;
self.consume(&TokenType::RCurly)?;
}

Ok(node)
Expand Down
6 changes: 3 additions & 3 deletions crates/gosub_css3/src/parser/at_rule/media.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ impl Css3<'_> {

let loc = self.tokenizer.current_location().clone();

self.consume(TokenType::LParen)?;
self.consume(&TokenType::LParen)?;

let mut value: Option<Node> = None;

Expand Down Expand Up @@ -64,7 +64,7 @@ impl Css3<'_> {
TokenType::Function(name) => {
let name = name.to_lowercase();
let args = self.parse_pseudo_function(name.as_str())?;
self.consume(TokenType::RParen)?;
self.consume(&TokenType::RParen)?;

Some(Node::new(
NodeType::Function {
Expand All @@ -85,7 +85,7 @@ impl Css3<'_> {
self.consume_whitespace_comments();

if !self.tokenizer.eof() {
self.consume(TokenType::RParen)?;
self.consume(&TokenType::RParen)?;
}
}

Expand Down
6 changes: 3 additions & 3 deletions crates/gosub_css3/src/parser/at_rule/scope.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,19 @@ impl Css3<'_> {
root = Some(self.parse_selector_list()?);
self.consume_whitespace_comments();

self.consume(TokenType::RParen)?;
self.consume(&TokenType::RParen)?;
}

if let TokenType::Ident(_value) = t.token_type {
self.consume_whitespace_comments();
self.consume_ident("to")?;
self.consume_whitespace_comments();
self.consume(TokenType::RParen)?;
self.consume(&TokenType::RParen)?;
self.consume_whitespace_comments();

limit = Some(self.parse_selector_list()?);
self.consume_whitespace_comments();
self.consume(TokenType::RParen)?;
self.consume(&TokenType::RParen)?;
}

Ok(Node::new(NodeType::Scope { root, limit }, t.location))
Expand Down
4 changes: 2 additions & 2 deletions crates/gosub_css3/src/parser/condition.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ impl Css3<'_> {
};

if term.is_err() {
self.consume(TokenType::RParen)?;
self.consume(&TokenType::RParen)?;
let res = self.parse_condition(kind.clone())?;
self.consume(TokenType::LParen)?;
self.consume(&TokenType::LParen)?;
return Ok(res);
}

Expand Down
2 changes: 1 addition & 1 deletion crates/gosub_css3/src/parser/function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ impl Css3<'_> {
};

if !self.tokenizer.eof() {
self.consume(TokenType::RParen)?;
self.consume(&TokenType::RParen)?;
}

Ok(Node::new(NodeType::Function { name, arguments }, loc))
Expand Down
4 changes: 2 additions & 2 deletions crates/gosub_css3/src/parser/rule.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ impl Css3<'_> {

let prelude = self.parse_selector_list()?;

self.consume(TokenType::LCurly)?;
self.consume(&TokenType::LCurly)?;
self.consume_whitespace_comments();

let block = self.parse_block(BlockParseMode::StyleBlock)?;

self.consume(TokenType::RCurly)?;
self.consume(&TokenType::RCurly)?;

Ok(Node::new(
NodeType::Rule {
Expand Down
1 change: 1 addition & 0 deletions crates/gosub_css3/src/unicode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ impl UnicodeChar {
pub const SHIFT_OUT: char = '\u{000E}';
pub const DELETE: char = '\u{007F}';
pub const INFORMATION_SEPARATOR_ONE: char = '\u{001F}';
#[allow(dead_code)] //TODO: why is this here?
pub const LOW_LINE: char = '\u{005F}';
pub const MAX_ALLOWED: char = '\u{10FFFF}';
pub const REPLACEMENT_CHARACTER: char = '\u{FFFD}';
Expand Down
2 changes: 1 addition & 1 deletion crates/gosub_jsapi/src/console.rs
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ impl Console {
pub fn time_log(&mut self, label: &str, data: &[&dyn fmt::Display]) {
let mut message = String::from(" ");
for arg in data {
write!(message, "{arg}");
let _ = write!(message, "{arg}");
}
let message = message.trim_end();

Expand Down
2 changes: 0 additions & 2 deletions crates/gosub_render_utils/src/layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ use crate::style::get_style_from_node;
pub fn generate_taffy_tree(rt: &mut RenderTree) -> anyhow::Result<(TaffyTree<GosubID>, NodeId)> {
let mut tree: TaffyTree<GosubID> = TaffyTree::with_capacity(rt.nodes.len());

rt.get_root();

let root = add_children_to_tree(rt, &mut tree, rt.root)?;

Ok((tree, root))
Expand Down
19 changes: 10 additions & 9 deletions crates/gosub_v8/src/v8/array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use v8::{Array, Local};

use gosub_shared::types::Result;
use gosub_webexecutor::js::{AsArray, JSArray, JSError, JSRuntime, Ref};
use gosub_webexecutor::JSError;
use gosub_webexecutor::ExecutorError;

use crate::{FromContext, V8Context, V8Engine, V8Value};

Expand Down Expand Up @@ -49,7 +49,7 @@ impl<'a> JSArray for V8Array<'a> {

fn get(&self, index: usize) -> Result<<Self::RT as JSRuntime>::Value> {
let Some(value) = self.value.get_index(self.ctx.scope(), index as u32) else {
return Err(JSError::JS(JSError::Generic(
return Err(ExecutorError::JS(JSError::Generic(
"failed to get a value from an array".to_owned(),
))
.into());
Expand All @@ -64,7 +64,7 @@ impl<'a> JSArray for V8Array<'a> {
.set_index(self.ctx.scope(), index as u32, value.value)
{
Some(_) => Ok(()),
None => Err(JSError::JS(JSError::Conversion(
None => Err(ExecutorError::JS(JSError::Conversion(
"failed to set a value in an array".to_owned(),
))
.into()),
Expand All @@ -76,24 +76,25 @@ impl<'a> JSArray for V8Array<'a> {

match self.value.set_index(self.ctx.scope(), index, value.value) {
Some(_) => Ok(()),
None => Err(
JSError::JS(JSError::Conversion("failed to push to an array".to_owned())).into(),
),
None => Err(ExecutorError::JS(JSError::Conversion(
"failed to push to an array".to_owned(),
))
.into()),
}
}

fn pop(&self) -> Result<<Self::RT as JSRuntime>::Value> {
let index = self.value.length() - 1;

let Some(value) = self.value.get_index(self.ctx.scope(), index) else {
return Err(JSError::JS(JSError::Generic(
return Err(ExecutorError::JS(JSError::Generic(
"failed to get a value from an array".to_owned(),
))
.into());
};

if self.value.delete_index(self.ctx.scope(), index).is_none() {
return Err(JSError::JS(JSError::Generic(
return Err(ExecutorError::JS(JSError::Generic(
"failed to delete a value from an array".to_owned(),
))
.into());
Expand All @@ -108,7 +109,7 @@ impl<'a> JSArray for V8Array<'a> {
.delete_index(self.ctx.scope(), index as u32)
.is_none()
{
return Err(JSError::JS(JSError::Generic(
return Err(ExecutorError::JS(JSError::Generic(
"failed to delete a value from an array".to_owned(),
))
.into());
Expand Down
Loading

0 comments on commit f2686a4

Please sign in to comment.