Exemple #1
0
        public static object CreateInstance(Type type)
        {
            // X:\jsc.svn\examples\javascript\async\test\TestEditAndContinue\TestEditAndContinue\ApplicationWebService.cs

            if ((object)type == null)
            {
                throw new NotSupportedException();
            }

            // X:\jsc.svn\examples\javascript\forms\test\TestTypeActivatorRef\TestTypeActivatorRef\Class1.cs
            // https://sites.google.com/a/jsc-solutions.net/backlog/knowledge-base/2014/201404/20140409
            // X:\jsc.svn\examples\javascript\test\TestTypeActivator\TestTypeActivator\Application.cs
            // No parameterless constructor defined for this object.

            // is jsc actually marking a consctructor ref for us?


            var ctor = (IFunction)Expando.InternalGetMember(
                ((__Type)type).AsExpando().constructor, "ctor");

            //var prototype = global::ScriptCoreLib.JavaScript.Runtime.Expando.Of(e.TypeHandle.Value);

            //var ctor = global::ScriptCoreLib.JavaScript.Runtime.Expando.Of(prototype.constructor).GetMember<IFunction>("ctor");

            //if (ctor == null)
            //    throw new NotSupportedException(e.Name);

            return(ctor.CreateType());
        }
Exemple #2
0
        static INode as_INode(this object e)
        {
            if (e != null)
            {
                // every browser names the Node type differently?

                // what about comments?
                if (Expando.InternalIsMember(e, "nodeType"))
                {
                    var nodeType = (int)Expando.InternalGetMember(e, "nodeType");

                    if (nodeType != 0)
                    {
                        return((INode)e);
                    }
                }

                // not yet?
                // see also: X:\jsc.svn\core\ScriptCoreLib\JavaScript\WebGL\WebGLRenderingContext.cs
                //if (Expando.InternalIsMember(e, "canvas"))
                //{
                //    return as_INode(Expando.InternalGetMember(e, "canvas"));
                //}
            }



            return(null);
        }
        public static Task <IFunction> ByName(string name, object target = null)
        {
            // X:\jsc.svn\examples\javascript\test\TestChromeStackFrames\TestChromeStackFrames\Application.cs

            // X:\jsc.svn\examples\javascript\Test\TestHistoryForwardEvent\TestHistoryForwardEvent\Application.cs
            Console.WriteLine("enter IFunction.ByName " + new { name });

            // X:\jsc.svn\core\ScriptCoreLib.Async\ScriptCoreLib.Async\JavaScript\DOM\HistoryExtensions.cs

            // tested by
            // X:\jsc.svn\examples\javascript\WorkerInsideSecondaryApplication\WorkerInsideSecondaryApplicationWithStateReplaceTwice\Application.cs

            if (target == null)
            {
                target = Native.self;
            }

            var x = new TaskCompletionSource <IFunction>();

            Action y = delegate
            {
                if (Expando.InternalIsMember(target, name))
                {
                    // should wo typecheck that member?
                    var f = (IFunction)Expando.InternalGetMember(target, name);

                    x.SetResult(f);
                    return;
                }

                // ?
            };

            y();

            if (!x.Task.IsCompleted)
            {
                new Timer(
                    t =>
                {
                    y();

                    if (x.Task.IsCompleted)
                    {
                        t.Stop();
                    }
                }
                    ).StartInterval(15);
            }

            return(x.Task);
        }
 public TItem this[int i]
 {
     [Script(DefineAsStatic = true)]
     get
     {
         return((TItem)Expando.InternalGetMember(this, i));
     }
     [Script(DefineAsStatic = true)]
     set
     {
         Expando.InternalSetMember(this, i, value);
     }
 }
Exemple #5
0
        // X:\jsc.svn\core\ScriptCoreLib\JavaScript\BCLImplementation\System\Runtime\Serialization\FormatterServices.cs

        // use by?
        public static object CreateInstance(Type type, params object[] args)
        {
            if ((object)type == null)
            {
                throw new NotSupportedException();
            }


            //  var ctor$dRwABhEmij_awUY_aNs2ypYA = pcI2XBEmij_awUY_aNs2ypYA.ctor = $ctor$(null, 'dRwABhEmij_awUY_aNs2ypYA', type$pcI2XBEmij_awUY_aNs2ypYA);
            //  var ctor$rwAABqwhHjSCn60Jy_bMQpA = $ctor$(null, 'rwAABqwhHjSCn60Jy_bMQpA', type$fAZ65awhHjSCn60Jy_bMQpA);

            // X:\jsc.svn\examples\javascript\test\TestActivatorWithArgs\TestActivatorWithArgs\Application.cs

            // can we get the default ctor with args?
            var ctor = (IFunction)Expando.InternalGetMember(
                ((__Type)type).AsExpando().constructor, "ctor");

            // 0:31ms { type = <Namespace>.Foo, ctor = function (b)


            //Console.WriteLine(new { type, ctor });
            //[Script(OptimizedCode = @"return new f();")]

            // how to apply ctor args correctly?

            if (args.Length == 0)
            {
                return(new IFunction("f",
                                     "return new f();").apply(null, ctor));
            }

            if (args.Length == 1)
            {
                return(new IFunction("f", "a",
                                     "return new f(a);").apply(null, ctor, args[0]));
            }

            if (args.Length == 2)
            {
                return(new IFunction("f", "a", "b",
                                     "return new f(a, b);").apply(null, ctor, args[0], args[1]));
            }

            // manually add more or make it more elegant?
            throw new NotImplementedException();
            //return ctor.CreateType();
        }
