@@ -59,7 +59,7 @@ Value Value::fromJSON(JSContextRef ctx, const String& json) {
59
59
return Value (ctx, result);
60
60
}
61
61
62
- JSValueRef Value::fromDynamic (JSContextRef ctx, const folly::dynamic& value) {
62
+ Value Value::fromDynamic (JSContextRef ctx, const folly::dynamic& value) {
63
63
// JavaScriptCore's iOS APIs have their own version of this direct conversion.
64
64
// In addition, using this requires exposing some of JSC's private APIs,
65
65
// so it's limited to non-apple platforms and to builds that use the custom JSC.
@@ -75,7 +75,7 @@ JSValueRef Value::fromDynamic(JSContextRef ctx, const folly::dynamic& value) {
75
75
JSValueRef jsVal = Value::fromDynamicInner (ctx, value);
76
76
JSUnlock (ctx);
77
77
JSResumeGarbageCollection (ctx, deferGC);
78
- return jsVal;
78
+ return Value (ctx, jsVal) ;
79
79
#else
80
80
auto json = folly::toJson (value);
81
81
return fromJSON (ctx, String (ctx, json.c_str ()));
@@ -140,9 +140,7 @@ Object Value::asObject() {
140
140
std::string exceptionText = Value (m_context, exn).toString ().str ();
141
141
throwJSExecutionException (" Failed to convert to object: %s" , exceptionText.c_str ());
142
142
}
143
- Object ret = Object (context (), jsObj);
144
- m_value = nullptr ;
145
- return ret;
143
+ return Object (context (), jsObj);
146
144
}
147
145
148
146
Value Value::makeError (JSContextRef ctx, const char *error)
@@ -207,7 +205,7 @@ Value Object::getProperty(const String& propName) const {
207
205
return Value (m_context, property);
208
206
}
209
207
210
- Value Object::getPropertyAtIndex (unsigned index) const {
208
+ Value Object::getPropertyAtIndex (unsigned int index) const {
211
209
JSValueRef exn;
212
210
JSValueRef property = JSC_JSObjectGetPropertyAtIndex (m_context, m_obj, index , &exn);
213
211
if (!property) {
@@ -221,16 +219,25 @@ Value Object::getProperty(const char *propName) const {
221
219
return getProperty (String (m_context, propName));
222
220
}
223
221
224
- void Object::setProperty (const String& propName, const Value& value) const {
225
- JSValueRef exn = NULL ;
222
+ void Object::setProperty (const String& propName, const Value& value) {
223
+ JSValueRef exn = nullptr ;
226
224
JSC_JSObjectSetProperty (m_context, m_obj, propName, value, kJSPropertyAttributeNone , &exn);
227
225
if (exn) {
228
226
std::string exceptionText = Value (m_context, exn).toString ().str ();
229
227
throwJSExecutionException (" Failed to set property: %s" , exceptionText.c_str ());
230
228
}
231
229
}
232
230
233
- void Object::setProperty (const char *propName, const Value& value) const {
231
+ void Object::setPropertyAtIndex (unsigned int index, const Value& value) {
232
+ JSValueRef exn = nullptr ;
233
+ JSC_JSObjectSetPropertyAtIndex (m_context, m_obj, index , value, &exn);
234
+ if (exn) {
235
+ std::string exceptionText = Value (m_context, exn).toString ().str ();
236
+ throwJSExecutionException (" Failed to set property: %s" , exceptionText.c_str ());
237
+ }
238
+ }
239
+
240
+ void Object::setProperty (const char *propName, const Value& value) {
234
241
setProperty (String (m_context, propName), value);
235
242
}
236
243
0 commit comments