liveedit.h 2.15 KB
Newer Older
1
// Copyright 2012 the V8 project authors. All rights reserved.
2 3
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
4

5 6
#ifndef V8_DEBUG_LIVEEDIT_H_
#define V8_DEBUG_LIVEEDIT_H_
7

8
#include <vector>
9

10
#include "src/common/globals.h"
11
#include "src/handles/handles.h"
12 13

namespace v8 {
14 15
namespace debug {
struct LiveEditResult;
16
}  // namespace debug
17 18
namespace internal {

19 20 21
class Script;
class String;
class Debug;
22 23
class JavaScriptFrame;

24 25 26 27 28 29 30
struct SourceChangeRange {
  int start_position;
  int end_position;
  int new_start_position;
  int new_end_position;
};

31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
/**
  Liveedit step-by-step:
  1. calculate diff between old source and new source,
  2. map function literals from old source to new source,
  3. create new script for new_source,
  4. mark literals with changed code as changed, all others as unchanged,
  5. check that for changed literals there are no:
    - running generators in the heap,
    - non droppable frames (e.g. running generator) above them on stack.
  6. mark the bottom most frame with changed function as scheduled for restart
     if any,
  7. for unchanged functions:
    - deoptimize,
    - remove from cache,
    - update source positions,
    - move to new script,
    - reset feedback information and preparsed scope information if any,
    - replace any sfi in constant pool with changed one if any.
  8. for changed functions:
    - deoptimize
    - remove from cache,
    - reset feedback information,
    - update all links from js functions to old shared with new one.
  9. swap scripts.
 */
56

57
class V8_EXPORT_PRIVATE LiveEdit : AllStatic {
58
 public:
59 60
  static void CompareStrings(Isolate* isolate, Handle<String> a,
                             Handle<String> b,
61
                             std::vector<SourceChangeRange>* diffs);
62 63
  static int TranslatePosition(const std::vector<SourceChangeRange>& changed,
                               int position);
64 65
  static void PatchScript(Isolate* isolate, Handle<Script> script,
                          Handle<String> source, bool preview,
66
                          debug::LiveEditResult* result);
67
};
68 69
}  // namespace internal
}  // namespace v8
70

71
#endif  // V8_DEBUG_LIVEEDIT_H_