From bc479d851b66d7c5fbcc989ce2658ba524cf97a2 Mon Sep 17 00:00:00 2001 From: vimirage Date: Fri, 10 Nov 2023 07:44:53 +0000 Subject: [PATCH 1/2] fix(idk) make to_boolean not return a Value (#72) * Update type_conversion.rs * Update operations_on_iterator_objects.rs * fix my fix * fix type "conver" Co-authored by sno2 * Update type_conversion.rs * Update operations_on_iterator_objects.rs * Boolean -> Value::Boolean * Update operations_on_iterator_objects.rs * Update type_conversion.rs --- .../operations_on_iterator_objects.rs | 6 ++--- .../abstract_operations/type_conversion.rs | 25 ++++++++++++------- 2 files changed, 19 insertions(+), 12 deletions(-) diff --git a/nova_vm/src/ecmascript/abstract_operations/operations_on_iterator_objects.rs b/nova_vm/src/ecmascript/abstract_operations/operations_on_iterator_objects.rs index 7a41b4e7..1dde5fe6 100644 --- a/nova_vm/src/ecmascript/abstract_operations/operations_on_iterator_objects.rs +++ b/nova_vm/src/ecmascript/abstract_operations/operations_on_iterator_objects.rs @@ -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 { +pub(crate) fn iterator_complete(agent: &mut Agent, iter_result: Object) -> JsResult { // 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) @@ -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); } diff --git a/nova_vm/src/ecmascript/abstract_operations/type_conversion.rs b/nova_vm/src/ecmascript/abstract_operations/type_conversion.rs index 9e41e14c..f8044ac9 100644 --- a/nova_vm/src/ecmascript/abstract_operations/type_conversion.rs +++ b/nova_vm/src/ecmascript/abstract_operations/type_conversion.rs @@ -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, @@ -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 { +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. @@ -155,13 +155,13 @@ pub(crate) fn to_boolean(agent: &mut Agent, argument: Value) -> JsResult || 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) @@ -186,8 +186,15 @@ pub(crate) fn to_number(agent: &mut Agent, argument: Value) -> JsResult } // 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. @@ -207,7 +214,7 @@ pub(crate) fn to_number(agent: &mut Agent, argument: Value) -> JsResult // 6. If argument is a String, return StringToNumber(argument). if argument.is_string() { - todo!(); + todo!("implement StringToNumber"); } // 7. Assert: argument is an Object. From 36fb34aeb1875649579a58a2774e8b85e970c4b3 Mon Sep 17 00:00:00 2001 From: Dean Srebnik <49134864+load1n9@users.noreply.github.com> Date: Mon, 13 Nov 2023 15:16:40 -0500 Subject: [PATCH 2/2] chore: bump deps and fix README --- README.md | 4 +++- nova_cli/Cargo.toml | 8 ++++---- nova_vm/Cargo.toml | 16 ++++++++-------- nova_vm/README.md | 4 ++-- 4 files changed, 17 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index 93d649c2..69938c53 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/nova_cli/Cargo.toml b/nova_cli/Cargo.toml index 324870ff..aa5475d6 100644 --- a/nova_cli/Cargo.toml +++ b/nova_cli/Cargo.toml @@ -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" } diff --git a/nova_vm/Cargo.toml b/nova_vm/Cargo.toml index e66e2a7a..c1dd9085 100644 --- a/nova_vm/Cargo.toml +++ b/nova_vm/Cargo.toml @@ -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" diff --git a/nova_vm/README.md b/nova_vm/README.md index 3c6870ad..79ad5553 100644 --- a/nova_vm/README.md +++ b/nova_vm/README.md @@ -1,4 +1,4 @@ -## Project structure +# Project structure The Nova VM source structure is as follows: @@ -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