Fix ArrayBuffer crashes and add performance test (issue #2521)
This commit is contained in:
parent
ead5caf25a
commit
cd24143111
|
@ -314,6 +314,8 @@ class V8TrackArrayBuffer : public CefTrackNode {
|
|||
buffer_(buffer),
|
||||
release_callback_(release_callback) {
|
||||
DCHECK(isolate_);
|
||||
isolate_->AdjustAmountOfExternalAllocatedMemory(
|
||||
static_cast<int>(sizeof(V8TrackArrayBuffer)));
|
||||
}
|
||||
|
||||
~V8TrackArrayBuffer() {
|
||||
|
@ -330,6 +332,13 @@ class V8TrackArrayBuffer : public CefTrackNode {
|
|||
|
||||
void Neuter() { buffer_ = nullptr; }
|
||||
|
||||
// Attach this track object to the specified V8 object.
|
||||
void AttachTo(v8::Local<v8::Context> context,
|
||||
v8::Local<v8::ArrayBuffer> arrayBuffer) {
|
||||
SetPrivate(context, arrayBuffer, kCefTrackObject,
|
||||
v8::External::New(isolate_, this));
|
||||
}
|
||||
|
||||
// Retrieve the track object for the specified V8 object.
|
||||
static V8TrackArrayBuffer* Unwrap(v8::Local<v8::Context> context,
|
||||
v8::Local<v8::Object> object) {
|
||||
|
@ -341,35 +350,10 @@ class V8TrackArrayBuffer : public CefTrackNode {
|
|||
return nullptr;
|
||||
}
|
||||
|
||||
// Attach this track object to the specified V8 object.
|
||||
void AttachTo(v8::Local<v8::Context> context,
|
||||
v8::Local<v8::ArrayBuffer> arrayBuffer) {
|
||||
isolate_->AdjustAmountOfExternalAllocatedMemory(
|
||||
static_cast<int>(sizeof(V8TrackArrayBuffer)));
|
||||
|
||||
SetPrivate(context, arrayBuffer, kCefTrackObject,
|
||||
v8::External::New(isolate_, this));
|
||||
|
||||
handle_.Reset(isolate_, arrayBuffer);
|
||||
handle_.SetWeak(this, FirstWeakCallback, v8::WeakCallbackType::kParameter);
|
||||
handle_.MarkIndependent();
|
||||
}
|
||||
|
||||
private:
|
||||
static void FirstWeakCallback(
|
||||
const v8::WeakCallbackInfo<V8TrackArrayBuffer>& data) {
|
||||
V8TrackArrayBuffer* wrapper = data.GetParameter();
|
||||
if (wrapper->buffer_ != nullptr) {
|
||||
wrapper->release_callback_->ReleaseBuffer(wrapper->buffer_);
|
||||
wrapper->buffer_ = nullptr;
|
||||
}
|
||||
wrapper->handle_.Reset();
|
||||
}
|
||||
|
||||
v8::Isolate* isolate_;
|
||||
void* buffer_;
|
||||
CefRefPtr<CefV8ArrayBufferReleaseCallback> release_callback_;
|
||||
v8::Persistent<v8::ArrayBuffer> handle_;
|
||||
};
|
||||
|
||||
// Object wrapped in a v8::External and passed as the Data argument to
|
||||
|
|
|
@ -318,6 +318,24 @@ PERF_TEST_FUNC(V8ObjectGetValueWithAccessor) {
|
|||
PERF_ITERATIONS_END()
|
||||
}
|
||||
|
||||
PERF_TEST_FUNC(V8ArrayBufferCreate) {
|
||||
class ReleaseCallback : public CefV8ArrayBufferReleaseCallback {
|
||||
public:
|
||||
void ReleaseBuffer(void* buffer) override { std::free(buffer); }
|
||||
IMPLEMENT_REFCOUNTING(ReleaseCallback);
|
||||
};
|
||||
|
||||
size_t len = 1;
|
||||
size_t byte_len = len * sizeof(float);
|
||||
CefRefPtr<CefV8ArrayBufferReleaseCallback> callback = new ReleaseCallback();
|
||||
|
||||
PERF_ITERATIONS_START()
|
||||
float* buffer = (float*)std::malloc(byte_len);
|
||||
CefRefPtr<CefV8Value> ret =
|
||||
CefV8Value::CreateArrayBuffer(buffer, byte_len, callback);
|
||||
PERF_ITERATIONS_END()
|
||||
}
|
||||
|
||||
PERF_TEST_FUNC(V8ContextEnterExit) {
|
||||
CefRefPtr<CefV8Context> context = CefV8Context::GetCurrentContext();
|
||||
|
||||
|
@ -363,6 +381,7 @@ const PerfTestEntry kPerfTests[] = {
|
|||
PERF_TEST_ENTRY(V8ObjectGetValue),
|
||||
PERF_TEST_ENTRY(V8ObjectSetValueWithAccessor),
|
||||
PERF_TEST_ENTRY(V8ObjectGetValueWithAccessor),
|
||||
PERF_TEST_ENTRY(V8ArrayBufferCreate),
|
||||
PERF_TEST_ENTRY(V8ContextEnterExit),
|
||||
PERF_TEST_ENTRY(V8ContextEval),
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue