mirror of https://gitee.com/bigwinds/arangodb
fix Buffer array access
This commit is contained in:
parent
8f0b512794
commit
e69e49f145
|
@ -163,8 +163,25 @@ global.DEFINE_MODULE('buffer', (function () {
|
||||||
|
|
||||||
// Buffer
|
// Buffer
|
||||||
function Buffer (subject, encoding, offset) {
|
function Buffer (subject, encoding, offset) {
|
||||||
|
var handler = {
|
||||||
|
get: function(target, name) {
|
||||||
|
if (name === '__buffer__') { return true; }
|
||||||
|
if (typeof name === 'string' && name.match(/^\d+$/)) {
|
||||||
|
return target.parent[name];
|
||||||
|
}
|
||||||
|
return target[name];
|
||||||
|
},
|
||||||
|
set: function(target, name, value) {
|
||||||
|
if (typeof name === 'string' && name.match(/^\d+$/)) {
|
||||||
|
target.parent[name] = value;
|
||||||
|
} else {
|
||||||
|
target[name] = value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
if (!(this instanceof Buffer)) {
|
if (!(this instanceof Buffer)) {
|
||||||
return new Buffer(subject, encoding, offset);
|
var b = new Buffer(subject, encoding, offset);
|
||||||
|
return new Proxy(b, handler);
|
||||||
}
|
}
|
||||||
|
|
||||||
var type;
|
var type;
|
||||||
|
@ -234,6 +251,7 @@ global.DEFINE_MODULE('buffer', (function () {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
return new Proxy(this, handler);
|
||||||
// SlowBuffer.makeFastBuffer(this.parent, this, this.offset, this.length)
|
// SlowBuffer.makeFastBuffer(this.parent, this, this.offset, this.length)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -246,6 +264,8 @@ global.DEFINE_MODULE('buffer', (function () {
|
||||||
exports.SlowBuffer = SlowBuffer;
|
exports.SlowBuffer = SlowBuffer;
|
||||||
exports.Buffer = Buffer;
|
exports.Buffer = Buffer;
|
||||||
|
|
||||||
|
Buffer.prototype.__buffer__ = true;
|
||||||
|
|
||||||
Buffer.isEncoding = function (encoding) {
|
Buffer.isEncoding = function (encoding) {
|
||||||
switch (encoding && encoding.toLowerCase()) {
|
switch (encoding && encoding.toLowerCase()) {
|
||||||
case 'hex':
|
case 'hex':
|
||||||
|
|
|
@ -761,6 +761,10 @@ bool V8Buffer::hasInstance(v8::Isolate* isolate, v8::Handle<v8::Value> val) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (obj->Has(TRI_V8_ASCII_STRING("__buffer__"))) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
return strcmp(*v8::String::Utf8Value(obj->GetConstructorName()), "Buffer") ==
|
return strcmp(*v8::String::Utf8Value(obj->GetConstructorName()), "Buffer") ==
|
||||||
0;
|
0;
|
||||||
}
|
}
|
||||||
|
@ -1701,7 +1705,7 @@ void TRI_InitV8Buffer(v8::Isolate* isolate, v8::Handle<v8::Context> context) {
|
||||||
|
|
||||||
TRI_V8_AddMethod(isolate, ft, TRI_V8_ASCII_STRING("byteLength"),
|
TRI_V8_AddMethod(isolate, ft, TRI_V8_ASCII_STRING("byteLength"),
|
||||||
JS_ByteLength);
|
JS_ByteLength);
|
||||||
|
|
||||||
// create the exports
|
// create the exports
|
||||||
v8::Handle<v8::Object> exports = v8::Object::New(isolate);
|
v8::Handle<v8::Object> exports = v8::Object::New(isolate);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue