Skip to content

Commit cc9736a

Browse files
hashseedCommit Bot
authored andcommitted
[debug] disable debug breaks in side-effect free debug-evaluate.
We don't want to run into the situation of breaking inside of debug-evaluate. That would get even more confusing with throw-on-side-effect. R=kozyatinskiy@chromium.org Bug: v8:7592 Change-Id: I93f5de63d8943792ff000dbf7c6311df655d3793 Reviewed-on: https://chromium-review.googlesource.com/978164 Reviewed-by: Aleksey Kozyatinskiy <kozyatinskiy@chromium.org> Commit-Queue: Yang Guo <yangguo@chromium.org> Cr-Commit-Position: refs/heads/master@{#52227}
1 parent 6f52d01 commit cc9736a

5 files changed

Lines changed: 57 additions & 8 deletions

File tree

src/debug/debug-evaluate.cc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ namespace internal {
2424
MaybeHandle<Object> DebugEvaluate::Global(Isolate* isolate,
2525
Handle<String> source,
2626
bool throw_on_side_effect) {
27+
// Disable breaks in side-effect free mode.
28+
DisableBreak disable_break_scope(isolate->debug(), throw_on_side_effect);
29+
2730
Handle<Context> context = isolate->native_context();
2831
ScriptOriginOptions origin_options(false, true);
2932
MaybeHandle<SharedFunctionInfo> maybe_function_info =

src/debug/debug.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2388,7 +2388,7 @@ NoSideEffectScope::~NoSideEffectScope() {
23882388
isolate_->Throw(*isolate_->factory()->NewEvalError(
23892389
MessageTemplate::kNoSideEffectDebugEvaluate));
23902390
}
2391-
isolate_->set_needs_side_effect_check(old_needs_side_effect_check_);
2391+
isolate_->set_needs_side_effect_check(false);
23922392
isolate_->debug()->UpdateHookOnFunctionCall();
23932393
isolate_->debug()->side_effect_check_failed_ = false;
23942394
}

src/debug/debug.h

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -700,9 +700,9 @@ class ReturnValueScope {
700700
// Stack allocated class for disabling break.
701701
class DisableBreak BASE_EMBEDDED {
702702
public:
703-
explicit DisableBreak(Debug* debug)
703+
explicit DisableBreak(Debug* debug, bool disable = true)
704704
: debug_(debug), previous_break_disabled_(debug->break_disabled_) {
705-
debug_->break_disabled_ = true;
705+
debug_->break_disabled_ = disable;
706706
}
707707
~DisableBreak() {
708708
debug_->break_disabled_ = previous_break_disabled_;
@@ -732,18 +732,17 @@ class SuppressDebug BASE_EMBEDDED {
732732
class NoSideEffectScope {
733733
public:
734734
NoSideEffectScope(Isolate* isolate, bool disallow_side_effects)
735-
: isolate_(isolate),
736-
old_needs_side_effect_check_(isolate->needs_side_effect_check()) {
737-
isolate->set_needs_side_effect_check(old_needs_side_effect_check_ ||
738-
disallow_side_effects);
735+
: isolate_(isolate) {
736+
// NoSideEffectScope is not re-entrant if already enabled.
737+
CHECK(!isolate->needs_side_effect_check());
738+
isolate->set_needs_side_effect_check(disallow_side_effects);
739739
isolate->debug()->UpdateHookOnFunctionCall();
740740
isolate->debug()->side_effect_check_failed_ = false;
741741
}
742742
~NoSideEffectScope();
743743

744744
private:
745745
Isolate* isolate_;
746-
bool old_needs_side_effect_check_;
747746
DISALLOW_COPY_AND_ASSIGN(NoSideEffectScope);
748747
};
749748

test/inspector/runtime/evaluate-without-side-effects-expected.txt

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,3 +48,26 @@ Test expression without side-effect, with throwOnSideEffect: true
4848
}
4949
}
5050
}
51+
Test that debug break triggers without throwOnSideEffect
52+
paused
53+
{
54+
id : <messageId>
55+
result : {
56+
result : {
57+
description : 2
58+
type : number
59+
value : 2
60+
}
61+
}
62+
}
63+
Test that debug break does not trigger with throwOnSideEffect
64+
{
65+
id : <messageId>
66+
result : {
67+
result : {
68+
description : 2
69+
type : number
70+
value : 2
71+
}
72+
}
73+
}

test/inspector/runtime/evaluate-without-side-effects.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,19 @@
44

55
let {session, contextGroup, Protocol} = InspectorTest.start("Tests that Runtime.evaluate can run without side effects.");
66

7+
session.setupScriptMap();
8+
contextGroup.addScript(`
9+
function f() {
10+
return 2;
11+
} //# sourceURL=test.js`);
712
Protocol.Runtime.enable();
813
Protocol.Debugger.enable();
14+
15+
Protocol.Debugger.onPaused(message => {
16+
InspectorTest.log("paused");
17+
Protocol.Debugger.resume();
18+
});
19+
920
(async function() {
1021
InspectorTest.log("Test throwOnSideEffect: false");
1122
InspectorTest.logMessage(await Protocol.Runtime.evaluate({
@@ -25,5 +36,18 @@ Protocol.Debugger.enable();
2536
throwOnSideEffect: true
2637
}));
2738

39+
InspectorTest.log("Test that debug break triggers without throwOnSideEffect");
40+
await Protocol.Debugger.setBreakpointByUrl({ url: 'test.js', lineNumber: 2 });
41+
InspectorTest.logMessage(await Protocol.Runtime.evaluate({
42+
expression: "f()",
43+
throwOnSideEffect: false
44+
}));
45+
46+
InspectorTest.log("Test that debug break does not trigger with throwOnSideEffect");
47+
InspectorTest.logMessage(await Protocol.Runtime.evaluate({
48+
expression: "f()",
49+
throwOnSideEffect: true
50+
}));
51+
2852
InspectorTest.completeTest();
2953
})();

0 commit comments

Comments
 (0)