@@ -46,10 +46,12 @@ PHONGO_API zend_class_entry *php_phongo_javascript_ce;
4646
4747zend_object_handlers php_phongo_handler_javascript ;
4848
49- /* Initialize the object from a string and return whether it was successful. */
49+ /* Initialize the object and return whether it was successful. An exception will
50+ * be thrown on error. */
5051static bool php_phongo_javascript_init (php_phongo_javascript_t * intern , const char * code , phongo_zpp_char_len code_len , zval * scope TSRMLS_DC )
5152{
5253 if (scope && Z_TYPE_P (scope ) != IS_OBJECT && Z_TYPE_P (scope ) != IS_ARRAY && Z_TYPE_P (scope ) != IS_NULL ) {
54+ phongo_throw_exception (PHONGO_ERROR_INVALID_ARGUMENT TSRMLS_CC , "Expected scope to be array or object, %s given" , zend_get_type_by_const (Z_TYPE_P (scope )));
5355 return false;
5456 }
5557
@@ -66,7 +68,8 @@ static bool php_phongo_javascript_init(php_phongo_javascript_t *intern, const ch
6668 return true;
6769}
6870
69- /* Initialize the object from a HashTable and return whether it was successful. */
71+ /* Initialize the object from a HashTable and return whether it was successful.
72+ * An exception will be thrown on error. */
7073static bool php_phongo_javascript_init_from_hash (php_phongo_javascript_t * intern , HashTable * props TSRMLS_DC )
7174{
7275#if PHP_VERSION_ID >= 70000
@@ -86,6 +89,8 @@ static bool php_phongo_javascript_init_from_hash(php_phongo_javascript_t *intern
8689 return php_phongo_javascript_init (intern , Z_STRVAL_PP (code ), Z_STRLEN_PP (code ), tmp TSRMLS_CC );
8790 }
8891#endif
92+
93+ phongo_throw_exception (PHONGO_ERROR_INVALID_ARGUMENT TSRMLS_CC , "%s initialization requires \"code\" string field" , ZSTR_VAL (php_phongo_javascript_ce -> name ));
8994 return false;
9095}
9196
@@ -131,9 +136,7 @@ PHP_METHOD(Javascript, __set_state)
131136 intern = Z_JAVASCRIPT_OBJ_P (return_value );
132137 props = Z_ARRVAL_P (array );
133138
134- if (!php_phongo_javascript_init_from_hash (intern , props TSRMLS_CC )) {
135- php_error (E_ERROR , "Invalid serialization data for Javascript object" );
136- }
139+ php_phongo_javascript_init_from_hash (intern , props TSRMLS_CC );
137140}
138141/* }}} */
139142
@@ -151,10 +154,7 @@ PHP_METHOD(Javascript, __wakeup)
151154 intern = Z_JAVASCRIPT_OBJ_P (getThis ());
152155 props = zend_std_get_properties (getThis () TSRMLS_CC );
153156
154- if (!php_phongo_javascript_init_from_hash (intern , props TSRMLS_CC )) {
155- php_error (E_ERROR , "Invalid serialization data for Javascript object" );
156- } else {
157- }
157+ php_phongo_javascript_init_from_hash (intern , props TSRMLS_CC );
158158}
159159/* }}} */
160160
0 commit comments