Reviewers: Peter Rybin, Erik Corry,
Message:
Please take a look.
Description:
Enable/disable LiveEdit using the (C++) debug API.
BUG=
Please review this at http://codereview.chromium.org/10875072/
SVN Base: https://v8.googlecode.com/svn/branches/bleeding_edge
Affected files:
M include/v8-debug.h
M src/api.cc
M src/debug.h
M src/debug.cc
M src/runtime.cc
M test/cctest/cctest.status
M test/cctest/test-debug.cc
Index: include/v8-debug.h
diff --git a/include/v8-debug.h b/include/v8-debug.h
index
9e85dc462cc6d8c5b776600130b0a5fbc062865d..a417c86d85e06b973e5c0e4af48876405f32b99a
100755
--- a/include/v8-debug.h
+++ b/include/v8-debug.h
@@ -388,6 +388,14 @@ class EXPORT Debug {
* to change.
*/
static Local<Context> GetDebugContext();
+
+
+ /**
+ * Optionally 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);
};
Index: src/api.cc
diff --git a/src/api.cc b/src/api.cc
index
0da6ab7378a4440178df3b8ece77c4db71353a3c..4bf24c4f3d7b70d3e4d33b8beb8ded3b9a60f3a5
100644
--- a/src/api.cc
+++ b/src/api.cc
@@ -5831,6 +5831,7 @@ void Debug::ProcessDebugMessages() {
i::Execution::ProcessDebugMessages(true);
}
+
Local<Context> Debug::GetDebugContext() {
i::Isolate* isolate = i::Isolate::Current();
EnsureInitializedForIsolate(isolate, "v8::Debug::GetDebugContext()");
@@ -5838,6 +5839,20 @@ Local<Context> Debug::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
Index: src/debug.cc
diff --git a/src/debug.cc b/src/debug.cc
index
12b2b576d48d36be289598a71e058de728308b78..314aa0d3c9eb56cc610ed1190fc3b1d65e870d99
100644
--- a/src/debug.cc
+++ b/src/debug.cc
@@ -2404,6 +2404,7 @@ Debugger::Debugger(Isolate* isolate)
event_listener_data_(Handle<Object>()),
compiling_natives_(false),
is_loading_debugger_(false),
+ is_live_edit_enabled_(true),
never_unload_debugger_(false),
force_debugger_active_(false),
message_handler_(NULL),
Index: src/debug.h
diff --git a/src/debug.h b/src/debug.h
index
bb804206cdd2a8626c22858eac05520448eb0fbe..825238209f99233606eee7e2b48cc6373d807de0
100644
--- a/src/debug.h
+++ b/src/debug.h
@@ -872,6 +872,8 @@ class Debugger {
bool compiling_natives() const { return compiling_natives_; }
void set_loading_debugger(bool v) { is_loading_debugger_ = v; }
bool is_loading_debugger() const { return is_loading_debugger_; }
+ void set_live_edit_enabled(bool v) { is_live_edit_enabled_ = v; }
+ bool is_live_edit_enabled() const { return is_live_edit_enabled_; }
void set_force_debugger_active(bool force_debugger_active) {
force_debugger_active_ = force_debugger_active;
}
@@ -900,6 +902,7 @@ class Debugger {
Handle<Object> event_listener_data_;
bool compiling_natives_; // Are we compiling natives?
bool is_loading_debugger_; // Are we loading the debugger?
+ bool is_live_edit_enabled_; // Enable LiveEdit.
bool never_unload_debugger_; // Can we unload the debugger?
bool force_debugger_active_; // Activate debugger without event
listeners.
v8::Debug::MessageHandler2 message_handler_;
Index: src/runtime.cc
diff --git a/src/runtime.cc b/src/runtime.cc
index
4e0a86b318c2a8225cefe177bb4bce23269e0677..b805133c77f125b9acc77e98f8f9773c5d403bf8
100644
--- a/src/runtime.cc
+++ b/src/runtime.cc
@@ -12687,6 +12687,7 @@ static int
FindSharedFunctionInfosForScript(HeapIterator* iterator,
// in OpaqueReferences.
RUNTIME_FUNCTION(MaybeObject*,
Runtime_LiveEditFindSharedFunctionInfosForScript) {
+ CHECK(isolate->debugger()->is_live_edit_enabled());
ASSERT(args.length() == 1);
HandleScope scope(isolate);
CONVERT_ARG_CHECKED(JSValue, script_value, 0);
@@ -12733,6 +12734,7 @@ RUNTIME_FUNCTION(MaybeObject*,
// 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.
RUNTIME_FUNCTION(MaybeObject*, Runtime_LiveEditGatherCompileInfo) {
+ CHECK(isolate->debugger()->is_live_edit_enabled());
ASSERT(args.length() == 2);
HandleScope scope(isolate);
CONVERT_ARG_CHECKED(JSValue, script, 0);
@@ -12752,6 +12754,7 @@ RUNTIME_FUNCTION(MaybeObject*,
Runtime_LiveEditGatherCompileInfo) {
// 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.
RUNTIME_FUNCTION(MaybeObject*, Runtime_LiveEditReplaceScript) {
+ CHECK(isolate->debugger()->is_live_edit_enabled());
ASSERT(args.length() == 3);
HandleScope scope(isolate);
CONVERT_ARG_CHECKED(JSValue, original_script_value, 0);
@@ -12775,6 +12778,7 @@ RUNTIME_FUNCTION(MaybeObject*,
Runtime_LiveEditReplaceScript) {
RUNTIME_FUNCTION(MaybeObject*, Runtime_LiveEditFunctionSourceUpdated) {
+ CHECK(isolate->debugger()->is_live_edit_enabled());
ASSERT(args.length() == 1);
HandleScope scope(isolate);
CONVERT_ARG_HANDLE_CHECKED(JSArray, shared_info, 0);
@@ -12784,6 +12788,7 @@ RUNTIME_FUNCTION(MaybeObject*,
Runtime_LiveEditFunctionSourceUpdated) {
// Replaces code of SharedFunctionInfo with a new one.
RUNTIME_FUNCTION(MaybeObject*, Runtime_LiveEditReplaceFunctionCode) {
+ CHECK(isolate->debugger()->is_live_edit_enabled());
ASSERT(args.length() == 2);
HandleScope scope(isolate);
CONVERT_ARG_HANDLE_CHECKED(JSArray, new_compile_info, 0);
@@ -12794,6 +12799,7 @@ RUNTIME_FUNCTION(MaybeObject*,
Runtime_LiveEditReplaceFunctionCode) {
// Connects SharedFunctionInfo to another script.
RUNTIME_FUNCTION(MaybeObject*, Runtime_LiveEditFunctionSetScript) {
+ CHECK(isolate->debugger()->is_live_edit_enabled());
ASSERT(args.length() == 2);
HandleScope scope(isolate);
Handle<Object> function_object(args[0], isolate);
@@ -12820,6 +12826,7 @@ RUNTIME_FUNCTION(MaybeObject*,
Runtime_LiveEditFunctionSetScript) {
// In a code of a parent function replaces original function as embedded
object
// with a substitution one.
RUNTIME_FUNCTION(MaybeObject*, Runtime_LiveEditReplaceRefToNestedFunction)
{
+ CHECK(isolate->debugger()->is_live_edit_enabled());
ASSERT(args.length() == 3);
HandleScope scope(isolate);
@@ -12840,6 +12847,7 @@ RUNTIME_FUNCTION(MaybeObject*,
Runtime_LiveEditReplaceRefToNestedFunction) {
// (change_begin, change_end, change_end_new_position).
// Each group describes a change in text; groups are sorted by
change_begin.
RUNTIME_FUNCTION(MaybeObject*, Runtime_LiveEditPatchFunctionPositions) {
+ CHECK(isolate->debugger()->is_live_edit_enabled());
ASSERT(args.length() == 2);
HandleScope scope(isolate);
CONVERT_ARG_HANDLE_CHECKED(JSArray, shared_array, 0);
@@ -12854,6 +12862,7 @@ RUNTIME_FUNCTION(MaybeObject*,
Runtime_LiveEditPatchFunctionPositions) {
// Returns array of the same length with corresponding results of
// LiveEdit::FunctionPatchabilityStatus type.
RUNTIME_FUNCTION(MaybeObject*, Runtime_LiveEditCheckAndDropActivations) {
+ CHECK(isolate->debugger()->is_live_edit_enabled());
ASSERT(args.length() == 2);
HandleScope scope(isolate);
CONVERT_ARG_HANDLE_CHECKED(JSArray, shared_array, 0);
@@ -12867,6 +12876,7 @@ RUNTIME_FUNCTION(MaybeObject*,
Runtime_LiveEditCheckAndDropActivations) {
// of JSArray of triplets (pos1, pos1_end, pos2_end) describing list
// of diff chunks.
RUNTIME_FUNCTION(MaybeObject*, Runtime_LiveEditCompareStrings) {
+ CHECK(isolate->debugger()->is_live_edit_enabled());
ASSERT(args.length() == 2);
HandleScope scope(isolate);
CONVERT_ARG_HANDLE_CHECKED(String, s1, 0);
@@ -12879,6 +12889,7 @@ RUNTIME_FUNCTION(MaybeObject*,
Runtime_LiveEditCompareStrings) {
// Restarts a call frame and completely drops all frames above.
// Returns true if successful. Otherwise returns undefined or an error
message.
RUNTIME_FUNCTION(MaybeObject*, Runtime_LiveEditRestartFrame) {
+ CHECK(isolate->debugger()->is_live_edit_enabled());
HandleScope scope(isolate);
ASSERT(args.length() == 2);
@@ -12918,6 +12929,7 @@ RUNTIME_FUNCTION(MaybeObject*,
Runtime_LiveEditRestartFrame) {
// A testing entry. Returns statement position which is the closest to
// source_position.
RUNTIME_FUNCTION(MaybeObject*, Runtime_GetFunctionCodePositionFromSource) {
+ CHECK(isolate->debugger()->is_live_edit_enabled());
ASSERT(args.length() == 2);
HandleScope scope(isolate);
CONVERT_ARG_HANDLE_CHECKED(JSFunction, function, 0);
Index: test/cctest/cctest.status
diff --git a/test/cctest/cctest.status b/test/cctest/cctest.status
index
f529adb497618d9417a8df020654ee58745dab31..df2c520567756786e19f3e7b0342c24c8b146414
100644
--- a/test/cctest/cctest.status
+++ b/test/cctest/cctest.status
@@ -44,6 +44,9 @@ test-heap-profiler/HeapSnapshotsDiff: PASS || FAIL
test-serialize/TestThatAlwaysFails: 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.
test-log/EquivalenceOfLoggingAndTraversal: PASS || FAIL
Index: test/cctest/test-debug.cc
diff --git a/test/cctest/test-debug.cc b/test/cctest/test-debug.cc
index
83cbbf30da404fb7938ecb4abe93bab2a2a63585..234b6df72217ef11d510e17c348dca9375920bc4
100644
--- a/test/cctest/test-debug.cc
+++ b/test/cctest/test-debug.cc
@@ -7420,4 +7420,23 @@ TEST(DebuggerCreatesContextIffActive) {
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
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev