Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(ecmascript): aggregate error construtor #541

Merged
merged 3 commits into from
Jan 18, 2025
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
1 change: 1 addition & 0 deletions nova_vm/src/builtin_strings
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ endsWith
entries
enumerable
EPSILON
errors
Error
escape
eval
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,27 @@
use crate::engine::context::GcScope;
use crate::{
ecmascript::{
abstract_operations::{
operations_on_iterator_objects::{get_iterator, iterator_to_list},
operations_on_objects::{create_array_from_list, define_property_or_throw},
type_conversion::to_string,
},
builders::builtin_function_builder::BuiltinFunctionBuilder,
builtins::{ArgumentsList, Behaviour, Builtin, BuiltinIntrinsicConstructor},
execution::{Agent, JsResult, RealmIdentifier},
types::{IntoObject, Object, String, Value, BUILTIN_STRING_MEMORY},
builtins::{
error::Error, ordinary::ordinary_create_from_constructor, ArgumentsList, Behaviour,
Builtin, BuiltinIntrinsicConstructor,
},
execution::{agent::ExceptionType, Agent, JsResult, ProtoIntrinsics, RealmIdentifier},
types::{
Function, IntoObject, IntoValue, Object, PropertyDescriptor, PropertyKey, String,
Value, BUILTIN_STRING_MEMORY,
},
},
heap::IntrinsicConstructorIndexes,
};

use super::error_constructor::get_error_cause;

