Skip to content

Commit

Permalink
Clean
Browse files Browse the repository at this point in the history
  • Loading branch information
nilproject committed Dec 9, 2015
1 parent a8b7aaa commit dd3773f
Show file tree
Hide file tree
Showing 20 changed files with 37 additions and 122 deletions.
3 changes: 0 additions & 3 deletions NiL.JS.Portable/NiL.JS.Portable.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -514,9 +514,6 @@
<Compile Include="..\NiL.JS\Extensions\JSValueExtensions.cs">
<Link>Extensions\JSValueExtensions.cs</Link>
</Compile>
<Compile Include="..\NiL.JS\Extensions\ObjectExtensions.cs">
<Link>Extensions\ObjectExtensions.cs</Link>
</Compile>
<Compile Include="..\NiL.JS\Module.cs">
<Link>Module.cs</Link>
</Compile>
Expand Down
4 changes: 2 additions & 2 deletions NiL.JS.Test/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ static void Main(string[] args)
}));

#if PORTABLE
Context.GlobalContext.DefineVariable("console").Assign(new
Context.GlobalContext.DefineVariable("console").Assign(JSValue.Marshal(new
{
log = new Action<Arguments>(arguments =>
{
Expand All @@ -54,7 +54,7 @@ static void Main(string[] args)
}
System.Console.WriteLine();
})
}.WrapToJSValue());
}));
#endif

int mode = 103
Expand Down
2 changes: 1 addition & 1 deletion NiL.JS/BaseLibrary/Array.cs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ internal Array(IEnumerator source)
while (source.MoveNext())
{
var e = source.Current;
data[index++] = (e as JSValue ?? TypeProxy.Marshal(e)).CloneImpl(false);
data[index++] = (e as JSValue ?? TypeProxy.Proxy(e)).CloneImpl(false);
}
attributes |= JSValueAttributesInternal.SystemObject;
}
Expand Down
2 changes: 1 addition & 1 deletion NiL.JS/BaseLibrary/GeneratorFunction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ protected internal override JSValue Invoke(bool construct, JSValue targetObject,
if (construct)
ExceptionsHelper.ThrowTypeError("Generators cannot be invoked as a constructor");

return TypeProxy.Marshal(new GeneratorIterator(this, targetObject, arguments));
return TypeProxy.Proxy(new GeneratorIterator(this, targetObject, arguments));
}

internal override JSObject GetDefaultPrototype()
Expand Down
4 changes: 2 additions & 2 deletions NiL.JS/Core/Functions/MethodGroup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ protected internal override JSValue Invoke(bool construct, JSValue targetObject,
for (var i = 0; i < methods.Length; i++)
{
if (methods[i].Parameters.Length == 1 && methods[i].Parameters[0].ParameterType == typeof(Arguments))
return TypeProxy.Marshal(methods[i].InvokeImpl(targetObject, null, arguments));
return TypeProxy.Proxy(methods[i].InvokeImpl(targetObject, null, arguments));
if (pass == 1 || methods[i].Parameters.Length == l)
{
if (l != 0)
Expand All @@ -88,7 +88,7 @@ protected internal override JSValue Invoke(bool construct, JSValue targetObject,
if (cargs == null)
continue;
}
return TypeProxy.Marshal(methods[i].InvokeImpl(targetObject, cargs, arguments));
return TypeProxy.Proxy(methods[i].InvokeImpl(targetObject, cargs, arguments));
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions NiL.JS/Core/Functions/MethodProxy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,7 @@ internal override JSValue InternalInvoke(JSValue targetObject, Expressions.Expre
}
}
}
return Interop.TypeProxy.Marshal(InvokeImpl(targetObject, args, null));
return Interop.TypeProxy.Proxy(InvokeImpl(targetObject, args, null));
}
}

Expand Down Expand Up @@ -538,7 +538,7 @@ internal object[] ConvertArgs(Arguments source, bool dummyValueTypes)

