Ejemplo n.º 1
0
        private DInt8Array createArrayFromObject(mdr.DObject array, int byteoffset = 0, int bytelength = 0)
        {
            var buffer = array as DArrayBuffer;

            if (buffer != null)
            {
                bytelength = (bytelength > 0) ? bytelength : buffer.ByteLength - byteoffset;
                checkOffsetCompatibility(byteoffset, bytelength);
                return(new DInt8Array(TargetPrototype, buffer, byteoffset, bytelength, TypeSize));
            }

            var darray = array as DTypedArray;

            if (darray != null)
            {
                bytelength = (bytelength > 0) ? bytelength : darray.ByteLength / darray.TypeSize * TypeSize;
                checkOffsetCompatibility(byteoffset, bytelength);
                DInt8Array tarray = new DInt8Array(TargetPrototype, bytelength, TypeSize);
                fillArray(tarray, darray);
                return(tarray);
            }

            Trace.Fail("invalid Arguments");
            return(null);
        }
Ejemplo n.º 2
0
        private void ctor(ref mdr.CallFrame callFrame)
        {
            if (IsConstrutor)
            {
                mdr.DObject newobject = new mdr.DObject(TargetPrototype);
                if (callFrame.PassedArgsCount > 0)
                {
                    newobject.PrimitiveValue.Set(Operations.Convert.ToBoolean.Run(ref callFrame.Arg0));
                }
                else
                {
                    newobject.PrimitiveValue.Set(false);
                }

                //newobject.Class = "Boolean";
                callFrame.This = (newobject);
            }
            else
            {
                if (callFrame.PassedArgsCount > 0)
                {
                    callFrame.Return.Set(Operations.Convert.ToBoolean.Run(ref callFrame.Arg0));
                }
                else
                {
                    callFrame.Return.Set(false);
                }
            }
        }
Ejemplo n.º 3
0
        public JSError() : base(new mdr.DObject(), "Error")
        {
            JittedCode = (ref mdr.CallFrame callFrame) =>
            {
                var error = new mdr.DObject(TargetPrototype);
                switch(callFrame.PassedArgsCount)
                {
                    case 0:
                        break;
                    case 1:
                        error.SetField("message", callFrame.Arg0.AsString());
                        goto case 0;
                    case 2:
                        error.SetField("fileName", callFrame.Arg1.AsString());
                        goto case 1;
                    case 3:
                        error.SetField("lineNumber", callFrame.Arg2.AsString());
                        goto case 2;
                }
                if (IsConstrutor)
                    callFrame.This = (error);
                else
                    callFrame.Return.Set(error);
            };

            TargetPrototype.DefineOwnProperty("message", "", mdr.PropertyDescriptor.Attributes.NotEnumerable | mdr.PropertyDescriptor.Attributes.Data);
            TargetPrototype.DefineOwnProperty("name", "Error", mdr.PropertyDescriptor.Attributes.NotEnumerable | mdr.PropertyDescriptor.Attributes.Data);
            TargetPrototype.DefineOwnProperty("toString", new mdr.DFunction((ref mdr.CallFrame callFrame) => 
            {
                var name = callFrame.This.GetField("name").AsString();
                var message = callFrame.This.GetField("message").AsString();
                callFrame.Return.Set(string.Format("{0}: {1}", name, message));
            }), mdr.PropertyDescriptor.Attributes.NotEnumerable | mdr.PropertyDescriptor.Attributes.Data);

        }
Ejemplo n.º 4
0
        public static void DeclareVariable(mdr.DObject context, string field, int fieldId, ref Stack stack)
        {
            //we may be looking at a global or this might be second time we call this function with the same context, so following assert will fail (incorrectly)
            //Debug.Assert(!context.HasOwnPropertyByFieldId(fieldId), "Cannot redeclare local variable {0}", field);

            context.AddOwnPropertyDescriptorByFieldId(fieldId, mdr.PropertyDescriptor.Attributes.Data | mdr.PropertyDescriptor.Attributes.NotConfigurable);
        }
Ejemplo n.º 5
0
 internal static void InitDFunctionPrototype(mdr.DObject dFunctionProto,
                                             string protoFieldName,
                                             int prototypeFieldId)
 {
     dFunctionProto.DefineOwnProperty(
         protoFieldName
         , new DProperty()
     {
         TargetValueType = ValueTypes.Object,
         OnGetDValue     = (DObject This, ref DValue v) =>
         {
             //This is the first time This["prototype"] is accessed
             //So, we create the object, and add it to the object with a new PropertyDescriptor so that the current code is not executed again later
             var func      = This.ToDFunction();
             var prototype = func.Map.AddOwnProperty(func, protoFieldName, prototypeFieldId, PropertyDescriptor.Attributes.Data | PropertyDescriptor.Attributes.NotEnumerable);
             func.PrototypePropertyDescriptor = prototype;
             func.Fields[prototype.Index].Set(new DObject());
             v.Set(ref func.Fields[prototype.Index]);
         },
         OnSetDValue = (DObject This, ref DValue v) =>
         {
             //This is the first time This["prototype"] is accessed
             //So, we add a new PropertyDescriptor so that the current code is not executed again later
             var func      = This.ToDFunction();
             var prototype = func.Map.AddOwnProperty(func, protoFieldName, prototypeFieldId, PropertyDescriptor.Attributes.Data | PropertyDescriptor.Attributes.NotEnumerable);
             func.PrototypePropertyDescriptor = prototype;
             func.Fields[prototype.Index].Set(ref v);
         },
     }
         , PropertyDescriptor.Attributes.Accessor
         | PropertyDescriptor.Attributes.NotEnumerable
         );
 }
Ejemplo n.º 6
0
        internal static void Init(mdr.DObject obj)
        {
            obj.SetField("global", obj);
            //obj.SetField("null", mdr.Runtime.Instance.DefaultDNull);
            obj.DefineOwnProperty("undefined", mdr.Runtime.Instance.DefaultDUndefined, mdr.PropertyDescriptor.Attributes.Data | mdr.PropertyDescriptor.Attributes.NotWritable | mdr.PropertyDescriptor.Attributes.NotEnumerable | mdr.PropertyDescriptor.Attributes.NotConfigurable);
            obj.DefineOwnProperty("NaN", double.NaN, mdr.PropertyDescriptor.Attributes.Data | mdr.PropertyDescriptor.Attributes.NotWritable | mdr.PropertyDescriptor.Attributes.NotEnumerable | mdr.PropertyDescriptor.Attributes.NotConfigurable);
            obj.DefineOwnProperty("Infinity", double.PositiveInfinity, mdr.PropertyDescriptor.Attributes.Data | mdr.PropertyDescriptor.Attributes.NotWritable | mdr.PropertyDescriptor.Attributes.NotEnumerable | mdr.PropertyDescriptor.Attributes.NotConfigurable);

            obj.SetField("Object", new JSObject());
            obj.SetField("Function", new JSFunction());
            obj.SetField("Array", new JSArray());
            obj.SetField("ArrayBuffer", new JSArrayBuffer());
            obj.SetField("Int8Array", new JSInt8Array());
            obj.SetField("Uint8Array", new JSUint8Array());
            obj.SetField("Int16Array", new JSInt16Array());
            obj.SetField("Uint16Array", new JSUint16Array());
            obj.SetField("Int32Array", new JSInt32Array());
            obj.SetField("Uint32Array", new JSUint32Array());
            obj.SetField("Float32Array", new JSFloat32Array());
            obj.SetField("Float64Array", new JSFloat64Array());

            obj.SetField("Math", new JSMath());
            obj.SetField("String", new JSString());
            obj.SetField("Number", new JSNumber());
            obj.SetField("Date", new JSDate());
            obj.SetField("Boolean", new JSBoolean());
            obj.SetField("Error", new JSError());
            obj.SetField("RegExp", new JSRegExp());

            obj.SetField("eval", BuiltinEval);

            AddStandardMethods(obj);
            AddExtendedMethods(obj);
        }
Ejemplo n.º 7
0
        static EventListeners GetEventListeners(mdr.DObject obj, EventTypes eventType)
        {
            var targetElement  = obj.FirstInPrototypeChainAs <EventTarget>();
            var eventListeners = targetElement.GetEventListeners(eventType, true);

            return(eventListeners);
        }
Ejemplo n.º 8
0
        public mdr.DFunction PrepareScript(string script, mdr.DObject ctx = null)
        {
            var scriptMetadata = LoadScriptStringMetadata(script);
            var prgFunc        = new mdr.DFunction(scriptMetadata, null);

            return(prgFunc);
        }
Ejemplo n.º 9
0
            //public void Visit(mdr.DVar obj)
            //{
            //    MarkAndVisit(obj.Object);
            //    if (_result == null)
            //        return;

            //    var tmpVar = GetVar();
            //    _output.WriteLine(
            //        "var {0} = new mdr.DVar({1});",
            //        tmpVar,
            //        _result
            //    );
            //    _result = tmpVar;
            //}

            public void Visit(mdr.DObject obj)
            {
                if (obj == mdr.DObject.Undefined)
                {
                    _result = "mdr.DObject.Undefined";
                    return;
                }

                string tmpVar;

                if (obj == JSLangImp.GlobalObj)
                {
                    tmpVar = "JSLangImp.GlobalObj";
                }
                else
                {
                    tmpVar = GetVar();
                    _output.WriteLine(
                        "var {0} = new mdr.DObject();",
                        tmpVar
                        );
                }
                WriteDClass(tmpVar, obj);
                _result = tmpVar;
            }
Ejemplo n.º 10
0
            bool MarkAndVisit(mdr.DObject obj)
            {
                if (obj == null)
                {
                    return(false);
                }

                string res = null;

                _dumpedObjects.TryGetValue(obj, out res);
                if (res != null)
                {
                    if (res == "")
                    {
                        res = null;
                    }
                    _result = res;
                    return(false);
                }
                else
                {
                    _dumpedObjects.Add(obj, "");
                    obj.Accept(this);
                    if (_result != null)
                    {
                        _dumpedObjects[obj] = _result;
                    }
                    return(true);
                }
            }
Ejemplo n.º 11
0
        public JSTypedArrayBase(mdr.DObject prototype, string arrayname, int typesize)
            : base(prototype, arrayname)
        {
            TypeSize = typesize;

            TargetPrototype.DefineOwnProperty("length", new mdr.DProperty()
            {
                TargetValueType = mdr.ValueTypes.Int32,
                OnGetDValue     = (mdr.DObject This, ref mdr.DValue v) => {
                    v.Set((This as DTypedArray).ByteLength / TypeSize);
                },
                OnSetDValue = (mdr.DObject This, ref mdr.DValue v) => { /* do nothing */ },
                OnSetInt    = (mdr.DObject This, int v) => { /* do nothing */ },
            });

            TargetPrototype.DefineOwnProperty("byteLength", new mdr.DProperty()
            {
                TargetValueType = mdr.ValueTypes.Int32,
                OnGetDValue     = (mdr.DObject This, ref mdr.DValue v) => {
                    v.Set((This as DTypedArray).ByteLength);
                },
                OnSetDValue = (mdr.DObject This, ref mdr.DValue v) => { /* do nothing */ },
                OnSetInt    = (mdr.DObject This, int v) => { /* do nothing */ },
            });

            // Constants
            this.DefineOwnProperty("BYTES_PER_ELEMENT", TypeSize, mdr.PropertyDescriptor.Attributes.NotConfigurable | mdr.PropertyDescriptor.Attributes.NotWritable | mdr.PropertyDescriptor.Attributes.NotEnumerable | mdr.PropertyDescriptor.Attributes.Data);
            TargetPrototype.DefineOwnProperty("BYTES_PER_ELEMENT", TypeSize, mdr.PropertyDescriptor.Attributes.NotConfigurable | mdr.PropertyDescriptor.Attributes.NotWritable | mdr.PropertyDescriptor.Attributes.NotEnumerable | mdr.PropertyDescriptor.Attributes.Data);
        }
Ejemplo n.º 12
0
        public static bool Run(mdr.DObject i0, int i1)
        {
            if (i1 == mdr.Runtime.InvalidFieldId)
            {
                return(false); //It is Local symbol with no FieldId
            }
            var context = i0;

            while (context != mdr.Runtime.Instance.GlobalContext)
            {
                if (context.HasOwnPropertyByFieldId(i1))
                {
                    return(false); //We cannot delete function locals
                }
                else
                {
                    context = context.Prototype;
                }
            }
            //Now we try to delete from GlobalContext
            //return (context.DeletePropertyDescriptorByFieldId(i1) != mdr.PropertyMap.DeleteStatus.NotDeletable);

            Debug.Warning("Deleting global members is not supported!");
            return(false); // as if it was local of a function
        }
Ejemplo n.º 13
0
        public static void LoadVariable(mdr.DObject context, int fieldId, int ancestorDistance, ref Stack stack)
        {
            mdr.PropertyDescriptor pd = null;

            //TODO: If we do not create a prototype for GlobalContext, the following code would have been enough!
            //var pd = context.GetPropertyDescriptorByLineId(fieldId);
            //pd.Get(context, ref stack.Items[stack.Sp++]);

            if (ancestorDistance < 0)
            {//We are dealing with unknown symbol type
                while (context != mdr.Runtime.Instance.GlobalContext)
                {
                    pd = context.Map.GetPropertyDescriptorByFieldId(fieldId);
                    if (pd != null)
                    {
                        break;
                    }
                    context = context.Prototype;
                }
            }
            else
            {//we are dealing with known symbol type
                for (var i = 0; i < ancestorDistance && context != mdr.Runtime.Instance.GlobalContext; ++i)
                {
                    context = context.Prototype;
                }
            }
            if (pd == null)
            {
                pd = context.GetPropertyDescriptorByFieldId(fieldId);
            }
            pd.Get(context, ref stack.Items[stack.Sp++]);
        }
Ejemplo n.º 14
0
 public virtual void SetGlobalContext(mdr.DObject globalContext)
 {
     Debug.Assert(globalContext != null, "Global Context cannot be null");
     GlobalContext = globalContext;
     //if (globalContext == null)
     //    GlobalContext = new mdr.DObject();
     //GlobalContext = new mdr.DObject(GlobalDObject);
 }
Ejemplo n.º 15
0
 protected DTypedArray(mdr.DObject prototype, DArrayBuffer array, int byteoffset, int bytelength, int typesize)
     : base(prototype)
 {
     ByteOffset_ = byteoffset;
     TypeSize_   = typesize;
     ByteLength_ = bytelength;
     Elements_   = array.Elements_;
 }
Ejemplo n.º 16
0
        public static string GetEventHandlerAttr(mdr.DObject obj, string name)
        {
            var ehp = obj.GetPropertyDescriptor(name).GetProperty() as EventHandlerProperty;

            if (ehp == null)
            {
                throw new Exception("Invalid Event " + name);
            }
            return(GetEventHandlerAttr(obj, ehp.EventType, name));
        }
Ejemplo n.º 17
0
 public static void CreateObject(ref mdr.CallFrame callFrame, int resultIndex, int fieldsCount)
 {
   //Here we assume we have (fieldId, value) pairs on the stack starting at resultIndex
   var values = callFrame.Values;
   var obj = new mdr.DObject();
   var lastSP = resultIndex + fieldsCount * 2;
   for (var sp = resultIndex; sp < lastSP; sp += 2)
     obj.SetFieldByFieldId(values[sp].AsInt32(), ref values[sp + 1]);
   values[resultIndex].Set(obj);
 }
Ejemplo n.º 18
0
 public DArrayBuffer(mdr.DObject prototype, int bytesize)
     : base(prototype)
 {
     ByteLength_ = Math.Min(bytesize, MaxElementsCount);
     Elements_   = new byte[ByteLength_];
     for (int i = 0; i < ByteLength_; ++i)
     {
         Elements_[i] = 0x00;
     }
 }
Ejemplo n.º 19
0
        static partial void CustomFillPrototype(mdr.DObject prototype)
        {
            var window = mwr.HTMLRuntime.Instance.GlobalContext;

            prototype.DefineOwnProperty("onblur", new mdr.DForwardingProperty(window, "onblur"));
            prototype.DefineOwnProperty("onerror", new mdr.DForwardingProperty(window, "onerror"));
            prototype.DefineOwnProperty("onfocus", new mdr.DForwardingProperty(window, "onfocus"));
            prototype.DefineOwnProperty("onload", new mdr.DForwardingProperty(window, "onload"));
            prototype.DefineOwnProperty("onscroll", new mdr.DForwardingProperty(window, "onscroll"));
        }
Ejemplo n.º 20
0
        public static void SetEventHandlerAttr(mdr.DObject obj, EventTypes type,
                                               string name, string script)
        {
            var targetElement = obj.FirstInPrototypeChainAs <HTMLElement>();

            targetElement.PrimSetEventHandlerAttr(type, script);
            var prgFunc = HTMLRuntime.Instance.PrepareScript(script);
            var pd      = obj.GetPropertyDescriptor(name);

            pd.Set(obj, prgFunc);
        }
Ejemplo n.º 21
0
 protected DTypedArray(mdr.DObject prototype, int bytelength, int typesize)
     : base(prototype)
 {
     ByteLength_ = Math.Min(bytelength, MaxElementsCount);
     TypeSize_   = typesize;
     Elements_   = new byte[ByteLength_];
     for (int i = 0; i < ByteLength_; ++i)
     {
         Elements_[i] = 0x00;
     }
 }
Ejemplo n.º 22
0
 static partial void CustomFillPrototype(mdr.DObject prototype)
 {
     Debug.WriteLine("++$> adding geolocation to Navigator props");
     prototype.DefineOwnProperty("geolocation", new mdr.DProperty()
     {
         TargetValueType = mdr.ValueTypes.String,
         OnGetDValue     = (mdr.DObject This, ref mdr.DValue v) =>
         {
             v.Set((This as Navigator).Geolocation);
         },
     }, mdr.PropertyDescriptor.Attributes.NotWritable);
 }
Ejemplo n.º 23
0
 public static mdr.DObject CheckUndefined(mdr.DObject obj)
 {
     // In case of calling "item" method on lists, a returned null should be converted to undefined.
     if (obj == null)
     {
         return(mdr.Runtime.Instance.DefaultDUndefined);
     }
     else
     {
         return(obj);
     }
 }
Ejemplo n.º 24
0
        public static void StoreVariable(mdr.DObject context, int fieldId, int ancestorDistance, bool pushBackResult, ref Stack stack)
        {
            var valueIndex = stack.Sp - 1;

            //TODO: If we do not create a prototype for GlobalContext, the following code would have been enough!
            //var pd = context.Map.GetPropertyDescriptorByFieldId(fieldId);
            //if (pd != null)
            //    pd.Set(context, ref stack.Items[stack.Sp - 1]);
            //else
            //    mdr.Runtime.Instance.GlobalContext.SetFieldByFieldId(fieldId, ref stack.Items[stack.Sp - 1]); //DOTO: this is very expensive!

            mdr.PropertyDescriptor pd = null;

            if (ancestorDistance < 0)
            {//We are dealing with unknown symbol type
             //while (context != mdr.Runtime.Instance.GlobalContext)
             //{
             //    pd = context.Map.GetCachedOwnPropertyDescriptorByFieldId(fieldId);
             //    if (pd != null)
             //        break;
             //    context = context.Prototype;
             //}
             //if (pd != null)
             //    pd.Set(context, ref stack.Items[stack.Sp - 1]);
             //else
             //    context.SetFieldByFieldId(fieldId, ref stack.Items[stack.Sp - 1]);

                pd = context.Map.GetPropertyDescriptorByFieldId(fieldId);
                if (pd != null && !pd.IsUndefined)
                {
                    pd.Set(context, ref stack.Items[valueIndex]);
                }
                else
                {
                    mdr.Runtime.Instance.GlobalContext.SetFieldByFieldId(fieldId, ref stack.Items[valueIndex]);
                }
            }
            else
            {//we are dealing with known symbol type
                for (var i = 0; i < ancestorDistance && context != mdr.Runtime.Instance.GlobalContext; ++i)
                {
                    context = context.Prototype;
                }
                pd = context.Map.GetPropertyDescriptorByFieldId(fieldId);
                Debug.Assert(pd != null && pd.IsDataDescriptor, "Invalid situation, variable is undeclared in current context");
                pd.Set(context, ref stack.Items[valueIndex]);
            }

            if (!pushBackResult)
            {
                stack.Sp = valueIndex;
            }
        }
