/// <summary> /// Value becomes (or is) rooted by the object. /// It's your responsibility to root it if you need it to outlive the object. /// </summary> public JS.Value this[uint index] { get { var temp = new Rooted <JS.Value>(Context); if (!JSAPI.GetElement(Context, Root, index, temp)) { throw new Exception("Operation failed"); } return(temp.Value); } set { var temp = new Rooted <JS.Value>(Context, value); if (!JSAPI.SetElement(Context, Root, index, temp)) { throw new Exception("Operation failed"); } } }
public unsafe void ArrayReadTest() { using (var tc = new TestContext()) { var evalResult = tc.Context.Evaluate(tc.Global, "[1, 2, 3, 4]"); var obj = evalResult.Value.AsObject; Assert.IsTrue(JSAPI.IsArrayObject(tc, &obj)); var arrayHandle = (JSHandleObject)evalResult; uint length; Assert.IsTrue(JSAPI.GetArrayLength(tc, arrayHandle, out length)); Assert.AreEqual(4, length); var elementRoot = new Rooted <JS.Value>(tc); Assert.IsTrue(JSAPI.GetElement(tc, arrayHandle, 0, elementRoot)); Assert.AreEqual(1, elementRoot.Value.ToManaged(tc)); Assert.IsTrue(JSAPI.GetElement(tc, arrayHandle, 3, elementRoot)); Assert.AreEqual(4, elementRoot.Value.ToManaged(tc)); } }