sebastienros / jint

Javascript Interpreter for .NET
BSD 2-Clause "Simplified" License
4.02k stars 556 forks source link

Make LazyPropertyDescriptor generic and some prototypes more lazy #1868

Closed lahma closed 2 months ago

lahma commented 2 months ago

Using LazyPropertyDescriptor for objects that have many properties that can be seldomly used. Generic interface makes usage simpler.

sebastienros commented 2 months ago

Take this line

["copyWithin"] = new LazyPropertyDescriptor<ArrayPrototype>(this, static prototype => new ClrFunction(prototype._engine, "copyWithin", prototype.CopyWithin, 2, PropertyFlag.Configurable), PropertyFlags),

What state and what behavior in the actual implementation could vary across engines and scripts that it would prevent it from being a static ClrFunction instance?

Rephrased, should there be something else that an Engine instance (which a script can mutate), which could change how this method behaves? If not then there could be a way to have these more stable and shared across engine instances.

lahma commented 2 months ago

The problematic piece is the actual Engine instance (and the active Realm instance). Engine configuration can alter some behaviors and as engine is not thread-safe it cannot shared between process-wide instances. Alternative would be to change every Call method etc to to take the active engine as parameter.