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

Last change on this file was 284075, checked in by [email protected], 4 years ago

Use std::variant instead of WTF::Variant
https://bugs.webkit.org/show_bug.cgi?id=231629

Patch by Alex Christensen <[email protected]> on 2021-10-12
Reviewed by Chris Dumez.

Source/JavaScriptCore:

  • bytecode/StructureStubClearingWatchpoint.h:
  • dfg/DFGSpeculativeJIT.cpp:

(JSC::DFG::SpeculativeJIT::compileCallDOM):

  • jit/AssemblyHelpers.cpp:

(JSC::AssemblyHelpers::branchIfValue):

  • jit/AssemblyHelpers.h:

(JSC::AssemblyHelpers::branchIfTruthy):
(JSC::AssemblyHelpers::branchIfFalsey):

  • jit/SnippetReg.h:
  • jsc.cpp:
  • parser/Lexer.h:
  • parser/VariableEnvironment.h:
  • runtime/BytecodeCacheError.h:
  • runtime/CachePayload.cpp:

(JSC::CachePayload::CachePayload):

  • runtime/CachePayload.h:
  • runtime/CacheUpdate.h:
  • runtime/ISO8601.cpp:

(JSC::ISO8601::parseTimeZoneBracketedAnnotation):

  • runtime/ISO8601.h:
  • wasm/WasmLLIntGenerator.cpp:

Source/WebCore:

  • Modules/async-clipboard/ClipboardItemBindingsDataSource.h:
  • Modules/cache/DOMCacheEngine.h:
  • Modules/fetch/FetchBody.h:
  • Modules/fetch/FetchBodyOwner.h:
  • Modules/fetch/FetchHeaders.h:
  • Modules/fetch/FetchRequest.h:
  • Modules/fetch/FetchResponse.h:
  • Modules/indexeddb/IDBCursor.h:
  • Modules/indexeddb/IDBDatabase.h:
  • Modules/indexeddb/IDBKey.h:
  • Modules/indexeddb/IDBKeyData.h:
  • Modules/indexeddb/IDBKeyPath.h:
  • Modules/indexeddb/IDBRequest.h:
  • Modules/mediacontrols/MediaControlsHost.cpp:

(WebCore::MediaControlsHost::showMediaControlsContextMenu):

  • Modules/mediacontrols/MediaControlsHost.h:
  • Modules/mediastream/MediaDevices.cpp:

(WebCore::createMediaConstraints):

  • Modules/mediastream/MediaDevices.h:
  • Modules/mediastream/MediaTrackConstraints.h:
  • Modules/mediastream/RTCIceServer.h:
  • Modules/mediastream/RTCPeerConnection.h:
  • Modules/mediastream/RTCRtpTransform.h:
  • Modules/mediastream/libwebrtc/LibWebRTCDataChannelHandler.h:
  • Modules/mediastream/libwebrtc/LibWebRTCRtpSenderBackend.h:
  • Modules/paymentrequest/PaymentMethodChangeEvent.h:
  • Modules/paymentrequest/PaymentRequest.h:
  • Modules/push-api/PushEventInit.h:
  • Modules/push-api/PushSubscriptionOptionsInit.h:
  • Modules/speech/SpeechRecognitionUpdate.h:
  • Modules/webaudio/AudioContextOptions.h:
  • Modules/webaudio/AudioNode.h:
  • Modules/webxr/WebXRWebGLLayer.h:
  • accessibility/AXObjectCache.h:
  • accessibility/AccessibilityObjectInterface.h:
  • accessibility/isolatedtree/AXIsolatedTree.h:
  • animation/EffectTiming.h:
  • animation/KeyframeEffect.cpp:

