V8 Project
v8::Script Class Reference

A compiled JavaScript script, tied to a Context which was active when the script was compiled. More...

#include <v8.h>

+ Collaboration diagram for v8::Script:

Public Member Functions

Local< ValueRun ()
 Runs the script returning the resulting value. More...
 
Local< UnboundScriptGetUnboundScript ()
 Returns the corresponding context-unbound script. More...
 
 V8_DEPRECATED ("Use GetUnboundScript()->GetId()", int GetId())
 

Static Public Member Functions

static Local< ScriptCompile (Handle< String > source, ScriptOrigin *origin=NULL)
 A shorthand for ScriptCompiler::Compile(). More...
 
static Local< ScriptCompile (Handle< String > source, Handle< String > file_name)
 

Detailed Description

A compiled JavaScript script, tied to a Context which was active when the script was compiled.

Definition at line 985 of file v8.h.

Member Function Documentation

◆ Compile() [1/2]

Local< Script > v8::Script::Compile ( v8::Handle< String source,
v8::Handle< String file_name 
)
static

Definition at line 1896 of file api.cc.

1897  {
1898  ScriptOrigin origin(file_name);
1899  return Compile(source, &origin);
1900 }
static Local< Script > Compile(Handle< String > source, ScriptOrigin *origin=NULL)
A shorthand for ScriptCompiler::Compile().
Definition: api.cc:1880

References v8::ScriptCompiler::Compile().

+ Here is the call graph for this function:

◆ Compile() [2/2]

Local< Script > v8::Script::Compile ( v8::Handle< String source,
v8::ScriptOrigin origin = NULL 
)
static

A shorthand for ScriptCompiler::Compile().

Definition at line 1880 of file api.cc.

1881  {
1882  i::Handle<i::String> str = Utils::OpenHandle(*source);
1883  if (origin) {
1884  ScriptCompiler::Source script_source(source, *origin);
1885  return ScriptCompiler::Compile(
1886  reinterpret_cast<v8::Isolate*>(str->GetIsolate()),
1887  &script_source);
1888  }
1889  ScriptCompiler::Source script_source(source);
1890  return ScriptCompiler::Compile(
1891  reinterpret_cast<v8::Isolate*>(str->GetIsolate()),
1892  &script_source);
1893 }
Isolate represents an isolated instance of the V8 engine.
Definition: v8.h:4356
static Local< Script > Compile(Isolate *isolate, Source *source, CompileOptions options=kNoCompileOptions)
Compiles the specified script (bound to current context).
Definition: api.cc:1783
static v8::internal::Handle< To > OpenHandle(v8::Local< From > handle)
Definition: api.h:288

References v8::ScriptCompiler::Compile(), and v8::Utils::OpenHandle().

Referenced by v8::Shell::InstallUtilityScript(), and main().

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

◆ GetUnboundScript()

Local< UnboundScript > v8::Script::GetUnboundScript ( )

Returns the corresponding context-unbound script.

Definition at line 1696 of file api.cc.

1696  {
1698  return ToApiHandle<UnboundScript>(
1699  i::Handle<i::SharedFunctionInfo>(i::JSFunction::cast(*obj)->shared()));
1700 }

References v8::Utils::OpenHandle().

+ Here is the call graph for this function:

◆ Run()

Local< Value > v8::Script::Run ( )

Runs the script returning the resulting value.

It will be run in the context in which it was created (ScriptCompiler::CompileBound or UnboundScript::BindToGlobalContext()).

Definition at line 1674 of file api.cc.

1674  {
1675  i::Handle<i::Object> obj = Utils::OpenHandle(this, true);
1676  // If execution is terminating, Compile(..)->Run() requires this
1677  // check.
1678  if (obj.is_null()) return Local<Value>();
1679  i::Isolate* isolate = i::Handle<i::HeapObject>::cast(obj)->GetIsolate();
1680  ON_BAILOUT(isolate, "v8::Script::Run()", return Local<Value>());
1681  LOG_API(isolate, "Script::Run");
1682  ENTER_V8(isolate);
1683  i::TimerEventScope<i::TimerEventExecute> timer_scope(isolate);
1684  i::HandleScope scope(isolate);
1686  EXCEPTION_PREAMBLE(isolate);
1687  i::Handle<i::Object> receiver(isolate->global_proxy(), isolate);
1688  i::Handle<i::Object> result;
1689  has_pending_exception = !i::Execution::Call(
1690  isolate, fun, receiver, 0, NULL).ToHandle(&result);
1691  EXCEPTION_BAILOUT_CHECK_DO_CALLBACK(isolate, Local<Value>());
1692  return Utils::ToLocal(scope.CloseAndEscape(result));
1693 }
#define ON_BAILOUT(isolate, location, code)
Definition: api.cc:60
#define LOG_API(isolate, expr)
Definition: api.cc:52
#define ENTER_V8(isolate)
Definition: api.cc:54
#define EXCEPTION_BAILOUT_CHECK_DO_CALLBACK(isolate, value)
Definition: api.cc:88
#define EXCEPTION_PREAMBLE(isolate)
Definition: api.cc:67
static Local< Context > ToLocal(v8::internal::Handle< v8::internal::Context > obj)
static Handle< T > cast(Handle< S > that)
Definition: handles.h:116
bool is_null() const
Definition: handles.h:124
JSObject * global_proxy()
Definition: isolate.h:675
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::internal::Handle< T >::cast(), v8::internal::HandleScope::CloseAndEscape(), ENTER_V8, EXCEPTION_BAILOUT_CHECK_DO_CALLBACK, EXCEPTION_PREAMBLE, v8::internal::Isolate::global_proxy(), v8::internal::Handle< T >::is_null(), LOG_API, NULL, ON_BAILOUT, v8::Utils::OpenHandle(), and v8::Utils::ToLocal().

+ Here is the call graph for this function:

◆ V8_DEPRECATED()

v8::Script::V8_DEPRECATED ( "Use GetUnboundScript()->GetId()"  ,
int   GetId() 
)
inline

Definition at line 1009 of file v8.h.

1010  {
1011  return GetUnboundScript()->GetId();
1012  }
Local< UnboundScript > GetUnboundScript()
Returns the corresponding context-unbound script.
Definition: api.cc:1696

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