Skip to content

Commit 30fe993

Browse files
committed
Merge pull request #187 from stesie/fix-regexp-vardump
Fix output of var_dump on regexp (V8 > 4.8)
2 parents d9e4ae5 + 3108d39 commit 30fe993

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

v8js_methods.cc

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -92,10 +92,20 @@ static void v8js_dumper(v8::Isolate *isolate, v8::Local<v8::Value> var, int leve
9292
}
9393

9494
v8::TryCatch try_catch; /* object.toString() can throw an exception */
95-
v8::Local<v8::String> details = var->ToDetailString();
96-
if (try_catch.HasCaught()) {
97-
details = V8JS_SYM("<toString threw exception>");
95+
v8::Local<v8::String> details;
96+
97+
if(var->IsRegExp()) {
98+
v8::RegExp *re = v8::RegExp::Cast(*var);
99+
details = re->GetSource();
98100
}
101+
else {
102+
details = var->ToDetailString();
103+
104+
if (try_catch.HasCaught()) {
105+
details = V8JS_SYM("<toString threw exception>");
106+
}
107+
}
108+
99109
v8::String::Utf8Value str(details);
100110
const char *valstr = ToCString(str);
101111
size_t valstr_len = details->ToString()->Utf8Length();
@@ -113,7 +123,7 @@ static void v8js_dumper(v8::Isolate *isolate, v8::Local<v8::Value> var, int leve
113123
}
114124
else if (var->IsRegExp())
115125
{
116-
php_printf("regexp(%s)\n", valstr);
126+
php_printf("regexp(/%s/)\n", valstr);
117127
}
118128
else if (var->IsArray())
119129
{

0 commit comments

Comments
 (0)