Fix incorrect usage of PersistentRootedObject in jsb websocket

This commit is contained in:
pandamicro
2017-09-19 09:55:21 +08:00
parent 21ce3ba37d
commit d54cdb6f4d
@@ -65,6 +65,7 @@ class JSB_WebSocketDelegate : public Ref, public WebSocket::Delegate
public:
JSB_WebSocketDelegate()
: _JSDelegate(nullptr)
{
}
@@ -83,7 +84,7 @@ public:
return;
JSContext* cx = ScriptingCore::getInstance()->getGlobalContext();
JS::RootedValue owner(cx, JS::ObjectOrNullValue(_JSDelegate));
JS::RootedValue owner(cx, JS::ObjectOrNullValue(_JSDelegate->get()));
if (owner.isObject())
{
// Set the protocol which server selects.
@@ -113,7 +114,7 @@ public:
return;
JSContext* cx = ScriptingCore::getInstance()->getGlobalContext();
JS::RootedValue delegate(cx, JS::ObjectOrNullValue(_JSDelegate));
JS::RootedValue delegate(cx, JS::ObjectOrNullValue(_JSDelegate->get()));
if (delegate.isObject())
{
JS::RootedObject jsobj(cx, JS_NewPlainObject(cx));
@@ -166,7 +167,7 @@ public:
if (cocos2d::Director::getInstance() != nullptr && cocos2d::Director::getInstance()->getRunningScene() && cocos2d::ScriptEngineManager::getInstance() != nullptr)
{
JSContext* cx = ScriptingCore::getInstance()->getGlobalContext();
JS::RootedValue delegate(cx, JS::ObjectOrNullValue(_JSDelegate));
JS::RootedValue delegate(cx, JS::ObjectOrNullValue(_JSDelegate->get()));
if (delegate.isObject())
{
JS::RootedObject jsobj(cx, JS_NewPlainObject(cx));
@@ -194,7 +195,7 @@ public:
return;
JSContext* cx = ScriptingCore::getInstance()->getGlobalContext();
JS::RootedValue delegate(cx, JS::ObjectOrNullValue(_JSDelegate));
JS::RootedValue delegate(cx, JS::ObjectOrNullValue(_JSDelegate->get()));
if (delegate.isObject())
{
JS::RootedObject jsobj(cx, JS_NewPlainObject(cx));
@@ -210,10 +211,14 @@ public:
void setJSDelegate(JS::HandleObject pJSDelegate)
{
_JSDelegate = pJSDelegate;
if (_JSDelegate) {
CC_SAFE_DELETE(_JSDelegate);
}
JSContext* cx = ScriptingCore::getInstance()->getGlobalContext();
_JSDelegate = new (std::nothrow) JS::PersistentRootedObject(cx, pJSDelegate);
}
private:
JS::PersistentRootedObject _JSDelegate;
JS::PersistentRootedObject *_JSDelegate;
};
JSClass *js_cocos2dx_websocket_class;