Add support for V8 ArrayBuffers (issue #244)

This commit is contained in:
Christopher Cifra
2018-04-10 15:37:33 -04:00
committed by Marshall Greenblatt
parent bb28b85bdd
commit 4315f3b724
16 changed files with 775 additions and 8 deletions

View File

@ -33,7 +33,7 @@
// by hand. See the translator.README.txt file in the tools directory for
// more information.
//
// $hash=e9e43167b1cf8033bd7e6ba6931213d7cf4b69b5$
// $hash=2303574e76708e5311aede8e66eb7f1f679e0d1f$
//
#ifndef CEF_INCLUDE_CAPI_CEF_V8_CAPI_H_
@ -355,6 +355,25 @@ typedef struct _cef_v8exception_t {
int(CEF_CALLBACK* get_end_column)(struct _cef_v8exception_t* self);
} cef_v8exception_t;
///
// Callback structure that is passed to cef_v8value_t::CreateArrayBuffer.
///
typedef struct _cef_v8array_buffer_release_callback_t {
///
// Base structure.
///
cef_base_ref_counted_t base;
///
// Called to release |buffer| when the ArrayBuffer JS object is garbage
// collected. |buffer| is the value that was passed to CreateArrayBuffer along
// with this object.
///
void(CEF_CALLBACK* release_buffer)(
struct _cef_v8array_buffer_release_callback_t* self,
void* buffer);
} cef_v8array_buffer_release_callback_t;
///
// Structure representing a V8 value handle. V8 handles can only be accessed
// from the thread on which they are created. Valid threads for creating a V8
@ -425,6 +444,11 @@ typedef struct _cef_v8value_t {
///
int(CEF_CALLBACK* is_array)(struct _cef_v8value_t* self);
///
// True if the value type is an ArrayBuffer.
///
int(CEF_CALLBACK* is_array_buffer)(struct _cef_v8value_t* self);
///
// True if the value type is function.
///
@ -639,6 +663,25 @@ typedef struct _cef_v8value_t {
///
int(CEF_CALLBACK* get_array_length)(struct _cef_v8value_t* self);
// ARRAY BUFFER METHODS - These functions are only available on ArrayBuffers.
///
// Returns the ReleaseCallback object associated with the ArrayBuffer or NULL
// if the ArrayBuffer was not created with CreateArrayBuffer.
///
struct _cef_v8array_buffer_release_callback_t*(
CEF_CALLBACK* get_array_buffer_release_callback)(
struct _cef_v8value_t* self);
///
// Prevent the ArrayBuffer from using it's memory block by setting the length
// to zero. This operation cannot be undone. If the ArrayBuffer was created
// with CreateArrayBuffer then
// cef_v8array_buffer_release_callback_t::ReleaseBuffer will be called to
// release the underlying buffer.
///
int(CEF_CALLBACK* neuter_array_buffer)(struct _cef_v8value_t* self);
// FUNCTION METHODS - These functions are only available on functions.
///
@ -751,6 +794,21 @@ CEF_EXPORT cef_v8value_t* cef_v8value_create_object(
///
CEF_EXPORT cef_v8value_t* cef_v8value_create_array(int length);
///
// Create a new cef_v8value_t object of type ArrayBuffer which wraps the
// provided |buffer| of size |length| bytes. The ArrayBuffer is externalized,
// meaning that it does not own |buffer|. The caller is responsible for freeing
// |buffer| when requested via a call to cef_v8array_buffer_release_callback_t::
// ReleaseBuffer. This function should only be called from within the scope of a
// cef_render_process_handler_t, cef_v8handler_t or cef_v8accessor_t callback,
// or in combination with calling enter() and exit() on a stored cef_v8context_t
// reference.
///
CEF_EXPORT cef_v8value_t* cef_v8value_create_array_buffer(
void* buffer,
size_t length,
cef_v8array_buffer_release_callback_t* release_callback);
///
// Create a new cef_v8value_t object of type function. This function should only
// be called from within the scope of a cef_render_process_handler_t,

View File

@ -407,6 +407,21 @@ class CefV8Exception : public virtual CefBaseRefCounted {
virtual int GetEndColumn() = 0;
};
///
// Callback interface that is passed to CefV8Value::CreateArrayBuffer.
///
/*--cef(source=client)--*/
class CefV8ArrayBufferReleaseCallback : public virtual CefBaseRefCounted {
public:
///
// Called to release |buffer| when the ArrayBuffer JS object is garbage
// collected. |buffer| is the value that was passed to CreateArrayBuffer along
// with this object.
///
/*--cef()--*/
virtual void ReleaseBuffer(void* buffer) = 0;
};
///
// Class representing a V8 value handle. V8 handles can only be accessed from
// the thread on which they are created. Valid threads for creating a V8 handle
@ -493,6 +508,22 @@ class CefV8Value : public virtual CefBaseRefCounted {
/*--cef()--*/
static CefRefPtr<CefV8Value> CreateArray(int length);
///
// Create a new CefV8Value object of type ArrayBuffer which wraps the provided
// |buffer| of size |length| bytes. The ArrayBuffer is externalized, meaning
// that it does not own |buffer|. The caller is responsible for freeing
// |buffer| when requested via a call to CefV8ArrayBufferReleaseCallback::
// ReleaseBuffer. This method should only be called from within the scope of a
// CefRenderProcessHandler, CefV8Handler or CefV8Accessor callback, or in
// combination with calling Enter() and Exit() on a stored CefV8Context
// reference.
///
/*--cef()--*/
static CefRefPtr<CefV8Value> CreateArrayBuffer(
void* buffer,
size_t length,
CefRefPtr<CefV8ArrayBufferReleaseCallback> release_callback);
///
// Create a new CefV8Value object of type function. This method should only be
// called from within the scope of a CefRenderProcessHandler, CefV8Handler or
@ -571,6 +602,12 @@ class CefV8Value : public virtual CefBaseRefCounted {
/*--cef()--*/
virtual bool IsArray() = 0;
///
// True if the value type is an ArrayBuffer.
///
/*--cef()--*/
virtual bool IsArrayBuffer() = 0;
///
// True if the value type is function.
///
@ -793,6 +830,25 @@ class CefV8Value : public virtual CefBaseRefCounted {
/*--cef()--*/
virtual int GetArrayLength() = 0;
// ARRAY BUFFER METHODS - These methods are only available on ArrayBuffers.
///
// Returns the ReleaseCallback object associated with the ArrayBuffer or NULL
// if the ArrayBuffer was not created with CreateArrayBuffer.
///
/*--cef()--*/
virtual CefRefPtr<CefV8ArrayBufferReleaseCallback>
GetArrayBufferReleaseCallback() = 0;
///
// Prevent the ArrayBuffer from using it's memory block by setting the length
// to zero. This operation cannot be undone. If the ArrayBuffer was created
// with CreateArrayBuffer then CefV8ArrayBufferReleaseCallback::ReleaseBuffer
// will be called to release the underlying buffer.
///
/*--cef()--*/
virtual bool NeuterArrayBuffer() = 0;
// FUNCTION METHODS - These methods are only available on functions.
///