Example usage for jdk.nashorn.api.scripting ScriptObjectMirror setIndexedPropertiesToExternalArrayData

List of usage examples for jdk.nashorn.api.scripting ScriptObjectMirror setIndexedPropertiesToExternalArrayData

Introduction

In this page you can find the example usage for jdk.nashorn.api.scripting ScriptObjectMirror setIndexedPropertiesToExternalArrayData.

Prototype

public void setIndexedPropertiesToExternalArrayData(final ByteBuffer buf) 

Source Link

Document

Nashorn extension: setIndexedPropertiesToExternalArrayData.

Usage

From source file:com.mckoi.mwpui.nodejs.nashorn.NashornJSSystem.java

License:Open Source License

@Override
public ByteBuffer allocateExternalArrayDataOf(GJSObject source, int alloc_size) {

    ScriptObjectMirror nashorn_ob = (ScriptObjectMirror) source.internalGetNative();
    // Allocate the buffer,
    ByteBuffer bb = ByteBuffer.allocate(alloc_size);
    // We use the unwrapped nashorn object as a key,
    ScriptObject script_ob = (ScriptObject) instance_global.unwrap(nashorn_ob);

    // The ByteBuffer property should be read only,
    int ro_flags = Property.NOT_WRITABLE | Property.NOT_ENUMERABLE | Property.NOT_CONFIGURABLE;

    script_ob.addOwnProperty(BYTEBUFFER_OBJECT_PROPERTY_NAME, ro_flags, bb);
    nashorn_ob.setIndexedPropertiesToExternalArrayData(bb);
    return bb;//from  ww  w.  java  2 s.  c o  m
}