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

@ -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.
///