V8 Project
v8::Shell Class Reference

#include <d8.h>

+ Inheritance diagram for v8::Shell:
+ Collaboration diagram for v8::Shell:

Static Public Member Functions

static Local< UnboundScriptCompileString (Isolate *isolate, Local< String > source, Local< Value > name, v8::ScriptCompiler::CompileOptions compile_options)
 
static bool ExecuteString (Isolate *isolate, Handle< String > source, Handle< Value > name, bool print_result, bool report_exceptions)
 
static const char * ToCString (const v8::String::Utf8Value &value)
 
static void ReportException (Isolate *isolate, TryCatch *try_catch)
 
static Handle< StringReadFile (Isolate *isolate, const char *name)
 
static Local< ContextCreateEvaluationContext (Isolate *isolate)
 
static int RunMain (Isolate *isolate, int argc, char *argv[])
 
static int Main (int argc, char *argv[])
 
static void Exit (int exit_code)
 
static void OnExit ()
 
static Handle< ArrayGetCompletions (Isolate *isolate, Handle< String > text, Handle< String > full)
 
static intLookupCounter (const char *name)
 
static void * CreateHistogram (const char *name, int min, int max, size_t buckets)
 
static void AddHistogramSample (void *histogram, int sample)
 
static void MapCounters (v8::Isolate *isolate, const char *name)
 
static Local< ObjectDebugMessageDetails (Isolate *isolate, Handle< String > message)
 
static Local< ValueDebugCommandToJSONRequest (Isolate *isolate, Handle< String > command)
 
static void PerformanceNow (const v8::FunctionCallbackInfo< v8::Value > &args)
 
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)
 
static void RealmSharedSet (Local< String > property, Local< Value > value, 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)
 
static Handle< StringReadFromStdin (Isolate *isolate)
 
static void ReadLine (const v8::FunctionCallbackInfo< v8::Value > &args)
 
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)
 
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)
 
static void AddOSMethods (v8::Isolate *isolate, Handle< ObjectTemplate > os_template)
 

Static Public Attributes

static const char * kPrompt = "d8> "
 
static ShellOptions options
 

Static Private Member Functions

static CounterGetCounter (const char *name, bool is_histogram)
 
static void InstallUtilityScript (Isolate *isolate)
 
static void Initialize (Isolate *isolate)
 
static void InitializeDebugger (Isolate *isolate)
 
static void RunShell (Isolate *isolate)
 
static bool SetOptions (int argc, char *argv[])
 
static Handle< ObjectTemplateCreateGlobalTemplate (Isolate *isolate)
 
static Handle< FunctionTemplateCreateArrayBufferTemplate (FunctionCallback)
 
static Handle< FunctionTemplateCreateArrayTemplate (FunctionCallback)
 
static Handle< ValueCreateExternalArrayBuffer (Isolate *isolate, Handle< Object > buffer, int32_t size)
 
static Handle< ObjectCreateExternalArray (Isolate *isolate, Handle< Object > array, Handle< Object > buffer, ExternalArrayType type, int32_t length, int32_t byteLength, int32_t byteOffset, int32_t element_size)
 
static void CreateExternalArray (const v8::FunctionCallbackInfo< v8::Value > &args, ExternalArrayType type, int32_t element_size)
 
static void ExternalArrayWeakCallback (Isolate *isolate, Persistent< Object > *object, uint8_t *data)
 

Static Private Attributes

static Persistent< Contextevaluation_context_
 
static Persistent< Contextutility_context_
 
static CounterMapcounter_map_
 
static CounterCollection local_counters_
 
static CounterCollectioncounters_ = &local_counters_
 
static base::OS::MemoryMappedFilecounters_file_ = NULL
 
static base::Mutex context_mutex_
 
static const base::TimeTicks kInitialTicks
 

Detailed Description

Definition at line 247 of file d8.h.

Member Function Documentation

◆ AddHistogramSample()

void v8::Shell::AddHistogramSample ( void *  histogram,
int  sample 
)
static

Definition at line 781 of file d8.cc.

781  {
782  Counter* counter = reinterpret_cast<Counter*>(histogram);
783  counter->AddSample(sample);
784 }

References v8::Counter::AddSample().

+ Here is the call graph for this function:

◆ AddOSMethods()

void v8::Shell::AddOSMethods ( v8::Isolate isolate,
Handle< ObjectTemplate os_template 
)
static

Definition at line 709 of file d8-posix.cc.

