Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Add C++ API for constructing fast buffer from string

  • Loading branch information...
commit dcc4fffe4dc7ccec3db2d1b55ab3a42a492a0c98 1 parent d1e5fbd
@ry ry authored
Showing with 19 additions and 0 deletions.
  1. +16 −0 src/node_buffer.cc
  2. +3 −0  src/node_buffer.h
View
16 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;
View
3  src/node_buffer.h
@@ -24,6 +24,9 @@ class Buffer : public ObjectWrap {
typedef void (*free_callback)(char *data, void *hint);
+ // C++ API for constructing fast buffer
+ static v8::Handle<v8::Object> New(v8::Handle<v8::String> string);
+
static void Initialize(v8::Handle<v8::Object> target);
static Buffer* New(size_t length); // public constructor
static Buffer* New(char *data, size_t len); // public constructor
Please sign in to comment.
Something went wrong with that request. Please try again.