android: compat webviewexecutor to support arraybuffer
This commit is contained in:
@@ -0,0 +1,23 @@
|
||||
package com.github.pengfeizhou.jscore;
|
||||
|
||||
public class JSArrayBuffer extends JSValue {
|
||||
private final byte[] mVal;
|
||||
|
||||
public JSArrayBuffer(byte[] val) {
|
||||
this.mVal = val;
|
||||
}
|
||||
|
||||
public int getByteLength() {
|
||||
return mVal.length;
|
||||
}
|
||||
|
||||
@Override
|
||||
public JSType getJSType() {
|
||||
return JSType.ArrayBuffer;
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] value() {
|
||||
return mVal;
|
||||
}
|
||||
}
|
@@ -25,6 +25,7 @@ public abstract class JSValue {
|
||||
String,
|
||||
Object,
|
||||
Array,
|
||||
ArrayBuffer,
|
||||
}
|
||||
|
||||
public abstract JSType getJSType();
|
||||
@@ -55,6 +56,10 @@ public abstract class JSValue {
|
||||
return getJSType() == JSType.Array;
|
||||
}
|
||||
|
||||
public boolean isArrayBuffer() {
|
||||
return getJSType() == JSType.ArrayBuffer;
|
||||
}
|
||||
|
||||
public JSNull asNull() {
|
||||
return (JSNull) this;
|
||||
}
|
||||
@@ -79,6 +84,10 @@ public abstract class JSValue {
|
||||
return (JSArray) this;
|
||||
}
|
||||
|
||||
public JSArrayBuffer asArrayBuffer() {
|
||||
return (JSArrayBuffer) this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return String.valueOf(value());
|
||||
|
@@ -25,10 +25,14 @@ public class JavaValue {
|
||||
protected static final int TYPE_STRING = 3;
|
||||
protected static final int TYPE_OBJECT = 4;
|
||||
protected static final int TYPE_ARRAY = 5;
|
||||
protected static final int TYPE_ARRAYBUFFER = 6;
|
||||
|
||||
protected JavaFunction[] functions = null;
|
||||
protected String[] functionNames = null;
|
||||
protected int type;
|
||||
protected String value = "";
|
||||
protected byte[] data = null;
|
||||
protected MemoryReleaser memoryReleaser = null;
|
||||
|
||||
public JavaValue() {
|
||||
this.type = TYPE_NULL;
|
||||
@@ -75,6 +79,17 @@ public class JavaValue {
|
||||
this.value = jsonArray.toString();
|
||||
}
|
||||
|
||||
public JavaValue(byte[] data) {
|
||||
this.type = TYPE_ARRAYBUFFER;
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
public JavaValue(byte[] data, MemoryReleaser memoryReleaser) {
|
||||
this.type = TYPE_ARRAYBUFFER;
|
||||
this.data = data;
|
||||
this.memoryReleaser = memoryReleaser;
|
||||
}
|
||||
|
||||
public int getType() {
|
||||
return type;
|
||||
}
|
||||
@@ -82,4 +97,24 @@ public class JavaValue {
|
||||
public String getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
public byte[] getByteData() {
|
||||
return data;
|
||||
}
|
||||
|
||||
public interface MemoryReleaser {
|
||||
/**
|
||||
* Called when JS deallocated the arraybuffer
|
||||
*/
|
||||
void deallocate(byte[] data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Called by JNI
|
||||
*/
|
||||
private void onDeallocated() {
|
||||
if (this.memoryReleaser != null) {
|
||||
this.memoryReleaser.deallocate(this.data);
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user