v8
V8 is Google’s open source high-performance JavaScript and WebAssembly engine, written in C++.
Loading...
Searching...
No Matches
v8::ScriptCompiler Class Reference

#include <v8-script.h>

Collaboration diagram for v8::ScriptCompiler:

Classes

struct  CachedData
 
struct  CompilationDetails
 
class  ConsumeCodeCacheTask
 
class  ExternalSourceStream
 
class  ScriptStreamingTask
 
class  Source
 
class  StreamedSource
 

Public Types

enum class  InMemoryCacheResult { kNotAttempted , kHit , kMiss , kPartial }
 
enum  CompileOptions {
  kNoCompileOptions = 0 , kConsumeCodeCache = 1 << 0 , kEagerCompile = 1 << 1 , kProduceCompileHints = 1 << 2 ,
  kConsumeCompileHints = 1 << 3 , kFollowCompileHintsMagicComment = 1 << 4 , kFollowCompileHintsPerFunctionMagicComment = 1 << 5
}
 
enum  NoCacheReason {
  kNoCacheNoReason = 0 , kNoCacheBecauseCachingDisabled , kNoCacheBecauseNoResource , kNoCacheBecauseInlineScript ,
  kNoCacheBecauseModule , kNoCacheBecauseStreamingSource , kNoCacheBecauseInspector , kNoCacheBecauseScriptTooSmall ,
  kNoCacheBecauseCacheTooCold , kNoCacheBecauseV8Extension , kNoCacheBecauseExtensionModule , kNoCacheBecausePacScript ,
  kNoCacheBecauseInDocumentWrite , kNoCacheBecauseResourceWithNoCacheHandler , kNoCacheBecauseDeferredProduceCodeCache , kNoCacheBecauseStaticCodeCache
}
 

Static Public Member Functions

static bool CompileOptionsIsValid (CompileOptions compile_options)
 
static V8_WARN_UNUSED_RESULT MaybeLocal< UnboundScriptCompileUnboundScript (Isolate *isolate, Source *source, CompileOptions options=kNoCompileOptions, NoCacheReason no_cache_reason=kNoCacheNoReason)
 
static V8_WARN_UNUSED_RESULT MaybeLocal< ScriptCompile (Local< Context > context, Source *source, CompileOptions options=kNoCompileOptions, NoCacheReason no_cache_reason=kNoCacheNoReason)
 
static ScriptStreamingTaskStartStreaming (Isolate *isolate, StreamedSource *source, ScriptType type=ScriptType::kClassic, CompileOptions options=kNoCompileOptions, CompileHintCallback compile_hint_callback=nullptr, void *compile_hint_callback_data=nullptr)
 
static ConsumeCodeCacheTaskStartConsumingCodeCache (Isolate *isolate, std::unique_ptr< CachedData > source)
 
static ConsumeCodeCacheTaskStartConsumingCodeCacheOnBackground (Isolate *isolate, std::unique_ptr< CachedData > source)
 
static V8_WARN_UNUSED_RESULT MaybeLocal< ScriptCompile (Local< Context > context, StreamedSource *source, Local< String > full_source_string, const ScriptOrigin &origin)
 
static uint32_t CachedDataVersionTag ()
 
static V8_WARN_UNUSED_RESULT MaybeLocal< ModuleCompileModule (Isolate *isolate, Source *source, CompileOptions options=kNoCompileOptions, NoCacheReason no_cache_reason=kNoCacheNoReason)
 
static V8_WARN_UNUSED_RESULT MaybeLocal< ModuleCompileModule (Local< Context > context, StreamedSource *v8_source, Local< String > full_source_string, const ScriptOrigin &origin)
 
static V8_WARN_UNUSED_RESULT MaybeLocal< FunctionCompileFunction (Local< Context > context, Source *source, size_t arguments_count=0, Local< String > arguments[]=nullptr, size_t context_extension_count=0, Local< Object > context_extensions[]=nullptr, CompileOptions options=kNoCompileOptions, NoCacheReason no_cache_reason=kNoCacheNoReason)
 
static CachedDataCreateCodeCache (Local< UnboundScript > unbound_script)
 
static CachedDataCreateCodeCache (Local< UnboundModuleScript > unbound_module_script)
 
static CachedDataCreateCodeCacheForFunction (Local< Function > function)
 

Static Private Member Functions

static V8_WARN_UNUSED_RESULT MaybeLocal< UnboundScriptCompileUnboundInternal (Isolate *isolate, Source *source, CompileOptions options, NoCacheReason no_cache_reason)
 
static V8_WARN_UNUSED_RESULT MaybeLocal< FunctionCompileFunctionInternal (Local< Context > context, Source *source, size_t arguments_count, Local< String > arguments[], size_t context_extension_count, Local< Object > context_extensions[], CompileOptions options, NoCacheReason no_cache_reason, Local< ScriptOrModule > *script_or_module_out)
 

