Browse Source

auto-detect V8 sandbox and call InitializeSandbox if needed

Stefan Siegl 2 years ago
parent
commit
26de750e8e
2 changed files with 19 additions and 1 deletions
  1. 18 0
      config.m4
  2. 1 1
      v8js_v8.cc

+ 18 - 0
config.m4

@@ -177,6 +177,24 @@ int main ()
   V8_SEARCH_BLOB([snapshot_blob.bin], [PHP_V8_SNAPSHOT_BLOB_PATH])
   V8_SEARCH_BLOB([snapshot_blob.bin], [PHP_V8_SNAPSHOT_BLOB_PATH])
 
 
 
 
+  dnl
+  dnl  Check for v8::V8::InitializeSandbox
+  dnl
+  AC_CACHE_CHECK([for v8::V8::InitializeSandbox], ac_cv_has_initialize_sandbox, [
+    AC_LINK_IFELSE([AC_LANG_PROGRAM([
+      #define V8_ENABLE_SANDBOX 1
+      #include <v8.h>
+    ], [ v8::V8::InitializeSandbox(); ])], [
+      ac_cv_has_initialize_sandbox=yes
+    ], [
+      ac_cv_has_initialize_sandbox=no
+    ])
+  ])
+  if test "x$ac_cv_has_initialize_sandbox" = "xyes"; then
+    AC_DEFINE([V8_HAS_INITIALIZE_SANDBOX], [1],
+              [Define if V8::InitializeSandbox must be called.])
+  fi
+
   dnl
   dnl
   dnl  Check for v8::ArrayBuffer::Allocator::NewDefaultAllocator
   dnl  Check for v8::ArrayBuffer::Allocator::NewDefaultAllocator
   dnl
   dnl

+ 1 - 1
v8js_v8.cc

@@ -71,7 +71,7 @@ void v8js_v8_init() /* {{{ */
 	v8js_process_globals.v8_platform = v8::platform::NewDefaultPlatform();
 	v8js_process_globals.v8_platform = v8::platform::NewDefaultPlatform();
 	v8::V8::InitializePlatform(v8js_process_globals.v8_platform.get());
 	v8::V8::InitializePlatform(v8js_process_globals.v8_platform.get());
 
 
-#ifdef V8_ENABLE_SANDBOX
+#ifdef V8_HAS_INITIALIZE_SANDBOX
 	v8::V8::InitializeSandbox();
 	v8::V8::InitializeSandbox();
 #endif
 #endif