Browse Source

cargo fmt

pull/97/head
Jason Williams 5 years ago
parent
commit
5a90e32888
  1. 3
      src/lib/js/array.rs
  2. 20
      src/lib/js/console.rs
  3. 10
      src/lib/js/function.rs
  4. 11
      src/lib/js/object.rs
  5. 3
      src/lib/js/regexp.rs
  6. 3
      src/lib/js/string.rs
  7. 26
      src/lib/js/value.rs

3
src/lib/js/array.rs

@ -255,8 +255,7 @@ pub fn unshift(this: &Value, args: &[Value], _: &mut Interpreter) -> ResultValue
pub fn _create(global: &Value) -> Value {
let array = to_value(make_array as NativeFunctionData);
let proto = ValueData::new_obj(Some(global));
let length = Property::default()
.get(to_value(get_array_length as NativeFunctionData));
let length = Property::default().get(to_value(get_array_length as NativeFunctionData));
proto.set_prop_slice("length", length);
let concat_func = to_value(concat as NativeFunctionData);

20
src/lib/js/console.rs

@ -31,8 +31,16 @@ fn log_string_from(x: Value) -> String {
}
ObjectKind::Array => {
write!(s, "[").unwrap();
let len: i32 =
from_value(v.borrow().properties.get("length").unwrap().value.clone().unwrap().clone())
let len: i32 = from_value(
v.borrow()
.properties
.get("length")
.unwrap()
.value
.clone()
.unwrap()
.clone(),
)
.unwrap();
for i in 0..len {
// Introduce recursive call to stringify any objects
@ -64,7 +72,13 @@ fn log_string_from(x: Value) -> String {
}
// Introduce recursive call to stringify any objects
// which are keys of the object
write!(s, "{}: {}", key, log_string_from(val.value.clone().unwrap().clone())).unwrap();
write!(
s,
"{}: {}",
key,
log_string_from(val.value.clone().unwrap().clone())
)
.unwrap();
if key != last_key {
write!(s, ", ").unwrap();
}

10
src/lib/js/function.rs

@ -73,7 +73,15 @@ impl Debug for NativeFunction {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{{")?;
for (key, val) in self.object.properties.iter() {
write!(f, "{}: {}", key, val.value.as_ref().unwrap_or(&Gc::new(ValueData::Undefined)).clone())?;
write!(
f,
"{}: {}",
key,
val.value
.as_ref()
.unwrap_or(&Gc::new(ValueData::Undefined))
.clone()
)?;
}
write!(f, "}}")
}

11
src/lib/js/object.rs

@ -281,8 +281,8 @@ impl Object {
// Convert to accessor
current.value = None;
current.writable = None;
} else { // c
} else {
// c
// convert to data
current.get = None;
current.set = None;
@ -296,7 +296,12 @@ impl Object {
return false;
}
if desc.value.is_some() && !same_value(&desc.value.clone().unwrap(), &current.value.clone().unwrap()) {
if desc.value.is_some()
&& !same_value(
&desc.value.clone().unwrap(),
&current.value.clone().unwrap(),
)
{
return false;
}

3
src/lib/js/regexp.rs

@ -181,8 +181,7 @@ fn get_unicode(this: &Value, _: &[Value], _: &mut Interpreter) -> ResultValue {
}
fn _make_prop(getter: NativeFunctionData) -> Property {
Property::default()
.get(to_value(getter))
Property::default().get(to_value(getter))
}
/// Search for a match between this regex and a specified string

3
src/lib/js/string.rs

@ -525,8 +525,7 @@ pub fn trim_end(this: &Value, _: &[Value], ctx: &mut Interpreter) -> ResultValue
pub fn _create(global: &Value) -> Value {
let string = to_value(make_string as NativeFunctionData);
let proto = ValueData::new_obj(Some(global));
let prop = Property::default()
.get(to_value(get_string_length as NativeFunctionData));
let prop = Property::default().get(to_value(get_string_length as NativeFunctionData));
proto.set_prop_slice("length", prop);
proto.set_field_slice("charAt", to_value(char_at as NativeFunctionData));

26
src/lib/js/value.rs

@ -291,7 +291,7 @@ impl ValueData {
// If the Property has [[Get]] set to a function, we should run that and return the Value
let prop_getter = match prop.get {
Some(_) => None,
None => None
None => None,
};
// If the getter is populated, use that. If not use [[Value]] instead
@ -478,9 +478,10 @@ impl ValueData {
JSONValue::Array(vs) => {
let mut new_obj = Object::default();
for (idx, json) in vs.iter().enumerate() {
new_obj
.properties
.insert(idx.to_string(), Property::default().value(to_value(json.clone())));
new_obj.properties.insert(
idx.to_string(),
Property::default().value(to_value(json.clone())),
);
}
new_obj.properties.insert(
"length".to_string(),
@ -491,9 +492,10 @@ impl ValueData {
JSONValue::Object(obj) => {
let mut new_obj = Object::default();
for (key, json) in obj.iter() {
new_obj
.properties
.insert(key.clone(), Property::default().value(to_value(json.clone())));
new_obj.properties.insert(
key.clone(),
Property::default().value(to_value(json.clone())),
);
}
ValueData::Object(GcCell::new(new_obj))
@ -562,7 +564,15 @@ impl Display for ValueData {
// Print public properties
if let Some((last_key, _)) = v.borrow().properties.iter().last() {
for (key, val) in v.borrow().properties.iter() {
write!(f, "{}: {}", key, val.value.as_ref().unwrap_or(&Gc::new(ValueData::Undefined)).clone())?;
write!(
f,
"{}: {}",
key,
val.value
.as_ref()
.unwrap_or(&Gc::new(ValueData::Undefined))
.clone()
)?;
if key != last_key {
write!(f, ", ")?;
}

Loading…
Cancel
Save