Exemple #6
0
        public static string GetScriptApplicationSourceForInlineWorker()
        {
            // ncaught TypeError: Cannot use 'in' operator to search for 'InternalScriptApplicationSource' in null

            var value = ScriptApplicationSourceForInlineWorker;

            //if (ScriptApplicationSourceForInlineWorker == null)
            {
                var x = Expando.Of(Native.self);

                // by default we should be running as view-source
                // what if we are being loaded from a blob?

                //value = Worker.ScriptApplicationSource;


                if (x.Contains("InternalScriptApplicationSource"))
                {
                    value = (string)Expando.InternalGetMember(Native.self, "InternalScriptApplicationSource");
                }

                // GetScriptApplicationSourceForInlineWorker { source = view-source }

                // { InternalScriptApplicationSource = blob:http%3A//192.168.43.252%3A21646/b74d8ef2-5b0a-4eee-8721-2f1ad91826ee }
                // GetScriptApplicationSourceForInlineWorker { source = blob:http%3A//192.168.43.252%3A21646/b74d8ef2-5b0a-4eee-8721-2f1ad91826ee }



                value += "#worker";
            }


            // https://sites.google.com/a/jsc-solutions.net/backlog/knowledge-base/2014/201411/20141112

            //Console.WriteLine("GetScriptApplicationSourceForInlineWorker "
            //    + new { value });

            return(value);
        }
