|
1 | | -#if !NETCOREAPP1_0 |
| 1 | +#if NET471 || NETCOREAPP2_1 || NETCOREAPP3_1 |
2 | 2 | using System; |
3 | 3 |
|
4 | 4 | using Xunit; |
@@ -213,68 +213,68 @@ public void MappingRuntimeErrorDuringOutOfMemoryIsCorrect() |
213 | 213 | Assert.Matches(@"^Script has allocated \d+ but is limited to 2097152$", exception.Description); |
214 | 214 | } |
215 | 215 |
|
216 | | -// [Fact] |
217 | | -// public void MappingRuntimeErrorDuringRecursionDepthOverflowIsCorrect() |
218 | | -// { |
219 | | -// // Arrange |
220 | | -// const string input = @"function fibonacci(n) { |
221 | | -// if (n === 1) { |
222 | | -// return 1; |
223 | | -// } |
224 | | -// else if (n === 2) { |
225 | | -// return 1; |
226 | | -// } |
227 | | -// else { |
228 | | -// return fibonacci(n - 1) + fibonacci(n - 2); |
229 | | -// } |
230 | | -//} |
231 | | - |
232 | | -//(function (fibonacci) { |
233 | | -// var a = 5; |
234 | | -// var b = 11; |
235 | | -// var c = fibonacci(b) - fibonacci(a); |
236 | | -//})(fibonacci);"; |
237 | | - |
238 | | -// JsRuntimeException exception = null; |
239 | | - |
240 | | -// // Act |
241 | | -// using (var jsEngine = new JintJsEngine( |
242 | | -// new JintSettings |
243 | | -// { |
244 | | -// MaxRecursionDepth = 5 |
245 | | -// } |
246 | | -// )) |
247 | | -// { |
248 | | -// try |
249 | | -// { |
250 | | -// jsEngine.Execute(input, "fibonacci.js"); |
251 | | -// } |
252 | | -// catch (JsRuntimeException e) |
253 | | -// { |
254 | | -// exception = e; |
255 | | -// } |
256 | | -// } |
257 | | - |
258 | | -// // Assert |
259 | | -// Assert.NotNull(exception); |
260 | | -// Assert.Equal("Runtime error", exception.Category); |
261 | | -// Assert.Equal("The recursion is forbidden by script host.", exception.Description); |
262 | | -// Assert.Equal("RangeError", exception.Type); |
263 | | -// Assert.Empty(exception.DocumentName); |
264 | | -// Assert.Equal(0, exception.LineNumber); |
265 | | -// Assert.Equal(0, exception.ColumnNumber); |
266 | | -// Assert.Empty(exception.SourceFragment); |
267 | | -// Assert.Equal( |
268 | | -// " at fibonacci" + Environment.NewLine + |
269 | | -// " at fibonacci" + Environment.NewLine + |
270 | | -// " at fibonacci" + Environment.NewLine + |
271 | | -// " at fibonacci" + Environment.NewLine + |
272 | | -// " at fibonacci" + Environment.NewLine + |
273 | | -// " at fibonacci" + Environment.NewLine + |
274 | | -// " at Anonymous function", |
275 | | -// exception.CallStack |
276 | | -// ); |
277 | | -// } |
| 216 | + [Fact] |
| 217 | + public void MappingRuntimeErrorDuringRecursionDepthOverflowIsCorrect() |
| 218 | + { |
| 219 | + // Arrange |
| 220 | + const string input = @"function fibonacci(n) { |
| 221 | + if (n === 1) { |
| 222 | + return 1; |
| 223 | + } |
| 224 | + else if (n === 2) { |
| 225 | + return 1; |
| 226 | + } |
| 227 | + else { |
| 228 | + return fibonacci(n - 1) + fibonacci(n - 2); |
| 229 | + } |
| 230 | +} |
| 231 | +
|
| 232 | +(function (fibonacci) { |
| 233 | + var a = 5; |
| 234 | + var b = 11; |
| 235 | + var c = fibonacci(b) - fibonacci(a); |
| 236 | +})(fibonacci);"; |
| 237 | + |
| 238 | + JsRuntimeException exception = null; |
| 239 | + |
| 240 | + // Act |
| 241 | + using (var jsEngine = new JintJsEngine( |
| 242 | + new JintSettings |
| 243 | + { |
| 244 | + MaxRecursionDepth = 5 |
| 245 | + } |
| 246 | + )) |
| 247 | + { |
| 248 | + try |
| 249 | + { |
| 250 | + jsEngine.Execute(input, "fibonacci.js"); |
| 251 | + } |
| 252 | + catch (JsRuntimeException e) |
| 253 | + { |
| 254 | + exception = e; |
| 255 | + } |
| 256 | + } |
| 257 | + |
| 258 | + // Assert |
| 259 | + Assert.NotNull(exception); |
| 260 | + Assert.Equal("Runtime error", exception.Category); |
| 261 | + Assert.Equal("The recursion is forbidden by script host.", exception.Description); |
| 262 | + Assert.Equal("RangeError", exception.Type); |
| 263 | + Assert.Empty(exception.DocumentName); |
| 264 | + Assert.Equal(0, exception.LineNumber); |
| 265 | + Assert.Equal(0, exception.ColumnNumber); |
| 266 | + Assert.Empty(exception.SourceFragment); |
| 267 | + Assert.Equal( |
| 268 | + " at fibonacci" + Environment.NewLine + |
| 269 | + " at fibonacci" + Environment.NewLine + |
| 270 | + " at fibonacci" + Environment.NewLine + |
| 271 | + " at fibonacci" + Environment.NewLine + |
| 272 | + " at fibonacci" + Environment.NewLine + |
| 273 | + " at fibonacci" + Environment.NewLine + |
| 274 | + " at Anonymous function", |
| 275 | + exception.CallStack |
| 276 | + ); |
| 277 | + } |
278 | 278 |
|
279 | 279 | [Fact] |
280 | 280 | public void MappingRuntimeErrorDuringStatementsCountOverflowIsCorrect() |
|
0 commit comments