protected internal override JSValue Invoke(bool construct, JSValue targetObject, Arguments arguments, Function newTarget)
{
return Interop.TypeProxy.Marshal(InvokeImpl(targetObject, null, arguments));
return Interop.TypeProxy.Proxy(InvokeImpl(targetObject, null, arguments));
}

private static object[] convertArray(NiL.JS.BaseLibrary.Array array)
Expand Down
2 changes: 1 addition & 1 deletion NiL.JS/Core/Interop/NativeList.cs
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ public JSValue pop()
if (result is IList)
return new NativeList(result as IList);
else
return TypeProxy.Marshal(result);
return TypeProxy.Proxy(result);
}

protected internal override JSValue GetProperty(JSValue key, bool forWrite, PropertyScope memberScope)
Expand Down
8 changes: 4 additions & 4 deletions NiL.JS/Core/Interop/TypeProxy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ private TypeProxy(Type type)
}
}

public static JSValue Marshal(object value)
public static JSValue Proxy(object value)
{
JSValue res;
if (value == null)
Expand Down Expand Up @@ -559,7 +559,7 @@ private JSValue proxyMember(bool forWrite, IList<MemberInfo> m)
{
for (int i = 0; i < m.Count; i++)
if (!(m[i] is MethodBase))
ExceptionsHelper.Throw(Marshal(new TypeError("Incompatible fields types.")));
ExceptionsHelper.Throw(Proxy(new TypeError("Incompatible fields types.")));
var cache = new MethodProxy[m.Count];
for (int i = 0; i < m.Count; i++)
cache[i] = new MethodProxy(m[i] as MethodBase);
Expand All @@ -586,7 +586,7 @@ private JSValue proxyMember(bool forWrite, IList<MemberInfo> m)
if ((field.Attributes & (FieldAttributes.Literal | FieldAttributes.InitOnly)) != 0
&& (field.Attributes & FieldAttributes.Static) != 0)
{
r = Marshal(field.GetValue(null));
r = Proxy(field.GetValue(null));
r.attributes |= JSValueAttributesInternal.ReadOnly;
}
else
Expand All @@ -596,7 +596,7 @@ private JSValue proxyMember(bool forWrite, IList<MemberInfo> m)
valueType = JSValueType.Property,
oValue = new GsPropertyPair
(
new ExternalFunction((thisBind, a) => Marshal(field.GetValue(field.IsStatic ? null : thisBind.Value))),
new ExternalFunction((thisBind, a) => Proxy(field.GetValue(field.IsStatic ? null : thisBind.Value))),
!m[0].IsDefined(typeof(Interop.ReadOnlyAttribute), false) ? new ExternalFunction((thisBind, a) =>
{
field.SetValue(field.IsStatic ? null : thisBind.Value, a[0].Value);
Expand Down
4 changes: 2 additions & 2 deletions NiL.JS/Core/JSException.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public sealed class JSException : Exception

public JSException(Error avatar)
{
Avatar = TypeProxy.Marshal(avatar);
Avatar = TypeProxy.Proxy(avatar);
}

public JSException(JSValue avatar)
Expand All @@ -33,7 +33,7 @@ public JSException(JSValue avatar, Exception innerException)
public JSException(Error avatar, Exception innerException)
: base("", innerException)
{
Avatar = TypeProxy.Marshal(avatar);
Avatar = TypeProxy.Proxy(avatar);
}

public override string Message
Expand Down
15 changes: 14 additions & 1 deletion NiL.JS/Core/JSValue.cs
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,8 @@ internal bool NeedClone
#if INLINE
[MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)]
#endif
get { return (attributes & (JSValueAttributesInternal.ReadOnly | JSValueAttributesInternal.SystemObject)) == JSValueAttributesInternal.SystemObject; }
get
{ return (attributes & (JSValueAttributesInternal.ReadOnly | JSValueAttributesInternal.SystemObject)) == JSValueAttributesInternal.SystemObject; }
}

internal bool IsBox
Expand Down Expand Up @@ -1161,5 +1162,17 @@ public virtual int CompareTo(JSValue other)
}

#endregion

public static JSValue Marshal(object value)
{
return TypeProxy.Proxy(value);
}

public static JSValue Wrap(object value)
{
if (value == null)
return JSValue.Null;
return new ObjectWrapper(value);
}
}
}
2 changes: 1 addition & 1 deletion NiL.JS/Core/Tools.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1520,7 +1520,7 @@ internal static LambdaExpression BuildJsCallTree(string name, Expression functio
expressions.Add(Expression.Call(
argumentsParameter,
typeof(Arguments).GetRuntimeMethod("Add", new[] { typeof(JSValue) }),
Expression.Call(Tools.methodof<object, JSValue>(TypeProxy.Marshal), handlerArgumentsParameters[i])));
Expression.Call(Tools.methodof<object, JSValue>(TypeProxy.Proxy), handlerArgumentsParameters[i])));
}
}

