Skip to content

Commit

Permalink
Removed a couple of extra panics (#1050)
Browse files Browse the repository at this point in the history
  • Loading branch information
Razican authored Jan 9, 2021
1 parent c083c85 commit c3ba744
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
10 changes: 4 additions & 6 deletions boa/src/builtins/map/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -185,9 +185,8 @@ impl Map {
_ => (args[0].clone(), args[1].clone()),
};

let size = if let Value::Object(ref object) = this {
let mut object = object.borrow_mut();
if let Some(map) = object.as_map_mut() {
let size = if let Some(object) = this.as_object() {
if let Some(map) = object.borrow_mut().as_map_mut() {
map.insert(key, value);
map.len()
} else {
Expand Down Expand Up @@ -218,9 +217,8 @@ impl Map {
_ => &args[0],
};

let (deleted, size) = if let Value::Object(ref object) = this {
let mut object = object.borrow_mut();
if let Some(map) = object.as_map_mut() {
let (deleted, size) = if let Some(object) = this.as_object() {
if let Some(map) = object.borrow_mut().as_map_mut() {
let deleted = map.remove(key).is_some();
(deleted, map.len())
} else {
Expand Down
9 changes: 7 additions & 2 deletions boa/src/builtins/string/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -692,7 +692,8 @@ impl String {
}
(Some('<'), _) => {
// $<
todo!("named capture groups")
// TODO: named capture groups
result.push_str("$<");
}
_ => {
// $?, ? is none of the above
Expand Down Expand Up @@ -845,7 +846,11 @@ impl String {
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/match
/// [regex]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions
pub(crate) fn r#match(this: &Value, args: &[Value], context: &mut Context) -> Result<Value> {
let re = RegExp::constructor(&Value::from(Object::default()), &[args[0].clone()], context)?;
let re = RegExp::constructor(
&Value::from(Object::default()),
&[args.get(0).cloned().unwrap_or_default()],
context,
)?;
RegExp::r#match(&re, this.to_string(context)?, context)
}

Expand Down

0 comments on commit c3ba744

Please sign in to comment.