jetma / jav8

Automatically exported from code.google.com/p/jav8
0 stars 0 forks source link

V8Array.to*Array() functions skips indexes with default values #31

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Get a V8Array object from the ScriptEngine
2. Call the toIntArray(int[], int) function with an existing array containing 
data other than all zeros

What is the expected output?
The java array passed in should contain a complete copy of the V8Array contents

What do you see instead?
Any index in the V8Array which is set to 0 does not get set in the existing 
array, therefore the arrays don't match after the operation.

What version of the product are you using? On what operating system?
The June 2013 version posted in the downloads section

Please provide any additional information below.
All of the V8Array.to...Array([], length) functions exhibit this problem.  The 
CPP code in jav8.cpp has the following condition which is causing the issue:

    if (value != 0) {
      data[i] = value;
    }

This is fine if the Java array being used is initialized to all zeros, but 
unexpected otherwise.

The workaround for now is to use Arrays.fill(myarray, 0) just before calling 
v8array.toIntArray(myarray, myarray.length).

Original issue reported on code.google.com by rje...@universalbits.com on 25 Oct 2014 at 3:40