Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 57 additions & 0 deletions nova_vm/src/builtin_strings
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@
[object String]
[object Undefined]
[Symbol.hasInstance]
[Symbol.iterator]
[Symbol.match]
[Symbol.matchAll]
[Symbol.replace]
[Symbol.search]
[Symbol.split]
[Symbol.toPrimitive]
abs
acos
Expand Down Expand Up @@ -42,7 +48,11 @@ caller
cause
cbrt
ceil
charAt
charCodeAt
clz32
codePointAt
concat
constructor
copyWithin
cos
Expand All @@ -55,11 +65,14 @@ defineProperties
defineProperty
description
done
dotAll
E
endsWith
entries
EPSILON
Error
EvalError
exec
exp
expm1
false
Expand All @@ -69,20 +82,33 @@ find
findIndex
findLast
findLastIndex
flags
flat
flatMap
Float32Array
Float64Array
floor
for
freeze
fromCharCode
fromCodePoint
fromEntries
fround
function
Function
get [Symbol.species]
get byteLength
get description
get dotAll
get flags
get global
get hasIndices
get ignoreCase
get multiline
get source
get stricky
get unicode
get unicodeSets
getDate
getDay
getFullYear
Expand All @@ -106,14 +132,18 @@ getUTCMilliseconds
getUTCMinutes
getUTCMonth
getUTCSeconds
global
globalThis
groupBy
hasIndices
hasInstance
hasOwn
hasOwnProperty
hypot
ignoreCase
imul
includes
indexOf
Infinity
Int16Array
Int32Array
Expand All @@ -128,12 +158,15 @@ isNaN
isPrototypeOf
isSafeInteger
isSealed
isWellFormed
iterator
keyFor
keys
lastIndexOf
length
LN10
LN2
localeCompare
log
log10
LOG10E
Expand All @@ -152,16 +185,20 @@ message
min
MIN_SAFE_INTEGER
MIN_VALUE
multiline
name
NaN
NEGATIVE_INFINITY
next
normalize
now
null
number
Number
object
Object
padEnd
padStart
parse
parseFloat
parseInt
Expand All @@ -175,9 +212,13 @@ prototype
Proxy
random
RangeError
raw
ReferenceError
RegExp
RegExp String Iterator
repeat
replace
replaceAll
round
seal
search
Expand All @@ -202,26 +243,35 @@ SharedArrayBuffer
sign
sin
sinh
slice
source
species
split
sqrt
SQRT1_2
SQRT2
startsWith
stricky
string
String
String Iterator
symbol
Symbol
SyntaxError
tan
tanh
test
toDateString
toExponential
toFixed
toISOString
toJSON
toLocaleDateString
toLocaleLowerCase
toLocaleString
toLocaleTimeString
toLocaleUpperCase
toLowerCase
toPrecision
toPrimitive
toReversed
Expand All @@ -230,7 +280,12 @@ toSpliced
toString
toStringTag
toTimeString
toUpperCase
toUTCString
toWellFormed
trim
trimEnd
trimStart
true
trunc
TypeError
Expand All @@ -239,6 +294,8 @@ Uint32Array
Uint8Array
Uint8ClampedArray
undefined
unicode
unicodeSets
unscopables
URIError
utc
Expand Down
29 changes: 26 additions & 3 deletions nova_vm/src/ecmascript/builders/builtin_function_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use super::property_builder::{self, PropertyBuilder};
pub struct NoPrototype;

#[derive(Clone, Copy)]
pub struct CreatorPrototype(Object);
pub struct CreatorPrototype(Option<Object>);

#[derive(Default, Clone, Copy)]
pub struct NoLength;
Expand Down Expand Up @@ -162,7 +162,30 @@ impl<'agent, L, N, B, Pr> BuiltinFunctionBuilder<'agent, NoPrototype, L, N, B, P
this: self.this,
object_index,
realm: self.realm,
prototype: CreatorPrototype(prototype),
prototype: CreatorPrototype(Some(prototype)),
length: self.length,
name: self.name,
behaviour: self.behaviour,
properties: self.properties,
}
}

