22#include < node.h>
33#include < assert.h>
44
5- using v8::Isolate;
5+ using v8::Array;
6+ using v8::ArrayBuffer;
7+ using v8::ArrayBufferView;
8+ using v8::BackingStore;
69using v8::Context;
10+ using v8::FunctionCallbackInfo;
11+ using v8::Isolate;
712using v8::Local;
813using v8::MaybeLocal;
9- using v8::Value;
1014using v8::Number;
11- using v8::String;
1215using v8::Object;
13- using v8::Array;
14- using v8::ArrayBufferView;
15- using v8::ArrayBuffer;
16- using v8::FunctionCallbackInfo;
16+ using v8::String;
17+ using v8::Uint32;
18+ using v8::Value;
1719
1820void CallWithString (const FunctionCallbackInfo<Value>& args) {
1921 assert (args.Length () == 1 && args[0 ]->IsString ());
@@ -22,7 +24,7 @@ void CallWithString(const FunctionCallbackInfo<Value>& args) {
2224 const int32_t length = str->Utf8Length (args.GetIsolate ()) + 1 ;
2325 char * buf = new char [length];
2426 str->WriteUtf8 (args.GetIsolate (), buf, length);
25- delete [] buf;
27+ delete[] buf;
2628 }
2729}
2830
@@ -31,7 +33,7 @@ void CallWithArray(const FunctionCallbackInfo<Value>& args) {
3133 if (args.Length () == 1 && args[0 ]->IsArray ()) {
3234 const Local<Array> array = args[0 ].As <Array>();
3335 uint32_t length = array->Length ();
34- for (uint32_t i = 0 ; i < length; ++ i ) {
36+ for (uint32_t i = 0 ; i < length; i++ ) {
3537 Local<Value> v;
3638 v = array->Get (args.GetIsolate ()->GetCurrentContext (),
3739 i).ToLocalChecked ();
@@ -101,24 +103,22 @@ void CallWithTypedarray(const FunctionCallbackInfo<Value>& args) {
101103 const size_t byte_length = view->ByteLength ();
102104 assert (byte_length > 0 );
103105 assert (view->HasBuffer ());
104- Local<ArrayBuffer> buffer;
105- buffer = view->Buffer ();
106- ArrayBuffer::Contents contents;
107- contents = buffer->GetContents ();
106+ Local<ArrayBuffer> buffer = view->Buffer ();
107+ std::shared_ptr<BackingStore> bs = buffer->GetBackingStore ();
108108 const uint32_t * data = reinterpret_cast <uint32_t *>(
109- static_cast <uint8_t *>(contents. Data ()) + byte_offset);
109+ static_cast <uint8_t *>(bs-> Data ()) + byte_offset);
110110 assert (data);
111111 }
112112}
113113
114114void CallWithArguments (const FunctionCallbackInfo<Value>& args) {
115115 assert (args.Length () > 1 && args[0 ]->IsNumber ());
116116 if (args.Length () > 1 && args[0 ]->IsNumber ()) {
117- int32_t loop = args[0 ].As <v8:: Uint32>()->Value ();
117+ int32_t loop = args[0 ].As <Uint32>()->Value ();
118118 for (int32_t i = 1 ; i < loop; ++i) {
119119 assert (i < args.Length ());
120120 assert (args[i]->IsUint32 ());
121- args[i].As <v8:: Uint32>()->Value ();
121+ args[i].As <Uint32>()->Value ();
122122 }
123123 }
124124}
0 commit comments