I found weird behavior in Node.js v0.11.13.
First of all, i just want to check v8::Object#HasIndexedPropertiesInExternalArrayData behavior.
However I could not get true
from the method( always return false...).
I tried repeatedly. So I just found the following behavior.
#include <node.h>
#include <nan.h>
using namespace v8;
NAN_METHOD(Method) {
NanScope();
// get first argument
v8::Handle<v8::Object> buffer = args[0]->ToObject();
// get HasIndexedPropertiesInExternalArrayData value.
// if buffer has indexed properties like {"0": 123, "1":234, "2":345}, return true.
bool hasIndexed = buffer->HasIndexedPropertiesInExternalArrayData();
NanReturnValue(NanNew<Boolean>(hasIndexed));
}
void init(Handle<Object> exports) {
exports->Set(NanSymbol("hasIndexed"),
NanNew<FunctionTemplate>(Method)->GetFunction());
}
NODE_MODULE(addon, init)
var hello = require("../hello");
var assert = require("assert");
var arr = new Uint8Array(8);
console.log(arr);
// HasIndexedPropertiesInExternalArrayData is false
console.log(hello.hasIndexed(arr));
// if arr.buffer is called
arr.buffer;
// HasIndexedPropertiesInExternalArrayData is true
console.log(hello.hasIndexed(arr));
v0.10 always returns true
regardless of arr.buffer.
Full Code is here https://github.com/yosuke-furukawa/NANSample/tree/test/hasindexed