44
55using namespace v8 ;
66
7- void StringArrayBuffer (const v8::FunctionCallbackInfo<v8::Value>& args) {
8- Isolate *isolate = args.GetIsolate ();
9-
10- const char *str = " !!!EHLO WORLD!!!" ;
11- node::ArrayBuffer *buffer = node::ArrayBuffer::New (isolate, str);
12-
13- args.GetReturnValue ().Set (buffer->ToArrayBuffer ());
14- }
15-
167void CreateArrayBuffer (const v8::FunctionCallbackInfo<v8::Value>& args) {
178 Isolate *isolate = args.GetIsolate ();
189
19- std::string str = " Hello World!" ;
20- node::ArrayBuffer *buffer = node::ArrayBuffer::New (isolate, str);
10+ node::ArrayBuffer *buffer = node::ArrayBuffer::New (isolate, " Hello World!" );
2111
2212 args.GetReturnValue ().Set (buffer->ToArrayBuffer ());
2313}
2414
25- void PrintWrapped (const v8::FunctionCallbackInfo<v8::Value>& args) {
26- Isolate *isolate = args.GetIsolate ();
27-
28- node::ArrayBuffer *buffer = node::ArrayBuffer::New (isolate, args[0 ]);
29- std::string str = buffer->Unwrap <std::string>();
30-
31- printf (" node::ArrayBuffer: '%s', %zu\n " , str.data (), str.length ());
32- }
33-
3415void PrintArrayBuffer (const v8::FunctionCallbackInfo<v8::Value>& args) {
3516 Isolate *isolate = args.GetIsolate ();
3617
@@ -49,15 +30,9 @@ void SampleInit(Handle<Object> exports) {
4930 Isolate* isolate = Isolate::GetCurrent ();
5031 HandleScope scope (isolate);
5132
52- exports->Set (String::NewFromUtf8 (isolate, " StringArrayBuffer" ),
53- FunctionTemplate::New (isolate, StringArrayBuffer)->GetFunction ());
54-
5533 exports->Set (String::NewFromUtf8 (isolate, " CreateArrayBuffer" ),
5634 FunctionTemplate::New (isolate, CreateArrayBuffer)->GetFunction ());
5735
58- exports->Set (String::NewFromUtf8 (isolate, " PrintWrapped" ),
59- FunctionTemplate::New (isolate, PrintWrapped)->GetFunction ());
60-
6136 exports->Set (String::NewFromUtf8 (isolate, " PrintArrayBuffer" ),
6237 FunctionTemplate::New (isolate, PrintArrayBuffer)->GetFunction ());
6338
0 commit comments