mirror of
https://github.com/phpv8/v8js.git
synced 2024-12-22 14:01:53 +00:00
Fix debug build; move debug stuff into seperate files
This commit is contained in:
parent
8934e8c078
commit
90c3b9db5f
@ -156,6 +156,7 @@ AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include <v8-debug.h>]],
|
||||
v8js_class.cc \
|
||||
v8js_commonjs.cc \
|
||||
v8js_convert.cc \
|
||||
v8js_debug.cc \
|
||||
v8js_exceptions.cc \
|
||||
v8js_methods.cc \
|
||||
v8js_object_export.cc \
|
||||
|
@ -13,7 +13,7 @@ if (PHP_V8JS != "no") {
|
||||
AC_DEFINE("PHP_V8_API_VERSION", "3017015", "", false);
|
||||
AC_DEFINE("PHP_V8_VERSION", "3.17.15", "", true);
|
||||
|
||||
EXTENSION("v8js", "v8js_array_access.cc v8js.cc v8js_class.cc v8js_commonjs.cc v8js_convert.cc v8js_exceptions.cc v8js_methods.cc v8js_object_export.cc v8js_timer.cc v8js_v8.cc v8js_v8object_class.cc v8js_variables.cc", "yes");
|
||||
EXTENSION("v8js", "v8js_array_access.cc v8js.cc v8js_class.cc v8js_commonjs.cc v8js_convert.cc v8js_debug.cc v8js_exceptions.cc v8js_methods.cc v8js_object_export.cc v8js_timer.cc v8js_v8.cc v8js_v8object_class.cc v8js_variables.cc", "yes");
|
||||
|
||||
} else {
|
||||
WARNING("v8js not enabled, headers or libs not found");
|
||||
|
2
v8js.cc
2
v8js.cc
@ -17,8 +17,6 @@
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include <v8-debug.h>
|
||||
|
||||
#include "php_v8js_macros.h"
|
||||
|
||||
extern "C" {
|
||||
|
@ -27,6 +27,7 @@ extern "C" {
|
||||
|
||||
#include "php_v8js_macros.h"
|
||||
#include "v8js_v8.h"
|
||||
#include "v8js_debug.h"
|
||||
#include "v8js_exceptions.h"
|
||||
#include "v8js_v8object_class.h"
|
||||
#include "v8js_timer.h"
|
||||
@ -64,10 +65,6 @@ struct v8js_jsext {
|
||||
};
|
||||
/* }}} */
|
||||
|
||||
#ifdef ENABLE_DEBUGGER_SUPPORT
|
||||
static v8js_ctx *v8js_debug_context;
|
||||
static int v8js_debug_auto_break_mode;
|
||||
#endif
|
||||
|
||||
static void v8js_free_storage(void *object TSRMLS_DC) /* {{{ */
|
||||
{
|
||||
@ -276,25 +273,6 @@ static void v8js_fatal_error_handler(const char *location, const char *message)
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
#ifdef ENABLE_DEBUGGER_SUPPORT
|
||||
static void DispatchDebugMessages() { /* {{{ */
|
||||
if(v8js_debug_context == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
v8::Isolate* isolate = v8js_debug_context->isolate;
|
||||
v8::Isolate::Scope isolate_scope(isolate);
|
||||
|
||||
v8::HandleScope handle_scope(isolate);
|
||||
v8::Local<v8::Context> context =
|
||||
v8::Local<v8::Context>::New(isolate, v8js_debug_context->context);
|
||||
v8::Context::Scope scope(context);
|
||||
|
||||
v8::Debug::ProcessDebugMessages();
|
||||
}
|
||||
/* }}} */
|
||||
#endif /* ENABLE_DEBUGGER_SUPPORT */
|
||||
|
||||
/* {{{ proto void V8Js::__construct([string object_name [, array variables [, array extensions [, bool report_uncaught_exceptions]]])
|
||||
__construct for V8Js */
|
||||
static PHP_METHOD(V8Js, __construct)
|
||||
@ -616,74 +594,6 @@ static PHP_METHOD(V8Js, checkString)
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
|
||||
#ifdef ENABLE_DEBUGGER_SUPPORT
|
||||
/* {{{ proto void V8Js::__destruct()
|
||||
__destruct for V8Js */
|
||||
static PHP_METHOD(V8Js, __destruct)
|
||||
{
|
||||
v8js_ctx *c = (v8js_ctx *) zend_object_store_get_object(getThis() TSRMLS_CC);
|
||||
|
||||
if(!c->isolate) {
|
||||
/* c->isolate is initialized by __construct, which wasn't called if this
|
||||
* instance was deserialized (which we already caught in __wakeup). */
|
||||
return;
|
||||
}
|
||||
|
||||
V8JS_CTX_PROLOGUE(c);
|
||||
if(v8js_debug_context == c) {
|
||||
v8::Debug::DisableAgent();
|
||||
v8js_debug_context = NULL;
|
||||
}
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
/* {{{ proto bool V8Js::startDebugAgent(string agent_name[, int port[, int auto_break]])
|
||||
*/
|
||||
static PHP_METHOD(V8Js, startDebugAgent)
|
||||
{
|
||||
char *str = NULL;
|
||||
int str_len = 0;
|
||||
long port = 0, auto_break = 0;
|
||||
|
||||
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|sll", &str, &str_len, &port, &auto_break) == FAILURE) {
|
||||
return;
|
||||
}
|
||||
|
||||
if(!port) {
|
||||
port = 9222;
|
||||
}
|
||||
|
||||
V8JS_BEGIN_CTX(c, getThis());
|
||||
|
||||
if(v8js_debug_context == c) {
|
||||
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Debug agent already started for this V8Js instance");
|
||||
RETURN_BOOL(0);
|
||||
}
|
||||
|
||||
if(v8js_debug_context != NULL) {
|
||||
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Debug agent already started for a different V8Js instance");
|
||||
RETURN_BOOL(0);
|
||||
}
|
||||
|
||||
v8js_debug_context = c;
|
||||
v8js_debug_auto_break_mode = auto_break;
|
||||
|
||||
v8::Debug::SetDebugMessageDispatchHandler(DispatchDebugMessages, true);
|
||||
v8::Debug::EnableAgent(str_len ? str : "V8Js", port, auto_break > 0);
|
||||
|
||||
if(auto_break) {
|
||||
/* v8::Debug::EnableAgent doesn't really do what we want it to do,
|
||||
since it only breaks processing on the default isolate.
|
||||
Hence just trigger another DebugBreak, no for our main isolate. */
|
||||
v8::Debug::DebugBreak(c->isolate);
|
||||
}
|
||||
|
||||
RETURN_BOOL(1);
|
||||
}
|
||||
/* }}} */
|
||||
#endif /* ENABLE_DEBUGGER_SUPPORT */
|
||||
|
||||
/* {{{ proto mixed V8Js::getPendingException()
|
||||
*/
|
||||
static PHP_METHOD(V8Js, getPendingException)
|
||||
|
113
v8js_debug.cc
Normal file
113
v8js_debug.cc
Normal file
@ -0,0 +1,113 @@
|
||||
/*
|
||||
+----------------------------------------------------------------------+
|
||||
| PHP Version 5 |
|
||||
+----------------------------------------------------------------------+
|
||||
| Copyright (c) 1997-2015 The PHP Group |
|
||||
+----------------------------------------------------------------------+
|
||||
| http://www.opensource.org/licenses/mit-license.php MIT License |
|
||||
+----------------------------------------------------------------------+
|
||||
| Author: Stefan Siegl <stesie@brokenpipe.de> |
|
||||
+----------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
extern "C" {
|
||||
#include "php.h"
|
||||
}
|
||||
|
||||
#include "php_v8js_macros.h"
|
||||
#include "v8js_debug.h"
|
||||
|
||||
#ifdef ENABLE_DEBUGGER_SUPPORT
|
||||
|
||||
v8js_ctx *v8js_debug_context;
|
||||
int v8js_debug_auto_break_mode;
|
||||
|
||||
|
||||
static void DispatchDebugMessages() { /* {{{ */
|
||||
if(v8js_debug_context == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
v8::Isolate* isolate = v8js_debug_context->isolate;
|
||||
v8::Isolate::Scope isolate_scope(isolate);
|
||||
|
||||
v8::HandleScope handle_scope(isolate);
|
||||
v8::Local<v8::Context> context =
|
||||
v8::Local<v8::Context>::New(isolate, v8js_debug_context->context);
|
||||
v8::Context::Scope scope(context);
|
||||
|
||||
v8::Debug::ProcessDebugMessages();
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
/* {{{ proto void V8Js::__destruct()
|
||||
__destruct for V8Js */
|
||||
PHP_METHOD(V8Js, __destruct)
|
||||
{
|
||||
v8js_ctx *c = (v8js_ctx *) zend_object_store_get_object(getThis() TSRMLS_CC);
|
||||
|
||||
if(!c->isolate) {
|
||||
/* c->isolate is initialized by __construct, which wasn't called if this
|
||||
* instance was deserialized (which we already caught in __wakeup). */
|
||||
return;
|
||||
}
|
||||
|
||||
V8JS_CTX_PROLOGUE(c);
|
||||
if(v8js_debug_context == c) {
|
||||
v8::Debug::DisableAgent();
|
||||
v8js_debug_context = NULL;
|
||||
}
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
/* {{{ proto bool V8Js::startDebugAgent(string agent_name[, int port[, int auto_break]])
|
||||
*/
|
||||
PHP_METHOD(V8Js, startDebugAgent)
|
||||
{
|
||||
char *str = NULL;
|
||||
int str_len = 0;
|
||||
long port = 0, auto_break = 0;
|
||||
|
||||
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|sll", &str, &str_len, &port, &auto_break) == FAILURE) {
|
||||
return;
|
||||
}
|
||||
|
||||
if(!port) {
|
||||
port = 9222;
|
||||
}
|
||||
|
||||
V8JS_BEGIN_CTX(c, getThis());
|
||||
|
||||
if(v8js_debug_context == c) {
|
||||
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Debug agent already started for this V8Js instance");
|
||||
RETURN_BOOL(0);
|
||||
}
|
||||
|
||||
if(v8js_debug_context != NULL) {
|
||||
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Debug agent already started for a different V8Js instance");
|
||||
RETURN_BOOL(0);
|
||||
}
|
||||
|
||||
v8js_debug_context = c;
|
||||
v8js_debug_auto_break_mode = auto_break;
|
||||
|
||||
v8::Debug::SetDebugMessageDispatchHandler(DispatchDebugMessages, true);
|
||||
v8::Debug::EnableAgent(str_len ? str : "V8Js", port, auto_break > 0);
|
||||
|
||||
if(auto_break) {
|
||||
/* v8::Debug::EnableAgent doesn't really do what we want it to do,
|
||||
since it only breaks processing on the default isolate.
|
||||
Hence just trigger another DebugBreak, no for our main isolate. */
|
||||
v8::Debug::DebugBreak(c->isolate);
|
||||
}
|
||||
|
||||
RETURN_BOOL(1);
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
|
||||
#endif /* ENABLE_DEBUGGER_SUPPORT */
|
25
v8js_debug.h
Normal file
25
v8js_debug.h
Normal file
@ -0,0 +1,25 @@
|
||||
/*
|
||||
+----------------------------------------------------------------------+
|
||||
| PHP Version 5 |
|
||||
+----------------------------------------------------------------------+
|
||||
| Copyright (c) 1997-2015 The PHP Group |
|
||||
+----------------------------------------------------------------------+
|
||||
| http://www.opensource.org/licenses/mit-license.php MIT License |
|
||||
+----------------------------------------------------------------------+
|
||||
| Author: Stefan Siegl <stesie@brokenpipe.de> |
|
||||
+----------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
#ifndef V8JS_DEBUG_H
|
||||
#define V8JS_DEBUG_H
|
||||
|
||||
#include <v8-debug.h>
|
||||
|
||||
extern PHP_METHOD(V8Js, __destruct);
|
||||
extern PHP_METHOD(V8Js, startDebugAgent);
|
||||
|
||||
extern v8js_ctx *v8js_debug_context;
|
||||
extern int v8js_debug_auto_break_mode;
|
||||
|
||||
#endif /* V8JS_DEBUG_H */
|
||||
|
@ -30,6 +30,7 @@ extern "C" {
|
||||
|
||||
#include "php_v8js_macros.h"
|
||||
#include "v8js_v8.h"
|
||||
#include "v8js_debug.h"
|
||||
#include "v8js_timer.h"
|
||||
#include "v8js_exceptions.h"
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user