Java Code Examples for org.mozilla.javascript.ScriptableObject#setExternalArrayData()

The following examples show how to use org.mozilla.javascript.ScriptableObject#setExternalArrayData() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ExternalArrayTest.java    From rhino-android with Apache License 2.0 5 votes vote down vote up
@Test
public void testIntArray()
{
    ScriptableObject a = (ScriptableObject)cx.newObject(root);
    TestIntArray l = new TestIntArray(10);
    a.setExternalArrayData(l);
    for (int i = 0; i < 10; i++) {
        l.setArrayElement(i, i);
    }
    root.put("testArray", root, a);
    root.put("testArrayLength", root, 10);
    root.put("regularArray", root, false);
    runScript("jstests/extensions/external-array-test.js", 1);
}
 
Example 2
Source File: ExternalArrayTest.java    From rhino-android with Apache License 2.0 5 votes vote down vote up
@Test
public void testIntArrayThenRemove()
{
    ScriptableObject a = (ScriptableObject)cx.newObject(root);
    // Set the external array data
    TestIntArray l = new TestIntArray(10);
    a.setExternalArrayData(l);
    for (int i = 0; i < 10; i++) {
        l.setArrayElement(i, i);
    }
    root.put("testArray", root, a);
    root.put("testArrayLength", root, 10);
    root.put("regularArray", root, false);
    runScript("jstests/extensions/external-array-test.js", 1);

    // Clear it and test again. When cleared, object should go back to behaving like a
    // regular JavaScript object.
    a.delete("stringField");
    a.delete("intField");
    a.setExternalArrayData(null);
    for (int i = 0; i < 10; i++) {
        a.put(i, a, i);
    }
    a.defineProperty("length", 10, ScriptableObject.DONTENUM);
    root.put("regularArray", root, true);
    runScript("jstests/extensions/external-array-test.js", 1);
}
 
Example 3
Source File: ExternalArrayTest.java    From rhino-android with Apache License 2.0 5 votes vote down vote up
@Test
public void testNativeIntArray()
{
    ScriptableObject a = (ScriptableObject)cx.newObject(root);
    NativeInt32Array l = new NativeInt32Array(10);
    a.setExternalArrayData(l);

    root.put("testArray", root, a);
    root.put("testArrayLength", root, 10);
    root.put("regularArray", root, false);
    runScript("testsrc/jstests/extensions/external-array-test.js", 1);
}
 
Example 4
Source File: ExternalArrayTest.java    From rhino-android with Apache License 2.0 5 votes vote down vote up
@Test
public void testNativeShortArray()
{
    ScriptableObject a = (ScriptableObject)cx.newObject(root);
    NativeInt16Array l = new NativeInt16Array(10);
    a.setExternalArrayData(l);

    root.put("testArray", root, a);
    root.put("testArrayLength", root, 10);
    root.put("regularArray", root, false);
    runScript("jstests/extensions/external-array-test.js", 1);
}
 
Example 5
Source File: ExternalArrayTest.java    From rhino-android with Apache License 2.0 5 votes vote down vote up
@Test
public void testNativeDoubleArray()
{
    ScriptableObject a = (ScriptableObject)cx.newObject(root);
    NativeFloat64Array l = new NativeFloat64Array(10);
    a.setExternalArrayData(l);

    root.put("testArray", root, a);
    root.put("testArrayLength", root, 10);
    root.put("regularArray", root, false);
    runScript("jstests/extensions/external-array-test.js", 1);
}