This repository has been archived by the owner. It is now read-only.
Permalink
Browse files

src: enable native v8 typed arrays

This commit removes our homegrown typed arrays implementation and
enables V8's built-in typed arrays implementation.
  • Loading branch information...
bnoordhuis committed Jun 29, 2013
1 parent c56a96c commit 0693d22f86de01b179343cc568a5609726bef9bb
Showing with 34 additions and 349 deletions.
  1. +0 −11 doc/api/buffer.markdown
  2. +34 −0 src/node.cc
  3. +0 −89 test/simple/test-arraybuffer-slice.js
  4. +0 −249 test/simple/test-typed-arrays.js
View
@@ -37,17 +37,6 @@ encoding method. Here are the different string encodings.
* `'hex'` - Encode each byte as two hexadecimal characters.
A `Buffer` object can also be used with typed arrays. The buffer object is
cloned to an `ArrayBuffer` that is used as the backing store for the typed
array. The memory of the buffer and the `ArrayBuffer` is not shared.
NOTE: Node.js v0.8 simply retained a reference to the buffer in `array.buffer`
instead of cloning it.
While more efficient, it introduces subtle incompatibilities with the typed
arrays specification. `ArrayBuffer#slice()` makes a copy of the slice while
`Buffer#slice()` creates a view.
## Class: Buffer
The Buffer class is a global type for dealing with binary data directly.
View
@@ -91,6 +91,7 @@ extern char **environ;
namespace node {
using v8::Array;
using v8::ArrayBuffer;
using v8::Boolean;
using v8::Context;
using v8::Exception;
@@ -204,6 +205,35 @@ static uv_async_t emit_debug_enabled_async;
Isolate* node_isolate = NULL;
class ArrayBufferAllocator : public ArrayBuffer::Allocator {
public:
// Impose an upper limit to avoid out of memory errors that bring down
// the process.
static const size_t kMaxLength = 0x3fffffff;
static ArrayBufferAllocator the_singleton;
virtual ~ArrayBufferAllocator() {}
virtual void* Allocate(size_t length);
virtual void Free(void* data);
private:
ArrayBufferAllocator() {}
ArrayBufferAllocator(const ArrayBufferAllocator&);
void operator=(const ArrayBufferAllocator&);
};
ArrayBufferAllocator ArrayBufferAllocator::the_singleton;
void* ArrayBufferAllocator::Allocate(size_t length) {
if (length > kMaxLength) return NULL;
return new char[length];
}
void ArrayBufferAllocator::Free(void* data) {
delete[] static_cast<char*>(data);
}
static void CheckImmediate(uv_check_t* handle, int status) {
assert(handle == &check_immediate_watcher);
assert(status == 0);
@@ -2924,6 +2954,10 @@ char** Init(int argc, char *argv[]) {
}
V8::SetFlagsFromCommandLine(&v8argc, v8argv, false);
const char typed_arrays_flag[] = "--harmony_typed_arrays";
V8::SetFlagsFromString(typed_arrays_flag, sizeof(typed_arrays_flag) - 1);
V8::SetArrayBufferAllocator(&ArrayBufferAllocator::the_singleton);
// Fetch a reference to the main isolate, so we have a reference to it
// even when we need it to access it from another (debugger) thread.
node_isolate = Isolate::GetCurrent();

This file was deleted.

Oops, something went wrong.
Oops, something went wrong.

0 comments on commit 0693d22

Please sign in to comment.