Permalink
Browse files

Introduce JsString, JsBoolean etc and support efficient string concat…

…enation (#463)

* introduce JsString and support efficient string concatenation

* introduce JsBoolean, JsNumber and JsObject

* introduce JsNull and JsUndefined, clean up JsValue

* make ObjectInstance JsValue

* favor instance fields for prototype objects instead of thread local

* optimize string concatenation prediction logic

* prefer ReferenceEquals for faster null and undefined checks
  • Loading branch information...
lahma authored and sebastienros committed Jan 10, 2018
1 parent a3c5cb1 commit e0d2e2f2446b9f9bc4cd0d71d5a1523d8e6b2ff8
Showing with 1,331 additions and 969 deletions.
  1. +5 −6 Jint.Tests.CommonScripts/Properties/AssemblyInfo.cs
  2. +0 −9 Jint.Tests.CommonScripts/packages.config
  3. +0 −1 Jint.Tests.Ecma/Properties/AssemblyInfo.cs
  4. +0 −9 Jint.Tests.Ecma/packages.config
  5. +0 −1 Jint.Tests/Parser/JavascriptParserTests.cs
  6. +0 −1 Jint.Tests/ReplaceCulture.cs
  7. +1 −1 Jint.Tests/Runtime/Domain/A.cs
  8. +1 −7 Jint.Tests/Runtime/Domain/Person.cs
  9. +34 −38 Jint.Tests/Runtime/Domain/Shape.cs
  10. +12 −13 Jint.Tests/Runtime/InteropTests.cs
  11. +7 −12 Jint.Tests/Runtime/JsValueConversionTests.cs
  12. +4 −6 Jint.Tests/Runtime/NullPropagation.cs
  13. +0 −10 Jint.Tests/packages.config
  14. +19 −23 Jint/Engine.cs
  15. +2 −2 Jint/Native/Argument/ArgumentsInstance.cs
  16. +0 −10 Jint/Native/Array/ArrayExecutionContext.cs
  17. +2 −2 Jint/Native/Array/ArrayInstance.cs
  18. +42 −33 Jint/Native/Array/ArrayPrototype.cs
  19. +1 −1 Jint/Native/Date/DateConstructor.cs
  20. +1 −1 Jint/Native/Error/ErrorConstructor.cs
  21. +1 −1 Jint/Native/Error/ErrorPrototype.cs
  22. +1 −1 Jint/Native/Function/FunctionConstructor.cs
  23. +2 −2 Jint/Native/Function/FunctionPrototype.cs
  24. +1 −1 Jint/Native/Function/FunctionShim.cs
  25. +4 −6 Jint/Native/Function/ScriptFunctionInstance.cs
  26. +34 −19 Jint/Native/Global/GlobalObject.cs
  27. +72 −0 Jint/Native/JsBoolean.cs
  28. +49 −0 Jint/Native/JsNull.cs
  29. +173 −0 Jint/Native/JsNumber.cs
  30. +210 −0 Jint/Native/JsString.cs
  31. +70 −0 Jint/Native/JsSymbol.cs
  32. +49 −0 Jint/Native/JsUndefined.cs
  33. +76 −532 Jint/Native/JsValue.cs
  34. +7 −8 Jint/Native/Json/JsonInstance.cs
  35. +1 −1 Jint/Native/Json/JsonParser.cs
  36. +2 −2 Jint/Native/Json/JsonSerializer.cs
  37. +1 −1 Jint/Native/Number/NumberPrototype.cs
  38. +4 −4 Jint/Native/Object/ObjectConstructor.cs
  39. +246 −33 Jint/Native/Object/ObjectInstance.cs
  40. +2 −2 Jint/Native/Object/ObjectPrototype.cs
  41. +7 −6 Jint/Native/RegExp/RegExpConstructor.cs
  42. +4 −4 Jint/Native/RegExp/RegExpPrototype.cs
  43. +0 −43 Jint/Native/String/StringExecutionContext.cs
  44. +96 −32 Jint/Native/String/StringPrototype.cs
  45. +3 −3 Jint/Native/Symbol/SymbolConstructor.cs
  46. +2 −2 Jint/Native/Symbol/SymbolPrototype.cs
  47. +2 −2 Jint/Native/Undefined.cs
  48. +1 −1 Jint/Runtime/Descriptors/PropertyDescriptor.cs
  49. +5 −5 Jint/Runtime/Environments/DeclarativeEnvironmentRecord.cs
  50. +5 −5 Jint/Runtime/Environments/ObjectEnvironmentRecord.cs
  51. +30 −19 Jint/Runtime/ExpressionIntepreter.cs
  52. +2 −2 Jint/Runtime/Interop/MethodInfoFunctionInstance.cs
  53. +7 −5 Jint/Runtime/Interop/NamespaceReference.cs
  54. +2 −2 Jint/Runtime/Interop/SetterFunctionInstance.cs
  55. +15 −24 Jint/Runtime/Interop/TypeReference.cs
  56. +2 −2 Jint/Runtime/JavaScriptException.cs
  57. +1 −1 Jint/Runtime/References/Reference.cs
  58. +1 −2 Jint/Runtime/StatementInterpreter.cs
  59. +10 −10 Jint/Runtime/TypeConverter.cs
@@ -1,8 +1,7 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("Jint.Tests.CommonScripts")]
@@ -14,8 +13,8 @@
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]
@@ -25,11 +24,11 @@
// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]

This file was deleted.

Oops, something went wrong.
@@ -1,5 +1,4 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using Xunit;

This file was deleted.

Oops, something went wrong.
@@ -1,5 +1,4 @@
using System;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
@@ -4,7 +4,6 @@
using System;
using System.Globalization;
using System.Reflection;
using System.Threading;
using Xunit.Sdk;
namespace Jint.Tests
@@ -40,7 +40,7 @@ public string Call5(Delegate callback)
public string Call6(Func<JsValue, JsValue[], JsValue> callback)
{
var thisArg = new JsValue("bar");
var thisArg = new JsString("bar");
var arguments = new JsValue[] { 1, "foo" };
return callback(thisArg, arguments).ToString();
@@ -1,10 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Jint.Tests.Runtime.Domain
namespace Jint.Tests.Runtime.Domain
{
public class Person : IPerson
{
@@ -1,8 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Jint.Tests.Runtime.Domain;
namespace Shapes
@@ -15,40 +11,40 @@ public abstract class Shape
}
public class Circle : Shape
{
public class Meta
{
public Meta()
{
_description = "descp";
}
private string _description;
public string Description
{
get
{
return _description;
}
set
{
_description = value;
}
}
public enum Usage
{
Public,
Private,
Internal = 11
}
}
public enum Kind
{
Unit,
Ellipse,
Round = 5
{
public class Meta
{
public Meta()
{
_description = "descp";
}
private string _description;
public string Description
{
get
{
return _description;
}
set
{
_description = value;
}
}
public enum Usage
{
Public,
Private,
Internal = 11
}
}
public enum Kind
{
Unit,
Ellipse,
Round = 5
}
public Circle()
@@ -1,6 +1,5 @@
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Reflection;
using Jint.Native;
using Jint.Native.Object;
@@ -411,8 +410,8 @@ public void PocosCanReturnJsValueDirectly()
{
var o = new
{
x = new JsValue(1),
y = new JsValue("string"),
x = new JsNumber(1),
y = new JsString("string"),
};
_engine.SetValue("o", o);
@@ -427,7 +426,7 @@ public void PocosCanReturnJsValueDirectly()
public void PocosCanReturnObjectInstanceDirectly()
{
var x = new ObjectInstance(_engine) { Extensible = true};
x.Put("foo", new JsValue("bar"), false);
x.Put("foo", new JsString("bar"), false);
var o = new
{
@@ -1487,7 +1486,7 @@ public void ShouldNotCatchClrExceptions()
try {
throwMyException();
return;
}
}
catch(e) {
return;
}
@@ -1497,7 +1496,7 @@ public void ShouldNotCatchClrExceptions()
try {
new Thrower().ThrowNotSupportedException();
return;
}
}
catch(e) {
return;
}
@@ -1521,7 +1520,7 @@ public void ShouldCatchAllClrExceptions()
try {
throwMyException();
return '';
}
}
catch(e) {
return e.message;
}
@@ -1531,7 +1530,7 @@ public void ShouldCatchAllClrExceptions()
try {
new Thrower().ThrowExceptionWithMessage('myExceptionMessage');
return;
}
}
catch(e) {
return e.message;
}
@@ -1556,7 +1555,7 @@ public void ShouldCatchSomeExceptions()
try {
throwMyException1();
return '';
}
}
catch(e) {
return e.message;
}
@@ -1566,7 +1565,7 @@ public void ShouldCatchSomeExceptions()
try {
throwMyException2();
return '';
}
}
catch(e) {
return e.message;
}
@@ -1576,7 +1575,7 @@ public void ShouldCatchSomeExceptions()
try {
new Thrower().ThrowNotSupportedExceptionWithMessage('myExceptionMessage');
return '';
}
}
catch(e) {
return e.message;
}
@@ -1586,13 +1585,13 @@ public void ShouldCatchSomeExceptions()
try {
new Thrower().ThrowArgumentNullException();
return '';
}
}
catch(e) {
return e.message;
}
}
");
Assert.Equal(engine.Invoke("throwException1").AsString(), exceptionMessage);
Assert.Throws<ArgumentNullException>(() => engine.Invoke("throwException2"));
Assert.Equal(engine.Invoke("throwException3").AsString(), exceptionMessage);
@@ -3,11 +3,6 @@
using Jint.Native.Date;
using Jint.Native.Object;
using Jint.Native.RegExp;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Xunit;
namespace Jint.Tests.Runtime
@@ -17,7 +12,7 @@ public class JsValueConversionTests
[Fact]
public void ShouldBeAnArray()
{
var value = new JsValue(new ArrayInstance(null));
var value = new ArrayInstance(null);
Assert.Equal(false, value.IsBoolean());
Assert.Equal(true, value.IsArray());
Assert.Equal(false, value.IsDate());
@@ -35,7 +30,7 @@ public void ShouldBeAnArray()
[Fact]
public void ShouldBeABoolean()
{
var value = new JsValue(true);
var value = new JsBoolean(true);
Assert.Equal(true, value.IsBoolean());
Assert.Equal(false, value.IsArray());
Assert.Equal(false, value.IsDate());
@@ -53,7 +48,7 @@ public void ShouldBeABoolean()
[Fact]
public void ShouldBeADate()
{
var value = new JsValue(new DateInstance(null));
var value = new DateInstance(null);
Assert.Equal(false, value.IsBoolean());
Assert.Equal(false, value.IsArray());
Assert.Equal(true, value.IsDate());
@@ -87,7 +82,7 @@ public void ShouldBeNull()
[Fact]
public void ShouldBeANumber()
{
var value = new JsValue(2);
var value = new JsNumber(2);
Assert.Equal(false, value.IsBoolean());
Assert.Equal(false, value.IsArray());
Assert.Equal(false, value.IsDate());
@@ -104,7 +99,7 @@ public void ShouldBeANumber()
[Fact]
public void ShouldBeAnObject()
{
var value = new JsValue(new ObjectInstance(null));
var value = new ObjectInstance(null);
Assert.Equal(false, value.IsBoolean());
Assert.Equal(false, value.IsArray());
Assert.Equal(false, value.IsDate());
@@ -121,7 +116,7 @@ public void ShouldBeAnObject()
[Fact]
public void ShouldBeARegExp()
{
var value = new JsValue(new RegExpInstance(null));
var value = new RegExpInstance(null);
Assert.Equal(false, value.IsBoolean());
Assert.Equal(false, value.IsArray());
Assert.Equal(false, value.IsDate());
@@ -138,7 +133,7 @@ public void ShouldBeARegExp()
[Fact]
public void ShouldBeAString()
{
var value = new JsValue("a");
var value = new JsString("a");
Assert.Equal(false, value.IsBoolean());
Assert.Equal(false, value.IsArray());
Assert.Equal(false, value.IsDate());
@@ -24,12 +24,10 @@ public bool TryPropertyReference(Engine engine, Reference reference, ref JsValue
public bool TryGetCallable(Engine engine, object reference, out JsValue value)
{
value = new JsValue(
new ClrFunctionInstance(engine, (thisObj, values) => thisObj)
);
value = new ClrFunctionInstance(engine, (thisObj, values) => thisObj);
return true;
}
public bool CheckCoercible(JsValue value)
{
return true;
@@ -42,8 +40,8 @@ public void NullPropagationTest()
var engine = new Engine(cfg => cfg.SetReferencesResolver(new NullPropagationReferenceResolver()));
const string Script = @"
var input = {
Address : null
var input = {
Address : null
};
var address = input.Address;
Oops, something went wrong.

0 comments on commit e0d2e2f

Please sign in to comment.