(WebCore::KeyframeEffect::create):

  • animation/KeyframeEffect.h:
  • animation/OptionalEffectTiming.h:
  • bindings/IDLTypes.h:
  • bindings/js/BufferSource.h:
  • bindings/js/JSValueInWrappedObject.h:
  • crypto/CryptoAlgorithm.h:
  • crypto/CryptoKey.h:
  • crypto/SubtleCrypto.h:
  • crypto/parameters/CryptoAlgorithmEcdsaParams.h:
  • crypto/parameters/CryptoAlgorithmHkdfParams.h:
  • crypto/parameters/CryptoAlgorithmHmacKeyParams.h:
  • crypto/parameters/CryptoAlgorithmPbkdf2Params.h:
  • crypto/parameters/CryptoAlgorithmRsaHashedImportParams.h:
  • crypto/parameters/CryptoAlgorithmRsaHashedKeyGenParams.h:
  • css/CSSCustomPropertyValue.h:
  • css/DOMMatrix.cpp:

(WebCore::DOMMatrix::create):

  • css/DOMMatrix.h:
  • css/DOMMatrixReadOnly.cpp:

(WebCore::DOMMatrixReadOnly::create):

  • css/DOMMatrixReadOnly.h:
  • css/FontFace.h:
  • css/StyleRule.h:
  • css/parser/CSSPropertyParserHelpers.h:
  • css/typedom/CSSNumericValue.h:
  • css/typedom/CSSUnparsedValue.h:
  • dom/Document.h:
  • dom/DocumentMarker.h:
  • dom/Element.cpp:

(WebCore::Element::scrollIntoView):
(WebCore::Element::animate):

  • dom/Element.h:
  • dom/EventTarget.h:
  • dom/MessageEvent.h:
  • dom/Node.h:
  • editing/AlternativeTextController.h:
  • editing/TextCheckingHelper.cpp:

(WebCore::TextCheckingHelper::findFirstMisspelledWordOrUngrammaticalPhrase const):

  • editing/TextCheckingHelper.h:
  • editing/TextManipulationController.h:
  • fileapi/Blob.h:
  • fileapi/FileReader.cpp:

(WebCore::FileReader::result const):

  • fileapi/FileReader.h:
  • fileapi/NetworkSendQueue.h:
  • html/DOMFormData.h:
  • html/HTMLAllCollection.cpp:

(WebCore::HTMLAllCollection::namedOrIndexedItemOrItems const):
(WebCore::HTMLAllCollection::namedItemOrItems const):

  • html/HTMLAllCollection.h:
  • html/HTMLDocument.cpp:

(WebCore::HTMLDocument::namedItem):

  • html/HTMLDocument.h:
  • html/HTMLFormControlsCollection.cpp:

(WebCore::HTMLFormControlsCollection::namedItemOrItems const):

  • html/HTMLFormControlsCollection.h:
  • html/HTMLFormElement.cpp:

(WebCore::HTMLFormElement::namedItem):

  • html/HTMLFormElement.h:
  • html/HTMLMediaElement.h:
  • html/HTMLOptionsCollection.h:
  • html/HTMLSelectElement.h:
  • html/ImageBitmap.h:
  • html/OffscreenCanvas.h:
  • html/URLSearchParams.cpp:

(WebCore::URLSearchParams::create):

  • html/URLSearchParams.h:
  • html/canvas/CanvasRenderingContext2DBase.h:
  • html/canvas/CanvasStyle.h:
  • html/canvas/WebGL2RenderingContext.h:
  • html/canvas/WebGLAny.h:
  • html/canvas/WebGLMultiDraw.h:
  • html/canvas/WebGLRenderingContextBase.h:
  • html/track/TrackEvent.h:
  • html/track/VTTCue.h:
  • inspector/InspectorCanvas.h:
  • inspector/InspectorShaderProgram.h:
  • layout/integration/InlineIteratorBox.h:
  • layout/integration/InlineIteratorLine.h:
  • page/DiagnosticLoggingClient.h:
  • page/IntersectionObserver.h:
  • page/Page.h:
  • page/Performance.h:
  • page/PerformanceMeasureOptions.h:
  • page/PerformanceUserTiming.cpp:

(WebCore::PerformanceUserTiming::convertMarkToTimestamp const):

  • page/PerformanceUserTiming.h:
  • page/scrolling/ScrollingCoordinator.h:
  • platform/PasteboardCustomData.cpp:

(WebCore::copyPlatformData):
(WebCore::PasteboardCustomData::forEachPlatformStringOrBuffer const):

  • platform/PasteboardCustomData.h:
  • platform/SharedBuffer.h:
  • platform/audio/AudioStreamDescription.h:
  • platform/encryptedmedia/CDMProxy.h:
  • platform/graphics/DecodingOptions.h:
  • platform/graphics/FontCascadeDescription.h:
  • platform/graphics/Gradient.h:
  • platform/graphics/InlinePathData.h:
  • platform/graphics/cocoa/SourceBufferParser.h:
  • platform/graphics/cocoa/SourceBufferParserWebM.h:
  • platform/graphics/displaylists/DisplayListResourceHeap.h:
  • platform/mediastream/mac/DisplayCaptureSourceMac.h:
  • platform/mock/MockMediaDevice.h:
  • platform/network/DNS.h:
  • platform/network/FormData.h:
  • platform/sql/SQLValue.h:
  • platform/xr/PlatformXR.h:
  • rendering/RenderBlockFlow.h:
  • testing/TypeConversions.h:
  • workers/SharedWorker.cpp:

(WebCore::SharedWorker::SharedWorker):

  • workers/SharedWorker.h:
  • workers/service/ExtendableMessageEvent.h:
  • workers/service/ServiceWorkerTypes.h:
  • xml/XMLHttpRequest.h:

Source/WebKit:

  • NetworkProcess/NetworkLoadChecker.h:
  • NetworkProcess/cache/NetworkCacheData.h:
  • Platform/IPC/ArgumentCoders.h:

(IPC::VariantCoder::encode):
(IPC::VariantCoder::decode):

  • Platform/IPC/Attachment.h:
  • Platform/IPC/MessageReceiveQueueMap.h:
  • Shared/SessionState.h:
  • Shared/WebCoreArgumentCoders.h:
  • Shared/WebPreferencesStore.h:
  • Shared/mac/MediaFormatReader/MediaSampleCursor.h:
  • UIProcess/API/APIWebAuthenticationPanel.h:
  • UIProcess/API/C/WKMockMediaDevice.cpp:

(WKAddMockMediaDevice):

  • UIProcess/API/Cocoa/WKWebView.mm:

(-[WKWebView _showSafeBrowsingWarning:completionHandler:]):
(-[WKWebView _showSafeBrowsingWarningWithURL:title:warning:detailsWithLinks:completionHandler:]):

  • UIProcess/API/Cocoa/WKWebViewInternal.h:
  • UIProcess/API/Cocoa/_WKWebAuthenticationPanel.mm:

(-[_WKWebAuthenticationPanel makeCredentialWithChallenge:origin:options:completionHandler:]):
(-[_WKWebAuthenticationPanel getAssertionWithChallenge:origin:options:completionHandler:]):

  • UIProcess/Automation/SimulatedInputDispatcher.h:
  • UIProcess/Automation/WebAutomationSession.cpp:

(WebKit::WebAutomationSession::simulateKeyboardInteraction):

  • UIProcess/Automation/WebAutomationSession.h:
  • UIProcess/Automation/ios/WebAutomationSessionIOS.mm:

(WebKit::WebAutomationSession::platformSimulateKeyboardInteraction):

  • UIProcess/Automation/mac/WebAutomationSessionMac.mm:

(WebKit::WebAutomationSession::platformSimulateKeyboardInteraction):

  • UIProcess/Cocoa/SOAuthorization/SubFrameSOAuthorizationSession.h:
  • UIProcess/Cocoa/WKSafeBrowsingWarning.h:
  • UIProcess/Cocoa/WKSafeBrowsingWarning.mm:

(-[WKSafeBrowsingWarning initWithFrame:safeBrowsingWarning:completionHandler:]):

  • UIProcess/Cocoa/WebViewImpl.h:
  • UIProcess/Cocoa/WebViewImpl.mm:

(WebKit::WebViewImpl::showSafeBrowsingWarning):

  • UIProcess/PageClient.h:

(WebKit::PageClient::showSafeBrowsingWarning):

  • UIProcess/ProcessThrottler.h:
  • UIProcess/WebAuthentication/Authenticator.h:
  • UIProcess/WebAuthentication/AuthenticatorManager.cpp:

