diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml
index c3779b5..6ce25f0 100644
--- a/.github/workflows/CI.yml
+++ b/.github/workflows/CI.yml
@@ -15,11 +15,11 @@ jobs:
run: |
export CI_PROJECT_DIR=`pwd`
cd /root/v8
- git checkout remotes/origin/8.3-lkgr
+ git checkout remotes/origin/9.3-lkgr
cp -R /root/v8/include $CI_PROJECT_DIR/v8-build/v8
cd $CI_PROJECT_DIR/v8-build/v8/src
echo "1. build v8 project."
- python build_v8.py --target android --v8-source /root/v8 --remote-branch remotes/origin/8.3-lkgr
+ python build_v8.py --target android --v8-source /root/v8 --remote-branch remotes/origin/9.3-lkgr
- name: "build jsenv"
run: |
mkdir -p third_party/android_tools/
diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index f5e71fc..9df9b74 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -11,11 +11,11 @@ build:
script:
# build v8
- cd /root/v8
- - git checkout remotes/origin/8.3-lkgr
+ - git checkout remotes/origin/9.3-lkgr
- cp -R /root/v8/include $CI_PROJECT_DIR/v8-build/v8
- cd $CI_PROJECT_DIR/v8-build/v8/src
- echo "1. build v8 project."
- - python build_v8.py --target android --v8-source /root/v8 --remote-branch remotes/origin/8.3-lkgr
+ - python build_v8.py --target android --v8-source /root/v8 --remote-branch remotes/origin/9.3-lkgr
# build jsenv
- cd $CI_PROJECT_DIR
- mkdir -p third_party/android_tools/
@@ -37,7 +37,7 @@ release:
- tags
script:
- cd /root/v8
- - git checkout remotes/origin/8.3-lkgr
+ - git checkout remotes/origin/9.3-lkgr
- cd $CI_PROJECT_DIR
- mkdir -p third_party/android_tools/
- ln -s /root/v8/third_party/android_ndk third_party/android_tools/ndk
diff --git a/Dockerfile b/Dockerfile
index 674b711..5a2bae5 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -1,4 +1,4 @@
-FROM ubuntu:19.10
+FROM ubuntu:20.04
ENV PATH=${PATH}:/root/depot_tools:/root/v8/tools/dev
@@ -20,16 +20,24 @@ RUN apt update -qq && apt upgrade -y && apt-get install -qq -y --no-install-reco
git
RUN apt-get install -y npm && \
- npm i -g n && \
- npm i -g yarn && \
- n latest
+ npm i -g n && \
+ npm i -g yarn && \
+ n latest
RUN cd ~ && git clone https://chromium.googlesource.com/chromium/tools/depot_tools.git --depth=1
-RUN cd ~ && fetch v8 && cd ~/v8 && gclient sync
+# Solve the problem of not being able to download android_ndk
+RUN cd ~ && fetch v8 \
+ && cd v8 && git checkout remotes/origin/9.3-lkgr \
+ && sed -i 's/2c2138e811487b13020eb331482fb991fd399d4e/083aa67a0d3309ebe37eafbe7bfd96c235a019cf/g' DEPS \
+ && echo "target_os = ['android']" >> ../.gclient \
+ && gclient sync
+
RUN apt install gcc-9-arm-linux-gnueabihf -y
+RUN apt autoremove -y
-RUN cd ~/v8 && sed -i 's/${dev_list} snapcraft/${dev_list}/g' build/install-build-deps.sh && build/install-build-deps.sh --lib32
+RUN cd ~/v8 && sed -i 's/${dev_list} snapcraft/${dev_list}/g' build/install-build-deps.sh \
+ && build/install-build-deps.sh --lib32
CMD [ "fish" ]
@@ -39,13 +47,9 @@ ENV ANDROID_NDK_HOME=/root/v8/third_party/android_ndk
RUN apt install openjdk-8-jdk -y && update-java-alternatives -s java-1.8.0-openjdk-amd64
RUN cd ~/v8 && build/install-build-deps-android.sh
-RUN cd ~/v8/build && git reset HEAD --hard
-
-RUN cd ~/v8 && echo "target_os = ['android']" >> ../.gclient \
- && gclient sync
-
RUN apt update && apt install libatomic1:i386 -y
+RUN apt install ninja-build
ENV PATH=${PATH}:${ANDROID_HOME}/cmdline-tools/latest/bin
ARG ANDROID_BUILD_VERSION=28
diff --git a/README.md b/README.md
index 1bb9356..596b7aa 100644
--- a/README.md
+++ b/README.md
@@ -6,17 +6,17 @@ Public GN documents can be found at: [https://chromium.googlesource.com/chromium
## 1. Pull docker image and enter container.
```
- docker pull quickapp/v8-build:200513
+ docker pull quickapp/v8-build:230901
```
## 2. build v8
```
export CI_PROJECT_DIR="/root/jsenv-runtime"
cd /root/v8
-git checkout remotes/origin/8.3-lkgr
+git checkout remotes/origin/9.3-lkgr
cp -R /root/v8/include $CI_PROJECT_DIR/v8-build/v8
cd $CI_PROJECT_DIR/v8-build/v8/src
-python build_v8.py --target android --v8-source /root/v8 --remote-branch remotes/origin/8.3-lkgr
+python build_v8.py --target android --v8-source /root/v8 --remote-branch remotes/origin/9.3-lkgr
```
## 3. Link third_party.
```
diff --git a/build/config/android/BUILD.gn b/build/config/android/BUILD.gn
index edb1558..8ef6ddd 100644
--- a/build/config/android/BUILD.gn
+++ b/build/config/android/BUILD.gn
@@ -34,74 +34,25 @@ config("compiler") {
"__ANDROID_API__=$compile_api_level",
]
- ldflags = [
- ]
+ ldflags = []
- android_compile_sysroot = "$android_ndk_root/sysroot"
- android_linker_sysroot = android_compile_sysroot
if (target_cpu == "arm") {
abi_target = "arm-linux-androideabi"
- arm_android_sysroot_subdir = "platforms/android-${android32_ndk_api_level}/arch-arm"
- android_linker_sysroot = "$android_ndk_root/$arm_android_sysroot_subdir"
} else if (target_cpu == "arm64") {
abi_target = "aarch64-linux-android"
- arm64_android_sysroot_subdir = "platforms/android-${android64_ndk_api_level}/arch-arm64"
- android_linker_sysroot = "$android_ndk_root/$arm64_android_sysroot_subdir"
} else if (target_cpu == "x86") {
abi_target = "i686-linux-android"
- x86_android_sysroot_subdir = "platforms/android-${android32_ndk_api_level}/arch-x86"
- android_linker_sysroot = "$android_ndk_root/$x86_android_sysroot_subdir"
} else if (target_cpu == "x64") {
abi_target = "x86_64-linux-android"
- x86_64_android_sysroot_subdir = "platforms/android-${android64_ndk_api_level}/arch-x86_64"
- android_linker_sysroot = "$android_ndk_root/$x86_64_android_sysroot_subdir"
} else {
assert(false, "Target ABI not supported.")
}
if (is_clang) {
- cflags += [
- "--target=$abi_target",
- ]
- ldflags += [
- "--target=$abi_target",
- ]
- }
-
- cflags += [
- "-isystem" +
- rebase_path("$android_ndk_root/sysroot/usr/include/$abi_target", root_build_dir),
- "--sysroot=" + rebase_path(android_compile_sysroot, root_build_dir),
- ]
-
- ldflags += [
- "--sysroot=" + rebase_path(android_linker_sysroot, root_build_dir),
- ]
-
- if (android_ndk_major_version >= 13) {
- libcxx_include_path =
- rebase_path("$android_libcpp_root/include", root_build_dir)
- libcxxabi_include_path =
- rebase_path("$android_ndk_root/sources/cxx-stl/llvm-libc++abi/include",
- root_build_dir)
- } else {
- libcxx_include_path =
- rebase_path("$android_libcpp_root/libcxx/include", root_build_dir)
- libcxxabi_include_path = rebase_path(
- "$android_ndk_root/sources/cxx-stl/llvm-libc++abi/libcxxabi/include",
- root_build_dir)
+ cflags += [ "--target=$abi_target$compile_api_level" ]
+ ldflags += [ "--target=$abi_target$compile_api_level" ]
}
- android_support_include_path = rebase_path(
- "$android_ndk_root/sources/android/support/include",
- root_build_dir)
-
- cflags_cc += [
- "-isystem" + libcxx_include_path,
- "-isystem" + libcxxabi_include_path,
- "-isystem" + android_support_include_path,
- ]
-
# Android Linker settings
ldflags += [
"-nostdlib++",
@@ -110,10 +61,6 @@ config("compiler") {
"-Wl,--warn-shared-textrel",
]
- if (is_clang) {
- ldflags += [ "--gcc-toolchain=" + rebase_path(android_toolchain_root, root_build_dir) ]
- }
-
# Use shared C++
libs = [ "c" ]
libs += [ "m" ]
@@ -121,6 +68,7 @@ config("compiler") {
libs += [ "c++abi" ]
libs += [ "android" ]
libs += [ "log" ]
+
# FIXME(liushouqun): Use llvm shared libc++, need to process the "libc++_shared.so".
libs += [ "c++_shared" ]
libs += [ android_libgcc_file ]
@@ -128,7 +76,7 @@ config("compiler") {
if (current_cpu == "arm" || current_cpu == "x86") {
# In Android NDK r17, libunwind and libandroid_support are only required in
# 32-bit build.
- if(current_cpu == "arm") {
+ if (current_cpu == "arm") {
libs += [ "unwind" ]
}
libs += [ "android_support" ]
@@ -139,13 +87,9 @@ config("compiler") {
copy("libc++_shared") {
soname = "libc++_shared.so"
- sources = [
- "${android_libcpp_lib_dir}/${soname}",
- ]
+ sources = [ "${android_libcpp_lib_dir}/${soname}" ]
- outputs = [
- "${root_out_dir}/${soname}",
- ]
+ outputs = [ "${root_out_dir}/${soname}" ]
}
config("executatble_config") {
diff --git a/build/config/android/config.gni b/build/config/android/config.gni
index 30adbaf..58f2439 100644
--- a/build/config/android/config.gni
+++ b/build/config/android/config.gni
@@ -13,7 +13,7 @@ if (is_android) {
android64_ndk_api_level = 21
# TODO(liushouqun): Fix this by reading the 'source.properties' file to get version.
- android_ndk_major_version = 20
+ android_ndk_major_version = 22
android_sdk_root = rebase_path("//third_party/android_tools/sdk")
android_sdk_version = "28"
@@ -73,11 +73,13 @@ if (is_android) {
android_toolchain_prefix = ""
android_app_abi = ""
if (target_cpu == "arm") {
- android_toolchain_root = android_ndk_root + "/toolchains/arm-linux-androideabi-4.9/prebuilt"
+ android_toolchain_root =
+ android_ndk_root + "/toolchains/arm-linux-androideabi-4.9/prebuilt"
android_toolchain_prefix = "arm-linux-androideabi"
android_app_abi = "armeabi-v7a"
} else if (target_cpu == "arm64") {
- android_toolchain_root = android_ndk_root + "/toolchains/aarch64-linux-android-4.9/prebuilt"
+ android_toolchain_root =
+ android_ndk_root + "/toolchains/aarch64-linux-android-4.9/prebuilt"
android_toolchain_prefix = "aarch64-linux-android"
android_app_abi = "arm64-v8a"
} else if (target_cpu == "x86") {
@@ -85,7 +87,8 @@ if (is_android) {
android_toolchain_prefix = "i686-linux-android"
android_app_abi = "x86"
} else if (target_cpu == "x64") {
- android_toolchain_root = android_ndk_root + "/toolchains/x86_64-4.9/prebuilt"
+ android_toolchain_root =
+ android_ndk_root + "/toolchains/x86_64-4.9/prebuilt"
android_toolchain_prefix = "x86_64-linux-android"
android_app_abi = "x86_64"
} else {
@@ -96,12 +99,15 @@ if (is_android) {
android_libcpp_root = "$android_ndk_root/sources/cxx-stl/llvm-libc++"
android_libcpp_lib_dir = "${android_libcpp_root}/libs/${android_app_abi}"
- android_libgcc_file = android_toolchain_root + "/" + android_toolchain_host_path + "/lib/gcc/" +
+ android_libgcc_file =
+ android_toolchain_root + "/" + android_toolchain_host_path + "/lib/gcc/" +
android_toolchain_prefix + "/4.9.x/" + "libgcc.a"
- android_toolchain_root = android_toolchain_root + "/" + android_toolchain_host_path
+ android_toolchain_root =
+ android_toolchain_root + "/" + android_toolchain_host_path
- android_clang_path = android_ndk_root + "/toolchains/llvm/prebuilt/" + android_toolchain_host_path + "/bin"
+ android_clang_path = android_ndk_root + "/toolchains/llvm/prebuilt/" +
+ android_toolchain_host_path + "/bin"
android_tool_prefix = "$android_toolchain_root/bin/$android_toolchain_prefix-"
android_readelf = "${android_tool_prefix}readelf"
diff --git a/src/main/java/com/eclipsesource/v8/LibraryLoader.java b/src/main/java/com/eclipsesource/v8/LibraryLoader.java
index 6ffc07b..8e48afa 100644
--- a/src/main/java/com/eclipsesource/v8/LibraryLoader.java
+++ b/src/main/java/com/eclipsesource/v8/LibraryLoader.java
@@ -7,6 +7,7 @@
*
* Contributors:
* EclipseSource - initial API and implementation
+ * Wolfgang Steiner - code separation PlatformDetector/LibraryLoader
******************************************************************************/
package com.eclipsesource.v8;
@@ -21,7 +22,7 @@ class LibraryLoader {
static final String DELIMITER;
// HYBRID MODIFY:
- //static final String SWT_LIB_DIR = ".j2v8";
+ // static final String SWT_LIB_DIR = ".j2v8";
static final String SWT_LIB_DIR = ".jsenv";
static {
@@ -29,57 +30,90 @@ class LibraryLoader {
SEPARATOR = System.getProperty("file.separator"); //$NON-NLS-1$
}
- private static String computeLibraryShortName() {
- // HYBRID MODIFY
- //String base = "j2v8";
- String base = "jsenv";
- String osSuffix = getOS();
- String archSuffix = getArchSuffix();
- return base + "_" + osSuffix + "_" + archSuffix;
- }
+ /**
+ * Returns the base-name for the native J2V8 library file.
+ * @param withLinuxVendor include/exclude the {vendor} part from the returned filename
+ *
NOTE: Vendors are only included for linux systems
+ * @return The filename string has the following structure:
+ * {arch}-[vendor]-{operating_system}
+ */
+ public static String computeLibraryShortName(boolean withLinuxVendor) {
+ // HYBRID MODIFY:
+ // String prefix = "j2v8";
+ String prefix = "jsenv";
+ String vendor = withLinuxVendor && PlatformDetector.OS.isLinux() ? PlatformDetector.Vendor.getName() : null;
+ String os = PlatformDetector.OS.getName();
+ String arch = PlatformDetector.Arch.getName();
+
+ final String separator = "-";
- private static String computeLibraryFullName() {
- return "lib" + computeLibraryShortName() + "." + getOSFileExtension();
+ return
+ prefix +
+ (vendor != null ? separator + vendor : "") +
+ separator + os +
+ separator + arch;
}
- static void loadLibrary(final String tempDirectory) {
- if ( isAndroid() ) {
- // HYBRID MODIFY:
- //System.loadLibrary("j2v8");
- System.loadLibrary("jsenv");
- return;
- }
- StringBuffer message = new StringBuffer();
- String libShortName = computeLibraryShortName();
- String libFullName = computeLibraryFullName();
- String ideLocation = System.getProperty("user.dir") + SEPARATOR + "jni" + SEPARATOR + computeLibraryFullName();
+ public static String computeLibraryFullName(boolean withLinuxVendor) {
+ return "lib" + computeLibraryShortName(withLinuxVendor) + "." + PlatformDetector.OS.getLibFileExtension();
+ }
- String path = null;
+ static boolean tryLoad(boolean withLinuxVendor, StringBuffer message) {
+ String libShortName = computeLibraryShortName(withLinuxVendor);
+ String libFullName = computeLibraryFullName(withLinuxVendor);
+ String ideLocation = System.getProperty("user.dir") + SEPARATOR + "jni" + SEPARATOR + libFullName;
/* Try loading library from java library path */
if (load(libFullName, message)) {
- return;
+ return true;
}
if (load(libShortName, message)) {
- return;
+ return true;
}
/* Try loading library from the IDE location */
if (new File(ideLocation).exists()) {
if (load(ideLocation, message)) {
- return;
+ return true;
}
}
+ return false;
+ }
+
+ static void loadLibrary(final String tempDirectory) {
+ if (PlatformDetector.OS.isAndroid()) {
+ // HYBRID MODIFY:
+ // System.loadLibrary("j2v8");
+ System.loadLibrary("jsenv");
+ return;
+ }
+
+ StringBuffer message = new StringBuffer();
+
+ // try loading a vendor-specific library first
+ if (tryLoad(true, message))
+ return;
+
+ // if there is no vendor-specific library, just try to load the default OS library
+ if (tryLoad(false, message))
+ return;
+
+ String path = null;
+
if (tempDirectory != null) {
path = tempDirectory;
} else {
path = System.getProperty("java.io.tmpdir"); //$NON-NLS-1$
}
- if (extract(path + SEPARATOR + libFullName, libFullName, message)) {
+ // try extracting a vendor-specific library first
+ if (extract(path, true, message))
+ return;
+
+ // if there is no vendor-specific library, just try to extract the default OS library
+ if (extract(path, false, message))
return;
- }
/* Failed to find the library */
throw new UnsatisfiedLinkError("Could not load J2V8 library. Reasons: " + message.toString()); //$NON-NLS-1$
@@ -104,6 +138,11 @@ static boolean load(final String libName, final StringBuffer message) {
return false;
}
+ static boolean extract(String libPath, boolean withLinuxVendor, StringBuffer message) {
+ String libFullName = computeLibraryFullName(withLinuxVendor);
+ return extract(libPath + SEPARATOR + libFullName, libFullName, message);
+ }
+
static boolean extract(final String fileName, final String mappedName, final StringBuffer message) {
FileOutputStream os = null;
InputStream is = null;
@@ -150,7 +189,7 @@ static boolean extract(final String fileName, final String mappedName, final Str
}
static void chmod(final String permision, final String path) {
- if (isWindows()) {
+ if (PlatformDetector.OS.isWindows()) {
return;
}
try {
@@ -158,69 +197,4 @@ static void chmod(final String permision, final String path) {
} catch (Throwable e) {
}
}
-
- static String getOsName() {
- return System.getProperty("os.name") + System.getProperty("java.specification.vendor");
- }
-
- static boolean isWindows() {
- return getOsName().startsWith("Windows");
- }
-
- static boolean isMac() {
- return getOsName().startsWith("Mac");
- }
-
- static boolean isLinux() {
- return getOsName().startsWith("Linux");
- }
-
- static boolean isNativeClient() {
- return getOsName().startsWith("nacl");
- }
-
- static boolean isAndroid() {
- return getOsName().contains("Android");
- }
-
- static String getArchSuffix() {
- String arch = System.getProperty("os.arch");
- if (arch.equals("i686")) {
- return "x86";
- } else if (arch.equals("amd64")) {
- return "x86_64";
- } else if (arch.equals("nacl")) {
- return "armv7l";
- } else if (arch.equals("aarch64")) {
- return "armv7l";
- }
- return arch;
- }
-
- static String getOSFileExtension() {
- if (isWindows()) {
- return "dll";
- } else if (isMac()) {
- return "dylib";
- } else if (isLinux()) {
- return "so";
- } else if (isNativeClient()) {
- return "so";
- }
- throw new UnsatisfiedLinkError("Unsupported platform: " + getOsName());
- }
-
- static String getOS() {
- if (isWindows()) {
- return "win32";
- } else if (isMac()) {
- return "macosx";
- } else if (isLinux() && !isAndroid()) {
- return "linux";
- } else if (isAndroid()) {
- return "android";
- }
- throw new UnsatisfiedLinkError("Unsupported platform: " + getOsName());
- }
-
}
diff --git a/src/main/java/com/eclipsesource/v8/NodeJS.java b/src/main/java/com/eclipsesource/v8/NodeJS.java
index 4655212..30d1483 100644
--- a/src/main/java/com/eclipsesource/v8/NodeJS.java
+++ b/src/main/java/com/eclipsesource/v8/NodeJS.java
@@ -91,7 +91,7 @@ public void invoke(final V8Object receiver, final V8Array parameters) {
try {
node.init(require.twin());
} finally {
- require.release();
+ require.close();
}
}
}, STARTUP_CALLBACK);
@@ -137,10 +137,10 @@ public boolean handleMessage() {
public void release() {
v8.checkThread();
if (!require.isReleased()) {
- require.release();
+ require.close();
}
if (!v8.isReleased()) {
- v8.release();
+ v8.close();
}
}
@@ -168,7 +168,7 @@ public V8Object require(final File file) {
requireParams.push(file.getAbsolutePath());
return (V8Object) require.call(null, requireParams);
} finally {
- requireParams.release();
+ requireParams.close();
}
}
@@ -205,7 +205,7 @@ public Object invoke(final V8Object receiver, final V8Array parameters) {
requireParams.push(file.getAbsolutePath());
return require.call(null, requireParams);
} finally {
- requireParams.release();
+ requireParams.close();
}
}
});
diff --git a/src/main/java/com/eclipsesource/v8/Platform.java b/src/main/java/com/eclipsesource/v8/Platform.java
index cfde660..8168935 100644
--- a/src/main/java/com/eclipsesource/v8/Platform.java
+++ b/src/main/java/com/eclipsesource/v8/Platform.java
@@ -1,8 +1,3 @@
-/**
- * Copyright (c) 2021, the hapjs-platform Project Contributors
- * SPDX-License-Identifier: EPL-1.0
- */
-
package com.eclipsesource.v8;
public class Platform {
diff --git a/src/main/java/com/eclipsesource/v8/PlatformDetector.java b/src/main/java/com/eclipsesource/v8/PlatformDetector.java
index 10fdb76..0913c1a 100644
--- a/src/main/java/com/eclipsesource/v8/PlatformDetector.java
+++ b/src/main/java/com/eclipsesource/v8/PlatformDetector.java
@@ -29,21 +29,19 @@
import java.io.Closeable;
import java.io.File;
import java.io.FileInputStream;
-import java.io.InputStreamReader;
import java.io.IOException;
-import java.util.HashMap;
+import java.io.InputStreamReader;
import java.util.Locale;
-import com.eclipsesource.v8.Platform;
-
public class PlatformDetector {
public static class Arch {
public static String getName() {
final String archProperty = System.getProperty("os.arch");
final String archName = normalizeArch(archProperty);
- if (archName.equals(Platform.UNKNOWN))
+ if (archName.equals(Platform.UNKNOWN)) {
throw new UnsatisfiedLinkError("Unsupported arch: " + archProperty);
+ }
return archName;
}
@@ -62,8 +60,9 @@ public static String getName() {
return Platform.ANDROID;
}
- if (osName.equals(Platform.UNKNOWN))
+ if (osName.equals(Platform.UNKNOWN)) {
throw new UnsatisfiedLinkError("Unsupported platform/vendor: " + osProperty + " / " + vendorProperty);
+ }
return osName;
}
@@ -89,16 +88,19 @@ public static boolean isAndroid() {
}
public static String getLibFileExtension() {
- if (isWindows())
+ if (isWindows()) {
return "dll";
+ }
- if (isMac())
+ if (isMac()) {
return "dylib";
+ }
if (isLinux()
|| isAndroid()
- || isNativeClient())
+ || isNativeClient()) {
return "so";
+ }
throw new UnsatisfiedLinkError("Unsupported platform library-extension for: " + getName());
}
@@ -110,14 +112,18 @@ public static class Vendor {
private static final String LINUX_ID_PREFIX = "ID=";
public static String getName() {
- if (OS.isWindows())
+ if (OS.isWindows()) {
return "microsoft";
- if (OS.isMac())
+ }
+ if (OS.isMac()) {
return "apple";
- if (OS.isLinux())
+ }
+ if (OS.isLinux()) {
return getLinuxOsReleaseId();
- if (OS.isAndroid())
+ }
+ if (OS.isAndroid()) {
return "google";
+ }
throw new UnsatisfiedLinkError("Unsupported vendor: " + getName());
}
@@ -141,7 +147,7 @@ private static String getLinuxOsReleaseId() {
throw new UnsatisfiedLinkError("Unsupported linux vendor: " + getName());
}
- private static String parseLinuxOsReleaseFile(File file) {
+ private static String parseLinuxOsReleaseFile(final File file) {
BufferedReader reader = null;
try {
reader = new BufferedReader(new InputStreamReader(new FileInputStream(file), "utf-8"));
@@ -166,7 +172,7 @@ private static String parseLinuxOsReleaseFile(File file) {
return null;
}
- private static String parseLinuxRedhatReleaseFile(File file) {
+ private static String parseLinuxRedhatReleaseFile(final File file) {
BufferedReader reader = null;
try {
reader = new BufferedReader(new InputStreamReader(new FileInputStream(file), "utf-8"));
@@ -198,7 +204,7 @@ private static String parseLinuxRedhatReleaseFile(File file) {
return null;
}
- private static void closeQuietly(Closeable obj) {
+ private static void closeQuietly(final Closeable obj) {
try {
if (obj != null) {
obj.close();
@@ -209,7 +215,7 @@ private static void closeQuietly(Closeable obj) {
}
}
- private static String normalizeOsReleaseValue(String value) {
+ private static String normalizeOsReleaseValue(final String value) {
// Remove any quotes from the string.
return value.trim().replace("\"", "");
}
@@ -224,7 +230,7 @@ private static String normalizeOs(String value) {
}
if (value.startsWith("os400")) {
// Avoid the names such as os4000
- if (value.length() <= 5 || !Character.isDigit(value.charAt(5))) {
+ if ((value.length() <= 5) || !Character.isDigit(value.charAt(5))) {
return "os400";
}
}
@@ -276,10 +282,10 @@ private static String normalizeArch(String value) {
if (value.matches("^(sparcv9|sparc64)$")) {
return "sparc_64";
}
- if (value.matches("^(arm|arm32)$")) {
+ if (value.matches("^(arm|arm32)$") || value.startsWith("armv7")) {
return "arm_32";
}
- if ("aarch64".equals(value)) {
+ if ("aarch64".equals(value) || value.startsWith("armv8")) {
return "aarch_64";
}
if (value.matches("^(ppc|ppc32)$")) {
@@ -301,7 +307,7 @@ private static String normalizeArch(String value) {
return Platform.UNKNOWN;
}
- private static String normalize(String value) {
+ private static String normalize(final String value) {
if (value == null) {
return "";
}
diff --git a/src/main/java/com/eclipsesource/v8/Releasable.java b/src/main/java/com/eclipsesource/v8/Releasable.java
index 0017787..3edee1e 100644
--- a/src/main/java/com/eclipsesource/v8/Releasable.java
+++ b/src/main/java/com/eclipsesource/v8/Releasable.java
@@ -10,15 +10,21 @@
******************************************************************************/
package com.eclipsesource.v8;
+import java.io.Closeable;
+
/**
* An interface used to denote all V8 Classes which can be released.
*/
-public interface Releasable {
+public interface Releasable extends Closeable {
/**
* Release the underlying resources. Once an object is released
* it typically cannot be used again.
*/
- void release();
+ void close();
+ /**
+ * Synonym for {@link #close()}.
+ */
+ void release();
}
diff --git a/src/main/java/com/eclipsesource/v8/SignatureProvider.java b/src/main/java/com/eclipsesource/v8/SignatureProvider.java
new file mode 100644
index 0000000..035c5b0
--- /dev/null
+++ b/src/main/java/com/eclipsesource/v8/SignatureProvider.java
@@ -0,0 +1,5 @@
+package com.eclipsesource.v8;
+
+public interface SignatureProvider {
+ public byte[] getSignature(String uri);
+}
diff --git a/src/main/java/com/eclipsesource/v8/V8.java b/src/main/java/com/eclipsesource/v8/V8.java
index 96db3b9..e03b806 100644
--- a/src/main/java/com/eclipsesource/v8/V8.java
+++ b/src/main/java/com/eclipsesource/v8/V8.java
@@ -20,6 +20,7 @@
import java.util.Map;
import java.util.Set;
+import com.eclipsesource.v8.inspector.V8InspectorDelegate;
import com.eclipsesource.v8.utils.V8Executor;
import com.eclipsesource.v8.utils.V8Map;
import com.eclipsesource.v8.utils.V8Runnable;
@@ -47,6 +48,7 @@ public class V8 extends V8Object {
private Map data = null;
private final V8Locker locker;
+ private SignatureProvider signatureProvider = null;
private long objectReferences = 0;
private long v8RuntimePtr = 0;
private List resources = null;
@@ -114,11 +116,11 @@ public static V8 createV8Runtime() {
return createV8Runtime(null, null);
}
- // HYBRID ADD BEGIN
+ // HYBRID ADD BEGIN:
public static V8 createV8Runtime(final String globalAlias, final String tempDirectory) {
return createV8Runtime(globalAlias, tempDirectory, null);
}
- // HYBRID END
+ // HYBRID ADD END
/**
* Creates a new V8Runtime and loads the required native libraries if they
@@ -148,8 +150,9 @@ public static V8 createV8Runtime(final String globalAlias) {
*
* @return A new isolated V8 Runtime.
*/
+
// HYBRID MODIFY:
- //public static V8 createV8Runtime(final String globalAlias, final String tempDirectory) {
+ // public static V8 createV8Runtime(final String globalAlias, final String tempDirectory) {
public static V8 createV8Runtime(final String globalAlias, final String tempDirectory,
final String nativejsSnapshotSoName) {
if (!nativeLibraryLoaded) {
@@ -165,7 +168,7 @@ public static V8 createV8Runtime(final String globalAlias, final String tempDire
initialized = true;
}
// HYBRID MODIFY:
- //V8 runtime = new V8(globalAlias);
+ // V8 runtime = new V8(globalAlias);
V8 runtime = new V8(globalAlias, nativejsSnapshotSoName);
synchronized (lock) {
runtimeCounter++;
@@ -173,6 +176,10 @@ public static V8 createV8Runtime(final String globalAlias, final String tempDire
return runtime;
}
+ public void setSignatureProvider(final SignatureProvider signatureProvider) {
+ this.signatureProvider = signatureProvider;
+ }
+
/**
* Adds a ReferenceHandler to track when new V8Objects are created.
*
@@ -260,12 +267,16 @@ private void notifyReferenceDisposed(final V8Value object) {
private static void checkNativeLibraryLoaded() {
if (!nativeLibraryLoaded) {
+ String vendorName = LibraryLoader.computeLibraryShortName(true);
+ String baseName = LibraryLoader.computeLibraryShortName(false);
+ String message = "J2V8 native library not loaded (" + baseName + "/" + vendorName + ")";
+
if (nativeLoadError != null) {
- throw new IllegalStateException("J2V8 native library not loaded", nativeLoadError);
+ throw new IllegalStateException(message, nativeLoadError);
} else if (nativeLoadException != null) {
- throw new IllegalStateException("J2V8 native library not loaded", nativeLoadException);
+ throw new IllegalStateException(message, nativeLoadException);
} else {
- throw new IllegalStateException("J2V8 native library not loaded");
+ throw new IllegalStateException(message);
}
}
}
@@ -275,12 +286,12 @@ protected V8() {
}
// HYBRID MODIFY:
- //protected V8(final String globalAlias) {
+ // protected V8(final String globalAlias) {
protected V8(final String globalAlias, final String nativejsSnapshotSoName) {
super(null);
released = false;
// HYBRID MODIFY:
- //v8RuntimePtr = _createIsolate(globalAlias);
+ // v8RuntimePtr = _createIsolate(globalAlias);
v8RuntimePtr = _createIsolate(globalAlias, nativejsSnapshotSoName);
locker = new V8Locker(this);
checkThread();
@@ -289,9 +300,23 @@ protected V8(final String globalAlias, final String nativejsSnapshotSoName) {
// HYBRID ADD BEGIN:
protected V8(final String globalAlias) {
- this(globalAlias, null);
+ this(globalAlias, null);
+ }
+ // HYBRID ADD END
+
+ public long createInspector(final V8InspectorDelegate inspectorDelegate, final String contextName) {
+ return _createInspector(v8RuntimePtr, inspectorDelegate, contextName);
+ }
+
+ public void dispatchProtocolMessage(final long V8InspectorPtr, final String protocolMessage) {
+ checkThread();
+ _dispatchProtocolMessage(v8RuntimePtr, V8InspectorPtr, protocolMessage);
+ }
+
+ public void schedulePauseOnNextStatement(final long V8InspectorPtr, final String reason) {
+ checkThread();
+ _schedulePauseOnNextStatement(v8RuntimePtr, V8InspectorPtr, reason);
}
- // HYBRID END
/**
* Returns an UNDEFINED constant.
@@ -344,11 +369,21 @@ public static String getSCMRevision() {
return "Unknown revision ID";
}
+ /*
+ * (non-Javadoc)
+ * @see com.eclipsesource.v8.V8Value#close()
+ */
+ @Override
+ public void close() {
+ release(true);
+ }
+
/*
* (non-Javadoc)
* @see com.eclipsesource.v8.V8Value#release()
*/
@Override
+ @Deprecated
public void release() {
release(true);
}
@@ -392,7 +427,7 @@ public void release(final boolean reportMemoryLeaks) {
v8RuntimePtr = 0L;
released = true;
if (reportMemoryLeaks && (getObjectReferenceCount() > 0)) {
- throw new IllegalStateException(objectReferences + " Object(s) still exist in runtime");
+ throw new IllegalStateException(getObjectReferenceCount() + " Object(s) still exist in runtime");
}
}
}
@@ -677,16 +712,51 @@ public Object executeScript(final String script) {
* Primitives will be boxed.
*
* @param script The script to execute.
- * @param scriptName The name of the script
+ * @param uri The name of the script
+ *
+ * @return The result of the script as a Java Object.
+ */
+ public Object executeScript(final String script, final String uri) {
+ checkThread();
+ checkScript(script);
+ return executeScript(getV8RuntimePtr(), UNKNOWN, script, uri, 0);
+ }
+
+ /**
+ * Executes a JS Script on this runtime and returns the result as a Java Object.
+ * Primitives will be boxed.
+ *
+ * @param script The script to execute.
+ * @param uri The name of the script
* @param lineNumber The line number that is considered to be the first line of
* the script. Typically 0, but could be set to another value for exception stack trace purposes.
*
* @return The result of the script as a Java Object.
*/
- public Object executeScript(final String script, final String scriptName, final int lineNumber) {
+ public Object executeScript(final String script, final String uri, final int lineNumber) {
checkThread();
checkScript(script);
- return executeScript(getV8RuntimePtr(), UNKNOWN, script, scriptName, lineNumber);
+ return executeScript(getV8RuntimePtr(), UNKNOWN, script, uri, lineNumber);
+ }
+
+ /**
+ * Executes a JS Script module on this runtime and returns the result as a Java Object.
+ * Primitives will be boxed.
+ *
+ * If the script does not match the signature (as verified with the public key) then a
+ * V8SecurityException will be thrown.
+ *
+ * @param script The signed script to execute
+ * @param modulePrefix The module prefix
+ * @param modulePostfix The module postfix
+ * @param uri The name of the script
+ *
+ * @return The result of the script as a Java Object.
+ */
+ public Object executeModule(final String script, final String modulePrefix, final String modulePostfix, final String uri) {
+ checkThread();
+ checkScript(script);
+ return executeScript(getV8RuntimePtr(), UNKNOWN, modulePrefix + script + modulePostfix, uri, 0);
}
/**
@@ -762,7 +832,7 @@ public V8Locker getLocker() {
*
* @return The unique build ID of the Native library.
*/
- public long getBuildID() {
+ public static long getBuildID() {
return _getBuildID();
}
@@ -854,7 +924,7 @@ protected void weakReferenceReleased(final long objectID) {
if (v8Value != null) {
v8WeakReferences.remove(objectID);
try {
- v8Value.release();
+ v8Value.close();
} catch (Exception e) {
// Swallow these exceptions. The V8 GC is running, and
// if we return to V8 with Java exception on our stack,
@@ -940,13 +1010,13 @@ private void releaseArguments(final Object[] args, final boolean hasVarArgs) {
Object[] varArgs = (Object[]) args[args.length - 1];
for (Object object : varArgs) {
if (object instanceof V8Value) {
- ((V8Value) object).release();
+ ((V8Value) object).close();
}
}
}
for (Object arg : args) {
if (arg instanceof V8Value) {
- ((V8Value) arg).release();
+ ((V8Value) arg).close();
}
}
}
@@ -1046,6 +1116,10 @@ protected long initNewV8Object(final long v8RuntimePtr) {
return _initNewV8Object(v8RuntimePtr);
}
+ protected long initEmptyContainer(final long v8RuntimePtr) {
+ return _initEmptyContainer(v8RuntimePtr);
+ }
+
protected void acquireLock(final long v8RuntimePtr) {
_acquireLock(v8RuntimePtr);
}
@@ -1090,6 +1164,10 @@ protected void setWeak(final long v8RuntimePtr, final long objectHandle) {
_setWeak(v8RuntimePtr, objectHandle);
}
+ protected void clearWeak(final long v8RuntimePtr, final long objectHandle) {
+ _clearWeak(v8RuntimePtr, objectHandle);
+ }
+
protected boolean isWeak(final long v8RuntimePtr, final long objectHandle) {
return _isWeak(v8RuntimePtr, objectHandle);
}
@@ -1320,6 +1398,10 @@ protected void addArrayNullItem(final long v8RuntimePtr, final long arrayHandle)
_addArrayNullItem(v8RuntimePtr, arrayHandle);
}
+ protected String getConstructorName(final long v8RuntimePtr, final long objectHandle) {
+ return _getConstructorName(v8RuntimePtr, objectHandle);
+ }
+
protected int getType(final long v8RuntimePtr, final long objectHandle) {
return _getType(v8RuntimePtr, objectHandle);
}
@@ -1394,6 +1476,8 @@ protected void releaseMethodDescriptor(final long v8RuntimePtr, final long metho
private native long _initNewV8Object(long v8RuntimePtr);
+ private native long _initEmptyContainer(long v8RuntimePtr);
+
private native void _acquireLock(long v8RuntimePtr);
private native void _releaseLock(long v8RuntimePtr);
@@ -1405,9 +1489,15 @@ protected void releaseMethodDescriptor(final long v8RuntimePtr, final long metho
private native void _releaseRuntime(long v8RuntimePtr);
// HYBRID MODIFY:
- //private native long _createIsolate(String globalAlias);
+ // private native long _createIsolate(String globalAlias);
private native long _createIsolate(String globalAlias, String nativejsSnapshotSoName);
+ private native long _createInspector(long v8RuntimePtr, final V8InspectorDelegate inspectorDelegate, final String contextName);
+
+ private native void _dispatchProtocolMessage(final long v8RuntimePtr, long v8InspectorPtr, final String protocolMessage);
+
+ private native void _schedulePauseOnNextStatement(final long v8RuntimePtr, long v8InspectorPtr, final String reason);
+
private native int _executeIntegerScript(long v8RuntimePtr, final String script, final String scriptName, final int lineNumber);
private native double _executeDoubleScript(long v8RuntimePtr, final String script, final String scriptName, final int lineNumber);
@@ -1518,6 +1608,8 @@ protected void releaseMethodDescriptor(final long v8RuntimePtr, final long metho
private native void _setPrototype(long v8RuntimePtr, long objectHandle, long prototypeHandle);
+ private native String _getConstructorName(long v8RuntimePtr, long objectHandle);
+
private native int _getType(long v8RuntimePtr, long objectHandle);
private native int _getType(long v8RuntimePtr, long objectHandle, final int index, final int length);
@@ -1566,6 +1658,8 @@ protected void releaseMethodDescriptor(final long v8RuntimePtr, final long metho
private native void _setWeak(long runtimePtr, long objectHandle);
+ private native void _clearWeak(long runtimePtr, long objectHandle);
+
private native boolean _isWeak(long runtimePtr, long objectHandle);
private native ByteBuffer _createV8ArrayBufferBackingStore(final long v8RuntimePtr, final long objectHandle, final int capacity);
@@ -1578,7 +1672,7 @@ protected void releaseMethodDescriptor(final long v8RuntimePtr, final long metho
private native long _getGlobalObject(final long v8RuntimePtr);
- private native long _getBuildID();
+ private native static long _getBuildID();
private native static void _startNodeJS(final long v8RuntimePtr, final String fileName);
@@ -1586,6 +1680,19 @@ protected void releaseMethodDescriptor(final long v8RuntimePtr, final long metho
private native static boolean _isRunning(final long v8RuntimePtr);
+ private native static boolean _isNodeCompatible();
+
+ public static boolean isNodeCompatible() {
+ if (!nativeLibraryLoaded) {
+ synchronized (lock) {
+ if (!nativeLibraryLoaded) {
+ load(null);
+ }
+ }
+ }
+ return _isNodeCompatible();
+ }
+
void addObjRef(final V8Value reference) {
objectReferences++;
if (!referenceHandlers.isEmpty()) {
diff --git a/src/main/java/com/eclipsesource/v8/V8Array.java b/src/main/java/com/eclipsesource/v8/V8Array.java
index 807353b..3523261 100644
--- a/src/main/java/com/eclipsesource/v8/V8Array.java
+++ b/src/main/java/com/eclipsesource/v8/V8Array.java
@@ -633,11 +633,20 @@ public boolean isReleased() {
return false;
}
+ /*
+ * (non-Javadoc)
+ * @see com.eclipsesource.v8.V8Value#close()
+ */
+ @Override
+ public void close() {
+ }
+
/*
* (non-Javadoc)
* @see com.eclipsesource.v8.V8Value#release()
*/
@Override
+ @Deprecated
public void release() {
}
diff --git a/src/main/java/com/eclipsesource/v8/V8ArrayBuffer.java b/src/main/java/com/eclipsesource/v8/V8ArrayBuffer.java
index bada577..4ecd48e 100644
--- a/src/main/java/com/eclipsesource/v8/V8ArrayBuffer.java
+++ b/src/main/java/com/eclipsesource/v8/V8ArrayBuffer.java
@@ -25,7 +25,7 @@
*/
public class V8ArrayBuffer extends V8Value {
- private ByteBuffer byteBuffer;
+ ByteBuffer byteBuffer;
/**
* Creates a new V8ArrayBuffer on a given V8Runtime with a
@@ -41,17 +41,11 @@ public V8ArrayBuffer(final V8 v8, final int capacity) {
byteBuffer.order(ByteOrder.nativeOrder());
}
- /**
- * Creates a new V8ArrayBuffer with the provided ByteBuffer as the backing store.
- * The ByteBuffer must be allocated as a DirectBuffer. If the ByteBuffer is not
- * a DirectBuffer an IllegalArgumentException will be thrown.
- *
- * @param v8 The runtime on which to create the ArrayBuffer
- * @param byteBuffer The ByteBuffer to use as the backing store. The ByteBuffer must
- * be allocated as a DirectBuffer.
- */
- public V8ArrayBuffer(final V8 v8, final ByteBuffer byteBuffer) {
+ public V8ArrayBuffer(final V8 v8, ByteBuffer byteBuffer) {
super(v8);
+ if (byteBuffer == null) {
+ byteBuffer = ByteBuffer.allocateDirect(0);
+ }
if (!byteBuffer.isDirect()) {
throw new IllegalArgumentException("ByteBuffer must be a allocated as a direct ByteBuffer");
}
@@ -86,18 +80,393 @@ protected V8Value createTwin() {
*/
@Override
public V8ArrayBuffer twin() {
+ v8.checkThread();
+ checkReleased();
return (V8ArrayBuffer) super.twin();
}
/**
- * Returns the backing store used for this ArrayBuffer.
+ * Returns the buffers limit
+ *
+ * @return the buffers limit
+ */
+ public int limit() {
+ v8.checkThread();
+ checkReleased();
+ return byteBuffer.limit();
+ }
+
+ /**
+ * Returns the buffers capacity
+ *
+ * @return the buffers capacity
+ */
+ public final int capacity() {
+ v8.checkThread();
+ checkReleased();
+ return byteBuffer.capacity();
+ }
+
+ /**
*
- * @return The backing store used for this ArrayBuffer.
+ * @return
*/
- public ByteBuffer getBackingStore() {
+ public final int position() {
+ v8.checkThread();
+ checkReleased();
+ return byteBuffer.position();
+ }
+
+ public final V8ArrayBuffer position(final int newPosition) {
+ v8.checkThread();
+ checkReleased();
+ byteBuffer.position(newPosition);
+ return this;
+ }
+
+ public final V8ArrayBuffer limit(final int newLimit) {
+ v8.checkThread();
+ checkReleased();
+ byteBuffer.limit(newLimit);
+ return this;
+ }
+
+ public final V8ArrayBuffer mark() {
+ v8.checkThread();
+ checkReleased();
+ byteBuffer.mark();
+ return this;
+ }
+
+ public final V8ArrayBuffer reset() {
+ v8.checkThread();
+ checkReleased();
+ byteBuffer.reset();
+ return this;
+ }
+
+ public final V8ArrayBuffer clear() {
+ v8.checkThread();
+ checkReleased();
+ byteBuffer.clear();
+ return this;
+ }
+
+ public final V8ArrayBuffer flip() {
+ v8.checkThread();
+ checkReleased();
+ byteBuffer.flip();
+ return this;
+ }
+
+ public final V8ArrayBuffer rewind() {
+ v8.checkThread();
+ checkReleased();
+ byteBuffer.rewind();
+ return this;
+ }
+
+ public final int remaining() {
+ v8.checkThread();
+ checkReleased();
+ return byteBuffer.remaining();
+ }
+
+ public final boolean hasRemaining() {
+ v8.checkThread();
+ checkReleased();
+ return byteBuffer.hasRemaining();
+ }
+
+ public boolean isReadOnly() {
+ v8.checkThread();
+ checkReleased();
+ return byteBuffer.isReadOnly();
+ }
+
+ public byte get() {
+ v8.checkThread();
+ checkReleased();
+ return byteBuffer.get();
+ }
+
+ public V8ArrayBuffer put(final byte b) {
+ v8.checkThread();
+ checkReleased();
+ byteBuffer.put(b);
+ return this;
+ }
+
+ public byte get(final int index) {
+ v8.checkThread();
+ checkReleased();
+ return byteBuffer.get(index);
+ }
+
+ public V8ArrayBuffer put(final int index, final byte b) {
+ v8.checkThread();
+ checkReleased();
+ byteBuffer.put(index, b);
+ return this;
+ }
+
+ public V8ArrayBuffer get(final byte[] dst, final int offset, final int length) {
+ v8.checkThread();
+ checkReleased();
+ byteBuffer.get(dst, offset, length);
+ return this;
+ }
+
+ public V8ArrayBuffer get(final byte[] dst) {
+ v8.checkThread();
+ checkReleased();
+ byteBuffer.get(dst);
+ return this;
+ }
+
+ public V8ArrayBuffer put(final ByteBuffer src) {
+ v8.checkThread();
+ checkReleased();
+ byteBuffer.put(src);
+ return this;
+ }
+
+ public V8ArrayBuffer put(final byte[] src, final int offset, final int length) {
+ v8.checkThread();
+ checkReleased();
+ byteBuffer.put(src, offset, length);
+ return this;
+ }
+
+ public final V8ArrayBuffer put(final byte[] src) {
+ v8.checkThread();
+ checkReleased();
+ byteBuffer.put(src);
+ return this;
+ }
+
+ public final boolean hasArray() {
+ v8.checkThread();
+ checkReleased();
+ return byteBuffer.hasArray();
+ }
+
+ public final byte[] array() {
+ v8.checkThread();
+ checkReleased();
+ return byteBuffer.array();
+ }
+
+ public final int arrayOffset() {
+ v8.checkThread();
+ checkReleased();
+ return byteBuffer.arrayOffset();
+ }
+
+ public V8ArrayBuffer compact() {
+ v8.checkThread();
+ checkReleased();
+ byteBuffer.compact();
+ return this;
+ }
+
+ public boolean isDirect() {
+ v8.checkThread();
+ checkReleased();
+ return byteBuffer.isDirect();
+ }
+
+ public final ByteOrder order() {
+ v8.checkThread();
+ checkReleased();
+ return byteBuffer.order();
+ }
+
+ public final V8ArrayBuffer order(final ByteOrder bo) {
+ v8.checkThread();
+ checkReleased();
+ byteBuffer.order(bo);
+ return this;
+ }
+
+ public char getChar() {
+ v8.checkThread();
+ checkReleased();
+ return byteBuffer.getChar();
+ }
+
+ public V8ArrayBuffer putChar(final char value) {
+ v8.checkThread();
+ checkReleased();
+ byteBuffer.putChar(value);
+ return this;
+ }
+
+ public char getChar(final int index) {
+ v8.checkThread();
+ checkReleased();
+ return byteBuffer.getChar(index);
+ }
+
+ public V8ArrayBuffer putChar(final int index, final char value) {
+ v8.checkThread();
+ checkReleased();
+ byteBuffer.putChar(index, value);
+ return this;
+ }
+
+ public short getShort() {
+ v8.checkThread();
+ checkReleased();
+ return byteBuffer.getShort();
+ }
+
+ public V8ArrayBuffer putShort(final short value) {
+ v8.checkThread();
+ checkReleased();
+ byteBuffer.putShort(value);
+ return this;
+ }
+
+ public short getShort(final int index) {
+ v8.checkThread();
+ checkReleased();
+ return byteBuffer.getShort(index);
+ }
+
+ public V8ArrayBuffer putShort(final int index, final short value) {
+ v8.checkThread();
+ checkReleased();
+ byteBuffer.putShort(index, value);
+ return this;
+ }
+
+ public int getInt() {
+ v8.checkThread();
+ checkReleased();
+ return byteBuffer.getInt();
+ }
+
+ public V8ArrayBuffer putInt(final int value) {
+ v8.checkThread();
+ checkReleased();
+ byteBuffer.putInt(value);
+ return this;
+ }
+
+ public int getInt(final int index) {
+ v8.checkThread();
+ checkReleased();
+ return byteBuffer.getInt(index);
+ }
+
+ public V8ArrayBuffer putInt(final int index, final int value) {
+ v8.checkThread();
+ checkReleased();
+ byteBuffer.asIntBuffer().put(index, value);
+ return this;
+ }
+
+ public long getLong() {
+ v8.checkThread();
+ checkReleased();
+ return byteBuffer.getLong();
+ }
+
+ public V8ArrayBuffer putLong(final long value) {
+ v8.checkThread();
+ checkReleased();
+ byteBuffer.putLong(value);
+ return this;
+ }
+
+ public long getLong(final int index) {
+ v8.checkThread();
+ checkReleased();
+ return byteBuffer.getLong(index);
+ }
+
+ public V8ArrayBuffer putLong(final int index, final long value) {
+ v8.checkThread();
+ checkReleased();
+ byteBuffer.putLong(index, value);
+ return this;
+ }
+
+ public float getFloat() {
+ v8.checkThread();
+ checkReleased();
+ return byteBuffer.getFloat();
+ }
+
+ public V8ArrayBuffer putFloat(final float value) {
+ v8.checkThread();
+ checkReleased();
+ byteBuffer.putFloat(value);
+ return this;
+ }
+
+ public float getFloat(final int index) {
+ v8.checkThread();
+ checkReleased();
+ return byteBuffer.getFloat(index);
+ }
+
+ public V8ArrayBuffer putFloat(final int index, final float value) {
+ v8.checkThread();
+ checkReleased();
+ byteBuffer.putFloat(index, value);
+ return this;
+ }
+
+ public double getDouble() {
+ v8.checkThread();
+ checkReleased();
+ return byteBuffer.getDouble();
+ }
+
+ public V8ArrayBuffer putDouble(final double value) {
+ v8.checkThread();
+ checkReleased();
+ byteBuffer.putDouble(value);
+ return this;
+ }
+
+ public double getDouble(final int index) {
+ v8.checkThread();
+ checkReleased();
+ return byteBuffer.getDouble(index);
+ }
+
+ public V8ArrayBuffer putDouble(final int index, final double value) {
+ v8.checkThread();
+ checkReleased();
+ byteBuffer.putDouble(index, value);
+ return this;
+ }
+
+ public int floatLimit() {
+ v8.checkThread();
+ checkReleased();
+ return byteBuffer.asFloatBuffer().limit();
+ }
+
+ public int intLimit() {
+ v8.checkThread();
+ checkReleased();
+ return byteBuffer.asIntBuffer().limit();
+ }
+
+ public int shortLimit() {
+ v8.checkThread();
+ checkReleased();
+ return byteBuffer.asShortBuffer().limit();
+ }
+
+ public int doubleLimit() {
v8.checkThread();
checkReleased();
- return byteBuffer;
+ return byteBuffer.asDoubleBuffer().limit();
}
}
diff --git a/src/main/java/com/eclipsesource/v8/V8Function.java b/src/main/java/com/eclipsesource/v8/V8Function.java
index e8cdb1a..c9fba3c 100644
--- a/src/main/java/com/eclipsesource/v8/V8Function.java
+++ b/src/main/java/com/eclipsesource/v8/V8Function.java
@@ -83,6 +83,7 @@ public V8Function twin() {
*
* @return The result of JavaScript function.
*/
+ @SuppressWarnings("resource")
public Object call(V8Object receiver, final V8Array parameters) {
v8.checkThread();
checkReleased();
diff --git a/src/main/java/com/eclipsesource/v8/V8Object.java b/src/main/java/com/eclipsesource/v8/V8Object.java
index f64a027..640e2a1 100644
--- a/src/main/java/com/eclipsesource/v8/V8Object.java
+++ b/src/main/java/com/eclipsesource/v8/V8Object.java
@@ -399,15 +399,15 @@ public Object executeJSFunction(final String name, final Object... parameters) {
} else if (object instanceof V8Value) {
parameterArray.push((V8Value) object);
} else if (object instanceof Integer) {
- parameterArray.push((Integer) object);
+ parameterArray.push(object);
} else if (object instanceof Double) {
- parameterArray.push((Double) object);
+ parameterArray.push(object);
} else if (object instanceof Long) {
parameterArray.push(((Long) object).doubleValue());
} else if (object instanceof Float) {
parameterArray.push(((Float) object).floatValue());
} else if (object instanceof Boolean) {
- parameterArray.push((Boolean) object);
+ parameterArray.push(object);
} else if (object instanceof String) {
parameterArray.push((String) object);
} else {
@@ -416,7 +416,7 @@ public Object executeJSFunction(final String name, final Object... parameters) {
}
return executeFunction(name, parameterArray);
} finally {
- parameterArray.release();
+ parameterArray.close();
}
}
@@ -683,10 +683,19 @@ public boolean isReleased() {
return false;
}
+ /*
+ * (non-Javadoc)
+ * @see com.eclipsesource.v8.V8Value#close()
+ */
+ @Override
+ public void close() {
+ }
+
/*
* (non-Javadoc)
* @see com.eclipsesource.v8.V8Value#release()
*/
+ @Deprecated
@Override
public void release() {
}
diff --git a/src/main/java/com/eclipsesource/v8/V8TypedArray.java b/src/main/java/com/eclipsesource/v8/V8TypedArray.java
index ec36589..423f9a7 100644
--- a/src/main/java/com/eclipsesource/v8/V8TypedArray.java
+++ b/src/main/java/com/eclipsesource/v8/V8TypedArray.java
@@ -10,8 +10,6 @@
******************************************************************************/
package com.eclipsesource.v8;
-import java.nio.ByteBuffer;
-
/**
* A representation of a JS TypedArray in Java. The typed array is simply a 'view' onto
* a back buffer.
@@ -37,6 +35,41 @@ private V8TypedArray(final V8 v8) {
super(v8);
}
+ @Override
+ protected V8Value createTwin() {
+ v8.checkThread();
+ checkReleased();
+ return new V8TypedArray(v8);
+ }
+
+ @Override
+ public Object get(final int index) {
+ v8.checkThread();
+ checkReleased();
+ int type = getType();
+ switch (type) {
+ case FLOAT_32_ARRAY:
+ return ((Number) super.get(index)).floatValue();
+ case FLOAT_64_ARRAY:
+ return super.get(index);
+ case INT_32_ARRAY:
+ return super.get(index);
+ case INT_16_ARRAY:
+ return ((Number) super.get(index)).shortValue();
+ case INT_8_ARRAY:
+ return ((Number) super.get(index)).byteValue();
+ case UNSIGNED_INT_16_ARRAY:
+ return 0xFFFF & (Integer) super.get(index);
+ case UNSIGNED_INT_32_ARRAY:
+ return 0x00000000FFFFFFFF & ((Number) super.get(index)).longValue();
+ case UNSIGNED_INT_8_CLAMPED_ARRAY:
+ return (short) (0x00FF & ((Number) super.get(index)).byteValue());
+ case UNSIGNED_INT_8_ARRAY:
+ return (short) (0x00FF & ((Number) super.get(index)).shortValue());
+ }
+ return null;
+ }
+
/**
* Provide access to the underlying ByteBuffer used for this TypedArray.
* The V8ArrayBuffer must be released.
@@ -47,20 +80,6 @@ public V8ArrayBuffer getBuffer() {
return (V8ArrayBuffer) get("buffer");
}
- /**
- * Returns the underlying ByteBuffer used to back this TypedArray.
- *
- * @return The ByteBuffer used as the backing store for this TypedArray
- */
- public ByteBuffer getByteBuffer() {
- V8ArrayBuffer buffer = getBuffer();
- try {
- return buffer.getBackingStore();
- } finally {
- buffer.release();
- }
- }
-
@Override
protected void initialize(final long runtimePtr, final Object data) {
v8.checkThread();
@@ -136,7 +155,7 @@ private void checkSize(final V8ArrayData arrayData) {
throw new IllegalStateException("RangeError: Invalid typed array length");
}
int limit = (arrayData.size * getStructureSize(arrayData.type)) + arrayData.offset;
- if (limit > arrayData.buffer.getBackingStore().limit()) {
+ if (limit > arrayData.buffer.limit()) {
throw new IllegalStateException("RangeError: Invalid typed array length");
}
}
@@ -147,11 +166,6 @@ private void checkOffset(final V8ArrayData arrayData) {
}
}
- @Override
- protected V8Value createTwin() {
- return new V8TypedArray(v8);
- }
-
private static class V8ArrayData {
private V8ArrayBuffer buffer;
private int offset;
diff --git a/src/main/java/com/eclipsesource/v8/V8Value.java b/src/main/java/com/eclipsesource/v8/V8Value.java
index 187347c..0804bf9 100644
--- a/src/main/java/com/eclipsesource/v8/V8Value.java
+++ b/src/main/java/com/eclipsesource/v8/V8Value.java
@@ -12,16 +12,16 @@
/**
* A base class for all V8 resources. V8 resources must
- * be released. The rules for releasing resources is as
+ * be closed/released. The rules for releasing resources is as
* follows:
*
- * 1. If you created it, you must release it, with one exception;
+ * 1. If you created it, you must close it, with one exception;
* if the object is being passed pack via a return statement,
* the system will release it for you.
*
* 2. If the system created it, you don’t need to worry about it,
* with one caveat; if the object was returned to you as a
- * result of a method call, you must release it.
+ * result of a method call, you must close it.
*/
abstract public class V8Value implements Releasable {
@@ -143,6 +143,17 @@ public static String getStringRepresentation(final int type) {
}
}
+ /**
+ * Returns a constructor name of the V8 Value.
+ *
+ * @return The V8Value constructor name as a string.
+ */
+ public String getConstructorName() {
+ v8.checkThread();
+ v8.checkReleased();
+ return v8.getConstructorName(v8.getV8RuntimePtr(), objectHandle);
+ }
+
/**
* Determines if this value is undefined.
*
@@ -184,7 +195,7 @@ public int getV8Type() {
* will be updated. Twins are .equal and .strict equals, but
* not == in Java.
*
- * Twins must be released separately since they have their own
+ * Twins must be closed separately since they have their own
* native resources.
*
* @return A new Java object pointing at the same V8 Value
@@ -203,13 +214,13 @@ public V8Value twin() {
/**
* Sets the V8Value as weak reference. A weak reference will eventually
- * be released when no more references exist to this object. Once setWeak
+ * be closed when no more references exist to this object. Once setWeak
* is called, you should check if {@link V8Value#isReleased()} is true
* before invoking any methods on this object.
*
* If any other references exist to this object, the object will not be
* reclaimed. Even if no reference exist, V8 does not give any guarantee
- * the object will be released, so this should only be used if there is no
+ * the object will be closed, so this should only be used if there is no
* other way to track object usage.
*
* @return The receiver.
@@ -222,6 +233,24 @@ public V8Value setWeak() {
return this;
}
+ /**
+ * Clears any weak reference set on this V8Value and makes this a strong
+ * reference. Strong references will not be garbage collected and this
+ * Object must be explicitly released.
+ *
+ * Calling clearWeak does nothing if the object is not currently set
+ * to weak.
+ *
+ * @return The receiver.
+ */
+ public V8Value clearWeak() {
+ v8.checkThread();
+ v8.checkReleased();
+ v8.v8WeakReferences.remove(getHandle());
+ v8.clearWeak(v8.getV8RuntimePtr(), getHandle());
+ return this;
+ }
+
/**
* If {@link V8Value#setWeak()} has been called on this Object, this method
* will return true. Otherwise it will return false.
@@ -234,11 +263,12 @@ public boolean isWeak() {
return v8.isWeak(v8.getV8RuntimePtr(), getHandle());
}
- /**
- * Releases the native resources associated with this V8Value.
+ /*
+ * (non-Javadoc)
+ * @see java.io.Closeable#close()
*/
@Override
- public void release() {
+ public void close() {
v8.checkThread();
if (!released) {
try {
@@ -250,6 +280,17 @@ public void release() {
}
}
+ /**
+ * Releases the native resources associated with this V8Value.
+ *
+ * @deprecated use close() instead.
+ */
+ @Override
+ @Deprecated
+ public void release() {
+ close();
+ }
+
/**
* Determine if the native resources have been released. Once released
* a V8 Value can no longer be used.
diff --git a/src/main/java/com/eclipsesource/v8/debug/DebugHandler.java b/src/main/java/com/eclipsesource/v8/debug/DebugHandler.java
index 6346d40..ffb680d 100644
--- a/src/main/java/com/eclipsesource/v8/debug/DebugHandler.java
+++ b/src/main/java/com/eclipsesource/v8/debug/DebugHandler.java
@@ -105,7 +105,7 @@ public int setBreakpoint(final V8Function function) {
try {
return debugObject.executeIntegerFunction(SET_BREAK_POINT, parameters);
} finally {
- parameters.release();
+ parameters.close();
}
}
@@ -124,7 +124,7 @@ public int setScriptBreakpoint(final String scriptID, final int lineNumber) {
try {
return debugObject.executeIntegerFunction(SET_SCRIPT_BREAK_POINT_BY_NAME, parameters);
} finally {
- parameters.release();
+ parameters.close();
}
}
@@ -139,7 +139,7 @@ public void enableScriptBreakPoint(final int breakpointID) {
try {
debugObject.executeVoidFunction(ENABLE_SCRIPT_BREAK_POINT, parameters);
} finally {
- parameters.release();
+ parameters.close();
}
}
@@ -154,7 +154,7 @@ public void disableScriptBreakPoint(final int breakpointID) {
try {
debugObject.executeVoidFunction(DISABLE_SCRIPT_BREAK_POINT, parameters);
} finally {
- parameters.release();
+ parameters.close();
}
}
@@ -169,7 +169,7 @@ public void clearBreakPoint(final int breakpointID) {
try {
debugObject.executeVoidFunction(CLEAR_BREAK_POINT, parameters);
} finally {
- parameters.release();
+ parameters.close();
}
}
@@ -190,7 +190,7 @@ public int getScriptBreakPointCount() {
try {
return breakPoints.length();
} finally {
- breakPoints.release();
+ breakPoints.close();
}
}
@@ -208,12 +208,12 @@ public int[] getScriptBreakPointIDs() {
try {
result[i] = breakPoint.executeIntegerFunction(NUMBER, null);
} finally {
- breakPoint.release();
+ breakPoint.close();
}
}
return result;
} finally {
- breakPoints.release();
+ breakPoints.close();
}
}
@@ -232,9 +232,9 @@ public ScriptBreakPoint getScriptBreakPoint(final int breakPointID) {
scriptBreakPoint = debugObject.executeObjectFunction(FIND_SCRIPT_BREAK_POINT, parameters);
return new ScriptBreakPoint(scriptBreakPoint);
} finally {
- parameters.release();
+ parameters.close();
if (scriptBreakPoint != null) {
- scriptBreakPoint.release();
+ scriptBreakPoint.close();
}
}
}
@@ -252,13 +252,23 @@ public void changeBreakPointCondition(final int breakpointID, final String condi
try {
debugObject.executeVoidFunction(CHANGE_BREAK_POINT_CONDITION, parameters);
} finally {
- parameters.release();
+ parameters.close();
}
}
+ /*
+ * (non-Javadoc)
+ * @see java.io.Closeable#close()
+ */
+ @Override
+ public void close() {
+ debugObject.close();
+ }
+
@Override
+ @Deprecated
public void release() {
- debugObject.release();
+ close();
}
private void setupDebugObject(final V8 runtime) {
@@ -266,7 +276,7 @@ private void setupDebugObject(final V8 runtime) {
try {
debugObject = outerDebug.getObject(V8_DEBUG_OBJECT);
} finally {
- outerDebug.release();
+ outerDebug.close();
}
}
@@ -277,14 +287,15 @@ private void setupBreakpointHandler() {
V8Array parameters = null;
try {
debugHandler = (V8Function) debugObject.getObject(DEBUG_BREAK_HANDLER);
- parameters = new V8Array(runtime).push(debugHandler);
+ parameters = new V8Array(runtime);
+ parameters.push(debugHandler);
debugObject.executeFunction(SET_LISTENER, parameters);
} finally {
if ((debugHandler != null) && !debugHandler.isReleased()) {
- debugHandler.release();
+ debugHandler.close();
}
if ((parameters != null) && !parameters.isReleased()) {
- parameters.release();
+ parameters.close();
}
}
}
diff --git a/src/main/java/com/eclipsesource/v8/debug/EventData.java b/src/main/java/com/eclipsesource/v8/debug/EventData.java
index e31342e..8b58a9c 100644
--- a/src/main/java/com/eclipsesource/v8/debug/EventData.java
+++ b/src/main/java/com/eclipsesource/v8/debug/EventData.java
@@ -25,10 +25,16 @@ public class EventData implements Releasable {
}
@Override
- public void release() {
+ public void close() {
if (!v8Object.isReleased()) {
- v8Object.release();
+ v8Object.close();
}
}
+ @Override
+ @Deprecated
+ public void release() {
+ close();
+ }
+
}
diff --git a/src/main/java/com/eclipsesource/v8/debug/ExecutionState.java b/src/main/java/com/eclipsesource/v8/debug/ExecutionState.java
index 77dad6f..43adb1b 100644
--- a/src/main/java/com/eclipsesource/v8/debug/ExecutionState.java
+++ b/src/main/java/com/eclipsesource/v8/debug/ExecutionState.java
@@ -58,7 +58,7 @@ public void prepareStep(final StepAction action) {
try {
v8Object.executeVoidFunction(PREPARE_STEP, parameters);
} finally {
- parameters.release();
+ parameters.close();
}
}
@@ -76,19 +76,25 @@ public Frame getFrame(final int index) {
frame = v8Object.executeObjectFunction(FRAME, parameters);
return new Frame(frame);
} finally {
- parameters.release();
+ parameters.close();
if (frame != null) {
- frame.release();
+ frame.close();
}
}
}
@Override
- public void release() {
+ public void close() {
if ((v8Object != null) && !v8Object.isReleased()) {
- v8Object.release();
+ v8Object.close();
v8Object = null;
}
}
+ @Override
+ @Deprecated
+ public void release() {
+ close();
+ }
+
}
\ No newline at end of file
diff --git a/src/main/java/com/eclipsesource/v8/debug/ScriptBreakPoint.java b/src/main/java/com/eclipsesource/v8/debug/ScriptBreakPoint.java
index 850c14b..d91ccc9 100644
--- a/src/main/java/com/eclipsesource/v8/debug/ScriptBreakPoint.java
+++ b/src/main/java/com/eclipsesource/v8/debug/ScriptBreakPoint.java
@@ -61,7 +61,7 @@ public void setCondition(final String condition) {
try {
v8Object.executeVoidFunction(SET_CONDITION, parameters);
} finally {
- parameters.release();
+ parameters.close();
}
}
@@ -80,10 +80,15 @@ public String getCondition() {
}
@Override
- public void release() {
+ public void close() {
if ((v8Object != null) && !v8Object.isReleased()) {
- v8Object.release();
+ v8Object.close();
v8Object = null;
}
}
+
+ @Override
+ public void release() {
+ close();
+ }
}
diff --git a/src/main/java/com/eclipsesource/v8/debug/V8DebugServer.java b/src/main/java/com/eclipsesource/v8/debug/V8DebugServer.java
index 8acbd44..f0e957d 100644
--- a/src/main/java/com/eclipsesource/v8/debug/V8DebugServer.java
+++ b/src/main/java/com/eclipsesource/v8/debug/V8DebugServer.java
@@ -141,7 +141,7 @@ public V8DebugServer(final V8 runtime, final int port, final boolean waitForConn
try {
debugObject = debugScope.getObject(V8_DEBUG_OBJECT);
} finally {
- debugScope.release();
+ debugScope.close();
}
runtime.executeVoidScript("(function() {\n"
@@ -236,15 +236,15 @@ public void stop() {
//release resources
if (runningStateDcp != null) {
- runningStateDcp.release();
+ runningStateDcp.close();
runningStateDcp = null;
}
if (debugObject != null) {
- debugObject.release();
+ debugObject.close();
debugObject = null;
}
if (stoppedStateDcp != null) {
- stoppedStateDcp.release();
+ stoppedStateDcp.close();
stoppedStateDcp = null;
}
};
@@ -329,6 +329,7 @@ private void processRequest(final String message) throws IOException {
V8Array params = new V8Array(runtime);
params.push(message);
+ @SuppressWarnings("resource")
V8Object dcp = stoppedStateDcp != null ? stoppedStateDcp : runningStateDcp;
Object result = dcp.executeFunction("processDebugJSONRequest", params);
@@ -356,14 +357,15 @@ private void setupEventHandler() {
V8Array parameters = null;
try {
debugHandler = (V8Function) debugObject.getObject(DEBUG_BREAK_HANDLER);
- parameters = new V8Array(runtime).push(debugHandler);
+ parameters = new V8Array(runtime);
+ parameters.push(debugHandler);
debugObject.executeFunction(SET_LISTENER, parameters);
} finally {
if ((debugHandler != null) && !debugHandler.isReleased()) {
- debugHandler.release();
+ debugHandler.close();
}
if ((parameters != null) && !parameters.isReleased()) {
- parameters.release();
+ parameters.close();
}
}
}
@@ -375,7 +377,7 @@ private void enterBreakLoop(final V8Object execState, final V8Object eventData)
params.push(false);
stoppedStateDcp = execState.executeObjectFunction("debugCommandProcessor", params);
} finally {
- params.release();
+ params.close();
}
//send event to debugger
@@ -394,10 +396,10 @@ private void enterBreakLoop(final V8Object execState, final V8Object eventData)
}
sendJson(json);
} finally {
- params.release();
- breakpointsHit.release();
+ params.close();
+ breakpointsHit.close();
if (event != null) {
- event.release();
+ event.close();
}
}
@@ -410,7 +412,7 @@ private void enterBreakLoop(final V8Object execState, final V8Object eventData)
}
}
} finally {
- stoppedStateDcp.release();
+ stoppedStateDcp.close();
stoppedStateDcp = null;
}
}
@@ -437,10 +439,10 @@ private void sendCompileEvent(final V8Object eventData) throws IOException {
sendJson(json);
}
} finally {
- params.release();
- script.release();
+ params.close();
+ script.close();
if (event != null) {
- event.release();
+ event.close();
}
}
}
diff --git a/src/main/java/com/eclipsesource/v8/debug/mirror/Frame.java b/src/main/java/com/eclipsesource/v8/debug/mirror/Frame.java
index 99ab845..f06c838 100644
--- a/src/main/java/com/eclipsesource/v8/debug/mirror/Frame.java
+++ b/src/main/java/com/eclipsesource/v8/debug/mirror/Frame.java
@@ -63,7 +63,7 @@ public SourceLocation getSourceLocation() {
V8Object scriptObject = (V8Object) sourceLocation.get(SCRIPT);
if (scriptObject != null) {
scriptName = scriptObject.getString(NAME);
- scriptObject.release();
+ scriptObject.close();
}
if ((scriptName == null) && (functionScriptName != null)) {
scriptName = functionScriptName;
@@ -76,8 +76,8 @@ public SourceLocation getSourceLocation() {
sourceLocation.getInteger(COLUMN),
sourceLocation.getString(SOURCE_TEXT));
} finally {
- function.release();
- sourceLocation.release();
+ function.close();
+ sourceLocation.close();
}
}
@@ -102,7 +102,7 @@ public String getArgumentName(final int index) {
try {
return v8Object.executeStringFunction(ARGUMENT_NAME, parameters);
} finally {
- parameters.release();
+ parameters.close();
}
}
@@ -123,9 +123,9 @@ public ValueMirror getArgumentValue(final int index) {
}
return new ValueMirror(result);
} finally {
- parameters.release();
+ parameters.close();
if (result != null) {
- result.release();
+ result.close();
}
}
}
@@ -147,9 +147,9 @@ public ValueMirror getLocalValue(final int index) {
}
return createMirror(result);
} finally {
- parameters.release();
+ parameters.close();
if (result != null) {
- result.release();
+ result.close();
}
}
}
@@ -175,7 +175,7 @@ public String getLocalName(final int index) {
try {
return v8Object.executeStringFunction(LOCAL_NAME, parameters);
} finally {
- parameters.release();
+ parameters.close();
}
}
@@ -193,9 +193,9 @@ public Scope getScope(final int index) {
scope = v8Object.executeObjectFunction(SCOPE, parameters);
return new Scope(scope);
} finally {
- parameters.release();
+ parameters.close();
if (scope != null) {
- scope.release();
+ scope.close();
}
}
}
@@ -212,7 +212,7 @@ public FunctionMirror getFunction() {
return new FunctionMirror(function);
} finally {
if (function != null) {
- function.release();
+ function.close();
}
}
}
diff --git a/src/main/java/com/eclipsesource/v8/debug/mirror/FunctionMirror.java b/src/main/java/com/eclipsesource/v8/debug/mirror/FunctionMirror.java
index 57bb434..fb5fea4 100644
--- a/src/main/java/com/eclipsesource/v8/debug/mirror/FunctionMirror.java
+++ b/src/main/java/com/eclipsesource/v8/debug/mirror/FunctionMirror.java
@@ -44,7 +44,7 @@ public String getScriptName() {
try {
return script.executeStringFunction(NAME, null);
} finally {
- script.release();
+ script.close();
}
}
diff --git a/src/main/java/com/eclipsesource/v8/debug/mirror/Mirror.java b/src/main/java/com/eclipsesource/v8/debug/mirror/Mirror.java
index 9b8eaa3..3dc5e02 100644
--- a/src/main/java/com/eclipsesource/v8/debug/mirror/Mirror.java
+++ b/src/main/java/com/eclipsesource/v8/debug/mirror/Mirror.java
@@ -156,14 +156,28 @@ public boolean isProperty() {
return false;
}
+ /*
+ * (non-Javadoc)
+ * @see java.io.Closeable#close()
+ */
@Override
- public void release() {
+ public void close() {
if ((v8Object != null) && !v8Object.isReleased()) {
- v8Object.release();
+ v8Object.close();
v8Object = null;
}
}
+ /*
+ * (non-Javadoc)
+ * @see com.eclipsesource.v8.Releasable#release()
+ */
+ @Override
+ @Deprecated
+ public void release() {
+ close();
+ }
+
protected static boolean isValue(final V8Object mirror) {
try {
return mirror.executeBooleanFunction(IS_VALUE, null);
diff --git a/src/main/java/com/eclipsesource/v8/debug/mirror/ObjectMirror.java b/src/main/java/com/eclipsesource/v8/debug/mirror/ObjectMirror.java
index b9a5e8b..11131d6 100644
--- a/src/main/java/com/eclipsesource/v8/debug/mirror/ObjectMirror.java
+++ b/src/main/java/com/eclipsesource/v8/debug/mirror/ObjectMirror.java
@@ -64,9 +64,9 @@ public String[] getPropertyNames(final PropertyKind kind, final int limit) {
}
return result;
} finally {
- parameters.release();
+ parameters.close();
if (propertyNames != null) {
- propertyNames.release();
+ propertyNames.close();
}
}
}
@@ -87,9 +87,9 @@ public PropertiesArray getProperties(final PropertyKind kind, final int limit) {
result = v8Object.executeArrayFunction(PROPERTIES, parameters);
return new PropertiesArray(result);
} finally {
- parameters.release();
+ parameters.close();
if ((result != null) && !result.isReleased()) {
- result.release();
+ result.close();
result = null;
}
}
diff --git a/src/main/java/com/eclipsesource/v8/debug/mirror/PropertiesArray.java b/src/main/java/com/eclipsesource/v8/debug/mirror/PropertiesArray.java
index c247e9e..e9cea1e 100644
--- a/src/main/java/com/eclipsesource/v8/debug/mirror/PropertiesArray.java
+++ b/src/main/java/com/eclipsesource/v8/debug/mirror/PropertiesArray.java
@@ -36,17 +36,31 @@ public PropertyMirror getProperty(final int index) {
try {
return new PropertyMirror(result);
} finally {
- result.release();
+ result.close();
}
}
+ /*
+ * (non-Javadoc)
+ * @see java.io.Closeable#close()
+ */
@Override
- public void release() {
+ public void close() {
if (!v8Array.isReleased()) {
- v8Array.release();
+ v8Array.close();
}
}
+ /*
+ * (non-Javadoc)
+ * @see com.eclipsesource.v8.Releasable#release()
+ */
+ @Override
+ @Deprecated
+ public void release() {
+ close();
+ }
+
/**
* Returns the number of properties contained in this array.
*
diff --git a/src/main/java/com/eclipsesource/v8/debug/mirror/PropertyMirror.java b/src/main/java/com/eclipsesource/v8/debug/mirror/PropertyMirror.java
index be94c76..235f657 100644
--- a/src/main/java/com/eclipsesource/v8/debug/mirror/PropertyMirror.java
+++ b/src/main/java/com/eclipsesource/v8/debug/mirror/PropertyMirror.java
@@ -40,7 +40,7 @@ public Mirror getValue() {
try {
return createMirror(mirror);
} finally {
- mirror.release();
+ mirror.close();
}
}
diff --git a/src/main/java/com/eclipsesource/v8/debug/mirror/Scope.java b/src/main/java/com/eclipsesource/v8/debug/mirror/Scope.java
index 8203206..9c3b0d2 100644
--- a/src/main/java/com/eclipsesource/v8/debug/mirror/Scope.java
+++ b/src/main/java/com/eclipsesource/v8/debug/mirror/Scope.java
@@ -63,7 +63,7 @@ public void setVariableValue(final String name, final int value) {
try {
v8Object.executeVoidFunction(SET_VARIABLE_VALUE, parameters);
} finally {
- parameters.release();
+ parameters.close();
}
}
@@ -80,7 +80,7 @@ public void setVariableValue(final String name, final V8Value value) {
try {
v8Object.executeVoidFunction(SET_VARIABLE_VALUE, parameters);
} finally {
- parameters.release();
+ parameters.close();
}
}
@@ -97,7 +97,7 @@ public void setVariableValue(final String name, final boolean value) {
try {
v8Object.executeVoidFunction(SET_VARIABLE_VALUE, parameters);
} finally {
- parameters.release();
+ parameters.close();
}
}
@@ -114,7 +114,7 @@ public void setVariableValue(final String name, final String value) {
try {
v8Object.executeVoidFunction(SET_VARIABLE_VALUE, parameters);
} finally {
- parameters.release();
+ parameters.close();
}
}
@@ -131,7 +131,7 @@ public void setVariableValue(final String name, final double value) {
try {
v8Object.executeVoidFunction(SET_VARIABLE_VALUE, parameters);
} finally {
- parameters.release();
+ parameters.close();
}
}
@@ -147,7 +147,7 @@ public ObjectMirror getScopeObject() {
return (ObjectMirror) createMirror(mirror);
} finally {
if ( mirror != null ) {
- mirror.release();
+ mirror.close();
}
}
diff --git a/src/main/java/com/eclipsesource/v8/inspector/DebuggerConnectionListener.java b/src/main/java/com/eclipsesource/v8/inspector/DebuggerConnectionListener.java
new file mode 100644
index 0000000..de1d9b5
--- /dev/null
+++ b/src/main/java/com/eclipsesource/v8/inspector/DebuggerConnectionListener.java
@@ -0,0 +1,7 @@
+package com.eclipsesource.v8.inspector;
+
+public interface DebuggerConnectionListener {
+ public void onDebuggerConnected();
+
+ public void onDebuggerDisconnected();
+}
diff --git a/src/main/java/com/eclipsesource/v8/inspector/V8Inspector.java b/src/main/java/com/eclipsesource/v8/inspector/V8Inspector.java
new file mode 100644
index 0000000..2034fcd
--- /dev/null
+++ b/src/main/java/com/eclipsesource/v8/inspector/V8Inspector.java
@@ -0,0 +1,67 @@
+package com.eclipsesource.v8.inspector;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import com.eclipsesource.v8.V8;
+import com.eclipsesource.v8.V8Object;
+
+public class V8Inspector {
+
+ private V8 runtime;
+ private long inspectorPtr = 0;
+ private boolean waitingForConnection = true;
+ private List debuggerConnectionListeners;
+
+ protected V8Inspector(final V8 runtime, final V8InspectorDelegate inspectorDelegate, final String contextName) {
+ this.runtime = runtime;
+ inspectorPtr = runtime.createInspector(inspectorDelegate, contextName);
+ debuggerConnectionListeners = new ArrayList();
+ }
+
+ public static V8Inspector createV8Inspector(final V8 runtime, final V8InspectorDelegate inspectorDelegate, final String contextName) {
+ return new V8Inspector(runtime, inspectorDelegate, contextName);
+ }
+
+ public static V8Inspector createV8Inspector(final V8 runtime, final V8InspectorDelegate inspectorDelegate) {
+ return new V8Inspector(runtime, inspectorDelegate, null);
+ }
+
+ public void dispatchProtocolMessage(final String protocolMessage) {
+ try {
+ runtime.dispatchProtocolMessage(inspectorPtr, protocolMessage);
+ if (waitingForConnection) {
+ verifyDebuggerConnection(protocolMessage);
+ }
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+
+ public void addDebuggerConnectionListener(final DebuggerConnectionListener listener) {
+ debuggerConnectionListeners.add(listener);
+ }
+
+ public void removeDebuggerConnectionListener(final DebuggerConnectionListener listener) {
+ debuggerConnectionListeners.remove(listener);
+ }
+
+ private void verifyDebuggerConnection(final String protocolMessage) {
+ V8Object json = null;
+ try {
+ json = runtime.executeObjectScript("JSON.parse(JSON.stringify(" + protocolMessage + "))");
+ if (json.getString("method").equals("Runtime.runIfWaitingForDebugger")) {
+ waitingForConnection = false;
+ runtime.schedulePauseOnNextStatement(inspectorPtr, "");
+ for (DebuggerConnectionListener listener : debuggerConnectionListeners) {
+ listener.onDebuggerConnected();
+ }
+ }
+ } finally {
+ if (json != null) {
+ json.close();
+ }
+ }
+ }
+
+}
diff --git a/src/main/java/com/eclipsesource/v8/inspector/V8InspectorDelegate.java b/src/main/java/com/eclipsesource/v8/inspector/V8InspectorDelegate.java
new file mode 100644
index 0000000..c799dcc
--- /dev/null
+++ b/src/main/java/com/eclipsesource/v8/inspector/V8InspectorDelegate.java
@@ -0,0 +1,7 @@
+package com.eclipsesource.v8.inspector;
+
+public interface V8InspectorDelegate {
+ public void onResponse(String message);
+
+ public void waitFrontendMessageOnPause();
+}
diff --git a/src/main/java/com/eclipsesource/v8/utils/ArrayBuffer.java b/src/main/java/com/eclipsesource/v8/utils/ArrayBuffer.java
new file mode 100644
index 0000000..d1a39b8
--- /dev/null
+++ b/src/main/java/com/eclipsesource/v8/utils/ArrayBuffer.java
@@ -0,0 +1,69 @@
+package com.eclipsesource.v8.utils;
+/*******************************************************************************
+ * Copyright (c) 2019 EclipseSource and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * EclipseSource - initial API and implementation
+ ******************************************************************************/
+
+import java.nio.ByteBuffer;
+
+import com.eclipsesource.v8.V8;
+import com.eclipsesource.v8.V8ArrayBuffer;
+
+/**
+ * A lightweight handle to a V8TypedArray. This handle provides
+ * access to a V8TypedArray. This handle does not need to be
+ * closed, but if the type array is accessed using getV8TypedArray
+ * then the result must be closed.
+ *
+ * The underlying V8TypedArray may be reclaimed by the JavaScript
+ * garbage collector. To check if it's still available, use
+ * isAvailable.
+ */
+public class ArrayBuffer {
+
+ private V8ArrayBuffer arrayBuffer;
+
+ ArrayBuffer(final V8ArrayBuffer arrayBuffer) {
+ this.arrayBuffer = (V8ArrayBuffer) arrayBuffer.twin().setWeak();
+ }
+
+ /**
+ * Create a new ArrayBuffer from a java.nio.ByteBuffer
+ *
+ * @param v8 the Runtime on which to create the ArrayBuffer
+ * @param byteBuffer the ByteBuffer to use to back the ArrayBuffer
+ */
+ public ArrayBuffer(final V8 v8, final ByteBuffer byteBuffer) {
+ V8ArrayBuffer v8ArrayBuffer = new V8ArrayBuffer(v8, byteBuffer);
+ try {
+ arrayBuffer = (V8ArrayBuffer) v8ArrayBuffer.twin().setWeak();
+ } finally {
+ v8ArrayBuffer.close();
+ }
+ }
+
+ /**
+ * Determine if the underlying V8ArrayBuffer is still available, or if it's been cleaned up by the JavaScript
+ * garbage collector.
+ *
+ * @return true if the underlying V8ArrayBuffer is still available, false otherwise.
+ */
+ public boolean isAvailable() {
+ return !arrayBuffer.isReleased();
+ }
+
+ /**
+ * Returns the underlying V8ArrayBuffer.
+ * @return the underlying V8ArrayBuffer.
+ */
+ public V8ArrayBuffer getV8ArrayBuffer() {
+ return arrayBuffer.twin();
+ }
+
+}
diff --git a/src/main/java/com/eclipsesource/v8/utils/ConcurrentV8.java b/src/main/java/com/eclipsesource/v8/utils/ConcurrentV8.java
index e3b75e4..a1b9d60 100644
--- a/src/main/java/com/eclipsesource/v8/utils/ConcurrentV8.java
+++ b/src/main/java/com/eclipsesource/v8/utils/ConcurrentV8.java
@@ -85,7 +85,7 @@ public void release() {
@Override
public void run(final V8 v8) {
if ((v8 != null) && !v8.isReleased()) {
- v8.release();
+ v8.close();
}
}
});
diff --git a/src/main/java/com/eclipsesource/v8/utils/MemoryManager.java b/src/main/java/com/eclipsesource/v8/utils/MemoryManager.java
index ddb4f88..7f236ae 100644
--- a/src/main/java/com/eclipsesource/v8/utils/MemoryManager.java
+++ b/src/main/java/com/eclipsesource/v8/utils/MemoryManager.java
@@ -98,7 +98,7 @@ public void release() {
releasing = true;
try {
for (V8Value reference : references) {
- reference.release();
+ reference.close();
}
v8.removeReferenceHandler(memoryManagerReferenceHandler);
references.clear();
diff --git a/src/main/java/com/eclipsesource/v8/utils/TypedArray.java b/src/main/java/com/eclipsesource/v8/utils/TypedArray.java
new file mode 100644
index 0000000..1c1616a
--- /dev/null
+++ b/src/main/java/com/eclipsesource/v8/utils/TypedArray.java
@@ -0,0 +1,73 @@
+package com.eclipsesource.v8.utils;
+/*******************************************************************************
+ * Copyright (c) 2019 EclipseSource and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * EclipseSource - initial API and implementation
+ ******************************************************************************/
+
+import com.eclipsesource.v8.V8;
+import com.eclipsesource.v8.V8ArrayBuffer;
+import com.eclipsesource.v8.V8TypedArray;
+
+/**
+ * A lightweight handle to a V8TypedArray. This handle provides
+ * access to a V8TypedArray. This handle does not need to be
+ * closed, but if the type array is accessed using getV8TypedArray
+ * then the result must be closed.
+ *
+ * The underlying V8TypedArray may be reclaimed by the JavaScript
+ * garbage collector. To check if it's still available, use
+ * isAvailable.
+ */
+public class TypedArray {
+
+ private V8TypedArray typedArray;
+
+ TypedArray(final V8TypedArray typedArray) {
+ this.typedArray = (V8TypedArray) typedArray.twin().setWeak();
+ }
+
+ /**
+ * Create a new TypedArray from an ArrayBuffer.
+ *
+ * @param v8 the V8Runtime on which to create the TypedArray
+ * @param buffer the ArrayBuffer to use to back the TypedArray
+ * @param type the Type of Array to create
+ * @param offset the Offset into the ArrayBuffer in which to map the TyepdArray
+ * @param size the Size of the TypedArray
+ */
+ public TypedArray(final V8 v8, final ArrayBuffer buffer, final int type, final int offset, final int size) {
+ V8ArrayBuffer v8ArrayBuffer = buffer.getV8ArrayBuffer();
+ V8TypedArray v8typedArray = new V8TypedArray(v8, v8ArrayBuffer, type, offset, size);
+ try {
+ typedArray = (V8TypedArray) v8typedArray.twin().setWeak();
+ } finally {
+ v8ArrayBuffer.close();
+ v8typedArray.close();
+ }
+ }
+
+ /**
+ * Determine if the underlying V8TypedArray is still available, or if it's been cleaned up by the JavaScript
+ * garbage collector.
+ *
+ * @return true if the underlying V8TypedArray is still available, false otherwise.
+ */
+ public boolean isAvailable() {
+ return !typedArray.isReleased();
+ }
+
+ /**
+ * Returns the underlying V8TypedArray.
+ * @return the underlying V8TypedArray.
+ */
+ public V8TypedArray getV8TypedArray() {
+ return (V8TypedArray) typedArray.twin();
+ }
+
+}
diff --git a/src/main/java/com/eclipsesource/v8/utils/V8Executor.java b/src/main/java/com/eclipsesource/v8/utils/V8Executor.java
index 50f8c34..881a229 100644
--- a/src/main/java/com/eclipsesource/v8/utils/V8Executor.java
+++ b/src/main/java/com/eclipsesource/v8/utils/V8Executor.java
@@ -125,9 +125,6 @@ public void run() {
if (scriptResult instanceof Releasable) {
((Releasable) scriptResult).release();
}
- if (scriptResult instanceof Releasable) {
- ((Releasable) scriptResult).release();
- }
}
while (!forceTerminating && longRunning) {
synchronized (this) {
@@ -149,8 +146,8 @@ public void run() {
parameters.push(strings);
runtime.executeVoidFunction(messageHandler, parameters);
} finally {
- strings.release();
- parameters.release();
+ strings.close();
+ parameters.close();
}
}
}
@@ -159,7 +156,7 @@ public void run() {
} finally {
synchronized (this) {
if (runtime.getLocker().hasLock()) {
- runtime.release();
+ runtime.close();
runtime = null;
}
terminated = true;
diff --git a/src/main/java/com/eclipsesource/v8/utils/V8Map.java b/src/main/java/com/eclipsesource/v8/utils/V8Map.java
index 08343fb..fa8d58c 100644
--- a/src/main/java/com/eclipsesource/v8/utils/V8Map.java
+++ b/src/main/java/com/eclipsesource/v8/utils/V8Map.java
@@ -40,14 +40,24 @@ public V8Map() {
twinMap = new HashMap();
}
+ /*
+ * (non-Javadoc)
+ * @see java.io.Closeable#close()
+ */
+ @Override
+ public void close() {
+ this.clear();
+ }
+
/**
* Releases all the resources associated with this map. A
* map can be used again once it's released, although
* if it's used again it should be released again.
*/
@Override
+ @Deprecated
public void release() {
- this.clear();
+ close();
}
/*
@@ -116,7 +126,7 @@ public V remove(final Object key) {
V result = map.remove(key);
V8Value twin = twinMap.remove(key);
if (twin != null) {
- twin.release();
+ twin.close();
}
return result;
}
@@ -127,7 +137,7 @@ public V remove(final Object key) {
*/
@Override
public void putAll(final Map extends V8Value, ? extends V> m) {
- for (Entry extends V8Value, ? extends V> entry : m.entrySet()) {
+ for (java.util.Map.Entry extends V8Value, ? extends V> entry : m.entrySet()) {
this.put(entry.getKey(), entry.getValue());
}
}
@@ -140,7 +150,7 @@ public void putAll(final Map extends V8Value, ? extends V> m) {
public void clear() {
map.clear();
for (V8Value V8Value : twinMap.keySet()) {
- V8Value.release();
+ V8Value.close();
}
twinMap.clear();
}
@@ -168,7 +178,7 @@ public Collection values() {
* @see java.util.Map#entrySet()
*/
@Override
- public Set> entrySet() {
+ public Set> entrySet() {
return map.entrySet();
}
diff --git a/src/main/java/com/eclipsesource/v8/utils/V8ObjectUtils.java b/src/main/java/com/eclipsesource/v8/utils/V8ObjectUtils.java
index 736e3a4..b433565 100644
--- a/src/main/java/com/eclipsesource/v8/utils/V8ObjectUtils.java
+++ b/src/main/java/com/eclipsesource/v8/utils/V8ObjectUtils.java
@@ -10,7 +10,6 @@
******************************************************************************/
package com.eclipsesource.v8.utils;
-import java.nio.ByteBuffer;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Hashtable;
@@ -25,17 +24,6 @@
import com.eclipsesource.v8.V8Object;
import com.eclipsesource.v8.V8TypedArray;
import com.eclipsesource.v8.V8Value;
-import com.eclipsesource.v8.utils.typedarrays.ArrayBuffer;
-import com.eclipsesource.v8.utils.typedarrays.Float32Array;
-import com.eclipsesource.v8.utils.typedarrays.Float64Array;
-import com.eclipsesource.v8.utils.typedarrays.Int16Array;
-import com.eclipsesource.v8.utils.typedarrays.Int32Array;
-import com.eclipsesource.v8.utils.typedarrays.Int8Array;
-import com.eclipsesource.v8.utils.typedarrays.TypedArray;
-import com.eclipsesource.v8.utils.typedarrays.UInt16Array;
-import com.eclipsesource.v8.utils.typedarrays.UInt32Array;
-import com.eclipsesource.v8.utils.typedarrays.UInt8Array;
-import com.eclipsesource.v8.utils.typedarrays.UInt8ClampedArray;
/**
* A set of static helper methods to convert V8Objects / V8Arrays to
@@ -92,7 +80,7 @@ public static Object getValue(final Object v8Object, final TypeAdapter adapter)
return v8Object;
}
} finally {
- cache.release();
+ cache.close();
}
}
@@ -124,7 +112,7 @@ public static Object getValue(final Object v8Object, final TypeAdapter adapter)
try {
return toMap(object, cache, adapter);
} finally {
- cache.release();
+ cache.close();
}
}
@@ -156,7 +144,7 @@ public static List super Object> toList(final V8Array array, final TypeAdapter
try {
return toList(array, cache, adapter);
} finally {
- cache.release();
+ cache.close();
}
}
@@ -258,7 +246,7 @@ public static V8Object toV8Object(final V8 v8, final Map list)
return toV8Array(v8, list, cache).twin();
} finally {
for (V8Value v8Object : cache.values()) {
- v8Object.release();
+ v8Object.close();
}
}
}
@@ -310,7 +298,7 @@ public static Object getV8Result(final V8 v8, final Object value) {
return result;
} finally {
for (V8Value v8Object : cache.values()) {
- v8Object.release();
+ v8Object.close();
}
}
}
@@ -331,7 +319,7 @@ public static void pushValue(final V8 v8, final V8Array array, final Object valu
pushValue(v8, array, value, cache);
} finally {
for (V8Value v8Object : cache.values()) {
- v8Object.release();
+ v8Object.close();
}
}
}
@@ -355,12 +343,16 @@ public static Object getValue(final V8Array array, final int index) {
try {
object = array.get(index);
type = array.getType(index);
- return getValue(object, type, cache, DEFAULT_TYPE_ADAPTER);
+ Object result = getValue(object, type, cache, DEFAULT_TYPE_ADAPTER);
+ if ((result == object) && (result instanceof V8Value)) {
+ return ((V8Value) result).twin();
+ }
+ return result;
} finally {
if (object instanceof Releasable) {
((Releasable) object).release();
}
- cache.release();
+ cache.close();
}
}
@@ -385,12 +377,16 @@ public static Object getValue(final V8Array array, final int index, final TypeAd
try {
object = array.get(index);
type = array.getType(index);
- return getValue(object, type, cache, adapter);
+ Object result = getValue(object, type, cache, adapter);
+ if ((result == object) && (result instanceof V8Value)) {
+ return ((V8Value) result).twin();
+ }
+ return result;
} finally {
if (object instanceof Releasable) {
((Releasable) object).release();
}
- cache.release();
+ cache.close();
}
}
@@ -431,12 +427,16 @@ public static Object getValue(final V8Object v8Object, final String key, final T
try {
object = v8Object.get(key);
type = v8Object.getType(key);
- return getValue(object, type, cache, adapter);
+ Object result = getValue(object, type, cache, adapter);
+ if ((result == object) && (result instanceof V8Value)) {
+ return ((V8Value) result).twin();
+ }
+ return result;
} finally {
if (object instanceof Releasable) {
((Releasable) object).release();
}
- cache.release();
+ cache.close();
}
}
@@ -499,6 +499,24 @@ private static List super Object> toList(final V8Array array, final V8Map cache) {
+ if (cache.containsKey(typeArray)) {
+ return (V8TypedArray) cache.get(typeArray);
+ }
+ V8TypedArray result = typeArray.getV8TypedArray();
+ cache.put(typeArray, result);
+ return result;
+ }
+
+ private static V8ArrayBuffer toV8ArrayBuffer(final V8 v8, final ArrayBuffer arrayBuffer, final Map