Java calling JS with Rhino (Uint8Array is not defined)

I'm trying to use the Rhino lib to call some javascript from java code. But it seems that it is choking on a typed array. Here is my simple js file

function decrypt(version, iv, encryptedBuffer) {
    var output8;
    output8 = new Uint8Array(encryptedBuffer);
    var outputBuffer = output8.buffer;
    var output32 = new Int32Array(outputBuffer);
    ... more funny code

But when calling, scope, scope, params);

I get this ReferenceError: "Uint8Array" is not defined. (JavaScript#5680)

Is there something extra to configure to have my little js snippet run ?



Have you set setLanguageVersion(Context.VERSION_ES6)? Typed Array is new Javascript feature. Rhino does not allow Typed array call in old js versions.


Try to use classes from package org.mozilla.javascript.typedarrays:


var decrypt = function(version, iv, encryptedBuffer, off, len) {
    var output8 = new NativeUint8Array(encryptedBuffer,off,len);
    var outputBuffer = output8.buffer;
    var output32 = new NativeInt32Array(outputBuffer,off,len);
    //... more funny code

var encryptedBuffer = new NativeArrayBuffer(1024);


Recent Questions

Top Questions

Home Tags Terms of Service Privacy Policy DMCA Contact Us

©2020 All rights reserved.