瀏覽代碼

Add configurable limit for Atomics.pause iterations (#2047)

Marko Lahma 6 月之前
父節點
當前提交
8925d0fa89
共有 2 個文件被更改,包括 6 次插入0 次删除
  1. 1 0
      Jint/Native/Atomics/AtomicsInstance.cs
  2. 5 0
      Jint/Options.cs

+ 1 - 0
Jint/Native/Atomics/AtomicsInstance.cs

@@ -53,6 +53,7 @@ internal sealed class AtomicsInstance : ObjectInstance
                 ExceptionHelper.ThrowRangeError(_realm, "Invalid iteration count");
             }
 
+            n = System.Math.Min(n, _engine.Options.Constraints.MaxAtomicsPauseIterations);
             Thread.SpinWait((int) n);
         }
         else

+ 5 - 0
Jint/Options.cs

@@ -433,6 +433,11 @@ public class Options
         /// The maximum size for JavaScript array, defaults to <see cref="uint.MaxValue"/>.
         /// </summary>
         public uint MaxArraySize { get; set; } = uint.MaxValue;
+
+        /// <summary>
+        /// How many iterations is Atomics.pause allowed to instruct to wait using <see cref="System.Threading.Thread.SpinWait"/>, defaults to 10 000.
+        /// </summary>
+        public int MaxAtomicsPauseIterations { get; set; } = 10_000;
     }
 
     /// <summary>