From 76981db2ac8f16040e3eb3516f17808ba7b7bfcb Mon Sep 17 00:00:00 2001 From: James Chen Date: Mon, 9 Oct 2017 14:59:05 +0800 Subject: [PATCH] se::Object::setProperty should return boolean. --- .../scripting/js-bindings/jswrapper/chakracore/Object.cpp | 3 ++- .../scripting/js-bindings/jswrapper/chakracore/Object.hpp | 2 +- native/cocos/scripting/js-bindings/jswrapper/jsc/Object.cpp | 6 +++++- native/cocos/scripting/js-bindings/jswrapper/jsc/Object.hpp | 3 ++- native/cocos/scripting/js-bindings/jswrapper/sm/Object.cpp | 4 ++-- native/cocos/scripting/js-bindings/jswrapper/sm/Object.hpp | 2 +- native/cocos/scripting/js-bindings/jswrapper/v8/Object.cpp | 6 ++++-- native/cocos/scripting/js-bindings/jswrapper/v8/Object.hpp | 2 +- 8 files changed, 18 insertions(+), 10 deletions(-) diff --git a/native/cocos/scripting/js-bindings/jswrapper/chakracore/Object.cpp b/native/cocos/scripting/js-bindings/jswrapper/chakracore/Object.cpp index 1ceae6dceb..afb432b1f8 100644 --- a/native/cocos/scripting/js-bindings/jswrapper/chakracore/Object.cpp +++ b/native/cocos/scripting/js-bindings/jswrapper/chakracore/Object.cpp @@ -225,13 +225,14 @@ namespace se { return exist; } - void Object::setProperty(const char* name, const Value& v) + bool Object::setProperty(const char* name, const Value& v) { JsValueRef jsValue = JS_INVALID_REFERENCE; internal::seToJsValue(v, &jsValue); JsPropertyIdRef propertyId; _CHECK(JsCreatePropertyId(name, strlen(name), &propertyId)); _CHECK(JsSetProperty(_obj, propertyId, jsValue, true)); + return true; } bool Object::defineProperty(const char *name, JsNativeFunction getter, JsNativeFunction setter) diff --git a/native/cocos/scripting/js-bindings/jswrapper/chakracore/Object.hpp b/native/cocos/scripting/js-bindings/jswrapper/chakracore/Object.hpp index db26d0ca35..9ffc6dff15 100644 --- a/native/cocos/scripting/js-bindings/jswrapper/chakracore/Object.hpp +++ b/native/cocos/scripting/js-bindings/jswrapper/chakracore/Object.hpp @@ -24,7 +24,7 @@ namespace se { static Object* createObjectWithClass(Class* cls); bool getProperty(const char* name, Value* data); - void setProperty(const char* name, const Value& v); + bool setProperty(const char* name, const Value& v); bool defineProperty(const char *name, JsNativeFunction getter, JsNativeFunction setter); bool isFunction() const; diff --git a/native/cocos/scripting/js-bindings/jswrapper/jsc/Object.cpp b/native/cocos/scripting/js-bindings/jswrapper/jsc/Object.cpp index 4fff432689..8fd2d6743d 100644 --- a/native/cocos/scripting/js-bindings/jswrapper/jsc/Object.cpp +++ b/native/cocos/scripting/js-bindings/jswrapper/jsc/Object.cpp @@ -227,8 +227,9 @@ namespace se { return exist; } - void Object::setProperty(const char* name, const Value& v) + bool Object::setProperty(const char* name, const Value& v) { + bool ret = true; JSStringRef jsName = JSStringCreateWithUTF8CString(name); JSValueRef jsValue = nullptr; JSObjectRef obj = _obj; @@ -265,9 +266,12 @@ namespace se { if (exception != nullptr) { ScriptEngine::getInstance()->_clearException(exception); + ret = false; } JSStringRelease(jsName); + + return ret; } bool Object::defineProperty(const char *name, JSObjectCallAsFunctionCallback getter, JSObjectCallAsFunctionCallback setter) diff --git a/native/cocos/scripting/js-bindings/jswrapper/jsc/Object.hpp b/native/cocos/scripting/js-bindings/jswrapper/jsc/Object.hpp index 025ee544ec..c7c445531f 100644 --- a/native/cocos/scripting/js-bindings/jswrapper/jsc/Object.hpp +++ b/native/cocos/scripting/js-bindings/jswrapper/jsc/Object.hpp @@ -87,8 +87,9 @@ namespace se { * @brief Sets a property to an object. * @param[in] name A utf-8 string containing the property's name. * @param[in] value A value to be used as the property's value. + * @return true if the property is set successfully, otherwise false. */ - void setProperty(const char* name, const Value& value); + bool setProperty(const char* name, const Value& value); /** * @brief Defines a property with native accessor callbacks for an object. diff --git a/native/cocos/scripting/js-bindings/jswrapper/sm/Object.cpp b/native/cocos/scripting/js-bindings/jswrapper/sm/Object.cpp index 2cba64ecf5..9ab8dd148a 100644 --- a/native/cocos/scripting/js-bindings/jswrapper/sm/Object.cpp +++ b/native/cocos/scripting/js-bindings/jswrapper/sm/Object.cpp @@ -176,13 +176,13 @@ namespace se { return ok; } - void Object::setProperty(const char* name, const Value& v) + bool Object::setProperty(const char* name, const Value& v) { JS::RootedObject object(__cx, _getJSObject()); JS::RootedValue value(__cx); internal::seToJsValue(__cx, v, &value); - JS_SetProperty(__cx, object, name, value); + return JS_SetProperty(__cx, object, name, value); } bool Object::defineProperty(const char *name, JSNative getter, JSNative setter) diff --git a/native/cocos/scripting/js-bindings/jswrapper/sm/Object.hpp b/native/cocos/scripting/js-bindings/jswrapper/sm/Object.hpp index 323a1bf8c3..ef64affc3e 100644 --- a/native/cocos/scripting/js-bindings/jswrapper/sm/Object.hpp +++ b/native/cocos/scripting/js-bindings/jswrapper/sm/Object.hpp @@ -24,7 +24,7 @@ namespace se { static Object* getObjectWithPtr(void* ptr); bool getProperty(const char* name, Value* data); - void setProperty(const char* name, const Value& v); + bool setProperty(const char* name, const Value& v); bool defineProperty(const char *name, JSNative getter, JSNative setter); bool isFunction() const; diff --git a/native/cocos/scripting/js-bindings/jswrapper/v8/Object.cpp b/native/cocos/scripting/js-bindings/jswrapper/v8/Object.cpp index 0819476c58..00c4557eb3 100644 --- a/native/cocos/scripting/js-bindings/jswrapper/v8/Object.cpp +++ b/native/cocos/scripting/js-bindings/jswrapper/v8/Object.cpp @@ -256,11 +256,11 @@ namespace se { return true; } - void Object::setProperty(const char *name, const Value& data) + bool Object::setProperty(const char *name, const Value& data) { v8::MaybeLocal nameValue = v8::String::NewFromUtf8(__isolate, name, v8::NewStringType::kNormal); if (nameValue.IsEmpty()) - return; + return false; v8::Local value; internal::seToJsValue(__isolate, data, &value); @@ -268,7 +268,9 @@ namespace se { if (ret.IsNothing()) { LOGD("ERROR: %s, Set return nothing ...\n", __FUNCTION__); + return false; } + return true; } bool Object::defineProperty(const char *name, v8::AccessorNameGetterCallback getter, v8::AccessorNameSetterCallback setter) diff --git a/native/cocos/scripting/js-bindings/jswrapper/v8/Object.hpp b/native/cocos/scripting/js-bindings/jswrapper/v8/Object.hpp index eaddbc08f0..3324d33cc7 100644 --- a/native/cocos/scripting/js-bindings/jswrapper/v8/Object.hpp +++ b/native/cocos/scripting/js-bindings/jswrapper/v8/Object.hpp @@ -30,7 +30,7 @@ namespace se { bool getProperty(const char *name, Value* data); - void setProperty(const char *name, const Value& data); + bool setProperty(const char *name, const Value& data); bool defineProperty(const char *name, v8::AccessorNameGetterCallback getter, v8::AccessorNameSetterCallback setter); bool isFunction() const;