Skip to content

Commit

Permalink
feat(ecmascript): Fill out Value enum (#113)
Browse files Browse the repository at this point in the history
  • Loading branch information
aapoalas authored Apr 13, 2024
1 parent 600819f commit 3a6a689
Show file tree
Hide file tree
Showing 11 changed files with 1,331 additions and 168 deletions.
1 change: 1 addition & 0 deletions nova_vm/src/builtin_strings
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
-0
[object Arguments]
[object Array]
[object Boolean]
[object Date]
Expand Down
20 changes: 20 additions & 0 deletions nova_vm/src/ecmascript/builtins/ecmascript_function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -597,6 +597,16 @@ pub(crate) fn make_constructor(
// 2. Else,
// a. Set F.[[Construct]] to the definition specified in 10.3.2.
}
Function::BuiltinGeneratorFunction => todo!(),
Function::BuiltinConstructorFunction => todo!(),
Function::BuiltinPromiseResolveFunction => todo!(),
Function::BuiltinPromiseRejectFunction => todo!(),
Function::BuiltinPromiseCollectorFunction => todo!(),
Function::BuiltinProxyRevokerFunction => todo!(),
Function::ECMAScriptAsyncFunction => todo!(),
Function::ECMAScriptAsyncGeneratorFunction => todo!(),
Function::ECMAScriptConstructorFunction => todo!(),
Function::ECMAScriptGeneratorFunction => todo!(),
}
// 5. If prototype is not present, then
let prototype = prototype.unwrap_or_else(|| {
Expand Down Expand Up @@ -685,6 +695,16 @@ pub(crate) fn set_function_name(
function.name = Some(name);
// 7. Return UNUSED.
}
Function::BuiltinGeneratorFunction => todo!(),
Function::BuiltinConstructorFunction => todo!(),
Function::BuiltinPromiseResolveFunction => todo!(),
Function::BuiltinPromiseRejectFunction => todo!(),
Function::BuiltinPromiseCollectorFunction => todo!(),
Function::BuiltinProxyRevokerFunction => todo!(),
Function::ECMAScriptAsyncFunction => todo!(),
Function::ECMAScriptAsyncGeneratorFunction => todo!(),
Function::ECMAScriptConstructorFunction => todo!(),
Function::ECMAScriptGeneratorFunction => todo!(),
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,16 @@ impl FunctionPrototype {
);
Ok(Value::from_string(agent, initial_name))
}
Function::BuiltinGeneratorFunction => todo!(),
Function::BuiltinConstructorFunction => todo!(),
Function::BuiltinPromiseResolveFunction => todo!(),
Function::BuiltinPromiseRejectFunction => todo!(),
Function::BuiltinPromiseCollectorFunction => todo!(),
Function::BuiltinProxyRevokerFunction => todo!(),
Function::ECMAScriptAsyncFunction => todo!(),
Function::ECMAScriptAsyncGeneratorFunction => todo!(),
Function::ECMAScriptConstructorFunction => todo!(),
Function::ECMAScriptGeneratorFunction => todo!(),
}

