@@ -216,7 +216,7 @@ static void getter(v8::Local<v8::String> property, const v8::PropertyCallbackInf
216
216
bool method_exists = Php::call (" method_exists" , *handle, *name);
217
217
bool is_callable = handle->isCallable (*name);
218
218
bool contains = handle->contains (*name, name.length ());
219
-
219
+
220
220
// does a property exist by the given name and is it not defined as a method?
221
221
if (contains && !method_exists)
222
222
{
@@ -270,8 +270,17 @@ static void setter(uint32_t index, v8::Local<v8::Value> input, const v8::Propert
270
270
v8::HandleScope scope (Isolate::get ());
271
271
Handle handle (info.Holder ()->GetInternalField (0 ));
272
272
273
- // store the property inside the object
274
- handle->call (" offsetSet" , static_cast <int64_t >(index ), value (input));
273
+ // We are calling into PHP space so we need to catch all exceptions
274
+ try
275
+ {
276
+ // store the property inside the object
277
+ handle->call (" offsetSet" , static_cast <int64_t >(index ), value (input));
278
+ }
279
+ catch (const Php::Exception& exception )
280
+ {
281
+ // pass the exception on to javascript userspace
282
+ Isolate::get ()->ThrowException (v8::Exception::Error (v8::String::NewFromUtf8 (Isolate::get (), exception .what ())));
283
+ }
275
284
}
276
285
277
286
/* *
@@ -288,17 +297,26 @@ static void setter(v8::Local<v8::String> property, v8::Local<v8::Value> input, c
288
297
Handle handle (info.Holder ()->GetInternalField (0 ));
289
298
v8::String::Utf8Value name (property);
290
299
291
- // if the object is not implementing ArrayAccess or has the given property as a member
292
- // then we set it directly, otherwise we use the offsetSet method to use it as an array
293
- if (!handle->instanceOf (" ArrayAccess" ) || handle->contains (*name, name.length ()))
300
+ // We are calling into PHP space so we need to catch all exceptions
301
+ try
294
302
{
295
- // store the property inside the object
296
- handle->set (*name, name.length (), value (input));
303
+ // if the object is not implementing ArrayAccess or has the given property as a member
304
+ // then we set it directly, otherwise we use the offsetSet method to use it as an array
305
+ if (!handle->instanceOf (" ArrayAccess" ) || handle->contains (*name, name.length ()))
306
+ {
307
+ // store the property inside the object
308
+ handle->set (*name, name.length (), value (input));
309
+ }
310
+ else
311
+ {
312
+ // set it as an array offset
313
+ handle->call (" offsetSet" , Php::Value{ *name, name.length () }, value (input));
314
+ }
297
315
}
298
- else
316
+ catch ( const Php::Exception& exception )
299
317
{
300
- // set it as an array offset
301
- handle-> call ( " offsetSet " , Php::Value{ *name, name. length () }, value (input ));
318
+ // pass the exception on to javascript userspace
319
+ Isolate::get ()-> ThrowException ( v8::Exception::Error ( v8::String::NewFromUtf8 ( Isolate::get (), exception . what ()) ));
302
320
}
303
321
}
304
322
0 commit comments