Skip to content

Commit b4f1b47

Browse files
committed
Convert JS exception to string before attaching it to a PHP exception.
1 parent 20c6212 commit b4f1b47

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

src/node_php_jsobject_class.cc

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,15 +57,17 @@ static zend_object_handlers node_php_jsobject_handlers;
5757
} \
5858
FETCH_OBJ(method, this_ptr)
5959

60-
#define THROW_IF_EXCEPTION(...) \
60+
#define THROW_IF_EXCEPTION(fmt, ...) \
6161
do { \
6262
if (msg.HasException()) { \
6363
ZVal e{ZEND_FILE_LINE_C}; \
6464
msg.exception().ToPhp(obj->channel, e TSRMLS_CC); \
65+
e.Separate(); \
66+
convert_to_string(e.Ptr()); \
6567
/* XXX attach the wrapped JS exception XX */ \
6668
zend_throw_exception_ex( \
6769
zend_exception_get_default(TSRMLS_C), 0 TSRMLS_CC, \
68-
__VA_ARGS__); \
70+
fmt ": %*s", __VA_ARGS__, Z_STRLEN_P(*e), Z_STRVAL_P(*e)); \
6971
return; \
7072
} \
7173
} while (0)
@@ -466,7 +468,7 @@ PHP_METHOD(JsObject, __invoke) {
466468
obj->id, &member, argc, argv TSRMLS_CC);
467469
efree(argv);
468470
obj->channel->SendToJs(&msg, MessageFlags::SYNC TSRMLS_CC);
469-
THROW_IF_EXCEPTION("JS exception thrown during __invoke");
471+
THROW_IF_EXCEPTION("JS exception thrown during %s", "__invoke");
470472
msg.retval().ToPhp(obj->channel, return_value, return_value_ptr TSRMLS_CC);
471473
TRACE("<");
472474
}

0 commit comments

Comments
 (0)