pub(crate) struct AggregateErrorConstructor;
impl Builtin for AggregateErrorConstructor {
const NAME: String<'static> = BUILTIN_STRING_MEMORY.AggregateError;
Expand All @@ -27,13 +40,72 @@ impl BuiltinIntrinsicConstructor for AggregateErrorConstructor {

impl AggregateErrorConstructor {
fn constructor(
_agent: &mut Agent,
agent: &mut Agent,
_this_value: Value,
_arguments: ArgumentsList,
_new_target: Option<Object>,
_gc: GcScope,
arguments: ArgumentsList,
new_target: Option<Object>,
mut gc: GcScope,
) -> JsResult<Value> {
todo!()
let errors = arguments.get(0);
let message = arguments.get(1);
let options = arguments.get(2);
// 1. If NewTarget is undefined, let newTarget be the active function object; else let newTarget be NewTarget.
let new_target = new_target.map_or_else(
|| agent.running_execution_context().function.unwrap(),
|new_target| Function::try_from(new_target).unwrap(),
);
// 2. Let O be ? OrdinaryCreateFromConstructor(newTarget, "%AggregateError.prototype%", « [[ErrorData]] »).
let o = ordinary_create_from_constructor(
agent,
new_target.unbind(),
ProtoIntrinsics::AggregateError,
gc.reborrow(),
)?;
let o = Error::try_from(o.unbind()).unwrap();
// 3. If message is not undefined, then
let message = if !message.is_undefined() {
// a. Let msg be ? ToString(message).
Some(
to_string(agent, message, gc.reborrow())?
.unbind()
.scope(agent, gc.nogc()),
)
} else {
None
};
// 4. Perform ? InstallErrorCause(O, options).
let cause = get_error_cause(agent, options, gc.reborrow())?;
// b. Perform CreateNonEnumerableDataPropertyOrThrow(O, "message", msg).
let message: Option<String<'_>> = message.map(|message| message.get(agent));
let heap_data = &mut agent[o];
heap_data.kind = ExceptionType::Error;
heap_data.message = message;
heap_data.cause = cause.map(|c| c.unbind());
// 5. Let errorsList be ? IteratorToList(? GetIterator(errors, sync)).
let iterator_record = get_iterator(agent, errors.unbind(), false, gc.reborrow())?;
let errors_list = iterator_to_list(agent, &iterator_record, gc.reborrow())?;
// 6. Perform ! DefinePropertyOrThrow(O, "errors", PropertyDescriptor {
let property_descriptor = PropertyDescriptor {
// [[Configurable]]: true,
configurable: Some(true),
// [[Enumerable]]: false,
enumerable: Some(false),
// [[Writable]]: true,
writable: Some(true),
// [[Value]]: CreateArrayFromList(errorsList)
value: Some(create_array_from_list(agent, &errors_list, gc.nogc()).into_value()),
..Default::default()
};
define_property_or_throw(
agent,
o.unbind(),
PropertyKey::from(BUILTIN_STRING_MEMORY.errors),
property_descriptor,
gc.reborrow(),
)?;
// }).
// 7. Return O.
Ok(o.into_value())
}

pub(crate) fn create_intrinsic(agent: &mut Agent, realm: RealmIdentifier) {
Expand Down
17 changes: 2 additions & 15 deletions tests/expectations.json
Original file line number Diff line number Diff line change
Expand Up @@ -2072,21 +2072,11 @@
"built-ins/Math/sumPrecise/takes-iterable.js": "CRASH",
"built-ins/Math/sumPrecise/throws-on-non-number.js": "FAIL",
"built-ins/Math/trunc/trunc-sampleTests.js": "FAIL",
"built-ins/NativeErrors/AggregateError/cause-property.js": "CRASH",
"built-ins/NativeErrors/AggregateError/errors-iterabletolist-failures.js": "CRASH",
"built-ins/NativeErrors/AggregateError/errors-iterabletolist.js": "CRASH",
"built-ins/NativeErrors/AggregateError/is-a-constructor.js": "CRASH",
"built-ins/NativeErrors/AggregateError/length.js": "FAIL",
"built-ins/NativeErrors/AggregateError/message-method-prop-cast.js": "CRASH",
"built-ins/NativeErrors/AggregateError/message-method-prop.js": "CRASH",
"built-ins/NativeErrors/AggregateError/message-tostring-abrupt-symbol.js": "CRASH",
"built-ins/NativeErrors/AggregateError/message-tostring-abrupt.js": "CRASH",
"built-ins/NativeErrors/AggregateError/message-undefined-no-prop.js": "CRASH",
"built-ins/NativeErrors/AggregateError/newtarget-is-undefined.js": "CRASH",
"built-ins/NativeErrors/AggregateError/newtarget-is-undefined.js": "FAIL",
"built-ins/NativeErrors/AggregateError/newtarget-proto-custom.js": "CRASH",
"built-ins/NativeErrors/AggregateError/newtarget-proto-fallback.js": "CRASH",
"built-ins/NativeErrors/AggregateError/newtarget-proto.js": "CRASH",
"built-ins/NativeErrors/AggregateError/order-of-args-evaluation.js": "CRASH",
"built-ins/NativeErrors/AggregateError/newtarget-proto.js": "FAIL",
"built-ins/NativeErrors/AggregateError/proto-from-ctor-realm.js": "FAIL",
"built-ins/NativeErrors/AggregateError/proto.js": "FAIL",
"built-ins/NativeErrors/EvalError/proto-from-ctor-realm.js": "FAIL",
Expand Down Expand Up @@ -2522,7 +2512,6 @@
"built-ins/Object/seal/object-seal-p-is-own-property-of-a-reg-exp-object-that-uses-object-s-get-own-property.js": "CRASH",
"built-ins/Object/seal/proxy-no-ownkeys-returned-keys-order.js": "CRASH",
"built-ins/Object/seal/proxy-with-defineProperty-handler.js": "CRASH",
"built-ins/Object/seal/seal-aggregateerror.js": "CRASH",
"built-ins/Object/seal/seal-date.js": "CRASH",
"built-ins/Object/seal/seal-finalizationregistry.js": "CRASH",
"built-ins/Object/seal/seal-proxy.js": "CRASH",
Expand Down Expand Up @@ -14867,7 +14856,6 @@
"language/expressions/class/private-static-setter-multiple-evaluations-of-class-realm.js": "FAIL",
"language/expressions/class/static-init-await-reference.js": "FAIL",
"language/expressions/class/static-method-length-dflt.js": "CRASH",
"language/expressions/class/subclass-builtins/subclass-AggregateError.js": "CRASH",
"language/expressions/class/subclass-builtins/subclass-ArrayBuffer.js": "CRASH",
"language/expressions/class/subclass-builtins/subclass-Date.js": "CRASH",
"language/expressions/class/subclass-builtins/subclass-Promise.js": "CRASH",
Expand Down Expand Up @@ -19357,7 +19345,6 @@
"language/statements/class/static-init-sequence.js": "CRASH",
"language/statements/class/static-init-super-property.js": "CRASH",
"language/statements/class/static-method-length-dflt.js": "CRASH",
"language/statements/class/subclass-builtins/subclass-AggregateError.js": "CRASH",
"language/statements/class/subclass-builtins/subclass-ArrayBuffer.js": "CRASH",
"language/statements/class/subclass-builtins/subclass-Date.js": "CRASH",
"language/statements/class/subclass-builtins/subclass-Promise.js": "CRASH",
Expand Down
4 changes: 2 additions & 2 deletions tests/metrics.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"results": {
"crash": 14359,
"crash": 14346,
"fail": 7213,
"pass": 23670,
"pass": 23683,
"skip": 46,
"timeout": 3,
"unresolved": 0
Expand Down
Loading