Skip to content

Commit 279c9ed

Browse files
committed
Update
1 parent 32b00c5 commit 279c9ed

File tree

2 files changed

+7
-47
lines changed

2 files changed

+7
-47
lines changed

sample.cc

Lines changed: 1 addition & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -4,33 +4,14 @@
44

55
using 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-
167
void 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-
3415
void 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

sample.js

Lines changed: 6 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -9,32 +9,17 @@ function PrintJS(arrayBuffer) {
99
}
1010

1111
function Print(arrayBuffer) {
12-
if (!arrayBuffer) {
13-
var buf = new Buffer(5);
14-
buf.write('HELLO', 0);
15-
16-
var arrayBuffer = new Uint8Array(buf).buffer;
17-
}
18-
1912
sample.PrintArrayBuffer(arrayBuffer);
2013
PrintJS(arrayBuffer);
2114
}
2215

23-
function Create() {
24-
var arrayBuffer = sample.CreateArrayBuffer();
25-
Print(arrayBuffer);
26-
sample.PrintWrapped(arrayBuffer);
27-
}
16+
var buf = new Buffer(5);
17+
buf.write('HELLO', 0);
2818

29-
function String() {
30-
var arrayBuffer = sample.StringArrayBuffer();
31-
Print(arrayBuffer);
32-
}
19+
var arrayBuffer = new Uint8Array(buf).buffer;
3320

34-
for (var index = 0; index < 100; index++) {
35-
Print('New ArrayBuffer From String!');
36-
Create();
37-
String();
38-
}
21+
Print(arrayBuffer);
22+
Print('New ArrayBuffer From String!');
23+
Print(sample.CreateArrayBuffer());
3924

4025
sample.DisposeMemory();

0 commit comments

Comments
 (0)