Example #1
0
    public Engine(RuntimeConfiguration configuration)
    {
      Trace.Assert(Instance == null, "Cannot have more than one instance of Engine");
      Engine.Instance = this;
      Configuration = configuration;
      configuration.ParseArgs(); // Do this now before anyone tries to read any configuration value.

      // Select Diagnose settings based on configuration.
      Diagnostics.EnableExceptionDump = configuration.EnableExceptionDump;
      Diagnostics.EnableStackDump = configuration.EnableStackDump;
      Diagnostics.FailOnException = configuration.FailOnException;
      Diagnostics.RedirectAllExceptions = configuration.RedirectAllExceptions;
    }
Example #2
0
        public Engine(RuntimeConfiguration configuration)
        {
            Trace.Assert(Instance == null, "Cannot have more than one instance of Engine");
            Engine.Instance = this;
            Configuration   = configuration;
            configuration.ParseArgs(); // Do this now before anyone tries to read any configuration value.

            // Select Diagnose settings based on configuration.
            Diagnostics.EnableExceptionDump   = configuration.EnableExceptionDump;
            Diagnostics.EnableStackDump       = configuration.EnableStackDump;
            Diagnostics.FailOnException       = configuration.FailOnException;
            Diagnostics.RedirectAllExceptions = configuration.RedirectAllExceptions;
        }
Example #3
0
        protected Runtime(RuntimeConfiguration configuration)
        {
            _inheritPropertyObjectCacheMaxIndex = 0;

            //We need to first set the Instance since the following constructors may use it!
            Runtime.Instance = this;

            Configuration = configuration;
            configuration.ParseArgs();//Do this now before anyone tries to read any configuration value.

            if (configuration.EnableTimers)
            {
                Timers = new m.Util.Timers();
                _timer = StartSimpleTimer(true, "MCJS");
            }

            if (configuration.EnableCounters)
            {
                Counters = new m.Util.Counters();
            }

            EmptyPropertyMapMetadata = new PropertyMapMetadata(null);

            ///We can initialize commong field Ids to save lookups later
            ValueOfFieldId   = GetFieldId("valueOf");
            ToStringFieldId  = GetFieldId("toString");
            PrototypeFieldId = GetFieldId("prototype");
            LengthFieldId    = GetFieldId("length");

            ///In each instance of Runtime we need to first reset prototypes in case a program has changed them

            //DUndefinedPrototype = new DObject(root.Root);

            DObjectPrototype = new DObject(EmptyPropertyMapMetadata.Root);
            DObjectMap       = GetRootMapOfPrototype(DObjectPrototype);

            DFunctionPrototype = new DObject(DObjectMap);
            DFunctionMap       = GetRootMapOfPrototype(DFunctionPrototype);

            DNumberPrototype = new DObject(DObjectMap);
            DNumberMap       = GetRootMapOfPrototype(DNumberPrototype);

            DStringPrototype = new DObject(DObjectMap);
            DStringMap       = GetRootMapOfPrototype(DStringPrototype);

            DBooleanPrototype = new DObject(DObjectMap);
            DBooleanMap       = GetRootMapOfPrototype(DBooleanPrototype);

            DArrayPrototype = new DObject(DObjectMap);
            DArrayMap       = GetRootMapOfPrototype(DArrayPrototype);

            DRegExpPrototype = new DObject(DObjectMap);
            DRegExpMap       = GetRootMapOfPrototype(DRegExpPrototype);


            //Now need to recreate default values based on fresh prototypes.
            DefaultDUndefined = new DUndefined();
            DefaultDNull      = new DNull();

            //DefaultDObject = new DObject();
            //DefaultDDouble = new DDouble(default(double));
            //DefaultDString = new DString(default(string));
            //DefaultDInt = new DInt(default(int));
            //DefaultDBoolean = new DBoolean(default(bool));
            //DefaultDFunction = new DFunction(null);
            //DefaultDArray = new DArray();
            //DefaultDProperty = new DProperty();

            ArrayItemAccessor = new PropertyDescriptor(null)
            {
                Getter = (mdr.PropertyDescriptor pd, mdr.DObject obj, ref mdr.DValue value) =>
                {
                    value = (obj as DArray).Elements[pd.Index];

                    /*if (mdr.Runtime.Instance.Configuration.ProfileStats)
                     * {
                     * mdr.Runtime.Instance.Counters.GetCounter("ArrayItemAccessor").Count++;
                     * }*/
                },
                Setter = (mdr.PropertyDescriptor pd, mdr.DObject obj, ref mdr.DValue value) =>
                {
                    (obj as DArray).Elements[pd.Index] = value;
                },
            };

            StringItemAccessor = new PropertyDescriptor(null)
            {
                Getter = (mdr.PropertyDescriptor pd, mdr.DObject obj, ref mdr.DValue value) =>
                {
                    var strObj = obj.FirstInPrototypeChainAs <DString>();
                    value.Set(strObj.PrimitiveValue.AsString()[pd.Index]);
                },
                Setter = (mdr.PropertyDescriptor pd, mdr.DObject obj, ref mdr.DValue value) =>
                {
                    var strObj = obj.FirstInPrototypeChainAs <DString>();
                    var chars  = strObj.PrimitiveValue.AsString().ToCharArray();
                    chars[pd.Index] = value.AsChar();
                    strObj.PrimitiveValue.Set(new String(chars));
                },
            };

            var lengthFieldName = GetFieldName(LengthFieldId);

            ProtoInitializer.InitDArrayPrototype(DArrayPrototype, lengthFieldName);
            ProtoInitializer.InitDStringPrototype(DStringPrototype, lengthFieldName);

            var protoFieldName = GetFieldName(PrototypeFieldId);

            ProtoInitializer.InitDFunctionPrototype(DFunctionPrototype,
                                                    protoFieldName,
                                                    PrototypeFieldId);
        }
Example #4
0
    protected Runtime(RuntimeConfiguration configuration)
    {
      _inheritPropertyObjectCacheMaxIndex = 0;

      //We need to first set the Instance since the following constructors may use it!
      Runtime.Instance = this;

      Configuration = configuration;
      configuration.ParseArgs();//Do this now before anyone tries to read any configuration value.

      if (configuration.EnableTimers)
      {
        Timers = new m.Util.Timers();
        _timer = StartSimpleTimer(true, "MCJS");
      }

      if (configuration.EnableCounters)
        Counters = new m.Util.Counters();

      EmptyPropertyMapMetadata = new PropertyMapMetadata(null);

      ///We can initialize commong field Ids to save lookups later
      ValueOfFieldId = GetFieldId("valueOf");
      ToStringFieldId = GetFieldId("toString");
      PrototypeFieldId = GetFieldId("prototype");
      LengthFieldId = GetFieldId("length");

      ///In each instance of Runtime we need to first reset prototypes in case a program has changed them

      //DUndefinedPrototype = new DObject(root.Root);

      DObjectPrototype = new DObject(EmptyPropertyMapMetadata.Root);
      DObjectMap = GetRootMapOfPrototype(DObjectPrototype);

      DFunctionPrototype = new DObject(DObjectMap);
      DFunctionMap = GetRootMapOfPrototype(DFunctionPrototype);

      DNumberPrototype = new DObject(DObjectMap);
      DNumberMap = GetRootMapOfPrototype(DNumberPrototype);

      DStringPrototype = new DObject(DObjectMap);
      DStringMap = GetRootMapOfPrototype(DStringPrototype);

      DBooleanPrototype = new DObject(DObjectMap);
      DBooleanMap = GetRootMapOfPrototype(DBooleanPrototype);

      DArrayPrototype = new DObject(DObjectMap);
      DArrayMap = GetRootMapOfPrototype(DArrayPrototype);

      DRegExpPrototype = new DObject(DObjectMap);
      DRegExpMap = GetRootMapOfPrototype(DRegExpPrototype);


      //Now need to recreate default values based on fresh prototypes.
      DefaultDUndefined = new DUndefined();
      DefaultDNull = new DNull();

      //DefaultDObject = new DObject();
      //DefaultDDouble = new DDouble(default(double));
      //DefaultDString = new DString(default(string));
      //DefaultDInt = new DInt(default(int));
      //DefaultDBoolean = new DBoolean(default(bool));
      //DefaultDFunction = new DFunction(null);
      //DefaultDArray = new DArray();
      //DefaultDProperty = new DProperty();

      ArrayItemAccessor = new PropertyDescriptor(null)
      {
        Getter = (mdr.PropertyDescriptor pd, mdr.DObject obj, ref mdr.DValue value) =>
        {
          value = (obj as DArray).Elements[pd.Index];
          /*if (mdr.Runtime.Instance.Configuration.ProfileStats)
          {
            mdr.Runtime.Instance.Counters.GetCounter("ArrayItemAccessor").Count++;
          }*/
        },
        Setter = (mdr.PropertyDescriptor pd, mdr.DObject obj, ref mdr.DValue value) =>
        {
          (obj as DArray).Elements[pd.Index] = value;
        },
      };

      StringItemAccessor = new PropertyDescriptor(null)
      {
        Getter = (mdr.PropertyDescriptor pd, mdr.DObject obj, ref mdr.DValue value) =>
        {
          var strObj = obj.FirstInPrototypeChainAs<DString>();
          value.Set(strObj.PrimitiveValue.AsString()[pd.Index]);
        },
        Setter = (mdr.PropertyDescriptor pd, mdr.DObject obj, ref mdr.DValue value) =>
        {
          var strObj = obj.FirstInPrototypeChainAs<DString>();
          var chars = strObj.PrimitiveValue.AsString().ToCharArray();
          chars[pd.Index] = value.AsChar();
          strObj.PrimitiveValue.Set(new String(chars));
        },
      };

      var lengthFieldName = GetFieldName(LengthFieldId);
      ProtoInitializer.InitDArrayPrototype(DArrayPrototype, lengthFieldName);
      ProtoInitializer.InitDStringPrototype(DStringPrototype, lengthFieldName);

      var protoFieldName = GetFieldName(PrototypeFieldId);
      ProtoInitializer.InitDFunctionPrototype(DFunctionPrototype,
                                              protoFieldName,
                                              PrototypeFieldId);

    }