#include "third_party/blink/renderer/bindings/core/v8/v8_script_runner.h"
#include "base/feature_list.h"
#include "base/metrics/histogram_functions.h"
#include "build/build_config.h"
#include "third_party/blink/public/common/features.h"
#include "third_party/blink/public/common/page/v8_compile_hints_histograms.h"
#include "third_party/blink/public/mojom/v8_cache_options.mojom-blink.h"
#include "third_party/blink/renderer/bindings/buildflags.h"
#include "third_party/blink/renderer/bindings/core/v8/binding_security.h"
#include "third_party/blink/renderer/bindings/core/v8/referrer_script_info.h"
#include "third_party/blink/renderer/bindings/core/v8/script_cache_consumer.h"
#include "third_party/blink/renderer/bindings/core/v8/script_evaluation_result.h"
#include "third_party/blink/renderer/bindings/core/v8/script_function.h"
#include "third_party/blink/renderer/bindings/core/v8/script_streamer.h"
#include "third_party/blink/renderer/bindings/core/v8/v8_binding_for_core.h"
#include "third_party/blink/renderer/bindings/core/v8/v8_code_cache.h"
#include "third_party/blink/renderer/bindings/core/v8/v8_compile_hints_common.h"
#include "third_party/blink/renderer/bindings/core/v8/v8_compile_hints_consumer.h"
#include "third_party/blink/renderer/bindings/core/v8/v8_compile_hints_producer.h"
#include "third_party/blink/renderer/bindings/core/v8/v8_initializer.h"
#include "third_party/blink/renderer/bindings/core/v8/v8_local_compile_hints_consumer.h"
#include "third_party/blink/renderer/bindings/core/v8/v8_local_compile_hints_producer.h"
#include "third_party/blink/renderer/bindings/core/v8/v8_throw_dom_exception.h"
#include "third_party/blink/renderer/bindings/core/v8/worker_or_worklet_script_controller.h"
#include "third_party/blink/renderer/core/execution_context/agent.h"
#include "third_party/blink/renderer/core/execution_context/execution_context.h"
#include "third_party/blink/renderer/core/frame/local_dom_window.h"
#include "third_party/blink/renderer/core/frame/local_frame.h"
#include "third_party/blink/renderer/core/inspector/inspector_trace_events.h"
#include "third_party/blink/renderer/core/loader/modulescript/module_script_creation_params.h"
#include "third_party/blink/renderer/core/page/page.h"
#include "third_party/blink/renderer/core/probe/core_probes.h"
#include "third_party/blink/renderer/core/script/classic_script.h"
#include "third_party/blink/renderer/core/script/modulator.h"
#include "third_party/blink/renderer/core/script/module_script.h"
#include "third_party/blink/renderer/core/workers/worker_or_worklet_global_scope.h"
#include "third_party/blink/renderer/platform/bindings/script_forbidden_scope.h"
#include "third_party/blink/renderer/platform/bindings/v8_throw_exception.h"
#include "third_party/blink/renderer/platform/instrumentation/histogram.h"
#include "third_party/blink/renderer/platform/instrumentation/tracing/trace_event.h"
#include "third_party/blink/renderer/platform/loader/fetch/cached_metadata.h"
#include "third_party/blink/renderer/platform/loader/fetch/url_loader/cached_metadata_handler.h"
#include "third_party/blink/renderer/platform/scheduler/public/event_loop.h"
#include "third_party/blink/renderer/platform/wtf/text/text_encoding.h"
namespace blink {
namespace {
const int kMaxRecursionDepth = …;
void ThrowStackOverflowException(
const v8::FunctionCallbackInfo<v8::Value>& info) { … }
void ThrowScriptForbiddenException(v8::Isolate* isolate) { … }
v8::MaybeLocal<v8::Value> ThrowStackOverflowExceptionIfNeeded(
v8::Isolate* isolate,
v8::MicrotaskQueue* microtask_queue) { … }
v8::MaybeLocal<v8::Script> CompileScriptInternal(
v8::Isolate* isolate,
ScriptState* script_state,
const ClassicScript& classic_script,
v8::ScriptOrigin origin,
v8::ScriptCompiler::CompileOptions compile_options,
v8::ScriptCompiler::NoCacheReason no_cache_reason,
bool can_use_crowdsourced_compile_hints,
std::optional<inspector_compile_script_event::V8ConsumeCacheResult>*
cache_result) { … }
int GetMicrotasksScopeDepth(v8::Isolate* isolate,
v8::MicrotaskQueue* microtask_queue) { … }
}
v8::MaybeLocal<v8::Script> V8ScriptRunner::CompileScript(
ScriptState* script_state,
const ClassicScript& classic_script,
v8::ScriptOrigin origin,
v8::ScriptCompiler::CompileOptions compile_options,
v8::ScriptCompiler::NoCacheReason no_cache_reason,
bool can_use_crowdsourced_compile_hints) { … }
v8::MaybeLocal<v8::Module> V8ScriptRunner::CompileModule(
v8::Isolate* isolate,
const ModuleScriptCreationParams& params,
const TextPosition& start_position,
v8::ScriptCompiler::CompileOptions compile_options,
v8::ScriptCompiler::NoCacheReason no_cache_reason,
const ReferrerScriptInfo& referrer_info) { … }
v8::MaybeLocal<v8::Value> V8ScriptRunner::RunCompiledScript(
v8::Isolate* isolate,
v8::Local<v8::Script> script,
v8::Local<v8::Data> host_defined_options,
ExecutionContext* context) { … }
namespace {
void DelayedProduceCodeCacheTask(ScriptState* script_state,
v8::Global<v8::Script> script,
CachedMetadataHandler* cache_handler,
size_t source_text_length,
KURL source_url,
TextPosition source_start_position) { … }
}
ScriptEvaluationResult V8ScriptRunner::CompileAndRunScript(
ScriptState* script_state,
ClassicScript* classic_script,
ExecuteScriptPolicy policy,
RethrowErrorsOption rethrow_errors) { … }
v8::MaybeLocal<v8::Value> V8ScriptRunner::CallAsConstructor(
v8::Isolate* isolate,
v8::Local<v8::Object> constructor,
ExecutionContext* context,
int argc,
v8::Local<v8::Value> argv[]) { … }
v8::MaybeLocal<v8::Value> V8ScriptRunner::CallFunction(
v8::Local<v8::Function> function,
ExecutionContext* context,
v8::Local<v8::Value> receiver,
int argc,
v8::Local<v8::Value> argv[],
v8::Isolate* isolate) { … }
class ModuleEvaluationRejectionCallback final
: public ScriptFunction::Callable { … };
ScriptEvaluationResult V8ScriptRunner::EvaluateModule(
ModuleScript* module_script,
RethrowErrorsOption rethrow_errors) { … }
void V8ScriptRunner::ReportException(v8::Isolate* isolate,
v8::Local<v8::Value> exception) { … }
}