709  {
710  os_templ->Set(String::NewFromUtf8(isolate, "system"),
711  FunctionTemplate::New(isolate, System));
712  os_templ->Set(String::NewFromUtf8(isolate, "chdir"),
714  os_templ->Set(String::NewFromUtf8(isolate, "setenv"),
716  os_templ->Set(String::NewFromUtf8(isolate, "unsetenv"),
718  os_templ->Set(String::NewFromUtf8(isolate, "umask"),
719  FunctionTemplate::New(isolate, SetUMask));
720  os_templ->Set(String::NewFromUtf8(isolate, "mkdirp"),
722  os_templ->Set(String::NewFromUtf8(isolate, "rmdir"),
724 }
static Local< FunctionTemplate > New(Isolate *isolate, FunctionCallback callback=0, Handle< Value > data=Handle< Value >(), Handle< Signature > signature=Handle< Signature >(), int length=0)
Creates a function template.
Definition: api.cc:904
static void SetEnvironment(const v8::FunctionCallbackInfo< v8::Value > &args)
Definition: d8-posix.cc:663
static void MakeDirectory(const v8::FunctionCallbackInfo< v8::Value > &args)
Definition: d8-posix.cc:617
static void ChangeDirectory(const v8::FunctionCallbackInfo< v8::Value > &args)
Definition: d8-posix.cc:527
static void System(const v8::FunctionCallbackInfo< v8::Value > &args)
Definition: d8-posix.cc:440
static void UnsetEnvironment(const v8::FunctionCallbackInfo< v8::Value > &args)
Definition: d8-posix.cc:690
static void RemoveDirectory(const v8::FunctionCallbackInfo< v8::Value > &args)
Definition: d8-posix.cc:645
static void SetUMask(const v8::FunctionCallbackInfo< v8::Value > &args)
Definition: d8-posix.cc:549
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

References ChangeDirectory(), MakeDirectory(), v8::FunctionTemplate::New(), v8::String::NewFromUtf8(), RemoveDirectory(), SetEnvironment(), SetUMask(), System(), and UnsetEnvironment().

+ Here is the call graph for this function:

◆ ArrayBuffer()

static void v8::Shell::ArrayBuffer ( const v8::FunctionCallbackInfo< v8::Value > &  args)
static

◆ ArrayBufferSlice()

static void v8::Shell::ArrayBufferSlice ( const v8::FunctionCallbackInfo< v8::Value > &  args)
static

◆ ArraySet()

static void v8::Shell::ArraySet ( const v8::FunctionCallbackInfo< v8::Value > &  args)
static

◆ ArraySubArray()

static void v8::Shell::ArraySubArray ( const v8::FunctionCallbackInfo< v8::Value > &  args)
static

◆ ChangeDirectory()

void v8::Shell::ChangeDirectory ( const v8::FunctionCallbackInfo< v8::Value > &  args)
static

Definition at line 527 of file d8-posix.cc.

527  {
528  if (args.Length() != 1) {
529  const char* message = "chdir() takes one argument";
530  args.GetIsolate()->ThrowException(
531  String::NewFromUtf8(args.GetIsolate(), message));
532  return;
533  }
534  String::Utf8Value directory(args[0]);
535  if (*directory == NULL) {
536  const char* message = "os.chdir(): String conversion of argument failed.";
537  args.GetIsolate()->ThrowException(
538  String::NewFromUtf8(args.GetIsolate(), message));
539  return;
540  }
541  if (chdir(*directory) != 0) {
542  args.GetIsolate()->ThrowException(
543  String::NewFromUtf8(args.GetIsolate(), strerror(errno)));
544  return;
545  }
546 }
Isolate * GetIsolate() const
Definition: v8.h:6342
int Length() const
Definition: v8.h:6360
Local< Value > ThrowException(Local< Value > exception)
Schedules an exception to be thrown when returning to JavaScript.
Definition: api.cc:6411
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

References v8::FunctionCallbackInfo< T >::GetIsolate(), v8::FunctionCallbackInfo< T >::Length(), v8::String::NewFromUtf8(), NULL, and v8::Isolate::ThrowException().

Referenced by AddOSMethods().

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

◆ CompileString()

Local< UnboundScript > v8::Shell::CompileString ( Isolate isolate,
Local< String source,
Local< Value name,
v8::ScriptCompiler::CompileOptions  compile_options 
)
static

Definition at line 181 of file d8.cc.

183  {
184  ScriptOrigin origin(name);
185  ScriptCompiler::Source script_source(source, origin);
186  Local<UnboundScript> script =
187  ScriptCompiler::CompileUnbound(isolate, &script_source, compile_options);
188 
189  // Was caching requested & successful? Then compile again, now with cache.
190  if (script_source.GetCachedData()) {
191  if (compile_options == ScriptCompiler::kProduceCodeCache) {
192  compile_options = ScriptCompiler::kConsumeCodeCache;
193  } else if (compile_options == ScriptCompiler::kProduceParserCache) {
194  compile_options = ScriptCompiler::kConsumeParserCache;
195  } else {
196  DCHECK(false); // A new compile option?
197  }
198  ScriptCompiler::Source cached_source(
199  source, origin, new v8::ScriptCompiler::CachedData(
200  script_source.GetCachedData()->data,
201  script_source.GetCachedData()->length,
203  script = ScriptCompiler::CompileUnbound(isolate, &cached_source,
204  compile_options);
205  }
206  return script;
207 }
@ kProduceParserCache
Definition: v8.h:1161
@ kConsumeParserCache
Definition: v8.h:1162
@ kProduceCodeCache
Definition: v8.h:1163
@ kConsumeCodeCache
Definition: v8.h:1164
static Local< UnboundScript > CompileUnbound(Isolate *isolate, Source *source, CompileOptions options=kNoCompileOptions)
Compiles the specified script (context-independent).
Definition: api.cc:1703
#define DCHECK(condition)
Definition: d8.cc:66
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 expose gc extension under the specified name show built in functions in stack traces use random jit cookie to mask large constants minimum length for automatic enable preparsing CPU profiler sampling interval in microseconds trace out of bounds accesses to external arrays default size of stack region v8 is allowed to maximum length of function source code printed in a stack trace min size of a semi the new space consists of two semi spaces print one trace line following each garbage collection do not print trace line after scavenger collection print cumulative GC statistics in name
Compilation data that the embedder can cache and pass back to speed up future compilations.
Definition: v8.h:1028

References v8::ScriptCompiler::CachedData::BufferNotOwned, v8::ScriptCompiler::CompileUnbound(), v8::ScriptCompiler::CachedData::data, DCHECK, v8::ScriptCompiler::Source::GetCachedData(), v8::ScriptCompiler::kConsumeCodeCache, v8::ScriptCompiler::kConsumeParserCache, v8::ScriptCompiler::kProduceCodeCache, v8::ScriptCompiler::kProduceParserCache, v8::ScriptCompiler::CachedData::length, and name.

Referenced by ExecuteString().

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

◆ CreateArrayBufferTemplate()

static Handle<FunctionTemplate> v8::Shell::CreateArrayBufferTemplate ( FunctionCallback  )
staticprivate

◆ CreateArrayTemplate()

static Handle<FunctionTemplate> v8::Shell::CreateArrayTemplate ( FunctionCallback  )
staticprivate

◆ CreateEvaluationContext()

Local< Context > v8::Shell::CreateEvaluationContext ( Isolate isolate)
static

Definition at line 960 of file d8.cc.

960  {
961 #ifndef V8_SHARED
962  // This needs to be a critical section since this is not thread-safe
963  base::LockGuard<base::Mutex> lock_guard(&context_mutex_);
964 #endif // !V8_SHARED
965  // Initialize the global objects
966  Handle<ObjectTemplate> global_template = CreateGlobalTemplate(isolate);
967  EscapableHandleScope handle_scope(isolate);
968  Local<Context> context = Context::New(isolate, NULL, global_template);
969  DCHECK(!context.IsEmpty());
970  Context::Scope scope(context);
971 
972 #ifndef V8_SHARED
973  i::Factory* factory = reinterpret_cast<i::Isolate*>(isolate)->factory();
974  i::JSArguments js_args = i::FLAG_js_arguments;
975  i::Handle<i::FixedArray> arguments_array =
976  factory->NewFixedArray(js_args.argc);
977  for (int j = 0; j < js_args.argc; j++) {
979  factory->NewStringFromUtf8(i::CStrVector(js_args[j])).ToHandleChecked();
980  arguments_array->set(j, *arg);
981  }
982  i::Handle<i::JSArray> arguments_jsarray =
983  factory->NewJSArrayWithElements(arguments_array);
984  context->Global()->Set(String::NewFromUtf8(isolate, "arguments"),
985  Utils::ToLocal(arguments_jsarray));
986 #endif // !V8_SHARED
987  return handle_scope.Escape(context);
988 }
static Local< Context > New(Isolate *isolate, ExtensionConfiguration *extensions=NULL, Handle< ObjectTemplate > global_template=Handle< ObjectTemplate >(), Handle< Value > global_object=Handle< Value >())
Creates a new context and returns a handle to the newly allocated context.
Definition: api.cc:5217
static base::Mutex context_mutex_
Definition: d8.h:377
static Handle< ObjectTemplate > CreateGlobalTemplate(Isolate *isolate)
Definition: d8.cc:870
static Local< Context > ToLocal(v8::internal::Handle< v8::internal::Context > obj)
Vector< const char > CStrVector(const char *data)
Definition: vector.h:158

References v8::internal::CStrVector(), DCHECK, v8::EscapableHandleScope::Escape(), v8::Handle< T >::IsEmpty(), v8::Context::New(), v8::String::NewFromUtf8(), NULL, and v8::Utils::ToLocal().

Referenced by v8::SourceGroup::ExecuteInThread().

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

◆ CreateExternalArray() [1/2]

static void v8::Shell::CreateExternalArray ( const v8::FunctionCallbackInfo< v8::Value > &  args,
ExternalArrayType  type,
int32_t  element_size 
)
staticprivate

◆ CreateExternalArray() [2/2]

static Handle<Object> v8::Shell::CreateExternalArray ( Isolate isolate,
Handle< Object array,
Handle< Object buffer,
ExternalArrayType  type,
int32_t  length,
int32_t  byteLength,
int32_t  byteOffset,
int32_t  element_size 
)
staticprivate

◆ CreateExternalArrayBuffer()

static Handle<Value> v8::Shell::CreateExternalArrayBuffer ( Isolate isolate,
Handle< Object buffer,
int32_t  size 
)
staticprivate

◆ CreateGlobalTemplate()

Handle< ObjectTemplate > v8::Shell::CreateGlobalTemplate ( Isolate isolate)
staticprivate

Definition at line 870 of file d8.cc.

870  {
871  Handle<ObjectTemplate> global_template = ObjectTemplate::New(isolate);
872  global_template->Set(String::NewFromUtf8(isolate, "print"),
873  FunctionTemplate::New(isolate, Print));
874  global_template->Set(String::NewFromUtf8(isolate, "write"),
875  FunctionTemplate::New(isolate, Write));
876  global_template->Set(String::NewFromUtf8(isolate, "read"),
877  FunctionTemplate::New(isolate, Read));
878  global_template->Set(String::NewFromUtf8(isolate, "readbuffer"),
880  global_template->Set(String::NewFromUtf8(isolate, "readline"),
881  FunctionTemplate::New(isolate, ReadLine));
882  global_template->Set(String::NewFromUtf8(isolate, "load"),
883  FunctionTemplate::New(isolate, Load));
884  global_template->Set(String::NewFromUtf8(isolate, "quit"),
885  FunctionTemplate::New(isolate, Quit));
886  global_template->Set(String::NewFromUtf8(isolate, "version"),
887  FunctionTemplate::New(isolate, Version));
888 
889  // Bind the Realm object.
890  Handle<ObjectTemplate> realm_template = ObjectTemplate::New(isolate);
891  realm_template->Set(String::NewFromUtf8(isolate, "current"),
893  realm_template->Set(String::NewFromUtf8(isolate, "owner"),
895  realm_template->Set(String::NewFromUtf8(isolate, "global"),
897  realm_template->Set(String::NewFromUtf8(isolate, "create"),
899  realm_template->Set(String::NewFromUtf8(isolate, "dispose"),
901  realm_template->Set(String::NewFromUtf8(isolate, "switch"),
903  realm_template->Set(String::NewFromUtf8(isolate, "eval"),
904  FunctionTemplate::New(isolate, RealmEval));
905  realm_template->SetAccessor(String::NewFromUtf8(isolate, "shared"),
907  global_template->Set(String::NewFromUtf8(isolate, "Realm"), realm_template);
908 
909 #ifndef V8_SHARED
910  Handle<ObjectTemplate> performance_template = ObjectTemplate::New(isolate);
911  performance_template->Set(String::NewFromUtf8(isolate, "now"),
913  global_template->Set(String::NewFromUtf8(isolate, "performance"),
914  performance_template);
915 #endif // !V8_SHARED
916 
917  Handle<ObjectTemplate> os_templ = ObjectTemplate::New(isolate);
918  AddOSMethods(isolate, os_templ);
919  global_template->Set(String::NewFromUtf8(isolate, "os"), os_templ);
920 
921  return global_template;
922 }
static Local< ObjectTemplate > New()
Definition: api.cc:1244
static void Read(const v8::FunctionCallbackInfo< v8::Value > &args)
Definition: d8.cc:501
static void Quit(const v8::FunctionCallbackInfo< v8::Value > &args)
Definition: d8.cc:574
static void RealmSharedGet(Local< String > property, const PropertyCallbackInfo< Value > &info)
Definition: d8.cc:452
static void PerformanceNow(const v8::FunctionCallbackInfo< v8::Value > &args)
Definition: d8.cc:337
static void RealmEval(const v8::FunctionCallbackInfo< v8::Value > &args)
Definition: d8.cc:430
static void RealmCreate(const v8::FunctionCallbackInfo< v8::Value > &args)
Definition: d8.cc:387
static void ReadBuffer(const v8::FunctionCallbackInfo< v8::Value > &args)
Definition: d8.cc:1115
static void ReadLine(const v8::FunctionCallbackInfo< v8::Value > &args)
Definition: d8.h:308
static void Version(const v8::FunctionCallbackInfo< v8::Value > &args)
Definition: d8.cc:581
static void Print(const v8::FunctionCallbackInfo< v8::Value > &args)
Definition: d8.cc:469
static void RealmSharedSet(Local< String > property, Local< Value > value, const PropertyCallbackInfo< void > &info)
Definition: d8.cc:460
static void RealmDispose(const v8::FunctionCallbackInfo< v8::Value > &args)
Definition: d8.cc:405
static void AddOSMethods(v8::Isolate *isolate, Handle< ObjectTemplate > os_template)
Definition: d8-posix.cc:709
static void RealmCurrent(const v8::FunctionCallbackInfo< v8::Value > &args)
Definition: d8.cc:352
static void RealmOwner(const v8::FunctionCallbackInfo< v8::Value > &args)
Definition: d8.cc:362
static void RealmSwitch(const v8::FunctionCallbackInfo< v8::Value > &args)
Definition: d8.cc:420
static void Load(const v8::FunctionCallbackInfo< v8::Value > &args)
Definition: d8.cc:549
static void RealmGlobal(const v8::FunctionCallbackInfo< v8::Value > &args)
Definition: d8.cc:377
static void Write(const v8::FunctionCallbackInfo< v8::Value > &args)
Definition: d8.cc:476

References v8::ObjectTemplate::New(), v8::FunctionTemplate::New(), v8::String::NewFromUtf8(), and v8::internal::ReadLine().

+ Here is the call graph for this function:

◆ CreateHistogram()

void * v8::Shell::CreateHistogram ( const char *  name,
int  min,
int  max,
size_t  buckets 
)
static

Definition at line 773 of file d8.cc.

776  {
777  return GetCounter(name, true);
778 }
static Counter * GetCounter(const char *name, bool is_histogram)
Definition: d8.cc:746

References name.

◆ DebugCommandToJSONRequest()

Local< Value > v8::Shell::DebugCommandToJSONRequest ( Isolate isolate,
Handle< String command 
)
static

Definition at line 673 of file d8.cc.

674  {
675  EscapableHandleScope handle_scope(isolate);
676  v8::Local<v8::Context> context =
678  v8::Context::Scope context_scope(context);
679  Handle<Object> global = context->Global();
680  Handle<Value> fun =
681  global->Get(String::NewFromUtf8(isolate, "DebugCommandToJSONRequest"));
682  static const int kArgc = 1;
683  Handle<Value> argv[kArgc] = { command };
684  Handle<Value> val = Handle<Function>::Cast(fun)->Call(global, kArgc, argv);
685  return handle_scope.Escape(Local<Value>(val));
686 }
Stack-allocated class which sets the execution context for all operations executed within a local sco...
Definition: v8.h:5579
static Handle< T > Cast(Handle< S > that)
Definition: v8.h:277
static Local< T > New(Isolate *isolate, Handle< T > that)
Create a local handle for the content of another handle.
Definition: v8.h:5987
static Persistent< Context > utility_context_
Definition: d8.h:370

References v8::Handle< T >::Cast(), v8::EscapableHandleScope::Escape(), v8::Local< T >::New(), and v8::String::NewFromUtf8().

Referenced by v8::HandleDebugEvent().

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

◆ DebugMessageDetails()

Local< Object > v8::Shell::DebugMessageDetails ( Isolate isolate,
Handle< String message 
)
static

Definition at line 657 of file d8.cc.

658  {
659  EscapableHandleScope handle_scope(isolate);
660  v8::Local<v8::Context> context =
662  v8::Context::Scope context_scope(context);
663  Handle<Object> global = context->Global();
664  Handle<Value> fun =
665  global->Get(String::NewFromUtf8(isolate, "DebugMessageDetails"));
666  static const int kArgc = 1;
667  Handle<Value> argv[kArgc] = { message };
668  Handle<Value> val = Handle<Function>::Cast(fun)->Call(global, kArgc, argv);
669  return handle_scope.Escape(Local<Object>(Handle<Object>::Cast(val)));
670 }

References v8::Handle< T >::Cast(), v8::EscapableHandleScope::Escape(), v8::Local< T >::New(), and v8::String::NewFromUtf8().

Referenced by v8::HandleDebugEvent().

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

◆ ExecuteString()

bool v8::Shell::ExecuteString ( Isolate isolate,
Handle< String source,
Handle< Value name,
bool  print_result,
bool  report_exceptions 
)
static

Definition at line 211 of file d8.cc.

215  {
216 #ifndef V8_SHARED
217  bool FLAG_debugger = i::FLAG_debugger;
218 #else
219  bool FLAG_debugger = false;
220 #endif // !V8_SHARED
221  HandleScope handle_scope(isolate);
222  TryCatch try_catch;
223  options.script_executed = true;
224  if (FLAG_debugger) {
225  // When debugging make exceptions appear to be uncaught.
226  try_catch.SetVerbose(true);
227  }
228 
229  Handle<UnboundScript> script =
231  if (script.IsEmpty()) {
232  // Print errors that happened during compilation.
233  if (report_exceptions && !FLAG_debugger)
234  ReportException(isolate, &try_catch);
235  return false;
236  } else {
237  PerIsolateData* data = PerIsolateData::Get(isolate);
238  Local<Context> realm =
239  Local<Context>::New(isolate, data->realms_[data->realm_current_]);
240  realm->Enter();
241  Handle<Value> result = script->BindToCurrentContext()->Run();
242  realm->Exit();
243  data->realm_current_ = data->realm_switch_;
244  if (result.IsEmpty()) {
245  DCHECK(try_catch.HasCaught());
246  // Print errors that happened during execution.
247  if (report_exceptions && !FLAG_debugger)
248  ReportException(isolate, &try_catch);
249  return false;
250  } else {
251  DCHECK(!try_catch.HasCaught());
252  if (print_result) {
253 #if !defined(V8_SHARED)
254  if (options.test_shell) {
255 #endif
256  if (!result->IsUndefined()) {
257  // If all went well and the result wasn't undefined then print
258  // the returned value.
259  v8::String::Utf8Value str(result);
260  fwrite(*str, sizeof(**str), str.length(), stdout);
261  printf("\n");
262  }
263 #if !defined(V8_SHARED)
264  } else {
265  v8::TryCatch try_catch;
266  v8::Local<v8::Context> context =
268  v8::Context::Scope context_scope(context);
269  Handle<Object> global = context->Global();
270  Handle<Value> fun =
271  global->Get(String::NewFromUtf8(isolate, "Stringify"));
272  Handle<Value> argv[1] = { result };
273  Handle<Value> s = Handle<Function>::Cast(fun)->Call(global, 1, argv);
274  if (try_catch.HasCaught()) return true;
275  v8::String::Utf8Value str(s);
276  fwrite(*str, sizeof(**str), str.length(), stdout);
277  printf("\n");
278  }
279 #endif
280  }
281  return true;
282  }
283  }
284 }
static PerIsolateData * Get(Isolate *isolate)
Definition: d8.cc:89
bool script_executed
Definition: d8.h:225
v8::ScriptCompiler::CompileOptions compile_options
Definition: d8.h:237
bool test_shell
Definition: d8.h:232
static Local< UnboundScript > CompileString(Isolate *isolate, Local< String > source, Local< Value > name, v8::ScriptCompiler::CompileOptions compile_options)
Definition: d8.cc:181
static void ReportException(Isolate *isolate, TryCatch *try_catch)
Definition: d8.cc:587
static ShellOptions options
Definition: d8.h:365
Converts an object to a UTF-8-encoded character array.
Definition: v8.h:2048
An external exception handler.
Definition: v8.h:5271
bool HasCaught() const
Returns true if an exception has been caught by this try/catch block.
Definition: api.cc:1954

References v8::Handle< T >::Cast(), v8::ShellOptions::compile_options, CompileString(), DCHECK, v8::PerIsolateData::Get(), v8::TryCatch::HasCaught(), v8::Handle< T >::IsEmpty(), v8::String::Utf8Value::length(), name, v8::Local< T >::New(), v8::String::NewFromUtf8(), options, v8::PerIsolateData::realm_current_, v8::PerIsolateData::realm_switch_, v8::PerIsolateData::realms_, ReportException(), v8::ShellOptions::script_executed, v8::TryCatch::SetVerbose(), v8::ShellOptions::test_shell, and utility_context_.

Referenced by v8::SourceGroup::Execute().

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

◆ Exit()

void v8::Shell::Exit ( int  exit_code)
static

Definition at line 991 of file d8.cc.

991  {
992  // Use _exit instead of exit to avoid races between isolate
993  // threads and static destructors.
994  fflush(stdout);
995  fflush(stderr);
996  _exit(exit_code);
997 }

Referenced by v8::SourceGroup::Execute().

+ Here is the caller graph for this function:

◆ ExternalArrayWeakCallback()

static void v8::Shell::ExternalArrayWeakCallback ( Isolate isolate,
Persistent< Object > *  object,
uint8_t *  data 
)
staticprivate

◆ Float32Array()

static void v8::Shell::Float32Array ( const v8::FunctionCallbackInfo< v8::Value > &  args)
static

◆ Float64Array()

static void v8::Shell::Float64Array ( const v8::FunctionCallbackInfo< v8::Value > &  args)
static

◆ GetCompletions()

Handle< Array > v8::Shell::GetCompletions ( Isolate isolate,
Handle< String text,
Handle< String full 
)
static

Definition at line 638 of file d8.cc.

640  {
641  EscapableHandleScope handle_scope(isolate);
642  v8::Local<v8::Context> utility_context =
644  v8::Context::Scope context_scope(utility_context);
645  Handle<Object> global = utility_context->Global();
646  Local<Value> fun =
647  global->Get(String::NewFromUtf8(isolate, "GetCompletions"));
648  static const int kArgc = 3;
649  v8::Local<v8::Context> evaluation_context =
651  Handle<Value> argv[kArgc] = { evaluation_context->Global(), text, full };
652  Local<Value> val = Local<Function>::Cast(fun)->Call(global, kArgc, argv);
653  return handle_scope.Escape(Local<Array>::Cast(val));
654 }
static Local< T > Cast(Local< S > that)
Definition: v8.h:348
static Persistent< Context > evaluation_context_
Definition: d8.h:368

References v8::Local< T >::Cast(), v8::EscapableHandleScope::Escape(), v8::Local< T >::New(), and v8::String::NewFromUtf8().

Referenced by v8::ReadLineEditor::CompletionGenerator().

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

◆ GetCounter()

Counter * v8::Shell::GetCounter ( const char *  name,
bool  is_histogram 
)
staticprivate

Definition at line 746 of file d8.cc.

746  {
747  Counter* counter = counter_map_->Lookup(name);
748 
749  if (counter == NULL) {
750  counter = counters_->GetNextCounter();
751  if (counter != NULL) {
752  counter_map_->Set(name, counter);
753  counter->Bind(name, is_histogram);
754  }
755  } else {
756  DCHECK(counter->is_histogram() == is_histogram);
757  }
758  return counter;
759 }
Counter * GetNextCounter()
Definition: d8.cc:713
void Set(const char *name, Counter *value)
Definition: d8.h:68
Counter * Lookup(const char *name)
Definition: d8.h:60
static CounterCollection * counters_
Definition: d8.h:375
static CounterMap * counter_map_
Definition: d8.h:371

References v8::Counter::Bind(), DCHECK, v8::Counter::is_histogram(), name, and NULL.

+ Here is the call graph for this function:

◆ Initialize()

void v8::Shell::Initialize ( Isolate isolate)
staticprivate

Definition at line 925 of file d8.cc.

925  {
926 #ifdef COMPRESS_STARTUP_DATA_BZ2
927  BZip2Decompressor startup_data_decompressor;
928  int bz2_result = startup_data_decompressor.Decompress();
929  if (bz2_result != BZ_OK) {
930  fprintf(stderr, "bzip error code: %d\n", bz2_result);
931  Exit(1);
932  }
933 #endif
934 
935 #ifndef V8_SHARED
936  Shell::counter_map_ = new CounterMap();
937  // Set up counters
938  if (i::StrLength(i::FLAG_map_counters) != 0)
939  MapCounters(isolate, i::FLAG_map_counters);
940  if (i::FLAG_dump_counters || i::FLAG_track_gc_object_stats) {
941  isolate->SetCounterFunction(LookupCounter);
942  isolate->SetCreateHistogramFunction(CreateHistogram);
943  isolate->SetAddHistogramSampleFunction(AddHistogramSample);
944  }
945 #endif // !V8_SHARED
946 }
static void AddHistogramSample(void *histogram, int sample)
Definition: d8.cc:781
static void * CreateHistogram(const char *name, int min, int max, size_t buckets)
Definition: d8.cc:773
static void Exit(int exit_code)
Definition: d8.cc:991
static int * LookupCounter(const char *name)
Definition: d8.cc:762
static void MapCounters(v8::Isolate *isolate, const char *name)
Definition: d8.cc:719
int StrLength(const char *string)
Definition: vector.h:147

References counter_map_, v8::Isolate::SetAddHistogramSampleFunction(), v8::Isolate::SetCounterFunction(), v8::Isolate::SetCreateHistogramFunction(), and v8::internal::StrLength().

+ Here is the call graph for this function:

◆ InitializeDebugger()

void v8::Shell::InitializeDebugger ( Isolate isolate)
staticprivate

Definition at line 949 of file d8.cc.

949  {
950  if (options.test_shell) return;
951 #ifndef V8_SHARED
952  HandleScope scope(isolate);
953  Handle<ObjectTemplate> global_template = CreateGlobalTemplate(isolate);
954  utility_context_.Reset(isolate,
955  Context::New(isolate, NULL, global_template));
956 #endif // !V8_SHARED
957 }

References v8::Context::New(), and NULL.

+ Here is the call graph for this function:

◆ InstallUtilityScript()

void v8::Shell::InstallUtilityScript ( Isolate isolate)
staticprivate

Definition at line 787 of file d8.cc.

787  {
788  HandleScope scope(isolate);
789  // If we use the utility context, we have to set the security tokens so that
790  // utility, evaluation and debug context can all access each other.
791  v8::Local<v8::Context> utility_context =
793  v8::Local<v8::Context> evaluation_context =
795  utility_context->SetSecurityToken(Undefined(isolate));
796  evaluation_context->SetSecurityToken(Undefined(isolate));
797  v8::Context::Scope context_scope(utility_context);
798 
799  if (i::FLAG_debugger) printf("JavaScript debugger enabled\n");
800  // Install the debugger object in the utility scope
801  i::Debug* debug = reinterpret_cast<i::Isolate*>(isolate)->debug();
802  debug->Load();
803  i::Handle<i::Context> debug_context = debug->debug_context();
804  i::Handle<i::JSObject> js_debug
805  = i::Handle<i::JSObject>(debug_context->global_object());
806  utility_context->Global()->Set(String::NewFromUtf8(isolate, "$debug"),
807  Utils::ToLocal(js_debug));
808  debug_context->set_security_token(
809  reinterpret_cast<i::Isolate*>(isolate)->heap()->undefined_value());
810 
811  // Run the d8 shell utility script in the utility context
812  int source_index = i::NativesCollection<i::D8>::GetIndex("d8");
813  i::Vector<const char> shell_source =
815  i::Vector<const char> shell_source_name =
817  Handle<String> source =
818  String::NewFromUtf8(isolate, shell_source.start(), String::kNormalString,
819  shell_source.length());
820  Handle<String> name =
821  String::NewFromUtf8(isolate, shell_source_name.start(),
822  String::kNormalString, shell_source_name.length());
823  ScriptOrigin origin(name);
824  Handle<Script> script = Script::Compile(source, &origin);
825  script->Run();
826  // Mark the d8 shell script as native to avoid it showing up as normal source
827  // in the debugger.
828  i::Handle<i::Object> compiled_script = Utils::OpenHandle(*script);
829  i::Handle<i::Script> script_object = compiled_script->IsJSFunction()
830  ? i::Handle<i::Script>(i::Script::cast(
831  i::JSFunction::cast(*compiled_script)->shared()->script()))
832  : i::Handle<i::Script>(i::Script::cast(
833  i::SharedFunctionInfo::cast(*compiled_script)->script()));
834  script_object->set_type(i::Smi::FromInt(i::Script::TYPE_NATIVE));
835 
836  // Start the in-process debugger if requested.
837  if (i::FLAG_debugger) v8::Debug::SetDebugEventListener(HandleDebugEvent);
838 }
static bool SetDebugEventListener(EventCallback that, Handle< Value > data=Handle< Value >())
Definition: api.cc:6917
static Local< Script > Compile(Handle< String > source, ScriptOrigin *origin=NULL)
A shorthand for ScriptCompiler::Compile().
Definition: api.cc:1880
@ kNormalString
Definition: v8.h:1963
static v8::internal::Handle< To > OpenHandle(v8::Local< From > handle)
Definition: api.h:288
Handle< Context > debug_context()
Definition: debug.h:459
static Vector< const char > GetScriptName(int index)
static Vector< const char > GetRawScriptSource(int index)
static int GetIndex(const char *name)
static Smi * FromInt(int value)
Definition: objects-inl.h:1321
T * start() const
Definition: vector.h:47
int length() const
Definition: vector.h:41
void HandleDebugEvent(const Debug::EventDetails &event_details)
Definition: d8-debug.cc:17
Handle< Primitive > Undefined(Isolate *isolate)
Definition: v8.h:6836

References v8::Script::Compile(), v8::internal::Debug::debug_context(), v8::internal::Smi::FromInt(), v8::internal::NativesCollection< type >::GetIndex(), v8::internal::NativesCollection< type >::GetRawScriptSource(), v8::internal::NativesCollection< type >::GetScriptName(), v8::HandleDebugEvent(), v8::String::kNormalString, v8::internal::Vector< T >::length(), v8::internal::Debug::Load(), name, v8::Local< T >::New(), v8::String::NewFromUtf8(), v8::Utils::OpenHandle(), v8::Debug::SetDebugEventListener(), v8::internal::Vector< T >::start(), v8::Utils::ToLocal(), v8::internal::Script::TYPE_NATIVE, and v8::Undefined().

+ Here is the call graph for this function:

◆ Int16Array()

static void v8::Shell::Int16Array ( const v8::FunctionCallbackInfo< v8::Value > &  args)
static

◆ Int32Array()

static void v8::Shell::Int32Array ( const v8::FunctionCallbackInfo< v8::Value > &  args)
static

◆ Int8Array()

static void v8::Shell::Int8Array ( const v8::FunctionCallbackInfo< v8::Value > &  args)
static

◆ Load()

void v8::Shell::Load ( const v8::FunctionCallbackInfo< v8::Value > &  args)
static

Definition at line 549 of file d8.cc.

549  {
550  for (int i = 0; i < args.Length(); i++) {
551  HandleScope handle_scope(args.GetIsolate());
552  String::Utf8Value file(args[i]);
553  if (*file == NULL) {
554  Throw(args.GetIsolate(), "Error loading file");
555  return;
556  }
557  Handle<String> source = ReadFile(args.GetIsolate(), *file);
558  if (source.IsEmpty()) {
559  Throw(args.GetIsolate(), "Error loading file");
560  return;
561  }
562  if (!ExecuteString(args.GetIsolate(),
563  source,
565  false,
566  true)) {
567  Throw(args.GetIsolate(), "Error executing file");
568  return;
569  }
570  }
571 }
static Handle< String > ReadFile(Isolate *isolate, const char *name)
Definition: d8.cc:1145
static bool ExecuteString(Isolate *isolate, Handle< String > source, Handle< Value > name, bool print_result, bool report_exceptions)
Definition: d8.cc:211
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 expose gc extension under the specified name show built in functions in stack traces use random jit cookie to mask large constants minimum length for automatic enable preparsing CPU profiler sampling interval in microseconds trace out of bounds accesses to external arrays default size of stack region v8 is allowed to maximum length of function source code printed in a stack trace min size of a semi the new space consists of two semi spaces print one trace line following each garbage collection do not print trace line after scavenger collection print cumulative GC statistics in only print modified registers Trace simulator debug messages Implied by trace sim abort randomize hashes to avoid predictable hash Fixed seed to use to hash property Print the time it takes to deserialize the snapshot A filename with extra code to be included in the A file to write the raw snapshot bytes A file to write the raw context snapshot bytes Write V8 startup blob file(mksnapshot only)") DEFINE_BOOL(profile_hydrogen_code_stub_compilation
static Handle< Value > Throw(Isolate *isolate, const char *message)
Definition: d8.cc:72

References file(), v8::FunctionCallbackInfo< T >::GetIsolate(), v8::Handle< T >::IsEmpty(), v8::FunctionCallbackInfo< T >::Length(), v8::String::NewFromUtf8(), NULL, v8::internal::ReadFile(), and v8::Throw().

+ Here is the call graph for this function:

◆ LookupCounter()

int * v8::Shell::LookupCounter ( const char *  name)
static

Definition at line 762 of file d8.cc.

762  {
763  Counter* counter = GetCounter(name, false);
764 
765  if (counter != NULL) {
766  return counter->ptr();
767  } else {
768  return NULL;
769  }
770 }

References name, NULL, and v8::Counter::ptr().

+ Here is the call graph for this function:

◆ Main()

int v8::Shell::Main ( int  argc,
char *  argv[] 
)
static

Definition at line 1603 of file d8.cc.

1603  {
1604 #if (defined(_WIN32) || defined(_WIN64))
1605  UINT new_flags =
1606  SEM_FAILCRITICALERRORS | SEM_NOGPFAULTERRORBOX | SEM_NOOPENFILEERRORBOX;
1607  UINT existing_flags = SetErrorMode(new_flags);
1608  SetErrorMode(existing_flags | new_flags);
1609 #if defined(_MSC_VER)
1610  _CrtSetReportMode(_CRT_WARN, _CRTDBG_MODE_DEBUG | _CRTDBG_MODE_FILE);
1611  _CrtSetReportFile(_CRT_WARN, _CRTDBG_FILE_STDERR);
1612  _CrtSetReportMode(_CRT_ASSERT, _CRTDBG_MODE_DEBUG | _CRTDBG_MODE_FILE);
1613  _CrtSetReportFile(_CRT_ASSERT, _CRTDBG_FILE_STDERR);
1614  _CrtSetReportMode(_CRT_ERROR, _CRTDBG_MODE_DEBUG | _CRTDBG_MODE_FILE);
1615  _CrtSetReportFile(_CRT_ERROR, _CRTDBG_FILE_STDERR);
1616  _set_error_mode(_OUT_TO_STDERR);
1617 #endif // defined(_MSC_VER)
1618 #endif // defined(_WIN32) || defined(_WIN64)
1619  if (!SetOptions(argc, argv)) return 1;
1622  v8::V8::InitializePlatform(platform);
1624 #ifdef V8_USE_EXTERNAL_STARTUP_DATA
1625  StartupDataHandler startup_data(options.natives_blob, options.snapshot_blob);
1626 #endif
1627  SetFlagsFromString("--trace-hydrogen-file=hydrogen.cfg");
1628  SetFlagsFromString("--redirect-code-traces-to=code.asm");
1629  ShellArrayBufferAllocator array_buffer_allocator;
1630  MockArrayBufferAllocator mock_arraybuffer_allocator;
1632  v8::V8::SetArrayBufferAllocator(&mock_arraybuffer_allocator);
1633  } else {
1634  v8::V8::SetArrayBufferAllocator(&array_buffer_allocator);
1635  }
1636  int result = 0;
1637  Isolate::CreateParams create_params;
1638 #if !defined(V8_SHARED) && defined(ENABLE_GDB_JIT_INTERFACE)
1639  if (i::FLAG_gdbjit) {
1640  create_params.code_event_handler = i::GDBJITInterface::EventHandler;
1641  }
1642 #endif
1643 #ifdef ENABLE_VTUNE_JIT_INTERFACE
1644  vTune::InitializeVtuneForV8(create_params);
1645 #endif
1646 #ifndef V8_SHARED
1647  create_params.constraints.ConfigureDefaults(
1648  base::SysInfo::AmountOfPhysicalMemory(),
1649  base::SysInfo::AmountOfVirtualMemory(),
1650  base::SysInfo::NumberOfProcessors());
1651 #endif
1652  Isolate* isolate = Isolate::New(create_params);
1653  DumbLineEditor dumb_line_editor(isolate);
1654  {
1655  Isolate::Scope scope(isolate);
1656  Initialize(isolate);
1657  PerIsolateData data(isolate);
1658  InitializeDebugger(isolate);
1659 
1660 #ifndef V8_SHARED
1662  DumpHeapConstants(reinterpret_cast<i::Isolate*>(isolate));
1663  return 0;
1664  }
1665 #endif
1666 
1671  int stress_runs = Testing::GetStressRuns();
1672  for (int i = 0; i < stress_runs && result == 0; i++) {
1673  printf("============ Stress %d/%d ============\n", i + 1, stress_runs);
1675  options.last_run = (i == stress_runs - 1);
1676  result = RunMain(isolate, argc, argv);
1677  }
1678  printf("======== Full Deoptimization =======\n");
1680 #if !defined(V8_SHARED)
1681  } else if (i::FLAG_stress_runs > 0) {
1682  int stress_runs = i::FLAG_stress_runs;
1683  for (int i = 0; i < stress_runs && result == 0; i++) {
1684  printf("============ Run %d/%d ============\n", i + 1, stress_runs);
1685  options.last_run = (i == stress_runs - 1);
1686  result = RunMain(isolate, argc, argv);
1687  }
1688 #endif
1689  } else {
1690  result = RunMain(isolate, argc, argv);
1691  }
1692 
1693  // Run interactive shell if explicitly requested or if no script has been
1694  // executed, but never on --test
1696 #ifndef V8_SHARED
1697  if (!i::FLAG_debugger) {
1698  InstallUtilityScript(isolate);
1699  }
1700 #endif // !V8_SHARED
1701  RunShell(isolate);
1702  }
1703  }
1704 #ifndef V8_SHARED
1705  // Dump basic block profiling data.
1707  reinterpret_cast<i::Isolate*>(isolate)->basic_block_profiler()) {
1708  i::OFStream os(stdout);
1709  os << *profiler;
1710  }
1711 #endif // !V8_SHARED
1712  isolate->Dispose();
1713  V8::Dispose();
1715  delete platform;
1716 
1717  OnExit();
1718 
1719  return result;
1720 }
static Isolate * New(const CreateParams &params=CreateParams())
Creates a new isolate.
Definition: api.cc:6583
V8 Platform abstraction layer.
Definition: v8-platform.h:28
const char * natives_blob
Definition: d8.h:240
const char * icu_data_file
Definition: d8.h:239
bool mock_arraybuffer_allocator
Definition: d8.h:235
bool use_interactive_shell()
Definition: d8.h:221
bool last_run
Definition: d8.h:226
const char * snapshot_blob
Definition: d8.h:241
bool dump_heap_constants
Definition: d8.h:233
bool stress_opt
Definition: d8.h:229
bool stress_deopt
Definition: d8.h:230
static void InstallUtilityScript(Isolate *isolate)
Definition: d8.cc:787
static void Initialize(Isolate *isolate)
Definition: d8.cc:925
static void RunShell(Isolate *isolate)
Definition: d8.cc:1156
static int RunMain(Isolate *isolate, int argc, char *argv[])
Definition: d8.cc:1421
static bool SetOptions(int argc, char *argv[])
Definition: d8.cc:1302
static void OnExit()
Definition: d8.cc:1013
static void InitializeDebugger(Isolate *isolate)
Definition: d8.cc:949
@ kStressTypeDeopt
Definition: v8-testing.h:19
@ kStressTypeOpt
Definition: v8-testing.h:18
static int GetStressRuns()
Get the number of runs of a given test that is required to get the full stress coverage.
Definition: api.cc:7461
static void DeoptimizeAll()
Force deoptimization of all functions.
Definition: api.cc:7514
static void PrepareStressRun(int run)
Indicate the number of the run which is about to start.
Definition: api.cc:7478
static void SetStressRunType(StressType type)
Set the type of stressing to do.
Definition: api.cc:7456
static bool InitializeICU(const char *icu_data_file=NULL)
Initialize the ICU library bundled with V8.
Definition: api.cc:5141
static void InitializePlatform(Platform *platform)
Sets the v8::Platform to use.
Definition: api.cc:5048
static void SetArrayBufferAllocator(ArrayBuffer::Allocator *allocator)
Set allocator to use for ArrayBuffer memory.
Definition: api.cc:5074
static void ShutdownPlatform()
Clears all references to the v8::Platform.
Definition: api.cc:5053
static bool Dispose()
Releases any resources used by v8 and stops any utility threads that may be running.
Definition: api.cc:5084
static bool Initialize()
Initializes V8.
Definition: api.cc:5058
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 expose gc extension under the specified name show built in functions in stack traces use random jit cookie to mask large constants minimum length for automatic enable preparsing CPU profiler sampling interval in microseconds trace out of bounds accesses to external arrays default size of stack region v8 is allowed to maximum length of function source code printed in a stack trace min size of a semi the new space consists of two semi spaces print one trace line following each garbage collection do not print trace line after scavenger collection print cumulative GC statistics in only print modified registers Trace simulator debug messages Implied by trace sim abort randomize hashes to avoid predictable hash Fixed seed to use to hash property Print the time it takes to deserialize the snapshot A filename with extra code to be included in the A file to write the raw snapshot bytes A file to write the raw context snapshot bytes Write V8 startup blob Print the time it takes to lazily compile hydrogen code stubs dump only objects containing this substring stress the GC compactor to flush out pretty print source code for builtins print C code to recreate TurboFan graphs report heap spill statistics along with enable possessive quantifier syntax for testing Minimal Log code events to the log file without profiling log positions Log statistical profiling Used with turns on browser compatible mode for profiling Enable perf linux profiler(experimental annotate support).") DEFINE_STRING(gc_fake_mmap
v8::Platform * CreateDefaultPlatform(int thread_pool_size)
Returns a new instance of the default v8::Platform implementation.
static void SetFlagsFromString(const char *flags)
Definition: api.cc:7473
static void DumpHeapConstants(i::Isolate *isolate)
Definition: d8.cc:1469
void InitializeVtuneForV8(v8::Isolate::CreateParams &params)
Definition: vtune-jit.cc:274

References v8::Isolate::CreateParams::code_event_handler, v8::ResourceConstraints::ConfigureDefaults(), v8::Isolate::CreateParams::constraints, v8::platform::CreateDefaultPlatform(), v8::Testing::DeoptimizeAll(), v8::Isolate::Dispose(), v8::V8::Dispose(), v8::DumpHeapConstants(), v8::Testing::GetStressRuns(), v8::V8::Initialize(), v8::V8::InitializeICU(), v8::V8::InitializePlatform(), vTune::InitializeVtuneForV8(), v8::Testing::kStressTypeDeopt, v8::Testing::kStressTypeOpt, v8::Isolate::New(), v8::Testing::PrepareStressRun(), profiler(), v8::V8::SetArrayBufferAllocator(), v8::SetFlagsFromString(), v8::Testing::SetStressRunType(), and v8::V8::ShutdownPlatform().

Referenced by main().

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

◆ MakeDirectory()

void v8::Shell::MakeDirectory ( const v8::FunctionCallbackInfo< v8::Value > &  args)
static

Definition at line 617 of file d8-posix.cc.

617  {
618  mode_t mask = 0777;
619  if (args.Length() == 2) {
620  if (args[1]->IsNumber()) {
621  mask = args[1]->Int32Value();
622  } else {
623  const char* message = "mkdirp() second argument must be numeric";
624  args.GetIsolate()->ThrowException(
625  String::NewFromUtf8(args.GetIsolate(), message));
626  return;
627  }
628  } else if (args.Length() != 1) {
629  const char* message = "mkdirp() takes one or two arguments";
630  args.GetIsolate()->ThrowException(
631  String::NewFromUtf8(args.GetIsolate(), message));
632  return;
633  }
634  String::Utf8Value directory(args[0]);
635  if (*directory == NULL) {
636  const char* message = "os.mkdirp(): String conversion of argument failed.";
637  args.GetIsolate()->ThrowException(
638  String::NewFromUtf8(args.GetIsolate(), message));
639  return;
640  }
641  mkdirp(args.GetIsolate(), *directory, mask);
642 }
static bool mkdirp(Isolate *isolate, char *directory, mode_t mask)
Definition: d8-posix.cc:589

References v8::FunctionCallbackInfo< T >::GetIsolate(), v8::FunctionCallbackInfo< T >::Length(), v8::mkdirp(), v8::String::NewFromUtf8(), NULL, and v8::Isolate::ThrowException().

Referenced by AddOSMethods().

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

◆ MapCounters()

void v8::Shell::MapCounters ( v8::Isolate isolate,
const char *  name 
)
static

Definition at line 719 of file d8.cc.

719  {
721  name, sizeof(CounterCollection), &local_counters_);
722  void* memory = (counters_file_ == NULL) ?
724  if (memory == NULL) {
725  printf("Could not map counters file %s\n", name);
726  Exit(1);
727  }
728  counters_ = static_cast<CounterCollection*>(memory);
732 }
void SetCounterFunction(CounterLookupCallback)
Enables the host application to provide a mechanism for recording statistics counters.
Definition: api.cc:6764
void SetAddHistogramSampleFunction(AddHistogramSampleCallback)
Definition: api.cc:6780
void SetCreateHistogramFunction(CreateHistogramCallback)
Enables the host application to provide a mechanism for recording histograms.
Definition: api.cc:6772
static base::OS::MemoryMappedFile * counters_file_
Definition: d8.h:376
static CounterCollection local_counters_
Definition: d8.h:374
static MemoryMappedFile * create(const char *name, int size, void *initial)

References v8::base::OS::MemoryMappedFile::create(), name, NULL, v8::Isolate::SetAddHistogramSampleFunction(), v8::Isolate::SetCounterFunction(), and v8::Isolate::SetCreateHistogramFunction().

+ Here is the call graph for this function:

◆ OnExit()

void v8::Shell::OnExit ( )
static

Definition at line 1013 of file d8.cc.

1013  {
1014  LineEditor* line_editor = LineEditor::Get();
1015  if (line_editor) line_editor->Close();
1016 #ifndef V8_SHARED
1017  if (i::FLAG_dump_counters) {
1018  int number_of_counters = 0;
1019  for (CounterMap::Iterator i(counter_map_); i.More(); i.Next()) {
1020  number_of_counters++;
1021  }
1022  CounterAndKey* counters = new CounterAndKey[number_of_counters];
1023  int j = 0;
1024  for (CounterMap::Iterator i(counter_map_); i.More(); i.Next(), j++) {
1025  counters[j].counter = i.CurrentValue();
1026  counters[j].key = i.CurrentKey();
1027  }
1028  std::sort(counters, counters + number_of_counters);
1029  printf("+----------------------------------------------------------------+"
1030  "-------------+\n");
1031  printf("| Name |"
1032  " Value |\n");
1033  printf("+----------------------------------------------------------------+"
1034  "-------------+\n");
1035  for (j = 0; j < number_of_counters; j++) {
1036  Counter* counter = counters[j].counter;
1037  const char* key = counters[j].key;
1038  if (counter->is_histogram()) {
1039  printf("| c:%-60s | %11i |\n", key, counter->count());
1040  printf("| t:%-60s | %11i |\n", key, counter->sample_total());
1041  } else {
1042  printf("| %-62s | %11i |\n", key, counter->count());
1043  }
1044  }
1045  printf("+----------------------------------------------------------------+"
1046  "-------------+\n");
1047  delete [] counters;
1048  }
1049  delete counters_file_;
1050  delete counter_map_;
1051 #endif // !V8_SHARED
1052 }
static LineEditor * Get()
Definition: d8.h:109

References v8::LineEditor::Close(), v8::Counter::count(), v8::CounterAndKey::counter, v8::LineEditor::Get(), v8::Counter::is_histogram(), v8::CounterAndKey::key, and v8::Counter::sample_total().

+ Here is the call graph for this function:

◆ OSObject()

static void v8::Shell::OSObject ( const v8::FunctionCallbackInfo< v8::Value > &  args)
static

◆ PerformanceNow()

void v8::Shell::PerformanceNow ( const v8::FunctionCallbackInfo< v8::Value > &  args)
static

Definition at line 337 of file d8.cc.

337  {
338  if (i::FLAG_verify_predictable) {
339  Isolate* v8_isolate = args.GetIsolate();
340  i::Heap* heap = reinterpret_cast<i::Isolate*>(v8_isolate)->heap();
341  args.GetReturnValue().Set(heap->synthetic_time());
342  } else {
343  base::TimeDelta delta =
344  base::TimeTicks::HighResolutionNow() - kInitialTicks;
345  args.GetReturnValue().Set(delta.InMillisecondsF());
346  }
347 }
ReturnValue< T > GetReturnValue() const
Definition: v8.h:6348
static const base::TimeTicks kInitialTicks
Definition: d8.h:378
double synthetic_time()
Definition: heap.h:943

References v8::FunctionCallbackInfo< T >::GetIsolate(), v8::FunctionCallbackInfo< T >::GetReturnValue(), and v8::internal::Heap::synthetic_time().

+ Here is the call graph for this function:

◆ Print()

void v8::Shell::Print ( const v8::FunctionCallbackInfo< v8::Value > &  args)
static

Definition at line 469 of file d8.cc.

469  {
470  Write(args);
471  printf("\n");
472  fflush(stdout);
473 }

◆ Quit()

void v8::Shell::Quit ( const v8::FunctionCallbackInfo< v8::Value > &  args)
static

Definition at line 574 of file d8.cc.

574  {
575  int exit_code = args[0]->Int32Value();
576  OnExit();
577  exit(exit_code);
578 }

◆ Read()

void v8::Shell::Read ( const v8::FunctionCallbackInfo< v8::Value > &  args)
static

Definition at line 501 of file d8.cc.

501  {
502  String::Utf8Value file(args[0]);
503  if (*file == NULL) {
504  Throw(args.GetIsolate(), "Error loading file");
505  return;
506  }
507  Handle<String> source = ReadFile(args.GetIsolate(), *file);
508  if (source.IsEmpty()) {
509  Throw(args.GetIsolate(), "Error loading file");
510  return;
511  }
512  args.GetReturnValue().Set(source);
513 }

References file(), v8::FunctionCallbackInfo< T >::GetIsolate(), v8::FunctionCallbackInfo< T >::GetReturnValue(), v8::Handle< T >::IsEmpty(), NULL, v8::internal::ReadFile(), and v8::Throw().

+ Here is the call graph for this function:

◆ ReadBuffer()

void v8::Shell::ReadBuffer ( const v8::FunctionCallbackInfo< v8::Value > &  args)
static

Definition at line 1115 of file d8.cc.

1115  {
1116  DCHECK(sizeof(char) == sizeof(uint8_t)); // NOLINT
1117  String::Utf8Value filename(args[0]);
1118  int length;
1119  if (*filename == NULL) {
1120  Throw(args.GetIsolate(), "Error loading file");
1121  return;
1122  }
1123 
1124  Isolate* isolate = args.GetIsolate();
1125  DataAndPersistent* data = new DataAndPersistent;
1126  data->data = reinterpret_cast<uint8_t*>(
1127  ReadChars(args.GetIsolate(), *filename, &length));
1128  if (data->data == NULL) {
1129  delete data;
1130  Throw(args.GetIsolate(), "Error reading file");
1131  return;
1132  }
1133  Handle<v8::ArrayBuffer> buffer =
1134  ArrayBuffer::New(isolate, data->data, length);
1135  data->handle.Reset(isolate, buffer);
1136  data->handle.SetWeak(data, ReadBufferWeakCallback);
1137  data->handle.MarkIndependent();
1138  isolate->AdjustAmountOfExternalAllocatedMemory(length);
1139 
1140  args.GetReturnValue().Set(buffer);
1141 }
static Local< ArrayBuffer > New(Isolate *isolate, size_t byte_length)
Create a new ArrayBuffer.
Definition: api.cc:6024
static void ReadBufferWeakCallback(const v8::WeakCallbackData< ArrayBuffer, DataAndPersistent > &data)
Definition: d8.cc:1103
static char * ReadChars(Isolate *isolate, const char *name, int *size_out)
Definition: d8.cc:1077

References v8::Isolate::AdjustAmountOfExternalAllocatedMemory(), v8::DataAndPersistent::data, DCHECK, v8::FunctionCallbackInfo< T >::GetIsolate(), v8::FunctionCallbackInfo< T >::GetReturnValue(), v8::DataAndPersistent::handle, v8::ArrayBuffer::New(), NULL, v8::ReadBufferWeakCallback(), v8::ReadChars(), and v8::Throw().

+ Here is the call graph for this function:

◆ ReadFile()

Handle< String > v8::Shell::ReadFile ( Isolate isolate,
const char *  name 
)
static

Definition at line 1145 of file d8.cc.

1145  {
1146  int size = 0;
1147  char* chars = ReadChars(isolate, name, &size);
1148  if (chars == NULL) return Handle<String>();
1149  Handle<String> result =
1151  delete[] chars;
1152  return result;
1153 }
enable harmony numeric enable harmony object literal extensions Optimize object size

References v8::String::kNormalString, name, v8::String::NewFromUtf8(), NULL, v8::ReadChars(), and size.

+ Here is the call graph for this function:

◆ ReadFromStdin()

Handle< String > v8::Shell::ReadFromStdin ( Isolate isolate)
static

Definition at line 516 of file d8.cc.

516  {
517  static const int kBufferSize = 256;
518  char buffer[kBufferSize];
519  Handle<String> accumulator = String::NewFromUtf8(isolate, "");
520  int length;
521  while (true) {
522  // Continue reading if the line ends with an escape '\\' or the line has
523  // not been fully read into the buffer yet (does not end with '\n').
524  // If fgets gets an error, just give up.
525  char* input = NULL;
526  input = fgets(buffer, kBufferSize, stdin);
527  if (input == NULL) return Handle<String>();
528  length = static_cast<int>(strlen(buffer));
529  if (length == 0) {
530  return accumulator;
531  } else if (buffer[length-1] != '\n') {
532  accumulator = String::Concat(
533  accumulator,
534  String::NewFromUtf8(isolate, buffer, String::kNormalString, length));
535  } else if (length > 1 && buffer[length-2] == '\\') {
536  buffer[length-2] = '\n';
537  accumulator = String::Concat(
538  accumulator, String::NewFromUtf8(isolate, buffer,
539  String::kNormalString, length - 1));
540  } else {
541  return String::Concat(
542  accumulator, String::NewFromUtf8(isolate, buffer,
543  String::kNormalString, length - 1));
544  }
545  }
546 }
static Local< String > Concat(Handle< String > left, Handle< String > right)
Creates a new string by concatenating the left and the right strings passed in as parameters.
Definition: api.cc:5486

References v8::String::Concat(), v8::base::anonymous_namespace{semaphore-unittest.cc}::kBufferSize, v8::String::kNormalString, v8::String::NewFromUtf8(), and NULL.

Referenced by v8::DumbLineEditor::Prompt(), and ReadLine().

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

◆ ReadLine()

static void v8::Shell::ReadLine ( const v8::FunctionCallbackInfo< v8::Value > &  args)
inlinestatic

Definition at line 308 of file d8.h.

308  {
309  args.GetReturnValue().Set(ReadFromStdin(args.GetIsolate()));
310  }
static Handle< String > ReadFromStdin(Isolate *isolate)
Definition: d8.cc:516

References v8::FunctionCallbackInfo< T >::GetIsolate(), v8::FunctionCallbackInfo< T >::GetReturnValue(), and ReadFromStdin().

+ Here is the call graph for this function:

◆ RealmCreate()

void v8::Shell::RealmCreate ( const v8::FunctionCallbackInfo< v8::Value > &  args)
static

Definition at line 387 of file d8.cc.

387  {
388  Isolate* isolate = args.GetIsolate();
389  PerIsolateData* data = PerIsolateData::Get(isolate);
390  Persistent<Context>* old_realms = data->realms_;
391  int index = data->realm_count_;
392  data->realms_ = new Persistent<Context>[++data->realm_count_];
393  for (int i = 0; i < index; ++i) {
394  data->realms_[i].Reset(isolate, old_realms[i]);
395  }
396  delete[] old_realms;
397  Handle<ObjectTemplate> global_template = CreateGlobalTemplate(isolate);
398  data->realms_[index].Reset(
399  isolate, Context::New(isolate, NULL, global_template));
400  args.GetReturnValue().Set(index);
401 }

References v8::PerIsolateData::Get(), v8::FunctionCallbackInfo< T >::GetIsolate(), v8::FunctionCallbackInfo< T >::GetReturnValue(), v8::Context::New(), NULL, v8::PerIsolateData::realm_count_, and v8::PerIsolateData::realms_.

+ Here is the call graph for this function:

◆ RealmCurrent()

void v8::Shell::RealmCurrent ( const v8::FunctionCallbackInfo< v8::Value > &  args)
static

Definition at line 352 of file d8.cc.

352  {
353  Isolate* isolate = args.GetIsolate();
354  PerIsolateData* data = PerIsolateData::Get(isolate);
355  int index = data->RealmFind(isolate->GetEnteredContext());
356  if (index == -1) return;
357  args.GetReturnValue().Set(index);
358 }

References v8::PerIsolateData::Get(), v8::Isolate::GetEnteredContext(), v8::FunctionCallbackInfo< T >::GetIsolate(), v8::FunctionCallbackInfo< T >::GetReturnValue(), and v8::PerIsolateData::RealmFind().

+ Here is the call graph for this function:

◆ RealmDispose()

void v8::Shell::RealmDispose ( const v8::FunctionCallbackInfo< v8::Value > &  args)
static

Definition at line 405 of file d8.cc.

405  {
406  Isolate* isolate = args.GetIsolate();
407  PerIsolateData* data = PerIsolateData::Get(isolate);
408  int index = data->RealmIndexOrThrow(args, 0);
409  if (index == -1) return;
410  if (index == 0 ||
411  index == data->realm_current_ || index == data->realm_switch_) {
412  Throw(args.GetIsolate(), "Invalid realm index");
413  return;
414  }
415  data->realms_[index].Reset();
416 }

References v8::PerIsolateData::Get(), v8::FunctionCallbackInfo< T >::GetIsolate(), v8::PerIsolateData::realm_current_, v8::PerIsolateData::realm_switch_, v8::PerIsolateData::RealmIndexOrThrow(), v8::PerIsolateData::realms_, and v8::Throw().

+ Here is the call graph for this function:

◆ RealmEval()

void v8::Shell::RealmEval ( const v8::FunctionCallbackInfo< v8::Value > &  args)
static

Definition at line 430 of file d8.cc.

430  {
431  Isolate* isolate = args.GetIsolate();
432  PerIsolateData* data = PerIsolateData::Get(isolate);
433  int index = data->RealmIndexOrThrow(args, 0);
434  if (index == -1) return;
435  if (args.Length() < 2 || !args[1]->IsString()) {
436  Throw(args.GetIsolate(), "Invalid argument");
437  return;
438  }
439  ScriptCompiler::Source script_source(args[1]->ToString());
440  Handle<UnboundScript> script = ScriptCompiler::CompileUnbound(
441  isolate, &script_source);
442  if (script.IsEmpty()) return;
443  Local<Context> realm = Local<Context>::New(isolate, data->realms_[index]);
444  realm->Enter();
445  Handle<Value> result = script->BindToCurrentContext()->Run();
446  realm->Exit();
447  args.GetReturnValue().Set(result);
448 }

References v8::ScriptCompiler::CompileUnbound(), v8::PerIsolateData::Get(), v8::FunctionCallbackInfo< T >::GetIsolate(), v8::FunctionCallbackInfo< T >::GetReturnValue(), v8::Handle< T >::IsEmpty(), v8::FunctionCallbackInfo< T >::Length(), v8::Local< T >::New(), v8::PerIsolateData::RealmIndexOrThrow(), v8::PerIsolateData::realms_, and v8::Throw().

+ Here is the call graph for this function:

◆ RealmGlobal()

void v8::Shell::RealmGlobal ( const v8::FunctionCallbackInfo< v8::Value > &  args)
static

Definition at line 377 of file d8.cc.

377  {
378  PerIsolateData* data = PerIsolateData::Get(args.GetIsolate());
379  int index = data->RealmIndexOrThrow(args, 0);
380  if (index == -1) return;
381  args.GetReturnValue().Set(
382  Local<Context>::New(args.GetIsolate(), data->realms_[index])->Global());
383 }

References v8::PerIsolateData::Get(), v8::FunctionCallbackInfo< T >::GetIsolate(), v8::FunctionCallbackInfo< T >::GetReturnValue(), v8::PerIsolateData::RealmIndexOrThrow(), and v8::PerIsolateData::realms_.

+ Here is the call graph for this function:

◆ RealmOwner()

void v8::Shell::RealmOwner ( const v8::FunctionCallbackInfo< v8::Value > &  args)
static

Definition at line 362 of file d8.cc.

362  {
363  Isolate* isolate = args.GetIsolate();
364  PerIsolateData* data = PerIsolateData::Get(isolate);
365  if (args.Length() < 1 || !args[0]->IsObject()) {
366  Throw(args.GetIsolate(), "Invalid argument");
367  return;
368  }
369  int index = data->RealmFind(args[0]->ToObject()->CreationContext());
370  if (index == -1) return;
371  args.GetReturnValue().Set(index);
372 }

References v8::PerIsolateData::Get(), v8::FunctionCallbackInfo< T >::GetIsolate(), v8::FunctionCallbackInfo< T >::GetReturnValue(), v8::FunctionCallbackInfo< T >::Length(), v8::PerIsolateData::RealmFind(), and v8::Throw().

+ Here is the call graph for this function:

◆ RealmSharedGet()

void v8::Shell::RealmSharedGet ( Local< String property,
const PropertyCallbackInfo< Value > &  info 
)
static

Definition at line 452 of file d8.cc.

453  {
454  Isolate* isolate = info.GetIsolate();
455  PerIsolateData* data = PerIsolateData::Get(isolate);
456  if (data->realm_shared_.IsEmpty()) return;
457  info.GetReturnValue().Set(data->realm_shared_);
458 }

References v8::PerIsolateData::Get(), v8::PropertyCallbackInfo< T >::GetIsolate(), v8::PropertyCallbackInfo< T >::GetReturnValue(), and v8::PerIsolateData::realm_shared_.

+ Here is the call graph for this function:

◆ RealmSharedSet()

void v8::Shell::RealmSharedSet ( Local< String property,
Local< Value value,
const PropertyCallbackInfo< void > &  info 
)
static

Definition at line 460 of file d8.cc.

462  {
463  Isolate* isolate = info.GetIsolate();
464  PerIsolateData* data = PerIsolateData::Get(isolate);
465  data->realm_shared_.Reset(isolate, value);
466 }

References v8::PerIsolateData::Get(), v8::PropertyCallbackInfo< T >::GetIsolate(), and v8::PerIsolateData::realm_shared_.

+ Here is the call graph for this function:

◆ RealmSwitch()

void v8::Shell::RealmSwitch ( const v8::FunctionCallbackInfo< v8::Value > &  args)
static

Definition at line 420 of file d8.cc.

420  {
421  Isolate* isolate = args.GetIsolate();
422  PerIsolateData* data = PerIsolateData::Get(isolate);
423  int index = data->RealmIndexOrThrow(args, 0);
424  if (index == -1) return;
425  data->realm_switch_ = index;
426 }

References v8::PerIsolateData::Get(), v8::FunctionCallbackInfo< T >::GetIsolate(), v8::PerIsolateData::realm_switch_, and v8::PerIsolateData::RealmIndexOrThrow().

+ Here is the call graph for this function:

◆ RemoveDirectory()

void v8::Shell::RemoveDirectory ( const v8::FunctionCallbackInfo< v8::Value > &  args)
static

Definition at line 645 of file d8-posix.cc.

645  {
646  if (args.Length() != 1) {
647  const char* message = "rmdir() takes one or two arguments";
648  args.GetIsolate()->ThrowException(
649  String::NewFromUtf8(args.GetIsolate(), message));
650  return;
651  }
652  String::Utf8Value directory(args[0]);
653  if (*directory == NULL) {
654  const char* message = "os.rmdir(): String conversion of argument failed.";
655  args.GetIsolate()->ThrowException(
656  String::NewFromUtf8(args.GetIsolate(), message));
657  return;
658  }
659  rmdir(*directory);
660 }

References v8::FunctionCallbackInfo< T >::GetIsolate(), v8::FunctionCallbackInfo< T >::Length(), v8::String::NewFromUtf8(), NULL, and v8::Isolate::ThrowException().

Referenced by AddOSMethods().

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

◆ ReportException()

void v8::Shell::ReportException ( Isolate isolate,
v8::TryCatch try_catch 
)
static

Definition at line 587 of file d8.cc.

587  {
588  HandleScope handle_scope(isolate);
589 #ifndef V8_SHARED
590  Handle<Context> utility_context;
591  bool enter_context = !isolate->InContext();
592  if (enter_context) {
593  utility_context = Local<Context>::New(isolate, utility_context_);
594  utility_context->Enter();
595  }
596 #endif // !V8_SHARED
597  v8::String::Utf8Value exception(try_catch->Exception());
598  const char* exception_string = ToCString(exception);
599  Handle<Message> message = try_catch->Message();
600  if (message.IsEmpty()) {
601  // V8 didn't provide any extra information about this error; just
602  // print the exception.
603  printf("%s\n", exception_string);
604  } else {
605  // Print (filename):(line number): (message).
606  v8::String::Utf8Value filename(message->GetScriptOrigin().ResourceName());
607  const char* filename_string = ToCString(filename);
608  int linenum = message->GetLineNumber();
609  printf("%s:%i: %s\n", filename_string, linenum, exception_string);
610  // Print line of source code.
611  v8::String::Utf8Value sourceline(message->GetSourceLine());
612  const char* sourceline_string = ToCString(sourceline);
613  printf("%s\n", sourceline_string);
614  // Print wavy underline (GetUnderline is deprecated).
615  int start = message->GetStartColumn();
616  for (int i = 0; i < start; i++) {
617  printf(" ");
618  }
619  int end = message->GetEndColumn();
620  for (int i = start; i < end; i++) {
621  printf("^");
622  }
623  printf("\n");
624  v8::String::Utf8Value stack_trace(try_catch->StackTrace());
625  if (stack_trace.length() > 0) {
626  const char* stack_trace_string = ToCString(stack_trace);
627  printf("%s\n", stack_trace_string);
628  }
629  }
630  printf("\n");
631 #ifndef V8_SHARED
632  if (enter_context) utility_context->Exit();
633 #endif // !V8_SHARED
634 }
static const char * ToCString(const v8::String::Utf8Value &value)
Definition: d8.cc:175
Local< v8::Message > Message() const
Returns the message associated with this exception.
Definition: api.cc:2012
Local< Value > Exception() const
Returns the exception caught by this try/catch block.
Definition: api.cc:1976
Local< Value > StackTrace() const
Returns the .stack property of the thrown object.
Definition: api.cc:1988

References v8::TryCatch::Exception(), v8::Isolate::InContext(), v8::Handle< T >::IsEmpty(), v8::String::Utf8Value::length(), v8::TryCatch::Message(), v8::Local< T >::New(), and v8::TryCatch::StackTrace().

Referenced by ExecuteString(), and v8::HandleDebugEvent().

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

◆ RunMain()

int v8::Shell::RunMain ( Isolate isolate,
int  argc,
char *  argv[] 
)
static

Definition at line 1421 of file d8.cc.

1421  {
1422 #ifndef V8_SHARED
1423  for (int i = 1; i < options.num_isolates; ++i) {
1425  }
1426 #endif // !V8_SHARED
1427  {
1428  HandleScope scope(isolate);
1429  Local<Context> context = CreateEvaluationContext(isolate);
1431  // Keep using the same context in the interactive shell.
1432  evaluation_context_.Reset(isolate, context);
1433 #ifndef V8_SHARED
1434  // If the interactive debugger is enabled make sure to activate
1435  // it before running the files passed on the command line.
1436  if (i::FLAG_debugger) {
1437  InstallUtilityScript(isolate);
1438  }
1439 #endif // !V8_SHARED
1440  }
1441  {
1442  Context::Scope cscope(context);
1443  PerIsolateData::RealmScope realm_scope(PerIsolateData::Get(isolate));
1444  options.isolate_sources[0].Execute(isolate);
1445  }
1446  }
1448  const int kLongIdlePauseInMs = 1000;
1449  isolate->ContextDisposedNotification();
1450  isolate->IdleNotification(kLongIdlePauseInMs);
1451  }
1453  // By sending a low memory notifications, we will try hard to collect all
1454  // garbage and will therefore also invoke all weak callbacks of actually
1455  // unreachable persistent handles.
1456  isolate->LowMemoryNotification();
1457  }
1458 
1459 #ifndef V8_SHARED
1460  for (int i = 1; i < options.num_isolates; ++i) {
1462  }
1463 #endif // !V8_SHARED
1464  return 0;
1465 }
friend class RealmScope
Definition: d8.cc:103
SourceGroup * isolate_sources
Definition: d8.h:238
bool invoke_weak_callbacks
Definition: d8.h:228
bool send_idle_notification
Definition: d8.h:227
int num_isolates
Definition: d8.h:236
static Local< Context > CreateEvaluationContext(Isolate *isolate)
Definition: d8.cc:960
void Execute(Isolate *isolate)
Definition: d8.cc:1184
void StartExecuteInThread()
Definition: d8.cc:1277
void WaitForThread()
Definition: d8.cc:1286

References v8::Isolate::ContextDisposedNotification(), v8::PerIsolateData::Get(), v8::Isolate::IdleNotification(), and v8::Isolate::LowMemoryNotification().

+ Here is the call graph for this function:

◆ RunShell()

void v8::Shell::RunShell ( Isolate isolate)
staticprivate

Definition at line 1156 of file d8.cc.

1156  {
1157  HandleScope outer_scope(isolate);
1158  v8::Local<v8::Context> context =
1160  v8::Context::Scope context_scope(context);
1161  PerIsolateData::RealmScope realm_scope(PerIsolateData::Get(isolate));
1162  Handle<String> name = String::NewFromUtf8(isolate, "(d8)");
1163  LineEditor* console = LineEditor::Get();
1164  printf("V8 version %s [console: %s]\n", V8::GetVersion(), console->name());
1165  console->Open(isolate);
1166  while (true) {
1167  HandleScope inner_scope(isolate);
1168  Handle<String> input = console->Prompt(Shell::kPrompt);
1169  if (input.IsEmpty()) break;
1170  ExecuteString(isolate, input, name, true, true);
1171  }
1172  printf("\n");
1173 }
static const char * kPrompt
Definition: d8.h:364
static const char * GetVersion()
Get the version string.
Definition: api.cc:5146

References v8::LineEditor::Get(), v8::PerIsolateData::Get(), v8::V8::GetVersion(), v8::Handle< T >::IsEmpty(), kPrompt, v8::LineEditor::name(), name, v8::Local< T >::New(), v8::String::NewFromUtf8(), v8::LineEditor::Open(), and v8::LineEditor::Prompt().

+ Here is the call graph for this function:

◆ SetEnvironment()

void v8::Shell::SetEnvironment ( const v8::FunctionCallbackInfo< v8::Value > &  args)
static

Definition at line 663 of file d8-posix.cc.

663  {
664  if (args.Length() != 2) {
665  const char* message = "setenv() takes two arguments";
666  args.GetIsolate()->ThrowException(
667  String::NewFromUtf8(args.GetIsolate(), message));
668  return;
669  }
670  String::Utf8Value var(args[0]);
671  String::Utf8Value value(args[1]);
672  if (*var == NULL) {
673  const char* message =
674  "os.setenv(): String conversion of variable name failed.";
675  args.GetIsolate()->ThrowException(
676  String::NewFromUtf8(args.GetIsolate(), message));
677  return;
678  }
679  if (*value == NULL) {
680  const char* message =
681  "os.setenv(): String conversion of variable contents failed.";
682  args.GetIsolate()->ThrowException(
683  String::NewFromUtf8(args.GetIsolate(), message));
684  return;
685  }
686  setenv(*var, *value, 1);
687 }

References v8::FunctionCallbackInfo< T >::GetIsolate(), v8::FunctionCallbackInfo< T >::Length(), v8::String::NewFromUtf8(), NULL, and v8::Isolate::ThrowException().

Referenced by AddOSMethods().

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

◆ SetOptions()

bool v8::Shell::SetOptions ( int  argc,
char *  argv[] 
)
staticprivate

Definition at line 1302 of file d8.cc.

1302  {
1303  bool logfile_per_isolate = false;
1304  for (int i = 0; i < argc; i++) {
1305  if (strcmp(argv[i], "--stress-opt") == 0) {
1306  options.stress_opt = true;
1307  argv[i] = NULL;
1308  } else if (strcmp(argv[i], "--nostress-opt") == 0) {
1309  options.stress_opt = false;
1310  argv[i] = NULL;
1311  } else if (strcmp(argv[i], "--stress-deopt") == 0) {
1312  options.stress_deopt = true;
1313  argv[i] = NULL;
1314  } else if (strcmp(argv[i], "--mock-arraybuffer-allocator") == 0) {
1316  argv[i] = NULL;
1317  } else if (strcmp(argv[i], "--noalways-opt") == 0) {
1318  // No support for stressing if we can't use --always-opt.
1319  options.stress_opt = false;
1320  options.stress_deopt = false;
1321  } else if (strcmp(argv[i], "--logfile-per-isolate") == 0) {
1322  logfile_per_isolate = true;
1323  argv[i] = NULL;
1324  } else if (strcmp(argv[i], "--shell") == 0) {
1325  options.interactive_shell = true;
1326  argv[i] = NULL;
1327  } else if (strcmp(argv[i], "--test") == 0) {
1328  options.test_shell = true;
1329  argv[i] = NULL;
1330  } else if (strcmp(argv[i], "--send-idle-notification") == 0) {
1332  argv[i] = NULL;
1333  } else if (strcmp(argv[i], "--invoke-weak-callbacks") == 0) {
1335  // TODO(jochen) See issue 3351
1337  argv[i] = NULL;
1338  } else if (strcmp(argv[i], "-f") == 0) {
1339  // Ignore any -f flags for compatibility with other stand-alone
1340  // JavaScript engines.
1341  continue;
1342  } else if (strcmp(argv[i], "--isolate") == 0) {
1343 #ifdef V8_SHARED
1344  printf("D8 with shared library does not support multi-threading\n");
1345  return false;
1346 #endif // V8_SHARED
1348  } else if (strcmp(argv[i], "--dump-heap-constants") == 0) {
1349 #ifdef V8_SHARED
1350  printf("D8 with shared library does not support constant dumping\n");
1351  return false;
1352 #else
1354  argv[i] = NULL;
1355 #endif // V8_SHARED
1356  } else if (strcmp(argv[i], "--throws") == 0) {
1357  options.expected_to_throw = true;
1358  argv[i] = NULL;
1359  } else if (strncmp(argv[i], "--icu-data-file=", 16) == 0) {
1360  options.icu_data_file = argv[i] + 16;
1361  argv[i] = NULL;
1362 #ifdef V8_SHARED
1363  } else if (strcmp(argv[i], "--dump-counters") == 0) {
1364  printf("D8 with shared library does not include counters\n");
1365  return false;
1366  } else if (strcmp(argv[i], "--debugger") == 0) {
1367  printf("Javascript debugger not included\n");
1368  return false;
1369 #endif // V8_SHARED
1370 #ifdef V8_USE_EXTERNAL_STARTUP_DATA
1371  } else if (strncmp(argv[i], "--natives_blob=", 15) == 0) {
1372  options.natives_blob = argv[i] + 15;
1373  argv[i] = NULL;
1374  } else if (strncmp(argv[i], "--snapshot_blob=", 16) == 0) {
1375  options.snapshot_blob = argv[i] + 16;
1376  argv[i] = NULL;
1377 #endif // V8_USE_EXTERNAL_STARTUP_DATA
1378  } else if (strcmp(argv[i], "--cache") == 0 ||
1379  strncmp(argv[i], "--cache=", 8) == 0) {
1380  const char* value = argv[i] + 7;
1381  if (!*value || strncmp(value, "=code", 6) == 0) {
1383  } else if (strncmp(value, "=parse", 7) == 0) {
1385  } else if (strncmp(value, "=none", 6) == 0) {
1387  } else {
1388  printf("Unknown option to --cache.\n");
1389  return false;
1390  }
1391  argv[i] = NULL;
1392  }
1393  }
1394 
1395  v8::V8::SetFlagsFromCommandLine(&argc, argv, true);
1396 
1397  // Set up isolated source groups.
1398  options.isolate_sources = new SourceGroup[options.num_isolates];
1399  SourceGroup* current = options.isolate_sources;
1400  current->Begin(argv, 1);
1401  for (int i = 1; i < argc; i++) {
1402  const char* str = argv[i];
1403  if (strcmp(str, "--isolate") == 0) {
1404  current->End(i);
1405  current++;
1406  current->Begin(argv, i + 1);
1407  } else if (strncmp(argv[i], "--", 2) == 0) {
1408  printf("Warning: unknown flag %s.\nTry --help for options\n", argv[i]);
1409  }
1410  }
1411  current->End(argc);
1412 
1413  if (!logfile_per_isolate && options.num_isolates) {
1414  SetFlagsFromString("--nologfile_per_isolate");
1415  }
1416 
1417  return true;
1418 }
@ kNoCompileOptions
Definition: v8.h:1160
bool interactive_shell
Definition: d8.h:231
bool expected_to_throw
Definition: d8.h:234
void Begin(char **argv, int offset)
Definition: d8.h:131
static void SetFlagsFromCommandLine(int *argc, char **argv, bool remove_flags)
Sets V8 flags from the command line.
Definition: api.cc:369

References v8::SourceGroup::Begin(), v8::SourceGroup::End(), v8::ScriptCompiler::kNoCompileOptions, v8::ScriptCompiler::kProduceCodeCache, v8::ScriptCompiler::kProduceParserCache, NULL, v8::V8::SetFlagsFromCommandLine(), and v8::SetFlagsFromString().

+ Here is the call graph for this function:

◆ SetUMask()

void v8::Shell::SetUMask ( const v8::FunctionCallbackInfo< v8::Value > &  args)
static

Definition at line 549 of file d8-posix.cc.

549  {
550  if (args.Length() != 1) {
551  const char* message = "umask() takes one argument";
552  args.GetIsolate()->ThrowException(
553  String::NewFromUtf8(args.GetIsolate(), message));
554  return;
555  }
556  if (args[0]->IsNumber()) {
557 #if V8_OS_NACL
558  // PNaCL has no support for umask.
559  int previous = 0;
560 #else
561  int previous = umask(args[0]->Int32Value());
562 #endif
563  args.GetReturnValue().Set(previous);
564  return;
565  } else {
566  const char* message = "umask() argument must be numeric";
567  args.GetIsolate()->ThrowException(
568  String::NewFromUtf8(args.GetIsolate(), message));
569  return;
570  }
571 }

References v8::FunctionCallbackInfo< T >::GetIsolate(), v8::FunctionCallbackInfo< T >::GetReturnValue(), v8::FunctionCallbackInfo< T >::Length(), v8::String::NewFromUtf8(), and v8::Isolate::ThrowException().

Referenced by AddOSMethods().

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

◆ System()

void v8::Shell::System ( const v8::FunctionCallbackInfo< v8::Value > &  args)
static

Definition at line 440 of file d8-posix.cc.

440  {
441  HandleScope scope(args.GetIsolate());
442  int read_timeout = -1;
443  int total_timeout = -1;
444  if (!GetTimeouts(args, &read_timeout, &total_timeout)) return;
445  Handle<Array> command_args;
446  if (args.Length() > 1) {
447  if (!args[1]->IsArray()) {
449  args.GetIsolate(), "system: Argument 2 must be an array"));
450  return;
451  }
452  command_args = Handle<Array>::Cast(args[1]);
453  } else {
454  command_args = Array::New(args.GetIsolate(), 0);
455  }
456  if (command_args->Length() > ExecArgs::kMaxArgs) {
458  args.GetIsolate(), "Too many arguments to system()"));
459  return;
460  }
461  if (args.Length() < 1) {
463  args.GetIsolate(), "Too few arguments to system()"));
464  return;
465  }
466 
467  struct timeval start_time;
468  gettimeofday(&start_time, NULL);
469 
470  ExecArgs exec_args;
471  if (!exec_args.Init(args.GetIsolate(), args[0], command_args)) {
472  return;
473  }
474  int exec_error_fds[2];
475  int stdout_fds[2];
476 
477  if (pipe(exec_error_fds) != 0) {
478  args.GetIsolate()->ThrowException(
479  String::NewFromUtf8(args.GetIsolate(), "pipe syscall failed."));
480  return;
481  }
482  if (pipe(stdout_fds) != 0) {
483  args.GetIsolate()->ThrowException(
484  String::NewFromUtf8(args.GetIsolate(), "pipe syscall failed."));
485  return;
486  }
487 
488  pid_t pid = fork();
489  if (pid == 0) { // Child process.
490  ExecSubprocess(exec_error_fds, stdout_fds, exec_args);
491  exit(1);
492  }
493 
494  // Parent process. Ensure that we clean up if we exit this function early.
495  ZombieProtector child_waiter(pid);
496  close(exec_error_fds[kWriteFD]);
497  close(stdout_fds[kWriteFD]);
498  OpenFDCloser error_read_closer(exec_error_fds[kReadFD]);
499  OpenFDCloser stdout_read_closer(stdout_fds[kReadFD]);
500 
501  if (!ChildLaunchedOK(args.GetIsolate(), exec_error_fds)) return;
502 
503  Handle<Value> accumulator = GetStdout(args.GetIsolate(),
504  stdout_fds[kReadFD],
505  start_time,
506  read_timeout,
507  total_timeout);
508  if (accumulator->IsUndefined()) {
509  kill(pid, SIGINT); // On timeout, kill the subprocess.
510  args.GetReturnValue().Set(accumulator);
511  return;
512  }
513 
514  if (!WaitForChild(args.GetIsolate(),
515  pid,
516  child_waiter,
517  start_time,
518  read_timeout,
519  total_timeout)) {
520  return;
521  }
522 
523  args.GetReturnValue().Set(accumulator);
524 }
static Local< Array > New(Isolate *isolate, int length=0)
Creates a JavaScript array with the given length.
Definition: api.cc:5805
static const unsigned kMaxArgs
Definition: d8-posix.cc:212
static bool WaitForChild(Isolate *isolate, int pid, ZombieProtector &child_waiter, const struct timeval &start_time, int read_timeout, int total_timeout)
Definition: d8-posix.cc:365
static bool GetTimeouts(const v8::FunctionCallbackInfo< v8::Value > &args, int *read_timeout, int *total_timeout)
Definition: d8-posix.cc:222
static void ExecSubprocess(int *exec_error_fds, int *stdout_fds, const ExecArgs &exec_args)
Definition: d8-posix.cc:254
static Handle< Value > GetStdout(Isolate *isolate, int child_fd, const struct timeval &start_time, int read_timeout, int total_timeout)
Definition: d8-posix.cc:293
static const int kWriteFD
Definition: d8-posix.cc:248
static bool ChildLaunchedOK(Isolate *isolate, int *exec_error_fds)
Definition: d8-posix.cc:277
static const int kReadFD
Definition: d8-posix.cc:247

References v8::Handle< T >::Cast(), v8::ChildLaunchedOK(), v8::ExecSubprocess(), v8::FunctionCallbackInfo< T >::GetIsolate(), v8::FunctionCallbackInfo< T >::GetReturnValue(), v8::GetStdout(), v8::GetTimeouts(), v8::ExecArgs::Init(), v8::ExecArgs::kMaxArgs, v8::kReadFD, v8::kWriteFD, v8::FunctionCallbackInfo< T >::Length(), v8::Array::New(), v8::String::NewFromUtf8(), NULL, v8::Isolate::ThrowException(), and v8::WaitForChild().

Referenced by AddOSMethods().

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

◆ ToCString()

const char * v8::Shell::ToCString ( const v8::String::Utf8Value value)
static

Definition at line 175 of file d8.cc.

175  {
176  return *value ? *value : "<string conversion failed>";
177 }

◆ Uint16Array()

static void v8::Shell::Uint16Array ( const v8::FunctionCallbackInfo< v8::Value > &  args)
static

◆ Uint32Array()

static void v8::Shell::Uint32Array ( const v8::FunctionCallbackInfo< v8::Value > &  args)
static

◆ Uint8Array()

static void v8::Shell::Uint8Array ( const v8::FunctionCallbackInfo< v8::Value > &  args)
static

◆ Uint8ClampedArray()

static void v8::Shell::Uint8ClampedArray ( const v8::FunctionCallbackInfo< v8::Value > &  args)
static

◆ UnsetEnvironment()

void v8::Shell::UnsetEnvironment ( const v8::FunctionCallbackInfo< v8::Value > &  args)
static

Definition at line 690 of file d8-posix.cc.

690  {
691  if (args.Length() != 1) {
692  const char* message = "unsetenv() takes one argument";
693  args.GetIsolate()->ThrowException(
694  String::NewFromUtf8(args.GetIsolate(), message));
695  return;
696  }
697  String::Utf8Value var(args[0]);
698  if (*var == NULL) {
699  const char* message =
700  "os.setenv(): String conversion of variable name failed.";
701  args.GetIsolate()->ThrowException(
702  String::NewFromUtf8(args.GetIsolate(), message));
703  return;
704  }
705  unsetenv(*var);
706 }

References v8::FunctionCallbackInfo< T >::GetIsolate(), v8::FunctionCallbackInfo< T >::Length(), v8::String::NewFromUtf8(), NULL, and v8::Isolate::ThrowException().

Referenced by AddOSMethods().

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

◆ Version()

void v8::Shell::Version ( const v8::FunctionCallbackInfo< v8::Value > &  args)
static

Definition at line 581 of file d8.cc.

581  {
582  args.GetReturnValue().Set(
584 }

References v8::FunctionCallbackInfo< T >::GetIsolate(), v8::FunctionCallbackInfo< T >::GetReturnValue(), v8::V8::GetVersion(), and v8::String::NewFromUtf8().

+ Here is the call graph for this function:

◆ Write()

void v8::Shell::Write ( const v8::FunctionCallbackInfo< v8::Value > &  args)
static

Definition at line 476 of file d8.cc.

476  {
477  for (int i = 0; i < args.Length(); i++) {
478  HandleScope handle_scope(args.GetIsolate());
479  if (i != 0) {
480  printf(" ");
481  }
482 
483  // Explicitly catch potential exceptions in toString().
484  v8::TryCatch try_catch;
485  Handle<String> str_obj = args[i]->ToString();
486  if (try_catch.HasCaught()) {
487  try_catch.ReThrow();
488  return;
489  }
490 
491  v8::String::Utf8Value str(str_obj);
492  int n = static_cast<int>(fwrite(*str, sizeof(**str), str.length(), stdout));
493  if (n != str.length()) {
494  printf("Error in fwrite\n");
495  Exit(1);
496  }
497  }
498 }
Handle< Value > ReThrow()
Throws the exception caught by this TryCatch in a way that avoids it being caught again by this same ...
Definition: api.cc:1969

References v8::FunctionCallbackInfo< T >::GetIsolate(), v8::TryCatch::HasCaught(), v8::String::Utf8Value::length(), v8::FunctionCallbackInfo< T >::Length(), and v8::TryCatch::ReThrow().

+ Here is the call graph for this function:

Member Data Documentation

◆ context_mutex_

base::Mutex v8::Shell::context_mutex_
staticprivate

Definition at line 377 of file d8.h.

◆ counter_map_

CounterMap * v8::Shell::counter_map_
staticprivate

Definition at line 371 of file d8.h.

Referenced by Initialize().

◆ counters_

CounterCollection * v8::Shell::counters_ = &local_counters_
staticprivate

Definition at line 375 of file d8.h.

◆ counters_file_

base::OS::MemoryMappedFile * v8::Shell::counters_file_ = NULL
staticprivate

Definition at line 376 of file d8.h.

◆ evaluation_context_

Persistent< Context > v8::Shell::evaluation_context_
staticprivate

Definition at line 368 of file d8.h.

◆ kInitialTicks

const base::TimeTicks v8::Shell::kInitialTicks
staticprivate
Initial value:
=
base::TimeTicks::HighResolutionNow()

Definition at line 378 of file d8.h.

◆ kPrompt

const char * v8::Shell::kPrompt = "d8> "
static

Definition at line 364 of file d8.h.

Referenced by RunShell().

◆ local_counters_

CounterCollection v8::Shell::local_counters_
staticprivate

Definition at line 374 of file d8.h.

◆ options

ShellOptions v8::Shell::options
static

◆ utility_context_

Persistent< Context > v8::Shell::utility_context_
staticprivate

Definition at line 370 of file d8.h.

Referenced by ExecuteString().


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