File tree Expand file tree Collapse file tree 2 files changed +25
-5
lines changed
test/addons/buffer-free-callback Expand file tree Collapse file tree 2 files changed +25
-5
lines changed Original file line number Diff line number Diff line change @@ -13,9 +13,16 @@ static void FreeCallback(char* data, void* hint) {
13
13
void Alloc (const v8::FunctionCallbackInfo<v8::Value>& args) {
14
14
v8::Isolate* isolate = args.GetIsolate ();
15
15
alive++;
16
+
17
+ uintptr_t alignment = args[1 ]->IntegerValue ();
18
+ uintptr_t offset = args[2 ]->IntegerValue ();
19
+
20
+ uintptr_t static_offset = reinterpret_cast <uintptr_t >(buf) % alignment;
21
+ char * aligned = buf + (alignment - static_offset) + offset;
22
+
16
23
args.GetReturnValue ().Set (node::Buffer::New (
17
24
isolate,
18
- buf ,
25
+ aligned ,
19
26
args[0 ]->IntegerValue (),
20
27
FreeCallback,
21
28
nullptr ).ToLocalChecked ());
Original file line number Diff line number Diff line change 4
4
require ( '../../common' ) ;
5
5
var binding = require ( './build/Release/binding' ) ;
6
6
7
- function check ( size ) {
8
- var buf = binding . alloc ( size ) ;
7
+ function check ( size , alignment , offset ) {
8
+ var buf = binding . alloc ( size , alignment , offset ) ;
9
9
var slice = buf . slice ( size >>> 1 ) ;
10
10
11
11
buf = null ;
@@ -16,7 +16,20 @@ function check(size) {
16
16
gc ( ) ;
17
17
}
18
18
19
- check ( 64 ) ;
19
+ check ( 64 , 1 , 0 ) ;
20
+
21
+ // Buffers can have weird sizes.
22
+ check ( 97 , 1 , 0 ) ;
23
+
24
+ // Buffers can be unaligned
25
+ check ( 64 , 8 , 0 ) ;
26
+ check ( 64 , 16 , 0 ) ;
27
+ check ( 64 , 8 , 1 ) ;
28
+ check ( 64 , 16 , 1 ) ;
29
+ check ( 97 , 8 , 1 ) ;
30
+ check ( 97 , 16 , 1 ) ;
31
+ check ( 97 , 8 , 3 ) ;
32
+ check ( 97 , 16 , 3 ) ;
20
33
21
34
// Empty ArrayBuffer does not allocate data, worth checking
22
- check ( 0 ) ;
35
+ check ( 0 , 1 , 0 ) ;
You can’t perform that action at this time.
0 commit comments