source: webkit/trunk/Source/JavaScriptCore/parser/SourceProvider.h

Last change on this file was 292487, checked in by Chris Dumez, 3 years ago

Start replacing String(const char*) constructor with a String::fromLatin1(const char*) function
https://bugs.webkit.org/show_bug.cgi?id=238701

Reviewed by Geoffrey Garen.

Source/JavaScriptCore:

  • API/JSValue.mm:

(createStructHandlerMap):
(handerForStructTag):

  • API/JSWrapperMap.mm:

(allocateConstructorForCustomClass):

  • API/ObjCCallbackFunction.mm:

(JSC::ObjCCallbackFunctionImpl::name):

  • API/glib/JSCContext.cpp:

(jsc_context_check_syntax):

  • b3/air/testair.cpp:
  • bindings/ScriptFunctionCall.cpp:

(Deprecated::ScriptCallArgumentHandler::appendArgument):

  • debugger/DebuggerCallFrame.cpp:

(JSC::DebuggerCallFrame::functionName const):

  • heap/HeapSnapshotBuilder.cpp:

(JSC::HeapSnapshotBuilder::json):

  • inspector/JSGlobalObjectInspectorController.cpp:

(Inspector::JSGlobalObjectInspectorController::appendAPIBacktrace):

  • inspector/remote/socket/RemoteInspectorSocket.cpp:

(Inspector::RemoteInspector::sendMessageToBackend):

  • jit/ExecutableAllocator.cpp:

(JSC::dumpJITMemory):

  • jsc.cpp:

(JSC_DEFINE_HOST_FUNCTION):
(runWithOptions):
(CommandLine::parseArguments):

  • parser/Parser.cpp:

(JSC::Parser<LexerType>::parsePrimaryExpression):

  • parser/Parser.h:

(JSC::Parser::updateErrorMessage):

  • parser/SourceProvider.h:
  • runtime/BytecodeCacheError.cpp:

(JSC::BytecodeCacheError::StandardError::message const):

  • runtime/IntlLocale.cpp:

(JSC::IntlLocale::keywordValue const):
(JSC::IntlLocale::numberingSystems):

  • runtime/IntlObject.cpp:

(JSC::numberingSystemsForLocale):

  • runtime/Number.cpp:

(JSC::toStringWithRadix):
(JSC::JSC_DEFINE_HOST_FUNCTION):
(JSC::numberToStringInternal):
(JSC::int52ToString):

  • runtime/Options.cpp:

(JSC::Options::overrideAliasedOptionWithHeuristic):
(JSC::Options::setAliasedOption):

  • runtime/RegExp.cpp:

(JSC::JSC_DEFINE_HOST_FUNCTION):

  • runtime/SamplingProfiler.cpp:

(JSC::SamplingProfiler::StackFrame::displayName):

  • runtime/String.cpp:

(JSC::toLocaleCase):

  • testRegExp.cpp:

(parseArguments):

  • tools/CompilerTimingScope.cpp:
  • tools/FunctionAllowlist.cpp:

(JSC::FunctionAllowlist::FunctionAllowlist):

  • wasm/js/WebAssemblyModuleConstructor.cpp:

(JSC::JSC_DEFINE_HOST_FUNCTION):

Source/WebCore:

  • Modules/mediastream/libwebrtc/LibWebRTCMediaEndpoint.cpp:

(WebCore::LibWebRTCMediaEndpoint::createSessionDescriptionFailed):
(WebCore::LibWebRTCMediaEndpoint::setLocalSessionDescriptionFailed):
(WebCore::LibWebRTCMediaEndpoint::setRemoteSessionDescriptionFailed):
(WebCore::RTCStatsLogger::toJSONString const):

  • Modules/mediastream/libwebrtc/LibWebRTCUtils.cpp:

(WebCore::toException):
(WebCore::toRTCError):

  • Modules/webauthn/WebAuthenticationUtils.cpp:

(WebCore::buildAttestationMap):

  • Modules/webauthn/cbor/CBORValue.cpp:

(cbor::CBORValue::CBORValue):

  • Modules/webdatabase/Database.cpp:

(WebCore::Database::Database):
(WebCore::Database::getVersionFromDatabase):
(WebCore::Database::setVersionInDatabase):

  • animation/KeyframeEffect.cpp:

(WebCore::processPropertyIndexedKeyframes):

  • animation/KeyframeEffect.h:
  • bindings/js/SerializedScriptValue.cpp:

(WebCore::CloneSerializer::dumpIfTerminal):

  • contentextensions/ContentExtensionParser.cpp:

(WebCore::ContentExtensions::getDomainList):

  • crypto/algorithms/CryptoAlgorithmAES_CBC.cpp:
  • crypto/algorithms/CryptoAlgorithmAES_CFB.cpp:
  • crypto/algorithms/CryptoAlgorithmAES_CTR.cpp:
  • crypto/algorithms/CryptoAlgorithmAES_GCM.cpp:
  • crypto/algorithms/CryptoAlgorithmAES_KW.cpp:
  • crypto/algorithms/CryptoAlgorithmECDSA.cpp:
  • crypto/algorithms/CryptoAlgorithmHMAC.cpp:
  • crypto/algorithms/CryptoAlgorithmRSAES_PKCS1_v1_5.cpp:
  • crypto/algorithms/CryptoAlgorithmRSASSA_PKCS1_v1_5.cpp:
  • crypto/algorithms/CryptoAlgorithmRSA_OAEP.cpp:
  • crypto/algorithms/CryptoAlgorithmRSA_PSS.cpp:
  • css/DOMCSSCustomPropertyDescriptor.h:
  • css/makeprop.pl:
  • dom/DataTransfer.cpp:

(WebCore::DataTransfer::types const):

  • dom/TextDecoder.cpp:

(WebCore::TextDecoder::encoding const):

  • editing/ApplyStyleCommand.cpp:

(WebCore::styleSpanClassString):

  • editing/ReplaceSelectionCommand.cpp:

(WebCore::isInterchangeNewlineNode):
(WebCore::isInterchangeConvertedSpaceSpan):

  • editing/TextInsertionBaseCommand.cpp:

(WebCore::canAppendNewLineFeedToSelection):

  • html/HiddenInputType.cpp:

(WebCore::HiddenInputType::appendFormData const):

  • html/MediaFragmentURIParser.cpp:

(WebCore::MediaFragmentURIParser::parseFragments):

  • html/canvas/WebGLRenderingContext.cpp:

(WebCore::WebGLRenderingContext::getSupportedExtensions):

  • html/parser/HTMLPreloadScanner.cpp:

(WebCore::testPreloadScannerViewportSupport):

  • loader/FormSubmission.cpp:

(WebCore::FormSubmission::create):

  • loader/MediaResourceLoader.cpp:

(WebCore::MediaResource::responseReceived):

  • loader/cache/CachedApplicationManifest.cpp:

(WebCore::CachedApplicationManifest::encoding const):

  • loader/cache/CachedCSSStyleSheet.cpp:

(WebCore::CachedCSSStyleSheet::didAddClient):
(WebCore::CachedCSSStyleSheet::encoding const):
(WebCore::CachedCSSStyleSheet::checkNotify):

  • loader/cache/CachedSVGDocument.cpp:

(WebCore::CachedSVGDocument::encoding const):

  • loader/cache/CachedScript.cpp:

(WebCore::CachedScript::encoding const):

  • loader/cache/CachedXSLStyleSheet.cpp:

(WebCore::CachedXSLStyleSheet::encoding const):

  • page/cocoa/ResourceUsageThreadCocoa.mm:

(WebCore::threadInfos):

  • platform/cocoa/PasteboardCocoa.mm:

(WebCore::Pasteboard::read):

  • platform/gamepad/GamepadConstants.cpp:

(WebCore::standardGamepadMappingString):
(WebCore::xrStandardGamepadMappingString):

  • platform/graphics/FourCC.h:

(WTF::LogArgument<WebCore::FourCC>::toString):

  • platform/graphics/angle/GraphicsContextGLANGLE.cpp:

(WebCore::GraphicsContextGLANGLE::initialize):
(WebCore::GraphicsContextGLANGLE::getString):

  • platform/mac/ThreadCheck.mm:

(WebCoreReportThreadViolation):

  • platform/mediastream/RealtimeMediaSourceCenter.cpp:

(WebCore::RealtimeMediaSourceCenter::hashStringWithSalt):

  • platform/mock/PlatformSpeechSynthesizerMock.cpp:

(WebCore::PlatformSpeechSynthesizerMock::initializeVoiceList):

  • platform/sql/SQLiteDatabase.cpp:

(WebCore::SQLiteDatabase::authorizerFunction):

  • platform/text/cocoa/LocaleCocoa.mm:

(WebCore::LocaleCocoa::monthLabels):
(WebCore::LocaleCocoa::shortMonthLabels):

  • testing/Internals.cpp:

