static ArrayPrototype() { Value = new MondValue(MondValueType.Object); Value["prototype"] = ObjectPrototype.Value; Value["length"] = new MondInstanceFunction(Length); }
static NumberPrototype() { Value = new MondValue(MondValueType.Object); Value.Prototype = ValuePrototype.Value; Value["isNaN"] = new MondInstanceFunction(IsNaN); Value.Lock(); }
/// <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); }
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(); }
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); }
/// <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); }
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(); }
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(); }
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(); }
/// <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); }
public Closure(MondInstanceFunction function) { Type = ClosureType.InstanceNative; InstanceNativeFunction = function; }
public static MondValue Function([NotNull] MondInstanceFunction value) { return(new MondValue(value)); }