Skip to content

Commit 7fabeb5

Browse files
committed
Fix tests
1 parent 511c1cd commit 7fabeb5

11 files changed

Lines changed: 37 additions & 23 deletions

File tree

NiL.JS/BaseLibrary/RegExp.cs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,12 @@ private void makeRegex(Arguments args)
4949
if (args.GetProperty("length")._iValue > 1 && args[1]._valueType > JSValueType.Undefined)
5050
ExceptionHelper.Throw(new TypeError("Cannot supply flags when constructing one RegExp from another"));
5151
_oValue = ptrn._oValue;
52-
_regex = (ptrn.Value as RegExp)._regex;
53-
_global = (ptrn.Value as RegExp)._global;
54-
_sticky = (ptrn.Value as RegExp)._sticky;
55-
_unicode = (ptrn.Value as RegExp)._unicode;
56-
_source = (ptrn.Value as RegExp)._source;
52+
var regExp = ptrn.Value as RegExp;
53+
_regex = regExp._regex;
54+
_global = regExp._global;
55+
_sticky = regExp._sticky;
56+
_unicode = regExp._unicode;
57+
_source = regExp._source;
5758
return;
5859
}
5960
var pattern = ptrn._valueType > JSValueType.Undefined ? ptrn.ToString() : "";

NiL.JS/Core/Interop/Proxy.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -434,7 +434,7 @@ internal JSValue proxyMember(bool forWrite, IList<MemberInfo> m)
434434
{
435435
for (int i = 0; i < m.Count; i++)
436436
if (!(m[i] is MethodBase))
437-
ExceptionHelper.Throw(_context.ProxyValue(new TypeError("Incompatible fields types.")));
437+
ExceptionHelper.Throw(new TypeError("Incompatible fields types."));
438438

439439
var cache = new MethodProxy[m.Count];
440440
for (int i = 0; i < m.Count; i++)

NiL.JS/Core/JSException.cs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,20 +25,21 @@ public JSException(Error data)
2525
}
2626

