Browse Source

updates

pull/5/head
Jason Williams 6 years ago
parent
commit
1b9dd477d7
  1. 6
      src/lib/exec.rs
  2. 5
      src/lib/js/array.rs
  3. 8
      src/lib/js/error.rs
  4. 1
      src/lib/js/json.rs
  5. 1
      src/lib/js/math.rs
  6. 2
      src/lib/js/string.rs
  7. 2
      src/lib/js/value.rs

6
src/lib/exec.rs

@ -90,15 +90,15 @@ impl Executor for Interpreter {
fn run(&mut self, expr: &Expr) -> ResultValue {
match expr.def {
ExprDef::ConstExpr(Const::Null) => Ok(to_value(None)),
ExprDef::ConstExpr(Const::Null) => Ok(to_value(None::<()>)),
ExprDef::ConstExpr(Const::Undefined) => Ok(Gc::new(ValueData::Undefined)),
ExprDef::ConstExpr(Const::Num(num)) => Ok(to_value(num)),
ExprDef::ConstExpr(Const::Int(num)) => Ok(to_value(num)),
ExprDef::ConstExpr(Const::String(str)) => Ok(to_value(str)),
ExprDef::ConstExpr(Const::Bool(val)) => Ok(to_value(val)),
ExprDef::ConstExpr(Const::RegExp(_, _, _)) => Ok(to_value(None)),
ExprDef::ConstExpr(Const::RegExp(_, _, _)) => Ok(to_value(None::<()>)),
ExprDef::BlockExpr(ref es) => {
let mut obj = to_value(None);
let mut obj = to_value(None::<()>);
for e in es.iter() {
let val = try!(self.run(e));
if e == es.last().unwrap() {

5
src/lib/js/array.rs

@ -1,15 +1,16 @@
use gc::Gc;
use js::function::NativeFunctionData;
use js::value::{to_value, ResultValue, Value, ValueData};
/// Create a new array
pub fn make_array(_: Vec<Value>, _: Value, _: Value, this: Value) -> ResultValue {
pub fn make_array(this: Value, _: Value, _: Vec<Value>) -> ResultValue {
let this_ptr = *this;
this_ptr.set_field_slice("length", to_value(0i32));
Ok(Gc::new(ValueData::Undefined))
}
/// Create a new `Array` object
pub fn _create() -> Value {
let array = to_value(make_array);
let array = to_value(make_array as NativeFunctionData);
array
}
/// Initialise the global object with the `Array` object

8
src/lib/js/error.rs

@ -1,5 +1,5 @@
use gc::Gc;
use js::function::Function;
use js::function::NativeFunctionData;
use js::object::PROTOTYPE;
use js::value::{to_value, ResultValue, Value, ValueData};
@ -11,7 +11,7 @@ pub fn make_error(this: Value, _: Value, args: Vec<Value>) -> ResultValue {
Ok(Gc::new(ValueData::Undefined))
}
/// Get the string representation of the error
pub fn to_string(_: Vec<Value>, _: Value, _: Value, this: Value) -> ResultValue {
pub fn to_string(this: Value, _: Value, _: Vec<Value>) -> ResultValue {
let name = this.get_field_slice("name");
let message = this.get_field_slice("message");
Ok(to_value(format!("{}: {}", name, message).to_string()))
@ -22,8 +22,8 @@ pub fn _create(global: Value) -> Value {
let prototype_ptr = prototype;
prototype_ptr.set_field_slice("message", to_value(""));
prototype_ptr.set_field_slice("name", to_value("Error"));
prototype_ptr.set_field_slice("toString", to_value(to_string));
let error = to_value(make_error);
prototype_ptr.set_field_slice("toString", to_value(to_string as NativeFunctionData));
let error = to_value(make_error as NativeFunctionData);
let error_ptr = error;
error_ptr.set_field_slice(PROTOTYPE, prototype);
error

1
src/lib/js/json.rs

@ -1,4 +1,3 @@
use js::function::Function;
/// The JSON Object
/// https://tc39.github.io/ecma262/#sec-json-object
use js::value::{to_value, ResultValue, Value, ValueData};

1
src/lib/js/math.rs

@ -1,4 +1,3 @@
use js::function::Function;
use js::value::{from_value, to_value, ResultValue, Value};
use rand::random;
use std::f64;

2
src/lib/js/string.rs

@ -22,7 +22,7 @@ pub fn _create(global: Value) -> Value {
enumerable: false,
writable: false,
value: Gc::new(ValueData::Undefined),
get: to_value(get_string_length),
get: to_value(get_string_length as NativeFunctionData),
set: Gc::new(ValueData::Undefined),
};
proto.set_prop_slice("length", prop);

2
src/lib/js/value.rs

@ -7,7 +7,7 @@ use serde_json::Value as JSONValue;
use std::collections::HashMap;
use std::f64::NAN;
use std::fmt;
use std::fmt::{Display, Formatter, Result as FmtResult};
use std::fmt::Display;
use std::iter::FromIterator;
use std::ops::Deref;
use std::ops::DerefMut;

Loading…
Cancel
Save