From 9f0ac300827a0d04d7c20432c37ae316dd46baa7 Mon Sep 17 00:00:00 2001 From: raskad <32105367+raskad@users.noreply.github.com> Date: Mon, 26 Sep 2022 05:09:14 +0000 Subject: [PATCH] Fix some Array spec deviations (#2306) This Pull Request changes the following: - Fix array constructor realm comparison. - Fix error that ignored `ToObject`. - Ignore `array-grouping` feature tests. --- boa_engine/src/builtins/array/mod.rs | 17 +++++++++++------ test_ignore.txt | 1 + 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/boa_engine/src/builtins/array/mod.rs b/boa_engine/src/builtins/array/mod.rs index 54f2280029..cf32523636 100644 --- a/boa_engine/src/builtins/array/mod.rs +++ b/boa_engine/src/builtins/array/mod.rs @@ -346,11 +346,16 @@ impl Array { let c = original_array.get("constructor", context)?; // 4. If IsConstructor(C) is true, then - // a. Let thisRealm be the current Realm Record. - // b. Let realmC be ? GetFunctionRealm(C). - // c. If thisRealm and realmC are not the same Realm Record, then - // i. If SameValue(C, realmC.[[Intrinsics]].[[%Array%]]) is true, set C to undefined. - // TODO: Step 4 is ignored, as there are no different realms for now + if let Some(c) = c.as_constructor() { + // a. Let thisRealm be the current Realm Record. + // b. Let realmC be ? GetFunctionRealm(C). + // c. If thisRealm and realmC are not the same Realm Record, then + if *c == context.intrinsics().constructors().array().constructor { + // i. If SameValue(C, realmC.[[Intrinsics]].[[%Array%]]) is true, set C to undefined. + // Note: fast path to step 6. + return Self::array_create(length, None, context); + } + } // 5. If Type(C) is Object, then let c = if let Some(c) = c.as_object() { @@ -1224,7 +1229,7 @@ impl Array { let k_value = o.get(k, context)?; // ii. Let mappedValue be ? Call(callbackfn, thisArg, « kValue, 𝔽(k), O »). let mapped_value = - callback.call(this_arg, &[k_value, k.into(), this.into()], context)?; + callback.call(this_arg, &[k_value, k.into(), o.clone().into()], context)?; // iii. Perform ? CreateDataPropertyOrThrow(A, Pk, mappedValue). a.create_data_property_or_throw(k, mapped_value, context)?; } diff --git a/test_ignore.txt b/test_ignore.txt index d84cc0e5fc..c30babae78 100644 --- a/test_ignore.txt +++ b/test_ignore.txt @@ -12,6 +12,7 @@ feature:FinalizationRegistry feature:Atomics feature:dynamic_import feature:decorators +feature:array-grouping // Non-implemented Intl features feature:intl-normative-optional