Detailed Description

For compiling scripts.

Definition at line 402 of file v8-script.h.

Member Enumeration Documentation

◆ CompileOptions

Enumerator
kNoCompileOptions 
kConsumeCodeCache 
kEagerCompile 
kProduceCompileHints 
kConsumeCompileHints 
kFollowCompileHintsMagicComment 
kFollowCompileHintsPerFunctionMagicComment 

Definition at line 673 of file v8-script.h.

◆ InMemoryCacheResult

Enumerator
kNotAttempted 
kHit 
kMiss 
kPartial 

Definition at line 462 of file v8-script.h.

◆ NoCacheReason

The reason for which we are not requesting or providing a code cache.

Enumerator
kNoCacheNoReason 
kNoCacheBecauseCachingDisabled 
kNoCacheBecauseNoResource 
kNoCacheBecauseInlineScript 
kNoCacheBecauseModule 
kNoCacheBecauseStreamingSource 
kNoCacheBecauseInspector 
kNoCacheBecauseScriptTooSmall 
kNoCacheBecauseCacheTooCold 
kNoCacheBecauseV8Extension 
kNoCacheBecauseExtensionModule 
kNoCacheBecausePacScript 
kNoCacheBecauseInDocumentWrite 
kNoCacheBecauseResourceWithNoCacheHandler 
kNoCacheBecauseDeferredProduceCodeCache 
kNoCacheBecauseStaticCodeCache 

Definition at line 706 of file v8-script.h.

Member Function Documentation

◆ CachedDataVersionTag()

uint32_t v8::ScriptCompiler::CachedDataVersionTag ( )
static

Return a version tag for CachedData for the current V8 version & flags.

This value is meant only for determining whether a previously generated CachedData instance is still valid; the tag has no other meaing.

Background: The data carried by CachedData may depend on the exact V8 version number or current compiler flags. This means that when persisting CachedData, the embedder must take care to not pass in data from another V8 version, or the same version with different features enabled.

The easiest way to do so is to clear the embedder's cache on any such change.

Alternatively, this tag can be stored alongside the cached data and compared when it is being used.

Definition at line 2668 of file api.cc.

Here is the call graph for this function:

◆ Compile() [1/2]

MaybeLocal< Script > v8::ScriptCompiler::Compile ( Local< Context > context,
Source * source,
CompileOptions options = kNoCompileOptions,
NoCacheReason no_cache_reason = kNoCacheNoReason )
static

Compiles the specified script (bound to current context).

Parameters
sourceScript source code.
pre_dataPre-parsing data, as obtained by ScriptData::PreCompile() using pre_data speeds compilation if it's done multiple times. Owned by caller, no references are kept when this function returns.
Returns
Compiled script object, bound to the context that was active when this function was called. When run it will always use this context.

Definition at line 2438 of file api.cc.

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

◆ Compile() [2/2]

MaybeLocal< Script > v8::ScriptCompiler::Compile ( Local< Context > context,
StreamedSource * source,
Local< String > full_source_string,
const ScriptOrigin & origin )
static

Compiles a streamed script (bound to current context).

This can only be called after the streaming has finished (ScriptStreamingTask has been run). V8 doesn't construct the source string during streaming, so the embedder needs to pass the full source here.

Definition at line 2630 of file api.cc.

Here is the call graph for this function:

◆ CompileFunction()

V8_WARN_UNUSED_RESULT MaybeLocal< Function > v8::ScriptCompiler::CompileFunction ( Local< Context > context,
Source * source,
size_t arguments_count = 0,
Local< String > arguments[] = nullptr,
size_t context_extension_count = 0,
Local< Object > context_extensions[] = nullptr,
CompileOptions options = kNoCompileOptions,
NoCacheReason no_cache_reason = kNoCacheNoReason )
static

Compile a function for a given context. This is equivalent to running

with (obj) { return function(args) { ... } }

It is possible to specify multiple context extensions (obj in the above example).

Definition at line 2473 of file api.cc.

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

◆ CompileFunctionInternal()

static V8_WARN_UNUSED_RESULT MaybeLocal< Function > v8::ScriptCompiler::CompileFunctionInternal ( Local< Context > context,
Source * source,
size_t arguments_count,
Local< String > arguments[],
size_t context_extension_count,
Local< Object > context_extensions[],
CompileOptions options,
NoCacheReason no_cache_reason,
Local< ScriptOrModule > * script_or_module_out )
staticprivate

◆ CompileModule() [1/2]

MaybeLocal< Module > v8::ScriptCompiler::CompileModule ( Isolate * isolate,
Source * source,
CompileOptions options = kNoCompileOptions,
NoCacheReason no_cache_reason = kNoCacheNoReason )
static

