antti@apple.com | be333a7 | 2011-01-25 18:44:11 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2011 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 | * 1. Redistributions of source code must retain the above copyright |
| 8 | * notice, this list of conditions and the following disclaimer. |
| 9 | * 2. Redistributions in binary form must reproduce the above copyright |
| 10 | * notice, this list of conditions and the following disclaimer in the |
| 11 | * documentation and/or other materials provided with the distribution. |
| 12 | * |
| 13 | * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' |
| 14 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, |
| 15 | * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
| 16 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS |
| 17 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| 18 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 19 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
| 20 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
| 21 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
| 22 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF |
| 23 | * THE POSSIBILITY OF SUCH DAMAGE. |
| 24 | */ |
| 25 | |
ryanhaddad@apple.com | 22104f5 | 2016-09-28 17:08:17 +0000 | [diff] [blame] | 26 | #pragma once |
msaboff@apple.com | 2e5003e | 2011-10-31 22:13:01 +0000 | [diff] [blame] | 27 | |
annulen@yandex.ru | 6712c2d | 2017-06-25 17:40:30 +0000 | [diff] [blame] | 28 | #include "ParserModes.h" |
msaboff@apple.com | 2e5003e | 2011-10-31 22:13:01 +0000 | [diff] [blame] | 29 | #include "ParserTokens.h" |
antti@apple.com | be333a7 | 2011-01-25 18:44:11 +0000 | [diff] [blame] | 30 | #include <wtf/Vector.h> |
utatane.tea@gmail.com | 8268d39 | 2015-05-23 18:41:53 +0000 | [diff] [blame] | 31 | #include <wtf/text/UniquedStringImpl.h> |
antti@apple.com | be333a7 | 2011-01-25 18:44:11 +0000 | [diff] [blame] | 32 | #include <wtf/text/WTFString.h> |
| 33 | |
| 34 | namespace JSC { |
| 35 | |
akling@apple.com | e93cba9 | 2013-01-28 06:34:03 +0000 | [diff] [blame] | 36 | struct SourceProviderCacheItemCreationParameters { |
mark.lam@apple.com | fa35e78 | 2013-11-19 21:55:16 +0000 | [diff] [blame] | 37 | unsigned functionNameStart; |
sbarati@apple.com | e1671a1 | 2016-04-25 19:08:53 +0000 | [diff] [blame] | 38 | unsigned lastTokenLine; |
| 39 | unsigned lastTokenStartOffset; |
| 40 | unsigned lastTokenEndOffset; |
| 41 | unsigned lastTokenLineStartOffset; |
commit-queue@webkit.org | 2a979b3 | 2015-06-26 06:49:20 +0000 | [diff] [blame] | 42 | unsigned endFunctionOffset; |
saambarati1@gmail.com | c497d15 | 2015-07-17 18:48:30 +0000 | [diff] [blame] | 43 | unsigned parameterCount; |
commit-queue@webkit.org | a1e1d57 | 2016-09-22 19:11:23 +0000 | [diff] [blame] | 44 | unsigned functionLength; |
akling@apple.com | e93cba9 | 2013-01-28 06:34:03 +0000 | [diff] [blame] | 45 | bool needsFullActivation; |
| 46 | bool usesEval; |
| 47 | bool strictMode; |
gskachkov@gmail.com | 82b8458 | 2017-01-20 11:43:24 +0000 | [diff] [blame] | 48 | bool needsSuperBinding; |
gskachkov@gmail.com | a198dd1 | 2016-02-28 19:14:26 +0000 | [diff] [blame] | 49 | InnerArrowFunctionCodeFeatures innerArrowFunctionFeatures; |
sbarati@apple.com | d60fffd | 2016-04-21 23:30:36 +0000 | [diff] [blame] | 50 | Vector<UniquedStringImpl*, 8> usedVariables; |
commit-queue@webkit.org | 2a979b3 | 2015-06-26 06:49:20 +0000 | [diff] [blame] | 51 | bool isBodyArrowExpression { false }; |
| 52 | JSTokenType tokenType { CLOSEBRACE }; |
sbarati@apple.com | e1671a1 | 2016-04-25 19:08:53 +0000 | [diff] [blame] | 53 | ConstructorKind constructorKind; |
| 54 | SuperBinding expectedSuperBinding; |
akling@apple.com | e93cba9 | 2013-01-28 06:34:03 +0000 | [diff] [blame] | 55 | }; |
| 56 | |
| 57 | #if COMPILER(MSVC) |
| 58 | #pragma warning(push) |
| 59 | #pragma warning(disable: 4200) // Disable "zero-sized array in struct/union" warning |
| 60 | #endif |
| 61 | |
antti@apple.com | be333a7 | 2011-01-25 18:44:11 +0000 | [diff] [blame] | 62 | class SourceProviderCacheItem { |
zoltan@webkit.org | c6395da | 2012-09-04 19:35:54 +0000 | [diff] [blame] | 63 | WTF_MAKE_FAST_ALLOCATED; |
antti@apple.com | be333a7 | 2011-01-25 18:44:11 +0000 | [diff] [blame] | 64 | public: |
andersca@apple.com | 2a6c489 | 2013-09-26 20:44:02 +0000 | [diff] [blame] | 65 | static std::unique_ptr<SourceProviderCacheItem> create(const SourceProviderCacheItemCreationParameters&); |
akling@apple.com | e93cba9 | 2013-01-28 06:34:03 +0000 | [diff] [blame] | 66 | ~SourceProviderCacheItem(); |
| 67 | |
commit-queue@webkit.org | 2a979b3 | 2015-06-26 06:49:20 +0000 | [diff] [blame] | 68 | JSToken endFunctionToken() const |
antti@apple.com | be333a7 | 2011-01-25 18:44:11 +0000 | [diff] [blame] | 69 | { |
| 70 | JSToken token; |
commit-queue@webkit.org | 2a979b3 | 2015-06-26 06:49:20 +0000 | [diff] [blame] | 71 | token.m_type = isBodyArrowExpression ? tokenType : CLOSEBRACE; |
sbarati@apple.com | e1671a1 | 2016-04-25 19:08:53 +0000 | [diff] [blame] | 72 | token.m_data.offset = lastTokenStartOffset; |
| 73 | token.m_location.startOffset = lastTokenStartOffset; |
| 74 | token.m_location.endOffset = lastTokenEndOffset; |
| 75 | token.m_location.line = lastTokenLine; |
| 76 | token.m_location.lineStartOffset = lastTokenLineStartOffset; |
mark.lam@apple.com | 5b45f90 | 2013-07-09 16:15:12 +0000 | [diff] [blame] | 77 | // token.m_location.sourceOffset is initialized once by the client. So, |
| 78 | // we do not need to set it here. |
antti@apple.com | be333a7 | 2011-01-25 18:44:11 +0000 | [diff] [blame] | 79 | return token; |
| 80 | } |
oliver@apple.com | d6b8be4 | 2012-11-28 21:11:53 +0000 | [diff] [blame] | 81 | |
mark.lam@apple.com | fa35e78 | 2013-11-19 21:55:16 +0000 | [diff] [blame] | 82 | unsigned functionNameStart : 31; |
oliver@apple.com | d6b8be4 | 2012-11-28 21:11:53 +0000 | [diff] [blame] | 83 | bool needsFullActivation : 1; |
commit-queue@webkit.org | 2a979b3 | 2015-06-26 06:49:20 +0000 | [diff] [blame] | 84 | unsigned endFunctionOffset : 31; |
oliver@apple.com | d6b8be4 | 2012-11-28 21:11:53 +0000 | [diff] [blame] | 85 | bool usesEval : 1; |
sbarati@apple.com | e1671a1 | 2016-04-25 19:08:53 +0000 | [diff] [blame] | 86 | unsigned lastTokenLine : 31; |
oliver@apple.com | d6b8be4 | 2012-11-28 21:11:53 +0000 | [diff] [blame] | 87 | bool strictMode : 1; |
sbarati@apple.com | e1671a1 | 2016-04-25 19:08:53 +0000 | [diff] [blame] | 88 | unsigned lastTokenStartOffset : 31; |
| 89 | unsigned lastTokenEndOffset: 31; |
| 90 | unsigned constructorKind : 2; // ConstructorKind |
| 91 | unsigned parameterCount : 31; |
| 92 | unsigned expectedSuperBinding : 1; // SuperBinding |
gskachkov@gmail.com | 82b8458 | 2017-01-20 11:43:24 +0000 | [diff] [blame] | 93 | bool needsSuperBinding: 1; |
commit-queue@webkit.org | a1e1d57 | 2016-09-22 19:11:23 +0000 | [diff] [blame] | 94 | unsigned functionLength; |
sbarati@apple.com | e1671a1 | 2016-04-25 19:08:53 +0000 | [diff] [blame] | 95 | unsigned lastTokenLineStartOffset; |
akling@apple.com | e93cba9 | 2013-01-28 06:34:03 +0000 | [diff] [blame] | 96 | unsigned usedVariablesCount; |
sbarati@apple.com | e1671a1 | 2016-04-25 19:08:53 +0000 | [diff] [blame] | 97 | InnerArrowFunctionCodeFeatures innerArrowFunctionFeatures; |
commit-queue@webkit.org | 2a979b3 | 2015-06-26 06:49:20 +0000 | [diff] [blame] | 98 | bool isBodyArrowExpression; |
| 99 | JSTokenType tokenType; |
akling@apple.com | e93cba9 | 2013-01-28 06:34:03 +0000 | [diff] [blame] | 100 | |
sbarati@apple.com | e1671a1 | 2016-04-25 19:08:53 +0000 | [diff] [blame] | 101 | UniquedStringImpl** usedVariables() const { return const_cast<UniquedStringImpl**>(m_variables); } |
| 102 | |
akling@apple.com | e93cba9 | 2013-01-28 06:34:03 +0000 | [diff] [blame] | 103 | private: |
| 104 | SourceProviderCacheItem(const SourceProviderCacheItemCreationParameters&); |
| 105 | |
utatane.tea@gmail.com | 8268d39 | 2015-05-23 18:41:53 +0000 | [diff] [blame] | 106 | UniquedStringImpl* m_variables[0]; |
antti@apple.com | be333a7 | 2011-01-25 18:44:11 +0000 | [diff] [blame] | 107 | }; |
| 108 | |
akling@apple.com | e93cba9 | 2013-01-28 06:34:03 +0000 | [diff] [blame] | 109 | inline SourceProviderCacheItem::~SourceProviderCacheItem() |
| 110 | { |
sbarati@apple.com | d60fffd | 2016-04-21 23:30:36 +0000 | [diff] [blame] | 111 | for (unsigned i = 0; i < usedVariablesCount; ++i) |
akling@apple.com | e93cba9 | 2013-01-28 06:34:03 +0000 | [diff] [blame] | 112 | m_variables[i]->deref(); |
| 113 | } |
| 114 | |
andersca@apple.com | 2a6c489 | 2013-09-26 20:44:02 +0000 | [diff] [blame] | 115 | inline std::unique_ptr<SourceProviderCacheItem> SourceProviderCacheItem::create(const SourceProviderCacheItemCreationParameters& parameters) |
akling@apple.com | e93cba9 | 2013-01-28 06:34:03 +0000 | [diff] [blame] | 116 | { |
sbarati@apple.com | d60fffd | 2016-04-21 23:30:36 +0000 | [diff] [blame] | 117 | size_t variableCount = parameters.usedVariables.size(); |
utatane.tea@gmail.com | 8268d39 | 2015-05-23 18:41:53 +0000 | [diff] [blame] | 118 | size_t objectSize = sizeof(SourceProviderCacheItem) + sizeof(UniquedStringImpl*) * variableCount; |
akling@apple.com | e93cba9 | 2013-01-28 06:34:03 +0000 | [diff] [blame] | 119 | void* slot = fastMalloc(objectSize); |
andersca@apple.com | 2a6c489 | 2013-09-26 20:44:02 +0000 | [diff] [blame] | 120 | return std::unique_ptr<SourceProviderCacheItem>(new (slot) SourceProviderCacheItem(parameters)); |
akling@apple.com | e93cba9 | 2013-01-28 06:34:03 +0000 | [diff] [blame] | 121 | } |
| 122 | |
| 123 | inline SourceProviderCacheItem::SourceProviderCacheItem(const SourceProviderCacheItemCreationParameters& parameters) |
mark.lam@apple.com | fa35e78 | 2013-11-19 21:55:16 +0000 | [diff] [blame] | 124 | : functionNameStart(parameters.functionNameStart) |
akling@apple.com | e93cba9 | 2013-01-28 06:34:03 +0000 | [diff] [blame] | 125 | , needsFullActivation(parameters.needsFullActivation) |
commit-queue@webkit.org | 2a979b3 | 2015-06-26 06:49:20 +0000 | [diff] [blame] | 126 | , endFunctionOffset(parameters.endFunctionOffset) |
akling@apple.com | e93cba9 | 2013-01-28 06:34:03 +0000 | [diff] [blame] | 127 | , usesEval(parameters.usesEval) |
sbarati@apple.com | e1671a1 | 2016-04-25 19:08:53 +0000 | [diff] [blame] | 128 | , lastTokenLine(parameters.lastTokenLine) |
akling@apple.com | e93cba9 | 2013-01-28 06:34:03 +0000 | [diff] [blame] | 129 | , strictMode(parameters.strictMode) |
sbarati@apple.com | e1671a1 | 2016-04-25 19:08:53 +0000 | [diff] [blame] | 130 | , lastTokenStartOffset(parameters.lastTokenStartOffset) |
| 131 | , lastTokenEndOffset(parameters.lastTokenEndOffset) |
| 132 | , constructorKind(static_cast<unsigned>(parameters.constructorKind)) |
| 133 | , parameterCount(parameters.parameterCount) |
| 134 | , expectedSuperBinding(static_cast<unsigned>(parameters.expectedSuperBinding)) |
gskachkov@gmail.com | 82b8458 | 2017-01-20 11:43:24 +0000 | [diff] [blame] | 135 | , needsSuperBinding(parameters.needsSuperBinding) |
commit-queue@webkit.org | a1e1d57 | 2016-09-22 19:11:23 +0000 | [diff] [blame] | 136 | , functionLength(parameters.functionLength) |
sbarati@apple.com | e1671a1 | 2016-04-25 19:08:53 +0000 | [diff] [blame] | 137 | , lastTokenLineStartOffset(parameters.lastTokenLineStartOffset) |
akling@apple.com | e93cba9 | 2013-01-28 06:34:03 +0000 | [diff] [blame] | 138 | , usedVariablesCount(parameters.usedVariables.size()) |
sbarati@apple.com | e1671a1 | 2016-04-25 19:08:53 +0000 | [diff] [blame] | 139 | , innerArrowFunctionFeatures(parameters.innerArrowFunctionFeatures) |
commit-queue@webkit.org | 2a979b3 | 2015-06-26 06:49:20 +0000 | [diff] [blame] | 140 | , isBodyArrowExpression(parameters.isBodyArrowExpression) |
| 141 | , tokenType(parameters.tokenType) |
akling@apple.com | e93cba9 | 2013-01-28 06:34:03 +0000 | [diff] [blame] | 142 | { |
sbarati@apple.com | d60fffd | 2016-04-21 23:30:36 +0000 | [diff] [blame] | 143 | for (unsigned i = 0; i < usedVariablesCount; ++i) { |
| 144 | m_variables[i] = parameters.usedVariables[i]; |
| 145 | m_variables[i]->ref(); |
akling@apple.com | e93cba9 | 2013-01-28 06:34:03 +0000 | [diff] [blame] | 146 | } |
| 147 | } |
| 148 | |
| 149 | #if COMPILER(MSVC) |
| 150 | #pragma warning(pop) |
| 151 | #endif |
| 152 | |
ryanhaddad@apple.com | 22104f5 | 2016-09-28 17:08:17 +0000 | [diff] [blame] | 153 | } // namespace JSC |