#[must_use]
pub fn with_null_prototype(
self,
) -> BuiltinFunctionBuilder<'agent, CreatorPrototype, L, N, B, Pr> {
let object_index = if self.object_index.is_none() {
self.agent.heap.objects.push(None);
Some(ObjectIndex::last(&self.agent.heap.objects))
} else {
self.object_index
};
BuiltinFunctionBuilder {
agent: self.agent,
this: self.this,
object_index,
realm: self.realm,
prototype: CreatorPrototype(None),
length: self.length,
name: self.name,
behaviour: self.behaviour,
Expand Down Expand Up @@ -518,7 +541,7 @@ impl<'agent>
assert!(slot.is_none());
*slot = Some(ObjectHeapData {
extensible: true,
prototype: Some(prototype.0),
prototype: prototype.0,
keys,
values,
});
Expand Down
2 changes: 2 additions & 0 deletions nova_vm/src/ecmascript/builtins.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ pub mod error;
pub(crate) mod fundamental_objects;
pub(crate) mod numbers_and_dates;
pub mod ordinary;
pub(crate) mod regexp;
pub(crate) mod text_processing;

pub(crate) use arguments::*;
pub(crate) use array::abstract_operations::*;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,7 @@ impl FunctionPrototype {
Some(this_object_index),
)
.with_property_capacity(8)
.with_null_prototype()
// 10.2.4 AddRestrictedFunctionProperties ( F, realm )
.with_property(|builder| {
builder
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -577,7 +577,7 @@ impl DatePrototype {
let date_constructor = intrinsics.date();

OrdinaryObjectBuilder::new_intrinsic_object(agent, realm, this)
.with_property_capacity(7)
.with_property_capacity(45)
.with_constructor_property(date_constructor)
.with_builtin_function_property::<DatePrototypeGetDate>()
.with_builtin_function_property::<DatePrototypeGetDay>()
Expand Down
7 changes: 7 additions & 0 deletions nova_vm/src/ecmascript/builtins/regexp.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
use crate::heap::indexes::ObjectIndex;

#[derive(Debug, Clone, Copy)]
pub struct RegExpHeapData {
pub(crate) object_index: ObjectIndex,
// _regex: RegExp,
}
2 changes: 2 additions & 0 deletions nova_vm/src/ecmascript/builtins/text_processing.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
pub(crate) mod regexp_objects;
pub(crate) mod string_objects;
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
pub(crate) mod regexp_constructor;
pub(crate) mod regexp_prototype;
pub(crate) mod regexp_string_iterator_prototype;
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
use crate::ecmascript::builders::builtin_function_builder::BuiltinFunctionBuilder;
use crate::ecmascript::builtins::ArgumentsList;
use crate::ecmascript::builtins::Behaviour;
use crate::ecmascript::builtins::Builtin;
use crate::ecmascript::execution::Agent;
use crate::ecmascript::execution::JsResult;
use crate::ecmascript::execution::RealmIdentifier;
use crate::ecmascript::types::IntoFunction;
use crate::ecmascript::types::IntoObject;
use crate::ecmascript::types::Object;
use crate::ecmascript::types::String;
use crate::ecmascript::types::Value;
use crate::ecmascript::types::BUILTIN_STRING_MEMORY;
use crate::heap::WellKnownSymbolIndexes;

pub struct RegExpConstructor;

impl Builtin for RegExpConstructor {
const BEHAVIOUR: Behaviour = Behaviour::Constructor(Self::behaviour);
const LENGTH: u8 = 1;
const NAME: String = BUILTIN_STRING_MEMORY.RegExp;
}

struct RegExpSpecies;
impl Builtin for RegExpSpecies {
const BEHAVIOUR: Behaviour = Behaviour::Regular(RegExpConstructor::species);
const LENGTH: u8 = 0;
const NAME: String = BUILTIN_STRING_MEMORY.get__Symbol_species_;
}
impl RegExpConstructor {
fn behaviour(
_agent: &mut Agent,
_this_value: Value,
_arguments: ArgumentsList,
_new_target: Option<Object>,
) -> JsResult<Value> {
todo!();
}

fn species(
_agent: &mut Agent,
_this_value: Value,
_arguments: ArgumentsList,
) -> JsResult<Value> {
todo!();
}

pub(crate) fn create_intrinsic(agent: &mut Agent, realm: RealmIdentifier) {
let intrinsics = agent.get_realm(realm).intrinsics();
let regexp_prototype = intrinsics.reg_exp_prototype();
let this = intrinsics.reg_exp();
let this_object_index = intrinsics.reg_exp_base_object();

BuiltinFunctionBuilder::new_intrinsic_constructor::<RegExpConstructor>(
agent,
realm,
this,
Some(this_object_index),
)
.with_property_capacity(2)
.with_prototype_property(regexp_prototype.into_object())
.with_property(|builder| {
builder
.with_key(WellKnownSymbolIndexes::Species.into())
.with_getter(|agent| {
BuiltinFunctionBuilder::new::<RegExpSpecies>(agent, realm)
.build()
.into_function()
})
.with_enumerable(false)
.build()
})
.build();
}
}
Loading