From 95825eadcca612c33a31bf9402eb3da27a196738 Mon Sep 17 00:00:00 2001 From: Adam Simon Date: Sun, 31 Mar 2024 03:56:05 +0200 Subject: [PATCH] Improvements --- Jint.Repl/Program.cs | 3 ++- Jint.Tests.CommonScripts/ConcurrencyTest.cs | 3 ++- .../Test262Harness.settings.json | 1 + Jint.Tests.Test262/Test262Test.cs | 8 +++++- Jint/AstExtensions.cs | 16 +++-------- Jint/Engine.cs | 3 ++- Jint/Messages.cs | 9 ------- Jint/Native/Function/EvalFunction.cs | 4 +-- Jint/Native/RegExp/RegExpConstructor.cs | 2 +- Jint/Native/ShadowRealm/ShadowRealm.cs | 4 +-- Jint/Runtime/CallStack/CallStackElement.cs | 11 ++++---- Jint/Runtime/Completion.cs | 2 +- Jint/Runtime/Debugger/CallFrame.cs | 7 ++--- Jint/Runtime/Debugger/DebugHandler.cs | 4 +-- Jint/Runtime/Debugger/DebugInformation.cs | 2 +- .../Environments/FunctionEnvironment.cs | 2 +- Jint/Runtime/ExceptionHelper.cs | 2 +- Jint/Runtime/IScriptOrModule.Extensions.cs | 2 +- .../BindingPatternAssignmentExpression.cs | 27 +++++++++---------- .../Expressions/JintAssignmentExpression.cs | 2 +- .../Statements/JintForInForOfStatement.cs | 7 +++-- .../Interpreter/Statements/JintStatement.cs | 2 +- .../Statements/JintVariableDeclaration.cs | 4 +-- Jint/Runtime/JavaScriptException.cs | 4 +-- Jint/Runtime/Modules/CyclicModule.cs | 5 ++-- Jint/Runtime/Modules/ModuleFactory.cs | 4 +-- Jint/Runtime/Modules/ModuleLoader.cs | 2 +- Jint/Runtime/TypeConverter.cs | 2 +- 28 files changed, 67 insertions(+), 77 deletions(-) delete mode 100644 Jint/Messages.cs diff --git a/Jint.Repl/Program.cs b/Jint.Repl/Program.cs index 8042814eaa..ff926451ba 100644 --- a/Jint.Repl/Program.cs +++ b/Jint.Repl/Program.cs @@ -43,7 +43,8 @@ var defaultColor = Console.ForegroundColor; var parserOptions = new ParserOptions { - EcmaVersion = EcmaVersion.Experimental, + EcmaVersion = EcmaVersion.ES2023, + ExperimentalESFeatures = ExperimentalESFeatures.ImportAttributes | ExperimentalESFeatures.RegExpDuplicateNamedCapturingGroups, Tolerant = true, RegExpParseMode = RegExpParseMode.AdaptToInterpreted }; diff --git a/Jint.Tests.CommonScripts/ConcurrencyTest.cs b/Jint.Tests.CommonScripts/ConcurrencyTest.cs index 422d503f1d..caebf26eb5 100644 --- a/Jint.Tests.CommonScripts/ConcurrencyTest.cs +++ b/Jint.Tests.CommonScripts/ConcurrencyTest.cs @@ -11,9 +11,10 @@ public class ConcurrencyTest public void ConcurrentEnginesCanUseSameAst(bool prepared) { var scriptContents = SunSpiderTests.GetEmbeddedFile("babel-standalone.js"); + var experimentalESFeatures = ExperimentalESFeatures.ImportAttributes | ExperimentalESFeatures.RegExpDuplicateNamedCapturingGroups; var script = prepared ? Engine.PrepareScript(scriptContents) - : new Parser(new ParserOptions { EcmaVersion = EcmaVersion.Experimental, RegExpParseMode = RegExpParseMode.AdaptToInterpreted }).ParseScript(scriptContents); + : new Parser(new ParserOptions { EcmaVersion = EcmaVersion.ES2023, ExperimentalESFeatures = experimentalESFeatures, RegExpParseMode = RegExpParseMode.AdaptToInterpreted }).ParseScript(scriptContents); Parallel.ForEach(Enumerable.Range(0, 3), x => { diff --git a/Jint.Tests.Test262/Test262Harness.settings.json b/Jint.Tests.Test262/Test262Harness.settings.json index b08c3ce7f8..5f432ab3f5 100644 --- a/Jint.Tests.Test262/Test262Harness.settings.json +++ b/Jint.Tests.Test262/Test262Harness.settings.json @@ -8,6 +8,7 @@ "Array.fromAsync", "async-iteration", "Atomics", + "decorators", "import-assertions", "iterator-helpers", "regexp-lookbehind", diff --git a/Jint.Tests.Test262/Test262Test.cs b/Jint.Tests.Test262/Test262Test.cs index 584588b078..18bd39d2f6 100644 --- a/Jint.Tests.Test262/Test262Test.cs +++ b/Jint.Tests.Test262/Test262Test.cs @@ -38,7 +38,13 @@ private Engine BuildTestExecutor(Test262File file) throw new Exception("only script parsing supported"); } - var options = new ParserOptions { EcmaVersion = EcmaVersion.Experimental, RegExpParseMode = RegExpParseMode.AdaptToInterpreted, Tolerant = false }; + var options = new ParserOptions + { + EcmaVersion = EcmaVersion.ES2023, + ExperimentalESFeatures = ExperimentalESFeatures.ImportAttributes | ExperimentalESFeatures.RegExpDuplicateNamedCapturingGroups, + RegExpParseMode = RegExpParseMode.AdaptToInterpreted, + Tolerant = false + }; var parser = new Parser(options); var script = parser.ParseScript(args.At(0).AsString()); diff --git a/Jint/AstExtensions.cs b/Jint/AstExtensions.cs index 3bf5e4cd50..cb6ce8735d 100644 --- a/Jint/AstExtensions.cs +++ b/Jint/AstExtensions.cs @@ -15,6 +15,8 @@ namespace Jint { public static class AstExtensions { + internal static readonly SourceLocation DefaultLocation; + public static JsValue GetKey(this T property, Engine engine) where T : IProperty => GetKey(property.Key, engine, property.Computed); public static JsValue GetKey(this Expression expression, Engine engine, bool resolveComputed = false) @@ -290,18 +292,6 @@ internal static void PrivateBoundIdentifiers(this Node parameter, HashSet -/// Helper to map Esprima error messages. -/// -internal static class Messages -{ - public const string InvalidLHSInAssignment = "Invalid left-hand side in assignment"; -} diff --git a/Jint/Native/Function/EvalFunction.cs b/Jint/Native/Function/EvalFunction.cs index 89049423ef..bdcc54db91 100644 --- a/Jint/Native/Function/EvalFunction.cs +++ b/Jint/Native/Function/EvalFunction.cs @@ -91,9 +91,7 @@ internal JsValue PerformEval(JsValue x, Realm callerRealm, bool strictCaller, bo } catch (ParseErrorException e) { - // TODO: This may be not reliable as Acornima messages are translatable. - // Also, there are multiple InvalidLHS messages. - if (string.Equals(e.Description, Messages.InvalidLHSInAssignment, StringComparison.Ordinal)) + if (string.Equals(e.Error.Code, "InvalidLhsInAssignment", StringComparison.Ordinal)) { ExceptionHelper.ThrowReferenceError(callerRealm, (string?) null); } diff --git a/Jint/Native/RegExp/RegExpConstructor.cs b/Jint/Native/RegExp/RegExpConstructor.cs index 049a4bd7aa..e78b69bd59 100644 --- a/Jint/Native/RegExp/RegExpConstructor.cs +++ b/Jint/Native/RegExp/RegExpConstructor.cs @@ -104,7 +104,7 @@ private JsRegExp RegExpInitialize(JsRegExp r, JsValue pattern, JsValue flags) try { - var regExpParseResult = Tokenizer.AdaptRegExp(p, f, compiled: false, _engine.Options.Constraints.RegexTimeout, EcmaVersion.Experimental); + var regExpParseResult = Tokenizer.AdaptRegExp(p, f, compiled: false, _engine.Options.Constraints.RegexTimeout, experimentalESFeatures: Engine.BaseParserOptions.ExperimentalESFeatures); if (!regExpParseResult.Success) { diff --git a/Jint/Native/ShadowRealm/ShadowRealm.cs b/Jint/Native/ShadowRealm/ShadowRealm.cs index 4d7b1834fb..12489c4003 100644 --- a/Jint/Native/ShadowRealm/ShadowRealm.cs +++ b/Jint/Native/ShadowRealm/ShadowRealm.cs @@ -114,9 +114,9 @@ internal JsValue PerformShadowRealmEval(string sourceText, Realm callerRealm) } catch (ParseErrorException e) { - if (string.Equals(e.Description, Messages.InvalidLHSInAssignment, StringComparison.Ordinal)) + if (string.Equals(e.Error.Code, "InvalidLhsInAssignment", StringComparison.Ordinal)) { - ExceptionHelper.ThrowReferenceError(callerRealm, Messages.InvalidLHSInAssignment); + ExceptionHelper.ThrowReferenceError(callerRealm, e.Description); } else { diff --git a/Jint/Runtime/CallStack/CallStackElement.cs b/Jint/Runtime/CallStack/CallStackElement.cs index 3ab32448e8..14dcaef11b 100644 --- a/Jint/Runtime/CallStack/CallStackElement.cs +++ b/Jint/Runtime/CallStack/CallStackElement.cs @@ -22,17 +22,18 @@ public CallStackElement( public readonly JintExpression? Expression; public readonly CallStackExecutionContext CallingExecutionContext; - public SourceLocation Location + public ref readonly SourceLocation Location { get { - var expressionLocation = Expression?._expression.Location; - if (expressionLocation != null && expressionLocation.Value != default) + ref readonly var expressionLocation = ref (Expression is not null ? ref Expression._expression.LocationRef : ref AstExtensions.DefaultLocation); + if (expressionLocation != default) { - return expressionLocation.Value; + return ref expressionLocation; } - return ((Node?) Function._functionDefinition?.Function)?.Location ?? default; + var function = (Node?) Function._functionDefinition?.Function; + return ref (function is not null ? ref function.LocationRef : ref AstExtensions.DefaultLocation); } } diff --git a/Jint/Runtime/Completion.cs b/Jint/Runtime/Completion.cs index 8f27906a29..6d9d5658c8 100644 --- a/Jint/Runtime/Completion.cs +++ b/Jint/Runtime/Completion.cs @@ -38,7 +38,7 @@ public Completion(CompletionType type, JsValue value, Node source) public readonly CompletionType Type; public readonly JsValue Value; - public readonly SourceLocation Location => _source.Location; + public readonly ref readonly SourceLocation Location => ref _source.LocationRef; public static ref readonly Completion Empty() => ref _emptyCompletion; diff --git a/Jint/Runtime/Debugger/CallFrame.cs b/Jint/Runtime/Debugger/CallFrame.cs index 7e096748db..8005001747 100644 --- a/Jint/Runtime/Debugger/CallFrame.cs +++ b/Jint/Runtime/Debugger/CallFrame.cs @@ -9,18 +9,19 @@ namespace Jint.Runtime.Debugger public sealed class CallFrame { private readonly CallStackExecutionContext _context; + private SourceLocation _location; private readonly CallStackElement? _element; private readonly Lazy _scopeChain; internal CallFrame( CallStackElement? element, in CallStackExecutionContext context, - SourceLocation location, + in SourceLocation location, JsValue? returnValue) { _element = element; _context = context; - Location = location; + _location = location; ReturnValue = returnValue; _scopeChain = new Lazy(() => new DebugScopes(Environment)); @@ -43,7 +44,7 @@ internal CallFrame( /// /// Currently executing source location in this call frame. /// - public SourceLocation Location { get; } + public ref SourceLocation Location => ref _location; /// /// The scope chain of this call frame. diff --git a/Jint/Runtime/Debugger/DebugHandler.cs b/Jint/Runtime/Debugger/DebugHandler.cs index e92360b13f..60a64ff6e0 100644 --- a/Jint/Runtime/Debugger/DebugHandler.cs +++ b/Jint/Runtime/Debugger/DebugHandler.cs @@ -177,7 +177,7 @@ internal void OnReturnPoint(Node functionBody, JsValue returnValue) private void CheckBreakPointAndPause( Node? node, - SourceLocation location, + in SourceLocation location, JsValue? returnValue = null) { CurrentLocation = location; @@ -216,7 +216,7 @@ private void CheckBreakPointAndPause( private void Pause( PauseType type, Node? node, - SourceLocation location, + in SourceLocation location, JsValue? returnValue = null, BreakPoint? breakPoint = null) { diff --git a/Jint/Runtime/Debugger/DebugInformation.cs b/Jint/Runtime/Debugger/DebugInformation.cs index 07586ee511..17e630b48e 100644 --- a/Jint/Runtime/Debugger/DebugInformation.cs +++ b/Jint/Runtime/Debugger/DebugInformation.cs @@ -57,7 +57,7 @@ internal DebugInformation( /// The current source Location. /// For return points, this starts and ends at the end of the function body. /// - public SourceLocation Location => CurrentCallFrame.Location; + public ref readonly SourceLocation Location => ref CurrentCallFrame.Location; /// /// Not implemented. Will always return 0. diff --git a/Jint/Runtime/Environments/FunctionEnvironment.cs b/Jint/Runtime/Environments/FunctionEnvironment.cs index 8a1e8714af..b2c9802583 100644 --- a/Jint/Runtime/Environments/FunctionEnvironment.cs +++ b/Jint/Runtime/Environments/FunctionEnvironment.cs @@ -300,7 +300,7 @@ private void HandleRestElementArray( { SetItemSafely(restIdentifier.Name, array, initiallyEmpty); } - else if (restElement.Argument.AsBindingPatternNode() is { } bindingPattern) + else if (restElement.Argument is DestructuringPattern bindingPattern) { SetFunctionParameter(context, bindingPattern, new [] { array }, 0, initiallyEmpty); } diff --git a/Jint/Runtime/ExceptionHelper.cs b/Jint/Runtime/ExceptionHelper.cs index 196e7529d7..6e2d0ef012 100644 --- a/Jint/Runtime/ExceptionHelper.cs +++ b/Jint/Runtime/ExceptionHelper.cs @@ -24,7 +24,7 @@ public static void ThrowSyntaxError(Realm realm, string? message = null) } [DoesNotReturn] - public static void ThrowSyntaxError(Realm realm, string message, SourceLocation location) + public static void ThrowSyntaxError(Realm realm, string message, in SourceLocation location) { throw new JavaScriptException(realm.Intrinsics.SyntaxError, message).SetJavaScriptLocation(location); } diff --git a/Jint/Runtime/IScriptOrModule.Extensions.cs b/Jint/Runtime/IScriptOrModule.Extensions.cs index 483e429209..344c62be3e 100644 --- a/Jint/Runtime/IScriptOrModule.Extensions.cs +++ b/Jint/Runtime/IScriptOrModule.Extensions.cs @@ -5,7 +5,7 @@ namespace Jint.Runtime; internal static class ScriptOrModuleExtensions { - public static Module AsModule(this IScriptOrModule? scriptOrModule, Engine engine, SourceLocation location) + public static Module AsModule(this IScriptOrModule? scriptOrModule, Engine engine, in SourceLocation location) { if (scriptOrModule is not Module module) { diff --git a/Jint/Runtime/Interpreter/Expressions/BindingPatternAssignmentExpression.cs b/Jint/Runtime/Interpreter/Expressions/BindingPatternAssignmentExpression.cs index f635099566..bad01852e0 100644 --- a/Jint/Runtime/Interpreter/Expressions/BindingPatternAssignmentExpression.cs +++ b/Jint/Runtime/Interpreter/Expressions/BindingPatternAssignmentExpression.cs @@ -9,13 +9,13 @@ namespace Jint.Runtime.Interpreter.Expressions { internal sealed class BindingPatternAssignmentExpression : JintExpression { - private readonly IDestructuringPattern _pattern; + private readonly DestructuringPattern _pattern; private JintExpression _right = null!; private bool _initialized; public BindingPatternAssignmentExpression(AssignmentExpression expression) : base(expression) { - _pattern = (IDestructuringPattern) expression.Left; + _pattern = (DestructuringPattern) expression.Left; } protected override object EvaluateInternal(EvaluationContext context) @@ -43,7 +43,7 @@ protected override object EvaluateInternal(EvaluationContext context) internal static JsValue ProcessPatterns( EvaluationContext context, - IDestructuringPattern pattern, + DestructuringPattern pattern, JsValue argument, Environment? environment, bool checkPatternPropertyReference = true) @@ -158,7 +158,7 @@ private static JsValue HandleArrayPattern( AssignToReference(engine, reference, value, environment); } - else if (left.AsBindingPattern() is { } bindingPattern) + else if (left is DestructuringPattern bindingPattern) { JsValue value; if (arrayOperations != null) @@ -216,9 +216,9 @@ private static JsValue HandleArrayPattern( { AssignToIdentifier(engine, leftIdentifier.Name, array, environment, checkReference); } - else if ((bindingPattern = restElement.Argument.AsBindingPattern()) is not null) + else if (restElement.Argument is DestructuringPattern bp) { - ProcessPatterns(context, bindingPattern, array, environment); + ProcessPatterns(context, bp, array, environment); } else { @@ -257,9 +257,9 @@ private static JsValue HandleArrayPattern( AssignToIdentifier(engine, leftIdentifier.Name, value, environment, checkReference); } - else if ((bindingPattern = assignmentPattern.Left.AsBindingPattern()) is not null) + else if (assignmentPattern.Left is DestructuringPattern bp) { - ProcessPatterns(context, bindingPattern, value, environment); + ProcessPatterns(context, bp, value, environment); } } else @@ -299,7 +299,6 @@ private static JsValue HandleObjectPattern( : null; var source = TypeConverter.ToObject(context.Engine.Realm, argument); - IDestructuringPattern? bindingPattern; for (var i = 0; i < pattern.Properties.Count; i++) { if (pattern.Properties[i] is AssignmentProperty p) @@ -336,9 +335,9 @@ private static JsValue HandleObjectPattern( value = completion; } - if ((bindingPattern = assignmentPattern.Left.AsBindingPattern()) is not null) + if (assignmentPattern.Left is DestructuringPattern bp) { - ProcessPatterns(context, bindingPattern, value, environment); + ProcessPatterns(context, bp, value, environment); continue; } @@ -351,7 +350,7 @@ private static JsValue HandleObjectPattern( AssignToIdentifier(context.Engine, target!.Name, value, environment, checkReference); } - else if ((bindingPattern = p.Value.AsBindingPattern()) is not null) + else if (p.Value is DestructuringPattern bindingPattern) { var value = source.Get(sourceKey); ProcessPatterns(context, bindingPattern, value, environment); @@ -380,9 +379,9 @@ private static JsValue HandleObjectPattern( source.CopyDataProperties(rest, processedProperties); AssignToIdentifier(context.Engine, leftIdentifier.Name, rest, environment, checkReference); } - else if ((bindingPattern = restElement.Argument.AsBindingPattern()) is not null) + else if (restElement.Argument is DestructuringPattern bp) { - ProcessPatterns(context, bindingPattern, argument, environment); + ProcessPatterns(context, bp, argument, environment); } else if (restElement.Argument is MemberExpression memberExpression) { diff --git a/Jint/Runtime/Interpreter/Expressions/JintAssignmentExpression.cs b/Jint/Runtime/Interpreter/Expressions/JintAssignmentExpression.cs index 6ff85115c4..f64c8d3509 100644 --- a/Jint/Runtime/Interpreter/Expressions/JintAssignmentExpression.cs +++ b/Jint/Runtime/Interpreter/Expressions/JintAssignmentExpression.cs @@ -29,7 +29,7 @@ internal static JintExpression Build(AssignmentExpression expression) { if (expression.Operator == Operator.Assignment) { - if (expression.Left.AsBindingPatternNode() is not null) + if (expression.Left is DestructuringPattern) { return new BindingPatternAssignmentExpression(expression); } diff --git a/Jint/Runtime/Interpreter/Statements/JintForInForOfStatement.cs b/Jint/Runtime/Interpreter/Statements/JintForInForOfStatement.cs index 1cc82353a5..ff2cf087d2 100644 --- a/Jint/Runtime/Interpreter/Statements/JintForInForOfStatement.cs +++ b/Jint/Runtime/Interpreter/Statements/JintForInForOfStatement.cs @@ -20,7 +20,7 @@ internal sealed class JintForInForOfStatement : JintStatement private ProbablyBlockStatement _body; private JintExpression? _expr; - private IDestructuringPattern? _assignmentPattern; + private DestructuringPattern? _assignmentPattern; private JintExpression _right = null!; private List? _tdzNames; private bool _destructuring; @@ -46,7 +46,6 @@ protected override void Initialize(EvaluationContext context) { _lhsKind = LhsKind.Assignment; var engine = context.Engine; - IDestructuringPattern? bindingPattern; if (_leftNode is VariableDeclaration variableDeclaration) { _lhsKind = variableDeclaration.Kind == VariableDeclarationKind.Var @@ -61,7 +60,7 @@ protected override void Initialize(EvaluationContext context) id.GetBoundNames(_tdzNames); } - if ((bindingPattern = id.AsBindingPattern()) is not null) + if (id is DestructuringPattern bindingPattern) { _destructuring = true; _assignmentPattern = bindingPattern; @@ -72,7 +71,7 @@ protected override void Initialize(EvaluationContext context) _expr = new JintIdentifierExpression(identifier); } } - else if ((bindingPattern = _leftNode.AsBindingPattern()) is not null) + else if (_leftNode is DestructuringPattern bindingPattern) { _destructuring = true; _assignmentPattern = bindingPattern; diff --git a/Jint/Runtime/Interpreter/Statements/JintStatement.cs b/Jint/Runtime/Interpreter/Statements/JintStatement.cs index 1e53648335..688cbc0dc1 100644 --- a/Jint/Runtime/Interpreter/Statements/JintStatement.cs +++ b/Jint/Runtime/Interpreter/Statements/JintStatement.cs @@ -46,7 +46,7 @@ public Completion Execute(EvaluationContext context) protected abstract Completion ExecuteInternal(EvaluationContext context); - public SourceLocation Location => _statement.Location; + public ref readonly SourceLocation Location => ref _statement.LocationRef; /// /// Opportunity to build one-time structures and caching based on lexical context. diff --git a/Jint/Runtime/Interpreter/Statements/JintVariableDeclaration.cs b/Jint/Runtime/Interpreter/Statements/JintVariableDeclaration.cs index 2c29ddd4a1..17dc85467d 100644 --- a/Jint/Runtime/Interpreter/Statements/JintVariableDeclaration.cs +++ b/Jint/Runtime/Interpreter/Statements/JintVariableDeclaration.cs @@ -12,7 +12,7 @@ internal sealed class JintVariableDeclaration : JintStatement ref _location; - internal void SetLocation(SourceLocation location) + internal void SetLocation(in SourceLocation location) { _location = location; } - internal void SetCallstack(Engine engine, SourceLocation location, bool overwriteExisting) + internal void SetCallstack(Engine engine, in SourceLocation location, bool overwriteExisting) { _location = location; diff --git a/Jint/Runtime/Modules/CyclicModule.cs b/Jint/Runtime/Modules/CyclicModule.cs index ec38fa7d60..6242ba0f81 100644 --- a/Jint/Runtime/Modules/CyclicModule.cs +++ b/Jint/Runtime/Modules/CyclicModule.cs @@ -33,6 +33,7 @@ public abstract class CyclicModule : Module private int _pendingAsyncDependencies; internal JsValue _evalResult; + private SourceLocation _abnormalCompletionLocation; internal CyclicModule(Engine engine, Realm realm, string location, bool async) : base(engine, realm, location) { @@ -40,7 +41,7 @@ internal CyclicModule(Engine engine, Realm realm, string location, bool async) : internal ModuleStatus Status { get; private set; } - internal SourceLocation AbnormalCompletionLocation { get; private set; } + internal ref readonly SourceLocation AbnormalCompletionLocation => ref _abnormalCompletionLocation; /// /// https://tc39.es/ecma262/#sec-moduledeclarationlinking @@ -132,7 +133,7 @@ public override JsValue Evaluate() m._evalError = result; } - AbnormalCompletionLocation = result.Location; + _abnormalCompletionLocation = result.Location; capability.Reject.Call(Undefined, new[] { result.Value }); } else diff --git a/Jint/Runtime/Modules/ModuleFactory.cs b/Jint/Runtime/Modules/ModuleFactory.cs index 59aa4eae6a..2135ee21e1 100644 --- a/Jint/Runtime/Modules/ModuleFactory.cs +++ b/Jint/Runtime/Modules/ModuleFactory.cs @@ -35,7 +35,7 @@ public static Module BuildSourceTextModule(Engine engine, ResolvedSpecifier reso } catch (Exception) { - ExceptionHelper.ThrowJavaScriptException(engine, $"Could not load module {source}", default(SourceLocation)); + ExceptionHelper.ThrowJavaScriptException(engine, $"Could not load module {source}", AstExtensions.DefaultLocation); module = null; } @@ -75,7 +75,7 @@ public static Module BuildJsonModule(Engine engine, ResolvedSpecifier resolved, } catch (Exception) { - ExceptionHelper.ThrowJavaScriptException(engine, $"Could not load module {source}", default(SourceLocation)); + ExceptionHelper.ThrowJavaScriptException(engine, $"Could not load module {source}", AstExtensions.DefaultLocation); module = null; } diff --git a/Jint/Runtime/Modules/ModuleLoader.cs b/Jint/Runtime/Modules/ModuleLoader.cs index 104b4dbdac..c2ce1c7b3a 100644 --- a/Jint/Runtime/Modules/ModuleLoader.cs +++ b/Jint/Runtime/Modules/ModuleLoader.cs @@ -18,7 +18,7 @@ public Module LoadModule(Engine engine, ResolvedSpecifier resolved) } catch (Exception) { - ExceptionHelper.ThrowJavaScriptException(engine, $"Could not load module {resolved.ModuleRequest.Specifier}", default(SourceLocation)); + ExceptionHelper.ThrowJavaScriptException(engine, $"Could not load module {resolved.ModuleRequest.Specifier}", AstExtensions.DefaultLocation); return default!; } diff --git a/Jint/Runtime/TypeConverter.cs b/Jint/Runtime/TypeConverter.cs index 540731a0e7..5fa37b5157 100644 --- a/Jint/Runtime/TypeConverter.cs +++ b/Jint/Runtime/TypeConverter.cs @@ -591,7 +591,7 @@ internal static BigInteger StringToBigInt(string str) if (!TryStringToBigInt(str, out var result)) { // TODO: define a dedicated exception type? - throw new SyntaxError(" Cannot convert " + str + " to a BigInt").ToException(); + throw new SyntaxError("CannotConvertToBigInt", " Cannot convert " + str + " to a BigInt").ToException(); } return result;