Exemple #7
0
        // who is calling?
        // triggered by InternalInvoke
        static void __worker_onfirstmessage(
            MessageEvent e,

            int InternalThreadCounter,
            object data___string,

            bool[] MethodTargetObjectDataIsProgress,
            object[] MethodTargetObjectData,

            // https://sites.google.com/a/jsc-solutions.net/backlog/knowledge-base/2014/201411/20141112
            object[] MethodTargetObjectDataTypes,

            object MethodTargetTypeIndex,


            // set by ?
            string MethodToken,
            string MethodType,


            object state_ObjectData,
            object stateTypeHandleIndex,
            object state,

            bool IsIProgress,
            //bool IsTuple2_Item1_IsIProgress,

            __Task <object>[] TaskArray
            )
        {
            // https://sites.google.com/a/jsc-solutions.net/backlog/knowledge-base/2015/201501/20150111

            #region ConsoleFormWriter
            var w = new InternalInlineWorkerTextWriter();

            var o = Console.Out;

            Console.SetOut(w);

            w.AtWrite =
                AtWrite =>
            {
                // X:\jsc.svn\examples\javascript\Test\Test435CoreDynamic\Test435CoreDynamic\Class1.cs
                //dynamic zdata = new object();
                //zdata.AtWrite = x;

                // working with multiple threads, keep the id in the log!
                // () means we are setting the thread up... [] is the thread
                AtWrite = "[" + Thread.CurrentThread.ManagedThreadId + "] " + AtWrite;

                var zdata = new { AtWrite };



                foreach (MessagePort port in e.ports)
                {
                    port.postMessage((object)zdata, new MessagePort[0]);
                }
            };

            #endregion

            __Thread.InternalCurrentThread.ManagedThreadId = InternalThreadCounter;
            __Thread.InternalCurrentThread.IsBackground    = true;

            // X:\jsc.svn\examples\javascript\Test\Test435CoreDynamic\Test435CoreDynamic\Class1.cs
            dynamic self = Native.self;

            var stateType = default(Type);

            if (stateTypeHandleIndex != null)
            {
                stateType = Type.GetTypeFromHandle(new __RuntimeTypeHandle((IntPtr)self[stateTypeHandleIndex]));
            }

            // X:\jsc.svn\examples\javascript\async\AsyncNonStaticHandler\AsyncNonStaticHandler\Application.cs
            var MethodTargetType = default(Type);

            if (MethodTargetTypeIndex != null)
            {
                MethodTargetType = Type.GetTypeFromHandle(new __RuntimeTypeHandle((IntPtr)self[MethodTargetTypeIndex]));
            }
            // stateType = <Namespace>.xFoo,



            // MethodTargetTypeIndex = type$GV0nCx_bM8z6My5NDh7GXlQ,

            Console.WriteLine(
                "__worker_onfirstmessage: " +
                new
            {
                Thread.CurrentThread.ManagedThreadId,
                Native.worker.location.href,

                MethodTargetTypeIndex,
                MethodTargetType,

                MethodToken,
                MethodType,


                //IsTuple2_Item1_IsIProgress,


                // X:\jsc.svn\examples\javascript\test\TestTypeHandle\TestTypeHandle\Application.cs
                stateTypeHandleIndex,
                stateType,
                state,
                IsIProgress,

                //MethodTokenReference
            }
                );

            #region MethodTokenReference
            var MethodTokenReference = default(IFunction);
            var MethodTarget         = default(object);

            if (MethodTargetType == null)
            {
                MethodTokenReference = IFunction.Of(MethodToken);
            }
            else
            {
                MethodTarget = FormatterServices.GetUninitializedObject(MethodTargetType);

                var MethodTargetTypeSerializableMembers = FormatterServices.GetSerializableMembers(MethodTargetType);

                // X:\jsc.svn\examples\javascript\async\test\TestWorkerScopeProgress\TestWorkerScopeProgress\Application.cs

                for (int i = 0; i < MethodTargetTypeSerializableMembers.Length; i++)
                {
                    var xMember     = MethodTargetTypeSerializableMembers[i] as FieldInfo;
                    var xObjectData = MethodTargetObjectData[i];

                    var xMethodTargetObjectDataTypeIndex = MethodTargetObjectDataTypes[i];


                    var xIsProgress = MethodTargetObjectDataIsProgress[i];

                    // X:\jsc.svn\examples\javascript\chrome\apps\ChromeTCPServer\ChromeTCPServer\Application.cs
                    // does our chrome tcp server get the damn path?
                    Console.WriteLine(new { xMember, xMethodTargetObjectDataTypeIndex, xObjectData, xIsProgress });

                    // need to resurrect the semaphores!
                    // X:\jsc.svn\examples\javascript\async\Test\TestSemaphoreSlim\TestSemaphoreSlim\ApplicationControl.cs


                    #region MethodTargetObjectDataIsProgress
                    // cant we use xMethodTargetObjectDataType instead?
                    if (xIsProgress)
                    {
                        var ii = i;
                        MethodTargetObjectData[ii] = new __Progress <object>(
                            ProgressEvent =>
                        {
                            // X:\jsc.svn\examples\javascript\Test\Test435CoreDynamic\Test435CoreDynamic\Class1.cs
                            dynamic zdata = new object();

                            zdata.MethodTargetObjectDataProgressReport = new { ProgressEvent, ii };

                            foreach (MessagePort port in e.ports)
                            {
                                port.postMessage((object)zdata, new MessagePort[0]);
                            }

                            //Console.WriteLine(new { MethodTargetTypeSerializableMember, MethodTargetTypeSerializableMemberIsProgress, ProgressEvent });
                        }
                            );
                    }
                    #endregion

                    else
                    {
                        var xMethodTargetObjectDataType = default(Type);
                        if (xMethodTargetObjectDataTypeIndex != null)
                        {
                            xMethodTargetObjectDataType = Type.GetTypeFromHandle(new __RuntimeTypeHandle((IntPtr)self[xMethodTargetObjectDataTypeIndex]));
                        }

                        // now we know the type. should we review it?

                        if (xMethodTargetObjectDataType != null)
                        {
                            var scope2copy = FormatterServices.GetUninitializedObject(xMethodTargetObjectDataType);

                            //shall we copy the members too?
                            //FormatterServices.PopulateObjectMembers(scope2copy, scope2TypeSerializableMembers, scope2ObjectData);

                            MethodTargetObjectData[i] = scope2copy;

                            #region __SemaphoreSlim
                            // X:\jsc.svn\examples\javascript\async\Test\TestSemaphoreSlim\TestSemaphoreSlim\ApplicationControl.cs
                            var xSemaphoreSlim = scope2copy as __SemaphoreSlim;
                            if (xSemaphoreSlim != null)
                            {
                                // we now have to complete the entanglement. we have the caller on the UI.

                                Action <string> WriteLine0 = text =>
                                {
                                    Console.WriteLine("(" + xMember.Name + ") " + text);
                                };


                                //xSemaphoreSlim.InternalIsEntangled = true;



                                #region InternalVirtualWaitAsync
                                var xInternalVirtualWaitAsync = default(TaskCompletionSource <object>);

                                xSemaphoreSlim.InternalVirtualWaitAsync += continuation =>
                                {
                                    WriteLine0("enter xSemaphoreSlim.InternalVirtualWaitAsync, worker is now awaiting for signal");

                                    xInternalVirtualWaitAsync = continuation;
                                };

                                // at this point lets call the UI to set up a new signal channel..

                                //new MessageChannel();

                                var c = new MessageChannel();

                                c.port1.onmessage +=
                                    ce =>
                                {
                                    // ui has released?

                                    if (xInternalVirtualWaitAsync == null)
                                    {
                                        // what if the thread is not yet awaiting?
                                        WriteLine0("ui has sent a release signal, yet nobody awaiting");
                                        return;
                                    }

                                    WriteLine0("ui has sent a release signal, resync");

                                    // we should have byte fields now.
                                    // next strings as in thread hopping...

                                    dynamic data = ce.data;

                                    #region read xSemaphoreSlim_ByteArrayFields
                                    {
                                        __Task.xByteArrayField[] xSemaphoreSlim_ByteArrayFields = data.xSemaphoreSlim_ByteArrayFields;

                                        // X:\jsc.svn\examples\javascript\async\test\TestBytesToSemaphore\TestBytesToSemaphore\Application.cs
                                        if (xSemaphoreSlim_ByteArrayFields != null)
                                        {
                                            foreach (var item in xSemaphoreSlim_ByteArrayFields)
                                            {
                                                var xFieldInfo = (FieldInfo)MethodTargetTypeSerializableMembers[item.index];

                                                // can we set the value?
                                                WriteLine0("worker resync " + new
                                                {
                                                    item.index,
                                                    //item.Name,
                                                    xFieldInfo = xFieldInfo.Name,
                                                    item.value
                                                });

                                                xFieldInfo.SetValue(
                                                    MethodTarget,

                                                    // null?
                                                    item.value
                                                    );
                                            }
                                        }
                                    }
                                    #endregion

                                    xInternalVirtualWaitAsync.SetResult(null);
                                };

                                c.port1.start();
                                c.port2.start();

                                WriteLine0("will set up the signal channel");

                                foreach (var p in e.ports)
                                {
                                    p.postMessage(
                                        new { xSemaphoreSlim = xMember.Name },
                                        transfer: new[] { c.port2 }
                                        );
                                }
                                #endregion


                                #region InternalVirtualRelease
                                xSemaphoreSlim.InternalVirtualRelease += delegate
                                {
                                    WriteLine0("enter xSemaphoreSlim.InternalVirtualRelease, will send a signal to ui...");

                                    // worker needs sync data about now.
                                    // the ui would be happy to have the latest version of the data.
                                    // this is tricky. we would really need to know which data fields have changed by now
                                    // and what will happen if the data was also changed on the ui.
                                    // technically we are doing a merge conflict resolver...

                                    // this is somewhat the same situation, we alrady have
                                    // when entering a worker
                                    // when exiting a worker
                                    // when hoping to or from a worker.

                                    // what data fields do we have to upload yo ui?
                                    // how much IL analysis is available for us to know what to sync
                                    // we should not sync fields that wont be used on the ui

                                    // the thread hop looks at strings only right now, as they are immputable yet primitive
                                    // what about bytewarrays?
                                    // X:\jsc.svn\examples\javascript\async\test\TestBytesFromSemaphore\TestBytesFromSemaphore\Application.cs

                                    #region xSemaphoreSlim_ByteArrayFields
                                    var xSemaphoreSlim_ByteArrayFields = new List <__Task.xByteArrayField>();


                                    var MethodTargetTypeSerializableMembers_index = 0;
                                    foreach (FieldInfo item in MethodTargetTypeSerializableMembers)
                                    {
                                        // how would we know if the array is a byte array?

                                        // FieldType is not exactly available yet
                                        //Console.WriteLine("worker resync candidate " + new { item.Name, item.FieldType, item.FieldType.IsArray });

                                        var item_value = item.GetValue(MethodTarget);
                                        if (item_value != null)
                                        {
                                            var item_value_constructor = Expando.Of(item_value).constructor;
                                            var item_value_IsByteArray = Native.self_Uint8ClampedArray == item_value_constructor;

                                            if (item_value_IsByteArray)
                                            {
                                                var value = (byte[])item_value;

                                                xSemaphoreSlim_ByteArrayFields.Add(
                                                    new __Task.xByteArrayField
                                                {
                                                    index = MethodTargetTypeSerializableMembers_index,

                                                    // keep name for diagnostics
                                                    Name = item.Name,

                                                    value = value
                                                }
                                                    );

                                                WriteLine0("worker resync xByteArrayField candidate " + new { item.Name, value.Length });
                                            }
                                        }


                                        MethodTargetTypeSerializableMembers_index++;
                                    }
                                    #endregion


                                    foreach (var p in e.ports)
                                    {
                                        p.postMessage(
                                            new
                                        {
                                            xSemaphoreSlim = xMember.Name,
                                            xSemaphoreSlim_ByteArrayFields = xSemaphoreSlim_ByteArrayFields.ToArray()
                                        }
                                            );
                                    }
                                };
                                #endregion
                            }
                            #endregion
                        }
                    }
                }

                FormatterServices.PopulateObjectMembers(
                    MethodTarget,
                    MethodTargetTypeSerializableMembers,
                    MethodTargetObjectData
                    );



                // X:\jsc.svn\examples\javascript\Test\Test435CoreDynamic\Test435CoreDynamic\Class1.cs
                MethodTokenReference = (MethodTarget as dynamic)[MethodToken];
            }

            // what if we are being called from within a secondary app?

            //  stateTypeHandleIndex = type$XjKww8iSKT_aFTpY_bSs5vBQ,
            if (MethodTokenReference == null)
            {
                // tested at
                // X:\jsc.svn\examples\javascript\WorkerInsideSecondaryApplication\WorkerInsideSecondaryApplication\Application.cs


                // X:\jsc.svn\examples\javascript\Test\TestHopToThreadPoolAwaitable\TestHopToThreadPoolAwaitable\Application.cs
                // why?
                throw new InvalidOperationException(
                          new { MethodToken } +" function is not available at " + new { Native.worker.location.href }
                          );
            }
            #endregion

            //Console.WriteLine(
            //     new
            //     {
            //         MethodTokenReference,
            //         Thread.CurrentThread.ManagedThreadId
            //     }
            // );

            // whats the type?



            #region xstate
            var xstate = default(object);

            if (stateType != null)
            {
                xstate = FormatterServices.GetUninitializedObject(stateType);
                var xstate_SerializableMembers = FormatterServices.GetSerializableMembers(stateType);

                FormatterServices.PopulateObjectMembers(
                    xstate,
                    xstate_SerializableMembers,
                    (object[])state_ObjectData
                    );

                // MethodType = FuncOfObjectToObject
                //Console.WriteLine("as FuncOfObjectToObject");
            }
            #endregion

            #region CreateProgress
            Func <__Progress <object> > CreateProgress =
                () => new __Progress <object>(
                    value =>
            {
                //Console.WriteLine("__IProgress_Report " + new { value });

                // X:\jsc.svn\examples\javascript\Test\Test435CoreDynamic\Test435CoreDynamic\Class1.cs
                dynamic zdata = new object();

                zdata.__IProgress_Report = new { value };

                foreach (MessagePort port in e.ports)
                {
                    port.postMessage((object)zdata, new MessagePort[0]);
                }
            }
                    );

            // X:\jsc.svn\examples\javascript\async\Test\TestWorkerProgress\TestWorkerProgress\Application.cs
            if (IsIProgress)
            {
                xstate = CreateProgress();
            }


            #endregion



            #region __string
            // X:\jsc.svn\examples\javascript\Test\Test435CoreDynamic\Test435CoreDynamic\Class1.cs
            dynamic target = __string;
            var     m      = Expando.Of(data___string).GetMembers();
            // https://sites.google.com/a/jsc-solutions.net/backlog/knowledge-base/2013/201308/20130826-domainmemory
            foreach (ExpandoMember nn in m)
            {
                target[nn.Name] = nn.Value;

                var trigger         = "set_" + nn.Name;
                var trigger_default = IFunction.Of(trigger);

                (Native.self as dynamic)[trigger] = IFunction.OfDelegate(
                    new Action <string>(
                        Value =>
                {
                    if (nn.Value == Value)
                    {
                        return;
                    }

                    trigger_default.apply(null, Value);

                    #region sync one field only

                    {
                        dynamic zdata          = new object();
                        dynamic zdata___string = new object();

                        zdata.__string = zdata___string;


                        zdata___string[nn.Name] = Value;

                        // prevent sync via diff
                        nn.Value = Value;

                        foreach (MessagePort port in e.ports)
                        {
                            port.postMessage((object)zdata, new MessagePort[0]);
                        }
                    }


                    #endregion
                }
                        )
                    );
            }
            #endregion


            {
                // https://sites.google.com/a/jsc-solutions.net/backlog/knowledge-base/2013/201308/20130828-thread-run
                // for now we only support static calls


                // X:\jsc.svn\examples\javascript\Test\Test435CoreDynamic\Test435CoreDynamic\Class1.cs
                dynamic zdata = new object();


                if (MethodType == typeof(ActionOfDedicatedWorkerGlobalScope).Name)
                {
                    MethodTokenReference.apply(null, Native.worker);
                }
                else if (MethodType == typeof(FuncOfObjectToObject).Name)
                {
                    //Console.WriteLine("worker Task Run function call");


                    #region FuncOfObjectToObject
                    // X:\jsc.svn\examples\javascript\test\TestTaskStartToString\TestTaskStartToString\Application.cs
                    // X:\jsc.svn\examples\javascript\async\test\TestTaskRun\TestTaskRun\Application.cs
                    // X:\jsc.svn\examples\javascript\Test\TestGetUninitializedObject\TestGetUninitializedObject\Application.cs


                    var value = MethodTokenReference.apply(MethodTarget, xstate);

                    // X:\jsc.svn\examples\javascript\async\test\TaskAsyncTaskRun\TaskAsyncTaskRun\Application.cs

                    // whatif its an Action not a Func?
                    //enter HopToThreadPoolAwaitable yield HopToUIAwaitable
                    //worker Task Run function has returned {{ value_Task = null, value_TaskOfT = null }}
                    //__Task.InternalStart inner complete {{ yield = {{ value = null }} }}

                    var value_Task    = value as __Task;
                    var value_TaskOfT = value as __Task <object>;

                    // if we are in a hop. allow the return task to be overriden.
                    if (InternalOverrideTaskOfT != null)
                    {
                        value_TaskOfT = InternalOverrideTaskOfT;
                    }


                    // 0:25611ms Task Run function has returned { value_Task = [object Object], value_TaskOfT = [object Object] }
                    //Console.WriteLine("worker Task Run function has returned " + new { value_Task, value_TaskOfT, InternalOverrideTaskOfT });
                    // 0:4284ms Task Run function has returned { value_Task = { IsCompleted = 1, Result =  }, value_TaskOfT = { IsCompleted = 1, Result =  } }
                    // 0:5523ms Task Run function has returned { value_Task = { IsCompleted = false, Result =  }, value_TaskOfT = { IsCompleted = false, Result =  } }

                    if (value_TaskOfT != null)
                    {
                        // special situation

                        // if IsCompleted, called twice? or heard twice?
                        value_TaskOfT.ContinueWith(
                            t =>
                        {
                            //Console.WriteLine("worker Task Run ContinueWith " + new { t });


                            // X:\jsc.svn\examples\javascript\Test\Test435CoreDynamic\Test435CoreDynamic\Class1.cs
                            dynamic zzdata = new object();

                            // null?
                            if (t.Result == null)
                            {
                                zzdata.ContinueWithResult = new { t.Result };
                                foreach (MessagePort port in e.ports)
                                {
                                    port.postMessage((object)zzdata, new MessagePort[0]);
                                }
                                return;
                            }

                            var ResultType      = t.Result.GetType();
                            var ResultTypeIndex = __Type.GetTypeIndex("workerResult", ResultType);

                            var ResultTypeSerializableMembers = FormatterServices.GetSerializableMembers(ResultType);
                            var ResultObjectData = FormatterServices.GetObjectData(t.Result, ResultTypeSerializableMembers);

                            var ContinueWithResult = new
                            {
                                ResultTypeIndex,
                                ResultObjectData,

                                t.Result
                            };

                            zzdata.ContinueWithResult = ContinueWithResult;

                            foreach (MessagePort port in e.ports)
                            {
                                port.postMessage((object)zzdata, new MessagePort[0]);
                            }
                        }
                            );
                    }
                    else
                    {
                        if (value_Task != null)
                        {
                            // X:\jsc.svn\examples\javascript\async\test\TestWorkerScopeProgress\TestWorkerScopeProgress\Application.cs

                            throw new NotImplementedException();
                        }
                        else
                        {
                            var yield = new { value };

                            //Console.WriteLine(new { yield });

                            zdata.yield = yield;
                        }
                    }
                    #endregion
                    // now what?
                }
                else if (MethodType == typeof(FuncOfTaskToObject).Name)
                {
                    // tested by?
                    #region FuncOfTaskToObject
                    // need to reconstruct the caller task?


                    var value = MethodTokenReference.apply(null, TaskArray.Single());
                    var yield = new { value };

                    //Console.WriteLine(new { yield });

                    zdata.yield = yield;
                    #endregion
                    // now what?
                }
                else if (MethodType == typeof(FuncOfTaskOfObjectArrayToObject).Name)
                {
                    // tested by?

                    #region FuncOfTaskOfObjectArrayToObject
                    // need to reconstruct the caller task?

                    Console.WriteLine("__worker_onfirstmessage: " + new { TaskArray = TaskArray.Length });

                    //Debugger.Break();

                    var args = new object[] { TaskArray };

                    var value = MethodTokenReference.apply(
                        o: null,

                        // watch out
                        args: args
                        );

                    var yield = new { value };

                    //Console.WriteLine(new { yield });

                    zdata.yield = yield;
                    #endregion
                    // now what?
                }

                #region [sync] diff and upload changes to DOM context, the latest now
                {
                    dynamic zdata___string = new object();

                    zdata.__string = zdata___string;

                    foreach (ExpandoMember nn in m)
                    {
                        string Value = (string)Expando.InternalGetMember((object)target, nn.Name);
                        // this is preferred:
                        //string Value = target[nn.Name];

                        if (Value != nn.Value)
                        {
                            zdata___string[nn.Name] = Value;
                        }
                    }
                }
                #endregion

                //e.post
                foreach (MessagePort port in e.ports)
                {
                    port.postMessage((object)zdata, new MessagePort[0]);
                }
            }
        }