(WebKit::WebCore::getRpId):
(WebKit::WebCore::getUserName):

  • UIProcess/WebAuthentication/AuthenticatorManager.h:
  • UIProcess/WebAuthentication/WebAuthenticationRequestData.cpp:

(WebKit::getClientDataType):
(WebKit::getUserVerificationRequirement):

  • UIProcess/WebAuthentication/WebAuthenticationRequestData.h:
  • UIProcess/WebAuthentication/WebAuthenticatorCoordinatorProxy.cpp:

(WebKit::WebAuthenticatorCoordinatorProxy::handleRequest):

  • UIProcess/WebPageProxy.cpp:

(WebKit::WebPageProxy::receivedPolicyDecision):

  • UIProcess/WebPageProxy.h:
  • UIProcess/ios/PageClientImplIOS.h:
  • UIProcess/ios/PageClientImplIOS.mm:

(WebKit::PageClientImpl::showSafeBrowsingWarning):

  • UIProcess/mac/PageClientImplMac.h:
  • UIProcess/mac/PageClientImplMac.mm:

(WebKit::PageClientImpl::showSafeBrowsingWarning):

  • WebAuthnProcess/WebAuthnConnectionToWebProcess.cpp:

(WebKit::WebAuthnConnectionToWebProcess::handleRequest):

  • WebProcess/GPU/graphics/ImageBufferBackendHandle.h:
  • WebProcess/Storage/WebServiceWorkerFetchTaskClient.h:
  • WebProcess/WebPage/RemoteLayerTree/PlatformCAAnimationRemote.h:

Source/WebKitLegacy/mac:

  • DOM/DOMHTMLSelectElement.mm:

(-[DOMHTMLSelectElement add:before:]):

Source/WTF:

  • wtf/LikelyDenseUnsignedIntegerSet.h:
  • wtf/SmallSet.h:
  • wtf/text/TextBreakIterator.cpp:

(WTF::mapModeToBackingIterator):

  • wtf/text/TextBreakIterator.h:
  • wtf/text/cocoa/TextBreakIteratorInternalICUCocoa.cpp:

(WTF::mapModeToBackingIterator):

  • Property svn:eol-style set to native
