本文整理汇总了C#中Jint.Native.JsObject.DefineProperty方法的典型用法代码示例。如果您正苦于以下问题:C# JsObject.DefineProperty方法的具体用法?C# JsObject.DefineProperty怎么用?C# JsObject.DefineProperty使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Jint.Native.JsObject
的用法示例。
在下文中一共展示了JsObject.DefineProperty方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ToPropertyDescriptor
/// <summary>
/// 8.10.5
/// </summary>
private static void ToPropertyDescriptor(JsGlobal global, JsObject owner, string name, object value)
{
var @object = value as JsObject;
if (@object == null)
throw new JsException(JsErrorType.TypeError, "The target object has to be an instance of an object");
if (
(@object.HasProperty(Id.value) || @object.HasProperty(Id.writable)) &&
(@object.HasProperty(Id.set) || @object.HasProperty(Id.get))
)
throw new JsException(JsErrorType.TypeError, "The property cannot be both writable and have get/set accessors or cannot have both a value and an accessor defined");
var attributes = PropertyAttributes.None;
JsObject getFunction = null;
JsObject setFunction = null;
object result;
if (
@object.TryGetProperty(Id.enumerable, out result) &&
!JsValue.ToBoolean(result)
)
attributes |= PropertyAttributes.DontEnum;
if (
@object.TryGetProperty(Id.configurable, out result) &&
!JsValue.ToBoolean(result)
)
attributes |= PropertyAttributes.DontDelete;
if (
@object.TryGetProperty(Id.writable, out result) &&
!JsValue.ToBoolean(result)
)
attributes |= PropertyAttributes.ReadOnly;
if (@object.TryGetProperty(Id.get, out result))
{
if (!JsValue.IsFunction(result))
throw new JsException(JsErrorType.TypeError, "The getter has to be a function");
getFunction = (JsObject)result;
}
if (@object.TryGetProperty(Id.set, out result))
{
if (!JsValue.IsFunction(result))
throw new JsException(JsErrorType.TypeError, "The setter has to be a function");
setFunction = (JsObject)result;
}
if (@object.HasProperty(Id.value))
{
owner.DefineProperty(
global.ResolveIdentifier(name),
@object.GetProperty(Id.value),
PropertyAttributes.None
);
}
else
{
owner.DefineAccessor(
global.ResolveIdentifier(name),
getFunction,
setFunction,
attributes
);
}
}
示例2: BuildObjectClass
private JsObject BuildObjectClass(JsObject prototype)
{
prototype.DefineProperty(Id.toString, ObjectFunctions.ToString, 0, PropertyAttributes.DontEnum);
prototype.DefineProperty(Id.toLocaleString, ObjectFunctions.ToString, 0, PropertyAttributes.DontEnum);
prototype.DefineProperty(Id.valueOf, ObjectFunctions.ValueOf, 0, PropertyAttributes.DontEnum);
prototype.DefineProperty(Id.hasOwnProperty, ObjectFunctions.HasOwnProperty, 1, PropertyAttributes.DontEnum);
prototype.DefineProperty(Id.isPrototypeOf, ObjectFunctions.IsPrototypeOf, 1, PropertyAttributes.DontEnum);
prototype.DefineProperty(Id.propertyIsEnumerable, ObjectFunctions.PropertyIsEnumerable, 1, PropertyAttributes.DontEnum);
prototype.DefineProperty(Id.getPrototypeOf, ObjectFunctions.GetPrototypeOf, 1, PropertyAttributes.DontEnum);
prototype.DefineProperty(Id.defineProperty, ObjectFunctions.DefineProperty, 1, PropertyAttributes.DontEnum);
prototype.DefineProperty(Id.__lookupGetter__, ObjectFunctions.LookupGetter, 1, PropertyAttributes.DontEnum);
prototype.DefineProperty(Id.__lookupSetter__, ObjectFunctions.LookupSetter, 1, PropertyAttributes.DontEnum);
return CreateNakedFunction("Object", ObjectFunctions.Constructor, 0, prototype);
}