forked from nodejs/node
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathv8-array-buffer-unittest.cc
More file actions
40 lines (30 loc) · 1.05 KB
/
v8-array-buffer-unittest.cc
File metadata and controls
40 lines (30 loc) · 1.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
// Copyright 2026 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.
#include "include/v8-array-buffer.h"
#include "test/unittests/test-utils.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace v8 {
namespace {
using ArrayBufferTest = TestWithContext;
TEST_F(ArrayBufferTest, TransferWithDetachKey) {
Local<ArrayBuffer> ab = ArrayBuffer::New(isolate(), 1);
Local<Value> key = Symbol::New(isolate());
ab->SetDetachKey(key);
Local<Object> global = context()->Global();
Local<String> property_name =
String::NewFromUtf8Literal(isolate(), "test_ab");
global->Set(context(), property_name, ab).ToChecked();
{
TryCatch try_catch(isolate());
CHECK(TryRunJS("globalThis.test_ab.transfer()").IsEmpty());
}
// Didnot transfer.
EXPECT_EQ(ab->ByteLength(), 1u);
ab->SetDetachKey(Undefined(isolate()));
RunJS("globalThis.test_ab.transfer()");
// Transferred.
EXPECT_EQ(ab->ByteLength(), 0u);
}
} // namespace
} // namespace v8