コード例 #1
0
ファイル: MethodGroup.cs プロジェクト: modulexcite/NiL.JS
        public override NiL.JS.Core.JSObject Invoke(NiL.JS.Core.JSObject thisBind, NiL.JS.Core.Arguments args)
        {
            int l = args == null ? 0 : args.length;
            object[] cargs = null;

            for (int pass = 0; pass < passCount; pass++)
            {
                for (var i = 0; i < methods.Length; i++)
                {
                    if (methods[i].Parameters.Length == 1 && methods[i].Parameters[0].ParameterType == typeof(Arguments))
                        return TypeProxy.Proxy(methods[i].InvokeImpl(thisBind, null, args));
                    if (pass == 1 || methods[i].Parameters.Length == l)
                    {
                        if (l != 0)
                        {
                            cargs = methods[i].ConvertArgs(args, pass == 1);
                            for (var j = cargs.Length; j-- > 0; )
                            {
                                var prmType = methods[i].Parameters[j].ParameterType;
                                if (!prmType.IsAssignableFrom(cargs[j].GetType()))
                                {
                                    cargs = null;
                                    break;
                                }
                            }
                            if (cargs == null)
                                continue;
                        }
                        return TypeProxy.Proxy(methods[i].InvokeImpl(thisBind, cargs, args));
                    }
                }
            }
            throw new JSException(new TypeError("Invalid arguments for function " + methods[0].name));
        }
コード例 #2
0
ファイル: EvalFunction.cs プロジェクト: modulexcite/NiL.JS
 public override NiL.JS.Core.JSObject Invoke(NiL.JS.Core.JSObject thisBind, Arguments args)
 {
     notExists.valueType = JSObjectType.NotExistsInObject;
     if (args == null)
         return notExists;
     var arg = args[0];
     if (arg.valueType != JSObjectType.String)
         return arg;
     if ((this.attributes & JSObjectAttributesInternal.Eval) != 0)
         return Context.CurrentContext.Eval(arg.ToString(), false);
     Stack<Context> stack = new Stack<Context>();
     try
     {
         var ccontext = Context.CurrentContext;
         var root = ccontext.Root;
         while (ccontext != root && ccontext != null)
         {
             stack.Push(ccontext);
             ccontext = ccontext.Deactivate();
         }
         if (ccontext == null)
         {
             root.Activate();
             try
             {
                 return root.Eval(args[0].ToString(), false);
             }
             finally
             {
                 root.Deactivate();
             }
         }
         else
             return ccontext.Eval(args[0].ToString(), false);
     }
     finally
     {
         while (stack.Count != 0) stack.Pop().Activate();
     }
 }
コード例 #3
0
ファイル: GlobalObject.cs プロジェクト: modulexcite/NiL.JS
 public override void Assign(NiL.JS.Core.JSObject value)
 {
     throw new JSException((new NiL.JS.BaseLibrary.ReferenceError("Invalid left-hand side")));
 }
コード例 #4
0
ファイル: MethodProxy.cs プロジェクト: modulexcite/NiL.JS
 private static object[] convertArray(NiL.JS.BaseLibrary.Array array)
 {
     var arg = new object[array.data.Count];
     for (var j = arg.Length; j-- > 0; )
     {
         var temp = (array.data[j] ?? undefined).Value;
         arg[j] = temp is NiL.JS.BaseLibrary.Array ? convertArray(temp as NiL.JS.BaseLibrary.Array) : temp;
     }
     return arg;
 }
コード例 #5
0
ファイル: TypeProxy.cs プロジェクト: modulexcite/NiL.JS
 public override void Assign(NiL.JS.Core.JSObject value)
 {
     if ((attributes & JSObjectAttributesInternal.ReadOnly) == 0)
         throw new JSException("Can not assign to __proto__ of immutable or special objects.");
 }
コード例 #6
0
ファイル: MethodProxy.cs プロジェクト: modulexcite/NiL.JS
 public override NiL.JS.Core.JSObject Invoke(NiL.JS.Core.JSObject thisBind, NiL.JS.Core.Arguments args)
 {
     return TypeProxing.TypeProxy.Proxy(InvokeImpl(thisBind, null, args));
 }
コード例 #7
0
ファイル: MethodProxy.cs プロジェクト: modulexcite/NiL.JS
        protected internal override NiL.JS.Core.JSObject InternalInvoke(NiL.JS.Core.JSObject self, NiL.JS.Expressions.Expression[] arguments, NiL.JS.Core.Context initiator)
        {
            if (parameters.Length == 0 || (forceInstance && parameters.Length == 1))
                return Invoke(self, null);
            if (raw)
            {
                Arguments _arguments = new Core.Arguments()
                {
                    caller = initiator.strict && initiator.caller != null && initiator.caller.creator.body.strict ? Function.propertiesDummySM : initiator.caller,
                    length = arguments.Length
                };

                for (int i = 0; i < arguments.Length; i++)
                    _arguments[i] = NiL.JS.Expressions.Call.prepareArg(initiator, arguments[i], false, arguments.Length > 1);
                initiator.objectSource = null;

                return Invoke(self, _arguments);
            }
            else
            {
                // copied from ConvertArgs
                object[] args = null;
                int targetCount = parameters.Length;
                args = new object[targetCount];
                for (int i = targetCount; i-- > 0; )
                {
                    var obj = arguments.Length > i ? NiL.JS.Expressions.Call.prepareArg(initiator, arguments[i], false, arguments.Length > 1) : notExists;
                    if (obj.IsExist)
                    {
                        args[i] = marshal(obj, parameters[i].ParameterType);
                        if (paramsConverters != null && paramsConverters[i] != null)
                            args[i] = paramsConverters[i].To(args[i]);
                    }
#if PORTABLE
                    if (args[i] == null && parameters[i].ParameterType.GetTypeInfo().IsValueType)
                        args[i] = Activator.CreateInstance(parameters[i].ParameterType);
#else
                    if (args[i] == null && parameters[i].ParameterType.IsValueType)
                        args[i] = Activator.CreateInstance(parameters[i].ParameterType);
#endif
                }
                return TypeProxing.TypeProxy.Proxy(InvokeImpl(self, args, null));
            }
        }
コード例 #8
0
ファイル: Arguments.cs プロジェクト: modulexcite/NiL.JS
        public override void Assign(NiL.JS.Core.JSObject value)
        {
            if ((attributes & JSObjectAttributesInternal.ReadOnly) != 0)
            {
#if DEBUG
                System.Diagnostics.Debugger.Break();
#endif
                throw new InvalidOperationException("Try to assign to Arguments");
            }
        }
コード例 #9
0
 public void SchemaChanged(NiL.JS.Core.JSValue schema) {
 }
コード例 #10
0
 public void ValueChanged(NiL.JS.Core.JSValue value) {
   this.cbBool.IsChecked= value.ValueType == JSC.JSValueType.Boolean && (bool)value;
 }