mirror of
https://github.com/nodejs/node.git
synced 2024-11-21 10:59:27 +00:00
Add C++ API for constructing fast buffer from string
This commit is contained in:
parent
d1e5fbdde4
commit
dcc4fffe4d
@ -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;
|
||||
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user