7788 * -----
99 * @Last modified by: Nate Corcoran <CLDMV> ([email protected] ) 10- * @Last modified time: 2026-10-12T14:17:16 -07:00 (1791839836 )
10+ * @Last modified time: 2026-10-12T15:32:42 -07:00 (1791844362 )
1111 * -----
1212 * @Copyright : Copyright (c) 2013-2026 Catalyzed Motivation Inc. All rights reserved.
1313 *
3131 * target or be refused by it;
3232 * - an array is copied with everything it holds (its elements and holes, any other own member and
3333 * each member's descriptor, which `slice()` would drop), and gets a layer when named exports are
34- * added (`addsMembers`);
34+ * added (`addsMembers`); an instance of an Array subclass is treated as a class instance;
3535 * - a class instance or built-in (a `Map`, a `Date`) keeps private fields and internal slots no copy
3636 * reproduces; nothing adopts from it, so it is used as-is unless named exports are added, and then
3737 * gets a layer;
@@ -346,6 +346,9 @@ function layerOver(underlying, members = [], hidden = []) {
346346 ...new Set ( [ ...Reflect . ownKeys ( underlying ) . filter ( ( key ) => ! removed . has ( key ) && ! added . has ( key ) ) , ...added . keys ( ) , ...shellFixedKeys ] )
347347 ] ,
348348 getPrototypeOf : ( ) => Reflect . getPrototypeOf ( underlying ) ,
349+ // The layer reports the value's prototype, and changing it would change the module's value, so a
350+ // change is refused; setting the prototype it already has succeeds, as on an object (#585 review).
351+ setPrototypeOf : ( _shell , prototype ) => prototype === Reflect . getPrototypeOf ( underlying ) ,
349352 // The layer reports keys its shell does not hold (the value's own and the added ones), which a
350353 // non-extensible shell would forbid, so it stays extensible: sealing it is refused.
351354 preventExtensions : ( ) => false ,
@@ -362,8 +365,8 @@ function layerOver(underlying, members = [], hidden = []) {
362365 * Copy an array with everything it holds: its elements and holes, any other own member (`items.label`)
363366 * and each member's descriptor (a read-only element, a getter), so the copy answers as the array does
364367 * (#585 review). `slice()` keeps only the elements, as plain data.
365- * @param {Array } value - The array.
366- * @returns {Array } The copy, with the array's prototype .
368+ * @param {Array } value - A plain array (an Array subclass instance is never copied) .
369+ * @returns {Array } The copy.
367370 * @private
368371 *
369372 * @example
@@ -374,7 +377,6 @@ function copyArray(value) {
374377 const { length, ...members } = Object . getOwnPropertyDescriptors ( value ) ;
375378 Object . defineProperties ( copy , members ) ;
376379 Object . defineProperty ( copy , "length" , length ) ;
377- if ( Object . getPrototypeOf ( copy ) !== Object . getPrototypeOf ( value ) ) Object . setPrototypeOf ( copy , Object . getPrototypeOf ( value ) ) ;
378380 return copy ;
379381}
380382
@@ -408,6 +410,9 @@ export function copyForComposition(value, { addsMembers = false } = {}) {
408410 // A function default with named exports is the node itself (`api.x()` calls it, `api.x.extra` is the
409411 // named export): the exports go on a callable layer, so the module's own function is never written to.
410412 if ( typeof value === "function" ) return addsMembers ? layerOver ( value ) : value ;
413+ // An instance of an Array subclass may hold private fields no copy reproduces: it is kept as itself,
414+ // as a class instance is (#585 review).
415+ if ( Array . isArray ( value ) && Object . getPrototypeOf ( value ) !== Array . prototype ) return addsMembers ? layerOver ( value ) : value ;
411416 if ( Array . isArray ( value ) ) return addsMembers ? layerOver ( value ) : copyArray ( value ) ;
412417 if ( hasOwnClass ( value ) ) return addsMembers ? layerOver ( value ) : value ;
413418 const descriptors = Object . getOwnPropertyDescriptors ( value ) ;
0 commit comments