1
0
Fork 0
This commit is contained in:
jsteemann 2016-03-18 16:56:05 +01:00
parent 33e2b7b844
commit f12320277f
2 changed files with 32 additions and 3 deletions

View File

@ -395,6 +395,9 @@ Buffer.prototype.write = function(string, offset, length, encoding) {
Buffer.prototype.toJSON = function() { Buffer.prototype.toJSON = function() {
if (this.parent) {
return Array.prototype.slice.call(this.parent, this.offset, this.offset + this.length);
}
return Array.prototype.slice.call(this, 0); return Array.prototype.slice.call(this, 0);
}; };

View File

@ -1547,13 +1547,26 @@ static void JS_ByteLength(v8::FunctionCallbackInfo<v8::Value> const& args) {
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
/// @brief selects an indexed attribute from the buffer /// @brief selects an indexed attribute from the buffer
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
/*
static void MapGetIndexedBuffer( static void MapGetIndexedBuffer(
uint32_t idx, const v8::PropertyCallbackInfo<v8::Value>& args) { uint32_t idx, const v8::PropertyCallbackInfo<v8::Value>& args) {
v8::Isolate* isolate = args.GetIsolate(); v8::Isolate* isolate = args.GetIsolate();
v8::HandleScope scope(isolate); v8::HandleScope scope(isolate);
v8::Handle<v8::Object> self = args.Holder(); v8::Handle<v8::Object> self = args.Holder();
if (self->InternalFieldCount() == 0) {
// seems object has become a FastBuffer already
if (self->Has(TRI_V8_ASCII_STRING("parent"))) {
v8::Handle<v8::Value> parent = self->Get(TRI_V8_ASCII_STRING("parent"));
if (!parent->IsObject()) {
TRI_V8_RETURN(v8::Handle<v8::Value>());
}
self = parent->ToObject();
// fallthrough intentional
}
}
V8Buffer* buffer = V8Buffer::unwrap(self); V8Buffer* buffer = V8Buffer::unwrap(self);
if (buffer == nullptr || idx >= buffer->_length) { if (buffer == nullptr || idx >= buffer->_length) {
@ -1575,6 +1588,19 @@ static void MapSetIndexedBuffer(
v8::HandleScope scope(isolate); v8::HandleScope scope(isolate);
v8::Handle<v8::Object> self = args.Holder(); v8::Handle<v8::Object> self = args.Holder();
if (self->InternalFieldCount() == 0) {
// seems object has become a FastBuffer already
if (self->Has(TRI_V8_ASCII_STRING("parent"))) {
v8::Handle<v8::Value> parent = self->Get(TRI_V8_ASCII_STRING("parent"));
if (!parent->IsObject()) {
TRI_V8_RETURN(v8::Handle<v8::Value>());
}
self = parent->ToObject();
// fallthrough intentional
}
}
V8Buffer* buffer = V8Buffer::unwrap(self); V8Buffer* buffer = V8Buffer::unwrap(self);
if (buffer == nullptr || idx >= buffer->_length) { if (buffer == nullptr || idx >= buffer->_length) {
@ -1588,7 +1614,7 @@ static void MapSetIndexedBuffer(
TRI_V8_RETURN( TRI_V8_RETURN(
v8::Integer::NewFromUnsigned(isolate, ((uint8_t)buffer->_data[idx]))); v8::Integer::NewFromUnsigned(isolate, ((uint8_t)buffer->_data[idx])));
} }
*/
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
/// @brief initializes the buffer module /// @brief initializes the buffer module
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
@ -1620,7 +1646,7 @@ void TRI_InitV8Buffer(v8::Isolate* isolate, v8::Handle<v8::Context> context) {
rt->SetInternalFieldCount(1); rt->SetInternalFieldCount(1);
// accessor for indexed properties (e.g. buffer[1]) // accessor for indexed properties (e.g. buffer[1])
// rt->SetIndexedPropertyHandler(MapGetIndexedBuffer, MapSetIndexedBuffer); rt->SetIndexedPropertyHandler(MapGetIndexedBuffer, MapSetIndexedBuffer);
v8g->BufferTempl.Reset(isolate, ft); v8g->BufferTempl.Reset(isolate, ft);