本文整理汇总了C#中Jint.Native.JsObject类的典型用法代码示例。如果您正苦于以下问题:C# JsObject类的具体用法?C# JsObject怎么用?C# JsObject使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
JsObject类属于Jint.Native命名空间,在下文中一共展示了JsObject类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Concat
/// <summary>
/// 15.4.4.4
/// </summary>
/// <param name="target"></param>
/// <param name="parameters"></param>
/// <returns></returns>
public JsInstance Concat(JsObject target, JsInstance[] parameters)
{
if (target is JsArray)
return ((JsArray)target).concat(Global, parameters);
JsArray array = Global.ArrayClass.New();
List<JsInstance> items = new List<JsInstance>();
items.Add(target);
items.AddRange(parameters);
int n = 0;
while (items.Count > 0) {
JsInstance e = items[0];
items.RemoveAt(0);
if (Global.ArrayClass.HasInstance(e as JsObject)) {
for (int k = 0; k < ((JsObject)e).Length; k++) {
string p = k.ToString();
JsInstance result = null;
if (((JsObject)e).TryGetProperty(p, out result))
array.put(n, result);
n++;
}
}
else {
array.put(n, e);
n++;
}
}
return array;
}
示例2: DecodeURIComponent
public static object DecodeURIComponent(JintRuntime runtime, object @this, JsObject callee, object[] arguments)
{
if (arguments.Length < 1 || JsValue.IsUndefined(arguments[0]))
return String.Empty;
return Uri.UnescapeDataString(JsValue.ToString(arguments[0]).Replace("+", " "));
}
示例3: Constructor
// 15.2.2.1
public static object Constructor(JintRuntime runtime, object @this, JsObject callee, object[] arguments)
{
// TODO: This looks wrong. It looks like this should be returning
// a JsObject that has the value set to the parameter. Chrome returns
// 'object' for typeof(new Object(7)) and typeof(Object(7)).
if (arguments.Length > 0)
{
var argument = arguments[0];
var global = runtime.Global;
switch (argument.GetJsType())
{
case JsType.String: return global.CreateObject(argument, global.StringClass);
case JsType.Number: return global.CreateObject((double)argument, global.NumberClass);
case JsType.Boolean: return global.CreateObject(argument, global.BooleanClass);
default: return argument;
}
}
var obj = runtime.Global.CreateObject(callee.Prototype);
obj.DefineProperty(
Id.constructor,
callee,
PropertyAttributes.DontEnum
);
return obj;
}
示例4: MarshalAccessorProperty
public MarshalAccessorProperty(int index, JsObject getter, JsObject setter, PropertyAttributes attributes)
{
Index = index;
Getter = getter;
Setter = setter;
Attributes = attributes;
}
示例5: ShouldHandleDictionaryObjects
public void ShouldHandleDictionaryObjects() {
var dic = new JsObject();
dic["prop1"] = new JsNumber(1, JsNull.Instance);
Assert.IsTrue(dic.HasProperty(new JsString("prop1", JsNull.Instance)));
Assert.IsTrue(dic.HasProperty("prop1"));
Assert.AreEqual(1, dic["prop1"].ToNumber());
}
示例6: JsCallFunction
public JsCallFunction(JsFunctionConstructor constructor)
{
if (constructor != null)
Prototype = new JsObject() { Prototype = constructor.Prototype };
Prototype.DefineOwnProperty("length", new ValueDescriptor(Prototype, "length", constructor.Global.NumberClass.New(1)) { Writable = false });
}
示例7: JsFunction
/// <summary>
/// Init new function object with a specified prototype
/// </summary>
/// <param name="prototype">prototype for this object</param>
public JsFunction(JsObject prototype)
: base(prototype)
{
Arguments = new List<string>();
Statement = new EmptyStatement();
DefineOwnProperty(PROTOTYPE, JsNull.Instance, PropertyAttributes.DontEnum);
}
示例8: InitPrototype
public override void InitPrototype(IGlobal global)
{
Prototype = new JsObject() { Prototype = global.FunctionClass.Prototype };
Prototype.DefineOwnProperty("constructor", this, PropertyAttributes.DontEnum);
#region Methods
Prototype.DefineOwnProperty("toString", global.FunctionClass.New<JsArray>(ToStringImpl), PropertyAttributes.DontEnum);
Prototype.DefineOwnProperty("toLocaleString", global.FunctionClass.New<JsArray>(ToLocaleStringImpl), PropertyAttributes.DontEnum);
Prototype.DefineOwnProperty("concat", global.FunctionClass.New<JsObject>(Concat), PropertyAttributes.DontEnum);
Prototype.DefineOwnProperty("join", global.FunctionClass.New<JsObject>(Join, 1), PropertyAttributes.DontEnum);
Prototype.DefineOwnProperty("pop", global.FunctionClass.New<JsObject>(Pop), PropertyAttributes.DontEnum);
Prototype.DefineOwnProperty("push", global.FunctionClass.New<JsObject>(Push, 1), PropertyAttributes.DontEnum);
Prototype.DefineOwnProperty("reverse", global.FunctionClass.New<JsObject>(Reverse), PropertyAttributes.DontEnum);
Prototype.DefineOwnProperty("shift", global.FunctionClass.New<JsObject>(Shift), PropertyAttributes.DontEnum);
Prototype.DefineOwnProperty("slice", global.FunctionClass.New<JsObject>(Slice, 2), PropertyAttributes.DontEnum);
Prototype.DefineOwnProperty("sort", global.FunctionClass.New<JsObject>(Sort), PropertyAttributes.DontEnum);
Prototype.DefineOwnProperty("splice", global.FunctionClass.New<JsObject>(Splice, 2), PropertyAttributes.DontEnum);
Prototype.DefineOwnProperty("unshift", global.FunctionClass.New<JsObject>(UnShift, 1), PropertyAttributes.DontEnum);
#region ES5
Prototype.DefineOwnProperty("indexOf", global.FunctionClass.New<JsObject>(IndexOfImpl, 1), PropertyAttributes.DontEnum);
Prototype.DefineOwnProperty("lastIndexOf", global.FunctionClass.New<JsObject>(LastIndexOfImpl, 1), PropertyAttributes.DontEnum);
#endregion
#endregion
}
示例9: Constructor
public static object Constructor(JintRuntime runtime, object @this, JsObject callee, object[] arguments)
{
var target = (JsObject)@this;
if (target == runtime.Global.GlobalScope)
target = runtime.Global.CreateObject(callee.Prototype);
string pattern = null;
string options = null;
if (arguments.Length > 0)
{
pattern = JsValue.ToString(arguments[0]);
if (arguments.Length > 1)
options = JsValue.ToString(arguments[1]);
}
var manager = new RegexManager(pattern, options);
target.SetClass(JsNames.ClassRegexp);
target.IsClr = false;
target.Value = manager;
target.SetProperty(Id.source, pattern);
target.SetProperty(Id.lastIndex, (double)0);
target.SetProperty(Id.global, BooleanBoxes.Box(manager.IsGlobal));
return target;
}
示例10: Exec
public static object Exec(JintRuntime runtime, object @this, JsObject callee, object[] arguments)
{
var target = (JsObject)@this;
var manager = (RegexManager)target.Value;
return (object)manager.Exec(runtime, JsValue.ToString(arguments[0])) ?? JsNull.Instance;
}
示例11: CreateError
public JsObject CreateError(JsObject constructor, string message)
{
return constructor.Construct(
_runtime,
new[] { (object)message }
);
}
示例12: Call
public static object Call(JintRuntime runtime, object @this, JsObject callee, object[] arguments)
{
if (!JsValue.IsFunction(@this))
throw new JsException(JsErrorType.TypeError, "The target of call() must be a function");
object target;
if (arguments.Length >= 1 && !JsValue.IsNullOrUndefined(arguments[0]))
target = arguments[0];
else
target = runtime.GlobalScope;
object[] argumentsCopy;
if (arguments.Length >= 2 && !JsValue.IsNull(arguments[1]))
{
argumentsCopy = new object[arguments.Length - 1];
Array.Copy(arguments, 1, argumentsCopy, 0, argumentsCopy.Length);
}
else
{
argumentsCopy = JsValue.EmptyArray;
}
// Executes the statements in 'that' and use _this as the target of the call
return ((JsObject)@this).Execute(runtime, target, argumentsCopy);
}
示例13: Apply
public static object Apply(JintRuntime runtime, object @this, JsObject callee, object[] arguments)
{
if (!JsValue.IsFunction(@this))
throw new ArgumentException("The target of call() must be a function");
object target;
if (arguments.Length >= 1 && !JsValue.IsNullOrUndefined(arguments[0]))
target = arguments[0];
else
target = runtime.Global.GlobalScope;
object[] argumentsCopy;
if (arguments.Length >= 2)
{
var shim = new ArrayShim(arguments[1]);
argumentsCopy = new object[shim.Length];
foreach (var item in shim)
{
argumentsCopy[item.Key] = item.Value;
}
}
else
{
argumentsCopy = JsValue.EmptyArray;
}
// Executes the statements in 'that' and use _this as the target of the call
return ((JsObject)@this).Execute(runtime, target, argumentsCopy);
}
示例14: NativeMethodOverload
public NativeMethodOverload(ICollection<MethodInfo> methods , JsObject prototype, IGlobal global)
: base(prototype)
{
if (global == null)
throw new ArgumentNullException("global");
m_marshaller = global.Marshaller;
foreach (MethodInfo info in methods)
{
Name = info.Name;
break;
}
foreach (var method in methods)
{
if (method.IsGenericMethodDefinition)
m_generics.AddLast(method);
else if (! method.ContainsGenericParameters)
m_methods.AddLast(method);
}
m_overloads = new NativeOverloadImpl<MethodInfo, JsMethodImpl>(
m_marshaller,
new NativeOverloadImpl<MethodInfo, JsMethodImpl>.GetMembersDelegate(this.GetMembers),
new NativeOverloadImpl<MethodInfo, JsMethodImpl>.WrapMmemberDelegate(this.WrapMember)
);
}
示例15: PropertyAccessor
public PropertyAccessor(JsObject getter, JsObject setter)
{
if (getter == null)
throw new ArgumentNullException("getter");
Getter = getter;
Setter = setter;
}