Skip to content

Commit

Permalink
Fix build after rebase
Browse files Browse the repository at this point in the history
  • Loading branch information
aapoalas committed Sep 17, 2023
1 parent d82026f commit dbefca2
Show file tree
Hide file tree
Showing 24 changed files with 279 additions and 162 deletions.
15 changes: 5 additions & 10 deletions nova_vm/src/builtins/ordinary.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ use crate::{
types::{InternalMethods, Object, PropertyDescriptor, PropertyKey, Value},
};

use super::ArgumentsList;

/// 10.1 Ordinary Object Internal Methods and Internal Slots
/// https://tc39.es/ecma262/#sec-ordinary-object-internal-methods-and-internal-slots
pub static METHODS: InternalMethods = InternalMethods {
Expand Down Expand Up @@ -37,7 +35,7 @@ fn get_prototype_of(agent: &mut Agent, object: Object) -> Option<Object> {
pub fn ordinary_get_prototype_of(agent: &mut Agent, object: Object) -> Option<Object> {
// 1. Return O.[[Prototype]].
// TODO: This is wrong.
Some(Object::new(object.prototype(agent).unwrap()))
Some(Object::try_from(object.prototype(agent).unwrap()).unwrap())
}

/// 10.1.2 [[SetPrototypeOf]] ( V )
Expand Down Expand Up @@ -105,7 +103,8 @@ pub fn ordinary_set_prototype_of(

// ii. Else, set p to p.[[Prototype]].
// TODO: This is wrong
parent_prototype_outer = Some(Object::new(parent_prototype.prototype(agent).unwrap()));
parent_prototype_outer =
Some(Object::try_from(parent_prototype.prototype(agent).unwrap()).unwrap());
}

// 8. Set O.[[Prototype]] to V.
Expand Down Expand Up @@ -686,12 +685,8 @@ pub fn ordinary_set_with_own_descriptor(
};

// iv. Return ? Receiver.[[DefineOwnProperty]](P, valueDesc).
return Ok((receiver.internal_methods(agent).define_own_property)(
agent,
receiver,
property_key,
value_descriptor,
));
let define_own_property = receiver.internal_methods(agent).define_own_property;
return define_own_property(agent, receiver, property_key, value_descriptor);
}
// e. Else,
else {
Expand Down
87 changes: 65 additions & 22 deletions nova_vm/src/execution/realm/intrinsics.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
use crate::{
heap::BuiltinObjectIndexes,
types::{Object, Value},
heap::{
indexes::{FunctionIndex, ObjectIndex},
BuiltinObjectIndexes,
},
types::Object,
};

// TODO: We should probably consider lazily loading intrinsics. This would
Expand All @@ -12,42 +15,58 @@ pub struct Intrinsics;
impl Intrinsics {
/// %Array%
pub const fn array() -> Object {
Object::Function(BuiltinObjectIndexes::ArrayConstructorIndex.into())
Object::Function(FunctionIndex::from_u32_index(
BuiltinObjectIndexes::ArrayConstructorIndex as u32,
))
}

/// %Array.prototype%
pub const fn array_prototype() -> Object {
Object::Object(BuiltinObjectIndexes::ArrayPrototypeIndex.into())
Object::Object(ObjectIndex::from_u32_index(
BuiltinObjectIndexes::ArrayPrototypeIndex as u32,
))
}

/// %BigInt%
pub const fn big_int() -> Object {
Object::Function(BuiltinObjectIndexes::BigintConstructorIndex.into())
Object::Function(FunctionIndex::from_u32_index(
BuiltinObjectIndexes::BigintConstructorIndex as u32,
))
}

/// %BigInt.prototype%
pub const fn big_int_prototype() -> Object {
Object::Object(BuiltinObjectIndexes::BigintPrototypeIndex.into())
Object::Object(ObjectIndex::from_u32_index(
BuiltinObjectIndexes::BigintPrototypeIndex as u32,
))
}

/// %Boolean%
pub const fn boolean() -> Object {
Object::Function(BuiltinObjectIndexes::BooleanConstructorIndex.into())
Object::Function(FunctionIndex::from_u32_index(
BuiltinObjectIndexes::BooleanConstructorIndex as u32,
))
}

/// %Boolean.prototype%
pub const fn boolean_prototype() -> Object {
Object::Object(BuiltinObjectIndexes::BooleanPrototypeIndex.into())
Object::Object(ObjectIndex::from_u32_index(
BuiltinObjectIndexes::BooleanPrototypeIndex as u32,
))
}

/// %Error%
pub const fn error() -> Object {
Object::Function(BuiltinObjectIndexes::ErrorConstructorIndex.into())
Object::Function(FunctionIndex::from_u32_index(
BuiltinObjectIndexes::ErrorConstructorIndex as u32,
))
}

/// %Error.prototype%
pub const fn error_prototype() -> Object {
Object::Object(BuiltinObjectIndexes::ErrorPrototypeIndex.into())
Object::Object(ObjectIndex::from_u32_index(
BuiltinObjectIndexes::ErrorPrototypeIndex as u32,
))
}

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

/// %EvalError%
pub const fn eval_error() -> Object {
Object::Function(BuiltinObjectIndexes::ArrayConstructorIndex.into())
Object::Function(FunctionIndex::from_u32_index(
BuiltinObjectIndexes::ArrayConstructorIndex as u32,
))
}

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

/// %Function%
pub const fn function() -> Object {
Object::Function(BuiltinObjectIndexes::FunctionConstructorIndex.into())
Object::Function(FunctionIndex::from_u32_index(
BuiltinObjectIndexes::FunctionConstructorIndex as u32,
))
}

/// %Function.prototype%
pub const fn function_prototype() -> Object {
// 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())
Object::Object(ObjectIndex::from_u32_index(
BuiltinObjectIndexes::FunctionPrototypeIndex as u32,
))
}

/// %isFinite%
Expand All @@ -90,27 +115,37 @@ impl Intrinsics {

/// %Math%
pub const fn math() -> Object {
Object::Object(BuiltinObjectIndexes::MathObjectIndex.into())
Object::Object(ObjectIndex::from_u32_index(
BuiltinObjectIndexes::MathObjectIndex as u32,
))
}

/// %Number%
pub const fn number() -> Object {
Object::Function(BuiltinObjectIndexes::NumberConstructorIndex.into())
Object::Function(FunctionIndex::from_u32_index(
BuiltinObjectIndexes::NumberConstructorIndex as u32,
))
}

/// %Number.prototype%
pub const fn number_prototype() -> Object {
Object::Object(BuiltinObjectIndexes::NumberPrototypeIndex.into())
Object::Object(ObjectIndex::from_u32_index(
BuiltinObjectIndexes::NumberPrototypeIndex as u32,
))
}

/// %Object%
pub const fn object() -> Object {
Object::Function(BuiltinObjectIndexes::ObjectConstructorIndex.into())
Object::Function(FunctionIndex::from_u32_index(
BuiltinObjectIndexes::ObjectConstructorIndex as u32,
))
}

/// %Object.prototype%
pub const fn object_prototype() -> Object {
Object::Object(BuiltinObjectIndexes::ObjectPrototypeIndex.into())
Object::Object(ObjectIndex::from_u32_index(
BuiltinObjectIndexes::ObjectPrototypeIndex as u32,
))
}

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

/// %String%
pub const fn string() -> Object {
Object::Function(BuiltinObjectIndexes::StringConstructorIndex.into())
Object::Function(FunctionIndex::from_u32_index(
BuiltinObjectIndexes::StringConstructorIndex as u32,
))
}

/// %String.prototype%
pub const fn string_prototype() -> Object {
Object::Object(BuiltinObjectIndexes::StringPrototypeIndex.into())
Object::Object(ObjectIndex::from_u32_index(
BuiltinObjectIndexes::StringPrototypeIndex as u32,
))
}

/// %Symbol%
pub const fn symbol() -> Object {
Object::Function(BuiltinObjectIndexes::SymbolConstructorIndex.into())
Object::Function(FunctionIndex::from_u32_index(
BuiltinObjectIndexes::SymbolConstructorIndex as u32,
))
}

/// %Symbol.prototype%
pub const fn symbol_prototype() -> Object {
Object::Object(BuiltinObjectIndexes::SymbolPrototypeIndex.into())
Object::Object(ObjectIndex::from_u32_index(
BuiltinObjectIndexes::SymbolPrototypeIndex as u32,
))
}

/// %SyntaxError%
Expand Down
42 changes: 21 additions & 21 deletions nova_vm/src/heap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ mod function;
mod heap_bits;
mod heap_constants;
mod heap_gc;
pub(crate) mod indexes;
pub mod indexes;
mod math;
mod number;
mod object;
mod regexp;
mod string;
mod symbol;

pub(crate) use self::heap_constants::BuiltinObjectIndexes;
pub use self::heap_constants::BuiltinObjectIndexes;

use self::{
array::{initialize_array_heap, ArrayHeapData},
Expand Down Expand Up @@ -51,18 +51,18 @@ pub struct Heap {
/// ElementsArrays is where all element arrays live;
/// Element arrays are static arrays of Values plus
/// a HashMap of possible property descriptors.
pub(crate) elements: ElementArrays,
pub(crate) arrays: Vec<Option<ArrayHeapData>>,
pub(crate) bigints: Vec<Option<BigIntHeapData>>,
pub(crate) errors: Vec<Option<ErrorHeapData>>,
pub(crate) functions: Vec<Option<FunctionHeapData>>,
pub(crate) dates: Vec<Option<DateHeapData>>,
pub(crate) globals: Vec<Value>,
pub(crate) numbers: Vec<Option<NumberHeapData>>,
pub(crate) objects: Vec<Option<ObjectHeapData>>,
pub(crate) regexps: Vec<Option<RegExpHeapData>>,
pub(crate) strings: Vec<Option<StringHeapData>>,
pub(crate) symbols: Vec<Option<SymbolHeapData>>,
pub elements: ElementArrays,
pub arrays: Vec<Option<ArrayHeapData>>,
pub bigints: Vec<Option<BigIntHeapData>>,
pub errors: Vec<Option<ErrorHeapData>>,
pub functions: Vec<Option<FunctionHeapData>>,
pub dates: Vec<Option<DateHeapData>>,
pub globals: Vec<Value>,
pub numbers: Vec<Option<NumberHeapData>>,
pub objects: Vec<Option<ObjectHeapData>>,
pub regexps: Vec<Option<RegExpHeapData>>,
pub strings: Vec<Option<StringHeapData>>,
pub symbols: Vec<Option<SymbolHeapData>>,
}

pub trait CreateHeapData<T, F> {
Expand Down Expand Up @@ -214,7 +214,7 @@ impl Heap {
heap
}

pub(crate) fn alloc_string(&mut self, message: &str) -> StringIndex {
pub fn alloc_string(&mut self, message: &str) -> StringIndex {
let found = self.strings.iter().position(|opt| {
opt.as_ref()
.map_or(false, |data| data.data == Wtf8::from_str(message))
Expand All @@ -233,12 +233,12 @@ impl Heap {
}
}

pub(crate) fn alloc_number(&mut self, number: f64) -> NumberIndex {
pub fn alloc_number(&mut self, number: f64) -> NumberIndex {
self.numbers.push(Some(NumberHeapData::new(number)));
NumberIndex::last(&self.numbers)
}

pub(crate) fn create_function(
pub fn create_function(
&mut self,
name: Value,
length: u8,
Expand Down Expand Up @@ -278,7 +278,7 @@ impl Heap {
index
}

pub(crate) fn create_object(&mut self, entries: Vec<ObjectEntry>) -> ObjectIndex {
pub fn create_object(&mut self, entries: Vec<ObjectEntry>) -> ObjectIndex {
let (keys, values) = self.elements.create_object_entries(entries);
let object_data = ObjectHeapData {
extensible: true,
Expand All @@ -290,7 +290,7 @@ impl Heap {
ObjectIndex::last(&self.objects)
}

pub(crate) fn create_null_object(&mut self, entries: Vec<ObjectEntry>) -> ObjectIndex {
pub fn create_null_object(&mut self, entries: Vec<ObjectEntry>) -> ObjectIndex {
let (keys, values) = self.elements.create_object_entries(entries);
let object_data = ObjectHeapData {
extensible: true,
Expand All @@ -302,7 +302,7 @@ impl Heap {
ObjectIndex::last(&self.objects)
}

pub(crate) fn create_object_with_prototype(&mut self, prototype: Value) -> ObjectIndex {
pub fn create_object_with_prototype(&mut self, prototype: Value) -> ObjectIndex {
let (keys, values) = self.elements.create_object_entries(vec![]);
let object_data = ObjectHeapData {
extensible: true,
Expand All @@ -314,7 +314,7 @@ impl Heap {
ObjectIndex::last(&self.objects)
}

pub(crate) fn insert_builtin_object(
pub fn insert_builtin_object(
&mut self,
index: BuiltinObjectIndexes,
extensible: bool,
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 @@ -16,7 +16,7 @@ use super::{
};

#[derive(Debug, Clone, Copy)]
pub(crate) struct ArrayHeapData {
pub struct ArrayHeapData {
pub object_index: Option<ObjectIndex>,
// TODO: Use SmallVec<[Value; 4]>
pub elements: ElementsVector,
Expand Down
4 changes: 2 additions & 2 deletions nova_vm/src/heap/bigint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ use crate::{
use num_bigint_dig::BigInt;

#[derive(Debug, Clone)]
pub(crate) struct BigIntHeapData {
pub struct BigIntHeapData {
pub(super) data: BigInt,
}

impl BigIntHeapData {
pub(crate) fn try_into_f64(&self) -> Option<f64> {
pub fn try_into_f64(&self) -> Option<f64> {
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 @@ -17,7 +17,7 @@ use super::{
};

#[derive(Debug, Clone, Copy)]
pub(crate) struct DateHeapData {
pub struct DateHeapData {
pub(super) object_index: ObjectIndex,
pub(super) _date: SystemTime,
}
Expand Down
Loading

0 comments on commit dbefca2

Please sign in to comment.