(WebCore::Internals::testDictionaryLogging):

  • xml/XPathValue.h:

(WebCore::XPath::Value::Value):

  • xml/XSLTProcessorLibxslt.cpp:

(WebCore::XSLTProcessor::parseErrorFunc):
(WebCore::docLoaderFunc):
(WebCore::XSLTProcessor::transformToString):

  • xml/parser/XMLDocumentParserLibxml2.cpp:

(WebCore::openFunc):

Source/WebCore/PAL:

  • pal/graphics/WebGPU/Impl/WebGPUAdapterImpl.cpp:

(PAL::WebGPU::adapterName):

  • pal/graphics/WebGPU/Impl/WebGPUDeviceImpl.cpp:

(PAL::WebGPU::DeviceImpl::popErrorScope):

Source/WebGPU:

  • WebGPU/APIConversions.h:

(WebGPU::fromAPI):

  • WebGPU/Adapter.mm:

(WebGPU::Adapter::requestDevice):

  • WebGPU/ComputePipeline.mm:

(WebGPU::createConstantValues):
(WebGPU::Device::createComputePipeline):

  • WebGPU/ShaderModule.mm:

(WebGPU::earlyCompileShaderModule):
(WebGPU::Device::createShaderModule):

Source/WTF:

  • wtf/Logger.h:

(WTF::LogArgument::toString):

  • wtf/text/WTFString.cpp:

(string):

  • wtf/text/WTFString.h:
  • Property svn:eol-style set to native
File size: 7.6 KB
Line 
1/*
2* Copyright (C) 2008-2021 Apple Inc. All rights reserved.
3*
4* Redistribution and use in source and binary forms, with or without
5* modification, are permitted provided that the following conditions
6* are met:
7*
8* 1. Redistributions of source code must retain the above copyright
9* notice, this list of conditions and the following disclaimer.
10* 2. Redistributions in binary form must reproduce the above copyright
11* notice, this list of conditions and the following disclaimer in the
12* documentation and/or other materials provided with the distribution.
13* 3. Neither the name of Apple Inc. ("Apple") nor the names of
14* its contributors may be used to endorse or promote products derived
15* from this software without specific prior written permission.
16*
17* THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
18* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20* DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
21* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
24* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27*/
28
29#pragma once
30
31#include "CachedBytecode.h"
32#include "CodeSpecializationKind.h"
33#include "SourceOrigin.h"
34#include <wtf/RefCounted.h>
35#include <wtf/text/TextPosition.h>
36#include <wtf/text/WTFString.h>
37
38namespace JSC {
39
40class SourceCode;
41class UnlinkedFunctionExecutable;
42class UnlinkedFunctionCodeBlock;
43
44enum class SourceProviderSourceType : uint8_t {
45Program,
46Module,
47WebAssembly,
48};
49
50using BytecodeCacheGenerator = Function<RefPtr<CachedBytecode>()>;
51
52class SourceProvider : public RefCounted<SourceProvider> {
53public:
54static const intptr_t nullID = 1;
55
56JS_EXPORT_PRIVATE SourceProvider(const SourceOrigin&, String&& sourceURL, const TextPosition& startPosition, SourceProviderSourceType);
57
58JS_EXPORT_PRIVATE virtual ~SourceProvider();
59
60virtual unsigned hash() const = 0;
61virtual StringView source() const = 0;
62virtual RefPtr<CachedBytecode> cachedBytecode() const { return nullptr; }
63virtual void cacheBytecode(const BytecodeCacheGenerator&) const { }
64virtual void updateCache(const UnlinkedFunctionExecutable*, const SourceCode&, CodeSpecializationKind, const UnlinkedFunctionCodeBlock*) const { }
65virtual void commitCachedBytecode() const { }
66
67StringView getRange(int start, int end) const
68{
69return source().substring(start, end - start);
70}
71
72const SourceOrigin& sourceOrigin() const { return m_sourceOrigin; }
73
74// This is NOT the path that should be used for computing relative paths from a script. Use SourceOrigin's URL for that, the values may or may not be the same...
75const String& sourceURL() const { return m_sourceURL; }
76const String& sourceURLDirective() const { return m_sourceURLDirective; }
77const String& sourceMappingURLDirective() const { return m_sourceMappingURLDirective; }
78
79TextPosition startPosition() const { return m_startPosition; }
80SourceProviderSourceType sourceType() const { return m_sourceType; }
81
82SourceID asID()
83{
84if (!m_id)
85getID();
86return m_id;
87}
88
89void setSourceURLDirective(const String& sourceURLDirective) { m_sourceURLDirective = sourceURLDirective; }
90void setSourceMappingURLDirective(const String& sourceMappingURLDirective) { m_sourceMappingURLDirective = sourceMappingURLDirective; }
91
92private:
93JS_EXPORT_PRIVATE void getID();
94
95SourceProviderSourceType m_sourceType;
96SourceOrigin m_sourceOrigin;
97String m_sourceURL;
98String m_sourceURLDirective;
99String m_sourceMappingURLDirective;
100TextPosition m_startPosition;
101SourceID m_id { 0 };
102};
103
104DECLARE_ALLOCATOR_WITH_HEAP_IDENTIFIER(StringSourceProvider);
105class StringSourceProvider : public SourceProvider {
106WTF_MAKE_FAST_ALLOCATED_WITH_HEAP_IDENTIFIER(StringSourceProvider);
107public:
108static Ref<StringSourceProvider> create(const String& source, const SourceOrigin& sourceOrigin, String sourceURL, const TextPosition& startPosition = TextPosition(), SourceProviderSourceType sourceType = SourceProviderSourceType::Program)
109{
110return adoptRef(*new StringSourceProvider(source, sourceOrigin, WTFMove(sourceURL), startPosition, sourceType));
111}
112
113unsigned hash() const override
114{
115return m_source.get().hash();
116}
117
118StringView source() const override
119{
120return m_source.get();
121}
122
123protected:
124StringSourceProvider(const String& source, const SourceOrigin& sourceOrigin, String&& sourceURL, const TextPosition& startPosition, SourceProviderSourceType sourceType)
125: SourceProvider(sourceOrigin, WTFMove(sourceURL), startPosition, sourceType)
126, m_source(source.isNull() ? *StringImpl::empty() : *source.impl())
127{
128}
129
130private:
131Ref<StringImpl> m_source;
132};
133
134#if ENABLE(WEBASSEMBLY)
135class BaseWebAssemblySourceProvider : public SourceProvider {
136public:
137virtual const uint8_t* data() = 0;
138virtual size_t size() const = 0;
139virtual void lockUnderlyingBuffer() { }
140virtual void unlockUnderlyingBuffer() { }
141
142protected:
143JS_EXPORT_PRIVATE BaseWebAssemblySourceProvider(const SourceOrigin&, String&&);
144};
145
146class WebAssemblySourceProvider final : public BaseWebAssemblySourceProvider {
147public:
148static Ref<WebAssemblySourceProvider> create(Vector<uint8_t>&& data, const SourceOrigin& sourceOrigin, String sourceURL)
149{
150return adoptRef(*new WebAssemblySourceProvider(WTFMove(data), sourceOrigin, WTFMove(sourceURL)));
151}
152
153unsigned hash() const final
154{
155return m_source.impl()->hash();
156}
157
158StringView source() const final
159{
160return m_source;
161}
162
163const uint8_t* data() final
164{
165return m_data.data();
166}
167
168size_t size() const final
169{
170return m_data.size();
171}
172
173const Vector<uint8_t>& dataVector() const
174{
175return m_data;
176}
177
178private:
179WebAssemblySourceProvider(Vector<uint8_t>&& data, const SourceOrigin& sourceOrigin, String&& sourceURL)
180: BaseWebAssemblySourceProvider(sourceOrigin, WTFMove(sourceURL))
181, m_source("[WebAssembly source]"_s)
182, m_data(WTFMove(data))
183{
184}
185
186String m_source;
187Vector<uint8_t> m_data;
188};
189
190// RAII class for managing a Wasm source provider's underlying buffer.
191class WebAssemblySourceProviderBufferGuard {
192public:
193explicit WebAssemblySourceProviderBufferGuard(BaseWebAssemblySourceProvider* sourceProvider)
194: m_sourceProvider(sourceProvider)
195{
196if (m_sourceProvider)
197m_sourceProvider->lockUnderlyingBuffer();
198}
199
200~WebAssemblySourceProviderBufferGuard()
201{
202if (m_sourceProvider)
203m_sourceProvider->unlockUnderlyingBuffer();
204}
205
206private:
207RefPtr<BaseWebAssemblySourceProvider> m_sourceProvider;
208};
209#endif
210
211} // namespace JSC
Note: See TracBrowser for help on using the repository browser.