File size: 14.4 KB
Line 
1/*
2 * Copyright (C) 1999-2000 Harri Porten ([email protected])
3 * Copyright (C) 2002-2019 Apple Inc. All rights reserved.
4 * Copyright (C) 2010 Zoltan Herczeg ([email protected])
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Library General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Library General Public License for more details.
15 *
16 * You should have received a copy of the GNU Library General Public License
17 * along with this library; see the file COPYING.LIB. If not, write to
18 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19 * Boston, MA 02110-1301, USA.
20 *
21 */
22
23#pragma once
24
25#include "Lookup.h"
26#include "ParserArena.h"
27#include "ParserModes.h"
28#include "ParserTokens.h"
29#include "SourceCode.h"
30#include <wtf/ASCIICType.h>
31#include <wtf/Vector.h>
32#include <wtf/unicode/CharacterNames.h>
33
34namespace JSC {
35
36struct ParsedUnicodeEscapeValue;
37
38enum class LexerFlags : uint8_t {
39 IgnoreReservedWords = 1 << 0,
40 DontBuildStrings = 1 << 1,
41 DontBuildKeywords = 1 << 2
42};
43
44bool isLexerKeyword(const Identifier&);
45
46template <typename T>
47class Lexer {
48 WTF_MAKE_NONCOPYABLE(Lexer);
49 WTF_MAKE_FAST_ALLOCATED;
50
51public:
52 Lexer(VM&, JSParserBuiltinMode, JSParserScriptMode);
53 ~Lexer();
54
55 // Character manipulation functions.
56 static bool isWhiteSpace(T character);
57 static bool isLineTerminator(T character);
58 static unsigned char convertHex(int c1, int c2);
59 static UChar convertUnicode(int c1, int c2, int c3, int c4);
60
61 // Functions to set up parsing.
62 void setCode(const SourceCode&, ParserArena*);
63 void setIsReparsingFunction() { m_isReparsingFunction = true; }
64 bool isReparsingFunction() const { return m_isReparsingFunction; }
65
66 JSTokenType lex(JSToken*, OptionSet<LexerFlags>, bool strictMode);
67 JSTokenType lexWithoutClearingLineTerminator(JSToken*, OptionSet<LexerFlags>, bool strictMode);
68 bool nextTokenIsColon();
69 int lineNumber() const { return m_lineNumber; }
70 ALWAYS_INLINE int currentOffset() const { return offsetFromSourcePtr(m_code); }
71 ALWAYS_INLINE int currentLineStartOffset() const { return offsetFromSourcePtr(m_lineStart); }
72 ALWAYS_INLINE JSTextPosition currentPosition() const
73 {
74 return JSTextPosition(m_lineNumber, currentOffset(), currentLineStartOffset());
75 }
76 JSTextPosition positionBeforeLastNewline() const { return m_positionBeforeLastNewline; }
77 JSTokenLocation lastTokenLocation() const { return m_lastTokenLocation; }
78 void setLastLineNumber(int lastLineNumber) { m_lastLineNumber = lastLineNumber; }
79 int lastLineNumber() const { return m_lastLineNumber; }
80 bool hasLineTerminatorBeforeToken() const { return m_hasLineTerminatorBeforeToken; }
81 JSTokenType scanRegExp(JSToken*, UChar patternPrefix = 0);
82 enum class RawStringsBuildMode { BuildRawStrings, DontBuildRawStrings };
83 JSTokenType scanTemplateString(JSToken*, RawStringsBuildMode);
84
85 // Functions for use after parsing.
86 bool sawError() const { return m_error; }
87 void setSawError(bool sawError) { m_error = sawError; }
88 String getErrorMessage() const { return m_lexErrorMessage; }
89 void setErrorMessage(const String& errorMessage) { m_lexErrorMessage = errorMessage; }
90 String sourceURLDirective() const { return m_sourceURLDirective; }
91 String sourceMappingURLDirective() const { return m_sourceMappingURLDirective; }
92 void clear();
93 void setOffset(int offset, int lineStartOffset)
94 {
95 m_error = 0;
96 m_lexErrorMessage = String();
97
98 m_code = sourcePtrFromOffset(offset);
99 m_lineStart = sourcePtrFromOffset(lineStartOffset);
100 ASSERT(currentOffset() >= currentLineStartOffset());
101
102 m_buffer8.shrink(0);
103 m_buffer16.shrink(0);
104 if (LIKELY(m_code < m_codeEnd))
105 m_current = *m_code;
106 else
107 m_current = 0;
108 }
109 void setLineNumber(int line)
110 {
111 ASSERT(line >= 0);
112 m_lineNumber = line;
113 }
114 void setHasLineTerminatorBeforeToken(bool terminator)
115 {
116 m_hasLineTerminatorBeforeToken = terminator;
117 }
118
119 JSTokenType lexExpectIdentifier(JSToken*, OptionSet<LexerFlags>, bool strictMode);
120
121 ALWAYS_INLINE StringView getToken(const JSToken& token)
122 {
123 SourceProvider* sourceProvider = m_source->provider();
124 ASSERT_WITH_MESSAGE(token.m_location.startOffset <= token.m_location.endOffset, "Calling this function with the baked token.");
125 return sourceProvider->getRange(token.m_location.startOffset, token.m_location.endOffset);
126 }
127
128 size_t codeLength() { return m_codeEnd - m_codeStart; }
129
130private:
131 void record8(int);
132 void append8(const T*, size_t);
133 void record16(int);
134 void record16(T);
135 void recordUnicodeCodePoint(UChar32);
136 void append16(const LChar*, size_t);
137 void append16(const UChar* characters, size_t length) { m_buffer16.append(characters, length); }
138
139 UChar32 currentCodePoint() const;
140 ALWAYS_INLINE void shift();
141 ALWAYS_INLINE bool atEnd() const;
142 ALWAYS_INLINE T peek(int offset) const;
143
144 ParsedUnicodeEscapeValue parseUnicodeEscape();
145 void shiftLineTerminator();
146
147 ALWAYS_INLINE int offsetFromSourcePtr(const T* ptr) const { return ptr - m_codeStart; }
148 ALWAYS_INLINE const T* sourcePtrFromOffset(int offset) const { return m_codeStart + offset; }
149
150 String invalidCharacterMessage() const;
151 ALWAYS_INLINE const T* currentSourcePtr() const;
152
153 ALWAYS_INLINE void setCodeStart(StringView);
154
155 ALWAYS_INLINE const Identifier* makeIdentifier(const LChar* characters, size_t length);
156 ALWAYS_INLINE const Identifier* makeIdentifier(const UChar* characters, size_t length);
157 ALWAYS_INLINE const Identifier* makeLCharIdentifier(const LChar* characters, size_t length);
158 ALWAYS_INLINE const Identifier* makeLCharIdentifier(const UChar* characters, size_t length);
159 ALWAYS_INLINE const Identifier* makeRightSizedIdentifier(const UChar* characters, size_t length, UChar orAllChars);
160 ALWAYS_INLINE const Identifier* makeIdentifierLCharFromUChar(const UChar* characters, size_t length);
161 ALWAYS_INLINE const Identifier* makeEmptyIdentifier();
162
163 ALWAYS_INLINE bool lastTokenWasRestrKeyword() const;
164
165 ALWAYS_INLINE void skipWhitespace();
166
167 template <int shiftAmount> void internalShift();
168 template <bool shouldCreateIdentifier> ALWAYS_INLINE JSTokenType parseKeyword(JSTokenData*);
169 template <bool shouldBuildIdentifiers> ALWAYS_INLINE JSTokenType parseIdentifier(JSTokenData*, OptionSet<LexerFlags>, bool strictMode);
170 template <bool shouldBuildIdentifiers> NEVER_INLINE JSTokenType parseIdentifierSlowCase(JSTokenData*, OptionSet<LexerFlags>, bool strictMode, const T* identifierStart);
171 enum StringParseResult {
172 StringParsedSuccessfully,
173 StringUnterminated,
174 StringCannotBeParsed
175 };
176 template <bool shouldBuildStrings> ALWAYS_INLINE StringParseResult parseString(JSTokenData*, bool strictMode);
177 template <bool shouldBuildStrings> NEVER_INLINE StringParseResult parseStringSlowCase(JSTokenData*, bool strictMode);
178
179
180 template <bool shouldBuildStrings> ALWAYS_INLINE StringParseResult parseComplexEscape(bool strictMode);
181 ALWAYS_INLINE StringParseResult parseTemplateLiteral(JSTokenData*, RawStringsBuildMode);
182
183 using NumberParseResult = std::variant<double, const Identifier*>;
184 ALWAYS_INLINE std::optional<NumberParseResult> parseHex();
185 ALWAYS_INLINE std::optional<NumberParseResult> parseBinary();
186 ALWAYS_INLINE std::optional<NumberParseResult> parseOctal();
187 ALWAYS_INLINE std::optional<NumberParseResult> parseDecimal();
188 ALWAYS_INLINE bool parseNumberAfterDecimalPoint();
189 ALWAYS_INLINE bool parseNumberAfterExponentIndicator();
190 ALWAYS_INLINE bool parseMultilineComment();
191
192 ALWAYS_INLINE void parseCommentDirective();
193 ALWAYS_INLINE String parseCommentDirectiveValue();
194
195 template <unsigned length>
196 ALWAYS_INLINE bool consume(const char (&input)[length]);
197
198 void fillTokenInfo(JSToken*, JSTokenType, int lineNumber, int endOffset, int lineStartOffset, JSTextPosition endPosition);
199
200 static constexpr size_t initialReadBufferCapacity = 32;
201
202 int m_lineNumber;
203 int m_lastLineNumber;
204
205 Vector<LChar> m_buffer8;
206 Vector<UChar> m_buffer16;
207 Vector<UChar> m_bufferForRawTemplateString16;
208 bool m_hasLineTerminatorBeforeToken;
209 int m_lastToken;
210
211 const SourceCode* m_source;
212 unsigned m_sourceOffset;
213 const T* m_code;
214 const T* m_codeStart;
215 const T* m_codeEnd;
216 const T* m_codeStartPlusOffset;
217 const T* m_lineStart;
218 JSTextPosition m_positionBeforeLastNewline;
219 JSTokenLocation m_lastTokenLocation;
220 bool m_isReparsingFunction;
221 bool m_atLineStart;
222 bool m_error;
223 String m_lexErrorMessage;
224
225 String m_sourceURLDirective;
226 String m_sourceMappingURLDirective;
227
228 T m_current;
229
230 IdentifierArena* m_arena;
231
232 VM& m_vm;
233 bool m_parsingBuiltinFunction;
234 JSParserScriptMode m_scriptMode;
235};
236
237template <>
238ALWAYS_INLINE bool Lexer<LChar>::isWhiteSpace(LChar ch)
239{
240 return ch == ' ' || ch == '\t' || ch == 0xB || ch == 0xC || ch == 0xA0;
241}
242
243template <>
244ALWAYS_INLINE bool Lexer<UChar>::isWhiteSpace(UChar ch)
245{
246 return isLatin1(ch) ? Lexer<LChar>::isWhiteSpace(static_cast<LChar>(ch)) : (u_charType(ch) == U_SPACE_SEPARATOR || ch == byteOrderMark);
247}
248
249template <>
250ALWAYS_INLINE bool Lexer<LChar>::isLineTerminator(LChar ch)
251{
252 return ch == '\r' || ch == '\n';
253}
254
255template <>
256ALWAYS_INLINE bool Lexer<UChar>::isLineTerminator(UChar ch)
257{
258 return ch == '\r' || ch == '\n' || (ch & ~1) == 0x2028;
259}
260
261template <typename T>
262inline unsigned char Lexer<T>::convertHex(int c1, int c2)
263{
264 return (toASCIIHexValue(c1) << 4) | toASCIIHexValue(c2);
265}
266
267template <typename T>
268inline UChar Lexer<T>::convertUnicode(int c1, int c2, int c3, int c4)
269{
270 return (convertHex(c1, c2) << 8) | convertHex(c3, c4);
271}
272
273template <typename T>
274ALWAYS_INLINE const Identifier* Lexer<T>::makeIdentifier(const LChar* characters, size_t length)
275{
276 return &m_arena->makeIdentifier(m_vm, characters, length);
277}
278
279template <typename T>
280ALWAYS_INLINE const Identifier* Lexer<T>::makeIdentifier(const UChar* characters, size_t length)
281{
282 return &m_arena->makeIdentifier(m_vm, characters, length);
283}
284
285template <>
286ALWAYS_INLINE const Identifier* Lexer<LChar>::makeRightSizedIdentifier(const UChar* characters, size_t length, UChar)
287{
288 return &m_arena->makeIdentifierLCharFromUChar(m_vm, characters, length);
289}
290
291template <>
292ALWAYS_INLINE const Identifier* Lexer<UChar>::makeRightSizedIdentifier(const UChar* characters, size_t length, UChar orAllChars)
293{
294 if (!(orAllChars & ~0xff))
295 return &m_arena->makeIdentifierLCharFromUChar(m_vm, characters, length);
296
297 return &m_arena->makeIdentifier(m_vm, characters, length);
298}
299
300template <typename T>
301ALWAYS_INLINE const Identifier* Lexer<T>::makeEmptyIdentifier()
302{
303 return &m_arena->makeEmptyIdentifier(m_vm);
304}
305
306template <>
307ALWAYS_INLINE void Lexer<LChar>::setCodeStart(StringView sourceString)
308{
309 ASSERT(sourceString.is8Bit());
310 m_codeStart = sourceString.characters8();
311}
312
313template <>
314ALWAYS_INLINE void Lexer<UChar>::setCodeStart(StringView sourceString)
315{
316 ASSERT(!sourceString.is8Bit());
317 m_codeStart = sourceString.characters16();
318}
319
320template <typename T>
321ALWAYS_INLINE const Identifier* Lexer<T>::makeIdentifierLCharFromUChar(const UChar* characters, size_t length)
322{
323 return &m_arena->makeIdentifierLCharFromUChar(m_vm, characters, length);
324}
325
326template <typename T>
327ALWAYS_INLINE const Identifier* Lexer<T>::makeLCharIdentifier(const LChar* characters, size_t length)
328{
329 return &m_arena->makeIdentifier(m_vm, characters, length);
330}
331
332template <typename T>
333ALWAYS_INLINE const Identifier* Lexer<T>::makeLCharIdentifier(const UChar* characters, size_t length)
334{
335 return &m_arena->makeIdentifierLCharFromUChar(m_vm, characters, length);
336}
337
338#if ASSERT_ENABLED
339bool isSafeBuiltinIdentifier(VM&, const Identifier*);
340#else
341ALWAYS_INLINE bool isSafeBuiltinIdentifier(VM&, const Identifier*) { return true; }
342#endif // ASSERT_ENABLED
343
344template <typename T>
345ALWAYS_INLINE JSTokenType Lexer<T>::lexExpectIdentifier(JSToken* tokenRecord, OptionSet<LexerFlags> lexerFlags, bool strictMode)
346{
347 JSTokenData* tokenData = &tokenRecord->m_data;
348 JSTokenLocation* tokenLocation = &tokenRecord->m_location;
349 ASSERT(lexerFlags.contains(LexerFlags::IgnoreReservedWords));
350 const T* start = m_code;
351 const T* ptr = start;
352 const T* end = m_codeEnd;
353 JSTextPosition startPosition = currentPosition();
354 if (ptr >= end) {
355 ASSERT(ptr == end);
356 goto slowCase;
357 }
358 if (!WTF::isASCIIAlpha(*ptr))
359 goto slowCase;
360 ++ptr;
361 while (ptr < end) {
362 if (!WTF::isASCIIAlphanumeric(*ptr))
363 break;
364 ++ptr;
365 }
366
367 // Here's the shift
368 if (ptr < end) {
369 if ((!WTF::isASCII(*ptr)) || (*ptr == '\\') || (*ptr == '_') || (*ptr == '$'))
370 goto slowCase;
371 m_current = *ptr;
372 } else
373 m_current = 0;
374
375 m_code = ptr;
376 ASSERT(currentOffset() >= currentLineStartOffset());
377
378 // Create the identifier if needed
379 if (lexerFlags.contains(LexerFlags::DontBuildKeywords)
380#if ASSERT_ENABLED
381 && !m_parsingBuiltinFunction
382#endif
383 )
384 tokenData->ident = nullptr;
385 else
386 tokenData->ident = makeLCharIdentifier(start, ptr - start);
387
388 tokenLocation->line = m_lineNumber;
389 tokenLocation->lineStartOffset = currentLineStartOffset();
390 tokenLocation->startOffset = offsetFromSourcePtr(start);
391 tokenLocation->endOffset = currentOffset();
392 ASSERT(tokenLocation->startOffset >= tokenLocation->lineStartOffset);
393 tokenRecord->m_startPosition = startPosition;
394 tokenRecord->m_endPosition = currentPosition();
395#if ASSERT_ENABLED
396 if (m_parsingBuiltinFunction) {
397 if (!isSafeBuiltinIdentifier(m_vm, tokenData->ident))
398 return ERRORTOK;
399 }
400#endif
401
402 m_lastToken = IDENT;
403 return IDENT;
404
405slowCase:
406 return lex(tokenRecord, lexerFlags, strictMode);
407}
408
409template <typename T>
410ALWAYS_INLINE JSTokenType Lexer<T>::lex(JSToken* tokenRecord, OptionSet<LexerFlags> lexerFlags, bool strictMode)
411{
412 m_hasLineTerminatorBeforeToken = false;
413 return lexWithoutClearingLineTerminator(tokenRecord, lexerFlags, strictMode);
414}
415
416} // namespace JSC
Note: See TracBrowser for help on using the repository browser.