|
6 | 6 | using IOriginalCallable = Jint.Native.ICallable; |
7 | 7 | using OriginalEngine = Jint.Engine; |
8 | 8 | using OriginalJavaScriptException = Jint.Runtime.JavaScriptException; |
| 9 | +using OriginalMemoryLimitExceededException = Jint.Runtime.MemoryLimitExceededException; |
9 | 10 | using OriginalObjectInstance = Jint.Native.Object.ObjectInstance; |
10 | 11 | using OriginalParser = Esprima.JavaScriptParser; |
11 | 12 | using OriginalParserException = Esprima.ParserException; |
@@ -92,6 +93,7 @@ public JintJsEngine(JintSettings settings) |
92 | 93 | _jsEngine = new OriginalEngine(c => c |
93 | 94 | .AllowDebuggerStatement(jintSettings.AllowDebuggerStatement) |
94 | 95 | .DebugMode(jintSettings.EnableDebugging) |
| 96 | + .LimitMemory(jintSettings.MemoryLimit) |
95 | 97 | .LimitRecursion(jintSettings.MaxRecursionDepth) |
96 | 98 | .LocalTimeZone(jintSettings.LocalTimeZone ?? TimeZoneInfo.Local) |
97 | 99 | .MaxStatements(jintSettings.MaxStatements) |
@@ -244,6 +246,22 @@ private static WrapperException WrapJavaScriptException( |
244 | 246 | return wrapperException; |
245 | 247 | } |
246 | 248 |
|
| 249 | + private static WrapperRuntimeException WrapMemoryLimitExceededException( |
| 250 | + OriginalMemoryLimitExceededException originalMemoryException) |
| 251 | + { |
| 252 | + string description = originalMemoryException.Message; |
| 253 | + string type = JsErrorType.Common; |
| 254 | + string message = JsErrorHelpers.GenerateScriptErrorMessage(type, description, string.Empty); |
| 255 | + |
| 256 | + var wrapperRuntimeException = new WrapperRuntimeException(message, EngineName, EngineVersion, |
| 257 | + originalMemoryException) |
| 258 | + { |
| 259 | + Description = description |
| 260 | + }; |
| 261 | + |
| 262 | + return wrapperRuntimeException; |
| 263 | + } |
| 264 | + |
247 | 265 | private static WrapperRuntimeException WrapRecursionDepthOverflowException( |
248 | 266 | OriginalRecursionDepthOverflowException originalRecursionException) |
249 | 267 | { |
@@ -376,6 +394,10 @@ protected override object InnerEvaluate(string expression, string documentName) |
376 | 394 | { |
377 | 395 | throw WrapJavaScriptException(e); |
378 | 396 | } |
| 397 | + catch (OriginalMemoryLimitExceededException e) |
| 398 | + { |
| 399 | + throw WrapMemoryLimitExceededException(e); |
| 400 | + } |
379 | 401 | catch (OriginalRecursionDepthOverflowException e) |
380 | 402 | { |
381 | 403 | throw WrapRecursionDepthOverflowException(e); |
@@ -431,6 +453,10 @@ protected override void InnerExecute(string code, string documentName) |
431 | 453 | { |
432 | 454 | throw WrapJavaScriptException(e); |
433 | 455 | } |
| 456 | + catch (OriginalMemoryLimitExceededException e) |
| 457 | + { |
| 458 | + throw WrapMemoryLimitExceededException(e); |
| 459 | + } |
434 | 460 | catch (OriginalRecursionDepthOverflowException e) |
435 | 461 | { |
436 | 462 | throw WrapRecursionDepthOverflowException(e); |
@@ -471,6 +497,10 @@ protected override void InnerExecute(IPrecompiledScript precompiledScript) |
471 | 497 | { |
472 | 498 | throw WrapJavaScriptException(e); |
473 | 499 | } |
| 500 | + catch (OriginalMemoryLimitExceededException e) |
| 501 | + { |
| 502 | + throw WrapMemoryLimitExceededException(e); |
| 503 | + } |
474 | 504 | catch (OriginalRecursionDepthOverflowException e) |
475 | 505 | { |
476 | 506 | throw WrapRecursionDepthOverflowException(e); |
@@ -531,6 +561,10 @@ protected override object InnerCallFunction(string functionName, params object[] |
531 | 561 | { |
532 | 562 | throw WrapJavaScriptException(e); |
533 | 563 | } |
| 564 | + catch (OriginalMemoryLimitExceededException e) |
| 565 | + { |
| 566 | + throw WrapMemoryLimitExceededException(e); |
| 567 | + } |
534 | 568 | catch (OriginalRecursionDepthOverflowException e) |
535 | 569 | { |
536 | 570 | throw WrapRecursionDepthOverflowException(e); |
|
0 commit comments