@@ -131,30 +131,45 @@ JavascriptExternal::GetProperty(wstring iName, Handle<Value> &result)
131
131
PropertyInfo^ propertyInfo = type->GetProperty (gcnew System::String (iName.c_str ()));
132
132
133
133
v8::Isolate *isolate = JavascriptContext::GetCurrentIsolate ();
134
- if (propertyInfo == nullptr )
135
- return false ;
136
- else {
137
- try
134
+ try
135
+ {
136
+ if (propertyInfo == nullptr )
138
137
{
139
- if (!propertyInfo->CanRead )
138
+ // may have an indexer
139
+ PropertyInfo^ indexerInfo = type->GetProperty (" Item" , System::Object::typeid , gcnew cli::array<System::Type^> { System::String::typeid });
140
+ if (indexerInfo == nullptr )
141
+ {
142
+ return false ;
143
+ }
144
+ if (!indexerInfo->CanRead )
140
145
{
141
146
result = isolate->ThrowException (JavascriptInterop::ConvertToV8 (" Property " + gcnew System::String (iName.c_str ()) + " may not be read." ));
142
147
}
143
148
else
144
149
{
145
- result = JavascriptInterop::ConvertToV8 (propertyInfo ->GetValue (self, nullptr ));
150
+ result = JavascriptInterop::ConvertToV8 (indexerInfo ->GetValue (self, gcnew cli::array<System::String^> { gcnew System::String (iName. c_str ()) } ));
146
151
}
152
+ return true ;
147
153
}
148
- catch (System::Reflection::TargetInvocationException^ exception)
154
+
155
+ if (!propertyInfo->CanRead )
149
156
{
150
- result = JavascriptInterop::HandleTargetInvocationException (exception );
157
+ result = isolate-> ThrowException ( JavascriptInterop::ConvertToV8 ( " Property " + gcnew System::String (iName. c_str ()) + " may not be read. " ) );
151
158
}
152
- catch (System::Exception^ exception)
159
+ else
153
160
{
154
- result = isolate-> ThrowException ( JavascriptInterop::ConvertToV8 (exception ));
161
+ result = JavascriptInterop::ConvertToV8 (propertyInfo-> GetValue (self, nullptr ));
155
162
}
156
- return true ;
157
163
}
164
+ catch (System::Reflection::TargetInvocationException^ exception)
165
+ {
166
+ result = JavascriptInterop::HandleTargetInvocationException (exception);
167
+ }
168
+ catch (System::Exception^ exception)
169
+ {
170
+ result = isolate->ThrowException (JavascriptInterop::ConvertToV8 (exception));
171
+ }
172
+ return true ;
158
173
}
159
174
160
175
// //////////////////////////////////////////////////////////////////////////////////////////////////
@@ -212,48 +227,62 @@ JavascriptExternal::SetProperty(wstring iName, Handle<Value> iValue)
212
227
PropertyInfo^ propertyInfo = type->GetProperty (gcnew System::String (iName.c_str ()));
213
228
214
229
v8::Isolate *isolate = JavascriptContext::GetCurrentIsolate ();
215
- if (propertyInfo == nullptr )
216
- {
217
- if ((mOptions & SetParameterOptions::RejectUnknownProperties) == SetParameterOptions::RejectUnknownProperties)
218
- return isolate->ThrowException (JavascriptInterop::ConvertToV8 (" Unknown member: " + gcnew System::String (iName.c_str ())));
219
- }
220
- else
230
+
231
+ try
221
232
{
222
- try
233
+ if (propertyInfo == nullptr )
223
234
{
224
- System::Object^ value = JavascriptInterop::ConvertFromV8 (iValue);
225
- if (value != nullptr ) {
226
- System::Type^ valueType = value->GetType ();
227
- System::Type^ propertyType = propertyInfo->PropertyType ;
228
-
229
- // attempt conversion if assigned value is of wrong type
230
- if (propertyType != valueType && !propertyType->IsAssignableFrom (valueType))
231
- value = SystemInterop::ConvertToType (value, propertyType);
235
+ // may have an indexer
236
+ PropertyInfo^ indexerInfo = type->GetProperty (" Item" , System::Object::typeid , gcnew cli::array<System::Type^> { System::String::typeid });
237
+ if (indexerInfo == nullptr )
238
+ {
239
+ if ((mOptions & SetParameterOptions::RejectUnknownProperties) == SetParameterOptions::RejectUnknownProperties)
240
+ return isolate->ThrowException (JavascriptInterop::ConvertToV8 (" Unknown member: " + gcnew System::String (iName.c_str ())));
241
+ return Handle<Value>();
232
242
}
233
-
234
- if (!propertyInfo->CanWrite )
243
+ if (!indexerInfo->CanWrite )
235
244
{
236
245
return isolate->ThrowException (JavascriptInterop::ConvertToV8 (" Property " + gcnew System::String (iName.c_str ()) + " may not be set." ));
237
246
}
238
247
else
239
248
{
240
- propertyInfo->SetValue (self, value, nullptr );
241
- // We used to convert and return propertyInfo->GetValue() here.
242
- // I don't know why we did, but I stopped it because CanRead
243
- // might be false, which should not stop us _setting_.
244
- // Also it wastes precious CPU time.
245
- return iValue;
249
+ indexerInfo->SetValue (self, JavascriptInterop::ConvertFromV8 (iValue), gcnew cli::array<System::String^> { gcnew System::String (iName.c_str ()) });
246
250
}
251
+ return iValue;
247
252
}
248
- catch (System::Reflection::TargetInvocationException^ exception)
253
+
254
+ System::Object^ value = JavascriptInterop::ConvertFromV8 (iValue);
255
+ if (value != nullptr ) {
256
+ System::Type^ valueType = value->GetType ();
257
+ System::Type^ propertyType = propertyInfo->PropertyType ;
258
+
259
+ // attempt conversion if assigned value is of wrong type
260
+ if (propertyType != valueType && !propertyType->IsAssignableFrom (valueType))
261
+ value = SystemInterop::ConvertToType (value, propertyType);
262
+ }
263
+
264
+ if (!propertyInfo->CanWrite )
249
265
{
250
- return JavascriptInterop::HandleTargetInvocationException (exception );
266
+ return isolate-> ThrowException ( JavascriptInterop::ConvertToV8 ( " Property " + gcnew System::String (iName. c_str ()) + " may not be set. " ) );
251
267
}
252
- catch (System::Exception^ exception)
268
+ else
253
269
{
254
- return isolate->ThrowException (JavascriptInterop::ConvertToV8 (exception));
270
+ propertyInfo->SetValue (self, value, nullptr );
271
+ // We used to convert and return propertyInfo->GetValue() here.
272
+ // I don't know why we did, but I stopped it because CanRead
273
+ // might be false, which should not stop us _setting_.
274
+ // Also it wastes precious CPU time.
275
+ return iValue;
255
276
}
256
277
}
278
+ catch (System::Reflection::TargetInvocationException^ exception)
279
+ {
280
+ return JavascriptInterop::HandleTargetInvocationException (exception);
281
+ }
282
+ catch (System::Exception^ exception)
283
+ {
284
+ return isolate->ThrowException (JavascriptInterop::ConvertToV8 (exception));
285
+ }
257
286
258
287
return Handle<Value>();
259
288
}
0 commit comments