V8 Project
v8::ReadLineEditor Class Reference
+ Inheritance diagram for v8::ReadLineEditor:
+ Collaboration diagram for v8::ReadLineEditor:

Public Member Functions

 ReadLineEditor ()
 
virtual Handle< StringPrompt (const char *prompt)
 
virtual bool Open (Isolate *isolate)
 
virtual bool Close ()
 
virtual void AddHistory (const char *str)
 
- Public Member Functions inherited from v8::LineEditor
 LineEditor (Type type, const char *name)
 
virtual ~LineEditor ()
 
const char * name ()
 

Static Public Attributes

static const char * kHistoryFileName = ".d8_history"
 
static const int kMaxHistoryEntries = 1000
 

Static Private Member Functions

static char ** AttemptedCompletion (const char *text, int start, int end)
 
static char * CompletionGenerator (const char *text, int state)
 

Private Attributes

Isolateisolate_
 

Static Private Attributes

static char kWordBreakCharacters []
 

Additional Inherited Members

- Public Types inherited from v8::LineEditor
enum  Type { DUMB = 0 , READLINE = 1 }
 
- Static Public Member Functions inherited from v8::LineEditor
static LineEditorGet ()
 

Detailed Description

Definition at line 25 of file d8-readline.cc.

Constructor & Destructor Documentation

◆ ReadLineEditor()

v8::ReadLineEditor::ReadLineEditor ( )
inline

Definition at line 27 of file d8-readline.cc.

27 : LineEditor(LineEditor::READLINE, "readline") { }
@ READLINE
Definition: d8.h:99
LineEditor(Type type, const char *name)
Definition: d8.cc:120

Member Function Documentation

◆ AddHistory()

void v8::ReadLineEditor::AddHistory ( const char *  str)
virtual

Reimplemented from v8::LineEditor.

Definition at line 92 of file d8-readline.cc.

92  {
93  // Do not record empty input.
94  if (strlen(str) == 0) return;
95  // Remove duplicate history entry.
96  history_set_pos(history_length-1);
97  if (current_history()) {
98  do {
99  if (strcmp(current_history()->line, str) == 0) {
100  remove_history(where_history());
101  break;
102  }
103  } while (previous_history());
104  }
105  add_history(str);
106 }

Referenced by Prompt().

+ Here is the caller graph for this function:

◆ AttemptedCompletion()

char ** v8::ReadLineEditor::AttemptedCompletion ( const char *  text,
int  start,
int  end 
)
staticprivate

Definition at line 110 of file d8-readline.cc.

112  {
113  char** result = completion_matches(text, CompletionGenerator);
114  rl_attempted_completion_over = true;
115  return result;
116 }
static char * CompletionGenerator(const char *text, int state)
Definition: d8-readline.cc:119

References CompletionGenerator().

Referenced by Open().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ Close()

bool v8::ReadLineEditor::Close ( )
virtual

Reimplemented from v8::LineEditor.

Definition at line 78 of file d8-readline.cc.

78  {
79  return write_history(kHistoryFileName) == 0;
80 }
static const char * kHistoryFileName
Definition: d8-readline.cc:33

References kHistoryFileName.

◆ CompletionGenerator()

char * v8::ReadLineEditor::CompletionGenerator ( const char *  text,
int  state 
)
staticprivate

Definition at line 119 of file d8-readline.cc.

