浏览代码

Provide ArrayBufferAllocator for v8 4.4.44 (and later)

Stefan Siegl 9 年之前
父节点
当前提交
493e448bae
共有 1 个文件被更改,包括 20 次插入0 次删除
  1. 20 0
      v8js_class.cc

+ 20 - 0
v8js_class.cc

@@ -65,6 +65,17 @@ struct v8js_jsext {
 };
 /* }}} */
 
+#if PHP_V8_API_VERSION >= 4004044
+class ArrayBufferAllocator : public v8::ArrayBuffer::Allocator {
+public:
+	virtual void* Allocate(size_t length) {
+		void* data = AllocateUninitialized(length);
+		return data == NULL ? data : memset(data, 0, length);
+	}
+	virtual void* AllocateUninitialized(size_t length) { return malloc(length); }
+	virtual void Free(void* data, size_t) { free(data); }
+};
+#endif
 
 static void v8js_free_storage(void *object TSRMLS_DC) /* {{{ */
 {
@@ -303,7 +314,16 @@ static PHP_METHOD(V8Js, __construct)
 	c->report_uncaught = report_uncaught;
 	c->pending_exception = NULL;
 	c->in_execution = 0;
+
+#if PHP_V8_API_VERSION >= 4004044
+	static ArrayBufferAllocator array_buffer_allocator;
+	static v8::Isolate::CreateParams create_params;
+	create_params.array_buffer_allocator = &array_buffer_allocator;
+	c->isolate = v8::Isolate::New(create_params);
+#else
 	c->isolate = v8::Isolate::New();
+#endif
+
 	c->isolate->SetData(0, c);
 
 	c->time_limit = 0;