55using IOriginalPrimitiveInstance = Jint . Native . IPrimitiveInstance ;
66using OriginalEngine = Jint . Engine ;
77using OriginalJavaScriptException = Jint . Runtime . JavaScriptException ;
8- using OriginalJintException = Jint . Runtime . JintException ;
98using OriginalMemoryLimitExceededException = Jint . Runtime . MemoryLimitExceededException ;
109using OriginalObjectInstance = Jint . Native . Object . ObjectInstance ;
1110using OriginalParser = Esprima . JavaScriptParser ;
1211using OriginalParserException = Esprima . ParserException ;
1312using OriginalParserOptions = Esprima . ParserOptions ;
1413using OriginalProgram = Esprima . Ast . Program ;
1514using OriginalRecursionDepthOverflowException = Jint . Runtime . RecursionDepthOverflowException ;
15+ using OriginalRuntimeException = Jint . Runtime . JintException ;
1616using OriginalStatementsCountOverflowException = Jint . Runtime . StatementsCountOverflowException ;
1717using OriginalTypeReference = Jint . Runtime . Interop . TypeReference ;
1818using OriginalTypes = Jint . Runtime . Types ;
2727
2828using CoreStrings = JavaScriptEngineSwitcher . Core . Resources . Strings ;
2929using WrapperCompilationException = JavaScriptEngineSwitcher . Core . JsCompilationException ;
30- using WrapperException = JavaScriptEngineSwitcher . Core . JsException ;
3130using WrapperRuntimeException = JavaScriptEngineSwitcher . Core . JsRuntimeException ;
3231using WrapperTimeoutException = JavaScriptEngineSwitcher . Core . JsTimeoutException ;
3332using WrapperUsageException = JavaScriptEngineSwitcher . Core . JsUsageException ;
@@ -188,24 +187,26 @@ private static WrapperCompilationException WrapParserException(OriginalParserExc
188187 return wrapperCompilationException ;
189188 }
190189
191- private static WrapperException WrapJintException (
192- OriginalJintException originalJintException )
190+ private static WrapperRuntimeException WrapRuntimeException ( OriginalRuntimeException originalRuntimeException )
193191 {
194- WrapperException wrapperException ;
195- string message = originalJintException . Message ;
192+ string message = originalRuntimeException . Message ;
196193 if ( string . IsNullOrWhiteSpace ( message ) )
197194 {
198195 message = "An unknown error occurred" ;
199196 }
200197 string description = message ;
198+ string type = string . Empty ;
199+ string documentName = string . Empty ;
200+ int lineNumber = 0 ;
201+ int columnNumber = 0 ;
202+ string callStack = string . Empty ;
201203
202- if ( originalJintException is OriginalJavaScriptException )
204+ if ( originalRuntimeException is OriginalJavaScriptException )
203205 {
204- var originalJavaScriptException = ( OriginalJavaScriptException ) originalJintException ;
205- string type = string . Empty ;
206- string documentName = originalJavaScriptException . Location . Source ;
207- int lineNumber = originalJavaScriptException . LineNumber ;
208- int columnNumber = originalJavaScriptException . Column + 1 ;
206+ var originalJavaScriptException = ( OriginalJavaScriptException ) originalRuntimeException ;
207+ documentName = originalJavaScriptException . Location . Source ;
208+ lineNumber = originalJavaScriptException . LineNumber ;
209+ columnNumber = originalJavaScriptException . Column + 1 ;
209210
210211 OriginalValue errorValue = originalJavaScriptException . Error ;
211212 if ( errorValue . IsObject ( ) )
@@ -219,46 +220,22 @@ private static WrapperException WrapJintException(
219220 }
220221 }
221222
222- if ( ! string . IsNullOrEmpty ( type ) )
223+ if ( string . IsNullOrEmpty ( type ) )
223224 {
224- message = JsErrorHelpers . GenerateScriptErrorMessage ( type , description , documentName , lineNumber ,
225- columnNumber ) ;
226-
227- var wrapperRuntimeException = new WrapperRuntimeException ( message , EngineName , EngineVersion ,
228- originalJavaScriptException )
229- {
230- Type = type ,
231- DocumentName = documentName ,
232- LineNumber = lineNumber ,
233- ColumnNumber = columnNumber
234- } ;
235-
236- wrapperException = wrapperRuntimeException ;
237- }
238- else
239- {
240- wrapperException = new WrapperException ( message , EngineName , EngineVersion ,
241- originalJavaScriptException ) ;
225+ type = JsErrorType . Common ;
242226 }
227+
228+ message = JsErrorHelpers . GenerateScriptErrorMessage ( type , description , documentName , lineNumber ,
229+ columnNumber ) ;
243230 }
244- else if ( originalJintException is OriginalMemoryLimitExceededException )
231+ else if ( originalRuntimeException is OriginalMemoryLimitExceededException )
245232 {
246- var originalMemoryException = ( OriginalMemoryLimitExceededException ) originalJintException ;
247- string type = JsErrorType . Common ;
233+ type = JsErrorType . Common ;
248234 message = JsErrorHelpers . GenerateScriptErrorMessage ( type , description , string . Empty ) ;
249-
250- var wrapperRuntimeException = new WrapperRuntimeException ( message , EngineName , EngineVersion ,
251- originalMemoryException )
252- {
253- Description = description
254- } ;
255-
256- wrapperException = wrapperRuntimeException ;
257235 }
258- else if ( originalJintException is OriginalRecursionDepthOverflowException )
236+ else if ( originalRuntimeException is OriginalRecursionDepthOverflowException )
259237 {
260- var originalRecursionException = ( OriginalRecursionDepthOverflowException ) originalJintException ;
261- string callStack = string . Empty ;
238+ var originalRecursionException = ( OriginalRecursionDepthOverflowException ) originalRuntimeException ;
262239 string [ ] callChainItems = originalRecursionException . CallChain
263240 . Split ( new string [ ] { "->" } , StringSplitOptions . None )
264241 ;
@@ -287,42 +264,32 @@ private static WrapperException WrapJintException(
287264 stringBuilderPool . Return ( stackBuilder ) ;
288265 }
289266
290- string type = JsErrorType . Range ;
267+ type = JsErrorType . Range ;
291268 message = JsErrorHelpers . GenerateScriptErrorMessage ( type , description , callStack ) ;
292-
293- var wrapperRuntimeException = new WrapperRuntimeException ( message , EngineName , EngineVersion ,
294- originalRecursionException )
295- {
296- Description = description ,
297- Type = type ,
298- CallStack = callStack
299- } ;
300-
301- wrapperException = wrapperRuntimeException ;
302269 }
303- else if ( originalJintException is OriginalStatementsCountOverflowException )
270+ else if ( originalRuntimeException is OriginalStatementsCountOverflowException )
304271 {
305- var originalStatementsException = ( OriginalStatementsCountOverflowException ) originalJintException ;
306- string type = JsErrorType . Range ;
272+ type = JsErrorType . Range ;
307273 message = JsErrorHelpers . GenerateScriptErrorMessage ( type , description , string . Empty ) ;
308-
309- var wrapperRuntimeException = new WrapperRuntimeException ( message , EngineName , EngineVersion ,
310- originalStatementsException )
311- {
312- Description = description
313- } ;
314-
315- wrapperException = wrapperRuntimeException ;
316274 }
317275 else
318276 {
319- wrapperException = new WrapperException ( message , EngineName , EngineVersion ,
320- originalJintException ) ;
277+ type = JsErrorType . Common ;
278+ message = JsErrorHelpers . GenerateScriptErrorMessage ( type , description , string . Empty ) ;
321279 }
322280
323- wrapperException . Description = description ;
281+ var wrapperRuntimeException = new WrapperRuntimeException ( message , EngineName , EngineVersion ,
282+ originalRuntimeException )
283+ {
284+ Description = description ,
285+ Type = type ,
286+ DocumentName = documentName ,
287+ LineNumber = lineNumber ,
288+ ColumnNumber = columnNumber ,
289+ CallStack = callStack
290+ } ;
324291
325- return wrapperException ;
292+ return wrapperRuntimeException ;
326293 }
327294
328295 private static WrapperTimeoutException WrapTimeoutException ( TimeoutException originalTimeoutException )
@@ -390,9 +357,9 @@ protected override object InnerEvaluate(string expression, string documentName)
390357 {
391358 throw WrapParserException ( e ) ;
392359 }
393- catch ( OriginalJintException e )
360+ catch ( OriginalRuntimeException e )
394361 {
395- throw WrapJintException ( e ) ;
362+ throw WrapRuntimeException ( e ) ;
396363 }
397364 catch ( TimeoutException e )
398365 {
@@ -437,9 +404,9 @@ protected override void InnerExecute(string code, string documentName)
437404 {
438405 throw WrapParserException ( e ) ;
439406 }
440- catch ( OriginalJintException e )
407+ catch ( OriginalRuntimeException e )
441408 {
442- throw WrapJintException ( e ) ;
409+ throw WrapRuntimeException ( e ) ;
443410 }
444411 catch ( TimeoutException e )
445412 {
@@ -466,9 +433,9 @@ protected override void InnerExecute(IPrecompiledScript precompiledScript)
466433 {
467434 _jsEngine . Execute ( jintPrecompiledScript . Program ) ;
468435 }
469- catch ( OriginalJintException e )
436+ catch ( OriginalRuntimeException e )
470437 {
471- throw WrapJintException ( e ) ;
438+ throw WrapRuntimeException ( e ) ;
472439 }
473440 catch ( TimeoutException e )
474441 {
@@ -489,9 +456,9 @@ protected override object InnerCallFunction(string functionName, params object[]
489456 {
490457 functionValue = _jsEngine . GetValue ( functionName ) ;
491458 }
492- catch ( OriginalJintException e )
459+ catch ( OriginalRuntimeException e )
493460 {
494- throw WrapJintException ( e ) ;
461+ throw WrapRuntimeException ( e ) ;
495462 }
496463
497464 OriginalValue resultValue ;
@@ -500,9 +467,9 @@ protected override object InnerCallFunction(string functionName, params object[]
500467 {
501468 resultValue = _jsEngine . Invoke ( functionValue , args ) ;
502469 }
503- catch ( OriginalJintException e )
470+ catch ( OriginalRuntimeException e )
504471 {
505- throw WrapJintException ( e ) ;
472+ throw WrapRuntimeException ( e ) ;
506473 }
507474 catch ( TimeoutException e )
508475 {
@@ -559,9 +526,9 @@ protected override object InnerGetVariableValue(string variableName)
559526 {
560527 variableValue = _jsEngine . GetValue ( variableName ) ;
561528 }
562- catch ( OriginalJintException e )
529+ catch ( OriginalRuntimeException e )
563530 {
564- throw WrapJintException ( e ) ;
531+ throw WrapRuntimeException ( e ) ;
565532 }
566533
567534 result = MapToHostType ( variableValue ) ;
@@ -587,9 +554,9 @@ protected override void InnerSetVariableValue(string variableName, object value)
587554 {
588555 _jsEngine . SetValue ( variableName , processedValue ) ;
589556 }
590- catch ( OriginalJintException e )
557+ catch ( OriginalRuntimeException e )
591558 {
592- throw WrapJintException ( e ) ;
559+ throw WrapRuntimeException ( e ) ;
593560 }
594561 }
595562 }
@@ -609,9 +576,9 @@ protected override void InnerEmbedHostObject(string itemName, object value)
609576 {
610577 _jsEngine . SetValue ( itemName , processedValue ) ;
611578 }
612- catch ( OriginalJintException e )
579+ catch ( OriginalRuntimeException e )
613580 {
614- throw WrapJintException ( e ) ;
581+ throw WrapRuntimeException ( e ) ;
615582 }
616583 }
617584 }
@@ -626,9 +593,9 @@ protected override void InnerEmbedHostType(string itemName, Type type)
626593 {
627594 _jsEngine . SetValue ( itemName , typeReference ) ;
628595 }
629- catch ( OriginalJintException e )
596+ catch ( OriginalRuntimeException e )
630597 {
631- throw WrapJintException ( e ) ;
598+ throw WrapRuntimeException ( e ) ;
632599 }
633600 }
634601 }
0 commit comments