Skip to content

Commit

Permalink
Merge branch 'master' into fix/environments
Browse files Browse the repository at this point in the history
  • Loading branch information
HalidOdat authored May 7, 2021
2 parents f52c86f + 7ee3a93 commit 80b7272
Show file tree
Hide file tree
Showing 14 changed files with 215 additions and 218 deletions.
290 changes: 144 additions & 146 deletions Cargo.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ See [Profiling](./docs/profiling.md)

```
USAGE:
boa_cli [OPTIONS] [FILE]...
boa [OPTIONS] [FILE]...
FLAGS:
-h, --help Prints help information
Expand Down
2 changes: 1 addition & 1 deletion boa/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ measureme = { version = "9.1.1", optional = true }
once_cell = { version = "1.7.2", optional = true }

[dev-dependencies]
criterion = "0.3.3"
criterion = "0.3.4"
float-cmp = "0.8.0"

[target.x86_64-unknown-linux-gnu.dev-dependencies]
Expand Down
2 changes: 1 addition & 1 deletion boa/src/builtins/array/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1017,7 +1017,7 @@ impl Array {
}
})
.collect::<Result<Vec<Option<Value>>>>()?;
let values = values.into_iter().filter_map(|v| v).collect::<Vec<_>>();
let values = values.into_iter().flatten().collect::<Vec<_>>();

Self::construct_array(&new, &values, context)
}
Expand Down
4 changes: 2 additions & 2 deletions boa/src/builtins/date/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -196,12 +196,12 @@ fn date_ctor_now_call() -> Result<(), Box<dyn std::error::Error>> {
let mut context = Context::new();

let date_time = forward(&mut context, "Date.now()");
let dt1 = u64::from_str_radix(&date_time, 10)?;
let dt1 = date_time.parse::<u64>()?;

std::thread::sleep(std::time::Duration::from_millis(1));

let date_time = forward(&mut context, "Date.now()");
let dt2 = u64::from_str_radix(&date_time, 10)?;
let dt2 = date_time.parse::<u64>()?;

assert_ne!(dt1, dt2);
Ok(())
Expand Down
33 changes: 16 additions & 17 deletions boa/src/builtins/json/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,9 +137,6 @@ impl Json {
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify
pub(crate) fn stringify(_: &Value, args: &[Value], context: &mut Context) -> Result<Value> {
let object = match args.get(0) {
Some(obj) if obj.is_symbol() || obj.is_function() || obj.is_undefined() => {
return Ok(Value::undefined())
}
None => return Ok(Value::undefined()),
Some(obj) => obj,
};
Expand Down Expand Up @@ -178,10 +175,11 @@ impl Json {
let replacer = match args.get(1) {
Some(replacer) if replacer.is_object() => replacer,
_ => {
return Ok(Value::from(json_to_pretty_string(
&object.to_json(context)?,
gap,
)))
if let Some(value) = object.to_json(context)? {
return Ok(Value::from(json_to_pretty_string(&value, gap)));
} else {
return Ok(Value::undefined());
}
}
};

Expand All @@ -208,10 +206,11 @@ impl Json {
),
);
}
Ok(Value::from(json_to_pretty_string(
&object_to_return.to_json(context)?,
gap,
)))
if let Some(value) = object_to_return.to_json(context)? {
Ok(Value::from(json_to_pretty_string(&value, gap)))
} else {
Ok(Value::undefined())
}
})
.ok_or_else(Value::undefined)?
} else if replacer_as_object.is_array() {
Expand All @@ -234,19 +233,19 @@ impl Json {
for field in fields {
let v = object.get_field(field.to_string(context)?, context)?;
if !v.is_undefined() {
let value = v.to_json(context)?;
obj_to_return.insert(field.to_string(context)?.to_string(), value);
if let Some(value) = v.to_json(context)? {
obj_to_return.insert(field.to_string(context)?.to_string(), value);
}
}
}
Ok(Value::from(json_to_pretty_string(
&JSONValue::Object(obj_to_return),
gap,
)))
} else if let Some(value) = object.to_json(context)? {
Ok(Value::from(json_to_pretty_string(&value, gap)))
} else {
Ok(Value::from(json_to_pretty_string(
&object.to_json(context)?,
gap,
)))
Ok(Value::undefined())
}
}
}
Expand Down
16 changes: 8 additions & 8 deletions boa/src/object/gcobject.rs
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,7 @@ impl GcObject {
}

/// Converts an object to JSON, checking for reference cycles and throwing a TypeError if one is found
pub(crate) fn to_json(&self, context: &mut Context) -> Result<JSONValue> {
pub(crate) fn to_json(&self, context: &mut Context) -> Result<Option<JSONValue>> {
let rec_limiter = RecursionLimiter::new(self);
if rec_limiter.live {
Err(context.construct_type_error("cyclic object value"))
Expand All @@ -402,24 +402,24 @@ impl GcObject {
let this = Value::from(self.clone());
for key in keys {
let value = this.get_field(key, context)?;
if value.is_undefined() || value.is_function() || value.is_symbol() {
arr.push(JSONValue::Null);
if let Some(value) = value.to_json(context)? {
arr.push(value);
} else {
arr.push(value.to_json(context)?);
arr.push(JSONValue::Null);
}
}
Ok(JSONValue::Array(arr))
Ok(Some(JSONValue::Array(arr)))
} else {
let mut new_obj = Map::new();
let this = Value::from(self.clone());
for k in self.borrow().keys() {
let key = k.clone();
let value = this.get_field(k.to_string(), context)?;
if !value.is_undefined() && !value.is_function() && !value.is_symbol() {
new_obj.insert(key.to_string(), value.to_json(context)?);
if let Some(value) = value.to_json(context)? {
new_obj.insert(key.to_string(), value);
}
}
Ok(JSONValue::Object(new_obj))
Ok(Some(JSONValue::Object(new_obj)))
}
}

Expand Down
4 changes: 1 addition & 3 deletions boa/src/syntax/lexer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ impl<R> Lexer<R> {
))
}
}
InputElement::RegExp | InputElement::RegExpOrTemplateTail => {
InputElement::RegExp => {
// Can be a regular expression.
RegexLiteral.lex(&mut self.cursor, start)
}
Expand Down Expand Up @@ -297,8 +297,6 @@ impl<R> Lexer<R> {
pub(crate) enum InputElement {
Div,
RegExp,
#[allow(dead_code)]
RegExpOrTemplateTail,
TemplateTail,
}

Expand Down
24 changes: 13 additions & 11 deletions boa/src/value/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -215,35 +215,37 @@ impl Value {
}

/// Converts the `Value` to `JSON`.
pub fn to_json(&self, context: &mut Context) -> Result<JSONValue> {
pub fn to_json(&self, context: &mut Context) -> Result<Option<JSONValue>> {
let to_json = self.get_field("toJSON", context)?;
if to_json.is_function() {
let json_value = context.call(&to_json, self, &[])?;
return json_value.to_json(context);
}

if self.is_function() {
return Ok(None);
}

match *self {
Self::Null => Ok(JSONValue::Null),
Self::Boolean(b) => Ok(JSONValue::Bool(b)),
Self::Null => Ok(Some(JSONValue::Null)),
Self::Boolean(b) => Ok(Some(JSONValue::Bool(b))),
Self::Object(ref obj) => obj.to_json(context),
Self::String(ref str) => Ok(JSONValue::String(str.to_string())),
Self::String(ref str) => Ok(Some(JSONValue::String(str.to_string()))),
Self::Rational(num) => {
if num.is_finite() {
Ok(JSONValue::Number(
Ok(Some(JSONValue::Number(
JSONNumber::from_str(&Number::to_native_string(num))
.expect("invalid number found"),
))
)))
} else {
Ok(JSONValue::Null)
Ok(Some(JSONValue::Null))
}
}
Self::Integer(val) => Ok(JSONValue::Number(JSONNumber::from(val))),
Self::Integer(val) => Ok(Some(JSONValue::Number(JSONNumber::from(val)))),
Self::BigInt(_) => {
Err(context.construct_type_error("BigInt value can't be serialized in JSON"))
}
Self::Symbol(_) | Self::Undefined => {
unreachable!("Symbols and Undefined JSON Values depend on parent type");
}
Self::Symbol(_) | Self::Undefined => Ok(None),
}
}

Expand Down
2 changes: 1 addition & 1 deletion boa_cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ rustyline-derive = "0.4.0"
structopt = "0.3.21"
serde_json = "1.0.64"
colored = "2.0.0"
regex = "1.4.6"
regex = "1.5.4"
lazy_static = "1.4.0"

[features]
Expand Down
2 changes: 1 addition & 1 deletion boa_cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
unused_lifetimes,
unreachable_pub,
trivial_numeric_casts,
rustdoc,
rustdoc::all,
missing_debug_implementations,
missing_copy_implementations,
deprecated_in_future,
Expand Down
2 changes: 1 addition & 1 deletion boa_tester/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ serde = { version = "1.0.125", features = ["derive"] }
serde_yaml = "0.8.17"
serde_json = "1.0.64"
bitflags = "1.2.1"
regex = "1.4.6"
regex = "1.5.4"
once_cell = "1.7.2"
colored = "2.0.0"
fxhash = "0.2.1"
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@
"bootstrap": "^4.6.0",
"clean-webpack-plugin": "^3.0.0",
"copy-webpack-plugin": "^8.1.1",
"css-loader": "^5.2.2",
"css-loader": "^5.2.4",
"file-loader": "^6.2.0",
"html-webpack-plugin": "^5.3.1",
"prettier": "2.2.1",
"style-loader": "^2.0.0",
"webpack": "^5.33.2",
"webpack": "^5.36.2",
"webpack-cli": "^4.6.0",
"webpack-dev-server": "^3.11.2"
},
Expand Down
46 changes: 23 additions & 23 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,10 @@
"@types/estree" "*"
"@types/json-schema" "*"

"@types/estree@*", "@types/estree@^0.0.46":
version "0.0.46"
resolved "https://registry.yarnpkg.com/@types/estree/-/estree-0.0.46.tgz#0fb6bfbbeabd7a30880504993369c4bf1deab1fe"
integrity sha512-laIjwTQaD+5DukBZaygQ79K1Z0jb1bPEMRrkXSLjtCcZm+abyp5YbrqpSLzD42FwWW6gK/aS4NYpJ804nG2brg==
"@types/estree@*", "@types/estree@^0.0.47":
version "0.0.47"
resolved "https://registry.yarnpkg.com/@types/estree/-/estree-0.0.47.tgz#d7a51db20f0650efec24cd04994f523d93172ed4"
integrity sha512-c5ciR06jK8u9BstrmJyO97m+klJrrhCf9u3rLu3DEAJBirxRqSCvDQoYKmxuYwQI5SZChAWu+tq9oVlGRuzPAg==

"@types/glob@^7.1.1":
version "7.1.3"
Expand Down Expand Up @@ -286,10 +286,10 @@ accepts@~1.3.4, accepts@~1.3.5, accepts@~1.3.7:
mime-types "~2.1.24"
negotiator "0.6.2"

acorn@^8.0.4:
version "8.0.4"
resolved "https://registry.yarnpkg.com/acorn/-/acorn-8.0.4.tgz#7a3ae4191466a6984eee0fe3407a4f3aa9db8354"
integrity sha512-XNP0PqF1XD19ZlLKvB7cMmnZswW4C/03pRHgirB30uSJTaS3A3V1/P4sS3HPvFmjoriPCJQs+JDSbm4bL1TxGQ==
acorn@^8.2.1:
version "8.2.2"
resolved "https://registry.yarnpkg.com/acorn/-/acorn-8.2.2.tgz#c4574e4fea298d6e6ed4b85ab844b06dd59f26d6"
integrity sha512-VrMS8kxT0e7J1EX0p6rI/E0FbfOVcvBpbIqHThFv+f8YrZIlMfVotYcXKVPmTvPW8sW5miJzfUFrrvthUZg8VQ==

ajv-errors@^1.0.0:
version "1.0.1"
Expand Down Expand Up @@ -862,10 +862,10 @@ cross-spawn@^7.0.3:
shebang-command "^2.0.0"
which "^2.0.1"

css-loader@^5.2.2:
version "5.2.2"
resolved "https://registry.yarnpkg.com/css-loader/-/css-loader-5.2.2.tgz#65f2c1482255f15847ecad6cbc515cae8a5b234e"
integrity sha512-IS722y7Lh2Yq+acMR74tdf3faMOLRP2RfLwS0VzSS7T98IHtacMWJLku3A0OBTFHB07zAa4nWBhA8gfxwQVWGQ==
css-loader@^5.2.4:
version "5.2.4"
resolved "https://registry.yarnpkg.com/css-loader/-/css-loader-5.2.4.tgz#e985dcbce339812cb6104ef3670f08f9893a1536"
integrity sha512-OFYGyINCKkdQsTrSYxzGSFnGS4gNjcXkKkQgWxK138jgnPt+lepxdjSZNc8sHAl5vP3DhsJUxufWIjOwI8PMMw==
dependencies:
camelcase "^6.2.0"
icss-utils "^5.1.0"
Expand Down Expand Up @@ -1114,10 +1114,10 @@ end-of-stream@^1.1.0:
dependencies:
once "^1.4.0"

enhanced-resolve@^5.7.0:
version "5.7.0"
resolved "https://registry.yarnpkg.com/enhanced-resolve/-/enhanced-resolve-5.7.0.tgz#525c5d856680fbd5052de453ac83e32049958b5c"
integrity sha512-6njwt/NsZFUKhM6j9U8hzVyD4E4r0x7NQzhTCbcWOJ0IQjNSAoalWmb0AE51Wn+fwan5qVESWi7t2ToBxs9vrw==
enhanced-resolve@^5.8.0:
version "5.8.0"
resolved "https://registry.yarnpkg.com/enhanced-resolve/-/enhanced-resolve-5.8.0.tgz#d9deae58f9d3773b6a111a5a46831da5be5c9ac0"
integrity sha512-Sl3KRpJA8OpprrtaIswVki3cWPiPKxXuFxJXBp+zNb6s6VwNWwFRUdtmzd2ReUut8n+sCPx7QCtQ7w5wfJhSgQ==
dependencies:
graceful-fs "^4.2.4"
tapable "^2.2.0"
Expand Down Expand Up @@ -3776,20 +3776,20 @@ webpack-sources@^2.1.1:
source-list-map "^2.0.1"
source-map "^0.6.1"

webpack@^5.33.2:
version "5.33.2"
resolved "https://registry.yarnpkg.com/webpack/-/webpack-5.33.2.tgz#c049717c9b038febf5a72fd2f53319ad59a8c1fc"
integrity sha512-X4b7F1sYBmJx8mlh2B7mV5szEkE0jYNJ2y3akgAP0ERi0vLCG1VvdsIxt8lFd4st6SUy0lf7W0CCQS566MBpJg==
webpack@^5.36.2:
version "5.36.2"
resolved "https://registry.yarnpkg.com/webpack/-/webpack-5.36.2.tgz#6ef1fb2453ad52faa61e78d486d353d07cca8a0f"
integrity sha512-XJumVnnGoH2dV+Pk1VwgY4YT6AiMKpVoudUFCNOXMIVrEKPUgEwdIfWPjIuGLESAiS8EdIHX5+TiJz/5JccmRg==
dependencies:
"@types/eslint-scope" "^3.7.0"
"@types/estree" "^0.0.46"
"@types/estree" "^0.0.47"
"@webassemblyjs/ast" "1.11.0"
"@webassemblyjs/wasm-edit" "1.11.0"
"@webassemblyjs/wasm-parser" "1.11.0"
acorn "^8.0.4"
acorn "^8.2.1"
browserslist "^4.14.5"
chrome-trace-event "^1.0.2"
enhanced-resolve "^5.7.0"
enhanced-resolve "^5.8.0"
es-module-lexer "^0.4.0"
eslint-scope "^5.1.1"
events "^3.2.0"
Expand Down

0 comments on commit 80b7272

Please sign in to comment.