Permalink
Browse files

Added BYTES_PER_ELEMENT constant to Float32Array

  • Loading branch information...
1 parent 90ab0a9 commit d3a7ac86744f5fb5f4080d34387781342612c8f5 @puffnfresh committed May 2, 2011
Showing with 12 additions and 3 deletions.
  1. +12 −3 src/typedarray.h
View
@@ -9,6 +9,8 @@
using namespace v8;
using namespace node;
+#define SET_
+
class Float32Array : public ObjectWrap {
public:
@@ -20,6 +22,8 @@ class Float32Array : public ObjectWrap {
t->InstanceTemplate()->SetInternalFieldCount(1);
t->SetClassName(String::NewSymbol("Float32Array"));
+ SetBytesPerElement(t, 4);
+
NODE_SET_PROTOTYPE_METHOD(t, "set", Set);
t->PrototypeTemplate()->SetAccessor(String::New("length"), LengthGetter);
@@ -92,14 +96,19 @@ class Float32Array : public ObjectWrap {
Float32Array *fa = Unwrap<Float32Array>(info.This());
Local<Value> buf = fa->handle_->GetHiddenValue(String::New("buffer"));
- int len = Buffer::Length(buf->ToObject());
-
- return scope.Close(Integer::New(len));
+ return scope.Close(Integer::New(Buffer::Length(buf->ToObject())));
}
Float32Array () : ObjectWrap() {
}
+private:
+
+ static void
+ SetBytesPerElement (Handle<FunctionTemplate> function, unsigned long value) {
+ function->Set(String::New("BYTES_PER_ELEMENT"), Integer::New(value), ReadOnly);
+ }
+
};
#endif // TYPEDARRAYS_H_

0 comments on commit d3a7ac8

Please sign in to comment.