Exemple #8
0
        // X:\jsc.svn\examples\javascript\async\test\TestBytesFromSemaphore\TestBytesFromSemaphore\Application.cs

        public virtual bool IsAssignableFrom(Type TargetType)
        {
            // jsc rewriter could replace it with is operator for static cases?

            // X:\jsc.svn\examples\javascript\test\TestIsAssignableFrom\TestIsAssignableFrom\Application.cs
            // X:\jsc.svn\examples\javascript\test\TestSwitchToIFrame\TestSwitchToIFrame\Application.cs

            // IAsyncStateMachine vs c

            //o33aimgYBj_aJ1Gk6clAOrw.Interfaces =
            //  {
            //    f7G82WqfyzOLoZ_b8v0KVxw: 1
            //  };

            //// TestIsAssignableFrom.foo
            //function o33aimgYBj_aJ1Gk6clAOrw() { }
            //o33aimgYBj_aJ1Gk6clAOrw.TypeName = "foo";
            //  o33aimgYBj_aJ1Gk6clAOrw.Assembly = YQ3YcnWoDE6CyQ7lsi20IQ;

            var TargetTypeHandle = TargetType.TypeHandle;
            var prototype        = (object)TargetTypeHandle.Value;

            if (prototype == null)
            {
                //throw new Exception("IsAssignableFrom:482 prototype null " + new { TargetType });
                return(false);
            }

            var prototype_constructor = Expando.InternalGetMember(prototype, "constructor");

            if (prototype_constructor == null)
            {
                return(false);
            }


            //0:4257ms { Name = foo, prototype_constructor_TypeName =  }

            var prototype_constructor_Interfaces = Expando.InternalGetMember(prototype_constructor, "Interfaces");

            if (prototype_constructor_Interfaces == null)
            {
                return(false);
            }

            // now if we are an interface, then there will be a match

            var this_prototype = (object)this.TypeHandle.Value;

            if (this_prototype == null)
            {
                return(false);
            }
            //throw new Exception("IsAssignableFrom:501 this_prototype null " + new { TargetType });

            var this_prototype_constructor = Expando.InternalGetMember(this_prototype, "constructor");

            // we should not compare names, we should resolve and compare refs

            var any = Expando.InternalGetMemberNames(prototype_constructor_Interfaces).AsEnumerable().Any(
                item =>
            {
                dynamic self = Native.self;
                object value = self[item];

                if (value == this_prototype_constructor)
                {
                    //Console.WriteLine(new { item, f });
                    return(true);
                }
                return(false);
            }
                );


            return(any);
        }
