Commit bf229e93 authored by yangguo@chromium.org's avatar yangguo@chromium.org

Enable/disable LiveEdit using the (C++) debug API.

BUG=

Review URL: https://chromiumcodereview.appspot.com/10875072

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@12472 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent 1a0c14f1
...@@ -321,7 +321,7 @@ class EXPORT Debug { ...@@ -321,7 +321,7 @@ class EXPORT Debug {
* \endcode * \endcode
*/ */
static Local<Value> Call(v8::Handle<v8::Function> fun, static Local<Value> Call(v8::Handle<v8::Function> fun,
Handle<Value> data = Handle<Value>()); Handle<Value> data = Handle<Value>());
/** /**
* Returns a mirror object for the given object. * Returns a mirror object for the given object.
...@@ -388,6 +388,14 @@ class EXPORT Debug { ...@@ -388,6 +388,14 @@ class EXPORT Debug {
* to change. * to change.
*/ */
static Local<Context> GetDebugContext(); static Local<Context> GetDebugContext();
/**
* Enable/disable LiveEdit functionality for the given Isolate
* (default Isolate if not provided). V8 will abort if LiveEdit is
* unexpectedly used. LiveEdit is enabled by default.
*/
static void SetLiveEditEnabled(bool enable, Isolate* isolate = NULL);
}; };
......
...@@ -5841,6 +5841,7 @@ void Debug::ProcessDebugMessages() { ...@@ -5841,6 +5841,7 @@ void Debug::ProcessDebugMessages() {
i::Execution::ProcessDebugMessages(true); i::Execution::ProcessDebugMessages(true);
} }
Local<Context> Debug::GetDebugContext() { Local<Context> Debug::GetDebugContext() {
i::Isolate* isolate = i::Isolate::Current(); i::Isolate* isolate = i::Isolate::Current();
EnsureInitializedForIsolate(isolate, "v8::Debug::GetDebugContext()"); EnsureInitializedForIsolate(isolate, "v8::Debug::GetDebugContext()");
...@@ -5848,6 +5849,20 @@ Local<Context> Debug::GetDebugContext() { ...@@ -5848,6 +5849,20 @@ Local<Context> Debug::GetDebugContext() {
return Utils::ToLocal(i::Isolate::Current()->debugger()->GetDebugContext()); return Utils::ToLocal(i::Isolate::Current()->debugger()->GetDebugContext());
} }
void Debug::SetLiveEditEnabled(bool enable, Isolate* isolate) {
// If no isolate is supplied, use the default isolate.
i::Debugger* debugger;
if (isolate != NULL) {
i::Isolate* internal_isolate = reinterpret_cast<i::Isolate*>(isolate);
debugger = internal_isolate->debugger();
} else {
debugger = i::Isolate::GetDefaultIsolateDebugger();
}
debugger->set_live_edit_enabled(enable);
}
#endif // ENABLE_DEBUGGER_SUPPORT #endif // ENABLE_DEBUGGER_SUPPORT
......
...@@ -2514,6 +2514,7 @@ Debugger::Debugger(Isolate* isolate) ...@@ -2514,6 +2514,7 @@ Debugger::Debugger(Isolate* isolate)
event_listener_data_(Handle<Object>()), event_listener_data_(Handle<Object>()),
compiling_natives_(false), compiling_natives_(false),
is_loading_debugger_(false), is_loading_debugger_(false),
live_edit_enabled_(true),
never_unload_debugger_(false), never_unload_debugger_(false),
force_debugger_active_(false), force_debugger_active_(false),
message_handler_(NULL), message_handler_(NULL),
......
...@@ -875,6 +875,8 @@ class Debugger { ...@@ -875,6 +875,8 @@ class Debugger {
bool compiling_natives() const { return compiling_natives_; } bool compiling_natives() const { return compiling_natives_; }
void set_loading_debugger(bool v) { is_loading_debugger_ = v; } void set_loading_debugger(bool v) { is_loading_debugger_ = v; }
bool is_loading_debugger() const { return is_loading_debugger_; } bool is_loading_debugger() const { return is_loading_debugger_; }
void set_live_edit_enabled(bool v) { live_edit_enabled_ = v; }
bool live_edit_enabled() const { return live_edit_enabled_; }
void set_force_debugger_active(bool force_debugger_active) { void set_force_debugger_active(bool force_debugger_active) {
force_debugger_active_ = force_debugger_active; force_debugger_active_ = force_debugger_active;
} }
...@@ -903,6 +905,7 @@ class Debugger { ...@@ -903,6 +905,7 @@ class Debugger {
Handle<Object> event_listener_data_; Handle<Object> event_listener_data_;
bool compiling_natives_; // Are we compiling natives? bool compiling_natives_; // Are we compiling natives?
bool is_loading_debugger_; // Are we loading the debugger? bool is_loading_debugger_; // Are we loading the debugger?
bool live_edit_enabled_; // Enable LiveEdit.
bool never_unload_debugger_; // Can we unload the debugger? bool never_unload_debugger_; // Can we unload the debugger?
bool force_debugger_active_; // Activate debugger without event listeners. bool force_debugger_active_; // Activate debugger without event listeners.
v8::Debug::MessageHandler2 message_handler_; v8::Debug::MessageHandler2 message_handler_;
......
...@@ -12252,6 +12252,7 @@ static int FindSharedFunctionInfosForScript(HeapIterator* iterator, ...@@ -12252,6 +12252,7 @@ static int FindSharedFunctionInfosForScript(HeapIterator* iterator,
// in OpaqueReferences. // in OpaqueReferences.
RUNTIME_FUNCTION(MaybeObject*, RUNTIME_FUNCTION(MaybeObject*,
Runtime_LiveEditFindSharedFunctionInfosForScript) { Runtime_LiveEditFindSharedFunctionInfosForScript) {
CHECK(isolate->debugger()->live_edit_enabled());
ASSERT(args.length() == 1); ASSERT(args.length() == 1);
HandleScope scope(isolate); HandleScope scope(isolate);
CONVERT_ARG_CHECKED(JSValue, script_value, 0); CONVERT_ARG_CHECKED(JSValue, script_value, 0);
...@@ -12298,6 +12299,7 @@ RUNTIME_FUNCTION(MaybeObject*, ...@@ -12298,6 +12299,7 @@ RUNTIME_FUNCTION(MaybeObject*,
// each function with all its descendant is always stored in a continues range // each function with all its descendant is always stored in a continues range
// with the function itself going first. The root function is a script function. // with the function itself going first. The root function is a script function.
RUNTIME_FUNCTION(MaybeObject*, Runtime_LiveEditGatherCompileInfo) { RUNTIME_FUNCTION(MaybeObject*, Runtime_LiveEditGatherCompileInfo) {
CHECK(isolate->debugger()->live_edit_enabled());
ASSERT(args.length() == 2); ASSERT(args.length() == 2);
HandleScope scope(isolate); HandleScope scope(isolate);
CONVERT_ARG_CHECKED(JSValue, script, 0); CONVERT_ARG_CHECKED(JSValue, script, 0);
...@@ -12319,6 +12321,7 @@ RUNTIME_FUNCTION(MaybeObject*, Runtime_LiveEditGatherCompileInfo) { ...@@ -12319,6 +12321,7 @@ RUNTIME_FUNCTION(MaybeObject*, Runtime_LiveEditGatherCompileInfo) {
// If old_script_name is provided (i.e. is a String), also creates a copy of // If old_script_name is provided (i.e. is a String), also creates a copy of
// the script with its original source and sends notification to debugger. // the script with its original source and sends notification to debugger.
RUNTIME_FUNCTION(MaybeObject*, Runtime_LiveEditReplaceScript) { RUNTIME_FUNCTION(MaybeObject*, Runtime_LiveEditReplaceScript) {
CHECK(isolate->debugger()->live_edit_enabled());
ASSERT(args.length() == 3); ASSERT(args.length() == 3);
HandleScope scope(isolate); HandleScope scope(isolate);
CONVERT_ARG_CHECKED(JSValue, original_script_value, 0); CONVERT_ARG_CHECKED(JSValue, original_script_value, 0);
...@@ -12342,6 +12345,7 @@ RUNTIME_FUNCTION(MaybeObject*, Runtime_LiveEditReplaceScript) { ...@@ -12342,6 +12345,7 @@ RUNTIME_FUNCTION(MaybeObject*, Runtime_LiveEditReplaceScript) {
RUNTIME_FUNCTION(MaybeObject*, Runtime_LiveEditFunctionSourceUpdated) { RUNTIME_FUNCTION(MaybeObject*, Runtime_LiveEditFunctionSourceUpdated) {
CHECK(isolate->debugger()->live_edit_enabled());
ASSERT(args.length() == 1); ASSERT(args.length() == 1);
HandleScope scope(isolate); HandleScope scope(isolate);
CONVERT_ARG_HANDLE_CHECKED(JSArray, shared_info, 0); CONVERT_ARG_HANDLE_CHECKED(JSArray, shared_info, 0);
...@@ -12351,6 +12355,7 @@ RUNTIME_FUNCTION(MaybeObject*, Runtime_LiveEditFunctionSourceUpdated) { ...@@ -12351,6 +12355,7 @@ RUNTIME_FUNCTION(MaybeObject*, Runtime_LiveEditFunctionSourceUpdated) {
// Replaces code of SharedFunctionInfo with a new one. // Replaces code of SharedFunctionInfo with a new one.
RUNTIME_FUNCTION(MaybeObject*, Runtime_LiveEditReplaceFunctionCode) { RUNTIME_FUNCTION(MaybeObject*, Runtime_LiveEditReplaceFunctionCode) {
CHECK(isolate->debugger()->live_edit_enabled());
ASSERT(args.length() == 2); ASSERT(args.length() == 2);
HandleScope scope(isolate); HandleScope scope(isolate);
CONVERT_ARG_HANDLE_CHECKED(JSArray, new_compile_info, 0); CONVERT_ARG_HANDLE_CHECKED(JSArray, new_compile_info, 0);
...@@ -12361,6 +12366,7 @@ RUNTIME_FUNCTION(MaybeObject*, Runtime_LiveEditReplaceFunctionCode) { ...@@ -12361,6 +12366,7 @@ RUNTIME_FUNCTION(MaybeObject*, Runtime_LiveEditReplaceFunctionCode) {
// Connects SharedFunctionInfo to another script. // Connects SharedFunctionInfo to another script.
RUNTIME_FUNCTION(MaybeObject*, Runtime_LiveEditFunctionSetScript) { RUNTIME_FUNCTION(MaybeObject*, Runtime_LiveEditFunctionSetScript) {
CHECK(isolate->debugger()->live_edit_enabled());
ASSERT(args.length() == 2); ASSERT(args.length() == 2);
HandleScope scope(isolate); HandleScope scope(isolate);
Handle<Object> function_object(args[0], isolate); Handle<Object> function_object(args[0], isolate);
...@@ -12387,6 +12393,7 @@ RUNTIME_FUNCTION(MaybeObject*, Runtime_LiveEditFunctionSetScript) { ...@@ -12387,6 +12393,7 @@ RUNTIME_FUNCTION(MaybeObject*, Runtime_LiveEditFunctionSetScript) {
// In a code of a parent function replaces original function as embedded object // In a code of a parent function replaces original function as embedded object
// with a substitution one. // with a substitution one.
RUNTIME_FUNCTION(MaybeObject*, Runtime_LiveEditReplaceRefToNestedFunction) { RUNTIME_FUNCTION(MaybeObject*, Runtime_LiveEditReplaceRefToNestedFunction) {
CHECK(isolate->debugger()->live_edit_enabled());
ASSERT(args.length() == 3); ASSERT(args.length() == 3);
HandleScope scope(isolate); HandleScope scope(isolate);
...@@ -12407,6 +12414,7 @@ RUNTIME_FUNCTION(MaybeObject*, Runtime_LiveEditReplaceRefToNestedFunction) { ...@@ -12407,6 +12414,7 @@ RUNTIME_FUNCTION(MaybeObject*, Runtime_LiveEditReplaceRefToNestedFunction) {
// (change_begin, change_end, change_end_new_position). // (change_begin, change_end, change_end_new_position).
// Each group describes a change in text; groups are sorted by change_begin. // Each group describes a change in text; groups are sorted by change_begin.
RUNTIME_FUNCTION(MaybeObject*, Runtime_LiveEditPatchFunctionPositions) { RUNTIME_FUNCTION(MaybeObject*, Runtime_LiveEditPatchFunctionPositions) {
CHECK(isolate->debugger()->live_edit_enabled());
ASSERT(args.length() == 2); ASSERT(args.length() == 2);
HandleScope scope(isolate); HandleScope scope(isolate);
CONVERT_ARG_HANDLE_CHECKED(JSArray, shared_array, 0); CONVERT_ARG_HANDLE_CHECKED(JSArray, shared_array, 0);
...@@ -12421,6 +12429,7 @@ RUNTIME_FUNCTION(MaybeObject*, Runtime_LiveEditPatchFunctionPositions) { ...@@ -12421,6 +12429,7 @@ RUNTIME_FUNCTION(MaybeObject*, Runtime_LiveEditPatchFunctionPositions) {
// Returns array of the same length with corresponding results of // Returns array of the same length with corresponding results of
// LiveEdit::FunctionPatchabilityStatus type. // LiveEdit::FunctionPatchabilityStatus type.
RUNTIME_FUNCTION(MaybeObject*, Runtime_LiveEditCheckAndDropActivations) { RUNTIME_FUNCTION(MaybeObject*, Runtime_LiveEditCheckAndDropActivations) {
CHECK(isolate->debugger()->live_edit_enabled());
ASSERT(args.length() == 2); ASSERT(args.length() == 2);
HandleScope scope(isolate); HandleScope scope(isolate);
CONVERT_ARG_HANDLE_CHECKED(JSArray, shared_array, 0); CONVERT_ARG_HANDLE_CHECKED(JSArray, shared_array, 0);
...@@ -12434,6 +12443,7 @@ RUNTIME_FUNCTION(MaybeObject*, Runtime_LiveEditCheckAndDropActivations) { ...@@ -12434,6 +12443,7 @@ RUNTIME_FUNCTION(MaybeObject*, Runtime_LiveEditCheckAndDropActivations) {
// of JSArray of triplets (pos1, pos1_end, pos2_end) describing list // of JSArray of triplets (pos1, pos1_end, pos2_end) describing list
// of diff chunks. // of diff chunks.
RUNTIME_FUNCTION(MaybeObject*, Runtime_LiveEditCompareStrings) { RUNTIME_FUNCTION(MaybeObject*, Runtime_LiveEditCompareStrings) {
CHECK(isolate->debugger()->live_edit_enabled());
ASSERT(args.length() == 2); ASSERT(args.length() == 2);
HandleScope scope(isolate); HandleScope scope(isolate);
CONVERT_ARG_HANDLE_CHECKED(String, s1, 0); CONVERT_ARG_HANDLE_CHECKED(String, s1, 0);
...@@ -12446,6 +12456,7 @@ RUNTIME_FUNCTION(MaybeObject*, Runtime_LiveEditCompareStrings) { ...@@ -12446,6 +12456,7 @@ RUNTIME_FUNCTION(MaybeObject*, Runtime_LiveEditCompareStrings) {
// Restarts a call frame and completely drops all frames above. // Restarts a call frame and completely drops all frames above.
// Returns true if successful. Otherwise returns undefined or an error message. // Returns true if successful. Otherwise returns undefined or an error message.
RUNTIME_FUNCTION(MaybeObject*, Runtime_LiveEditRestartFrame) { RUNTIME_FUNCTION(MaybeObject*, Runtime_LiveEditRestartFrame) {
CHECK(isolate->debugger()->live_edit_enabled());
HandleScope scope(isolate); HandleScope scope(isolate);
ASSERT(args.length() == 2); ASSERT(args.length() == 2);
...@@ -12485,6 +12496,7 @@ RUNTIME_FUNCTION(MaybeObject*, Runtime_LiveEditRestartFrame) { ...@@ -12485,6 +12496,7 @@ RUNTIME_FUNCTION(MaybeObject*, Runtime_LiveEditRestartFrame) {
// A testing entry. Returns statement position which is the closest to // A testing entry. Returns statement position which is the closest to
// source_position. // source_position.
RUNTIME_FUNCTION(MaybeObject*, Runtime_GetFunctionCodePositionFromSource) { RUNTIME_FUNCTION(MaybeObject*, Runtime_GetFunctionCodePositionFromSource) {
CHECK(isolate->debugger()->live_edit_enabled());
ASSERT(args.length() == 2); ASSERT(args.length() == 2);
HandleScope scope(isolate); HandleScope scope(isolate);
CONVERT_ARG_HANDLE_CHECKED(JSFunction, function, 0); CONVERT_ARG_HANDLE_CHECKED(JSFunction, function, 0);
......
...@@ -44,6 +44,9 @@ test-heap-profiler/HeapSnapshotsDiff: PASS || FAIL ...@@ -44,6 +44,9 @@ test-heap-profiler/HeapSnapshotsDiff: PASS || FAIL
test-serialize/TestThatAlwaysFails: FAIL test-serialize/TestThatAlwaysFails: FAIL
test-serialize/DependentTestThatAlwaysFails: FAIL test-serialize/DependentTestThatAlwaysFails: FAIL
# This test always fails. It tests that LiveEdit causes abort when turned off.
test-debug/LiveEditDisabled: FAIL
# TODO(gc): Temporarily disabled in the GC branch. # TODO(gc): Temporarily disabled in the GC branch.
test-log/EquivalenceOfLoggingAndTraversal: PASS || FAIL test-log/EquivalenceOfLoggingAndTraversal: PASS || FAIL
......
...@@ -7420,4 +7420,23 @@ TEST(DebuggerCreatesContextIffActive) { ...@@ -7420,4 +7420,23 @@ TEST(DebuggerCreatesContextIffActive) {
v8::Debug::SetDebugEventListener(NULL); v8::Debug::SetDebugEventListener(NULL);
} }
TEST(LiveEditEnabled) {
v8::internal::FLAG_allow_natives_syntax = true;
v8::HandleScope scope;
LocalContext context;
v8::Debug::SetLiveEditEnabled(true);
CompileRun("%LiveEditCompareStrings('', '')");
}
TEST(LiveEditDisabled) {
v8::internal::FLAG_allow_natives_syntax = true;
v8::HandleScope scope;
LocalContext context;
v8::Debug::SetLiveEditEnabled(false);
CompileRun("%LiveEditCompareStrings('', '')");
}
#endif // ENABLE_DEBUGGER_SUPPORT #endif // ENABLE_DEBUGGER_SUPPORT
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment