Skip to content

Commit

Permalink
Merge branch 'main' into feat/environments
Browse files Browse the repository at this point in the history
  • Loading branch information
aapoalas authored Nov 24, 2023
2 parents d2e7fc9 + 36fb34a commit 9a0f381
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 27 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
## Warning: This project is a Work In Progress, and is very far from being suitable for use
# Nova - Your favorite javascript and wasm engine

## :warning: This project is a Work In Progress, and is very far from being suitable for use :warning:

Nova is a [JavaScript](https://tc39.es/ecma262) and
[WebAssembly](https://webassembly.org) engine written in Rust.
Expand Down
8 changes: 4 additions & 4 deletions nova_cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
clap = { version = "4.3", features = ["derive"] }
oxc_parser = "0.1.0"
oxc_ast = "0.1.0"
oxc_span = "0.1.0"
clap = { version = "4.4.8", features = ["derive"] }
oxc_parser = "0.3.0"
oxc_ast = "0.3.0"
oxc_span = "0.3.0"
nova_vm = { path = "../nova_vm" }
16 changes: 8 additions & 8 deletions nova_vm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
gc = { version = "0.4", features = ["derive"] }
gc = { version = "0.5.0", features = ["derive"] }
wtf8 = "0.1"
oxc_parser = "0.1.0"
oxc_span = "0.1.0"
oxc_ast = "0.1.0"
oxc_allocator = "0.1.0"
oxc_diagnostics = "0.1.0"
num-bigint-dig = "0.8"
small_vec = "0.1"
oxc_parser = "0.3.0"
oxc_span = "0.3.0"
oxc_ast = "0.3.0"
oxc_allocator = "0.3.0"
oxc_diagnostics = "0.3.0"
num-bigint-dig = "0.8.4"
small_vec = "0.1.2"
4 changes: 2 additions & 2 deletions nova_vm/README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
## Project structure
# Project structure

The Nova VM source structure is as follows:

Expand All @@ -8,7 +8,7 @@ The Nova VM source structure is as follows:
1. The `heap` folder contains the setup for the heap of the VM and the direct
APIs to work with it.

### ECMAScript folder structure
## ECMAScript folder structure

The ECMAScript folder will have its own READMEs to better describe various
details of the structure but the basic idea is to stay fairly close to the
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,10 +154,10 @@ pub(crate) fn iterator_next(
/// The abstract operation IteratorComplete takes argument iterResult (an
/// Object) and returns either a normal completion containing a Boolean or a
/// throw completion.
pub(crate) fn iterator_complete(agent: &mut Agent, iter_result: Object) -> JsResult<Value> {
pub(crate) fn iterator_complete(agent: &mut Agent, iter_result: Object) -> JsResult<bool> {
// 1. Return ToBoolean(? Get(iterResult, "done")).
let done = get(agent, iter_result, String::from_small_string("done").into())?;
to_boolean(agent, done)
Ok(to_boolean(agent, done))
}

/// [7.4.6 IteratorValue ( iterResult )](https://tc39.es/ecma262/#sec-iteratorvalue)
Expand Down Expand Up @@ -196,7 +196,7 @@ pub(crate) fn iterator_step(
let done = iterator_complete(agent, result)?;

// 3. If done is true, return false.
if done.is_true() {
if done {
return Ok(None);
}

Expand Down
25 changes: 16 additions & 9 deletions nova_vm/src/ecmascript/abstract_operations/type_conversion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

use crate::{
ecmascript::{
execution::{agent::JsError, Agent, JsResult},
execution::{agent::ExceptionType, agent::JsError, Agent, JsResult},
types::{BigInt, Number, Object, PropertyKey, String, Value},
},
heap::WellKnownSymbolIndexes,
Expand Down Expand Up @@ -140,10 +140,10 @@ pub(crate) fn ordinary_to_primitive(
}

/// ### [7.1.2 ToBoolean ( argument )](https://tc39.es/ecma262/#sec-toboolean)
pub(crate) fn to_boolean(agent: &mut Agent, argument: Value) -> JsResult<Value> {
pub(crate) fn to_boolean(agent: &mut Agent, argument: Value) -> bool {
// 1. If argument is a Boolean, return argument.
if argument.is_boolean() {
return Ok(argument);
if let Value::Boolean(ret) = argument {
return ret;
}

// 2. If argument is one of undefined, null, +0𝔽, -0𝔽, NaN, 0ℤ, or the empty String, return false.
Expand All @@ -155,13 +155,13 @@ pub(crate) fn to_boolean(agent: &mut Agent, argument: Value) -> JsResult<Value>
|| argument.is_nan(agent)
|| argument.is_empty_string()
{
return Ok(false.into());
return false;
}

// 3. NOTE: This step is replaced in section B.3.6.1.

// 4. Return true.
Ok(true.into())
true
}

/// ### [7.1.3 ToNumeric ( value )](https://tc39.es/ecma262/#sec-tonumeric)
Expand All @@ -186,8 +186,15 @@ pub(crate) fn to_number(agent: &mut Agent, argument: Value) -> JsResult<Number>
}

// 2. If argument is either a Symbol or a BigInt, throw a TypeError exception.
if argument.is_symbol() || argument.is_bigint() {
todo!();
if argument.is_symbol() {
return Err(
agent.throw_exception(ExceptionType::TypeError, "cannot convert symbol to number")
);
}
if argument.is_bigint() {
return Err(
agent.throw_exception(ExceptionType::TypeError, "cannot convert bigint to number")
);
}

// 3. If argument is undefined, return NaN.
Expand All @@ -207,7 +214,7 @@ pub(crate) fn to_number(agent: &mut Agent, argument: Value) -> JsResult<Number>

// 6. If argument is a String, return StringToNumber(argument).
if argument.is_string() {
todo!();
todo!("implement StringToNumber");
}

// 7. Assert: argument is an Object.
Expand Down

0 comments on commit 9a0f381

Please sign in to comment.