2727
public JSException(Error data, CodeNode exceptionMaker, string code)
28+
: this(Context.CurrentGlobalContext.ProxyValue(data), exceptionMaker, code)
29+
{
30+
}
31+
32+
public JSException(JSValue data, CodeNode exceptionMaker, string code)
2833
{
2934
Error = Context.CurrentGlobalContext.ProxyValue(data);
3035
ExceptionMaker = exceptionMaker;
3136
Code = code;
32-
if (code != null) {
37+
if (code != null)
38+
{
3339
CodeCoordinates = CodeCoordinates.FromTextPosition(code, exceptionMaker.Position, exceptionMaker.Length);
3440
}
3541
}
3642

37-
public JSException(JSValue data)
38-
{
39-
Error = data;
40-
}
41-
4243
public JSException(JSValue data, Exception innerException)
4344
: base("External error", innerException)
4445
{

NiL.JS/Core/JSValue.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -555,6 +555,7 @@ internal protected virtual JSValue GetProperty(JSValue key, bool forWrite, Prope
555555
{
556556
if (propertyScope == PropertyScope.Own)
557557
return notExists;
558+
558559
forWrite = false;
559560
return Context.CurrentGlobalContext.GetPrototype(typeof(BaseLibrary.Boolean)).GetProperty(key, false, PropertyScope.Common);
560561
}
@@ -563,6 +564,7 @@ internal protected virtual JSValue GetProperty(JSValue key, bool forWrite, Prope
563564
{
564565
if (propertyScope == PropertyScope.Own)
565566
return notExists;
567+
566568
forWrite = false;
567569
return Context.CurrentGlobalContext.GetPrototype(typeof(Number)).GetProperty(key, false, PropertyScope.Common);
568570
}
@@ -581,8 +583,10 @@ internal protected virtual JSValue GetProperty(JSValue key, bool forWrite, Prope
581583
{
582584
if (_oValue == this)
583585
break;
586+
584587
if (_oValue == null)
585588
ExceptionHelper.ThrowTypeError(string.Format(Strings.TryingToGetProperty, key, "null"));
589+
586590
var inObj = _oValue as JSObject;
587591
if (inObj != null)
588592
return inObj.GetProperty(key, forWrite, propertyScope);

NiL.JS/ExceptionHelper.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,9 @@ internal static void Throw(Error error, CodeNode exceptionMaker, Context context
4343
/// </exception>
4444
[MethodImpl(MethodImplOptions.NoInlining)]
4545
[DebuggerStepThrough]
46-
internal static void Throw(JSValue error)
46+
internal static void Throw(JSValue error, CodeNode exceptionMaker, Context context)
4747
{
48-
throw new JSException(error ?? JSValue.undefined);
48+
throw new JSException(error ?? JSValue.undefined, exceptionMaker, GetCode(context));
4949
}
5050

5151
/// <exception cref="NiL.JS.Core.JSException">

NiL.JS/Expressions/AwaitExpression.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public override JSValue Evaluate(Context context)
2424
if ((bool)context.SuspendData[this])
2525
{
2626
context._executionMode = ExecutionMode.Regular;
27-
throw new JSException(context._executionInfo);
27+
ExceptionHelper.Throw(context._executionInfo, this, context);
2828
}
2929
}
3030
else if (context._executionMode == ExecutionMode.Resume)

NiL.JS/Expressions/Yield.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ public override JSValue Evaluate(Context context)
9191
context.SuspendData.Clear();
9292
context._executionMode = ExecutionMode.Regular;
9393
var exceptionData = context._executionInfo;
94-
ExceptionHelper.Throw(exceptionData);
94+
ExceptionHelper.Throw(exceptionData, this, context);
9595
}
9696

9797
if (_reiterate)

NiL.JS/Script.cs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,10 @@ namespace NiL.JS
77
{
88
public sealed class Script
99
{
10+
private static readonly object _scriptStackLock = new();
11+
1012
[ThreadStatic]
11-
private static readonly Stack<Script> _scriptsStack = new Stack<Script>();
13+
private static Stack<Script> _scriptsStack;
1214

1315
internal static Script CurrentScript => _scriptsStack.Count > 0 ? _scriptsStack.Peek() : null;
1416

@@ -67,8 +69,13 @@ public JSValue Evaluate(Context context)
6769
if (Code == "")
6870
return JSValue.Undefined;
6971

70-
lock (_scriptsStack)
72+
lock (_scriptStackLock)
73+
{
74+
if (_scriptsStack == null)
75+
_scriptsStack = new();
76+
7177
_scriptsStack.Push(this);
78+
}
7279

7380
try
7481
{
@@ -81,7 +88,7 @@ public JSValue Evaluate(Context context)
8188
Root._variables[i].cacheContext = null;
8289
context.Deactivate();
8390

84-
lock (_scriptsStack)
91+
lock (_scriptStackLock)
8592
_scriptsStack.Pop();
8693
}
8794
}

NiL.JS/Statements/Throw.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public override JSValue Evaluate(Context context)
5959
if (context._executionMode == ExecutionMode.Suspend)
6060
return null;
6161

62-
ExceptionHelper.Throw(value);
62+
ExceptionHelper.Throw(value, this, context);
6363
return null;
6464
}
6565

NiL.JS/Statements/TryCatch.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ public override JSValue Evaluate(Context context)
141141
continue;
142142

143143
isOurException = true;
144-
stackTrace.Add(" at " + (item.Item1?._owner?.name ?? "<unknown function>") + ": line " + item.Item2.Line);
144+
stackTrace.Add(" at " + (item.Item1?._owner?.name ?? "<unknown function>") + (item.Item2 != null ? ": line " + item.Item2.Line : string.Empty));
145145
}
146146

147147
if (!isOurException)

0 commit comments

Comments
 (0)