Skip to content

Commit

Permalink
Merge e88673c into 07389cb
Browse files Browse the repository at this point in the history
  • Loading branch information
jedel1043 authored Oct 10, 2022
2 parents 07389cb + e88673c commit c115fd5
Show file tree
Hide file tree
Showing 101 changed files with 4,156 additions and 3,053 deletions.
58 changes: 38 additions & 20 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ members = [
"boa_unicode",
"boa_wasm",
"boa_examples",
"boa_macros",
]

[workspace.package]
Expand All @@ -26,6 +27,7 @@ boa_interner = { version = "0.16.0", path = "boa_interner" }
boa_gc = { version = "0.16.0", path = "boa_gc" }
boa_profiler = { version = "0.16.0", path = "boa_profiler" }
boa_unicode = { version = "0.16.0", path = "boa_unicode" }
boa_macros = { version = "0.16.0", path = "boa_macros" }

[workspace.metadata.workspaces]
allow_branch = "main"
Expand Down
3 changes: 3 additions & 0 deletions boa_engine/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ boa_unicode.workspace = true
boa_interner.workspace = true
boa_gc.workspace = true
boa_profiler.workspace = true
boa_macros.workspace = true
gc = "0.4.1"
serde = { version = "1.0.145", features = ["derive", "rc"] }
serde_json = "1.0.85"
Expand All @@ -50,6 +51,8 @@ unicode-normalization = "0.1.22"
dyn-clone = "1.0.9"
once_cell = "1.15.0"
tap = "1.0.1"
sptr = "0.3.2"
static_assertions = "1.1.0"
icu_locale_canonicalizer = { version = "0.6.0", features = ["serde"], optional = true }
icu_locid = { version = "0.6.0", features = ["serde"], optional = true }
icu_datetime = { version = "0.6.0", features = ["serde"], optional = true }
Expand Down
22 changes: 14 additions & 8 deletions boa_engine/src/builtins/array/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,15 @@ use crate::{
builtins::BuiltIn,
builtins::Number,
context::intrinsics::StandardConstructors,
js_string,
object::{
internal_methods::get_prototype_from_constructor, ConstructorBuilder, FunctionBuilder,
JsFunction, JsObject, ObjectData,
},
property::{Attribute, PropertyDescriptor, PropertyNameKind},
symbol::WellKnownSymbols,
value::{IntegerOrInfinity, JsValue},
Context, JsResult, JsString,
Context, JsResult,
};
use std::cmp::{max, min, Ordering};

