public object[] EvaluateParameters() { var values = new object[_parameters.Length]; for (int i = 0; i < values.Length; i++) { try { object param = _parameters[i].Evaluate(); if (param == null) { values[i] = new Undefined(); } else { values[i] = param; } } catch { values[i] = new Undefined(); } } evald_params = values; return(values); }
public static SExp Cond(SExp[] vals, Environment env) { SExp res = new Undefined(); foreach (SExp exp in vals) { if (!(exp is Cell)) { string msg = "cond: malformed clauses."; throw new TypeNotMatchException(msg); } SExp test = (exp as Cell).Car; if (!((exp as Cell).Cdr is Cell)) { string msg = "cond: malformed clauses."; throw new TypeNotMatchException(msg); } SExp[] body = ((exp as Cell).Cdr as Cell).ToArray(); if (Utilities.CanRegardAsTrue(Utilities.Eval(test, env))) { res = Utilities.Eval(body, env); break; } } return res; }
public static Undefined <T>[] DeserializeArray(string jsonArray) { var jss = new JavaScriptSerializer(); var objs = jss.Deserialize <object[]>(jsonArray); var undefinedArray = new Undefined <T> [objs.Length]; for (int i = 0; i < objs.Length; i++) { if (objs[i] is Dictionary <string, object> ) { var undefined = (Dictionary <string, object>)objs[i]; if (undefined.ContainsKey("undefined") && undefined["undefined"] == null) { undefinedArray[i] = new Undefined <T>(default(T), false); continue; } } T val; // The object being must be serializable by the JavaScriptSerializer // Or at the very least, be convertible from one type to another // by implementing IConvertible. try { val = (T)objs[i]; } catch (InvalidCastException) { val = (T)Convert.ChangeType(objs[i], typeof(T)); } undefinedArray[i] = new Undefined <T>(val, true); } return(undefinedArray); }
/// <summary> /// Sets the aliases and values. /// </summary> internal void SetAliasesAndValues(Dictionary <string, string> queryParams) { _props ??= GetType().GetProperties(BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public); foreach (var qp in queryParams) { var found = false; foreach (var kvp in Map) { if (!kvp.Key.EqualsEx(qp.Key) && !kvp.Value.Any(s => s.EqualsEx(qp.Key))) { continue; } var prop = _props.FirstOrDefault(p => p.Name.EqualsEx(kvp.Key)); prop?.SetNullableValue(this, qp.Value); found = true; } if (!found) { Undefined.Add(qp); } } }
// ReSharper disable once UnusedMember.Local static Bool Runtime(string queryString, IMessage message, Route route) { string deviceId = null; try { message.SystemProperties.TryGetValue(SystemProperties.DeviceId, out deviceId); QueryValue queryValue = message.GetQueryValue(queryString); if (queryValue == QueryValue.Null) { return(Bool.False); } else if (!Undefined.IsDefined(queryValue)) { return(Bool.Undefined); } else { return(Bool.True); } } catch (Exception ex) when(!ex.IsFatal()) { Events.RuntimeError(route, message, deviceId, ex); return(Bool.Undefined); } }
public void WriteBytes(Undefined value, SerializationContext context) { var bytesNeed = Amf0CommonValues.MARKER_LENGTH; var bufferBackend = _arrayPool.Rent(bytesNeed); context.Buffer.WriteToBuffer((byte)Amf0Type.Undefined); }
// ReSharper disable once UnusedMember.Local static Bool RuntimeQueryValue(QueryValue input) { if (Undefined.IsDefined(input)) { return((Bool)(input != QueryValue.Null)); } return(Bool.Undefined); }
public void NormalTest() { Undefined un = Undefined.Value; Assert.IsFalse(un); Assert.IsTrue(un == null); Assert.IsFalse(un != null); Assert.IsTrue(undefined == un); Assert.IsFalse(undefined != un); }
// ReSharper disable once UnusedMember.Local static Bool Runtime(QueryValue input) { if (input?.ValueType != QueryValueType.String) { return(Bool.False); } string inputString = (string)input.Value; return(Undefined.IsDefined(inputString) && (Bool)(inputString != null)); }
// ReSharper disable once UnusedMember.Local static double Runtime(QueryValue input) { if (input?.ValueType != QueryValueType.Double) { return(Undefined.Instance); } double inputValue = (double)input.Value; return(Undefined.IsDefined(inputValue) ? Math.Sign(inputValue) : (double)Undefined.Instance); }
private object Pop() { object value = null; if (Interop.duk_is_undefined(_ctx, -1)) { value = new Undefined(); } if (Interop.duk_is_null(_ctx, -1)) { value = null; } else if (Interop.duk_is_boolean(_ctx, -1)) { value = Interop.duk_get_boolean(_ctx, -1); } else if (Interop.duk_is_number(_ctx, -1)) { var number = Interop.duk_get_number(_ctx, -1); if ((number % 1) == 0) { value = System.Convert.ToInt32(number); } else { value = number; } } else if (Interop.duk_is_string(_ctx, -1)) { value = System.Runtime.InteropServices.Marshal.PtrToStringAnsi( Interop.duk_to_string(_ctx, -1)); } else if (Interop.duk_is_array(_ctx, -1)) { Interop.duk_pop(_ctx); throw new NotImplementedException("JS to C# Arrays not implemented"); } else if (Interop.duk_is_object(_ctx, -1)) { Interop.duk_pop(_ctx); throw new NotImplementedException("JS to C# Objects not implemented"); } Interop.duk_pop(_ctx); return(value); }
public virtual void ObjectCreateMethodIsSupported() { // Arrange const string initCode1 = "var obj1 = Object.create(null);"; const string input1 = "obj1.prototype"; Undefined targetOutput1 = Undefined.Value; const string initCode2 = "var obj2 = Object.create(Object.prototype);"; const string input2 = "typeof obj2;"; const string targetOutput2 = "object"; const string initCode3 = @"var greeter = { id: 678, name: 'stranger', greet: function() { return 'Hello, ' + this.name + '!'; } }; var myGreeter = Object.create(greeter); greeter.name = 'Vasya'"; const string input3A = "myGreeter.id"; const string input3B = "myGreeter.greet()"; const int targetOutput3A = 678; const string targetOutput3B = "Hello, Vasya!"; // Act object output1; object output2; int output3A; string output3B; using (var jsEngine = CreateJsEngine()) { jsEngine.Execute(initCode1); output1 = jsEngine.Evaluate(input1); jsEngine.Execute(initCode2); output2 = jsEngine.Evaluate(input2); jsEngine.Execute(initCode3); output3A = jsEngine.Evaluate <int>(input3A); output3B = jsEngine.Evaluate <string>(input3B); } // Assert Assert.Equal(targetOutput1, output1); Assert.Equal(targetOutput2, output2); Assert.Equal(targetOutput3A, output3A); Assert.Equal(targetOutput3B, output3B); }
private object VisitQuestion(Question question) { Value result = new Undefined(); if (question.IsComputed) { result = question.Expression.Accept(new ExpressionInterpreter(_context)); } _results.Add(question.Id.Name, result); return(null); }
public void TestEquals() { var d1 = new Undefined(); var d2 = new Undefined(); Assert.Equal(Bool.Undefined, d1 == d2); Assert.Equal(Bool.Undefined, d1 != d2); Assert.Equal(Bool.Undefined, Bool.True == d1); Assert.Equal(Bool.Undefined, Bool.False == d1); Assert.Equal(Bool.Undefined, d1 == Bool.True); Assert.Equal(Bool.Undefined, d1 == Bool.False); }
public override bool Equals(object other) { Undefined <T> o = other as Undefined <T>; if (o == null) { return(false); } if ((!this.IsDefined && o.IsDefined) || this.IsDefined && !o.IsDefined) { return(false); } return(this.Value.Equals(o.Value)); }
// ReSharper disable once UnusedMember.Local static Bool Runtime(QueryValue input) { if (Undefined.IsDefined(input)) { if (input?.ValueType != QueryValueType.Bool) { return(Bool.False); } return(Undefined.IsDefined((Bool)input.Value)); } return(Bool.Undefined); }
public bool TryGetUndefined(Span <byte> buffer, out Undefined value, out int consumedLength) { value = default; consumedLength = default; if (!TryDescribeData(buffer, out var type, out var length)) { return(false); } if (type != Amf0Type.Undefined) { return(false); } value = new Undefined(); consumedLength = Amf0CommonValues.MARKER_LENGTH; return(true); }
public void TestComparison() { var d1 = new Undefined(); var d2 = new Undefined(); Assert.Equal(Bool.Undefined, d1 < 12.34); Assert.Equal(Bool.Undefined, 12.34 < d1); Assert.Equal(Bool.Undefined, d1 < d2); Assert.Equal(Bool.Undefined, d1 > 12.34); Assert.Equal(Bool.Undefined, 12.34 > d1); Assert.Equal(Bool.Undefined, d1 > d2); Assert.Equal(Bool.Undefined, d1 <= 12.34); Assert.Equal(Bool.Undefined, 12.34 <= d1); Assert.Equal(Bool.Undefined, d1 <= d2); Assert.Equal(Bool.Undefined, d1 >= 12.34); Assert.Equal(Bool.Undefined, 12.34 >= d1); Assert.Equal(Bool.Undefined, d1 >= d2); }
public void TestArthimetic() { var d1 = new Undefined(); var d2 = new Undefined(); Assert.Equal(double.NaN, d1 + 12.34); Assert.Equal(double.NaN, 12.34 + d1); Assert.Equal(double.NaN, d1 + d2); Assert.Equal(double.NaN, d1 - 12.34); Assert.Equal(double.NaN, 12.34 - d1); Assert.Equal(double.NaN, d1 - d2); Assert.Equal(double.NaN, d1 * 4.0); Assert.Equal(double.NaN, 4.0 * d1); Assert.Equal(double.NaN, d1 * d2); Assert.Equal(double.NaN, d1 / 4.0); Assert.Equal(double.NaN, 4.0 / d1); Assert.Equal(double.NaN, d1 / d2); }
public void Visit(Undefined dataFormat, byte data) => Visit((None)null, data);
public bool Equals(Undefined other) { return !ReferenceEquals(null, other); }
public void TestTypes() { Assert.Equal(Bool.True, Undefined.IsDefined("undefined")); Assert.Equal(Bool.False, Undefined.IsDefined((string)Undefined.Instance)); }
static Bool RuntimeBool(Bool input) => Undefined.IsDefined(input);
static Bool RuntimeDouble(double input) => Undefined.IsDefined(input);
static Bool RuntimeQueryValue(QueryValue input) => Undefined.IsDefined(input);
// ReSharper disable once UnusedMember.Local static Bool Runtime(QueryValue input) { if (input?.ValueType != QueryValueType.Double) { return(Bool.False); } double inputValue = (double)input.Value; return((Bool)(!double.IsInfinity(inputValue) && !double.IsNaN(inputValue) && Undefined.IsDefined(inputValue))); }
// ReSharper disable once UnusedMember.Local static string Runtime(QueryValue[] input) { return(input.All(s => s?.ValueType == QueryValueType.String && Undefined.IsDefined((string)s.Value)) ? string.Concat(input.Select(_ => _.Value)) : Undefined.Instance); }
// ReSharper disable UnusedMember.Local static Bool RuntimeString(string input) => Undefined.IsDefined(input);
public void OnUndefined() { Undefined?.Invoke(this, EventArgs.Empty); }
public void Visit(Undefined dataFormat, byte data) { }
internal void OnUndefined(long Position, int RawOpCode) { Undefined?.Invoke(this, new AInstUndefinedEventArgs(Position, RawOpCode)); }
internal void OnUndefined(ulong address, int opCode) { Undefined?.Invoke(this, new InstUndefinedEventArgs(address, opCode)); }