1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162 |
- using System;
- using Jint.Native.Object;
- using Jint.Runtime;
- using Jint.Runtime.Descriptors;
- namespace Jint.Native.String
- {
- public class StringInstance : ObjectInstance, IPrimitiveType
- {
- private readonly Engine _engine;
- public StringInstance(Engine engine)
- : base(engine)
- {
- _engine = engine;
- }
- public override string Class
- {
- get
- {
- return "String";
- }
- }
- Types IPrimitiveType.Type
- {
- get { return Types.Boolean; }
- }
- object IPrimitiveType.PrimitiveValue
- {
- get { return PrimitiveValue; }
- }
- public string PrimitiveValue { get; set; }
- public override PropertyDescriptor GetOwnProperty(string propertyName)
- {
- var desc = base.GetOwnProperty(propertyName);
- if (desc != PropertyDescriptor.Undefined)
- {
- return desc;
- }
- if (propertyName != System.Math.Abs(TypeConverter.ToInteger(propertyName)).ToString())
- {
- return PropertyDescriptor.Undefined;
- }
- var str = PrimitiveValue;
- var index = (int)TypeConverter.ToInteger(propertyName);
- var len = str.Length;
- if (len <= index)
- {
- return PropertyDescriptor.Undefined;
- }
- var resultStr = str[index].ToString();
- return new DataDescriptor(resultStr) {Enumerable = true, Writable = false, Configurable = false};
- }
- }
- }
|