Commit 275bfa1b authored by wingo@igalia.com's avatar wingo@igalia.com

Relocate suspended generator activations when enabling debug mode

R=yangguo@chromium.org
BUG=v8:3289
LOG=N

Review URL: https://codereview.chromium.org/264973014

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@21145 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent 12b2f9d6
This diff is collapsed.
......@@ -511,6 +511,10 @@ class Debug {
Handle<Object> CheckBreakPoints(Handle<Object> break_point);
bool CheckBreakPoint(Handle<Object> break_point_object);
void MaybeRecompileFunctionForDebugging(Handle<JSFunction> function);
void RecompileAndRelocateSuspendedGenerators(
const List<Handle<JSGeneratorObject> > &suspended_generators);
// Global handle to debug context where all the debugger JavaScript code is
// loaded.
Handle<Context> debug_context_;
......
......@@ -5711,6 +5711,11 @@ SMI_ACCESSORS(JSGeneratorObject, continuation, kContinuationOffset)
ACCESSORS(JSGeneratorObject, operand_stack, FixedArray, kOperandStackOffset)
SMI_ACCESSORS(JSGeneratorObject, stack_handler_index, kStackHandlerIndexOffset)
bool JSGeneratorObject::is_suspended() {
ASSERT_LT(kGeneratorExecuting, kGeneratorClosed);
ASSERT_EQ(kGeneratorClosed, 0);
return continuation() > 0;
}
JSGeneratorObject* JSGeneratorObject::cast(Object* obj) {
ASSERT(obj->IsJSGeneratorObject());
......
......@@ -7461,6 +7461,7 @@ class JSGeneratorObject: public JSObject {
// cannot be resumed.
inline int continuation();
inline void set_continuation(int continuation);
inline bool is_suspended();
// [operand_stack]: Saved operand stack.
DECL_ACCESSORS(operand_stack, FixedArray)
......
// Copyright 2014 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flags: --expose-debug-as debug --harmony-generators
var Debug = debug.Debug;
function assertIteratorResult(value, done, result) {
assertEquals({value: value, done: done}, result);
}
function RunTest(formals_and_body, args, value1, value2) {
// A null listener. It isn't important what the listener does.
function listener(event, exec_state, event_data, data) {
}
// Create the generator function outside a debugging context. It will probably
// be lazily compiled.
var gen = (function*(){}).constructor.apply(null, formals_and_body);
// Instantiate the generator object.
var obj = gen.apply(null, args);
// Advance to the first yield.
assertIteratorResult(value1, false, obj.next());
// Add a breakpoint on line 3 (the second yield).
var bp = Debug.setBreakPoint(gen, 3);
// Enable the debugger, which should force recompilation of the generator
// function and relocation of the suspended generator activation.
Debug.setListener(listener);
// Check that the generator resumes and suspends properly.
assertIteratorResult(value2, false, obj.next());
// Disable debugger -- should not force recompilation.
Debug.clearBreakPoint(bp);
Debug.setListener(null);
// Run to completion.
assertIteratorResult(undefined, true, obj.next());
}
function prog(a, b, c) {
return a + ';\n' + 'yield ' + b + ';\n' + 'yield ' + c;
}
// Simple empty local scope.
RunTest([prog('', '1', '2')], [], 1, 2);
RunTest([prog('for (;;) break', '1', '2')], [], 1, 2);
RunTest([prog('while (0) foo()', '1', '2')], [], 1, 2);
RunTest(['a', prog('var x = 3', 'a', 'x')], [1], 1, 3);
RunTest(['a', prog('', '1', '2')], [42], 1, 2);
RunTest(['a', prog('for (;;) break', '1', '2')], [42], 1, 2);
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