Arguments root stuff fix.

This commit is contained in:
James Chen
2017-08-03 11:47:18 +08:00
parent c7397d3865
commit 24136c2133
7 changed files with 16 additions and 11 deletions
@@ -125,8 +125,8 @@ namespace se {
if (obj == nullptr)
{
obj = Object::_createJSObject(nullptr, jsValue);
obj->root();
}
obj->root(); // Root it here since it will be unrooted in at the end of SE_BIND_FUNC
data->setObject(obj);
obj->release();
}
@@ -158,8 +158,8 @@ namespace se {
if (obj == nullptr)
{
obj = Object::_createJSObject(nullptr, jsobj);
obj->root();
}
obj->root(); // Root it here since it will be unrooted in at the end of SE_BIND_FUNC
data->setObject(obj);
obj->release();
}
@@ -135,8 +135,8 @@ namespace se {
if (object == nullptr)
{
object = Object::_createJSObject(nullptr, jsval.toObjectOrNull());
object->root();
}
object->root(); // Root it here since it will be unrooted in at the end of SE_BIND_FUNC
v->setObject(object);
object->release();
}
@@ -154,8 +154,6 @@ namespace se {
}
}
// --- Sets the return value for a function
void setReturnValue(JSContext* cx, const Value& data, const JS::CallArgs& argv)
{
JS::RootedValue rval(cx);
@@ -107,8 +107,8 @@ namespace se {
if (obj == nullptr)
{
obj = Object::_createJSObject(nullptr, jsObj.ToLocalChecked());
obj->root();
}
obj->root(); // Root it here since it will be unrooted in at the end of SE_BIND_FUNC
v->setObject(obj);
obj->release();
}
@@ -276,7 +276,6 @@ bool native_ptr_to_rooted_seval(typename std::enable_if<!std::is_base_of<cocos2d
auto iter = se::__nativePtrToObjectMap.find(v);
if (iter == se::__nativePtrToObjectMap.end())
{ // If we couldn't find native object in map, then the native object is created from native code. e.g. TMXLayer::getTileAt
CCLOGWARN("WARNING: non-Ref type: (%s) isn't catched!", typeid(*v).name());
se::Class* cls = JSBClassType::findClass<T>(v);
assert(cls != nullptr);
obj = se::Object::createObjectWithClass(cls);
@@ -287,14 +286,17 @@ bool native_ptr_to_rooted_seval(typename std::enable_if<!std::is_base_of<cocos2d
{
*isReturnCachedValue = false;
}
CCLOGWARN("WARNING: non-Ref type: (%s) isn't catched!", typeid(*v).name());
}
else
{
obj = iter->second;
assert(obj->isRooted());
if (isReturnCachedValue != nullptr)
{
*isReturnCachedValue = true;
}
// CCLOG("return cached object: %s, se::Object:%p, native: %p", typeid(*v).name(), obj, v);
}
ret->setObject(obj);
@@ -353,7 +355,6 @@ bool native_ptr_to_rooted_seval(typename std::enable_if<!std::is_base_of<cocos2d
auto iter = se::__nativePtrToObjectMap.find(v);
if (iter == se::__nativePtrToObjectMap.end())
{ // If we couldn't find native object in map, then the native object is created from native code. e.g. TMXLayer::getTileAt
CCLOGWARN("WARNING: non-Ref type: (%s) isn't catched!", typeid(*v).name());
assert(cls != nullptr);
obj = se::Object::createObjectWithClass(cls);
obj->root();
@@ -363,14 +364,17 @@ bool native_ptr_to_rooted_seval(typename std::enable_if<!std::is_base_of<cocos2d
{
*isReturnCachedValue = false;
}
CCLOGWARN("WARNING: non-Ref type: (%s) isn't catched, se::Object:%p, native: %p", typeid(*v).name(), obj, v);
}
else
{
obj = iter->second;
assert(obj->isRooted());
if (isReturnCachedValue != nullptr)
{
*isReturnCachedValue = true;
}
// CCLOG("return cached object: %s, se::Object:%p, native: %p", typeid(*v).name(), obj, v);
}
ret->setObject(obj);
@@ -34,7 +34,9 @@ static bool js_creator_PhysicsContactListener_setPreSolve(se::State& s)
CC_UNUSED bool ok = true;
se::ValueArray args;
args.resize(1);
ok &= native_ptr_to_rooted_seval<b2Contact>(larg0, __jsb_b2Contact_class, &args[0]);
bool fromCache = false;
ok &= native_ptr_to_rooted_seval<b2Contact>(larg0, __jsb_b2Contact_class, &args[0], &fromCache);
se::Value rval;
se::Object* thisObj = jsThis.isObject() ? jsThis.toObject() : nullptr;
se::Object* funcObj = jsFunc.toObject();
+3 -2
View File
@@ -34,7 +34,7 @@ replace_headers = CCScale9Sprite.h::creator/CCScale9Sprite.h,CCGraphicsNode.h::c
# what classes to produce code for. You can use regular expressions here. When testing the regular
# expression, it will be enclosed in "^$", like this: "^Menu*$".
classes = Scale9SpriteV2 GraphicsNode PhysicsDebugDraw PhysicsUtils PhysicsContactListener PhysicsAABBQueryCallback PhysicsRayCastCallback PhysicsWorldManifoldWrapper PhysicsContactImpulse CameraNode
classes = Scale9SpriteV2 GraphicsNode PhysicsDebugDraw PhysicsUtils PhysicsContactListener PhysicsAABBQueryCallback PhysicsRayCastCallback PhysicsWorldManifoldWrapper PhysicsManifoldWrapper PhysicsContactImpulse CameraNode
classes_need_extend = Scale9SpriteV2 GraphicsNode
@@ -50,6 +50,7 @@ skip = PhysicsDebugDraw::[DrawPolygon DrawSolidPolygon DrawCircle DrawSolidCircl
PhysicsAABBQueryCallback::[ReportFixture getFixtures],
PhysicsRayCastCallback::[ReportFixture getFixtures getNormals getPoints],
PhysicsWorldManifoldWrapper::[init getb2WorldManifold],
PhysicsManifoldWrapper::[init],
PhysicsContactImpulse::[init],
CameraNode::[(.*)Visit]
@@ -71,4 +72,4 @@ base_classes_to_skip = Ref
abstract_classes = Helper LayoutManager AbstractCheckButton
classes_owned_by_cpp = PhysicsContactImpulse
classes_owned_by_cpp = PhysicsContactImpulse PhysicsWorldManifoldWrapper PhysicsManifoldWrapper