Remove readline support from d8.
Nobody seems to use it. A good alternative is rlwrap. R=jochen@chromium.org Review URL: https://codereview.chromium.org/1250223002 Cr-Commit-Position: refs/heads/master@{#29810}
This commit is contained in:
parent
3bc1b1346a
commit
8e027195b4
2
BUILD.gn
2
BUILD.gn
@ -1751,7 +1751,7 @@ if ((current_toolchain == host_toolchain && v8_toolset_for_d8 == "host") ||
|
||||
"//build/config/sanitizers:deps",
|
||||
]
|
||||
|
||||
# TODO(jochen): Add support for readline and vtunejit.
|
||||
# TODO(jochen): Add support for vtunejit.
|
||||
|
||||
if (is_posix) {
|
||||
sources += [ "src/d8-posix.cc" ]
|
||||
|
4
Makefile
4
Makefile
@ -44,10 +44,6 @@ endif
|
||||
ifdef component
|
||||
GYPFLAGS += -Dcomponent=$(component)
|
||||
endif
|
||||
# console=readline
|
||||
ifdef console
|
||||
GYPFLAGS += -Dconsole=$(console)
|
||||
endif
|
||||
# disassembler=on
|
||||
ifeq ($(disassembler), on)
|
||||
GYPFLAGS += -Dv8_enable_disassembler=1
|
||||
|
@ -1,155 +0,0 @@
|
||||
// Copyright 2012 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.
|
||||
|
||||
#include <stdio.h> // NOLINT
|
||||
#include <string.h> // NOLINT
|
||||
#include <readline/readline.h> // NOLINT
|
||||
#include <readline/history.h> // NOLINT
|
||||
|
||||
// The readline includes leaves RETURN defined which breaks V8 compilation.
|
||||
#undef RETURN
|
||||
|
||||
#include "src/d8.h"
|
||||
|
||||
// There are incompatibilities between different versions and different
|
||||
// implementations of readline. This smooths out one known incompatibility.
|
||||
#if RL_READLINE_VERSION >= 0x0500
|
||||
#define completion_matches rl_completion_matches
|
||||
#endif
|
||||
|
||||
|
||||
namespace v8 {
|
||||
|
||||
|
||||
class ReadLineEditor: public LineEditor {
|
||||
public:
|
||||
ReadLineEditor() : LineEditor(LineEditor::READLINE, "readline") { }
|
||||
virtual Local<String> Prompt(const char* prompt);
|
||||
virtual bool Open(Isolate* isolate);
|
||||
virtual bool Close();
|
||||
virtual void AddHistory(const char* str);
|
||||
|
||||
static const char* kHistoryFileName;
|
||||
static const int kMaxHistoryEntries;
|
||||
|
||||
private:
|
||||
#ifndef V8_SHARED
|
||||
static char** AttemptedCompletion(const char* text, int start, int end);
|
||||
static char* CompletionGenerator(const char* text, int state);
|
||||
#endif // V8_SHARED
|
||||
static char kWordBreakCharacters[];
|
||||
|
||||
Isolate* isolate_;
|
||||
};
|
||||
|
||||
|
||||
static ReadLineEditor read_line_editor;
|
||||
char ReadLineEditor::kWordBreakCharacters[] = {' ', '\t', '\n', '"',
|
||||
'\\', '\'', '`', '@', '.', '>', '<', '=', ';', '|', '&', '{', '(',
|
||||
'\0'};
|
||||
|
||||
|
||||
const char* ReadLineEditor::kHistoryFileName = ".d8_history";
|
||||
const int ReadLineEditor::kMaxHistoryEntries = 1000;
|
||||
|
||||
|
||||
bool ReadLineEditor::Open(Isolate* isolate) {
|
||||
isolate_ = isolate;
|
||||
|
||||
rl_initialize();
|
||||
|
||||
#ifdef V8_SHARED
|
||||
// Don't do completion on shared library mode
|
||||
// http://cnswww.cns.cwru.edu/php/chet/readline/readline.html#SEC24
|
||||
rl_bind_key('\t', rl_insert);
|
||||
#else
|
||||
rl_attempted_completion_function = AttemptedCompletion;
|
||||
#endif // V8_SHARED
|
||||
|
||||
rl_completer_word_break_characters = kWordBreakCharacters;
|
||||
rl_bind_key('\t', rl_complete);
|
||||
using_history();
|
||||
stifle_history(kMaxHistoryEntries);
|
||||
return read_history(kHistoryFileName) == 0;
|
||||
}
|
||||
|
||||
|
||||
bool ReadLineEditor::Close() {
|
||||
return write_history(kHistoryFileName) == 0;
|
||||
}
|
||||
|
||||
|
||||
Local<String> ReadLineEditor::Prompt(const char* prompt) {
|
||||
char* result = NULL;
|
||||
result = readline(prompt);
|
||||
if (result == NULL) return Local<String>();
|
||||
AddHistory(result);
|
||||
return String::NewFromUtf8(isolate_, result, NewStringType::kNormal)
|
||||
.ToLocalChecked();
|
||||
}
|
||||
|
||||
|
||||
void ReadLineEditor::AddHistory(const char* str) {
|
||||
// Do not record empty input.
|
||||
if (strlen(str) == 0) return;
|
||||
// Remove duplicate history entry.
|
||||
history_set_pos(history_length-1);
|
||||
if (current_history()) {
|
||||
do {
|
||||
if (strcmp(current_history()->line, str) == 0) {
|
||||
remove_history(where_history());
|
||||
break;
|
||||
}
|
||||
} while (previous_history());
|
||||
}
|
||||
add_history(str);
|
||||
}
|
||||
|
||||
|
||||
#ifndef V8_SHARED
|
||||
char** ReadLineEditor::AttemptedCompletion(const char* text,
|
||||
int start,
|
||||
int end) {
|
||||
char** result = completion_matches(text, CompletionGenerator);
|
||||
rl_attempted_completion_over = true;
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
char* ReadLineEditor::CompletionGenerator(const char* text, int state) {
|
||||
static unsigned current_index;
|
||||
static Global<Array> current_completions;
|
||||
Isolate* isolate = read_line_editor.isolate_;
|
||||
HandleScope scope(isolate);
|
||||
Local<Array> completions;
|
||||
if (state == 0) {
|
||||
Local<String> full_text =
|
||||
String::NewFromUtf8(isolate, rl_line_buffer, NewStringType::kNormal,
|
||||
rl_point)
|
||||
.ToLocalChecked();
|
||||
completions = Shell::GetCompletions(
|
||||
isolate, String::NewFromUtf8(isolate, text, NewStringType::kNormal)
|
||||
.ToLocalChecked(),
|
||||
full_text);
|
||||
current_completions.Reset(isolate, completions);
|
||||
current_index = 0;
|
||||
} else {
|
||||
completions = Local<Array>::New(isolate, current_completions);
|
||||
}
|
||||
if (current_index < completions->Length()) {
|
||||
Local<Context> context(isolate->GetCurrentContext());
|
||||
Local<Integer> index = Integer::New(isolate, current_index);
|
||||
Local<Value> str_obj = completions->Get(context, index).ToLocalChecked();
|
||||
current_index++;
|
||||
String::Utf8Value str(str_obj);
|
||||
return strdup(*str);
|
||||
} else {
|
||||
current_completions.Reset();
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
#endif // V8_SHARED
|
||||
|
||||
|
||||
} // namespace v8
|
69
src/d8.cc
69
src/d8.cc
@ -167,37 +167,6 @@ class PerIsolateData {
|
||||
};
|
||||
|
||||
|
||||
LineEditor *LineEditor::current_ = NULL;
|
||||
|
||||
|
||||
LineEditor::LineEditor(Type type, const char* name)
|
||||
: type_(type), name_(name) {
|
||||
if (current_ == NULL || current_->type_ < type) current_ = this;
|
||||
}
|
||||
|
||||
|
||||
class DumbLineEditor: public LineEditor {
|
||||
public:
|
||||
explicit DumbLineEditor(Isolate* isolate)
|
||||
: LineEditor(LineEditor::DUMB, "dumb"), isolate_(isolate) { }
|
||||
virtual Local<String> Prompt(const char* prompt);
|
||||
|
||||
private:
|
||||
Isolate* isolate_;
|
||||
};
|
||||
|
||||
|
||||
Local<String> DumbLineEditor::Prompt(const char* prompt) {
|
||||
printf("%s", prompt);
|
||||
#if defined(__native_client__)
|
||||
// Native Client libc is used to being embedded in Chrome and
|
||||
// has trouble recognizing when to flush.
|
||||
fflush(stdout);
|
||||
#endif
|
||||
return Shell::ReadFromStdin(isolate_);
|
||||
}
|
||||
|
||||
|
||||
#ifndef V8_SHARED
|
||||
CounterMap* Shell::counter_map_;
|
||||
base::OS::MemoryMappedFile* Shell::counters_file_ = NULL;
|
||||
@ -216,7 +185,6 @@ i::List<SharedArrayBuffer::Contents> Shell::externalized_shared_contents_;
|
||||
Global<Context> Shell::evaluation_context_;
|
||||
ArrayBuffer::Allocator* Shell::array_buffer_allocator;
|
||||
ShellOptions Shell::options;
|
||||
const char* Shell::kPrompt = "d8> ";
|
||||
base::OnceType Shell::quit_once_ = V8_ONCE_INIT;
|
||||
|
||||
#ifndef V8_SHARED
|
||||
@ -919,28 +887,6 @@ void Shell::ReportException(Isolate* isolate, v8::TryCatch* try_catch) {
|
||||
|
||||
|
||||
#ifndef V8_SHARED
|
||||
Local<Array> Shell::GetCompletions(Isolate* isolate, Local<String> text,
|
||||
Local<String> full) {
|
||||
EscapableHandleScope handle_scope(isolate);
|
||||
v8::Local<v8::Context> utility_context =
|
||||
v8::Local<v8::Context>::New(isolate, utility_context_);
|
||||
v8::Context::Scope context_scope(utility_context);
|
||||
Local<Object> global = utility_context->Global();
|
||||
Local<Value> fun = global->Get(utility_context,
|
||||
String::NewFromUtf8(isolate, "GetCompletions",
|
||||
NewStringType::kNormal)
|
||||
.ToLocalChecked()).ToLocalChecked();
|
||||
static const int kArgc = 3;
|
||||
v8::Local<v8::Context> evaluation_context =
|
||||
v8::Local<v8::Context>::New(isolate, evaluation_context_);
|
||||
Local<Value> argv[kArgc] = {evaluation_context->Global(), text, full};
|
||||
Local<Value> val = Local<Function>::Cast(fun)
|
||||
->Call(utility_context, global, kArgc, argv)
|
||||
.ToLocalChecked();
|
||||
return handle_scope.Escape(Local<Array>::Cast(val));
|
||||
}
|
||||
|
||||
|
||||
int32_t* Counter::Bind(const char* name, bool is_histogram) {
|
||||
int i;
|
||||
for (i = 0; i < kMaxNameSize - 1 && name[i]; i++)
|
||||
@ -1285,8 +1231,6 @@ inline bool operator<(const CounterAndKey& lhs, const CounterAndKey& rhs) {
|
||||
|
||||
|
||||
void Shell::OnExit(v8::Isolate* isolate) {
|
||||
LineEditor* line_editor = LineEditor::Get();
|
||||
if (line_editor) line_editor->Close();
|
||||
#ifndef V8_SHARED
|
||||
reinterpret_cast<i::Isolate*>(isolate)->DumpAndResetCompilationStats();
|
||||
if (i::FLAG_dump_counters) {
|
||||
@ -1444,12 +1388,16 @@ void Shell::RunShell(Isolate* isolate) {
|
||||
Local<String> name =
|
||||
String::NewFromUtf8(isolate, "(d8)", NewStringType::kNormal)
|
||||
.ToLocalChecked();
|
||||
LineEditor* console = LineEditor::Get();
|
||||
printf("V8 version %s [console: %s]\n", V8::GetVersion(), console->name());
|
||||
console->Open(isolate);
|
||||
printf("V8 version %s\n", V8::GetVersion());
|
||||
while (true) {
|
||||
HandleScope inner_scope(isolate);
|
||||
Local<String> input = console->Prompt(Shell::kPrompt);
|
||||
printf(" d8>");
|
||||
#if defined(__native_client__)
|
||||
// Native Client libc is used to being embedded in Chrome and
|
||||
// has trouble recognizing when to flush.
|
||||
fflush(stdout);
|
||||
#endif
|
||||
Local<String> input = Shell::ReadFromStdin(isolate);
|
||||
if (input.IsEmpty()) break;
|
||||
ExecuteString(isolate, input, name, true, true);
|
||||
}
|
||||
@ -2434,7 +2382,6 @@ int Shell::Main(int argc, char* argv[]) {
|
||||
}
|
||||
#endif
|
||||
Isolate* isolate = Isolate::New(create_params);
|
||||
DumbLineEditor dumb_line_editor(isolate);
|
||||
{
|
||||
Isolate::Scope scope(isolate);
|
||||
Initialize(isolate);
|
||||
|
@ -28,7 +28,6 @@
|
||||
{
|
||||
'variables': {
|
||||
'v8_code': 1,
|
||||
'console%': '',
|
||||
# Enable support for Intel VTune. Supported on ia32/x64 only
|
||||
'v8_enable_vtunejit%': 0,
|
||||
'v8_enable_i18n_support%': 1,
|
||||
@ -61,10 +60,6 @@
|
||||
[ 'want_separate_host_toolset==1', {
|
||||
'toolsets': [ '<(v8_toolset_for_d8)', ],
|
||||
}],
|
||||
[ 'console=="readline"', {
|
||||
'libraries': [ '-lreadline', ],
|
||||
'sources': [ 'd8-readline.cc' ],
|
||||
}],
|
||||
['(OS=="linux" or OS=="mac" or OS=="freebsd" or OS=="netbsd" \
|
||||
or OS=="openbsd" or OS=="solaris" or OS=="android" \
|
||||
or OS=="qnx" or OS=="aix")', {
|
||||
|
22
src/d8.h
22
src/d8.h
@ -93,26 +93,6 @@ class CounterMap {
|
||||
#endif // !V8_SHARED
|
||||
|
||||
|
||||
class LineEditor {
|
||||
public:
|
||||
enum Type { DUMB = 0, READLINE = 1 };
|
||||
LineEditor(Type type, const char* name);
|
||||
virtual ~LineEditor() { }
|
||||
|
||||
virtual Local<String> Prompt(const char* prompt) = 0;
|
||||
virtual bool Open(Isolate* isolate) { return true; }
|
||||
virtual bool Close() { return true; }
|
||||
virtual void AddHistory(const char* str) { }
|
||||
|
||||
const char* name() { return name_; }
|
||||
static LineEditor* Get() { return current_; }
|
||||
private:
|
||||
Type type_;
|
||||
const char* name_;
|
||||
static LineEditor* current_;
|
||||
};
|
||||
|
||||
|
||||
class SourceGroup {
|
||||
public:
|
||||
SourceGroup() :
|
||||
@ -380,8 +360,6 @@ class Shell : public i::AllStatic {
|
||||
const SerializationData& data,
|
||||
int* offset);
|
||||
static void CleanupWorkers();
|
||||
static Local<Array> GetCompletions(Isolate* isolate, Local<String> text,
|
||||
Local<String> full);
|
||||
static int* LookupCounter(const char* name);
|
||||
static void* CreateHistogram(const char* name,
|
||||
int min,
|
||||
|
45
src/d8.js
45
src/d8.js
@ -4,51 +4,6 @@
|
||||
|
||||
"use strict";
|
||||
|
||||
String.prototype.startsWith = function (str) {
|
||||
if (str.length > this.length) {
|
||||
return false;
|
||||
}
|
||||
return this.substr(0, str.length) == str;
|
||||
};
|
||||
|
||||
function ToInspectableObject(obj) {
|
||||
if (!obj && typeof obj === 'object') {
|
||||
return UNDEFINED;
|
||||
} else {
|
||||
return Object(obj);
|
||||
}
|
||||
}
|
||||
|
||||
function GetCompletions(global, last, full) {
|
||||
var full_tokens = full.split();
|
||||
full = full_tokens.pop();
|
||||
var parts = full.split('.');
|
||||
parts.pop();
|
||||
var current = global;
|
||||
for (var i = 0; i < parts.length; i++) {
|
||||
var part = parts[i];
|
||||
var next = current[part];
|
||||
if (!next) {
|
||||
return [];
|
||||
}
|
||||
current = next;
|
||||
}
|
||||
var result = [];
|
||||
current = ToInspectableObject(current);
|
||||
while (typeof current !== 'undefined') {
|
||||
var mirror = new $debug.ObjectMirror(current);
|
||||
var properties = mirror.properties();
|
||||
for (var i = 0; i < properties.length; i++) {
|
||||
var name = properties[i].name();
|
||||
if (typeof name === 'string' && name.startsWith(last)) {
|
||||
result.push(name);
|
||||
}
|
||||
}
|
||||
current = ToInspectableObject(Object.getPrototypeOf(current));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
// A more universal stringify that supports more types than JSON.
|
||||
// Used by the d8 shell to output results.
|
||||
var stringifyDepthLimit = 4; // To avoid crashing on cyclic objects
|
||||
|
Loading…
Reference in New Issue
Block a user