Skip to content

Commit 5dc464f

Browse files
Fix cross realm array creation behaviour.
1 parent b78871b commit 5dc464f

2 files changed

Lines changed: 9 additions & 6 deletions

File tree

rhino/src/main/java/org/mozilla/javascript/ArrayLikeAbstractOperations.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,14 @@ public static Object coercibleIterativeMethod(
176176
static Scriptable arraySpeciesCreate(Context cx, VarScope scope, Object o, int length) {
177177
if (o instanceof NativeArray) {
178178
Object c = ScriptableObject.getProperty((Scriptable) o, "constructor");
179+
if (c instanceof Function f && f.isConstructor()) {
180+
VarScope ctorScope = ScriptableObject.getTopLevelScope(f.getDeclarationScope());
181+
if (ctorScope != ScriptableObject.getTopLevelScope(scope)
182+
&& c == ScriptableObject.getProperty(ctorScope, "Array")) {
183+
c = Undefined.instance;
184+
}
185+
}
186+
179187
if (c instanceof Scriptable) {
180188
c = ScriptableObject.getProperty((Scriptable) c, SymbolKey.SPECIES);
181189
if (c == null || c == NOT_FOUND) {

tests/testsrc/test262.properties

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -449,13 +449,12 @@ built-ins/AggregateError 3/25 (12.0%)
449449
newtarget-proto-fallback.js
450450
proto-from-ctor-realm.js
451451

452-
built-ins/Array 241/3081 (7.82%)
452+
built-ins/Array 236/3081 (7.66%)
453453
fromAsync 95/95 (100.0%)
454454
length/define-own-prop-length-coercion-order-set.js
455455
prototype/at/coerced-index-resize.js
456456
prototype/at/typed-array-resizable-buffer.js
457457
prototype/concat/Array.prototype.concat_non-array.js
458-
prototype/concat/create-proto-from-ctor-realm-array.js
459458
prototype/concat/create-proxy.js
460459
prototype/copyWithin/coerced-values-start-change-start.js
461460
prototype/copyWithin/coerced-values-start-change-target.js
@@ -471,7 +470,6 @@ built-ins/Array 241/3081 (7.82%)
471470
prototype/fill/resizable-buffer.js
472471
prototype/fill/typed-array-resize.js
473472
prototype/filter/callbackfn-resize-arraybuffer.js
474-
prototype/filter/create-proto-from-ctor-realm-array.js
475473
prototype/filter/create-proxy.js
476474
prototype/filter/resizable-buffer.js
477475
prototype/filter/resizable-buffer-grow-mid-iteration.js
@@ -518,7 +516,6 @@ built-ins/Array 241/3081 (7.82%)
518516
prototype/lastIndexOf/length-zero-returns-minus-one.js
519517
prototype/lastIndexOf/resizable-buffer.js
520518
prototype/map/callbackfn-resize-arraybuffer.js
521-
prototype/map/create-proto-from-ctor-realm-array.js
522519
prototype/map/create-proxy.js
523520
prototype/map/resizable-buffer.js
524521
prototype/map/resizable-buffer-grow-mid-iteration.js
@@ -553,7 +550,6 @@ built-ins/Array 241/3081 (7.82%)
553550
prototype/shift/throws-when-this-value-length-is-writable-false.js non-strict
554551
prototype/slice/coerced-start-end-grow.js
555552
prototype/slice/coerced-start-end-shrink.js
556-
prototype/slice/create-proto-from-ctor-realm-array.js
557553
prototype/slice/create-proxy.js
558554
prototype/slice/create-species.js
559555
prototype/slice/resizable-buffer.js
@@ -566,7 +562,6 @@ built-ins/Array 241/3081 (7.82%)
566562
prototype/sort/comparefn-shrink.js
567563
prototype/sort/resizable-buffer-default-comparator.js
568564
prototype/splice/clamps-length-to-integer-limit.js
569-
prototype/splice/create-proto-from-ctor-realm-array.js
570565
prototype/splice/create-proto-from-ctor-realm-non-array.js
571566
prototype/splice/create-proxy.js
572567
prototype/splice/create-revoked-proxy.js

0 commit comments

Comments
 (0)