mirror of
https://github.com/cocos/cocos4.git
synced 2026-12-04 18:42:40 +08:00
se::Object::setProperty should return boolean.
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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<v8::String> nameValue = v8::String::NewFromUtf8(__isolate, name, v8::NewStringType::kNormal);
|
||||
if (nameValue.IsEmpty())
|
||||
return;
|
||||
return false;
|
||||
|
||||
v8::Local<v8::Value> 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)
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user