Compile an ES module, returning a Module that encapsulates the compiled code.

Corresponds to the ParseModule abstract operation in the ECMAScript specification.

Definition at line 2454 of file api.cc.

Here is the call graph for this function:

◆ CompileModule() [2/2]

MaybeLocal< Module > v8::ScriptCompiler::CompileModule ( Local< Context > context,
StreamedSource * v8_source,
Local< String > full_source_string,
const ScriptOrigin & origin )
static

Compiles a streamed module script.

This can only be called after the streaming has finished (ScriptStreamingTask has been run). V8 doesn't construct the source string during streaming, so the embedder needs to pass the full source here.

Definition at line 2651 of file api.cc.

Here is the call graph for this function:

◆ CompileOptionsIsValid()

static bool v8::ScriptCompiler::CompileOptionsIsValid ( CompileOptions compile_options)
inlinestatic

Definition at line 683 of file v8-script.h.

Here is the caller graph for this function:

◆ CompileUnboundInternal()

MaybeLocal< UnboundScript > v8::ScriptCompiler::CompileUnboundInternal ( Isolate * isolate,
Source * source,
CompileOptions options,
NoCacheReason no_cache_reason )
staticprivate

Definition at line 2366 of file api.cc.

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

◆ CompileUnboundScript()

MaybeLocal< UnboundScript > v8::ScriptCompiler::CompileUnboundScript ( Isolate * isolate,
Source * source,
CompileOptions options = kNoCompileOptions,
NoCacheReason no_cache_reason = kNoCacheNoReason )
static

Compiles the specified script (context-independent). Cached data as part of the source object can be optionally produced to be consumed later to speed up compilation of identical source scripts.

Note that when producing cached data, the source must point to NULL for cached data. When consuming cached data, the cached data must have been produced by the same version of V8, and the embedder needs to ensure the cached data is the correct one for the given script.

Parameters
sourceScript source code.
Returns
Compiled script object (context independent; for running it must be bound to a context).

Definition at line 2428 of file api.cc.

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

◆ CreateCodeCache() [1/2]

ScriptCompiler::CachedData * v8::ScriptCompiler::CreateCodeCache ( Local< UnboundModuleScript > unbound_module_script)
static

Creates and returns code cache for the specified unbound_module_script. This will return nullptr if the script cannot be serialized. The CachedData returned by this function should be owned by the caller.

Definition at line 2688 of file api.cc.

Here is the call graph for this function:

◆ CreateCodeCache() [2/2]

ScriptCompiler::CachedData * v8::ScriptCompiler::CreateCodeCache ( Local< UnboundScript > unbound_script)
static

Creates and returns code cache for the specified unbound_script. This will return nullptr if the script cannot be serialized. The CachedData returned by this function should be owned by the caller.

Definition at line 2673 of file api.cc.

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

◆ CreateCodeCacheForFunction()

ScriptCompiler::CachedData * v8::ScriptCompiler::CreateCodeCacheForFunction ( Local< Function > function)
static

Creates and returns code cache for the specified function that was previously produced by CompileFunction. This will return nullptr if the script cannot be serialized. The CachedData returned by this function should be owned by the caller.

Definition at line 2703 of file api.cc.

Here is the call graph for this function:

◆ StartConsumingCodeCache()

ScriptCompiler::ConsumeCodeCacheTask * v8::ScriptCompiler::StartConsumingCodeCache ( Isolate * isolate,
std::unique_ptr< CachedData > source )
static

Definition at line 2594 of file api.cc.

◆ StartConsumingCodeCacheOnBackground()

ScriptCompiler::ConsumeCodeCacheTask * v8::ScriptCompiler::StartConsumingCodeCacheOnBackground ( Isolate * isolate,
std::unique_ptr< CachedData > source )
static

Definition at line 2605 of file api.cc.

◆ StartStreaming()

ScriptCompiler::ScriptStreamingTask * v8::ScriptCompiler::StartStreaming ( Isolate * isolate,
StreamedSource * source,
v8::ScriptType type = ScriptType::kClassic,
CompileOptions options = kNoCompileOptions,
CompileHintCallback compile_hint_callback = nullptr,
void * compile_hint_callback_data = nullptr )
static

Returns a task which streams script data into V8, or NULL if the script cannot be streamed. The user is responsible for running the task on a background thread and deleting it. When ran, the task starts parsing the script, and it will request data from the StreamedSource as needed. When ScriptStreamingTask::Run exits, all data has been streamed and the script can be compiled (see Compile below).

This API allows to start the streaming with as little data as possible, and the remaining data (for example, the ScriptOrigin) is passed to Compile.

Definition at line 2540 of file api.cc.

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

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