Example #1
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"));
 }
Example #2
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);
 }
Example #3
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);
 }
Example #4
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);
        }
Example #5
0
        public static new void PreparePrototype(mdr.DObject prototype)
        {
            prototype.DefineOwnProperty("latitude", new mdr.DProperty()
            {
                OnGetDValue = (mdr.DObject This, ref mdr.DValue v) =>
                {
                    var ev = This.FirstInPrototypeChainAs<JSPosition>();
                    v.Set(ev.Data.latitude);
                },
            }, mdr.PropertyDescriptor.Attributes.NotWritable);
            prototype.DefineOwnProperty("longitude", new mdr.DProperty()
            {
                OnGetDValue = (mdr.DObject This, ref mdr.DValue v) =>
                {
                    var ev = This.FirstInPrototypeChainAs<JSPosition>();
                    v.Set(ev.Data.longitude);
                },
            }, mdr.PropertyDescriptor.Attributes.NotWritable);
            prototype.DefineOwnProperty("altitude", new mdr.DProperty()
            {
                OnGetDValue = (mdr.DObject This, ref mdr.DValue v) =>
                {
                    var ev = This.FirstInPrototypeChainAs<JSPosition>();
                    v.Set(ev.Data.altitude);
                },
            }, mdr.PropertyDescriptor.Attributes.NotWritable);
            prototype.DefineOwnProperty("accuracy", new mdr.DProperty()
            {
                OnGetDValue = (mdr.DObject This, ref mdr.DValue v) =>
                {
                    var ev = This.FirstInPrototypeChainAs<JSPosition>();
                    v.Set(ev.Data.accuracy);
                },
            }, mdr.PropertyDescriptor.Attributes.NotWritable);
            prototype.DefineOwnProperty("altitudeAccuracy", new mdr.DProperty()
            {
                OnGetDValue = (mdr.DObject This, ref mdr.DValue v) =>
                {
                    var ev = This.FirstInPrototypeChainAs<JSPosition>();
                    v.Set(ev.Data.altitudeAccuracy);
                },
            }, mdr.PropertyDescriptor.Attributes.NotWritable);
            prototype.DefineOwnProperty("heading", new mdr.DProperty()
            {
                OnGetDValue = (mdr.DObject This, ref mdr.DValue v) =>
                {
                    var ev = This.FirstInPrototypeChainAs<JSPosition>();
                    v.Set(ev.Data.heading);
                },
            }, mdr.PropertyDescriptor.Attributes.NotWritable);
            prototype.DefineOwnProperty("speed", new mdr.DProperty()
            {
                OnGetDValue = (mdr.DObject This, ref mdr.DValue v) =>
                {
                    var ev = This.FirstInPrototypeChainAs<JSPosition>();
                    v.Set(ev.Data.speed);
                },
            }, mdr.PropertyDescriptor.Attributes.NotWritable); 
            prototype.DefineOwnProperty("lciid", new mdr.DProperty()
            {
                OnGetDValue = (mdr.DObject This, ref mdr.DValue v) =>
                {
                    var ev = This.FirstInPrototypeChainAs<JSPosition>();
                    v.Set(ev.Data.lciid);
                },
            }, mdr.PropertyDescriptor.Attributes.NotWritable); 
            prototype.DefineOwnProperty("timestamp", new mdr.DProperty()
            {
                OnGetDValue = (mdr.DObject This, ref mdr.DValue v) =>
                {
                    var ev = This.FirstInPrototypeChainAs<JSPosition>();
                    v.Set(ev.Data.timestamp);
                },
            }, mdr.PropertyDescriptor.Attributes.NotWritable); 
            prototype.DefineOwnProperty("status", new mdr.DProperty()
            {
                OnGetDValue = (mdr.DObject This, ref mdr.DValue v) =>
                {
                    var ev = This.FirstInPrototypeChainAs<JSPosition>();
                    v.Set(ev.Data.status);
                },
            }, mdr.PropertyDescriptor.Attributes.NotWritable); 

        }
Example #6
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
   );
 }
Example #7
0
 internal static void InitDStringPrototype(mdr.DObject dStringProto,
                                           string protoFieldName)
 {
   dStringProto.DefineOwnProperty(
       protoFieldName
       , new DProperty()
       {
         TargetValueType = ValueTypes.Int32,
         OnGetInt = (This) =>
         {
           var str = This as DString;
           if (str.PrimitiveValue.AsString() != null)
             return str.PrimitiveValue.AsString().Length;
           else
             return 0;
         },
         OnGetDValue = (DObject This, ref DValue v) =>
         {
           var str = This as DString;
           if (str != null && str.PrimitiveValue.AsString() != null)
             v.Set(str.PrimitiveValue.AsString().Length);
           else
             v.Set(0);
         },
         OnSetDValue = (DObject This, ref DValue v) => { },
       }
       , PropertyDescriptor.Attributes.Accessor
       | PropertyDescriptor.Attributes.NotEnumerable
       | PropertyDescriptor.Attributes.NotConfigurable
       | PropertyDescriptor.Attributes.NotWritable
   );
 }
Example #8
0
 internal static void InitDArrayPrototype(mdr.DObject dArrayProto,
                                          string protoFieldName)
 {
   dArrayProto.DefineOwnProperty(
       protoFieldName
       , new DProperty()
       {
         TargetValueType = ValueTypes.Int32,
         OnGetInt = (This) => { return (This as DArray).Length; },
         OnSetInt = (This, v) => { (This as DArray).Length = v; },
         OnGetDValue = (DObject This, ref DValue v) =>
         {
           var array = This.FirstInPrototypeChainAs<DArray>(false);
           if (array != null)
             v.Set(array.Length);
           else
             v.Set(0);
         },
         OnSetDValue = (DObject This, ref DValue v) =>
         {
           var array = This.FirstInPrototypeChainAs<DArray>(false);
           if (array != null)
             array.Length = v.AsInt32();
         },
       }
       , PropertyDescriptor.Attributes.Accessor
       | PropertyDescriptor.Attributes.NotEnumerable
       | PropertyDescriptor.Attributes.NotConfigurable
   );
 }