Exemple #9
0
        // used by X:\jsc.svn\core\ScriptCoreLib\JavaScript\BCLImplementation\System\Threading\Tasks\Task\Task.ctor.cs
        public static object GetTypeIndex(string Name, Type TargetType)
        {
            // X:\jsc.svn\examples\javascript\async\test\TestSwitchToServiceContextAsync\TestSwitchToServiceContextAsync\ApplicationWebService.cs

            var AllMemberNames = Expando.Of(Native.self).GetMemberNames();

            var TargetTypeHandle = TargetType.TypeHandle;
            var prototype        = (object)TargetTypeHandle.Value;


            //function IzkeSBiD_aTGMsWPjgYVYEg() {}
            //IzkeSBiD_aTGMsWPjgYVYEg.TypeName = "IDataParameter";
            //IzkeSBiD_aTGMsWPjgYVYEg.Assembly = _7ryscGGN80KExNOXH5xlgw;
            //IzkeSBiD_aTGMsWPjgYVYEg.Interfaces =
            //{
            //  f7G82WqfyzOLoZ_b8v0KVxw: 1
            //};

            //var type$IzkeSBiD_aTGMsWPjgYVYEg = IzkeSBiD_aTGMsWPjgYVYEg.prototype;
            //type$IzkeSBiD_aTGMsWPjgYVYEg.constructor = IzkeSBiD_aTGMsWPjgYVYEg;


            var prototype_constructor = Expando.InternalGetMember(prototype, "constructor");

            if (prototype_constructor == null)
            {
                return(null);
            }


            //0:4257ms { Name = foo, prototype_constructor_TypeName =  }

            var prototype_constructor_TypeName = Expando.InternalGetMember(prototype_constructor, "TypeName");

            if (prototype_constructor_TypeName == null)
            {
                return(null);
            }

            //Console.WriteLine(new { Name, prototype_constructor_TypeName });

            var TargetTypeIndex = AllMemberNames.FirstOrDefault(
                item =>
            {
                // X:\jsc.svn\examples\javascript\Test\Test435CoreDynamic\Test435CoreDynamic\Class1.cs
                dynamic self = Native.self;
                object value = self[item];

                if (value == prototype)
                {
                    //Console.WriteLine(new { item, f });
                    return(true);
                }

                return(false);
            }
                );


            // what are we to return?
            return(TargetTypeIndex);
        }
        public void Add(__Binding binding)
        {
            Console.WriteLine("__ControlBindingsCollection.Add " + new
            {
                binding.PropertyName,
                binding.DataSource,
                binding.DataMember
            });

            if (binding.DataSource == null)
            {
                return;
            }


            // X:\jsc.svn\examples\javascript\forms\FormsDataBindingForEnabled\FormsDataBindingForEnabled\ApplicationControl.cs
            //4:158ms __ControlBindingsCollection.Add


            var asControl = (this.BindableComponent as Control);

            if (asControl == null)
            {
                return;
            }


            // X:\jsc.svn\examples\javascript\forms\Test\TestWebBrowserOneWayDataBinding\TestWebBrowserOneWayDataBinding\ApplicationControl.Designer.cs

            #region asBindingSource
            var asBindingSource = binding.DataSource as __BindingSource;
            if (asBindingSource != null)
            {
                //this.navigationOrdersNavigateBindingSourceBindingSource.DataSource = typeof(SharedBrowserSessionExperiment.DataLayer.Data.NavigationOrdersNavigateBindingSource);
                //this.navigationOrdersNavigateBindingSourceBindingSource.Position = 0;

                // this.webBrowser1.DataBindings.Add(new System.Windows.Forms.Binding("Url", this.navigationOrdersNavigateBindingSourceBindingSource, "urlString", true, System.Windows.Forms.DataSourceUpdateMode.Never));


                Action AtDataSource = delegate
                {
                    // onetime here or shall be done by host BindingSource ?
                    var newBindingSource = asBindingSource.ActivatedDataSource as __BindingSource;
                    if (newBindingSource != null)
                    {
                        var asDataTable = newBindingSource.ActivatedDataSource as DataTable;

                        // 27:162ms { asWebBrowser = <Namespace>.WebBrowser, PropertyName = Url, DataMember = urlString, asDataTable = [object Object] }


                        //Console.WriteLine(
                        //      new
                        //      {
                        //          asWebBrowser,
                        //          binding.PropertyName,
                        //          binding.DataMember,
                        //          //asDataTable
                        //          asBindingSource.Position,
                        //      }
                        //  );

                        Console.WriteLine("await newBindingSource.InternalAfterEndInit");
                        // is this called?
                        newBindingSource.InternalInvokeAfterEndInit(
                            delegate
                        {
                            Console.WriteLine("await newBindingSource.InternalAfterEndInit done");


                            #region AtPosition
                            Action AtPosition = delegate
                            {
                                if (asBindingSource.Position < 0)
                                {
                                    return;
                                }

                                if (asBindingSource.Position >= asDataTable.Rows.Count)
                                {
                                    return;
                                }

                                var asRow = asDataTable.Rows[asBindingSource.Position];

                                // X:\jsc.svn\examples\javascript\forms\Test\TestWebBrowserOneWayDataBinding\TestWebBrowserOneWayDataBinding\ApplicationControl.cs
                                var value = asRow[binding.DataMember];

                                // 31:9446ms { asWebBrowser = <Namespace>.WebBrowser, PropertyName = Url, value = http://example.com/ }

                                //Console.WriteLine(
                                //    new
                                //    {
                                //        asWebBrowser,
                                //        binding.PropertyName,
                                //        value
                                //    }
                                //);

                                // X:\jsc.svn\examples\javascript\p2p\SharedBrowserSessionExperiment\SharedBrowserSessionExperiment\TheBrowserTab.cs

                                #region Text
                                if (binding.PropertyName == "Text")
                                {
                                    Console.WriteLine("data source to Text " + new
                                    {
                                        asBindingSource.Position,
                                        binding.DataMember,
                                        value
                                    });

                                    asControl.Text = (string)value;
                                    return;
                                }
                                #endregion


                                #region asWebBrowser
                                var asWebBrowser = this.BindableComponent as WebBrowser;
                                if (asWebBrowser != null)
                                {
                                    //X:\jsc.svn\examples\javascript\forms\HashForBindingSource\HashForBindingSource\ApplicationControl.cs


                                    if (binding.PropertyName == "DocumentText")
                                    {
                                        asWebBrowser.DocumentText = ((string)value);
                                    }

                                    if (binding.PropertyName == "Url")
                                    {
                                        asWebBrowser.Navigate((string)value);
                                    }

                                    return;
                                }
                                #endregion
                            };
                            #endregion


                            // now or later?
                            AtPosition();

                            asBindingSource.PositionChanged +=
                                delegate
                            {
                                AtPosition();
                            };

                            #region TextChanged
                            if (binding.PropertyName == "Text")
                            {
                                asControl.TextChanged +=
                                    delegate
                                {
                                    if (asBindingSource.Position < 0)
                                    {
                                        return;
                                    }

                                    if (asBindingSource.Position >= asDataTable.Rows.Count)
                                    {
                                        return;
                                    }

                                    var asRow = asDataTable.Rows[asBindingSource.Position];

                                    Console.WriteLine("Text to data source " + new
                                    {
                                        asBindingSource.Position,
                                        binding.DataMember,
                                        asControl.Text
                                    });

                                    // X:\jsc.svn\examples\javascript\forms\Test\TestWebBrowserOneWayDataBinding\TestWebBrowserOneWayDataBinding\ApplicationControl.cs
                                    asRow[binding.DataMember] = asControl.Text;
                                };
                            }
                            #endregion
                        }
                            );
                    }
                };

                // await
                if (asBindingSource.ActivatedDataSource == null)
                {
                    asBindingSource.DataSourceChanged += delegate { AtDataSource(); }
                }
                ;
                else
                {
                    AtDataSource();
                }
            }
            #endregion



            // 4:105ms __ControlBindingsCollection.Add { asControl = <Namespace>.Button, DataSource =  }
            //Console.WriteLine("__ControlBindingsCollection.Add " + new { asControl });

            //4:117ms __ControlBindingsCollection.Add { asControl = <Namespace>.Button } view-source:37151
            //Uncaught TypeError: Cannot read property 'constructor' of undefined

            #region asINotifyPropertyChanged
            var isINotifyPropertyChanged = binding.DataSource is INotifyPropertyChanged;
            //Console.WriteLine("__ControlBindingsCollection.Add " + new { isINotifyPropertyChanged });

            if (!isINotifyPropertyChanged)
            {
                return;
            }

            var f = "_" + binding.DataMember + "_k__BackingField";

            #region update
            Action update = delegate
            {
                // would this work with properties?
                // script: error JSC1000: No implementation found for this native method, please implement [static Microsoft.CSharp.RuntimeBinder.Binder.GetIndex(Microsoft.CSharp.RuntimeBinder.CSharpBinderFlags, System.Type, System.Collections.Generic.IEnumerable`1[[Microsoft.CSharp.RuntimeBinder.CSharpArgumentInfo, Microsoft.CSharp, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a]])]


                //var value = (binding.DataSource as dynamic)[binding.DataMember];

                //   type$aw89N0f_aSzmxyAettfDeww._BooleanValue_k__BackingField = false;


                var value = Expando.InternalGetMember(binding.DataSource, f);

                //Console.WriteLine(new { binding.PropertyName, value });

                // this is the only example for now.
                if (binding.PropertyName == "Enabled")
                {
                    asControl.Enabled = (bool)value;
                }

                if (binding.PropertyName == "Text")
                {
                    asControl.Text = (string)value;
                }
            };
            #endregion


            // d = ( function () { var c$189 = f.binding.WQEABuWzsDyCcW0H2L852Q(); return (( function () { var c$189 = c$189.constructor; return 'Interfaces' in c$189 ? ('idtkRlDX9zioWpwjiQ7IgA' in c$189.Interfaces) : false; } )() ? c$189 : null); } )();
            var asINotifyPropertyChanged = (INotifyPropertyChanged)binding.DataSource;
            //var asINotifyPropertyChanged = (__INotifyPropertyChanged)binding.DataSource;
            asINotifyPropertyChanged.PropertyChanged +=
                (sender, e) =>
            {
                //Console.WriteLine("__ControlBindingsCollection asINotifyPropertyChanged.PropertyChanged " + new { e.PropertyName, f });


                //if (e.PropertyName != binding.PropertyName)
                if (e.PropertyName != binding.DataMember)
                {
                    return;
                }

                update();
            };

            update();
            #endregion
        }