Skip to content

Commit

Permalink
Fix some post-rebase issues
Browse files Browse the repository at this point in the history
  • Loading branch information
aapoalas committed Sep 10, 2023
1 parent 5afd047 commit d82026f
Show file tree
Hide file tree
Showing 20 changed files with 57 additions and 102 deletions.
2 changes: 1 addition & 1 deletion nova_vm/src/builtins/builtin_function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ pub fn create_builtin_function<'a, 'b: 'a>(
// a. Perform SetFunctionName(func, name, prefix).

// 13. Return func.
Function::new(Value::Function(func))
Function(func)
}

pub fn define_builtin_function<'a, 'b>(
Expand Down
81 changes: 23 additions & 58 deletions nova_vm/src/execution/realm/intrinsics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,58 +12,42 @@ pub struct Intrinsics;
impl Intrinsics {
/// %Array%
pub const fn array() -> Object {
Object::new(Value::Object(
BuiltinObjectIndexes::ArrayConstructorIndex.into(),
))
Object::Function(BuiltinObjectIndexes::ArrayConstructorIndex.into())
}

/// %Array.prototype%
pub const fn array_prototype() -> Object {
Object::new(Value::Object(
BuiltinObjectIndexes::ArrayPrototypeIndex.into(),
))
Object::Object(BuiltinObjectIndexes::ArrayPrototypeIndex.into())
}

/// %BigInt%
pub const fn big_int() -> Object {
Object::new(Value::Object(
BuiltinObjectIndexes::BigintConstructorIndex.into(),
))
Object::Function(BuiltinObjectIndexes::BigintConstructorIndex.into())
}

/// %BigInt.prototype%
pub const fn big_int_prototype() -> Object {
Object::new(Value::Object(
BuiltinObjectIndexes::BigintPrototypeIndex.into(),
))
Object::Object(BuiltinObjectIndexes::BigintPrototypeIndex.into())
}

/// %Boolean%
pub const fn boolean() -> Object {
Object::new(Value::Object(
BuiltinObjectIndexes::BooleanConstructorIndex.into(),
))
Object::Function(BuiltinObjectIndexes::BooleanConstructorIndex.into())
}

/// %Boolean.prototype%
pub const fn boolean_prototype() -> Object {
Object::new(Value::Object(
BuiltinObjectIndexes::BooleanPrototypeIndex.into(),
))
Object::Object(BuiltinObjectIndexes::BooleanPrototypeIndex.into())
}

/// %Error%
pub const fn error() -> Object {
Object::new(Value::Object(
BuiltinObjectIndexes::ErrorConstructorIndex.into(),
))
Object::Function(BuiltinObjectIndexes::ErrorConstructorIndex.into())
}

/// %Error.prototype%
pub const fn error_prototype() -> Object {
Object::new(Value::Object(
BuiltinObjectIndexes::ErrorPrototypeIndex.into(),
))
Object::Object(BuiltinObjectIndexes::ErrorPrototypeIndex.into())
}

/// %eval%
Expand All @@ -73,9 +57,7 @@ impl Intrinsics {

/// %EvalError%
pub const fn eval_error() -> Object {
Object::new(Value::Object(
BuiltinObjectIndexes::ArrayConstructorIndex.into(),
))
Object::Function(BuiltinObjectIndexes::ArrayConstructorIndex.into())
}

/// %EvalError.prototype%
Expand All @@ -85,16 +67,15 @@ impl Intrinsics {

/// %Function%
pub const fn function() -> Object {
Object::new(Value::Object(
BuiltinObjectIndexes::FunctionConstructorIndex.into(),
))
Object::Function(BuiltinObjectIndexes::FunctionConstructorIndex.into())
}

/// %Function.prototype%
pub const fn function_prototype() -> Object {
Object::new(Value::Object(
BuiltinObjectIndexes::FunctionPrototypeIndex.into(),
))
// Note: This is not spec-compliant. Function prototype should
// be a function that always returns undefined no matter how
// it is called. That's stupid so we do not have that.
Object::Object(BuiltinObjectIndexes::FunctionPrototypeIndex.into())
}

/// %isFinite%
Expand All @@ -109,35 +90,27 @@ impl Intrinsics {

/// %Math%
pub const fn math() -> Object {
Object::new(Value::Object(BuiltinObjectIndexes::MathObjectIndex.into()))
Object::Object(BuiltinObjectIndexes::MathObjectIndex.into())
}

/// %Number%
pub const fn number() -> Object {
Object::new(Value::Object(
BuiltinObjectIndexes::NumberConstructorIndex.into(),
))
Object::Function(BuiltinObjectIndexes::NumberConstructorIndex.into())
}

/// %Number.prototype%
pub const fn number_prototype() -> Object {
Object::new(Value::Object(
BuiltinObjectIndexes::NumberPrototypeIndex.into(),
))
Object::Object(BuiltinObjectIndexes::NumberPrototypeIndex.into())
}

/// %Object%
pub const fn object() -> Object {
Object::new(Value::Object(
BuiltinObjectIndexes::ObjectConstructorIndex.into(),
))
Object::Function(BuiltinObjectIndexes::ObjectConstructorIndex.into())
}

/// %Object.prototype%
pub const fn object_prototype() -> Object {
Object::new(Value::Object(
BuiltinObjectIndexes::ObjectPrototypeIndex.into(),
))
Object::Object(BuiltinObjectIndexes::ObjectPrototypeIndex.into())
}

/// %Object.prototype.toString%
Expand Down Expand Up @@ -172,30 +145,22 @@ impl Intrinsics {

/// %String%
pub const fn string() -> Object {
Object::new(Value::Object(
BuiltinObjectIndexes::StringConstructorIndex.into(),
))
Object::Function(BuiltinObjectIndexes::StringConstructorIndex.into())
}

/// %String.prototype%
pub const fn string_prototype() -> Object {
Object::new(Value::Object(
BuiltinObjectIndexes::StringPrototypeIndex.into(),
))
Object::Object(BuiltinObjectIndexes::StringPrototypeIndex.into())
}

/// %Symbol%
pub const fn symbol() -> Object {
Object::new(Value::Object(
BuiltinObjectIndexes::SymbolConstructorIndex.into(),
))
Object::Function(BuiltinObjectIndexes::SymbolConstructorIndex.into())
}

/// %Symbol.prototype%
pub const fn symbol_prototype() -> Object {
Object::new(Value::Object(
BuiltinObjectIndexes::SymbolPrototypeIndex.into(),
))
Object::Object(BuiltinObjectIndexes::SymbolPrototypeIndex.into())
}

/// %SyntaxError%
Expand Down
4 changes: 2 additions & 2 deletions nova_vm/src/heap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,14 +151,14 @@ impl CreateHeapData<&str, String> for Heap {
impl CreateHeapData<FunctionHeapData, Function> for Heap {
fn create(&mut self, data: FunctionHeapData) -> Function {
self.functions.push(Some(data));
Function::new(Value::Function(FunctionIndex::last(&self.functions)))
Function(FunctionIndex::last(&self.functions))
}
}

impl CreateHeapData<ObjectHeapData, Object> for Heap {
fn create(&mut self, data: ObjectHeapData) -> Object {
self.objects.push(Some(data));
Object::new(Value::Object(ObjectIndex::last(&self.objects)))
Object::Object(ObjectIndex::last(&self.objects))
}
}

Expand Down
2 changes: 1 addition & 1 deletion nova_vm/src/heap/array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ pub fn initialize_array_heap(heap: &mut Heap) {
heap.functions
[get_constructor_index(BuiltinObjectIndexes::ArrayConstructorIndex).into_index()] =
Some(FunctionHeapData {
object_index: BuiltinObjectIndexes::ArrayConstructorIndex.into(),
object_index: Some(BuiltinObjectIndexes::ArrayConstructorIndex.into()),
length: 1,
// uses_arguments: false,
// bound: None,
Expand Down
2 changes: 1 addition & 1 deletion nova_vm/src/heap/bigint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ pub fn initialize_bigint_heap(heap: &mut Heap) {
heap.functions
[get_constructor_index(BuiltinObjectIndexes::BigintConstructorIndex).into_index()] =
Some(FunctionHeapData {
object_index: ObjectIndex::last(&heap.objects),
object_index: Some(ObjectIndex::last(&heap.objects)),
length: 1,
// uses_arguments: false,
// bound: None,
Expand Down
2 changes: 1 addition & 1 deletion nova_vm/src/heap/boolean.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ pub fn initialize_boolean_heap(heap: &mut Heap) {
heap.functions
[get_constructor_index(BuiltinObjectIndexes::BooleanConstructorIndex).into_index()] =
Some(FunctionHeapData {
object_index: BuiltinObjectIndexes::BooleanConstructorIndex.into(),
object_index: Some(BuiltinObjectIndexes::BooleanConstructorIndex.into()),
length: 1,
// uses_arguments: false,
// bound: None,
Expand Down
2 changes: 1 addition & 1 deletion nova_vm/src/heap/date.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ pub fn initialize_date_heap(heap: &mut Heap) {
heap.functions
[get_constructor_index(BuiltinObjectIndexes::DateConstructorIndex).into_index()] =
Some(FunctionHeapData {
object_index: BuiltinObjectIndexes::DateConstructorIndex.into(),
object_index: Some(BuiltinObjectIndexes::DateConstructorIndex.into()),
length: 1,
// uses_arguments: false,
// bound: None,
Expand Down
2 changes: 1 addition & 1 deletion nova_vm/src/heap/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ pub fn initialize_error_heap(heap: &mut Heap) {
heap.functions
[get_constructor_index(BuiltinObjectIndexes::ErrorConstructorIndex).into_index()] =
Some(FunctionHeapData {
object_index: BuiltinObjectIndexes::ErrorConstructorIndex.into(),
object_index: Some(BuiltinObjectIndexes::ErrorConstructorIndex.into()),
length: 1,
// uses_arguments: false,
// bound: None,
Expand Down
2 changes: 1 addition & 1 deletion nova_vm/src/heap/function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ pub fn initialize_function_heap(heap: &mut Heap) {
heap.functions
[get_constructor_index(BuiltinObjectIndexes::FunctionConstructorIndex).into_index()] =
Some(FunctionHeapData {
object_index: BuiltinObjectIndexes::FunctionConstructorIndex.into(),
object_index: Some(BuiltinObjectIndexes::FunctionConstructorIndex.into()),
length: 1,
// uses_arguments: false,
// bound: None,
Expand Down
4 changes: 3 additions & 1 deletion nova_vm/src/heap/heap_gc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,9 @@ pub(crate) fn heap_gc(heap: &mut Heap) {
}
marked.store(true, Ordering::Relaxed);
let data = heap.functions.get(index).unwrap().as_ref().unwrap();
queues.objects.push(data.object_index);
if let Some(object_index) = data.object_index {
queues.objects.push(object_index);
}
// if let Some(bound) = &data.bound {
// bound.iter().for_each(|&value| {
// queues.push_value(value);
Expand Down
2 changes: 1 addition & 1 deletion nova_vm/src/heap/number.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ pub fn initialize_number_heap(heap: &mut Heap) {
heap.functions
[get_constructor_index(BuiltinObjectIndexes::NumberConstructorIndex).into_index()] =
Some(FunctionHeapData {
object_index: BuiltinObjectIndexes::NumberConstructorIndex.into(),
object_index: Some(BuiltinObjectIndexes::NumberConstructorIndex.into()),
length: 1,
// uses_arguments: false,
// bound: None,
Expand Down
2 changes: 1 addition & 1 deletion nova_vm/src/heap/object.rs
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ pub fn initialize_object_heap(heap: &mut Heap) {
heap.functions
[get_constructor_index(BuiltinObjectIndexes::ObjectConstructorIndex).into_index()] =
Some(FunctionHeapData {
object_index: BuiltinObjectIndexes::ObjectConstructorIndex.into(),
object_index: Some(BuiltinObjectIndexes::ObjectConstructorIndex.into()),
length: 1,
// uses_arguments: false,
// bound: None,
Expand Down
2 changes: 1 addition & 1 deletion nova_vm/src/heap/regexp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ pub fn initialize_regexp_heap(heap: &mut Heap) {
heap.functions
[get_constructor_index(BuiltinObjectIndexes::RegExpConstructorIndex).into_index()] =
Some(FunctionHeapData {
object_index: BuiltinObjectIndexes::RegExpConstructorIndex.into(),
object_index: Some(BuiltinObjectIndexes::RegExpConstructorIndex.into()),
length: 1,
// uses_arguments: false,
// bound: None,
Expand Down
2 changes: 1 addition & 1 deletion nova_vm/src/heap/string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ pub fn initialize_string_heap(heap: &mut Heap) {
heap.functions
[get_constructor_index(BuiltinObjectIndexes::StringConstructorIndex).into_index()] =
Some(FunctionHeapData {
object_index: BuiltinObjectIndexes::StringConstructorIndex.into(),
object_index: Some(BuiltinObjectIndexes::StringConstructorIndex.into()),
length: 1,
// uses_arguments: false,
// bound: None,
Expand Down
2 changes: 1 addition & 1 deletion nova_vm/src/heap/symbol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ pub fn initialize_symbol_heap(heap: &mut Heap) {
heap.functions
[get_constructor_index(BuiltinObjectIndexes::SymbolConstructorIndex).into_index()] =
Some(FunctionHeapData {
object_index: BuiltinObjectIndexes::SymbolConstructorIndex.into(),
object_index: Some(BuiltinObjectIndexes::SymbolConstructorIndex.into()),
length: 1,
// uses_arguments: false,
// bound: None,
Expand Down
9 changes: 4 additions & 5 deletions nova_vm/src/types/language/function.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
use crate::heap::{FunctionHeapData, Handle};

use super::{Object, Value};
use crate::heap::indexes::FunctionIndex;

/// https://tc39.es/ecma262/#function-object
#[derive(Clone, Copy)]
pub struct Function(pub Handle<FunctionHeapData>);
pub struct Function(pub FunctionIndex);

impl std::fmt::Debug for Function {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{:?}", self.0)
}
}

impl From<Handle<FunctionHeapData>> for Function {
fn from(value: Handle<FunctionHeapData>) -> Self {
impl From<FunctionIndex> for Function {
fn from(value: FunctionIndex) -> Self {
Function(value)
}
}
Expand Down
2 changes: 1 addition & 1 deletion nova_vm/src/types/language/object.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ impl From<Object> for Value {
fn from(value: Object) -> Self {
match value {
Object::Object(x) => Value::Object(x),
Object::Array(x) => Value::ArrayObject(x),
Object::Array(x) => Value::Array(x),
Object::Function(x) => Value::Function(x),
}
}
Expand Down
14 changes: 7 additions & 7 deletions nova_vm/src/types/language/object/property_key.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
use crate::{
execution::Agent,
heap::{GetHeapData, Handle, StringHeapData},
heap::{indexes::StringIndex, GetHeapData},
types::{String, Value},
SmallInteger, SmallString,
};

#[derive(Debug, Clone, Copy)]
pub enum PropertyKey {
String(Handle<StringHeapData>),
String(StringIndex),
SmallString(SmallString),
SmallInteger(SmallInteger),
}

impl From<Handle<StringHeapData>> for PropertyKey {
fn from(value: Handle<StringHeapData>) -> Self {
impl From<StringIndex> for PropertyKey {
fn from(value: StringIndex) -> Self {
PropertyKey::String(value)
}
}
Expand Down Expand Up @@ -45,7 +45,7 @@ impl TryFrom<Value> for PropertyKey {
match value {
Value::String(x) => Ok(PropertyKey::String(x)),
Value::SmallString(x) => Ok(PropertyKey::SmallString(x)),
Value::IntegerNumber(x) => Ok(PropertyKey::SmallInteger(x)),
Value::Integer(x) => Ok(PropertyKey::SmallInteger(x)),
_ => Err(()),
}
}
Expand All @@ -56,7 +56,7 @@ impl From<PropertyKey> for Value {
match value {
PropertyKey::String(x) => Value::String(x),
PropertyKey::SmallString(x) => Value::SmallString(x),
PropertyKey::SmallInteger(x) => Value::IntegerNumber(x),
PropertyKey::SmallInteger(x) => Value::Integer(x),
}
}
}
Expand All @@ -68,7 +68,7 @@ impl PropertyKey {

pub fn is_array_index(self) -> bool {
// TODO: string check
matches!(self.into_value(), Value::IntegerNumber(_))
matches!(self.into_value(), Value::Integer(_))
}

pub(self) fn is_str_eq_num(s: &str, n: i64) -> bool {
Expand Down
Loading

0 comments on commit d82026f

Please sign in to comment.