2012-01-11 14:42:58 +00:00
|
|
|
// Copyright 2012 the V8 project authors. All rights reserved.
|
2014-04-29 06:42:26 +00:00
|
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
|
|
// found in the LICENSE file.
|
2008-10-21 09:12:27 +00:00
|
|
|
|
|
|
|
#ifndef V8_D8_H_
|
|
|
|
#define V8_D8_H_
|
|
|
|
|
2011-08-08 09:34:18 +00:00
|
|
|
#ifndef V8_SHARED
|
2014-06-03 08:12:43 +00:00
|
|
|
#include "src/allocation.h"
|
|
|
|
#include "src/hashmap.h"
|
|
|
|
#include "src/smart-pointers.h"
|
|
|
|
#include "src/v8.h"
|
2011-07-14 15:43:40 +00:00
|
|
|
#else
|
2014-06-03 08:12:43 +00:00
|
|
|
#include "include/v8.h"
|
2014-09-02 07:23:55 +00:00
|
|
|
#include "src/base/compiler-specific.h"
|
2014-04-25 11:00:37 +00:00
|
|
|
#endif // !V8_SHARED
|
2008-10-21 09:12:27 +00:00
|
|
|
|
|
|
|
namespace v8 {
|
|
|
|
|
|
|
|
|
2011-08-08 09:34:18 +00:00
|
|
|
#ifndef V8_SHARED
|
2008-12-03 09:35:21 +00:00
|
|
|
// A single counter in a counter collection.
|
2008-10-21 09:12:27 +00:00
|
|
|
class Counter {
|
|
|
|
public:
|
2008-12-03 09:35:21 +00:00
|
|
|
static const int kMaxNameSize = 64;
|
2009-04-14 00:30:44 +00:00
|
|
|
int32_t* Bind(const char* name, bool histogram);
|
|
|
|
int32_t* ptr() { return &count_; }
|
|
|
|
int32_t count() { return count_; }
|
|
|
|
int32_t sample_total() { return sample_total_; }
|
|
|
|
bool is_histogram() { return is_histogram_; }
|
|
|
|
void AddSample(int32_t sample);
|
2008-10-21 09:12:27 +00:00
|
|
|
private:
|
2009-04-14 00:30:44 +00:00
|
|
|
int32_t count_;
|
|
|
|
int32_t sample_total_;
|
|
|
|
bool is_histogram_;
|
2008-12-03 09:35:21 +00:00
|
|
|
uint8_t name_[kMaxNameSize];
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// A set of counters and associated information. An instance of this
|
|
|
|
// class is stored directly in the memory-mapped counters file if
|
|
|
|
// the --map-counters options is used
|
|
|
|
class CounterCollection {
|
|
|
|
public:
|
|
|
|
CounterCollection();
|
|
|
|
Counter* GetNextCounter();
|
|
|
|
private:
|
2012-07-13 12:22:09 +00:00
|
|
|
static const unsigned kMaxCounters = 512;
|
2008-12-03 09:35:21 +00:00
|
|
|
uint32_t magic_number_;
|
|
|
|
uint32_t max_counters_;
|
|
|
|
uint32_t max_name_size_;
|
|
|
|
uint32_t counters_in_use_;
|
|
|
|
Counter counters_[kMaxCounters];
|
2008-10-21 09:12:27 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2009-03-24 13:33:54 +00:00
|
|
|
class CounterMap {
|
|
|
|
public:
|
|
|
|
CounterMap(): hash_map_(Match) { }
|
|
|
|
Counter* Lookup(const char* name) {
|
|
|
|
i::HashMap::Entry* answer = hash_map_.Lookup(
|
|
|
|
const_cast<char*>(name),
|
|
|
|
Hash(name),
|
|
|
|
false);
|
|
|
|
if (!answer) return NULL;
|
|
|
|
return reinterpret_cast<Counter*>(answer->value);
|
|
|
|
}
|
|
|
|
void Set(const char* name, Counter* value) {
|
|
|
|
i::HashMap::Entry* answer = hash_map_.Lookup(
|
|
|
|
const_cast<char*>(name),
|
|
|
|
Hash(name),
|
|
|
|
true);
|
2014-08-04 11:34:54 +00:00
|
|
|
DCHECK(answer != NULL);
|
2009-03-24 13:33:54 +00:00
|
|
|
answer->value = value;
|
|
|
|
}
|
|
|
|
class Iterator {
|
|
|
|
public:
|
2009-03-24 14:29:49 +00:00
|
|
|
explicit Iterator(CounterMap* map)
|
|
|
|
: map_(&map->hash_map_), entry_(map_->Start()) { }
|
2009-03-24 13:33:54 +00:00
|
|
|
void Next() { entry_ = map_->Next(entry_); }
|
|
|
|
bool More() { return entry_ != NULL; }
|
|
|
|
const char* CurrentKey() { return static_cast<const char*>(entry_->key); }
|
|
|
|
Counter* CurrentValue() { return static_cast<Counter*>(entry_->value); }
|
|
|
|
private:
|
|
|
|
i::HashMap* map_;
|
|
|
|
i::HashMap::Entry* entry_;
|
|
|
|
};
|
2011-06-07 07:17:46 +00:00
|
|
|
|
2009-03-24 13:33:54 +00:00
|
|
|
private:
|
|
|
|
static int Hash(const char* name);
|
|
|
|
static bool Match(void* key1, void* key2);
|
|
|
|
i::HashMap hash_map_;
|
|
|
|
};
|
2014-04-25 11:00:37 +00:00
|
|
|
#endif // !V8_SHARED
|
2009-03-24 13:33:54 +00:00
|
|
|
|
|
|
|
|
2011-09-14 14:39:56 +00:00
|
|
|
class LineEditor {
|
|
|
|
public:
|
|
|
|
enum Type { DUMB = 0, READLINE = 1 };
|
|
|
|
LineEditor(Type type, const char* name);
|
|
|
|
virtual ~LineEditor() { }
|
|
|
|
|
2012-01-17 13:37:09 +00:00
|
|
|
virtual Handle<String> Prompt(const char* prompt) = 0;
|
2013-03-12 08:00:20 +00:00
|
|
|
virtual bool Open(Isolate* isolate) { return true; }
|
2011-09-14 14:39:56 +00:00
|
|
|
virtual bool Close() { return true; }
|
|
|
|
virtual void AddHistory(const char* str) { }
|
|
|
|
|
|
|
|
const char* name() { return name_; }
|
2013-02-28 17:40:24 +00:00
|
|
|
static LineEditor* Get() { return current_; }
|
2011-09-14 14:39:56 +00:00
|
|
|
private:
|
|
|
|
Type type_;
|
|
|
|
const char* name_;
|
2013-02-28 17:40:24 +00:00
|
|
|
static LineEditor* current_;
|
2011-09-14 14:39:56 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2011-07-11 07:38:09 +00:00
|
|
|
class SourceGroup {
|
|
|
|
public:
|
2011-07-14 15:43:40 +00:00
|
|
|
SourceGroup() :
|
2011-08-08 09:34:18 +00:00
|
|
|
#ifndef V8_SHARED
|
2013-09-02 12:26:06 +00:00
|
|
|
next_semaphore_(0),
|
|
|
|
done_semaphore_(0),
|
2011-09-08 22:44:03 +00:00
|
|
|
thread_(NULL),
|
2014-04-25 11:00:37 +00:00
|
|
|
#endif // !V8_SHARED
|
2011-07-14 15:43:40 +00:00
|
|
|
argv_(NULL),
|
|
|
|
begin_offset_(0),
|
2011-09-08 13:51:06 +00:00
|
|
|
end_offset_(0) {}
|
2011-07-11 07:38:09 +00:00
|
|
|
|
2011-09-08 22:44:03 +00:00
|
|
|
~SourceGroup();
|
|
|
|
|
2011-07-11 07:38:09 +00:00
|
|
|
void Begin(char** argv, int offset) {
|
|
|
|
argv_ = const_cast<const char**>(argv);
|
|
|
|
begin_offset_ = offset;
|
|
|
|
}
|
|
|
|
|
|
|
|
void End(int offset) { end_offset_ = offset; }
|
|
|
|
|
2012-11-20 14:47:56 +00:00
|
|
|
void Execute(Isolate* isolate);
|
2011-07-11 07:38:09 +00:00
|
|
|
|
2011-08-08 09:34:18 +00:00
|
|
|
#ifndef V8_SHARED
|
2011-07-11 07:38:09 +00:00
|
|
|
void StartExecuteInThread();
|
|
|
|
void WaitForThread();
|
|
|
|
|
|
|
|
private:
|
2014-06-30 13:25:46 +00:00
|
|
|
class IsolateThread : public base::Thread {
|
2011-07-11 07:38:09 +00:00
|
|
|
public:
|
|
|
|
explicit IsolateThread(SourceGroup* group)
|
2014-06-30 13:25:46 +00:00
|
|
|
: base::Thread(GetThreadOptions()), group_(group) {}
|
2011-07-11 07:38:09 +00:00
|
|
|
|
|
|
|
virtual void Run() {
|
|
|
|
group_->ExecuteInThread();
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
SourceGroup* group_;
|
|
|
|
};
|
|
|
|
|
2014-06-30 13:25:46 +00:00
|
|
|
static base::Thread::Options GetThreadOptions();
|
2011-07-11 07:38:09 +00:00
|
|
|
void ExecuteInThread();
|
|
|
|
|
2014-06-30 13:25:46 +00:00
|
|
|
base::Semaphore next_semaphore_;
|
|
|
|
base::Semaphore done_semaphore_;
|
|
|
|
base::Thread* thread_;
|
2014-04-25 11:00:37 +00:00
|
|
|
#endif // !V8_SHARED
|
2011-07-11 07:38:09 +00:00
|
|
|
|
|
|
|
void ExitShell(int exit_code);
|
2012-11-20 14:47:56 +00:00
|
|
|
Handle<String> ReadFile(Isolate* isolate, const char* name);
|
2011-07-11 07:38:09 +00:00
|
|
|
|
|
|
|
const char** argv_;
|
|
|
|
int begin_offset_;
|
|
|
|
int end_offset_;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2014-09-10 12:38:12 +00:00
|
|
|
class BinaryResource : public v8::String::ExternalOneByteStringResource {
|
2012-01-24 11:55:11 +00:00
|
|
|
public:
|
|
|
|
BinaryResource(const char* string, int length)
|
|
|
|
: data_(string),
|
|
|
|
length_(length) { }
|
|
|
|
|
|
|
|
~BinaryResource() {
|
|
|
|
delete[] data_;
|
|
|
|
data_ = NULL;
|
|
|
|
length_ = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual const char* data() const { return data_; }
|
|
|
|
virtual size_t length() const { return length_; }
|
|
|
|
|
|
|
|
private:
|
|
|
|
const char* data_;
|
|
|
|
size_t length_;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2011-07-11 07:38:09 +00:00
|
|
|
class ShellOptions {
|
|
|
|
public:
|
Change ScriptCompiler::CompileOptions to allow for two 'cache' modes
(parser or code) and to be explicit about cache consumption or production
(rather than making presence of cached_data imply one or the other.)
Also add a --cache flag to d8, to allow testing the functionality.
-----------------------------
API change
Reason: Currently, V8 supports a 'parser cache' for repeatedly executing the same script. We'd like to add a 2nd mode that would cache code, and would like to let the embedder decide which mode they chose (if any).
Note: Previously, the 'use cached data' property was implied by the presence of the cached data itself. (That is, kNoCompileOptions and source->cached_data != NULL.) That is no longer sufficient, since the presence of data is no longer sufficient to determine /which kind/ of data is present.
Changes from old behaviour:
- If you previously didn't use caching, nothing changes.
Example:
v8::CompileUnbound(isolate, source, kNoCompileOptions);
- If you previously used caching, it worked like this:
- 1st run:
v8::CompileUnbound(isolate, source, kProduceToCache);
Then, source->cached_data would contain the
data-to-be cached. This remains the same, except you
need to tell V8 which type of data you want.
v8::CompileUnbound(isolate, source, kProduceParserCache);
- 2nd run:
v8::CompileUnbound(isolate, source, kNoCompileOptions);
with source->cached_data set to the data you received in
the first run. This will now ignore the cached data, and
you need to explicitly tell V8 to use it:
v8::CompileUnbound(isolate, source, kConsumeParserCache);
-----------------------------
BUG=
R=marja@chromium.org, yangguo@chromium.org
Review URL: https://codereview.chromium.org/389573006
git-svn-id: https://v8.googlecode.com/svn/branches/bleeding_edge@22431 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
2014-07-16 12:18:33 +00:00
|
|
|
ShellOptions()
|
|
|
|
: script_executed(false),
|
|
|
|
last_run(true),
|
|
|
|
send_idle_notification(false),
|
|
|
|
invoke_weak_callbacks(false),
|
|
|
|
stress_opt(false),
|
|
|
|
stress_deopt(false),
|
|
|
|
interactive_shell(false),
|
|
|
|
test_shell(false),
|
|
|
|
dump_heap_constants(false),
|
|
|
|
expected_to_throw(false),
|
|
|
|
mock_arraybuffer_allocator(false),
|
|
|
|
num_isolates(1),
|
|
|
|
compile_options(v8::ScriptCompiler::kNoCompileOptions),
|
|
|
|
isolate_sources(NULL),
|
|
|
|
icu_data_file(NULL),
|
|
|
|
natives_blob(NULL),
|
|
|
|
snapshot_blob(NULL) {}
|
2011-07-14 15:43:40 +00:00
|
|
|
|
2011-09-13 13:16:13 +00:00
|
|
|
~ShellOptions() {
|
|
|
|
delete[] isolate_sources;
|
|
|
|
}
|
2011-09-13 09:31:41 +00:00
|
|
|
|
2014-05-27 07:19:32 +00:00
|
|
|
bool use_interactive_shell() {
|
|
|
|
return (interactive_shell || !script_executed) && !test_shell;
|
|
|
|
}
|
|
|
|
|
2011-07-11 07:38:09 +00:00
|
|
|
bool script_executed;
|
|
|
|
bool last_run;
|
2012-08-20 13:19:52 +00:00
|
|
|
bool send_idle_notification;
|
2014-05-27 15:16:42 +00:00
|
|
|
bool invoke_weak_callbacks;
|
2011-07-11 07:38:09 +00:00
|
|
|
bool stress_opt;
|
|
|
|
bool stress_deopt;
|
|
|
|
bool interactive_shell;
|
|
|
|
bool test_shell;
|
2013-08-02 09:02:02 +00:00
|
|
|
bool dump_heap_constants;
|
2013-10-04 16:21:23 +00:00
|
|
|
bool expected_to_throw;
|
2013-11-18 14:50:45 +00:00
|
|
|
bool mock_arraybuffer_allocator;
|
2011-07-11 07:38:09 +00:00
|
|
|
int num_isolates;
|
Change ScriptCompiler::CompileOptions to allow for two 'cache' modes
(parser or code) and to be explicit about cache consumption or production
(rather than making presence of cached_data imply one or the other.)
Also add a --cache flag to d8, to allow testing the functionality.
-----------------------------
API change
Reason: Currently, V8 supports a 'parser cache' for repeatedly executing the same script. We'd like to add a 2nd mode that would cache code, and would like to let the embedder decide which mode they chose (if any).
Note: Previously, the 'use cached data' property was implied by the presence of the cached data itself. (That is, kNoCompileOptions and source->cached_data != NULL.) That is no longer sufficient, since the presence of data is no longer sufficient to determine /which kind/ of data is present.
Changes from old behaviour:
- If you previously didn't use caching, nothing changes.
Example:
v8::CompileUnbound(isolate, source, kNoCompileOptions);
- If you previously used caching, it worked like this:
- 1st run:
v8::CompileUnbound(isolate, source, kProduceToCache);
Then, source->cached_data would contain the
data-to-be cached. This remains the same, except you
need to tell V8 which type of data you want.
v8::CompileUnbound(isolate, source, kProduceParserCache);
- 2nd run:
v8::CompileUnbound(isolate, source, kNoCompileOptions);
with source->cached_data set to the data you received in
the first run. This will now ignore the cached data, and
you need to explicitly tell V8 to use it:
v8::CompileUnbound(isolate, source, kConsumeParserCache);
-----------------------------
BUG=
R=marja@chromium.org, yangguo@chromium.org
Review URL: https://codereview.chromium.org/389573006
git-svn-id: https://v8.googlecode.com/svn/branches/bleeding_edge@22431 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
2014-07-16 12:18:33 +00:00
|
|
|
v8::ScriptCompiler::CompileOptions compile_options;
|
2011-07-11 07:38:09 +00:00
|
|
|
SourceGroup* isolate_sources;
|
2014-03-25 12:05:33 +00:00
|
|
|
const char* icu_data_file;
|
2014-06-23 13:52:17 +00:00
|
|
|
const char* natives_blob;
|
|
|
|
const char* snapshot_blob;
|
2011-07-11 07:38:09 +00:00
|
|
|
};
|
|
|
|
|
2011-08-08 09:34:18 +00:00
|
|
|
#ifdef V8_SHARED
|
2011-07-14 15:43:40 +00:00
|
|
|
class Shell {
|
|
|
|
#else
|
|
|
|
class Shell : public i::AllStatic {
|
2011-08-08 09:34:18 +00:00
|
|
|
#endif // V8_SHARED
|
2011-09-08 19:57:14 +00:00
|
|
|
|
2008-10-21 09:12:27 +00:00
|
|
|
public:
|
2015-02-10 19:11:44 +00:00
|
|
|
enum SourceType { SCRIPT, MODULE };
|
|
|
|
|
|
|
|
static Local<Script> CompileString(
|
Change ScriptCompiler::CompileOptions to allow for two 'cache' modes
(parser or code) and to be explicit about cache consumption or production
(rather than making presence of cached_data imply one or the other.)
Also add a --cache flag to d8, to allow testing the functionality.
-----------------------------
API change
Reason: Currently, V8 supports a 'parser cache' for repeatedly executing the same script. We'd like to add a 2nd mode that would cache code, and would like to let the embedder decide which mode they chose (if any).
Note: Previously, the 'use cached data' property was implied by the presence of the cached data itself. (That is, kNoCompileOptions and source->cached_data != NULL.) That is no longer sufficient, since the presence of data is no longer sufficient to determine /which kind/ of data is present.
Changes from old behaviour:
- If you previously didn't use caching, nothing changes.
Example:
v8::CompileUnbound(isolate, source, kNoCompileOptions);
- If you previously used caching, it worked like this:
- 1st run:
v8::CompileUnbound(isolate, source, kProduceToCache);
Then, source->cached_data would contain the
data-to-be cached. This remains the same, except you
need to tell V8 which type of data you want.
v8::CompileUnbound(isolate, source, kProduceParserCache);
- 2nd run:
v8::CompileUnbound(isolate, source, kNoCompileOptions);
with source->cached_data set to the data you received in
the first run. This will now ignore the cached data, and
you need to explicitly tell V8 to use it:
v8::CompileUnbound(isolate, source, kConsumeParserCache);
-----------------------------
BUG=
R=marja@chromium.org, yangguo@chromium.org
Review URL: https://codereview.chromium.org/389573006
git-svn-id: https://v8.googlecode.com/svn/branches/bleeding_edge@22431 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
2014-07-16 12:18:33 +00:00
|
|
|
Isolate* isolate, Local<String> source, Local<Value> name,
|
2015-02-10 19:11:44 +00:00
|
|
|
v8::ScriptCompiler::CompileOptions compile_options,
|
|
|
|
SourceType source_type);
|
|
|
|
static bool ExecuteString(Isolate* isolate, Handle<String> source,
|
|
|
|
Handle<Value> name, bool print_result,
|
|
|
|
bool report_exceptions,
|
|
|
|
SourceType source_type = SCRIPT);
|
2010-04-16 12:19:47 +00:00
|
|
|
static const char* ToCString(const v8::String::Utf8Value& value);
|
2013-03-15 12:06:53 +00:00
|
|
|
static void ReportException(Isolate* isolate, TryCatch* try_catch);
|
2012-11-20 14:47:56 +00:00
|
|
|
static Handle<String> ReadFile(Isolate* isolate, const char* name);
|
2013-05-08 07:45:16 +00:00
|
|
|
static Local<Context> CreateEvaluationContext(Isolate* isolate);
|
2012-11-20 14:47:56 +00:00
|
|
|
static int RunMain(Isolate* isolate, int argc, char* argv[]);
|
2011-07-14 15:43:40 +00:00
|
|
|
static int Main(int argc, char* argv[]);
|
2011-09-13 13:16:13 +00:00
|
|
|
static void Exit(int exit_code);
|
2014-11-21 09:53:04 +00:00
|
|
|
static void OnExit(Isolate* isolate);
|
2011-07-14 15:43:40 +00:00
|
|
|
|
2011-08-08 09:34:18 +00:00
|
|
|
#ifndef V8_SHARED
|
2013-03-15 12:06:53 +00:00
|
|
|
static Handle<Array> GetCompletions(Isolate* isolate,
|
|
|
|
Handle<String> text,
|
2011-07-14 15:43:40 +00:00
|
|
|
Handle<String> full);
|
2008-12-01 07:40:43 +00:00
|
|
|
static int* LookupCounter(const char* name);
|
2009-04-14 00:30:44 +00:00
|
|
|
static void* CreateHistogram(const char* name,
|
|
|
|
int min,
|
|
|
|
int max,
|
|
|
|
size_t buckets);
|
|
|
|
static void AddHistogramSample(void* histogram, int sample);
|
2014-07-07 07:19:46 +00:00
|
|
|
static void MapCounters(v8::Isolate* isolate, const char* name);
|
2011-07-14 15:43:40 +00:00
|
|
|
|
2014-01-09 13:57:09 +00:00
|
|
|
static Local<Object> DebugMessageDetails(Isolate* isolate,
|
|
|
|
Handle<String> message);
|
|
|
|
static Local<Value> DebugCommandToJSONRequest(Isolate* isolate,
|
|
|
|
Handle<String> command);
|
2014-01-10 12:07:29 +00:00
|
|
|
|
|
|
|
static void PerformanceNow(const v8::FunctionCallbackInfo<v8::Value>& args);
|
2014-04-25 11:00:37 +00:00
|
|
|
#endif // !V8_SHARED
|
2013-10-24 11:59:09 +00:00
|
|
|
|
2013-06-05 12:36:33 +00:00
|
|
|
static void RealmCurrent(const v8::FunctionCallbackInfo<v8::Value>& args);
|
|
|
|
static void RealmOwner(const v8::FunctionCallbackInfo<v8::Value>& args);
|
|
|
|
static void RealmGlobal(const v8::FunctionCallbackInfo<v8::Value>& args);
|
|
|
|
static void RealmCreate(const v8::FunctionCallbackInfo<v8::Value>& args);
|
|
|
|
static void RealmDispose(const v8::FunctionCallbackInfo<v8::Value>& args);
|
|
|
|
static void RealmSwitch(const v8::FunctionCallbackInfo<v8::Value>& args);
|
|
|
|
static void RealmEval(const v8::FunctionCallbackInfo<v8::Value>& args);
|
|
|
|
static void RealmSharedGet(Local<String> property,
|
|
|
|
const PropertyCallbackInfo<Value>& info);
|
2013-04-22 11:29:52 +00:00
|
|
|
static void RealmSharedSet(Local<String> property,
|
|
|
|
Local<Value> value,
|
2013-06-05 12:36:33 +00:00
|
|
|
const PropertyCallbackInfo<void>& info);
|
|
|
|
|
|
|
|
static void Print(const v8::FunctionCallbackInfo<v8::Value>& args);
|
|
|
|
static void Write(const v8::FunctionCallbackInfo<v8::Value>& args);
|
|
|
|
static void Quit(const v8::FunctionCallbackInfo<v8::Value>& args);
|
|
|
|
static void Version(const v8::FunctionCallbackInfo<v8::Value>& args);
|
|
|
|
static void Read(const v8::FunctionCallbackInfo<v8::Value>& args);
|
|
|
|
static void ReadBuffer(const v8::FunctionCallbackInfo<v8::Value>& args);
|
2012-11-20 14:47:56 +00:00
|
|
|
static Handle<String> ReadFromStdin(Isolate* isolate);
|
2013-06-05 12:36:33 +00:00
|
|
|
static void ReadLine(const v8::FunctionCallbackInfo<v8::Value>& args) {
|
|
|
|
args.GetReturnValue().Set(ReadFromStdin(args.GetIsolate()));
|
2012-01-17 13:37:09 +00:00
|
|
|
}
|
2013-06-05 12:36:33 +00:00
|
|
|
static void Load(const v8::FunctionCallbackInfo<v8::Value>& args);
|
|
|
|
static void ArrayBuffer(const v8::FunctionCallbackInfo<v8::Value>& args);
|
|
|
|
static void Int8Array(const v8::FunctionCallbackInfo<v8::Value>& args);
|
|
|
|
static void Uint8Array(const v8::FunctionCallbackInfo<v8::Value>& args);
|
|
|
|
static void Int16Array(const v8::FunctionCallbackInfo<v8::Value>& args);
|
|
|
|
static void Uint16Array(const v8::FunctionCallbackInfo<v8::Value>& args);
|
|
|
|
static void Int32Array(const v8::FunctionCallbackInfo<v8::Value>& args);
|
|
|
|
static void Uint32Array(const v8::FunctionCallbackInfo<v8::Value>& args);
|
|
|
|
static void Float32Array(const v8::FunctionCallbackInfo<v8::Value>& args);
|
|
|
|
static void Float64Array(const v8::FunctionCallbackInfo<v8::Value>& args);
|
|
|
|
static void Uint8ClampedArray(
|
|
|
|
const v8::FunctionCallbackInfo<v8::Value>& args);
|
|
|
|
static void ArrayBufferSlice(const v8::FunctionCallbackInfo<v8::Value>& args);
|
|
|
|
static void ArraySubArray(const v8::FunctionCallbackInfo<v8::Value>& args);
|
|
|
|
static void ArraySet(const v8::FunctionCallbackInfo<v8::Value>& args);
|
2009-03-31 06:51:25 +00:00
|
|
|
// The OS object on the global object contains methods for performing
|
|
|
|
// operating system calls:
|
|
|
|
//
|
|
|
|
// os.system("program_name", ["arg1", "arg2", ...], timeout1, timeout2) will
|
|
|
|
// run the command, passing the arguments to the program. The standard output
|
|
|
|
// of the program will be picked up and returned as a multiline string. If
|
2009-03-27 13:50:26 +00:00
|
|
|
// timeout1 is present then it should be a number. -1 indicates no timeout
|
|
|
|
// and a positive number is used as a timeout in milliseconds that limits the
|
|
|
|
// time spent waiting between receiving output characters from the program.
|
|
|
|
// timeout2, if present, should be a number indicating the limit in
|
|
|
|
// milliseconds on the total running time of the program. Exceptions are
|
|
|
|
// thrown on timeouts or other errors or if the exit status of the program
|
|
|
|
// indicates an error.
|
2009-03-31 06:51:25 +00:00
|
|
|
//
|
|
|
|
// os.chdir(dir) changes directory to the given directory. Throws an
|
|
|
|
// exception/ on error.
|
|
|
|
//
|
|
|
|
// os.setenv(variable, value) sets an environment variable. Repeated calls to
|
|
|
|
// this method leak memory due to the API of setenv in the standard C library.
|
2009-03-31 12:45:33 +00:00
|
|
|
//
|
|
|
|
// os.umask(alue) calls the umask system call and returns the old umask.
|
|
|
|
//
|
|
|
|
// os.mkdirp(name, mask) creates a directory. The mask (if present) is anded
|
|
|
|
// with the current umask. Intermediate directories are created if necessary.
|
|
|
|
// An exception is not thrown if the directory already exists. Analogous to
|
|
|
|
// the "mkdir -p" command.
|
2013-06-05 12:36:33 +00:00
|
|
|
static void OSObject(const v8::FunctionCallbackInfo<v8::Value>& args);
|
|
|
|
static void System(const v8::FunctionCallbackInfo<v8::Value>& args);
|
|
|
|
static void ChangeDirectory(const v8::FunctionCallbackInfo<v8::Value>& args);
|
|
|
|
static void SetEnvironment(const v8::FunctionCallbackInfo<v8::Value>& args);
|
|
|
|
static void UnsetEnvironment(const v8::FunctionCallbackInfo<v8::Value>& args);
|
|
|
|
static void SetUMask(const v8::FunctionCallbackInfo<v8::Value>& args);
|
|
|
|
static void MakeDirectory(const v8::FunctionCallbackInfo<v8::Value>& args);
|
|
|
|
static void RemoveDirectory(const v8::FunctionCallbackInfo<v8::Value>& args);
|
2009-03-31 12:45:33 +00:00
|
|
|
|
2013-11-22 12:35:39 +00:00
|
|
|
static void AddOSMethods(v8::Isolate* isolate,
|
|
|
|
Handle<ObjectTemplate> os_template);
|
2012-01-17 13:37:09 +00:00
|
|
|
|
2008-10-21 09:12:27 +00:00
|
|
|
static const char* kPrompt;
|
2011-07-11 07:38:09 +00:00
|
|
|
static ShellOptions options;
|
|
|
|
|
2008-10-21 09:12:27 +00:00
|
|
|
private:
|
|
|
|
static Persistent<Context> evaluation_context_;
|
2011-08-08 09:34:18 +00:00
|
|
|
#ifndef V8_SHARED
|
2011-07-14 15:43:40 +00:00
|
|
|
static Persistent<Context> utility_context_;
|
2009-03-24 13:33:54 +00:00
|
|
|
static CounterMap* counter_map_;
|
2008-12-03 09:35:21 +00:00
|
|
|
// We statically allocate a set of local counters to be used if we
|
|
|
|
// don't want to store the stats in a memory-mapped file
|
|
|
|
static CounterCollection local_counters_;
|
|
|
|
static CounterCollection* counters_;
|
2014-06-30 13:25:46 +00:00
|
|
|
static base::OS::MemoryMappedFile* counters_file_;
|
|
|
|
static base::Mutex context_mutex_;
|
|
|
|
static const base::TimeTicks kInitialTicks;
|
2011-07-14 15:43:40 +00:00
|
|
|
|
2009-04-14 00:30:44 +00:00
|
|
|
static Counter* GetCounter(const char* name, bool is_histogram);
|
2013-01-18 07:20:17 +00:00
|
|
|
static void InstallUtilityScript(Isolate* isolate);
|
2014-04-25 11:00:37 +00:00
|
|
|
#endif // !V8_SHARED
|
2012-11-20 14:47:56 +00:00
|
|
|
static void Initialize(Isolate* isolate);
|
2012-11-22 08:35:21 +00:00
|
|
|
static void InitializeDebugger(Isolate* isolate);
|
2012-11-20 14:47:56 +00:00
|
|
|
static void RunShell(Isolate* isolate);
|
2011-07-14 15:43:40 +00:00
|
|
|
static bool SetOptions(int argc, char* argv[]);
|
2012-11-20 14:47:56 +00:00
|
|
|
static Handle<ObjectTemplate> CreateGlobalTemplate(Isolate* isolate);
|
2013-08-27 11:47:52 +00:00
|
|
|
static Handle<FunctionTemplate> CreateArrayBufferTemplate(FunctionCallback);
|
|
|
|
static Handle<FunctionTemplate> CreateArrayTemplate(FunctionCallback);
|
2012-11-20 14:47:56 +00:00
|
|
|
static Handle<Value> CreateExternalArrayBuffer(Isolate* isolate,
|
|
|
|
Handle<Object> buffer,
|
2012-06-28 16:29:53 +00:00
|
|
|
int32_t size);
|
2012-11-20 14:47:56 +00:00
|
|
|
static Handle<Object> CreateExternalArray(Isolate* isolate,
|
|
|
|
Handle<Object> array,
|
2012-06-28 16:29:53 +00:00
|
|
|
Handle<Object> buffer,
|
|
|
|
ExternalArrayType type,
|
|
|
|
int32_t length,
|
|
|
|
int32_t byteLength,
|
|
|
|
int32_t byteOffset,
|
|
|
|
int32_t element_size);
|
2013-06-05 12:36:33 +00:00
|
|
|
static void CreateExternalArray(
|
|
|
|
const v8::FunctionCallbackInfo<v8::Value>& args,
|
|
|
|
ExternalArrayType type,
|
|
|
|
int32_t element_size);
|
2013-01-25 08:31:46 +00:00
|
|
|
static void ExternalArrayWeakCallback(Isolate* isolate,
|
2013-05-07 10:44:30 +00:00
|
|
|
Persistent<Object>* object,
|
|
|
|
uint8_t* data);
|
2008-10-21 09:12:27 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
} // namespace v8
|
|
|
|
|
|
|
|
|
|
|
|
#endif // V8_D8_H_
|