From e92eb707798623f2dd8ab5a9f521b63842e9dad4 Mon Sep 17 00:00:00 2001 From: James Chen Date: Wed, 2 Aug 2017 18:06:40 +0800 Subject: [PATCH] cleanup for chakracore. --- .../jswrapper/chakracore/Class.cpp | 8 +- .../jswrapper/chakracore/HelperMacros.h | 7 +- .../jswrapper/chakracore/Object.cpp | 144 ++++++------------ .../jswrapper/chakracore/Object.hpp | 54 +++---- .../jswrapper/chakracore/ScriptEngine.cpp | 14 +- .../jswrapper/chakracore/ScriptEngine.hpp | 3 + .../jswrapper/chakracore/Utils.cpp | 20 ++- .../jswrapper/chakracore/Utils.hpp | 3 - .../js-bindings/jswrapper/jsc/Object.cpp | 2 + .../js-bindings/jswrapper/jsc/Object.hpp | 2 +- .../js-bindings/jswrapper/jsc/Utils.cpp | 5 +- .../js-bindings/jswrapper/jsc/Utils.hpp | 3 - .../js-bindings/jswrapper/sm/Utils.cpp | 3 - .../js-bindings/jswrapper/sm/Utils.hpp | 3 - .../js-bindings/jswrapper/v8/Object.hpp | 3 +- .../js-bindings/jswrapper/v8/Utils.cpp | 3 - .../js-bindings/jswrapper/v8/Utils.hpp | 3 - 17 files changed, 115 insertions(+), 165 deletions(-) diff --git a/native/cocos/scripting/js-bindings/jswrapper/chakracore/Class.cpp b/native/cocos/scripting/js-bindings/jswrapper/chakracore/Class.cpp index bdb1235416..638619ff13 100644 --- a/native/cocos/scripting/js-bindings/jswrapper/chakracore/Class.cpp +++ b/native/cocos/scripting/js-bindings/jswrapper/chakracore/Class.cpp @@ -6,6 +6,7 @@ #include "Utils.hpp" #include "State.hpp" #include "ScriptEngine.hpp" +#include "../HandleObject.hpp" namespace se { @@ -94,13 +95,14 @@ namespace se { } _CHECK(JsCreateNamedFunction(funcName, _ctor, nullptr, &jsConstructor)); - Object* ctorObj = Object::_createJSObject(nullptr, jsConstructor, false); + HandleObject ctorObj(Object::_createJSObject(nullptr, jsConstructor)); // create class's prototype and project its member functions JsValueRef prototype; _CHECK(JsCreateObject(&prototype)); - Object* prototypeObj = Object::_createJSObject(this, prototype, true); + Object* prototypeObj = Object::_createJSObject(this, prototype); + prototypeObj->root(); for (const auto& func : _funcs) { @@ -134,8 +136,6 @@ namespace se { _proto = prototypeObj; _parent->setProperty(_name.c_str(), Value(ctorObj)); - ctorObj->release(); - return true; } diff --git a/native/cocos/scripting/js-bindings/jswrapper/chakracore/HelperMacros.h b/native/cocos/scripting/js-bindings/jswrapper/chakracore/HelperMacros.h index cc497f8f09..bf38d9f1f3 100644 --- a/native/cocos/scripting/js-bindings/jswrapper/chakracore/HelperMacros.h +++ b/native/cocos/scripting/js-bindings/jswrapper/chakracore/HelperMacros.h @@ -47,12 +47,15 @@ { \ if (nativeThisObject != nullptr) \ { \ + auto se = se::ScriptEngine::getInstance(); \ + se->_setInGC(true); \ bool ret = false; \ se::State state(nativeThisObject); \ se::Object* _thisObject = state.thisObject(); \ if (_thisObject) _thisObject->_cleanup(nativeThisObject); \ ret = funcName(state); \ SAFE_RELEASE(_thisObject); \ + se->_setInGC(false); \ } \ } @@ -68,7 +71,7 @@ bool ret = true; \ se::ValueArray args; \ se::internal::jsToSeArgs(argc, _argv+1, &args); \ - se::Object* thisObject = se::Object::createObjectWithClass(cls, false); \ + se::Object* thisObject = se::Object::createObjectWithClass(cls); \ JsValueRef _jsRet = thisObject->_getJSObject(); \ se::State state(thisObject, args); \ ret = funcName(state); \ @@ -98,7 +101,7 @@ bool ret = true; \ se::ValueArray args; \ se::internal::jsToSeArgs(argc, _argv+1, &args); \ - se::Object* thisObject = se::Object::_createJSObject(cls, _argv[0], false); \ + se::Object* thisObject = se::Object::_createJSObject(cls, _argv[0]); \ thisObject->_setFinalizeCallback(_SE(finalizeCb)); \ se::State state(thisObject, args); \ ret = funcName(state); \ diff --git a/native/cocos/scripting/js-bindings/jswrapper/chakracore/Object.cpp b/native/cocos/scripting/js-bindings/jswrapper/chakracore/Object.cpp index 5a46445694..69f7a40c05 100644 --- a/native/cocos/scripting/js-bindings/jswrapper/chakracore/Object.cpp +++ b/native/cocos/scripting/js-bindings/jswrapper/chakracore/Object.cpp @@ -8,13 +8,13 @@ namespace se { std::unordered_map __nativePtrToObjectMap; + std::unordered_map __nonRefNativeObjectCreatedByCtorMap; Object::Object() : _cls(nullptr) , _obj(JS_INVALID_REFERENCE) - , _isRooted(false) - , _isKeepRootedUntilDie(false) - , _hasPrivateData(false) + , _rootCount(0) + , _privateData(nullptr) , _isCleanup(false) , _finalizeCb(nullptr) { @@ -25,31 +25,23 @@ namespace se { _cleanup(); } - Object* Object::createPlainObject(bool rooted) + Object* Object::createPlainObject() { JsValueRef jsobj; _CHECK(JsCreateObject(&jsobj)); - Object* obj = _createJSObject(nullptr, jsobj, rooted); + Object* obj = _createJSObject(nullptr, jsobj); return obj; } -// Object* Object::createObject(const char* clsName, bool rooted) -// { -// Class* cls = nullptr; -// JsValueRef jsObj = Class::_createJSObject(clsName, &cls); -// Object* obj = _createJSObject(cls, jsObj, rooted); -// return obj; -// } - - Object* Object::createArrayObject(size_t length, bool rooted) + Object* Object::createArrayObject(size_t length) { JsValueRef jsObj = JS_INVALID_REFERENCE; _CHECK(JsCreateArray((unsigned int)length, &jsObj)); - Object* obj = _createJSObject(nullptr, jsObj, rooted); + Object* obj = _createJSObject(nullptr, jsObj); return obj; } - Object* Object::createArrayBufferObject(void* data, size_t byteLength, bool rooted) + Object* Object::createArrayBufferObject(void* data, size_t byteLength) { Object* obj = nullptr; JsValueRef jsobj; @@ -59,13 +51,13 @@ namespace se { if (JsNoError == JsGetArrayBufferStorage(jsobj, &buffer, &bufferLength)) { memcpy((void*)buffer, data, byteLength); - obj = Object::_createJSObject(nullptr, jsobj, rooted); + obj = Object::_createJSObject(nullptr, jsobj); } return obj; } - Object* Object::createUint8TypedArray(uint8_t* data, size_t byteLength, bool rooted) + Object* Object::createUint8TypedArray(uint8_t* data, size_t byteLength) { Object* obj = nullptr; JsValueRef jsobj; @@ -77,13 +69,13 @@ namespace se { if (JsNoError == JsGetTypedArrayStorage(jsobj, &buffer, &bufferLength, &arrType, &elementSize)) { memcpy((void*)buffer, data, byteLength); - obj = Object::_createJSObject(nullptr, jsobj, rooted); + obj = Object::_createJSObject(nullptr, jsobj); } return obj; } - Object* Object::createJSONObject(const std::string& jsonStr, bool rooted) + Object* Object::createJSONObject(const std::string& jsonStr) { bool ok = false; Object* obj = nullptr; @@ -102,7 +94,7 @@ namespace se { args.push_back(Value(jsonStr)); if (parseVal.toObject()->call(args, jsonVal.toObject(), &ret)) { - obj = Object::_createJSObject(nullptr, ret.toObject(), rooted); + obj = Object::_createJSObject(nullptr, ret.toObject()); } return obj; @@ -120,21 +112,10 @@ namespace se { return obj; } -// Object* Object::getOrCreateObjectWithPtr(void* ptr, const char* clsName, bool rooted) -// { -// Object* obj = getObjectWithPtr(ptr); -// if (obj == nullptr) -// { -// obj = createObject(clsName, rooted); -// obj->setPrivateData(ptr); -// } -// return obj; -// } - - Object* Object::_createJSObject(Class* cls, JsValueRef obj, bool rooted) + Object* Object::_createJSObject(Class* cls, JsValueRef obj) { Object* ret = new Object(); - if (!ret->init(obj, rooted)) + if (!ret->init(obj)) { delete ret; ret = nullptr; @@ -144,22 +125,16 @@ namespace se { return ret; } - Object* Object::createObjectWithClass(Class* cls, bool rooted) + Object* Object::createObjectWithClass(Class* cls) { JsValueRef jsobj = Class::_createJSObjectWithClass(cls); - Object* obj = Object::_createJSObject(cls, jsobj, rooted); + Object* obj = Object::_createJSObject(cls, jsobj); return obj; } - bool Object::init(JsValueRef obj, bool rooted) + bool Object::init(JsValueRef obj) { _obj = obj; - _isRooted = rooted; - if (_isRooted) - { - unsigned int count = 0; - _CHECK(JsAddRef(_obj, &count)); - } return true; } @@ -168,7 +143,7 @@ namespace se { if (_isCleanup) return; - if (_hasPrivateData) + if (_privateData != nullptr) { if (_obj != nullptr) { @@ -188,7 +163,7 @@ namespace se { } } - if (_isRooted) + if (_rootCount > 0) { // Don't unprotect if it's in cleanup, otherwise, it will trigger crash. if (!ScriptEngine::getInstance()->_isInCleanup) @@ -196,6 +171,7 @@ namespace se { unsigned int count = 0; _CHECK(JsRelease(_obj, &count)); } + _rootCount = 0; } _isCleanup = true; @@ -205,6 +181,7 @@ namespace se { { ScriptEngine::getInstance()->addAfterCleanupHook([](){ __nativePtrToObjectMap.clear(); + __nonRefNativeObjectCreatedByCtorMap.clear(); }); } @@ -533,48 +510,32 @@ namespace se { return ret; } -// void Object::getAsUint8Array(unsigned char **ptr, unsigned int *length) -// { -// assert(false); -// } -// -// void Object::getAsUint16Array(unsigned short **ptr, unsigned int *length) -// { -// assert(false); -// } -// void Object::getAsUint32Array(unsigned int **ptr, unsigned int *length) -// { -// assert(false); -// } -// -// void Object::getAsFloat32Array(float **ptr, unsigned int *length) -// { -// assert(false); -// } - - - void* Object::getPrivateData() + void* Object::getPrivateData() const { - return internal::getPrivate(_obj); + if (_privateData == nullptr) + { + const_cast(this)->_privateData = internal::getPrivate(_obj); + } + return _privateData; } - void Object::setPrivateData(void *data) + void Object::setPrivateData(void* data) { - assert(!_hasPrivateData); + assert(_privateData == nullptr); assert(__nativePtrToObjectMap.find(data) == __nativePtrToObjectMap.end()); internal::setPrivate(_obj, data, _finalizeCb); __nativePtrToObjectMap.emplace(data, this); - _hasPrivateData = true; + _privateData = data; } void Object::clearPrivateData() { - if (_hasPrivateData) + if (_privateData != nullptr) { void* data = getPrivateData(); __nativePtrToObjectMap.erase(data); internal::clearPrivate(_obj); - _hasPrivateData = false; + _privateData = nullptr; } } @@ -590,41 +551,30 @@ namespace se { void Object::root() { - if (_isRooted) - return; - - unsigned int count = 0; - _CHECK(JsAddRef(_obj, &count)); - _isRooted = true; + if (_rootCount == 0) + { + unsigned int count = 0; + _CHECK(JsAddRef(_obj, &count)); + } + ++_rootCount; } void Object::unroot() { - if (!_isRooted) - return; - - if (_isKeepRootedUntilDie) - return; - - unsigned int count = 0; - _CHECK(JsRelease(_obj, &count)); - _isRooted = false; - } - - void Object::setKeepRootedUntilDie(bool keepRooted) - { - _isKeepRootedUntilDie = keepRooted; - - if (_isKeepRootedUntilDie) + if (_rootCount > 0) { - if (!_isRooted) - root(); + --_rootCount; + if (_rootCount == 0) + { + unsigned int count = 0; + _CHECK(JsRelease(_obj, &count)); + } } } bool Object::isRooted() const { - return _isRooted; + return _rootCount > 0; } bool Object::isSame(Object* o) const diff --git a/native/cocos/scripting/js-bindings/jswrapper/chakracore/Object.hpp b/native/cocos/scripting/js-bindings/jswrapper/chakracore/Object.hpp index 8fea200a6a..3bc6083510 100644 --- a/native/cocos/scripting/js-bindings/jswrapper/chakracore/Object.hpp +++ b/native/cocos/scripting/js-bindings/jswrapper/chakracore/Object.hpp @@ -14,35 +14,20 @@ namespace se { class Object final : public Ref { - private: - Object(); public: - virtual ~Object(); - - static Object* createPlainObject(bool rooted); -// static Object* createObject(const char* clsName, bool rooted); - static Object* createArrayObject(size_t length, bool rooted); - static Object* createUint8TypedArray(uint8_t* data, size_t byteLength, bool rooted); - static Object* createArrayBufferObject(void* data, size_t byteLength, bool rooted); - static Object* createJSONObject(const std::string& jsonStr, bool rooted); + static Object* createPlainObject(); + static Object* createArrayObject(size_t length); + static Object* createUint8TypedArray(uint8_t* data, size_t byteLength); + static Object* createArrayBufferObject(void* data, size_t byteLength); + static Object* createJSONObject(const std::string& jsonStr); static Object* getObjectWithPtr(void* ptr); -// static Object* getOrCreateObjectWithPtr(void* ptr, const char* clsName, bool rooted); - static Object* createObjectWithClass(Class* cls, bool rooted); - static Object* _createJSObject(Class* cls, JsValueRef obj, bool rooted); - - bool init(JsValueRef obj, bool rooted); + static Object* createObjectWithClass(Class* cls); bool getProperty(const char* name, Value* data); void setProperty(const char* name, const Value& v); bool defineProperty(const char *name, JsNativeFunction getter, JsNativeFunction setter); - JsValueRef _getJSObject() const; - Class* _getClass() const; - void _cleanup(void* nativeObject = nullptr); - void _setFinalizeCallback(JsFinalizeCallback finalizeCb); - bool isFunction() const; - bool _isNativeFunction() const; bool call(const ValueArray& args, Object* thisObject, Value* rval = nullptr); bool defineFunction(const char *funcName, JsNativeFunction func); @@ -50,11 +35,6 @@ namespace se { bool isTypedArray() const; bool getTypedArrayData(uint8_t** ptr, size_t* length) const; -// void getAsUint8Array(unsigned char **ptr, unsigned int *length); -// void getAsUint16Array(unsigned short **ptr, unsigned int *length); -// void getAsUint32Array(unsigned int **ptr, unsigned int *length); -// void getAsFloat32Array(float **ptr, unsigned int *length); - bool isArray() const; bool getArrayLength(uint32_t* length) const; bool getArrayElement(uint32_t index, Value* data) const; @@ -66,26 +46,37 @@ namespace se { bool getAllKeys(std::vector* allKeys) const; void setPrivateData(void* data); - void* getPrivateData(); + void* getPrivateData() const; void clearPrivateData(); void root(); void unroot(); - void setKeepRootedUntilDie(bool keepRooted); bool isRooted() const; bool isSame(Object* o) const; bool attachChild(Object* child); bool detachChild(Object* child); + // Private API used in wrapper + static Object* _createJSObject(Class* cls, JsValueRef obj); + JsValueRef _getJSObject() const; + Class* _getClass() const; + void _cleanup(void* nativeObject = nullptr); + void _setFinalizeCallback(JsFinalizeCallback finalizeCb); + bool _isNativeFunction() const; + // + private: static void cleanup(); + Object(); + virtual ~Object(); + bool init(JsValueRef obj); + Class* _cls; JsValueRef _obj; - bool _isRooted; - bool _isKeepRootedUntilDie; - bool _hasPrivateData; + uint32_t _rootCount; + void* _privateData; bool _isCleanup; JsFinalizeCallback _finalizeCb; @@ -94,6 +85,7 @@ namespace se { extern std::unordered_map __nativePtrToObjectMap; + extern std::unordered_map __nonRefNativeObjectCreatedByCtorMap; } // namespace se { diff --git a/native/cocos/scripting/js-bindings/jswrapper/chakracore/ScriptEngine.cpp b/native/cocos/scripting/js-bindings/jswrapper/chakracore/ScriptEngine.cpp index 4502594900..09fc1f035f 100644 --- a/native/cocos/scripting/js-bindings/jswrapper/chakracore/ScriptEngine.cpp +++ b/native/cocos/scripting/js-bindings/jswrapper/chakracore/ScriptEngine.cpp @@ -76,6 +76,7 @@ namespace se { , _globalObj(nullptr) , _isValid(false) , _isInCleanup(false) + , _isInGC(false) , _currentSourceContext(0) { } @@ -96,7 +97,8 @@ namespace se { _CHECK(JsSetRuntimeBeforeCollectCallback(_rt, nullptr, myJsBeforeCollectCallback)); - _globalObj = Object::_createJSObject(nullptr, globalObj, true); + _globalObj = Object::_createJSObject(nullptr, globalObj); + _globalObj->root(); _globalObj->defineFunction("log", __log); _globalObj->defineFunction("forceGC", __forceGC); @@ -242,6 +244,16 @@ namespace se { return ok; } + bool ScriptEngine::isInGC() + { + return _isInGC; + } + + void ScriptEngine::_setInGC(bool isInGC) + { + _isInGC = isInGC; + } + void ScriptEngine::gc() { LOGD("GC begin ..., (Native -> JS map) count: %d\n", (int)__nativePtrToObjectMap.size()); diff --git a/native/cocos/scripting/js-bindings/jswrapper/chakracore/ScriptEngine.hpp b/native/cocos/scripting/js-bindings/jswrapper/chakracore/ScriptEngine.hpp index c870893955..5ac71f32e4 100644 --- a/native/cocos/scripting/js-bindings/jswrapper/chakracore/ScriptEngine.hpp +++ b/native/cocos/scripting/js-bindings/jswrapper/chakracore/ScriptEngine.hpp @@ -46,6 +46,8 @@ namespace se { bool executeScriptBuffer(const char *string, Value *data = nullptr, const char *fileName = nullptr); bool executeScriptBuffer(const char *string, size_t length, Value *data = nullptr, const char *fileName = nullptr); + bool isInGC(); + void _setInGC(bool isInGC); void gc(); bool isValid() { return _isValid; } @@ -78,6 +80,7 @@ namespace se { bool _isValid; bool _isInCleanup; + bool _isInGC; unsigned _currentSourceContext; NodeEventListener _nodeEventListener; diff --git a/native/cocos/scripting/js-bindings/jswrapper/chakracore/Utils.cpp b/native/cocos/scripting/js-bindings/jswrapper/chakracore/Utils.cpp index 5334200e3f..c3138222fd 100644 --- a/native/cocos/scripting/js-bindings/jswrapper/chakracore/Utils.cpp +++ b/native/cocos/scripting/js-bindings/jswrapper/chakracore/Utils.cpp @@ -12,12 +12,10 @@ #include "Object.hpp" #include "ScriptEngine.hpp" +#include "../HandleObject.hpp" namespace se { - const bool NEED_THIS = true; - const bool DONT_NEED_THIS = false; - namespace internal { bool defineProperty(JsValueRef obj, const char* name, JsNativeFunction getter, JsNativeFunction setter, bool enumerable, bool configurable) @@ -117,7 +115,18 @@ namespace se { else if (type == JsObject || type == JsFunction || type == JsArrayBuffer || type == JsTypedArray || type == JsArray) { - Object* obj = Object::_createJSObject(nullptr, jsValue, true); + void* nativePtr = internal::getPrivate(jsValue); + Object* obj = nullptr; + if (nativePtr != nullptr) + { + obj = Object::getObjectWithPtr(nativePtr); + } + + if (obj == nullptr) + { + obj = Object::_createJSObject(nullptr, jsValue); + obj->root(); + } data->setObject(obj); obj->release(); } @@ -216,7 +225,7 @@ namespace se { } assert(finalizeCb); - Object* privateObj = Object::createObjectWithClass(__jsb_CCPrivateData_class, false); + HandleObject privateObj(Object::createObjectWithClass(__jsb_CCPrivateData_class)); internal::PrivateData* privateData = (internal::PrivateData*)malloc(sizeof(internal::PrivateData)); privateData->data = data; privateData->finalizeCb = finalizeCb; @@ -226,7 +235,6 @@ namespace se { JsPropertyIdRef propertyId = JS_INVALID_REFERENCE; JsCreatePropertyId(KEY_PRIVATE_DATA, strlen(KEY_PRIVATE_DATA), &propertyId); _CHECK(JsSetProperty(obj, propertyId, privateObj->_getJSObject(), true)); - privateObj->release(); } void* getPrivate(JsValueRef obj) diff --git a/native/cocos/scripting/js-bindings/jswrapper/chakracore/Utils.hpp b/native/cocos/scripting/js-bindings/jswrapper/chakracore/Utils.hpp index 19fcb0803b..ec2a50fb49 100644 --- a/native/cocos/scripting/js-bindings/jswrapper/chakracore/Utils.hpp +++ b/native/cocos/scripting/js-bindings/jswrapper/chakracore/Utils.hpp @@ -10,9 +10,6 @@ namespace se { - extern const bool NEED_THIS; - extern const bool DONT_NEED_THIS; - namespace internal { struct PrivateData diff --git a/native/cocos/scripting/js-bindings/jswrapper/jsc/Object.cpp b/native/cocos/scripting/js-bindings/jswrapper/jsc/Object.cpp index e49e9dda76..e3ae9e7072 100644 --- a/native/cocos/scripting/js-bindings/jswrapper/jsc/Object.cpp +++ b/native/cocos/scripting/js-bindings/jswrapper/jsc/Object.cpp @@ -174,6 +174,8 @@ namespace se { // Don't unprotect if it's in cleanup, otherwise, it will trigger crash. if (!ScriptEngine::getInstance()->_isInCleanup) JSValueUnprotect(__cx, _obj); + + _rootCount = 0; } _isCleanup = true; diff --git a/native/cocos/scripting/js-bindings/jswrapper/jsc/Object.hpp b/native/cocos/scripting/js-bindings/jswrapper/jsc/Object.hpp index 8e778195bc..b20215bc1a 100644 --- a/native/cocos/scripting/js-bindings/jswrapper/jsc/Object.hpp +++ b/native/cocos/scripting/js-bindings/jswrapper/jsc/Object.hpp @@ -22,7 +22,6 @@ namespace se { static Object* createJSONObject(const std::string& jsonStr); static Object* getObjectWithPtr(void* ptr); static Object* createObjectWithClass(Class* cls); - static Object* _createJSObject(Class* cls, JSObjectRef obj); bool getProperty(const char* name, Value* data); void setProperty(const char* name, const Value& v); @@ -60,6 +59,7 @@ namespace se { bool detachChild(Object* child); // Private API used in wrapper + static Object* _createJSObject(Class* cls, JSObjectRef obj); JSObjectRef _getJSObject() const; Class* _getClass() const; void _setFinalizeCallback(JSObjectFinalizeCallback finalizeCb); diff --git a/native/cocos/scripting/js-bindings/jswrapper/jsc/Utils.cpp b/native/cocos/scripting/js-bindings/jswrapper/jsc/Utils.cpp index ef7ef3367a..96fe687b6d 100644 --- a/native/cocos/scripting/js-bindings/jswrapper/jsc/Utils.cpp +++ b/native/cocos/scripting/js-bindings/jswrapper/jsc/Utils.cpp @@ -12,13 +12,10 @@ #include "Object.hpp" #include "ScriptEngine.hpp" -#include "HandleObject.hpp" +#include "../HandleObject.hpp" namespace se { - const bool NEED_THIS = true; - const bool DONT_NEED_THIS = false; - namespace internal { namespace { diff --git a/native/cocos/scripting/js-bindings/jswrapper/jsc/Utils.hpp b/native/cocos/scripting/js-bindings/jswrapper/jsc/Utils.hpp index e1c86824ba..97c98a84e3 100644 --- a/native/cocos/scripting/js-bindings/jswrapper/jsc/Utils.hpp +++ b/native/cocos/scripting/js-bindings/jswrapper/jsc/Utils.hpp @@ -9,9 +9,6 @@ #include "../Value.hpp" namespace se { - - extern const bool NEED_THIS; - extern const bool DONT_NEED_THIS; namespace internal { diff --git a/native/cocos/scripting/js-bindings/jswrapper/sm/Utils.cpp b/native/cocos/scripting/js-bindings/jswrapper/sm/Utils.cpp index f39eeb084d..52dbde5f95 100644 --- a/native/cocos/scripting/js-bindings/jswrapper/sm/Utils.cpp +++ b/native/cocos/scripting/js-bindings/jswrapper/sm/Utils.cpp @@ -16,9 +16,6 @@ namespace se { - const bool NEED_THIS = true; - const bool DONT_NEED_THIS = false; - namespace internal { std::string jsToStdString(JSContext* cx, JS::HandleString jsStr) diff --git a/native/cocos/scripting/js-bindings/jswrapper/sm/Utils.hpp b/native/cocos/scripting/js-bindings/jswrapper/sm/Utils.hpp index 8de2a0b743..67c5fae540 100644 --- a/native/cocos/scripting/js-bindings/jswrapper/sm/Utils.hpp +++ b/native/cocos/scripting/js-bindings/jswrapper/sm/Utils.hpp @@ -10,9 +10,6 @@ namespace se { - extern const bool NEED_THIS; - extern const bool DONT_NEED_THIS; - class Class; namespace internal { diff --git a/native/cocos/scripting/js-bindings/jswrapper/v8/Object.hpp b/native/cocos/scripting/js-bindings/jswrapper/v8/Object.hpp index 96e1079ebb..61fdbbf1ac 100644 --- a/native/cocos/scripting/js-bindings/jswrapper/v8/Object.hpp +++ b/native/cocos/scripting/js-bindings/jswrapper/v8/Object.hpp @@ -27,7 +27,7 @@ namespace se { static Object* createJSONObject(const std::string& jsonStr); static Object* getObjectWithPtr(void* ptr); static Object* createObjectWithClass(Class* cls); - static Object* _createJSObject(Class* cls, v8::Local obj); + bool getProperty(const char *name, Value* data); void setProperty(const char *name, const Value& data); @@ -65,6 +65,7 @@ namespace se { bool detachChild(Object* child); // Private API used in wrapper + static Object* _createJSObject(Class* cls, v8::Local obj); v8::Local _getJSObject() const; ObjectWrap& _getWrap(); Class* _getClass() const; diff --git a/native/cocos/scripting/js-bindings/jswrapper/v8/Utils.cpp b/native/cocos/scripting/js-bindings/jswrapper/v8/Utils.cpp index f0a5bf25d1..10140df29f 100644 --- a/native/cocos/scripting/js-bindings/jswrapper/v8/Utils.cpp +++ b/native/cocos/scripting/js-bindings/jswrapper/v8/Utils.cpp @@ -8,9 +8,6 @@ namespace se { - const bool NEED_THIS = true; - const bool DONT_NEED_THIS = false; - namespace internal { void jsToSeArgs(const v8::FunctionCallbackInfo& v8args, ValueArray* outArr) diff --git a/native/cocos/scripting/js-bindings/jswrapper/v8/Utils.hpp b/native/cocos/scripting/js-bindings/jswrapper/v8/Utils.hpp index 10072226dd..91d122c55c 100644 --- a/native/cocos/scripting/js-bindings/jswrapper/v8/Utils.hpp +++ b/native/cocos/scripting/js-bindings/jswrapper/v8/Utils.hpp @@ -9,9 +9,6 @@ #include "ObjectWrap.h" namespace se { - - extern const bool NEED_THIS; - extern const bool DONT_NEED_THIS; namespace internal {