mirror of
https://github.com/nodejs/node-v0.x-archive.git
synced 2026-04-28 03:01:10 -04:00
Create a public Buffer constructor for use in addons.
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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_;
|
||||
|
||||
@@ -13,7 +13,6 @@ class ObjectWrap {
|
||||
}
|
||||
|
||||
virtual ~ObjectWrap ( ) {
|
||||
assert(handle_.IsNearDeath());
|
||||
handle_->SetInternalField(0, v8::Undefined());
|
||||
handle_.Dispose();
|
||||
handle_.Clear();
|
||||
|
||||
Reference in New Issue
Block a user