119  {
120  static unsigned current_index;
121  static Persistent<Array> current_completions;
122  Isolate* isolate = read_line_editor.isolate_;
123  HandleScope scope(isolate);
124  Handle<Array> completions;
125  if (state == 0) {
126  Local<String> full_text = String::NewFromUtf8(isolate,
127  rl_line_buffer,
129  rl_point);
130  completions = Shell::GetCompletions(isolate,
131  String::NewFromUtf8(isolate, text),
132  full_text);
133  current_completions.Reset(isolate, completions);
134  current_index = 0;
135  } else {
136  completions = Local<Array>::New(isolate, current_completions);
137  }
138  if (current_index < completions->Length()) {
139  Handle<Integer> index = Integer::New(isolate, current_index);
140  Handle<Value> str_obj = completions->Get(index);
141  current_index++;
142  String::Utf8Value str(str_obj);
143  return strdup(*str);
144  } else {
145  current_completions.Reset();
146  return NULL;
147  }
148 }
static Local< Integer > New(Isolate *isolate, int32_t value)
Definition: api.cc:6281
static Local< T > New(Isolate *isolate, Handle< T > that)
Create a local handle for the content of another handle.
Definition: v8.h:5987
Isolate * isolate_
Definition: d8-readline.cc:43
static Handle< Array > GetCompletions(Isolate *isolate, Handle< String > text, Handle< String > full)
Definition: d8.cc:638
@ kNormalString
Definition: v8.h:1963
static Local< String > NewFromUtf8(Isolate *isolate, const char *data, NewStringType type=kNormalString, int length=-1)
Allocates a new string from UTF-8 data.
Definition: api.cc:5447
enable harmony numeric enable harmony object literal extensions Optimize object Array DOM strings and string trace pretenuring decisions of HAllocate instructions Enables optimizations which favor memory size over execution speed maximum source size in bytes considered for a single inlining maximum cumulative number of AST nodes considered for inlining trace the tracking of allocation sites deoptimize every n garbage collections perform array bounds checks elimination analyze liveness of environment slots and zap dead values flushes the cache of optimized code for closures on every GC allow uint32 values on optimize frames if they are used only in safe operations track concurrent recompilation artificial compilation delay in ms do not emit check maps for constant values that have a leaf deoptimize the optimized code if the layout of the maps changes enable context specialization in TurboFan execution budget before interrupt is triggered max percentage of megamorphic generic ICs to allow optimization enable use of SAHF instruction if enable use of VFP3 instructions if available enable use of NEON instructions if enable use of SDIV and UDIV instructions if enable use of MLS instructions if enable loading bit constant by means of movw movt instruction enable unaligned accesses for enable use of d16 d31 registers on ARM this requires VFP3 force all emitted branches to be in long enable alignment of csp to bytes on platforms which prefer the register to always be NULL
static ReadLineEditor read_line_editor
Definition: d8-readline.cc:47

References v8::Shell::GetCompletions(), isolate_, v8::String::kNormalString, v8::Local< T >::New(), v8::Integer::New(), v8::String::NewFromUtf8(), NULL, v8::read_line_editor, and v8::PersistentBase< T >::Reset().

Referenced by AttemptedCompletion().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ Open()

bool v8::ReadLineEditor::Open ( Isolate isolate)
virtual

Reimplemented from v8::LineEditor.

Definition at line 57 of file d8-readline.cc.

57  {
58  isolate_ = isolate;
59 
60  rl_initialize();
61 
62 #ifdef V8_SHARED
63  // Don't do completion on shared library mode
64  // http://cnswww.cns.cwru.edu/php/chet/readline/readline.html#SEC24
65  rl_bind_key('\t', rl_insert);
66 #else
67  rl_attempted_completion_function = AttemptedCompletion;
68 #endif // V8_SHARED
69 
70  rl_completer_word_break_characters = kWordBreakCharacters;
71  rl_bind_key('\t', rl_complete);
72  using_history();
73  stifle_history(kMaxHistoryEntries);
74  return read_history(kHistoryFileName) == 0;
75 }
static char kWordBreakCharacters[]
Definition: d8-readline.cc:41
static char ** AttemptedCompletion(const char *text, int start, int end)
Definition: d8-readline.cc:110
static const int kMaxHistoryEntries
Definition: d8-readline.cc:34

References AttemptedCompletion(), isolate_, kHistoryFileName, kMaxHistoryEntries, and kWordBreakCharacters.

+ Here is the call graph for this function:

◆ Prompt()

Handle< String > v8::ReadLineEditor::Prompt ( const char *  prompt)
virtual

Implements v8::LineEditor.

Definition at line 83 of file d8-readline.cc.

83  {
84  char* result = NULL;
85  result = readline(prompt);
86  if (result == NULL) return Handle<String>();
87  AddHistory(result);
88  return String::NewFromUtf8(isolate_, result);
89 }
virtual void AddHistory(const char *str)
Definition: d8-readline.cc:92

References AddHistory(), isolate_, v8::String::NewFromUtf8(), and NULL.

+ Here is the call graph for this function:

Member Data Documentation

◆ isolate_

Isolate* v8::ReadLineEditor::isolate_
private

Definition at line 43 of file d8-readline.cc.

Referenced by CompletionGenerator(), Open(), and Prompt().

◆ kHistoryFileName

const char * v8::ReadLineEditor::kHistoryFileName = ".d8_history"
static

Definition at line 33 of file d8-readline.cc.

Referenced by Close(), and Open().

◆ kMaxHistoryEntries

const int v8::ReadLineEditor::kMaxHistoryEntries = 1000
static

Definition at line 34 of file d8-readline.cc.

Referenced by Open().

◆ kWordBreakCharacters

char v8::ReadLineEditor::kWordBreakCharacters
staticprivate
Initial value:
= {' ', '\t', '\n', '"',
'\\', '\'', '`', '@', '.', '>', '<', '=', ';', '|', '&', '{', '(',
'\0'}

Definition at line 41 of file d8-readline.cc.

Referenced by Open().


The documentation for this class was generated from the following file: