From 40a355a42d4a9444dc753c04c6608dade2f06a23 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Fri, 19 Apr 2024 03:13:27 +0200 Subject: Adding upstream version 125.0.1. Signed-off-by: Daniel Baumann --- js/src/frontend/CompileScript.cpp | 81 ++++++++++++--------------------------- 1 file changed, 25 insertions(+), 56 deletions(-) (limited to 'js/src/frontend/CompileScript.cpp') diff --git a/js/src/frontend/CompileScript.cpp b/js/src/frontend/CompileScript.cpp index 925b8201a2..b561d7d124 100644 --- a/js/src/frontend/CompileScript.cpp +++ b/js/src/frontend/CompileScript.cpp @@ -87,73 +87,46 @@ JS_PUBLIC_API const JSErrorReport* JS::GetFrontendWarningAt( return &fc->warnings()[index]; } -JS::CompilationStorage::~CompilationStorage() { - if (input_ && !isBorrowed_) { - js_delete(input_); - input_ = nullptr; - } -} - -size_t JS::CompilationStorage::sizeOfIncludingThis( - mozilla::MallocSizeOf mallocSizeOf) const { - size_t sizeOfCompilationInput = - input_ ? input_->sizeOfExcludingThis(mallocSizeOf) : 0; - return mallocSizeOf(this) + sizeOfCompilationInput; -} - -bool JS::CompilationStorage::allocateInput( - FrontendContext* fc, const JS::ReadOnlyCompileOptions& options) { - MOZ_ASSERT(!input_); - input_ = fc->getAllocator()->new_(options); - return !!input_; -} - -void JS::CompilationStorage::trace(JSTracer* trc) { - if (input_) { - input_->trace(trc); - } -} - template static already_AddRefed CompileGlobalScriptToStencilImpl( JS::FrontendContext* fc, const JS::ReadOnlyCompileOptions& options, - JS::SourceText& srcBuf, JS::CompilationStorage& compilationStorage) { + JS::SourceText& srcBuf) { ScopeKind scopeKind = options.nonSyntacticScope ? ScopeKind::NonSyntactic : ScopeKind::Global; JS::SourceText data(std::move(srcBuf)); - compilationStorage.allocateInput(fc, options); - if (!compilationStorage.hasInput()) { - return nullptr; - } + frontend::CompilationInput compilationInput(options); frontend::NoScopeBindingCache scopeCache; LifoAlloc tempLifoAlloc(JSContext::TEMP_LIFO_ALLOC_PRIMARY_CHUNK_SIZE); - RefPtr stencil_ = - frontend::CompileGlobalScriptToStencil(nullptr, fc, tempLifoAlloc, - compilationStorage.getInput(), - &scopeCache, data, scopeKind); + RefPtr stencil_ = frontend::CompileGlobalScriptToStencil( + nullptr, fc, tempLifoAlloc, compilationInput, &scopeCache, data, + scopeKind); + // CompilationInput initialized with CompileGlobalScriptToStencil only + // references information from the JS::Stencil context and the + // ref-counted ScriptSource, which are both GC-free. + JS_HAZ_VALUE_IS_GC_SAFE(compilationInput); return stencil_.forget(); } template static already_AddRefed CompileModuleScriptToStencilImpl( JS::FrontendContext* fc, const JS::ReadOnlyCompileOptions& optionsInput, - JS::SourceText& srcBuf, JS::CompilationStorage& compilationStorage) { + JS::SourceText& srcBuf) { JS::CompileOptions options(nullptr, optionsInput); options.setModule(); - compilationStorage.allocateInput(fc, options); - if (!compilationStorage.hasInput()) { - return nullptr; - } + frontend::CompilationInput compilationInput(options); NoScopeBindingCache scopeCache; js::LifoAlloc tempLifoAlloc(JSContext::TEMP_LIFO_ALLOC_PRIMARY_CHUNK_SIZE); - RefPtr stencil = - ParseModuleToStencil(nullptr, fc, tempLifoAlloc, - compilationStorage.getInput(), &scopeCache, srcBuf); + RefPtr stencil = ParseModuleToStencil( + nullptr, fc, tempLifoAlloc, compilationInput, &scopeCache, srcBuf); + // CompilationInput initialized with ParseModuleToStencil only + // references information from the JS::Stencil context and the + // ref-counted ScriptSource, which are both GC-free. + JS_HAZ_VALUE_IS_GC_SAFE(compilationInput); if (!stencil) { return nullptr; } @@ -164,42 +137,38 @@ static already_AddRefed CompileModuleScriptToStencilImpl( already_AddRefed JS::CompileGlobalScriptToStencil( JS::FrontendContext* fc, const JS::ReadOnlyCompileOptions& options, - JS::SourceText& srcBuf, - JS::CompilationStorage& compileStorage) { + JS::SourceText& srcBuf) { #ifdef DEBUG fc->assertNativeStackLimitThread(); #endif - return CompileGlobalScriptToStencilImpl(fc, options, srcBuf, compileStorage); + return CompileGlobalScriptToStencilImpl(fc, options, srcBuf); } already_AddRefed JS::CompileGlobalScriptToStencil( JS::FrontendContext* fc, const JS::ReadOnlyCompileOptions& options, - JS::SourceText& srcBuf, JS::CompilationStorage& compileStorage) { + JS::SourceText& srcBuf) { #ifdef DEBUG fc->assertNativeStackLimitThread(); #endif - return CompileGlobalScriptToStencilImpl(fc, options, srcBuf, compileStorage); + return CompileGlobalScriptToStencilImpl(fc, options, srcBuf); } already_AddRefed JS::CompileModuleScriptToStencil( JS::FrontendContext* fc, const JS::ReadOnlyCompileOptions& optionsInput, - JS::SourceText& srcBuf, - JS::CompilationStorage& compileStorage) { + JS::SourceText& srcBuf) { #ifdef DEBUG fc->assertNativeStackLimitThread(); #endif - return CompileModuleScriptToStencilImpl(fc, optionsInput, srcBuf, - compileStorage); + return CompileModuleScriptToStencilImpl(fc, optionsInput, srcBuf); } already_AddRefed JS::CompileModuleScriptToStencil( JS::FrontendContext* fc, const JS::ReadOnlyCompileOptions& optionsInput, - JS::SourceText& srcBuf, JS::CompilationStorage& compileStorage) { + JS::SourceText& srcBuf) { #ifdef DEBUG fc->assertNativeStackLimitThread(); #endif - return CompileModuleScriptToStencilImpl(fc, optionsInput, srcBuf, - compileStorage); + return CompileModuleScriptToStencilImpl(fc, optionsInput, srcBuf); } bool JS::PrepareForInstantiate(JS::FrontendContext* fc, JS::Stencil& stencil, -- cgit v1.2.3