v8/test/cctest/manually-externalized-buffer.h
Andreas Haas bfe3d6bce7 [api] Deprecate [Shared]ArrayBuffer::Externalize/GetContents and constructors
The new API with v8::BackingStore should be used instead as explained in
https://docs.google.com/document/d/1sTc_jRL87Fu175Holm5SV0kajkseGl2r8ifGY76G35k

This also relaxes the pre-condition for [Shared]ArrayBuffer::Detach to
not require externalization first.

Bug: v8:9380, v8:9908
Change-Id: Idd119fcd28be84a2fae74ae86f7381fd997766f5
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1859628
Commit-Queue: Andreas Haas <ahaas@chromium.org>
Reviewed-by: Clemens Backes <clemensb@chromium.org>
Reviewed-by: Andreas Haas <ahaas@chromium.org>
Cr-Commit-Position: refs/heads/master@{#64625}
2019-10-29 22:01:54 +00:00

35 lines
1.0 KiB
C++

// Copyright 2019 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef V8_CCTEST_MANUALLY_EXTERNALIZED_BUFFER_H_
#define V8_CCTEST_MANUALLY_EXTERNALIZED_BUFFER_H_
#include "src/api/api-inl.h"
namespace v8 {
namespace internal {
namespace testing {
// Utility to free the allocated memory for a buffer that is manually
// externalized in a test.
struct ManuallyExternalizedBuffer {
Handle<JSArrayBuffer> buffer_;
std::shared_ptr<v8::BackingStore> backing_store_;
explicit ManuallyExternalizedBuffer(Handle<JSArrayBuffer> buffer)
: buffer_(buffer),
backing_store_(v8::Utils::ToLocal(buffer_)->GetBackingStore()) {}
~ManuallyExternalizedBuffer() {
// Nothing to be done. The reference to the backing store will be
// dropped automatically.
}
void* backing_store() { return backing_store_->Data(); }
};
} // namespace testing
} // namespace internal
} // namespace v8
#endif // V8_CCTEST_MANUALLY_EXTERNALIZED_BUFFER_H_