Commit aba95110 authored by Andreas Haas's avatar Andreas Haas Committed by Commit Bot

[arraybuffer][test] Test creating a BackingStore with nullptr

R= ulan@chromium.org

Bug: chromium:1104580
Change-Id: I5824de7aa4c71b1464fc8b2c35375bcb5d84f2e9
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2320329Reviewed-by: 's avatarUlan Degenbaev <ulan@chromium.org>
Commit-Queue: Andreas Haas <ahaas@chromium.org>
Cr-Commit-Position: refs/heads/master@{#69073}
parent a7bb323b
......@@ -707,6 +707,30 @@ THREADED_TEST(BackingStore_Shared) {
->IsShared());
}
THREADED_TEST(ArrayBuffer_NewBackingStore_NullData) {
// This test creates a BackingStore with nullptr as data. The test then
// creates an ArrayBuffer and a TypedArray from this BackingStore. Writing
// into that TypedArray at index 0 is expected to be a no-op, reading from
// that TypedArray at index 0 should result in the default value '0'.
LocalContext env;
v8::Isolate* isolate = env->GetIsolate();
v8::HandleScope handle_scope(isolate);
std::unique_ptr<v8::BackingStore> backing_store =
v8::ArrayBuffer::NewBackingStore(nullptr, 0,
v8::BackingStore::EmptyDeleter, nullptr);
v8::Local<v8::ArrayBuffer> buffer =
v8::ArrayBuffer::New(isolate, std::move(backing_store));
CHECK(env->Global()->Set(env.local(), v8_str("buffer"), buffer).FromJust());
v8::Local<v8::Value> result =
CompileRunChecked(isolate,
"const view = new Int32Array(buffer);"
"view[0] = 14;"
"view[0];");
CHECK_EQ(0, result->Int32Value(env.local()).FromJust());
}
class DummyAllocator final : public v8::ArrayBuffer::Allocator {
public:
DummyAllocator() : allocator_(NewDefaultAllocator()) {}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment