summaryrefslogtreecommitdiff
path: root/src/node_buffer.cc
diff options
context:
space:
mode:
authorRyan Dahl <ry@tinyclouds.org>2010-10-26 13:43:58 -0700
committerRyan Dahl <ry@tinyclouds.org>2010-10-26 13:43:58 -0700
commitdcc4fffe4dc7ccec3db2d1b55ab3a42a492a0c98 (patch)
treebc4b95bc193f5f7943c5689c4ee90123ba29af8b /src/node_buffer.cc
parentd1e5fbdde4d08efa6656a0df3bd9546030b80f1e (diff)
downloadnode-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.cc16
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;