Expand Down
2 changes: 1 addition & 1 deletion NiL.JS/Extensions/IterationProtocolExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public EnumeratorToIteratorWrapper(IEnumerator enumerator)

public IIteratorResult next(Arguments arguments = null)
{
return new EnumeratorResult(!enumerator.MoveNext(), TypeProxy.Marshal(enumerator.Current));
return new EnumeratorResult(!enumerator.MoveNext(), TypeProxy.Proxy(enumerator.Current));
}

public IIteratorResult @return()
Expand Down
69 changes: 0 additions & 69 deletions NiL.JS/Extensions/JSValueExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
using System;
using System.Linq;
using System.Linq.Expressions;
using System.Reflection;
using System.Reflection.Emit;
using NiL.JS.Core;

namespace NiL.JS.Extensions
Expand Down Expand Up @@ -165,70 +161,5 @@ public static T As<T>(this JSValue self)
}
throw new InvalidCastException();
}

#if DEBUG && !PORTABLE // TODO
private static WeakReference<AssemblyBuilder> dynamicAssembly = new WeakReference<AssemblyBuilder>(null);

public static T AsImplementationOf<T>(this JSValue self)
{
if (!typeof(T).IsInterface)
throw new ArgumentException(typeof(T).FullName + " is not an interface type");

if (self.oValue is T)
return (T)self.oValue;
if (typeof(T) == typeof(IIterable))
return (T)self.AsIterable();
if (typeof(T) == typeof(IIterator))
return (T)(object)new IteratorAdapter(self);

AssemblyBuilder assemblyBuilder;
if (!dynamicAssembly.TryGetTarget(out assemblyBuilder))
{
assemblyBuilder = AppDomain.CurrentDomain.DefineDynamicAssembly(new AssemblyName("<nil.js>DynamicAssembly"), AssemblyBuilderAccess.RunAndCollect);
dynamicAssembly.SetTarget(assemblyBuilder);
}

var module = assemblyBuilder.GetDynamicModule("InterfaceImplementations") ?? assemblyBuilder.DefineDynamicModule("InterfaceImplementations");
var typename = "<jswrapper>" + typeof(T).FullName;
var type = (TypeBuilder)module.GetType(typename);
if (type == null)
{
type = module.DefineType(typename, TypeAttributes.Class | TypeAttributes.Public | TypeAttributes.Sealed, typeof(object), new[] { typeof(T) });
var methods = typeof(T).GetMethods();

var jsobjectField = type.DefineField("_jsvalue", typeof(JSValue), FieldAttributes.Private);
var ctor = type.DefineConstructor(MethodAttributes.Public, CallingConventions.Standard, new[] { typeof(JSValue) });
{
var ilgen = ctor.GetILGenerator();
ilgen.Emit(OpCodes.Ldarg_0);
ilgen.Emit(OpCodes.Ldarg_1);
ilgen.Emit(OpCodes.Stfld, jsobjectField);
}

var thisParameter = Expression.Parameter(type, "self");

var getPropertyMethod = typeof(JSValue).GetMethod(nameof(JSValue.GetProperty), BindingFlags.NonPublic | BindingFlags.Instance, null, new[] { typeof(JSValue), typeof(bool), typeof(PropertyScope) }, null);

for (var i = 0; i < methods.Length; i++)
{
var method = type.DefineMethod(
methods[i].Name,
MethodAttributes.Public,
methods[i].ReturnParameter.ParameterType,
methods[i].GetParameters().Select(x => x.ParameterType).ToArray());

//var tree = Tools.BuildJsCallTree(method.Name,
// Expression.Convert(Expression.Field(Expression.Call(Expression.Field(thisParameter, jsobjectField), getPropertyMethod,
// Expression.Constant((JSValue)method.Name), Expression.Constant(false), Expression.Constant(PropertyScope.Сommon)), "oValue"), typeof(Function)),
// thisParameter,
// methods[i],
// null);
//tree.CompileToMethod(method);
}
}

return default(T);
}
#endif
}
}
25 changes: 0 additions & 25 deletions NiL.JS/Extensions/ObjectExtensions.cs