// NOTE: NativeFunction means the following string:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,14 +140,17 @@ impl ObjectPrototype {
Value::Null => Ok(BUILTIN_STRING_MEMORY._object_Null_.into_value()),
// 9. Else if O has a [[BooleanData]] internal slot, let builtinTag be "Boolean".
// 17. Return the string-concatenation of "[object ", tag, and "]".
Value::Boolean(_) => Ok(BUILTIN_STRING_MEMORY._object_Boolean_.into_value()),
Value::Boolean(_) | Value::BooleanObject => {
Ok(BUILTIN_STRING_MEMORY._object_Boolean_.into_value())
}
// 6. Else if O has a [[ParameterMap]] internal slot, let builtinTag be "Arguments".
Value::Arguments => Ok(BUILTIN_STRING_MEMORY._object_Arguments_.into_value()),
// 11. Else if O has a [[StringData]] internal slot, let builtinTag be "String".
Value::String(_) | Value::SmallString(_) => {
Value::String(_) | Value::SmallString(_) | Value::StringObject => {
Ok(BUILTIN_STRING_MEMORY._object_String_.into_value())
}
// 10. Else if O has a [[NumberData]] internal slot, let builtinTag be "Number".
Value::Number(_) | Value::Integer(_) | Value::Float(_) => {
Value::Number(_) | Value::Integer(_) | Value::Float(_) | Value::NumberObject => {
Ok(BUILTIN_STRING_MEMORY._object_Error_.into_value())
}
Value::Object(_) => todo!(),
Expand All @@ -162,9 +165,13 @@ impl ObjectPrototype {
Value::BoundFunction(_) | Value::BuiltinFunction(_) | Value::ECMAScriptFunction(_) => {
Ok(BUILTIN_STRING_MEMORY._object_Function_.into_value())
}
// TODO: Check for [[Call]] slot of Proxy
Value::Proxy => todo!(),
// TODO: Check for [[Call]] slot of EmbedderObject
Value::EmbedderObject => todo!(),
// 13. Else if O has a [[RegExpMatcher]] internal slot, let builtinTag be "RegExp".
Value::RegExp(_) => Ok(BUILTIN_STRING_MEMORY._object_RegExp_.into_value()),
Value::Symbol(_) | Value::BigInt(_) | Value::SmallBigInt(_) | Value::ArrayBuffer(_) => {
_ => {
// 14. Else, let builtinTag be "Object".
let builtin_tag = BUILTIN_STRING_MEMORY.Object;
// 3. Let O be ! ToObject(this value).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,16 @@ impl FunctionEnvironmentIndex {
.unwrap();
data.ecmascript_function.home_object.is_some()
}
Function::BuiltinGeneratorFunction => todo!(),
Function::BuiltinConstructorFunction => todo!(),
Function::BuiltinPromiseResolveFunction => todo!(),
Function::BuiltinPromiseRejectFunction => todo!(),
Function::BuiltinPromiseCollectorFunction => todo!(),
Function::BuiltinProxyRevokerFunction => todo!(),
Function::ECMAScriptAsyncFunction => todo!(),
Function::ECMAScriptAsyncGeneratorFunction => todo!(),
Function::ECMAScriptConstructorFunction => todo!(),
Function::ECMAScriptGeneratorFunction => todo!(),
}
}

Expand All @@ -327,6 +337,16 @@ impl FunctionEnvironmentIndex {
.unwrap();
data.ecmascript_function.home_object
}
Function::BuiltinGeneratorFunction => todo!(),
Function::BuiltinConstructorFunction => todo!(),
Function::BuiltinPromiseResolveFunction => todo!(),
Function::BuiltinPromiseRejectFunction => todo!(),
Function::BuiltinPromiseCollectorFunction => todo!(),
Function::BuiltinProxyRevokerFunction => todo!(),
Function::ECMAScriptAsyncFunction => todo!(),
Function::ECMAScriptAsyncGeneratorFunction => todo!(),
Function::ECMAScriptConstructorFunction => todo!(),
Function::ECMAScriptGeneratorFunction => todo!(),
};
// 2. If home is undefined, return undefined.
let Some(home) = home else {
Expand Down
4 changes: 2 additions & 2 deletions nova_vm/src/ecmascript/execution/realm/intrinsics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ use super::RealmIdentifier;

#[derive(Debug, Clone)]
pub(crate) struct Intrinsics {
object_index_base: ObjectIndex,
builtin_function_index_base: BuiltinFunctionIndex,
pub(crate) object_index_base: ObjectIndex,
pub(crate) builtin_function_index_base: BuiltinFunctionIndex,
}

/// Enumeration of intrinsics intended to be used as the \[\[Prototype\]\] value of
Expand Down
Loading

0 comments on commit 3a6a689

Please sign in to comment.