diff options
author | Ryan Dahl <ry@tinyclouds.org> | 2010-10-26 13:43:58 -0700 |
---|---|---|
committer | Ryan Dahl <ry@tinyclouds.org> | 2010-10-26 13:43:58 -0700 |
commit | dcc4fffe4dc7ccec3db2d1b55ab3a42a492a0c98 (patch) | |
tree | bc4b95bc193f5f7943c5689c4ee90123ba29af8b /src/node_buffer.cc | |
parent | d1e5fbdde4d08efa6656a0df3bd9546030b80f1e (diff) | |
download | node-dcc4fffe4dc7ccec3db2d1b55ab3a42a492a0c98.tar.gz |
Add C++ API for constructing fast buffer from string
Diffstat (limited to 'src/node_buffer.cc')
-rw-r--r-- | src/node_buffer.cc | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/src/node_buffer.cc b/src/node_buffer.cc index bac41cf78..8d7fc6dc9 100644 --- a/src/node_buffer.cc +++ b/src/node_buffer.cc @@ -82,6 +82,22 @@ static size_t ByteLength (Handle<String> string, enum encoding enc) { } +Handle<Object> Buffer::New(Handle<String> string) { + HandleScope scope; + + // get Buffer from global scope. + Local<Object> global = v8::Context::GetCurrent()->Global(); + Local<Value> bv = global->Get(String::NewSymbol("Buffer")); + assert(bv->IsFunction()); + Local<Function> b = Local<Function>::Cast(bv); + + Local<Value> argv[1] = { Local<Value>::New(string) }; + Local<Object> instance = b->NewInstance(1, argv); + + return scope.Close(instance); +} + + Buffer* Buffer::New(size_t length) { HandleScope scope; |