Ejemplo n.º 25
0
        public void SetTopGlobalContext(mdr.DObject topWindow)
        {
#if ENABLE_RR
            if (RecordReplayManager.Instance.RecordEnabled)
            {
                RecordReplayManager.Instance.Record("HTMLRuntime", null, "SetTopGlobalContext", false, topWindow);
            }
#endif
            Debug.WriteLine("Setting global context");
            TopGlobalContext = topWindow;
            GlobalContext    = topWindow;   // Just to be sure GlobalContext also has current value
            // RunScriptString("if(undefined);","xyzyyz"); // This might JIT most of the compiler code early
        }
Ejemplo n.º 26
0
        public static void CreateObject(ref mdr.CallFrame callFrame, int resultIndex, int fieldsCount)
        {
            //Here we assume we have (fieldId, value) pairs on the stack starting at resultIndex
            var values = callFrame.Values;
            var obj    = new mdr.DObject();
            var lastSP = resultIndex + fieldsCount * 2;

            for (var sp = resultIndex; sp < lastSP; sp += 2)
            {
                obj.SetFieldByFieldId(values[sp].AsInt32(), ref values[sp + 1]);
            }
            values[resultIndex].Set(obj);
        }
Ejemplo n.º 27
0
        // all event handler attribute accessors should eventually call these
        public static string GetEventHandlerAttr(mdr.DObject obj, EventTypes type, string name)
        {
#if ENABLE_RR
            if (RecordReplayManager.Instance != null && RecordReplayManager.Instance.RecordEnabled)
            {
                mwr.RecordReplayManager.Instance.Record("Element", null, "GetEventHandlerAttr", false, obj, type, name);
            }
#endif
            var targetElement = obj.FirstInPrototypeChainAs <HTMLElement>();
            var s             = targetElement.PrimGetEventHandlerAttr(type);
            Debug.WriteLine("GetEventHandlerAttr({0}) = '{1}'", name, s);
            return(s);
        }