Expand Down Expand Up @@ -412,7 +413,12 @@ impl Array {
let mapping = match mapfn {
JsValue::Undefined => None,
JsValue::Object(o) if o.is_callable() => Some(o),
_ => return context.throw_type_error(format!("{} is not a function", mapfn.type_of())),
_ => {
return context.throw_type_error(format!(
"{} is not a function",
mapfn.type_of().to_std_string_escaped()
))
}
};

// 4. Let usingIterator be ? GetMethod(items, @@iterator).
Expand Down Expand Up @@ -864,34 +870,34 @@ impl Array {
// 4. Else, let sep be ? ToString(separator).
let separator = args.get_or_undefined(0);
let separator = if separator.is_undefined() {
JsString::new(",")
js_string!(",")
} else {
separator.to_string(context)?
};

// 5. Let R be the empty String.
let mut r = String::new();
let mut r = Vec::new();
// 6. Let k be 0.
// 7. Repeat, while k < len,
for k in 0..len {
// a. If k > 0, set R to the string-concatenation of R and sep.
if k > 0 {
r.push_str(&separator);
r.extend_from_slice(&separator);
}
// b. Let element be ? Get(O, ! ToString(𝔽(k))).
let element = o.get(k, context)?;
// c. If element is undefined or null, let next be the empty String; otherwise, let next be ? ToString(element).
let next = if element.is_null_or_undefined() {
JsString::new("")
js_string!()
} else {
element.to_string(context)?
};
// d. Set R to the string-concatenation of R and next.
r.push_str(&next);
r.extend_from_slice(&next);
// e. Set k to k + 1.
}
// 8. Return R.
Ok(r.into())
Ok(js_string!(&r[..]).into())
}

/// `Array.prototype.toString( separator )`
Expand Down
42 changes: 30 additions & 12 deletions boa_engine/src/builtins/console/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,11 @@ pub fn formatter(data: &[JsValue], context: &mut Context) -> JsResult<String> {

match data.len() {
0 => Ok(String::new()),
1 => Ok(target.to_string()),
1 => Ok(target.to_std_string_escaped()),
_ => {
let mut formatted = String::new();
let mut arg_index = 1;
let target = target.to_std_string_escaped();
let mut chars = target.chars();
while let Some(c) = chars.next() {
if c == '%' {
Expand Down Expand Up @@ -96,7 +97,8 @@ pub fn formatter(data: &[JsValue], context: &mut Context) -> JsResult<String> {
.get(arg_index)
.cloned()
.unwrap_or_default()
.to_string(context)?;
.to_string(context)?
.to_std_string_escaped();
formatted.push_str(&arg);
arg_index += 1;
}
Expand All @@ -114,7 +116,10 @@ pub fn formatter(data: &[JsValue], context: &mut Context) -> JsResult<String> {

/* unformatted data */
for rest in data.iter().skip(arg_index) {
formatted.push_str(&format!(" {}", rest.to_string(context)?));
formatted.push_str(&format!(
" {}",
rest.to_string(context)?.to_std_string_escaped()
));
}

Ok(formatted)
Expand Down Expand Up @@ -300,7 +305,7 @@ impl Console {
context
.interner()
.resolve_expect(frame.code.name)
.to_owned(),
.to_string(),
);
}

Expand Down Expand Up @@ -365,7 +370,7 @@ impl Console {
None => "default".into(),
};

let msg = format!("count {label}:");
let msg = format!("count {}:", label.to_std_string_escaped());
let c = context.console_mut().count_map.entry(label).or_insert(0);
*c += 1;

Expand Down Expand Up @@ -396,7 +401,7 @@ impl Console {
context.console_mut().count_map.remove(&label);

logger(
LogMessage::Warn(format!("countReset {label}")),
LogMessage::Warn(format!("countReset {}", label.to_std_string_escaped())),
context.console(),
);

Expand Down Expand Up @@ -429,7 +434,10 @@ impl Console {

if context.console().timer_map.get(&label).is_some() {
logger(
LogMessage::Warn(format!("Timer '{label}' already exist")),
LogMessage::Warn(format!(
"Timer '{}' already exist",
label.to_std_string_escaped()
)),
context.console(),
);
} else {
Expand Down Expand Up @@ -462,14 +470,17 @@ impl Console {

if let Some(t) = context.console().timer_map.get(&label) {
let time = Self::system_time_in_ms();
let mut concat = format!("{label}: {} ms", time - t);
let mut concat = format!("{}: {} ms", label.to_std_string_escaped(), time - t);
for msg in args.iter().skip(1) {
concat = concat + " " + &msg.display().to_string();
}
logger(LogMessage::Log(concat), context.console());
} else {
logger(
LogMessage::Warn(format!("Timer '{label}' doesn't exist")),
LogMessage::Warn(format!(
"Timer '{}' doesn't exist",
label.to_std_string_escaped()
)),
context.console(),
);
}
Expand Down Expand Up @@ -497,15 +508,22 @@ impl Console {
None => "default".into(),
};

if let Some(t) = context.console_mut().timer_map.remove(label.as_str()) {
if let Some(t) = context.console_mut().timer_map.remove(&label) {
let time = Self::system_time_in_ms();
logger(
LogMessage::Info(format!("{label}: {} ms - timer removed", time - t)),
LogMessage::Info(format!(
"{}: {} ms - timer removed",
label.to_std_string_escaped(),
time - t
)),
context.console(),
);
} else {
logger(
LogMessage::Warn(format!("Timer '{label}' doesn't exist")),
LogMessage::Warn(format!(
"Timer '{}' doesn't exist",
label.to_std_string_escaped()
)),
context.console(),
);
}
Expand Down
Loading

0 comments on commit c115fd5

Please sign in to comment.