@@ -21,6 +21,7 @@ import type {
2121 Pointer ,
2222 VirtualEnvironmentOptions ,
2323 CallableTrackAsFastTarget ,
24+ CallableDescriptorCallback ,
2425} from './types' ;
2526
2627const LOCKER_NEAR_MEMBRANE_UNDEFINED_VALUE_SYMBOL = Symbol . for (
@@ -248,16 +249,45 @@ export class VirtualEnvironment {
248249 this . blueCallableGetPropertyValuePointer = blueCallableGetPropertyValuePointer ;
249250 this . blueCallableLinkPointers = blueCallableLinkPointers ;
250251
251- this . redGlobalThisPointer = redGlobalThisPointer ;
252- this . redCallableGetPropertyValuePointer = redCallableGetPropertyValuePointer ;
252+ // Ensure the `this` context of red callable functions is `undefined`.
253+ this . redGlobalThisPointer = ( ) => redGlobalThisPointer ( ) ;
254+ this . redCallableGetPropertyValuePointer = ( targetPointer : Pointer , key : PropertyKey ) =>
255+ redCallableGetPropertyValuePointer ( targetPointer , key ) ;
253256 this . redCallableEvaluate = signSourceCallback
254257 ? ( sourceText : string ) => redCallableEvaluate ( signSourceCallback ( sourceText ) )
255- : redCallableEvaluate ;
256- this . redCallableLinkPointers = redCallableLinkPointers ;
257- this . redCallableSetPrototypeOf = redCallableSetPrototypeOf ;
258- this . redCallableDefineProperties = redCallableDefineProperties ;
259- this . redCallableInstallLazyPropertyDescriptors = redCallableInstallLazyPropertyDescriptors ;
260- this . redCallableTrackAsFastTarget = redCallableTrackAsFastTarget ;
258+ : ( sourceText : string ) => redCallableEvaluate ( sourceText ) ;
259+ this . redCallableLinkPointers = ( targetPointer : Pointer , foreignTargetPointer : Pointer ) =>
260+ redCallableLinkPointers ( targetPointer , foreignTargetPointer ) ;
261+ this . redCallableSetPrototypeOf = (
262+ targetPointer : Pointer ,
263+ protoPointerOrNull : Pointer | null
264+ ) => redCallableSetPrototypeOf ( targetPointer , protoPointerOrNull ) ;
265+ this . redCallableDefineProperties = (
266+ targetPointer : Pointer ,
267+ ...descriptorTuples : [ ...Parameters < CallableDescriptorCallback > ]
268+ ) => {
269+ const { length } = descriptorTuples ;
270+ const args = new ArrayCtor ( length + 1 ) ;
271+ args [ 0 ] = targetPointer ;
272+ for ( let i = 0 ; i < length ; i += 1 ) {
273+ args [ i + 1 ] = descriptorTuples [ i ] ;
274+ }
275+ ReflectApply ( redCallableDefineProperties , undefined , args ) ;
276+ } ;
277+ this . redCallableInstallLazyPropertyDescriptors = (
278+ targetPointer : Pointer ,
279+ ...ownKeysAndUnforgeableGlobalThisKeys : PropertyKey [ ]
280+ ) => {
281+ const { length } = ownKeysAndUnforgeableGlobalThisKeys ;
282+ const args = new ArrayCtor ( length + 1 ) ;
283+ args [ 0 ] = targetPointer ;
284+ for ( let i = 0 ; i < length ; i += 1 ) {
285+ args [ i + 1 ] = ownKeysAndUnforgeableGlobalThisKeys [ i ] ;
286+ }
287+ ReflectApply ( redCallableInstallLazyPropertyDescriptors , undefined , args ) ;
288+ } ;
289+ this . redCallableTrackAsFastTarget = ( targetPointer : Pointer ) =>
290+ redCallableTrackAsFastTarget ( targetPointer ) ;
261291 }
262292
263293 evaluate ( sourceText : string ) : any {
0 commit comments