From 3108d3947d92df5bc3fdfe899b96bd193fcce73e Mon Sep 17 00:00:00 2001 From: Stefan Siegl Date: Wed, 30 Dec 2015 14:59:37 +0100 Subject: [PATCH] Fix output of var_dump on regexp (V8 > 4.8) Newer V8 versions' toString() converts RegExp objects just to [object RegExp] (instead of the actual regexp as before). Work-around by calling GetSource() on the regexp and create former outhway that way. --- v8js_methods.cc | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/v8js_methods.cc b/v8js_methods.cc index 8832df2..9cde0cf 100644 --- a/v8js_methods.cc +++ b/v8js_methods.cc @@ -92,10 +92,20 @@ static void v8js_dumper(v8::Isolate *isolate, v8::Local var, int leve } v8::TryCatch try_catch; /* object.toString() can throw an exception */ - v8::Local details = var->ToDetailString(); - if (try_catch.HasCaught()) { - details = V8JS_SYM(""); + v8::Local details; + + if(var->IsRegExp()) { + v8::RegExp *re = v8::RegExp::Cast(*var); + details = re->GetSource(); } + else { + details = var->ToDetailString(); + + if (try_catch.HasCaught()) { + details = V8JS_SYM(""); + } + } + v8::String::Utf8Value str(details); const char *valstr = ToCString(str); size_t valstr_len = details->ToString()->Utf8Length(); @@ -113,7 +123,7 @@ static void v8js_dumper(v8::Isolate *isolate, v8::Local var, int leve } else if (var->IsRegExp()) { - php_printf("regexp(%s)\n", valstr); + php_printf("regexp(/%s/)\n", valstr); } else if (var->IsArray()) {