diff --git a/README.md b/README.md index 55bf9b1..faba6e9 100644 --- a/README.md +++ b/README.md @@ -136,12 +136,16 @@ PHP API /* Properties */ protected string JsFileName = NULL; protected int JsLineNumber = NULL; + protected int JsStartColumn = NULL; + protected int JsEndColumn = NULL; protected string JsSourceLine = NULL; protected string JsTrace = NULL; /* Methods */ final public string getJsFileName( ) final public int getJsLineNumber( ) + final public int getJsStartColumn( ) + final public int getJsEndColumn( ) final public string getJsSourceLine( ) final public string getJsTrace( ) } diff --git a/tests/exception.phpt b/tests/exception.phpt index aa3da98..59b5949 100644 --- a/tests/exception.phpt +++ b/tests/exception.phpt @@ -19,7 +19,7 @@ try { ?> ===EOF=== --EXPECTF-- -object(V8JsScriptException)#%d (11) { +object(V8JsScriptException)#%d (13) { ["message":protected]=> string(75) "exception.js:1: ReferenceError: this_function_does_not_exist is not defined" ["string":"Exception":private]=> @@ -59,6 +59,10 @@ object(V8JsScriptException)#%d (11) { string(12) "exception.js" ["JsLineNumber":protected]=> int(1) + ["JsStartColumn":protected]=> + int(0) + ["JsEndColumn":protected]=> + int(1) ["JsSourceLine":protected]=> string(31) "this_function_does_not_exist();" ["JsTrace":protected]=> diff --git a/tests/exception_propagation_2.phpt b/tests/exception_propagation_2.phpt index 06e75e3..a822eda 100644 --- a/tests/exception_propagation_2.phpt +++ b/tests/exception_propagation_2.phpt @@ -33,7 +33,7 @@ try { ?> ===EOF=== --EXPECTF-- -object(V8JsScriptException)#%d (11) { +object(V8JsScriptException)#%d (13) { ["message":protected]=> string(49) "throw_0:1: ReferenceError: fooobar is not defined" ["string":"Exception":private]=> @@ -89,6 +89,10 @@ object(V8JsScriptException)#%d (11) { string(7) "throw_0" ["JsLineNumber":protected]=> int(1) + ["JsStartColumn":protected]=> + int(0) + ["JsEndColumn":protected]=> + int(1) ["JsSourceLine":protected]=> string(7) "fooobar" ["JsTrace":protected]=> diff --git a/tests/exception_start_column.phpt b/tests/exception_start_column.phpt new file mode 100644 index 0000000..682e290 --- /dev/null +++ b/tests/exception_start_column.phpt @@ -0,0 +1,20 @@ +--TEST-- +Test V8::executeString() : Test getJsStartColumn on script exception +--SKIPIF-- + +--FILE-- +executeString("print(blar());"); +} +catch(V8JsScriptException $e) { + var_dump($e->getJsStartColumn()); +} + +?> +===EOF=== +--EXPECT-- +int(6) +===EOF=== diff --git a/tests/js-construct-protected-ctor.phpt b/tests/js-construct-protected-ctor.phpt index a132d06..7b379a1 100644 --- a/tests/js-construct-protected-ctor.phpt +++ b/tests/js-construct-protected-ctor.phpt @@ -42,7 +42,7 @@ try { ctor called (php) Hello John caught js exception -object(V8JsScriptException)#%d (11) { +object(V8JsScriptException)#%d (13) { ["message":protected]=> string(56) "ctor-test:4: Call to protected __construct() not allowed" ["string":"Exception":private]=> @@ -87,6 +87,10 @@ object(V8JsScriptException)#%d (11) { string(9) "ctor-test" ["JsLineNumber":protected]=> int(4) + ["JsStartColumn":protected]=> + int(18) + ["JsEndColumn":protected]=> + int(19) ["JsSourceLine":protected]=> string(55) " var ngGreeter = new PHP.greeter.constructor("Ringo");" ["JsTrace":protected]=> diff --git a/v8js.cc b/v8js.cc index c052a6f..2873e36 100644 --- a/v8js.cc +++ b/v8js.cc @@ -1791,7 +1791,7 @@ static void php_v8js_create_script_exception(zval *return_value, v8::TryCatch *t v8::Handle tc_message = try_catch->Message(); const char *filename_string, *sourceline_string; char *message_string; - int linenum, message_len; + int linenum, start_col, end_col, message_len; object_init_ex(return_value, php_ce_v8js_script_exception); @@ -1814,6 +1814,12 @@ static void php_v8js_create_script_exception(zval *return_value, v8::TryCatch *t linenum = tc_message->GetLineNumber(); PHPV8_EXPROP(_long, JsLineNumber, linenum); + start_col = tc_message->GetStartColumn(); + PHPV8_EXPROP(_long, JsStartColumn, start_col); + + end_col = tc_message->GetEndColumn(); + PHPV8_EXPROP(_long, JsEndColumn, end_col); + message_len = spprintf(&message_string, 0, "%s:%d: %s", filename_string, linenum, exception_string); v8::String::Utf8Value stacktrace(try_catch->StackTrace()); @@ -1869,6 +1875,16 @@ V8JS_EXCEPTION_METHOD(JsFileName); V8JS_EXCEPTION_METHOD(JsLineNumber); /* }}} */ +/* {{{ proto string V8JsScriptException::getJsStartColumn() + */ +V8JS_EXCEPTION_METHOD(JsStartColumn); +/* }}} */ + +/* {{{ proto string V8JsScriptException::getJsEndColumn() + */ +V8JS_EXCEPTION_METHOD(JsEndColumn); +/* }}} */ + /* {{{ proto string V8JsScriptException::getJsSourceLine() */ V8JS_EXCEPTION_METHOD(JsSourceLine); @@ -1882,6 +1898,8 @@ V8JS_EXCEPTION_METHOD(JsTrace); static const zend_function_entry v8js_script_exception_methods[] = { /* {{{ */ PHP_ME(V8JsScriptException, getJsFileName, arginfo_v8jsscriptexception_no_args, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL) PHP_ME(V8JsScriptException, getJsLineNumber, arginfo_v8jsscriptexception_no_args, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL) + PHP_ME(V8JsScriptException, getJsStartColumn, arginfo_v8jsscriptexception_no_args, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL) + PHP_ME(V8JsScriptException, getJsEndColumn, arginfo_v8jsscriptexception_no_args, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL) PHP_ME(V8JsScriptException, getJsSourceLine, arginfo_v8jsscriptexception_no_args, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL) PHP_ME(V8JsScriptException, getJsTrace, arginfo_v8jsscriptexception_no_args, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL) {NULL, NULL, NULL} @@ -1973,8 +1991,10 @@ static PHP_MINIT_FUNCTION(v8js) /* Add custom JS specific properties */ zend_declare_property_null(php_ce_v8js_script_exception, ZEND_STRL("JsFileName"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(php_ce_v8js_script_exception, ZEND_STRL("JsLineNumber"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(php_ce_v8js_script_exception, ZEND_STRL("JsSourceLine"), ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_null(php_ce_v8js_script_exception, ZEND_STRL("JsLineNumber"), ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_null(php_ce_v8js_script_exception, ZEND_STRL("JsStartColumn"), ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_null(php_ce_v8js_script_exception, ZEND_STRL("JsEndColumn"), ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_null(php_ce_v8js_script_exception, ZEND_STRL("JsSourceLine"), ZEND_ACC_PROTECTED TSRMLS_CC); zend_declare_property_null(php_ce_v8js_script_exception, ZEND_STRL("JsTrace"), ZEND_ACC_PROTECTED TSRMLS_CC); /* V8JsTimeLimitException Class */