本文整理汇总了C#中JsValue.At方法的典型用法代码示例。如果您正苦于以下问题:C# JsValue.At方法的具体用法?C# JsValue.At怎么用?C# JsValue.At使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类JsValue
的用法示例。
在下文中一共展示了JsValue.At方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Call
public JsValue Call(JsValue thisObject, JsValue[] arguments)
{
// direct calls on a NamespaceReference constructor object is creating a generic type
var genericTypes = new Type[arguments.Length];
for (int i = 0; i < arguments.Length; i++)
{
var genericTypeReference = arguments.At(i);
if (genericTypeReference == Undefined.Instance || !genericTypeReference.IsObject() || genericTypeReference.AsObject().Class != "TypeReference")
{
throw new JavaScriptException(Engine.TypeError, "Invalid generic type parameter");
}
genericTypes[i] = arguments.At(0).As<TypeReference>().Type;
}
var typeReference = GetPath(_path + "`" + arguments.Length.ToString(CultureInfo.InvariantCulture)).As<TypeReference>();
if (typeReference == null)
{
return Undefined.Instance;
}
var genericType = typeReference.Type.MakeGenericType(genericTypes);
return TypeReference.CreateTypeReference(Engine, genericType);
}
示例2: Call
public override JsValue Call(JsValue thisObject, JsValue[] arguments)
{
var pattern = arguments.At(0);
var flags = arguments.At(1);
if (pattern != Undefined.Instance && flags == Undefined.Instance && TypeConverter.ToObject(Engine, pattern).Class == "Regex")
{
return pattern;
}
return Construct(arguments);
}
示例3: Construct
public ObjectInstance Construct(JsValue[] arguments)
{
var instance = new ErrorInstance(Engine, _name);
instance.Prototype = PrototypeObject;
instance.Extensible = true;
if (arguments.At(0) != Undefined.Instance)
{
instance.Put("message", TypeConverter.ToString(arguments.At(0)), false);
}
return instance;
}
示例4: Bind
private JsValue Bind(JsValue thisObj, JsValue[] arguments)
{
var target = thisObj.TryCast<ICallable>(x =>
{
throw new JavaScriptException(Engine.TypeError);
});
var thisArg = arguments.At(0);
var f = new BindFunctionInstance(Engine) {Extensible = true};
f.TargetFunction = thisObj;
f.BoundThis = thisArg;
f.BoundArgs = arguments.Skip(1).ToArray();
f.Prototype = Engine.Function.PrototypeObject;
var o = target as FunctionInstance;
if (o != null)
{
var l = TypeConverter.ToNumber(o.Get("length")) - (arguments.Length - 1);
f.FastAddProperty("length", System.Math.Max(l, 0), false, false, false);
}
else
{
f.FastAddProperty("length", 0, false, false, false);
}
var thrower = Engine.Function.ThrowTypeError;
f.DefineOwnProperty("caller", new PropertyDescriptor(thrower, thrower, false, false), false);
f.DefineOwnProperty("arguments", new PropertyDescriptor(thrower, thrower, false, false), false);
return f;
}
示例5: Parse
private JsValue Parse(JsValue thisObj, JsValue[] arguments)
{
DateTime result;
var date = TypeConverter.ToString(arguments.At(0));
if (!DateTime.TryParseExact(date, new[]
{
"yyyy-MM-ddTHH:mm:ss.FFF",
"yyyy-MM-ddTHH:mm:ss",
"yyyy-MM-ddTHH:mm",
"yyyy-MM-dd",
"yyyy-MM",
"yyyy"
}, CultureInfo.InvariantCulture, DateTimeStyles.AdjustToUniversal | DateTimeStyles.AssumeUniversal, out result))
{
if (!DateTime.TryParseExact(date, new[]
{
// Formats used in DatePrototype toString methods
"ddd MMM dd yyyy HH:mm:ss 'GMT'K",
"ddd MMM dd yyyy",
"HH:mm:ss 'GMT'K",
// standard formats
"yyyy-M-dTH:m:s.FFFK",
"yyyy/M/dTH:m:s.FFFK",
"yyyy-M-dTH:m:sK",
"yyyy/M/dTH:m:sK",
"yyyy-M-dTH:mK",
"yyyy/M/dTH:mK",
"yyyy-M-d H:m:s.FFFK",
"yyyy/M/d H:m:s.FFFK",
"yyyy-M-d H:m:sK",
"yyyy/M/d H:m:sK",
"yyyy-M-d H:mK",
"yyyy/M/d H:mK",
"yyyy-M-dK",
"yyyy/M/dK",
"yyyy-MK",
"yyyy/MK",
"yyyyK",
"THH:mm:ss.FFFK",
"THH:mm:ssK",
"THH:mmK",
"THHK"
}, CultureInfo.InvariantCulture, DateTimeStyles.AdjustToUniversal, out result))
{
if (!DateTime.TryParse(date, Engine.Options.GetCulture(), DateTimeStyles.AdjustToUniversal, out result))
{
if (!DateTime.TryParse(date, CultureInfo.InvariantCulture, DateTimeStyles.AdjustToUniversal, out result))
{
// unrecognized dates should return NaN (15.9.4.2)
return double.NaN;
}
}
}
}
return FromDateTime(result);
}
示例6: ParseInt
/// <summary>
/// http://www.ecma-international.org/ecma-262/5.1/#sec-15.1.2.2
/// </summary>
public static JsValue ParseInt(JsValue thisObject, JsValue[] arguments)
{
string inputString = TypeConverter.ToString(arguments.At(0));
var s = inputString.Trim();
var sign = 1;
if (!System.String.IsNullOrEmpty(s))
{
if (s[0] == '-')
{
sign = -1;
}
if (s[0] == '-' || s[0] == '+')
{
s = s.Substring(1);
}
}
var stripPrefix = true;
int radix = arguments.Length > 1 ? TypeConverter.ToInt32(arguments[1]) : 0;
if (radix == 0)
{
if (s.Length >= 2 && s.StartsWith("0x") || s.StartsWith("0X"))
{
radix = 16;
}
else
{
radix = 10;
}
}
else if (radix < 2 || radix > 36)
{
return double.NaN;
}
else if(radix != 16)
{
stripPrefix = false;
}
if (stripPrefix && s.Length >= 2 && s.StartsWith("0x") || s.StartsWith("0X"))
{
s = s.Substring(2);
}
try
{
return sign * Parse(s, radix).AsNumber();
}
catch
{
return double.NaN;
}
}
示例7: IsArray
private JsValue IsArray(JsValue thisObj, JsValue[] arguments)
{
if (arguments.Length == 0)
{
return false;
}
var o = arguments.At(0);
return o.IsObject() && o.AsObject().Class == "Array";
}
示例8: Construct
public ObjectInstance Construct(JsValue[] arguments)
{
var instance = new ArrayInstance(Engine);
instance.Prototype = PrototypeObject;
instance.Extensible = true;
if (arguments.Length == 1 && arguments.At(0).IsNumber())
{
var length = TypeConverter.ToUint32(arguments.At(0));
if (!TypeConverter.ToNumber(arguments[0]).Equals(length))
{
throw new JavaScriptException(Engine.RangeError, "Invalid array length");
}
instance.FastAddProperty("length", length, true, false, false);
}
else if (arguments.Length == 1 && arguments.At(0).IsObject() && arguments.At(0).As<ObjectWrapper>() != null)
{
var enumerable = arguments.At(0).As<ObjectWrapper>().Target as IEnumerable;
if (enumerable != null)
{
var jsArray = Engine.Array.Construct(Arguments.Empty);
foreach (var item in enumerable)
{
var jsItem = JsValue.FromObject(Engine, item);
Engine.Array.PrototypeObject.Push(jsArray, Arguments.From(jsItem));
}
return jsArray;
}
}
else
{
instance.FastAddProperty("length", 0, true, false, false);
PrototypeObject.Push(instance, arguments);
}
return instance;
}
示例9: Parse
private JsValue Parse(JsValue thisObj, JsValue[] arguments)
{
DateTime result;
var date = TypeConverter.ToString(arguments.At(0));
if (!DateTime.TryParseExact(date, new[]
{
"yyyy-MM-ddTHH:mm:ss.FFF",
"yyyy-MM-ddTHH:mm:ss",
"yyyy-MM-ddTHH:mm",
"yyyy-MM-dd",
"yyyy-MM",
"yyyy"
}, CultureInfo.InvariantCulture, DateTimeStyles.AdjustToUniversal | DateTimeStyles.AssumeUniversal, out result))
{
if (!DateTime.TryParseExact(date, new[]
{
"yyyy-M-dTH:m:s.FFFK",
"yyyy/M/dTH:m:s.FFFK",
"yyyy-M-dTH:m:sK",
"yyyy/M/dTH:m:sK",
"yyyy-M-dTH:mK",
"yyyy/M/dTH:mK",
"yyyy-M-d H:m:s.FFFK",
"yyyy/M/d H:m:s.FFFK",
"yyyy-M-d H:m:sK",
"yyyy/M/d H:m:sK",
"yyyy-M-d H:mK",
"yyyy/M/d H:mK",
"yyyy-M-dK",
"yyyy/M/dK",
"yyyy-MK",
"yyyy/MK",
"yyyyK",
"THH:mm:ss.FFFK",
"THH:mm:ssK",
"THH:mmK",
"THHK"
}, CultureInfo.InvariantCulture, DateTimeStyles.AdjustToUniversal, out result))
{
if (!DateTime.TryParse(date, CultureInfo.InvariantCulture, DateTimeStyles.AdjustToUniversal,out result))
{
// unrecognized dates should return NaN (15.9.4.2)
return double.NaN;
}
}
}
return FromDateTime(result);
}
示例10: Parse
private JsValue Parse(JsValue thisObj, JsValue[] arguments)
{
DateTime result;
var date = TypeConverter.ToString(arguments.At(0));
if (!DateTime.TryParseExact(date, new[]
{
"yyyy-MM-ddTHH:mm:ss.FFF",
"yyyy-MM-ddTHH:mm:ss",
"yyyy-MM-ddTHH:mm",
"yyyy-MM-dd",
"yyyy-MM",
"yyyy"
}, CultureInfo.InvariantCulture, DateTimeStyles.AssumeUniversal, out result))
{
if (!DateTime.TryParseExact(date, new[]
{
"yyyy-M-dTH:m:s.FFFK",
"yyyy/M/dTH:m:s.FFFK",
"yyyy-M-dTH:m:sK",
"yyyy/M/dTH:m:sK",
"yyyy-M-dTH:mK",
"yyyy/M/dTH:mK",
"yyyy-M-d H:m:s.FFFK",
"yyyy/M/d H:m:s.FFFK",
"yyyy-M-d H:m:sK",
"yyyy/M/d H:m:sK",
"yyyy-M-d H:mK",
"yyyy/M/d H:mK",
"yyyy-M-dK",
"yyyy/M/dK",
"yyyy-MK",
"yyyy/MK",
"yyyyK",
"THH:mm:ss.FFFK",
"THH:mm:ssK",
"THH:mmK",
"THHK"
}, CultureInfo.InvariantCulture, DateTimeStyles.AdjustToUniversal, out result))
{
if (!DateTime.TryParse(date, CultureInfo.InvariantCulture, DateTimeStyles.AdjustToUniversal,out result))
{
throw new JavaScriptException(Engine.SyntaxError, "Invalid date");
}
}
}
return FromDateTime(result);
}
示例11: LastIndexOf
private JsValue LastIndexOf(JsValue thisObj, JsValue[] arguments)
{
var o = TypeConverter.ToObject(Engine, thisObj);
var lenValue = o.Get("length");
var len = TypeConverter.ToUint32(lenValue);
if (len == 0)
{
return -1;
}
var n = arguments.Length > 1 ? TypeConverter.ToInteger(arguments[1]) : len - 1;
double k;
if (n >= 0)
{
k = System.Math.Min(n, len - 1); // min
}
else
{
k = len - System.Math.Abs(n);
}
var searchElement = arguments.At(0);
for (; k >= 0; k--)
{
var kString = TypeConverter.ToString(k);
var kPresent = o.HasProperty(kString);
if (kPresent)
{
var elementK = o.Get(kString);
var same = ExpressionInterpreter.StrictlyEqual(elementK, searchElement);
if (same)
{
return k;
}
}
}
return -1;
}
示例12: Splice
private JsValue Splice(JsValue thisObj, JsValue[] arguments)
{
var start = arguments.At(0);
var deleteCount = arguments.At(1);
var o = TypeConverter.ToObject(Engine, thisObj);
var a = Engine.Array.Construct(Arguments.Empty);
var lenVal = o.Get("length");
var len = TypeConverter.ToUint32(lenVal);
var relativeStart = TypeConverter.ToInteger(start);
uint actualStart;
if (relativeStart < 0)
{
actualStart = (uint)System.Math.Max(len + relativeStart, 0);
}
else
{
actualStart = (uint)System.Math.Min(relativeStart, len);
}
var actualDeleteCount = System.Math.Min(System.Math.Max(TypeConverter.ToInteger(deleteCount), 0), len - actualStart);
for (var k = 0; k < actualDeleteCount; k++)
{
var from = (actualStart + k).ToString();
var fromPresent = o.HasProperty(from);
if (fromPresent)
{
var fromValue = o.Get(from);
a.DefineOwnProperty(k.ToString(), new PropertyDescriptor(fromValue, true, true, true), false);
}
}
var items = arguments.Skip(2).ToArray();
if (items.Length < actualDeleteCount)
{
for (var k = actualStart; k < len - actualDeleteCount; k++)
{
var from = (k + actualDeleteCount).ToString();
var to = (k + items.Length).ToString();
var fromPresent = o.HasProperty(from);
if (fromPresent)
{
var fromValue = o.Get(from);
o.Put(to, fromValue, true);
}
else
{
o.Delete(to, true);
}
}
for (var k = len; k > len - actualDeleteCount + items.Length; k-- )
{
o.Delete((k - 1).ToString(), true);
}
}
else if (items.Length > actualDeleteCount)
{
for (var k = len - actualDeleteCount; k > actualStart; k--)
{
var from = (k + actualDeleteCount - 1).ToString();
var to = (k + items.Length - 1).ToString();
var fromPresent = o.HasProperty(from);
if (fromPresent)
{
var fromValue = o.Get(from);
o.Put(to, fromValue, true);
}
else
{
o.Delete(to, true);
}
}
}
for(var k = 0; k< items.Length; k++)
{
var e = items[k];
o.Put((k+actualStart).ToString(), e, true);
}
o.Put("length", len - actualDeleteCount + items.Length, true);
return a;
}
示例13: Sort
private JsValue Sort(JsValue thisObj, JsValue[] arguments)
{
if (!thisObj.IsObject())
{
throw new JavaScriptException(Engine.TypeError, "Array.prorotype.sort can only be applied on objects");
}
var obj = thisObj.AsObject();
var len = obj.Get("length");
var lenVal = TypeConverter.ToInt32(len);
if (lenVal <= 1)
{
return obj;
}
var compareArg = arguments.At(0);
ICallable compareFn = null;
if (compareArg != Undefined.Instance)
{
compareFn = compareArg.TryCast<ICallable>(x =>
{
throw new JavaScriptException(Engine.TypeError, "The sort argument must be a function");
});
}
Comparison<JsValue> comparer = (x, y) =>
{
if (x == Undefined.Instance && y == Undefined.Instance)
{
return 0;
}
if (x == Undefined.Instance)
{
return 1;
}
if (y == Undefined.Instance)
{
return -1;
}
if (compareFn != null)
{
var s = (int) TypeConverter.ToUint32(compareFn.Call(Undefined.Instance, new[] {x, y}));
return s;
}
var xString = TypeConverter.ToString(x);
var yString = TypeConverter.ToString(y);
var r = System.String.CompareOrdinal(xString, yString);
return r;
};
var array = Enumerable.Range(0, lenVal).Select(i => obj.Get(i.ToString())).ToArray();
// don't eat inner exceptions
try
{
System.Array.Sort(array, comparer);
}
catch (InvalidOperationException e)
{
throw e.InnerException;
}
foreach (var i in Enumerable.Range(0, lenVal))
{
obj.Put(i.ToString(), array[i], false);
}
return obj;
}
示例14: Map
private JsValue Map(JsValue thisObj, JsValue[] arguments)
{
var callbackfn = arguments.At(0);
var thisArg = arguments.At(1);
var o = TypeConverter.ToObject(Engine, thisObj);
var lenValue = o.Get("length");
var len = TypeConverter.ToUint32(lenValue);
var callable = callbackfn.TryCast<ICallable>(x =>
{
throw new JavaScriptException(Engine.TypeError, "Argument must be callable");
});
var a = Engine.Array.Construct(new JsValue[] {len});
for (var k = 0; k < len; k++)
{
var pk = k.ToString();
var kpresent = o.HasProperty(pk);
if (kpresent)
{
var kvalue = o.Get(pk);
var mappedValue = callable.Call(thisArg, new [] { kvalue, k, o });
a.DefineOwnProperty(pk, new PropertyDescriptor(mappedValue, true, true, true), false);
}
}
return a;
}
示例15: Every
private JsValue Every(JsValue thisObj, JsValue[] arguments)
{
var callbackfn = arguments.At(0);
var thisArg = arguments.At(1);
var o = TypeConverter.ToObject(Engine, thisObj);
var lenValue = o.Get("length");
var len = TypeConverter.ToUint32(lenValue);
var callable = callbackfn.TryCast<ICallable>(x =>
{
throw new JavaScriptException(Engine.TypeError, "Argument must be callable");
});
for (var k = 0; k < len; k++)
{
var pk = k.ToString();
var kpresent = o.HasProperty(pk);
if (kpresent)
{
var kvalue = o.Get(pk);
var testResult = callable.Call(thisArg, new [] { kvalue, k, o });
if (false == TypeConverter.ToBoolean(testResult))
{
return JsValue.False;
}
}
}
return JsValue.True;
}