Skip to content

Arrays are returned as TypedArray, but not converted back in v8ToJava #396

@MarcusSt

Description

@MarcusSt

After #358 arrays will be returned as the respective TypedArray, but v8ToJava is lacking the functionality to convert them back. Therefore really slow (may take several seconds for a few megabytes) workarounds are needed:

var jArr = java.newArray("byte", Array.prototype.slice.call(int8array))

Here's what I came up with (quick and possibly dirty – I don't know anything about v8) for Int8Array:

if (arg->IsInt8Array())
{
  v8::Local<v8::ArrayBuffer> ab = v8::Local<v8::TypedArray>::Cast(arg)->Buffer();

  jbyteArray result = env->NewByteArray(ab->GetContents().ByteLength());
  env->SetByteArrayRegion(result, 0, ab->GetContents().ByteLength(), (const jbyte *) ab->GetContents().Data());
  return(result);
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions