send handle from JS (#2795)

This commit is contained in:
minggo
2020-09-16 16:20:07 +08:00
committed by GitHub
parent 32b5dc9ea0
commit e114dda530
3 changed files with 19 additions and 15 deletions
+4 -6
View File
@@ -21,13 +21,13 @@ ArrayPool::~ArrayPool() {
Object *ArrayPool::alloc(uint index) {
uint bytes = _size * BYTES_PER_ELEMENT;
auto obj = Object::createTypedArray(Object::TypedArrayType::UINT32, nullptr, bytes);
obj->incRef();
_objects[index] = obj;
_indexes[obj] = index;
return obj;
}
Object *ArrayPool::resize(Object *origin, uint size) {
Object *ArrayPool::resize(Object *origin, uint size, uint index) {
uint bytes = size * BYTES_PER_ELEMENT;
uint8_t *buffer = static_cast<uint8_t *>(CC_MALLOC(bytes));
if (!buffer) {
@@ -44,10 +44,8 @@ Object *ArrayPool::resize(Object *origin, uint size) {
auto obj = Object::createTypedArray(Object::TypedArrayType::UINT32, buffer, bytes);
CC_FREE(buffer);
uint originIndex = _indexes[origin];
_objects[originIndex] = obj;
_indexes[obj] = originIndex;
_indexes.erase(origin);
CC_ASSERT(_objects.count(index) != 0);
_objects[index] = obj;
return obj;
}
+1 -2
View File
@@ -17,13 +17,12 @@ public:
~ArrayPool();
Object *alloc(uint index);
Object *resize(Object *origin, uint size);
Object *resize(Object *origin, uint size, uint index);
private:
static cc::map<PoolType, ArrayPool *> _pools;
cc::map<uint, Object *> _objects;
cc::map<Object *, uint> _indexes;
PoolType _type;
uint _size = 0;
};
+14 -7
View File
@@ -196,15 +196,22 @@ static bool jsb_ArrayPool_resize(se::State &s) {
const auto &args = s.args();
size_t argc = args.size();
if (argc == 2) {
if (argc == 3) {
uint size = 0;
if (seval_to_uint(args[1], &size)) {
s.rval().setObject(arrayPool->resize(args[0].toObject(), size));
return true;
if (!seval_to_uint(args[1], &size)) {
SE_REPORT_ERROR("jsb_ArrayPool_reize: failed to get size.");
return false;
}
SE_REPORT_ERROR("jsb_ArrayPool_reize: failed to resize array");
return false;
uint index = 0;
if (!seval_to_uint(args[2], &index)) {
SE_REPORT_ERROR("jsb_ArrayPool_reize: failed to get index.");
return false;
} else {
s.rval().setObject(arrayPool->resize(args[0].toObject(), size, index));
}
return true;
}
SE_REPORT_ERROR("wrong number of arguments: %d", (int)argc);