• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #ifndef V8_DEBUG_LIVEEDIT_H_
6 #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 namespace debug {
15 struct LiveEditResult;
16 }  // namespace debug
17 namespace internal {
18 
19 class Script;
20 class String;
21 class Debug;
22 class JavaScriptFrame;
23 
24 struct SourceChangeRange {
25   int start_position;
26   int end_position;
27   int new_start_position;
28   int new_end_position;
29 };
30 
31 /**
32   Liveedit step-by-step:
33   1. calculate diff between old source and new source,
34   2. map function literals from old source to new source,
35   3. create new script for new_source,
36   4. mark literals with changed code as changed, all others as unchanged,
37   5. check that for changed literals there are no:
38     - running generators in the heap,
39     - non droppable frames (e.g. running generator) above them on stack.
40   6. mark the bottom most frame with changed function as scheduled for restart
41      if any,
42   7. for unchanged functions:
43     - deoptimize,
44     - remove from cache,
45     - update source positions,
46     - move to new script,
47     - reset feedback information and preparsed scope information if any,
48     - replace any sfi in constant pool with changed one if any.
49   8. for changed functions:
50     - deoptimize
51     - remove from cache,
52     - reset feedback information,
53     - update all links from js functions to old shared with new one.
54   9. swap scripts.
55  */
56 
57 class V8_EXPORT_PRIVATE LiveEdit : AllStatic {
58  public:
59   static void CompareStrings(Isolate* isolate, Handle<String> a,
60                              Handle<String> b,
61                              std::vector<SourceChangeRange>* diffs);
62   static int TranslatePosition(const std::vector<SourceChangeRange>& changed,
63                                int position);
64   static void PatchScript(Isolate* isolate, Handle<Script> script,
65                           Handle<String> source, bool preview,
66                           debug::LiveEditResult* result);
67 };
68 }  // namespace internal
69 }  // namespace v8
70 
71 #endif  // V8_DEBUG_LIVEEDIT_H_
72