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) {
1313void Alloc (const v8::FunctionCallbackInfo<v8::Value>& args) {
1414 v8::Isolate* isolate = args.GetIsolate ();
1515 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+
1623 args.GetReturnValue ().Set (node::Buffer::New (
1724 isolate,
18- buf ,
25+ aligned ,
1926 args[0 ]->IntegerValue (),
2027 FreeCallback,
2128 nullptr ).ToLocalChecked ());
Original file line number Diff line number Diff line change 44require ( '../../common' ) ;
55var binding = require ( './build/Release/binding' ) ;
66
7- function check ( size ) {
8- var buf = binding . alloc ( size ) ;
7+ function check ( size , alignment , offset ) {
8+ var buf = binding . alloc ( size , alignment , offset ) ;
99 var slice = buf . slice ( size >>> 1 ) ;
1010
1111 buf = null ;
@@ -16,7 +16,20 @@ function check(size) {
1616 gc ( ) ;
1717}
1818
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 ) ;
2033
2134// 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