Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Create a public Buffer constructor for use in addons.

  • Loading branch information...
commit 3768aaaea406dd32db2f74395f6414bcd26dba74 1 parent c4876d0
@ry ry authored
View
9 src/node_buffer.cc
@@ -119,6 +119,15 @@ class AsciiSliceExt: public String::ExternalAsciiStringResource {
};
#endif
+Buffer* Buffer::New(size_t size) {
+ HandleScope scope;
+
+ Local<Value> arg = Integer::NewFromUnsigned(size);
+ Local<Object> b = constructor_template->GetFunction()->NewInstance(1, &arg);
+
+ return ObjectWrap::Unwrap<Buffer>(b);
+}
+
Handle<Value> Buffer::New(const Arguments &args) {
HandleScope scope;
View
17 src/node_buffer.h
@@ -30,13 +30,10 @@ struct Blob_;
class Buffer : public ObjectWrap {
public:
- static v8::Persistent<v8::FunctionTemplate> constructor_template;
-
- Buffer(size_t length);
- Buffer(Buffer *parent, size_t start, size_t end);
~Buffer();
static void Initialize(v8::Handle<v8::Object> target);
+ static Buffer* New(size_t length); // public constructor
static inline bool HasInstance(v8::Handle<v8::Value> val) {
if (!val->IsObject()) return false;
v8::Local<v8::Object> obj = val->ToObject();
@@ -47,7 +44,12 @@ class Buffer : public ObjectWrap {
size_t length() const { return length_; }
struct Blob_* blob() const { return blob_; }
- protected:
+ int AsciiWrite(char *string, int offset, int length);
+ int Utf8Write(char *string, int offset, int length);
+
+ private:
+ static v8::Persistent<v8::FunctionTemplate> constructor_template;
+
static v8::Handle<v8::Value> New(const v8::Arguments &args);
static v8::Handle<v8::Value> Slice(const v8::Arguments &args);
static v8::Handle<v8::Value> BinarySlice(const v8::Arguments &args);
@@ -60,10 +62,9 @@ class Buffer : public ObjectWrap {
static v8::Handle<v8::Value> Unpack(const v8::Arguments &args);
static v8::Handle<v8::Value> Copy(const v8::Arguments &args);
- int AsciiWrite(char *string, int offset, int length);
- int Utf8Write(char *string, int offset, int length);
+ Buffer(size_t length);
+ Buffer(Buffer *parent, size_t start, size_t end);
- private:
size_t off_; // offset inside blob_
size_t length_; // length inside blob_
struct Blob_ *blob_;
View
1  src/node_object_wrap.h
@@ -13,7 +13,6 @@ class ObjectWrap {
}
virtual ~ObjectWrap ( ) {
- assert(handle_.IsNearDeath());
handle_->SetInternalField(0, v8::Undefined());
handle_.Dispose();
handle_.Clear();
Please sign in to comment.
Something went wrong with that request. Please try again.