This file was deleted.

1 change: 0 additions & 1 deletion NiL.JS/NiL.JS.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,6 @@
<Compile Include="Expressions\AssignmentOverReplace.cs" />
<Compile Include="Expressions\Yield.cs" />
<Compile Include="Extensions\JSValueExtensions.cs" />
<Compile Include="Extensions\ObjectExtensions.cs" />
<Compile Include="NamespaceProvider.cs" />
<Compile Include="Statements\LabeledStatement.cs" />
<Compile Include="Expressions\AssignmentOperatorCache.cs" />
Expand Down
4 changes: 2 additions & 2 deletions NiL.JS/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
[assembly: AssemblyCompany("NiLProject")]
[assembly: AssemblyCopyright("Copyright © NiLProject 2015")]
[assembly: AssemblyTrademark("NiL.JS")]
[assembly: AssemblyVersion("2.0.847")]
[assembly: AssemblyFileVersion("2.0.847")]
[assembly: AssemblyVersion("2.0.850")]
[assembly: AssemblyFileVersion("2.0.850")]
[assembly: NeutralResourcesLanguage("en-US")]
[assembly: ComVisible(false)]
[assembly: CLSCompliant(true)]
Expand Down
2 changes: 1 addition & 1 deletion NiL.JS/Statements/Throw.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public sealed class Throw : CodeNode

public Throw(Exception e)
{
body = new Constant(TypeProxy.Marshal(e));
body = new Constant(TypeProxy.Proxy(e));
}

internal Throw(Expression statement)
Expand Down
2 changes: 1 addition & 1 deletion NiL.JS/Statements/TryCatch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ private void catchHandler(Context context, Exception e)
}
else
#endif
cvar = e is JSException ? (e as JSException).Avatar.CloneImpl(false) : TypeProxy.Marshal(e);
cvar = e is JSException ? (e as JSException).Avatar.CloneImpl(false) : TypeProxy.Proxy(e);
cvar.attributes |= JSValueAttributesInternal.DoNotDelete;
var catchContext = new CatchContext(cvar, context, catchVariableDesc.name);
#if DEBUG
Expand Down
2 changes: 1 addition & 1 deletion Portable.Test.Phone.Windows/MainPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ private void test(string code)

Context.RefreshGlobalContext();
var s = new Module(staCode); // инициализация
s.Context.DefineVariable("console").Assign(logger.WrapToJSValue());
s.Context.DefineVariable("console").Assign(JSValue.Marshal(logger));
s.Invoke();
try
{
Expand Down
2 changes: 1 addition & 1 deletion Portable.Test.Phone/MainPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ private void test(string code)

Context.RefreshGlobalContext();
var s = new Module(staCode); // инициализация
s.Context.DefineVariable("console").Assign(logger.WrapToJSValue());
s.Context.DefineVariable("console").Assign(JSValue.Marshal(logger));
s.Invoke();
try
{
Expand Down

0 comments on commit dd3773f

Please sign in to comment.