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. 13
      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 { pub fn _create(global: &Value) -> Value {
let array = to_value(make_array as NativeFunctionData); let array = to_value(make_array as NativeFunctionData);
let proto = ValueData::new_obj(Some(global)); let proto = ValueData::new_obj(Some(global));
let length = Property::default() let length = Property::default().get(to_value(get_array_length as NativeFunctionData));
.get(to_value(get_array_length as NativeFunctionData));
proto.set_prop_slice("length", length); proto.set_prop_slice("length", length);
let concat_func = to_value(concat as NativeFunctionData); 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 => { ObjectKind::Array => {
write!(s, "[").unwrap(); write!(s, "[").unwrap();
let len: i32 = let len: i32 = from_value(
from_value(v.borrow().properties.get("length").unwrap().value.clone().unwrap().clone()) v.borrow()
.properties
.get("length")
.unwrap()
.value
.clone()
.unwrap()
.clone(),
)
.unwrap(); .unwrap();
for i in 0..len { for i in 0..len {
// Introduce recursive call to stringify any objects // 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 // Introduce recursive call to stringify any objects
// which are keys of the object // 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 { if key != last_key {
write!(s, ", ").unwrap(); 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 { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{{")?; write!(f, "{{")?;
for (key, val) in self.object.properties.iter() { 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, "}}") write!(f, "}}")
} }

13
src/lib/js/object.rs

@ -281,8 +281,8 @@ impl Object {
// Convert to accessor // Convert to accessor
current.value = None; current.value = None;
current.writable = None; current.writable = None;
} else {
} else { // c // c
// convert to data // convert to data
current.get = None; current.get = None;
current.set = None; current.set = None;
@ -291,12 +291,17 @@ impl Object {
// 7 // 7
} else if current.is_data_descriptor() && desc.is_data_descriptor() { } else if current.is_data_descriptor() && desc.is_data_descriptor() {
// a // a
if !current.configurable.unwrap()&& !current.writable.unwrap() { if !current.configurable.unwrap() && !current.writable.unwrap() {
if desc.writable.is_some() && desc.writable.unwrap() { if desc.writable.is_some() && desc.writable.unwrap() {
return false; 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; 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 { fn _make_prop(getter: NativeFunctionData) -> Property {
Property::default() Property::default().get(to_value(getter))
.get(to_value(getter))
} }
/// Search for a match between this regex and a specified string /// 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 { pub fn _create(global: &Value) -> Value {
let string = to_value(make_string as NativeFunctionData); let string = to_value(make_string as NativeFunctionData);
let proto = ValueData::new_obj(Some(global)); let proto = ValueData::new_obj(Some(global));
let prop = Property::default() let prop = Property::default().get(to_value(get_string_length as NativeFunctionData));
.get(to_value(get_string_length as NativeFunctionData));
proto.set_prop_slice("length", prop); proto.set_prop_slice("length", prop);
proto.set_field_slice("charAt", to_value(char_at as NativeFunctionData)); 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 // If the Property has [[Get]] set to a function, we should run that and return the Value
let prop_getter = match prop.get { let prop_getter = match prop.get {
Some(_) => None, Some(_) => None,
None => None None => None,
}; };
// If the getter is populated, use that. If not use [[Value]] instead // If the getter is populated, use that. If not use [[Value]] instead
@ -478,9 +478,10 @@ impl ValueData {
JSONValue::Array(vs) => { JSONValue::Array(vs) => {
let mut new_obj = Object::default(); let mut new_obj = Object::default();
for (idx, json) in vs.iter().enumerate() { for (idx, json) in vs.iter().enumerate() {
new_obj new_obj.properties.insert(
.properties idx.to_string(),
.insert(idx.to_string(), Property::default().value(to_value(json.clone()))); Property::default().value(to_value(json.clone())),
);
} }
new_obj.properties.insert( new_obj.properties.insert(
"length".to_string(), "length".to_string(),
@ -491,9 +492,10 @@ impl ValueData {
JSONValue::Object(obj) => { JSONValue::Object(obj) => {
let mut new_obj = Object::default(); let mut new_obj = Object::default();
for (key, json) in obj.iter() { for (key, json) in obj.iter() {
new_obj new_obj.properties.insert(
.properties key.clone(),
.insert(key.clone(), Property::default().value(to_value(json.clone()))); Property::default().value(to_value(json.clone())),
);
} }
ValueData::Object(GcCell::new(new_obj)) ValueData::Object(GcCell::new(new_obj))
@ -562,7 +564,15 @@ impl Display for ValueData {
// Print public properties // Print public properties
if let Some((last_key, _)) = v.borrow().properties.iter().last() { if let Some((last_key, _)) = v.borrow().properties.iter().last() {
for (key, val) in v.borrow().properties.iter() { 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 { if key != last_key {
write!(f, ", ")?; write!(f, ", ")?;
} }

Loading…
Cancel
Save