summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorKonstantin Käfer <github@kkaefer.com>2010-11-30 13:18:02 +0200
committerRyan Dahl <ry@tinyclouds.org>2011-05-06 13:39:12 -0700
commit5e1b7cadb48aaf47978b7661a5ce58b0c4d21d27 (patch)
tree3f8dda10a18a331e827222347852e84f1ca9f992 /src
parent9812e31e8ba43be9c50d07f83cbf459427a5d877 (diff)
downloadandroid-node-v8-5e1b7cadb48aaf47978b7661a5ce58b0c4d21d27.tar.gz
android-node-v8-5e1b7cadb48aaf47978b7661a5ce58b0c4d21d27.tar.bz2
android-node-v8-5e1b7cadb48aaf47978b7661a5ce58b0c4d21d27.zip
Add Buffer::fill method to do memset
Fixes #477.
Diffstat (limited to 'src')
-rw-r--r--src/node_buffer.cc22
-rw-r--r--src/node_buffer.h1
2 files changed, 23 insertions, 0 deletions
diff --git a/src/node_buffer.cc b/src/node_buffer.cc
index 63db6107e0..f8d1a30879 100644
--- a/src/node_buffer.cc
+++ b/src/node_buffer.cc
@@ -376,6 +376,27 @@ Handle<Value> Buffer::Base64Slice(const Arguments &args) {
}
+// buffer.fill(value, start, end);
+Handle<Value> Buffer::Fill(const Arguments &args) {
+ HandleScope scope;
+
+ if (!args[0]->IsInt32()) {
+ return ThrowException(Exception::Error(String::New(
+ "value is not a number")));
+ }
+ int value = (char)args[0]->Int32Value();
+
+ Buffer *parent = ObjectWrap::Unwrap<Buffer>(args.This());
+ SLICE_ARGS(args[1], args[2])
+
+ memset( (void*)(parent->data_ + start),
+ value,
+ end - start);
+
+ return Undefined();
+}
+
+
// var bytesCopied = buffer.copy(target, targetStart, sourceStart, sourceEnd);
Handle<Value> Buffer::Copy(const Arguments &args) {
HandleScope scope;
@@ -734,6 +755,7 @@ void Buffer::Initialize(Handle<Object> target) {
NODE_SET_PROTOTYPE_METHOD(constructor_template, "binaryWrite", Buffer::BinaryWrite);
NODE_SET_PROTOTYPE_METHOD(constructor_template, "base64Write", Buffer::Base64Write);
NODE_SET_PROTOTYPE_METHOD(constructor_template, "ucs2Write", Buffer::Ucs2Write);
+ NODE_SET_PROTOTYPE_METHOD(constructor_template, "fill", Buffer::Fill);
NODE_SET_PROTOTYPE_METHOD(constructor_template, "copy", Buffer::Copy);
NODE_SET_METHOD(constructor_template->GetFunction(),
diff --git a/src/node_buffer.h b/src/node_buffer.h
index 91f93dc1d0..e6d47452e9 100644
--- a/src/node_buffer.h
+++ b/src/node_buffer.h
@@ -117,6 +117,7 @@ class Buffer : public ObjectWrap {
static v8::Handle<v8::Value> Ucs2Write(const v8::Arguments &args);
static v8::Handle<v8::Value> ByteLength(const v8::Arguments &args);
static v8::Handle<v8::Value> MakeFastBuffer(const v8::Arguments &args);
+ static v8::Handle<v8::Value> Fill(const v8::Arguments &args);
static v8::Handle<v8::Value> Copy(const v8::Arguments &args);
Buffer(v8::Handle<v8::Object> wrapper, size_t length);