Ejemplo n.º 28
0
        public override void SetGlobalContext(mdr.DObject globalContext)
        {
            var timer = StartTimer(Configuration.ProfileInitTime, "JS/GlobalInit");

            try
            {
                base.SetGlobalContext(globalContext); //This will set the GlobalContext
                if (JSRuntime.Instance.Configuration.EnableRecursiveInterpreter && false)
                {
                    var result = new mdr.DValue();
                    Builtins.JSGlobalObject.EvalString(@"
Object.defineProperty(Array.prototype, 'pop', 
{
  enumerable: false,
  value: function() 
  {
    var n = (this.length);
    if (n == 0) {
      this.length = n;
      return;
    }
    n--;
    var value = this[n];
    delete this[n];
    this.length = n;
    return value;
  }
});

Object.defineProperty(Array.prototype, 'push', 
{
  enumerable: false,
  value: function() 
  {
    var n = this.length;
    var m = arguments.length;
    for (var i = 0; i < m; i++) {
      this[i+n] = arguments[i];
    }
    this.length = n + m;
    return this.length;
  }
});
", ref result);
                }
            }
            finally
            {
                StopTimer(timer);
            }
        }
Ejemplo n.º 29
0
        public static void SetEventHandlerAttr(mdr.DObject obj, string name, string script)
        {
#if ENABLE_RR
            if (RecordReplayManager.Instance != null && RecordReplayManager.Instance.RecordEnabled)
            {
                RecordReplayManager.Instance.Record("Element", null, "SetEventHandlerAttr", false, obj, name, script);
            }
#endif
            var ehp = obj.GetPropertyDescriptor(name).GetProperty() as EventHandlerProperty;
            if (ehp == null)
            {
                throw new Exception("Invalid Event " + name);
            }
            SetEventHandlerAttr(obj, ehp.EventType, name, script);
        }
Ejemplo n.º 30
0
 public static mdr.DObject CreateContext(ref mdr.CallFrame callFrame, ref Stack stack)
 {
   mdr.DObject context;
   var contextMap = callFrame.Function.Metadata.ContextMap;
   if (contextMap != null)
   {
     context = new mdr.DObject(contextMap);
   }
   else
   {
     var outerContext = callFrame.Function.OuterContext;
     context = new mdr.DObject(outerContext);
     callFrame.Function.Metadata.ContextMap = context.Map; //This will at least prevent the lookup in the DObject
   }
   return context;
 }
Ejemplo n.º 31
0
        public static mdr.DObject CreateContext(ref mdr.CallFrame callFrame, ref Stack stack)
        {
            mdr.DObject context;
            var         contextMap = callFrame.Function.Metadata.ContextMap;

            if (contextMap != null)
            {
                context = new mdr.DObject(contextMap);
            }
            else
            {
                var outerContext = callFrame.Function.OuterContext;
                context = new mdr.DObject(outerContext);
                callFrame.Function.Metadata.ContextMap = context.Map; //This will at least prevent the lookup in the DObject
            }
            return(context);
        }
Ejemplo n.º 32
0
 protected JSBuiltinConstructor(mdr.DObject prototype, string Class)
     : base(null, null)
 {
     TargetPrototype = prototype;
     TargetDType = mdr.Runtime.Instance.GetRootMapOfPrototype(TargetPrototype);
     TargetDType.Metadata.Name = Class;
     //var protoPD = PrototypePropertyDescriptor;
     //protoPD.SetAttributes(mdr.PropertyDescriptor.Attributes.NotConfigurable | mdr.PropertyDescriptor.Attributes.NotWritable | mdr.PropertyDescriptor.Attributes.NotEnumerable, true);
     //protoPD.Set(this, prototype);
     SetField("prototype", prototype);
     prototype.DefineOwnProperty(
         "constructor"
         , this
         , mdr.PropertyDescriptor.Attributes.Data | mdr.PropertyDescriptor.Attributes.NotEnumerable
     );
     //prototype.SetField("constructor", this);
 }
Ejemplo n.º 33
0
 protected JSBuiltinConstructor(mdr.DObject prototype, string Class)
     : base(null, null)
 {
     TargetPrototype           = prototype;
     TargetDType               = mdr.Runtime.Instance.GetRootMapOfPrototype(TargetPrototype);
     TargetDType.Metadata.Name = Class;
     //var protoPD = PrototypePropertyDescriptor;
     //protoPD.SetAttributes(mdr.PropertyDescriptor.Attributes.NotConfigurable | mdr.PropertyDescriptor.Attributes.NotWritable | mdr.PropertyDescriptor.Attributes.NotEnumerable, true);
     //protoPD.Set(this, prototype);
     SetField("prototype", prototype);
     prototype.DefineOwnProperty(
         "constructor"
         , this
         , mdr.PropertyDescriptor.Attributes.Data | mdr.PropertyDescriptor.Attributes.NotEnumerable
         );
     //prototype.SetField("constructor", this);
 }
Ejemplo n.º 34
0
        public static void CreateJson(int itemsCount, ref Stack stack)
        {
            //Debug.WriteLine("calling Exec.CreateJson");
            var obj         = new mdr.DObject();
            var resultIndex = stack.Sp - itemsCount * 2;

            //TODO: here we know things are string, so just push their fieldIds and user then here!
            if (itemsCount > 0)
            {
                var sp = resultIndex;
                for (var i = itemsCount - 1; i >= 0; --i, sp += 2)
                {
                    obj.SetField(ref stack.Items[sp], ref stack.Items[sp + 1]);
                }
            }
            stack.Items[resultIndex].Set(obj);
            stack.Sp = resultIndex + 1;;
        }
Ejemplo n.º 35
0
		static SampleDOMNode()
		{
		    //Here we build the prototype of DOM Object Wrapper. This prototype must have all
		    //the methods of the DOM object callable by JS.
		    prototype = new mdr.DObject();
		    prototype.SetField("GetElementByName", new mdr.DFunction((ref mdr.CallFrame callFrame) =>
		    {
		        var o = callFrame.This as WrappedObject;
		        var domptr = o.Domptr;

				//GCHandle gchWrapperIndex = GCHandle.Alloc(new int(), GCHandleType.Pinned);
		        var elemName = callFrame.Arg0.ToString();

				WrappedObject elemPtr = GetElementByName(domptr,                 /*gchWrapperIndex.AddrOfPinnedObject(),*/elemName) as WrappedObject;

				//int wrapperindex = (int)gchWrapperIndex.Target;
		        //gchWrapperIndex.Free();

				callFrame.Return.Set(elemPtr);
		    }));

            prototype.SetField("GetName", new mdr.DFunction((ref mdr.CallFrame callFrame) =>
		    {
		        var o = callFrame.This as WrappedObject;
		        var arg0 = o.Domptr;
		        callFrame.Return.Set(GetName(arg0));
		    }));

            prototype.SetField("Num", new mdr.DProperty()
            {
                TargetValueType = mdr.ValueTypes.Int32,
                OnGetInt = (This) =>
                {
                    Console.WriteLine("running getNum in C#");
                    Console.Out.Flush();
                    return GetNum(((WrappedObject) This).Domptr);
                },
                OnSetInt = (This, n) => SetNum(((WrappedObject) This).Domptr, n),
                OnGetDValue = (mdr.DObject This, ref mdr.DValue v) => { v.Set(GetNum(((WrappedObject) This).Domptr)); },
            });

		}
Ejemplo n.º 36
0
    void LoadRuntime(ProgramConfiguration config)
    {
      _runtime = new mjr.JSRuntime(config);

      var globalContext = new mdr.DObject();
      _runtime.InitGlobalContext(globalContext);
      _runtime.SetGlobalContext(globalContext);

      _scripts = new LinkedList<KeyValuePair<string, string>>();

      foreach (var s in config.ScriptFileNames)
        _scripts.AddLast(new KeyValuePair<string, string>(s, _runtime.ReadAllScript(s)));

      foreach (var s in config.ScriptStrings)
      {
        var MD5 = new MD5CryptoServiceProvider();
        var key = BitConverter.ToString(MD5.ComputeHash(Encoding.UTF8.GetBytes(s)));
        _scripts.AddLast(new KeyValuePair<string, string>(key, s));
      }
    }
Ejemplo n.º 37
0
    private void ctor(ref mdr.CallFrame callFrame)
    {
      if (IsConstrutor)
      {
        mdr.DObject newobject = new mdr.DObject(TargetPrototype);
        if (callFrame.PassedArgsCount > 0)
          newobject.PrimitiveValue.Set(Operations.Convert.ToBoolean.Run(ref callFrame.Arg0));
        else
          newobject.PrimitiveValue.Set(false);

        //newobject.Class = "Boolean";
        callFrame.This = (newobject);
      }
      else
      {
        if (callFrame.PassedArgsCount > 0)
          callFrame.Return.Set(Operations.Convert.ToBoolean.Run(ref callFrame.Arg0));
        else
          callFrame.Return.Set(false);
      }
    }
Ejemplo n.º 38
0
        public mdr.PropertyMap GetPropertyMapOfWrappedObjectType(Type wrappedObjectType)
        {
            mdr.PropertyMap pmap = null;
            if (!_propertyMaps.TryGetValue(wrappedObjectType, out pmap))
            {
                if (wrappedObjectType == typeof(DOM.WrappedObject))
                    return mdr.Runtime.Instance.DObjectMap;

                var baseMap = GetPropertyMapOfWrappedObjectType(wrappedObjectType.BaseType);
                var prototype = new mdr.DObject(baseMap);

                Debug.WriteLine("Creating PropertyMap for {0}", wrappedObjectType.FullName);

                var preparePrototypeMethod = wrappedObjectType.GetMethod("PreparePrototype");
                Debug.Assert(preparePrototypeMethod != null, "Cannot find method {0}.PreparePrototype()", wrappedObjectType.FullName);

                preparePrototypeMethod.Invoke(null, new object[] { prototype });
                pmap = GetRootMapOfPrototype(prototype);
                _propertyMaps[wrappedObjectType] = pmap;
            }
            return pmap;
        }
Ejemplo n.º 39
0
 public static void CreateJson(int itemsCount, ref Stack stack)
 {
   //Debug.WriteLine("calling Exec.CreateJson");
   var obj = new mdr.DObject();
   var resultIndex = stack.Sp - itemsCount * 2;
   //TODO: here we know things are string, so just push their fieldIds and user then here!
   if (itemsCount > 0)
   {
     var sp = resultIndex;
     for (var i = itemsCount - 1; i >= 0; --i, sp += 2)
       obj.SetField(ref stack.Items[sp], ref stack.Items[sp + 1]);
   }
   stack.Items[resultIndex].Set(obj);
   stack.Sp = resultIndex + 1; ;
 }
Ejemplo n.º 40
0
        public static mdr.DObject GetPrototype(EventClasses eventClass)
        {
            mdr.DObject prototype = null;
            switch (eventClass)
            {
                case EventClasses.Event:
                    {
                        prototype = new mdr.DObject();
                        prototype.DefineOwnProperty("type", new mdr.DProperty()
                        {
                            OnGetDValue = (mdr.DObject This, ref mdr.DValue v) =>
                            {
                                var ev = This.FirstInPrototypeChainAs<JSEvent>();
                                v.Set(ev.Data.Type.ToString().ToLower());
                            },
                        }, mdr.PropertyDescriptor.Attributes.NotWritable);
                        prototype.DefineOwnProperty("screenX", new mdr.DProperty()
                        {
                            OnGetDValue = (mdr.DObject This, ref mdr.DValue v) =>
                            {
                                var ev = This.FirstInPrototypeChainAs<JSEvent>();
                                v.Set((int)ev.Data.screenX);
                            },
                        }, mdr.PropertyDescriptor.Attributes.NotWritable);
                        prototype.DefineOwnProperty("screenY", new mdr.DProperty()
                        {
                            OnGetDValue = (mdr.DObject This, ref mdr.DValue v) =>
                            {
                                var ev = This.FirstInPrototypeChainAs<JSEvent>();
                                v.Set((int)ev.Data.screenY);
                            },
                        }, mdr.PropertyDescriptor.Attributes.NotWritable);
                        prototype.DefineOwnProperty("clientX", new mdr.DProperty()
                        {
                            OnGetDValue = (mdr.DObject This, ref mdr.DValue v) =>
                            {
                                var ev = This.FirstInPrototypeChainAs<JSEvent>();
                                v.Set((int)ev.Data.clientX);
                            },
                        }, mdr.PropertyDescriptor.Attributes.NotWritable);
                        prototype.DefineOwnProperty("clientY", new mdr.DProperty()
                        {
                            OnGetDValue = (mdr.DObject This, ref mdr.DValue v) =>
                            {
                                var ev = This.FirstInPrototypeChainAs<JSEvent>();
                                v.Set((int)ev.Data.clientY);
                            },
                        }, mdr.PropertyDescriptor.Attributes.NotWritable);
                        prototype.DefineOwnProperty("pageX", new mdr.DProperty()
                        {
                            OnGetDValue = (mdr.DObject This, ref mdr.DValue v) =>
                            {
                                var ev = This.FirstInPrototypeChainAs<JSEvent>();
                                v.Set((int)ev.Data.pageX);
                            },
                        }, mdr.PropertyDescriptor.Attributes.NotWritable);
                        prototype.DefineOwnProperty("pageY", new mdr.DProperty()
                        {
                            OnGetDValue = (mdr.DObject This, ref mdr.DValue v) =>
                            {
                                var ev = This.FirstInPrototypeChainAs<JSEvent>();
                                v.Set((int)ev.Data.pageY);
                            },
                        }, mdr.PropertyDescriptor.Attributes.NotWritable);
                        prototype.DefineOwnProperty("buttons", new mdr.DProperty()
                        {
                            OnGetDValue = (mdr.DObject This, ref mdr.DValue v) =>
                            {
                                var ev = This.FirstInPrototypeChainAs<JSEvent>();
                                v.Set((int)ev.Data.buttons);
                            },
                        }, mdr.PropertyDescriptor.Attributes.NotWritable);
                        prototype.DefineOwnProperty("button", new mdr.DProperty()
                        {
                            OnGetDValue = (mdr.DObject This, ref mdr.DValue v) =>
                            {
                                var ev = This.FirstInPrototypeChainAs<JSEvent>();
                                v.Set((int)ev.Data.button);
                            },
                        }, mdr.PropertyDescriptor.Attributes.NotWritable);
                        prototype.DefineOwnProperty("metaKey", new mdr.DProperty()
                        {
                            OnGetDValue = (mdr.DObject This, ref mdr.DValue v) =>
                            {
                                var ev = This.FirstInPrototypeChainAs<JSEvent>();
                                v.Set(ev.Data.metaKey);
                            },
                        }, mdr.PropertyDescriptor.Attributes.NotWritable);
                        prototype.DefineOwnProperty("ctrlKey", new mdr.DProperty()
                        {
                            OnGetDValue = (mdr.DObject This, ref mdr.DValue v) =>
                            {
                                var ev = This.FirstInPrototypeChainAs<JSEvent>();
                                v.Set(ev.Data.ctrlKey);
                            },
                        }, mdr.PropertyDescriptor.Attributes.NotWritable);
                        prototype.DefineOwnProperty("shiftKey", new mdr.DProperty()
                        {
                            OnGetDValue = (mdr.DObject This, ref mdr.DValue v) =>
                            {
                                var ev = This.FirstInPrototypeChainAs<JSEvent>();
                                v.Set(ev.Data.shiftKey);
                            },
                        }, mdr.PropertyDescriptor.Attributes.NotWritable);
                        prototype.DefineOwnProperty("altKey", new mdr.DProperty()
                        {
                            OnGetDValue = (mdr.DObject This, ref mdr.DValue v) =>
                            {
                                var ev = This.FirstInPrototypeChainAs<JSEvent>();
                                v.Set(ev.Data.altKey);
                            },
                        }, mdr.PropertyDescriptor.Attributes.NotWritable);
                        prototype.DefineOwnProperty("target", new mdr.DProperty()
                        {
                            OnGetDValue = (mdr.DObject This, ref mdr.DValue v) =>
                            {
                                var ev = This.FirstInPrototypeChainAs<JSEvent>();
                                v.Set(ev.Target);
                            },
                        }, mdr.PropertyDescriptor.Attributes.NotWritable);
                        prototype.DefineOwnProperty("currentTarget", new mdr.DProperty()
                        {
                            OnGetDValue = (mdr.DObject This, ref mdr.DValue v) =>
                            {
                                var ev = This.FirstInPrototypeChainAs<JSEvent>();
                                v.Set(ev.CurrentTarget);
                            },
                        }, mdr.PropertyDescriptor.Attributes.NotWritable);
                        prototype.DefineOwnProperty("eventPhase", new mdr.DProperty()
                        {
                            OnGetDValue = (mdr.DObject This, ref mdr.DValue v) =>
                            {
                                var ev = This.FirstInPrototypeChainAs<JSEvent>();
                                v.Set((UInt32)ev.Phase);
                            },
                        }, mdr.PropertyDescriptor.Attributes.NotWritable);
                        prototype.DefineOwnProperty("bubbles", new mdr.DProperty()
                        {
                            OnGetDValue = (mdr.DObject This, ref mdr.DValue v) =>
                            {
                                var ev = This.FirstInPrototypeChainAs<JSEvent>();
                                v.Set(ev.Bubbles);
                            },
                        }, mdr.PropertyDescriptor.Attributes.NotWritable);
                        prototype.DefineOwnProperty("cancelable", new mdr.DProperty()
                        {
                            OnGetDValue = (mdr.DObject This, ref mdr.DValue v) =>
                            {
                                var ev = This.FirstInPrototypeChainAs<JSEvent>();
                                v.Set(ev.Cancelable);
                            },
                        }, mdr.PropertyDescriptor.Attributes.NotWritable);


                        prototype.SetField("initEvent", new mdr.DFunction((ref mdr.CallFrame callFrame) =>
                        {
                            string eventTypeString = callFrame.Arg0.AsString();
                            bool bubbles = mjr.Operations.Convert.ToBoolean.Run(ref callFrame.Arg1);
                            bool cancelable = mjr.Operations.Convert.ToBoolean.Run(ref callFrame.Arg2);

                            var ev = callFrame.This.FirstInPrototypeChainAs<JSEvent>();
                            EventTypes type;
                            eventTypesToString.TryGetValue(eventTypeString, out type);
                            ev.InitEvent(type, bubbles, cancelable);

                        }));
                        prototype.SetField("stopPropagation", new mdr.DFunction((ref mdr.CallFrame callFrame) =>
                        {
                            var ev = callFrame.This.FirstInPrototypeChainAs<JSEvent>();
                            ev.StopPropagation();

                        }));
                        prototype.SetField("stopImmediatePropagation", new mdr.DFunction((ref mdr.CallFrame callFrame) =>
                        {
                            var ev = callFrame.This.FirstInPrototypeChainAs<JSEvent>();
                            ev.StopImmediatePropagation();

                        }));
                        prototype.SetField("preventDefault", new mdr.DFunction((ref mdr.CallFrame callFrame) =>
                        {
                            var ev = callFrame.This.FirstInPrototypeChainAs<JSEvent>();
                            ev.PreventDefault();

                        }));
                        //Fill the rest ...
                        break;
                    }
                case EventClasses.UIEvent:
                    {
                        prototype = new mdr.DObject(HTMLRuntime.Instance.GetPropertyMapOfEventPrototype(EventClasses.Event));
                        /*
                                                prototype.DefineOwnProperty("type", new mdr.DProperty()
                                                {
                                                    OnGetDValue = (mdr.DObject This, ref mdr.DValue v) =>
                                                    {
                                                        var ev = This.FirstInPrototypeChainAs<JSEvent>();
                                                        v.Set(ev.Data.Type.ToString());
                                                    },
                                                }, mdr.PropertyDescriptor.Attributes.NotWritable);
                         * */
                        prototype.SetField("initUIEvent", new mdr.DFunction((ref mdr.CallFrame callFrame) =>
                        {
                            string eventTypeString = callFrame.Arg0.AsString();
                            bool bubbles = mjr.Operations.Convert.ToBoolean.Run(ref callFrame.Arg1);
                            bool cancelable = mjr.Operations.Convert.ToBoolean.Run(ref callFrame.Arg2);
                            // TODO: Variables 'view' and 'detail' are never used; remove?
                            /*string view = callFrame.Arg3.ToString();
                            int detail = -1;
                            if (callFrame.ArgsCount > 4)
                            {
                                detail = callFrame.Arguments[0].ToInt32();
                            }*/

                            var ev = callFrame.This.FirstInPrototypeChainAs<JSEvent>();
                            EventTypes type;
                            eventTypesToString.TryGetValue(eventTypeString, out type);
                            ev.InitEvent(type, bubbles, cancelable);

                        }));
                        //Fill the rest ...
                        break;
                    }
                case EventClasses.MouseEvent:
                    {
                        prototype = new mdr.DObject(HTMLRuntime.Instance.GetPropertyMapOfEventPrototype(EventClasses.UIEvent));
                        prototype.DefineOwnProperty("type", new mdr.DProperty()
                        {
                            OnGetDValue = (mdr.DObject This, ref mdr.DValue v) =>
                            {
                                var ev = This.FirstInPrototypeChainAs<JSEvent>();
                                v.Set(ev.Data.Type.ToString());
                            },
                        }, mdr.PropertyDescriptor.Attributes.NotWritable);
                        //Fill the rest ...
                        break;
                    }
                default:
                    Trace.Fail("Invalid event class type {0}", eventClass);
                    break;
            }
            return prototype;
        }
Ejemplo n.º 41
0
        public void SetTopGlobalContext(mdr.DObject topWindow)
        {
#if ENABLE_RR
            if (RecordReplayManager.Instance.RecordEnabled)
            {
                RecordReplayManager.Instance.Record("HTMLRuntime", null, "SetTopGlobalContext", false, topWindow);
            }
#endif
            Debug.WriteLine("Setting global context");
            TopGlobalContext = topWindow;
            GlobalContext = topWindow;      // Just to be sure GlobalContext also has current value
            // RunScriptString("if(undefined);","xyzyyz"); // This might JIT most of the compiler code early
        }
Ejemplo n.º 42
0
        private static void AddExtendedMethods(mdr.DObject obj)
        {
            #region Mozilla intrinsics
            obj.SetField("assertTrue", new mdr.DFunction((ref mdr.CallFrame callFrame) =>
            {
                int argsLen = callFrame.PassedArgsCount;
                if (argsLen > 0)
                {
                    var b = Operations.Convert.ToBoolean.Run(ref callFrame.Arg0);
                    assert(b, argsLen > 1 ? callFrame.Arg1.AsString() : null);
                }
                else
                    Trace.Fail("Not enough arguments");
            }));

            obj.SetField("assertFalse", new mdr.DFunction((ref mdr.CallFrame callFrame) =>
            {
                int argsLen = callFrame.PassedArgsCount;
                if (argsLen > 0)
                {
                    var b = Operations.Convert.ToBoolean.Run(ref callFrame.Arg0);
                    assert(!b, argsLen > 1 ? callFrame.Arg1.AsString() : null);
                }
                else
                    Trace.Fail("Not enough arguments");
            }));

            obj.SetField("assertEquals", new mdr.DFunction((ref mdr.CallFrame callFrame) =>
            {
                int argsLen = callFrame.PassedArgsCount;
                if (argsLen > 1)
                {
                    bool b = Operations.Binary.Equal.Run(ref callFrame.Arg0, ref callFrame.Arg1);
                    assert(b, argsLen > 2 ? callFrame.Arg2.AsString() : null);
                }
                else
                    Trace.Fail("Not enough arguments");
            }));

            obj.SetField("assertArrayEquals", new mdr.DFunction((ref mdr.CallFrame callFrame) =>
            {
                int argsLen = callFrame.PassedArgsCount;
                if (argsLen > 1)
                {
                    var arrayA = callFrame.Arg0.AsDArray();
                    var arrayB = callFrame.Arg1.AsDArray();
                    bool areEqual = true;
                    if (arrayA != null && arrayB != null && arrayA.Length == arrayB.Length)
                    {
                        for (int i = 0; i < arrayA.Length; i++)
                            if (Operations.Binary.Equal.Run(ref arrayA.Elements[i], ref arrayB.Elements[i]))
                            {
                                areEqual = false;
                                break;
                            }
                    }
                    else if (arrayA != arrayB)
                        areEqual = false;
                    assert(areEqual, argsLen > 2 ? callFrame.Arg2.AsString() : null);
                }
                else
                    Trace.Fail("Not enough arguments");
            }));
            #endregion

            // FIXME: The below causes an infinite recursion in CodeSourceGenerator. Commenting for now. - SF
            //SetField("global", this); //to enable access to global scope directly!
            obj.SetField("print", new mdr.DFunction((ref mdr.CallFrame callFrame) =>
            {
                var l = callFrame.PassedArgsCount;
                for (var i = 0; i < l; ++i)
                {
                    var arg = callFrame.Arg(i);
                    string s = ToString(ref arg);
                    Console.Write("{0}{1}", s, (i < l - 1) ? " " : "");

                }
                Console.WriteLine();
            }));

            obj.SetField("load", new mdr.DFunction((ref mdr.CallFrame callFrame) =>
            {
                var l = callFrame.PassedArgsCount;
                if (l < 1)
                    throw new Exception("load must have an argument");
                var filename = callFrame.Arg0.AsString();
                JSRuntime.Instance.RunScriptFile(filename);
            }));

            #region __mcjs__ object
            {
                var mcjs = new mdr.DObject(mdr.Runtime.Instance.EmptyPropertyMapMetadata.Root);
                obj.SetField("__mcjs__", mcjs);
                mcjs.SetField("SetSwitch", new mdr.DFunction((ref mdr.CallFrame callFrame) =>
                {
                    var switchName = callFrame.Arg0.AsString();
                    var switchValue = Operations.Convert.ToBoolean.Run(ref callFrame.Arg1);
                    var prop = typeof(JSRuntimeConfiguration).GetProperty(switchName, CodeGen.Types.ClrSys.Boolean);
                    if (prop != null)
                        prop.GetSetMethod().Invoke(JSRuntime.Instance.Configuration, new object[] { switchValue });
                    else
                        Debug.WriteLine("JSRuntime.Instance.Configuration does not contain the switch '{0}'", switchName);
                }));

                mcjs.SetField("PrintDump", new mdr.DFunction((ref mdr.CallFrame callFrame) =>
                {
                    var l = callFrame.PassedArgsCount;
                    if (l != 1)
                        throw new Exception("PrintDump must have one argument");
                    Debug.WriteLine("##JS: {0}", callFrame.Arg0.AsString());
#if DEBUG
                    //Check for android log directory
                    if (printOutFile == null)
                    {
                      printOutFile = System.IO.File.CreateText(System.IO.Path.Combine(JSRuntime.Instance.Configuration.OutputDir, "mcprint" + System.Threading.Thread.CurrentThread.ManagedThreadId.ToString() + ".out"));
                    }

                    printOutFile.Write("{0}", callFrame.Arg0.AsString());
                    printOutFile.Flush();
                    //Debug.WriteLine("MCPRINTVAR: {0}={1}", callFrame.Arg1.ToString(), s);
#endif
                }));

            }
            #endregion

        }
Ejemplo n.º 43
0
        public override void ShutDown()
        {
            Debug.WriteLine("HTMLRuntime Shutdown method was called");
#if ENABLE_RR            
            if (RecordReplayManager.Instance.RecordEnabled)
            {
                RecordReplayManager.Instance.Record("HTMLRuntime", null, "ShutDown", false);
            }
            if (RecordReplayManager.Instance.RecordEnabled)
            {
                RecordReplayManager.Instance.StopRecord();
                Debug.WriteLine("Stop recording the session.");
            }
#endif
            TopGlobalContext = null;
            GlobalContext = null;
            base.ShutDown();
            //Instance = null;
        }
Ejemplo n.º 44
0
        public bool MoveNext()
        {
            // Debug.WriteLine("calling PropertyNameEnumerator.MoveNext");
            while (_dobject != null)
            {
                var array = _dobject as mdr.DArray;
                if (array != null)
                {
                    while (++_elementsIndex < array.ElementsLength)
                    {
                        if (!_visiteds.Contains(-_elementsIndex))
                        {
                            _visiteds.Add(-_elementsIndex);
                            _current = _elementsIndex.ToString();
                            return true;
                        }
                    }
                }

                /*
                ///Spec says the order of retreiving the properties does not matter, so the following code is faster
                ///However some stupid websites (e.g. BBC) count on the fact that Browsers list properties with a certain order
                ///So, we had to change to the slower to be browser compatible, rather than spec compatible
                if (_map == null)
                    _map = _dobject.Map;

                while (_map != null)
                {
                    var prop = _map.Property;
                    _map = _map.Parent;

                    if (!prop.IsNotEnumerable && !_visiteds.Contains(prop.NameId))
                    {
                        _visiteds.Add(prop.NameId);
                        _current = prop.Name;
                        return true;
                    }
                }
                _dobject = _dobject.Prototype;
                _elementsIndex = -1;
                _current = null;
                 */
                if (_currentNode == null)
                {
                    //We may have reached to the end of collected properties, but meanwhile some new ones may have been added
                    _propNames.Clear();
                    if (_map != null && _map != _dobject.Map)
                      _map = _dobject.Map;
                    for (var m = _dobject.Map; m != _map; m = m.Parent)
                    {
                        var prop = m.Property;
                        if (!prop.IsNotEnumerable && !_visiteds.Contains(prop.NameId))
                        {
                          _visiteds.Add(prop.NameId);
                          _propNames.AddFirst(prop.Name);
                        }
                    }
                    _map = _dobject.Map;
                    _currentNode = _propNames.First;

                    if (_currentNode == null)
                    {
                        _dobject = _dobject.Prototype;
                        _elementsIndex = -1;
                        _current = null;
                        _map = null;
                        continue; //Jump to begining of the loop!
                    }
                }
                _current = _currentNode.Value;
                _currentNode = _currentNode.Next;
                return true;
            }
            return false;
        }
Ejemplo n.º 45
0
 private void PrepareContext(ref mdr.CallFrame callFrame)
 {
   if (_currScope.IsProgram)
     Context = JSFunctionContext.CreateProgramContext(ref callFrame);
   else if (_currScope.IsEvalFunction)
     Context = JSFunctionContext.CreateEvalContext(ref callFrame);
   else if (_currScope.IsConstContext)
     Context = JSFunctionContext.CreateConstantContext(ref callFrame);
   else
     Context = JSFunctionContext.CreateFunctionContext(ref callFrame);
 }
Ejemplo n.º 46
0
 public override void Execute(ref mdr.DValue result, ref mdr.CallFrame callFrame, Interpreter interpreter)
 {
   interpreter.PushLocation(this);
   var obj = new mdr.DObject();
   for (var i = 0; i < Properties.Count; ++i)
   {
     var prop = Properties[i];
     prop.Execute(ref result, ref callFrame, interpreter);
     obj.DefineOwnProperty(prop.Name, ref result, mdr.PropertyDescriptor.Attributes.Data);
   }
   result.Set(obj);
   interpreter.PopLocation(this, ref result);
 }
Ejemplo n.º 47
0
 public JSPropertyNameEnumerator(mdr.DObject dobject)
 {
     _dobject = dobject;
     _elementsIndex = -1;
     _current = null;
 }