Skip to content

Commit

Permalink
chore: Remove duplicate PropertyKey enum
Browse files Browse the repository at this point in the history
  • Loading branch information
aapoalas committed Oct 20, 2023
1 parent 885773d commit d3bc05f
Show file tree
Hide file tree
Showing 17 changed files with 144 additions and 166 deletions.
8 changes: 3 additions & 5 deletions nova_vm/src/heap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,14 @@ use self::{
indexes::{BaseIndex, FunctionIndex, NumberIndex, ObjectIndex, StringIndex},
math::initialize_math_object,
number::{initialize_number_heap, NumberHeapData},
object::{
initialize_object_heap, ObjectEntry, ObjectHeapData, PropertyDescriptor, PropertyKey,
},
object::{initialize_object_heap, ObjectEntry, ObjectHeapData, PropertyDescriptor},
regexp::{initialize_regexp_heap, RegExpHeapData},
string::initialize_string_heap,
symbol::{initialize_symbol_heap, SymbolHeapData},
};
use crate::{
execution::{Environments, Realm, RealmIdentifier},
types::{Function, Number, Object, String, StringHeapData, Value},
types::{Function, Number, Object, PropertyKey, String, StringHeapData, Value},
};
use wtf8::{Wtf8, Wtf8Buf};

Expand Down Expand Up @@ -275,7 +273,7 @@ impl<'ctx, 'host> Heap<'ctx, 'host> {
&mut self,
name: Value,
length: u8,
uses_arguments: bool,
_uses_arguments: bool,
// behaviour: Behaviour,
) -> FunctionIndex {
let entries = vec![
Expand Down
17 changes: 8 additions & 9 deletions nova_vm/src/heap/array.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
use super::{
element_array::ElementsVector,
function::FunctionHeapData,
heap_constants::WellKnownSymbolIndexes,
indexes::{FunctionIndex, ObjectIndex},
object::ObjectEntry,
};
use crate::{
execution::JsResult,
heap::{
heap_constants::{get_constructor_index, BuiltinObjectIndexes},
Heap, PropertyDescriptor,
},
types::{Object, Value},
};

use super::{
element_array::ElementsVector,
function::FunctionHeapData,
heap_constants::WellKnownSymbolIndexes,
indexes::{FunctionIndex, ObjectIndex},
object::{ObjectEntry, PropertyKey},
types::{Object, PropertyKey, Value},
};

#[derive(Debug, Clone, Copy)]
Expand Down
9 changes: 3 additions & 6 deletions nova_vm/src/heap/array_buffer.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
use super::{
function::FunctionHeapData,
heap_constants::WellKnownSymbolIndexes,
indexes::{ArrayBufferIndex, ObjectIndex},
object::{ObjectEntry, PropertyKey},
function::FunctionHeapData, heap_constants::WellKnownSymbolIndexes, indexes::ObjectIndex,
object::ObjectEntry,
};
use crate::{
execution::JsResult,
heap::{
heap_constants::{get_constructor_index, BuiltinObjectIndexes},
Heap, PropertyDescriptor,
},
types::{Object, Value},
types::{Object, PropertyKey, Value},
};
use std::{
alloc::{alloc_zeroed, handle_alloc_error, Layout},
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 @@ -3,9 +3,9 @@ use crate::{
execution::JsResult,
heap::{
heap_constants::{get_constructor_index, BuiltinObjectIndexes},
FunctionHeapData, Heap, ObjectEntry, PropertyDescriptor, PropertyKey,
FunctionHeapData, Heap, ObjectEntry, PropertyDescriptor,
},
types::{Object, Value},
types::{Object, PropertyKey, Value},
};
use num_bigint_dig::BigInt;

Expand Down
8 changes: 2 additions & 6 deletions nova_vm/src/heap/boolean.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
use super::{object::ObjectEntry, Heap};
use crate::{
execution::JsResult,
heap::{
heap_constants::{get_constructor_index, BuiltinObjectIndexes},
FunctionHeapData, PropertyDescriptor,
},
types::{Object, Value},
};

use super::{
object::{ObjectEntry, PropertyKey},
Heap,
types::{Object, PropertyKey, Value},
};

pub fn initialize_boolean_heap(heap: &mut Heap) {
Expand Down
18 changes: 8 additions & 10 deletions nova_vm/src/heap/date.rs
Original file line number Diff line number Diff line change
@@ -1,20 +1,18 @@
use std::time::SystemTime;

use super::{
function::FunctionHeapData,
heap_constants::WellKnownSymbolIndexes,
indexes::{FunctionIndex, ObjectIndex},
object::ObjectEntry,
};
use crate::{
execution::JsResult,
heap::{
heap_constants::{get_constructor_index, BuiltinObjectIndexes},
Heap, PropertyDescriptor,
},
types::{Object, Value},
};

use super::{
function::FunctionHeapData,
heap_constants::WellKnownSymbolIndexes,
indexes::{FunctionIndex, ObjectIndex},
object::{ObjectEntry, PropertyKey},
types::{Object, PropertyKey, Value},
};
use std::time::SystemTime;

#[derive(Debug, Clone, Copy)]
pub struct DateHeapData {
Expand Down
8 changes: 4 additions & 4 deletions nova_vm/src/heap/element_array.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use super::{
indexes::{ElementIndex, FunctionIndex},
object::{ObjectEntry, PropertyDescriptor, PropertyKey},
object::{ObjectEntry, PropertyDescriptor},
};
use crate::{types::Value, Heap};
use crate::types::{PropertyKey, Value};
use core::panic;
use std::{collections::HashMap, mem::MaybeUninit, num::NonZeroU16, vec};
use std::{collections::HashMap, mem::MaybeUninit, num::NonZeroU16};

#[derive(Debug, Clone, Copy)]
pub enum ElementArrayKey {
Expand Down Expand Up @@ -789,8 +789,8 @@ impl ElementArrays {
let (maybe_descriptor, maybe_value) =
ElementDescriptor::from_property_descriptor(value);
let key = match key {
PropertyKey::Integer(data) => Value::Integer(data),
PropertyKey::SmallString(data) => Value::SmallString(data),
PropertyKey::Smi(data) => Value::from(data),
PropertyKey::String(data) => Value::String(data),
PropertyKey::Symbol(data) => Value::Symbol(data),
};
Expand Down
13 changes: 6 additions & 7 deletions nova_vm/src/heap/error.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
use super::{
function::FunctionHeapData,
indexes::{FunctionIndex, ObjectIndex},
object::ObjectEntry,
};
use crate::{
execution::JsResult,
heap::{
heap_constants::{get_constructor_index, BuiltinObjectIndexes},
Heap, PropertyDescriptor,
},
types::{Object, Value},
};

use super::{
function::FunctionHeapData,
indexes::{FunctionIndex, ObjectIndex},
object::{ObjectEntry, PropertyKey},
types::{Object, PropertyKey, Value},
};

#[derive(Debug, Clone, Copy)]
Expand Down
14 changes: 6 additions & 8 deletions nova_vm/src/heap/function.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
use super::{
heap_constants::WellKnownSymbolIndexes,
indexes::{FunctionIndex, ObjectIndex},
object::ObjectEntry,
};
use crate::{
builtins::Behaviour,
execution::JsResult,
heap::{
heap_constants::{get_constructor_index, BuiltinObjectIndexes},
Heap, PropertyDescriptor,
},
types::{Object, Value},
};

use super::{
heap_constants::WellKnownSymbolIndexes,
indexes::{FunctionIndex, ObjectIndex},
object::{ObjectEntry, PropertyKey},
types::{Object, PropertyKey, Value},
};

#[derive(Debug, Clone)]
Expand Down
6 changes: 2 additions & 4 deletions nova_vm/src/heap/heap_bits.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
use std::sync::atomic::AtomicBool;

use crate::types::Value;

use super::{
indexes::{
ArrayBufferIndex, ArrayIndex, BigIntIndex, DateIndex, ElementIndex, ErrorIndex,
FunctionIndex, NumberIndex, ObjectIndex, RegExpIndex, StringIndex, SymbolIndex,
},
Heap,
};
use crate::types::Value;
use std::sync::atomic::AtomicBool;

pub struct HeapBits {
pub e_2_4: Box<[AtomicBool]>,
Expand Down
6 changes: 2 additions & 4 deletions nova_vm/src/heap/heap_gc.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
use std::sync::atomic::Ordering;

use crate::types::Value;

use super::{
element_array::ElementArrayKey,
heap_bits::{HeapBits, WorkQueues},
Expand All @@ -11,6 +7,8 @@ use super::{
},
ElementsVector, Heap,
};
use crate::types::Value;
use std::sync::atomic::Ordering;

pub fn heap_gc(heap: &mut Heap) {
let bits = HeapBits::new(heap);
Expand Down
8 changes: 5 additions & 3 deletions nova_vm/src/heap/math.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
use crate::{execution::JsResult, types::Value};

use super::{
heap_constants::WellKnownSymbolIndexes,
object::{ObjectEntry, PropertyDescriptor, PropertyKey},
object::{ObjectEntry, PropertyDescriptor},
Heap,
};
use crate::{
execution::JsResult,
types::{PropertyKey, Value},
};

pub(super) fn initialize_math_object(heap: &mut Heap) {
let e = Value::from_f64(heap, std::f64::consts::E);
Expand Down
7 changes: 2 additions & 5 deletions nova_vm/src/heap/number.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
use super::{
object::{ObjectEntry, PropertyKey},
Heap,
};
use super::{object::ObjectEntry, Heap};
use crate::{
execution::JsResult,
heap::{
heap_constants::{get_constructor_index, BuiltinObjectIndexes},
FunctionHeapData, PropertyDescriptor,
},
types::{Object, Value},
types::{Object, PropertyKey, Value},
};

#[derive(Debug, Clone, Copy)]
Expand Down
25 changes: 3 additions & 22 deletions nova_vm/src/heap/object.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
use super::{
element_array::ElementsVector,
indexes::{FunctionIndex, ObjectIndex, StringIndex, SymbolIndex},
indexes::{FunctionIndex, ObjectIndex, SymbolIndex},
};
use crate::{
execution::JsResult,
heap::{
heap_constants::{get_constructor_index, BuiltinObjectIndexes},
FunctionHeapData, Heap,
},
types::{Object, Value},
SmallString,
types::{Object, PropertyKey, Value},
};
use std::{fmt::Debug, vec};

Expand All @@ -34,7 +33,7 @@ impl ObjectEntry {
let key = PropertyKey::from_str(heap, name);
let name = match key {
PropertyKey::SmallString(data) => Value::SmallString(data.clone()),
PropertyKey::Smi(_) => unreachable!("No prototype functions should have SMI names"),
PropertyKey::Integer(_) => unreachable!("No prototype functions should have SMI names"),
PropertyKey::String(idx) => Value::String(idx),
PropertyKey::Symbol(idx) => Value::Symbol(idx),
};
Expand Down Expand Up @@ -78,24 +77,6 @@ impl ObjectEntry {
}
}

#[derive(Debug)]
pub enum PropertyKey {
SmallString(SmallString),
Smi(i32),
String(StringIndex),
Symbol(SymbolIndex),
}

impl PropertyKey {
pub fn from_str(heap: &mut Heap, str: &str) -> Self {
if let Ok(ascii_string) = SmallString::try_from(str) {
PropertyKey::SmallString(ascii_string)
} else {
PropertyKey::String(heap.alloc_string(str))
}
}
}

#[derive(Debug)]
pub enum PropertyDescriptor {
Data {
Expand Down
15 changes: 7 additions & 8 deletions nova_vm/src/heap/regexp.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
use super::{
function::FunctionHeapData,
heap_constants::WellKnownSymbolIndexes,
indexes::{FunctionIndex, ObjectIndex},
object::ObjectEntry,
};
use crate::{
execution::JsResult,
heap::{
heap_constants::{get_constructor_index, BuiltinObjectIndexes},
Heap, PropertyDescriptor,
},
types::{Object, Value},
};

use super::{
function::FunctionHeapData,
heap_constants::WellKnownSymbolIndexes,
indexes::{FunctionIndex, ObjectIndex},
object::{ObjectEntry, PropertyKey},
types::{Object, PropertyKey, Value},
};

#[derive(Debug, Clone, Copy)]
Expand Down
11 changes: 5 additions & 6 deletions nova_vm/src/heap/symbol.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
use super::{
indexes::{FunctionIndex, StringIndex, SymbolIndex},
object::ObjectEntry,
};
use crate::{
execution::JsResult,
heap::{
heap_constants::{get_constructor_index, BuiltinObjectIndexes, WellKnownSymbolIndexes},
FunctionHeapData, Heap, PropertyDescriptor,
},
types::{Object, Value},
};

use super::{
indexes::{FunctionIndex, StringIndex, SymbolIndex},
object::{ObjectEntry, PropertyKey},
types::{Object, PropertyKey, Value},
};

#[derive(Debug, Clone, Copy)]
Expand Down
Loading

0 comments on commit d3bc05f

Please sign in to comment.