@@ -589,12 +589,17 @@ export class CanonicalImports {
589589 // add: one import is one implementation, and this is that one again.
590590 return answer ;
591591 }
592- // Still the definition the identity was stated about. A claimed object the
593- // provider went on to edit is a different implementation, and taking a
594- // fresh copy of it here would record the edited one under the revision
595- // that described the original. Asked before anything is recorded and
596- // before the window is spent, so a refusal leaves both untouched.
597- if ( held . baseline === undefined || ! stillDescribes ( held . baseline , answer ) ) {
592+ // Retained once before it is compared: the answer may run user-controlled
593+ // machinery when read, so comparing it and then retaining it would leave
594+ // a gap in which those two reads could describe different definitions.
595+ // Asked before anything is recorded and before the window is spent, so a
596+ // refusal leaves both untouched.
597+ const copy = retain ( answer ) ;
598+ if (
599+ held . baseline === undefined ||
600+ copy === undefined ||
601+ ! stillDescribes ( held . baseline , copy )
602+ ) {
598603 throw new AnswerIdentityError (
599604 "this answer no longer describes the implementation its identity was stated about, so a " +
600605 "further import cannot be answered with it. One implementation states what it is " +
@@ -607,7 +612,7 @@ export class CanonicalImports {
607612 if ( this . #spent. get ( installation ) ?. has ( open ) === true ) {
608613 throw new AnswerIdentityError ( SPENT_OPPORTUNITY ) ;
609614 }
610- held . copies . set ( open , retain ( answer ) ) ;
615+ held . copies . set ( open , copy ) ;
611616 this . #spend( installation , open ) ;
612617 return answer ;
613618 }
0 commit comments