Exemplo n.º 1
0
        static ArrayPrototype()
        {
            Value = new MondValue(MondValueType.Object);
            Value["prototype"] = ObjectPrototype.Value;

            Value["length"] = new MondInstanceFunction(Length);
        }
Exemplo n.º 2
0
        static NumberPrototype()
        {
            Value           = new MondValue(MondValueType.Object);
            Value.Prototype = ValuePrototype.Value;

            Value["isNaN"] = new MondInstanceFunction(IsNaN);

            Value.Lock();
        }
Exemplo n.º 3
0
        /// <summary>
        /// Construct a new Function MondValue with the specified value. Instance functions will
        /// bind themselves to their parent object when being retrieved.
        /// </summary>
        private MondValue(MondInstanceFunction function)
        {
            if (ReferenceEquals(function, null))
            {
                throw new ArgumentNullException(nameof(function));
            }

            Type          = MondValueType.Function;
            FunctionValue = new Closure(function);
        }
Exemplo n.º 4
0
        static ValuePrototype()
        {
            Value           = new MondValue(MondValueType.Object);
            Value.Prototype = MondValue.Null; // required to break the chain

            Value["getType"]   = new MondInstanceFunction(GetType);
            Value["toString"]  = new MondInstanceFunction(ToString);
            Value["serialize"] = new MondInstanceFunction(Serialize);
            Value.Lock();
        }
Exemplo n.º 5
0
        public void NativeInstanceFunction()
        {
            var state = new MondState();

            state["value"]    = 123;
            state["function"] = new MondInstanceFunction((_, instance, arguments) => instance[arguments[0]]);

            var result = state.Run(@"
                return global.function('value');
            ");

            Assert.True(result == 123);
        }
Exemplo n.º 6
0
        public void NativeInstanceFunction()
        {
            var state = new MondState();

            state["value"] = 123;
            state["function"] = new MondInstanceFunction((_, instance, arguments) => instance[arguments[0]]);

            var result = state.Run(@"
                return global.function('value');
            ");

            Assert.True(result == 123);
        }
Exemplo n.º 7
0
        /// <summary>
        /// Construct a new Function MondValue with the specified value. Instance functions will
        /// bind themselves to their parent object when being retrieved.
        /// </summary>
        private MondValue(MondInstanceFunction function)
        {
            if (ReferenceEquals(function, null))
            {
                throw new ArgumentNullException(nameof(function));
            }

            _type        = MondValueType.Function;
            _numberValue = 0;

            ObjectValue   = null;
            ArrayValue    = null;
            _stringValue  = null;
            FunctionValue = new Closure(function);
        }
Exemplo n.º 8
0
        static ObjectPrototype()
        {
            Value           = new MondValue(MondValueType.Object);
            Value.Prototype = ValuePrototype.Value;

            Value["add"]           = new MondInstanceFunction(Add);
            Value["clear"]         = new MondInstanceFunction(Clear);
            Value["containsKey"]   = new MondInstanceFunction(ContainsKey);
            Value["containsValue"] = new MondInstanceFunction(ContainsValue);
            Value["get"]           = new MondInstanceFunction(Get);
            Value["remove"]        = new MondInstanceFunction(Remove);

            Value["length"]        = new MondInstanceFunction(Length);
            Value["getEnumerator"] = new MondInstanceFunction(GetEnumerator);

            Value["prototype"] = new MondInstanceFunction(Prototype);

            Value.Lock();
        }
Exemplo n.º 9
0
        static ArrayPrototype()
        {
            Value           = new MondValue(MondValueType.Object);
            Value.Prototype = ValuePrototype.Value;

            Value["add"]         = new MondInstanceFunction(Add);
            Value["clear"]       = new MondInstanceFunction(Clear);
            Value["contains"]    = new MondInstanceFunction(Contains);
            Value["indexOf"]     = new MondInstanceFunction(IndexOf);
            Value["lastIndexOf"] = new MondInstanceFunction(LastIndexOf);
            Value["insert"]      = new MondInstanceFunction(Insert);
            Value["remove"]      = new MondInstanceFunction(Remove);
            Value["removeAt"]    = new MondInstanceFunction(RemoveAt);

            Value["length"]        = new MondInstanceFunction(Length);
            Value["getEnumerator"] = new MondInstanceFunction(GetEnumerator);

            Value.Lock();
        }
Exemplo n.º 10
0
        static StringPrototype()
        {
            Value           = new MondValue(MondValueType.Object);
            Value.Prototype = ValuePrototype.Value;

            Value["charAt"]      = new MondInstanceFunction(CharAt);
            Value["contains"]    = new MondInstanceFunction(Contains);
            Value["endsWith"]    = new MondInstanceFunction(EndsWith);
            Value["indexOf"]     = new MondInstanceFunction(IndexOf);
            Value["insert"]      = new MondInstanceFunction(Insert);
            Value["lastIndexOf"] = new MondInstanceFunction(LastIndexOf);
            Value["replace"]     = new MondInstanceFunction(Replace);
            Value["split"]       = new MondInstanceFunction(Split);
            Value["startsWith"]  = new MondInstanceFunction(StartsWith);
            Value["substring"]   = new MondInstanceFunction(Substring);
            Value["toUpper"]     = new MondInstanceFunction(ToUpper);
            Value["toLower"]     = new MondInstanceFunction(ToLower);
            Value["trim"]        = new MondInstanceFunction(Trim);

            Value["length"]        = new MondInstanceFunction(Length);
            Value["getEnumerator"] = new MondInstanceFunction(GetEnumerator);

            Value.Lock();
        }
Exemplo n.º 11
0
 /// <summary>
 /// Construct a new Function MondValue with the specified value. Instance functions will
 /// bind themselves to their parent object when being retrieved.
 /// </summary>
 public MondValue(MondInstanceFunction function)
     : this()
 {
     Type          = MondValueType.Function;
     FunctionValue = new Closure(function);
 }
Exemplo n.º 12
0
        public Closure(MondInstanceFunction function)
        {
            Type = ClosureType.InstanceNative;

            InstanceNativeFunction = function;
        }
Exemplo n.º 13
0
 public static MondValue Function([NotNull] MondInstanceFunction value)
 {
     return(new MondValue(value));
 }
Exemplo n.º 14
0
        public Closure(MondInstanceFunction function)
        {
            Type = ClosureType.InstanceNative;

            InstanceNativeFunction = function;
        }