| Differences between
and this patch
- Source/JavaScriptCore/bytecode/UnlinkedFunctionExecutable.cpp -1 / +1 lines
Lines 82-88 static UnlinkedFunctionCodeBlock* genera Source/JavaScriptCore/bytecode/UnlinkedFunctionExecutable.cpp_sec1
82
    return result;
82
    return result;
83
}
83
}
84
84
85
UnlinkedFunctionExecutable::UnlinkedFunctionExecutable(VM& vm, Structure* structure, const SourceCode& parentSource, FunctionMetadataNode* node, UnlinkedFunctionKind kind, ConstructAbility constructAbility, JSParserScriptMode scriptMode, Optional<CompactVariableMap::Handle> parentScopeTDZVariables, DerivedContextType derivedContextType, NeedsClassFieldInitializer needsClassFieldInitializer, bool isBuiltinDefaultClassConstructor)
85
UnlinkedFunctionExecutable::UnlinkedFunctionExecutable(VM& vm, Structure* structure, const SourceCode& parentSource, FunctionMetadataNode* node, UnlinkedFunctionKind kind, ConstructAbility constructAbility, JSParserScriptMode scriptMode, Optional<Vector<CompactVariableMap::Handle>> parentScopeTDZVariables, DerivedContextType derivedContextType, NeedsClassFieldInitializer needsClassFieldInitializer, bool isBuiltinDefaultClassConstructor)
86
    : Base(vm, structure)
86
    : Base(vm, structure)
87
    , m_firstLineOffset(node->firstLine() - parentSource.firstLine().oneBasedInt())
87
    , m_firstLineOffset(node->firstLine() - parentSource.firstLine().oneBasedInt())
88
    , m_isInStrictContext(node->isInStrictContext())
88
    , m_isInStrictContext(node->isInStrictContext())
- Source/JavaScriptCore/bytecode/UnlinkedFunctionExecutable.h -5 / +5 lines
Lines 70-76 public: Source/JavaScriptCore/bytecode/UnlinkedFunctionExecutable.h_sec1
70
        return &vm.unlinkedFunctionExecutableSpace.space;
70
        return &vm.unlinkedFunctionExecutableSpace.space;
71
    }
71
    }
72
72
73
    static UnlinkedFunctionExecutable* create(VM& vm, const SourceCode& source, FunctionMetadataNode* node, UnlinkedFunctionKind unlinkedFunctionKind, ConstructAbility constructAbility, JSParserScriptMode scriptMode, Optional<CompactVariableMap::Handle> parentScopeTDZVariables, DerivedContextType derivedContextType, NeedsClassFieldInitializer needsClassFieldInitializer, bool isBuiltinDefaultClassConstructor = false)
73
    static UnlinkedFunctionExecutable* create(VM& vm, const SourceCode& source, FunctionMetadataNode* node, UnlinkedFunctionKind unlinkedFunctionKind, ConstructAbility constructAbility, JSParserScriptMode scriptMode, Optional<Vector<CompactVariableMap::Handle>> parentScopeTDZVariables, DerivedContextType derivedContextType, NeedsClassFieldInitializer needsClassFieldInitializer, bool isBuiltinDefaultClassConstructor = false)
74
    {
74
    {
75
        UnlinkedFunctionExecutable* instance = new (NotNull, allocateCell<UnlinkedFunctionExecutable>(vm.heap))
75
        UnlinkedFunctionExecutable* instance = new (NotNull, allocateCell<UnlinkedFunctionExecutable>(vm.heap))
76
            UnlinkedFunctionExecutable(vm, vm.unlinkedFunctionExecutableStructure.get(), source, node, unlinkedFunctionKind, constructAbility, scriptMode, WTFMove(parentScopeTDZVariables), derivedContextType, needsClassFieldInitializer, isBuiltinDefaultClassConstructor);
76
            UnlinkedFunctionExecutable(vm, vm.unlinkedFunctionExecutableStructure.get(), source, node, unlinkedFunctionKind, constructAbility, scriptMode, WTFMove(parentScopeTDZVariables), derivedContextType, needsClassFieldInitializer, isBuiltinDefaultClassConstructor);
Lines 170-178 public: Source/JavaScriptCore/bytecode/UnlinkedFunctionExecutable.h_sec2
170
170
171
    VariableEnvironment parentScopeTDZVariables() const
171
    VariableEnvironment parentScopeTDZVariables() const
172
    {
172
    {
173
        if (!m_rareData || !m_rareData->m_parentScopeTDZVariables)
173
        if (!m_rareData || m_rareData->m_parentScopeTDZVariables.isEmpty())
174
            return VariableEnvironment();
174
            return VariableEnvironment();
175
        return m_rareData->m_parentScopeTDZVariables.environment().toVariableEnvironment();
175
        return variableEnvironmentFromCompactHandleStack(m_rareData->m_parentScopeTDZVariables);
176
    }
176
    }
177
    
177
    
178
    bool isArrowFunction() const { return isArrowFunctionParseMode(parseMode()); }
178
    bool isArrowFunction() const { return isArrowFunctionParseMode(parseMode()); }
Lines 208-214 public: Source/JavaScriptCore/bytecode/UnlinkedFunctionExecutable.h_sec3
208
        SourceCode m_classSource;
208
        SourceCode m_classSource;
209
        String m_sourceURLDirective;
209
        String m_sourceURLDirective;
210
        String m_sourceMappingURLDirective;
210
        String m_sourceMappingURLDirective;
211
        CompactVariableMap::Handle m_parentScopeTDZVariables;
211
        Vector<CompactVariableMap::Handle> m_parentScopeTDZVariables;
212
        Vector<JSTextPosition> m_instanceFieldLocations;
212
        Vector<JSTextPosition> m_instanceFieldLocations;
213
    };
213
    };
214
214
Lines 229-235 public: Source/JavaScriptCore/bytecode/UnlinkedFunctionExecutable.h_sec4
229
    }
229
    }
230
230
231
private:
231
private:
232
    UnlinkedFunctionExecutable(VM&, Structure*, const SourceCode&, FunctionMetadataNode*, UnlinkedFunctionKind, ConstructAbility, JSParserScriptMode, Optional<CompactVariableMap::Handle>,  JSC::DerivedContextType, JSC::NeedsClassFieldInitializer, bool isBuiltinDefaultClassConstructor);
232
    UnlinkedFunctionExecutable(VM&, Structure*, const SourceCode&, FunctionMetadataNode*, UnlinkedFunctionKind, ConstructAbility, JSParserScriptMode, Optional<Vector<CompactVariableMap::Handle>>,  JSC::DerivedContextType, JSC::NeedsClassFieldInitializer, bool isBuiltinDefaultClassConstructor);
233
    UnlinkedFunctionExecutable(Decoder&, const CachedFunctionExecutable&);
233
    UnlinkedFunctionExecutable(Decoder&, const CachedFunctionExecutable&);
234
234
235
    static void visitChildren(JSCell*, SlotVisitor&);
235
    static void visitChildren(JSCell*, SlotVisitor&);
- Source/JavaScriptCore/bytecompiler/BytecodeGenerator.cpp -41 / +34 lines
Lines 48-53 Source/JavaScriptCore/bytecompiler/BytecodeGenerator.cpp_sec1
48
#include "Options.h"
48
#include "Options.h"
49
#include "PrivateFieldPutKind.h"
49
#include "PrivateFieldPutKind.h"
50
#include "StrongInlines.h"
50
#include "StrongInlines.h"
51
#include "SuperSampler.h"
51
#include "UnlinkedCodeBlock.h"
52
#include "UnlinkedCodeBlock.h"
52
#include "UnlinkedEvalCodeBlock.h"
53
#include "UnlinkedEvalCodeBlock.h"
53
#include "UnlinkedFunctionCodeBlock.h"
54
#include "UnlinkedFunctionCodeBlock.h"
Lines 300-306 BytecodeGenerator::BytecodeGenerator(VM& Source/JavaScriptCore/bytecompiler/BytecodeGenerator.cpp_sec2
300
    , m_isBuiltinFunction(false)
301
    , m_isBuiltinFunction(false)
301
    , m_usesNonStrictEval(false)
302
    , m_usesNonStrictEval(false)
302
    , m_inTailPosition(false)
303
    , m_inTailPosition(false)
303
    , m_hasCachedVariablesUnderTDZ(false)
304
    , m_needsToUpdateArrowFunctionContext(programNode->usesArrowFunction() || programNode->usesEval())
304
    , m_needsToUpdateArrowFunctionContext(programNode->usesArrowFunction() || programNode->usesEval())
305
    , m_ecmaMode(ecmaMode)
305
    , m_ecmaMode(ecmaMode)
306
{
306
{
Lines 355-361 BytecodeGenerator::BytecodeGenerator(VM& Source/JavaScriptCore/bytecompiler/BytecodeGenerator.cpp_sec3
355
    //
355
    //
356
    // Note that we intentionally enable tail call for naked constructors since it does not have special code for "return".
356
    // Note that we intentionally enable tail call for naked constructors since it does not have special code for "return".
357
    , m_inTailPosition(Options::useTailCalls() && !isConstructor() && constructorKind() == ConstructorKind::None && ecmaMode.isStrict())
357
    , m_inTailPosition(Options::useTailCalls() && !isConstructor() && constructorKind() == ConstructorKind::None && ecmaMode.isStrict())
358
    , m_hasCachedVariablesUnderTDZ(false)
359
    , m_needsToUpdateArrowFunctionContext(functionNode->usesArrowFunction() || functionNode->usesEval())
358
    , m_needsToUpdateArrowFunctionContext(functionNode->usesArrowFunction() || functionNode->usesEval())
360
    , m_ecmaMode(ecmaMode)
359
    , m_ecmaMode(ecmaMode)
361
    , m_derivedContextType(codeBlock->derivedContextType())
360
    , m_derivedContextType(codeBlock->derivedContextType())
Lines 852-858 BytecodeGenerator::BytecodeGenerator(VM& Source/JavaScriptCore/bytecompiler/BytecodeGenerator.cpp_sec4
852
    , m_isBuiltinFunction(false)
851
    , m_isBuiltinFunction(false)
853
    , m_usesNonStrictEval(codeBlock->usesEval() && !ecmaMode.isStrict())
852
    , m_usesNonStrictEval(codeBlock->usesEval() && !ecmaMode.isStrict())
854
    , m_inTailPosition(false)
853
    , m_inTailPosition(false)
855
    , m_hasCachedVariablesUnderTDZ(false)
856
    , m_needsToUpdateArrowFunctionContext(evalNode->usesArrowFunction() || evalNode->usesEval())
854
    , m_needsToUpdateArrowFunctionContext(evalNode->usesArrowFunction() || evalNode->usesEval())
857
    , m_ecmaMode(ecmaMode)
855
    , m_ecmaMode(ecmaMode)
858
    , m_derivedContextType(codeBlock->derivedContextType())
856
    , m_derivedContextType(codeBlock->derivedContextType())
Lines 916-922 BytecodeGenerator::BytecodeGenerator(VM& Source/JavaScriptCore/bytecompiler/BytecodeGenerator.cpp_sec5
916
    , m_isBuiltinFunction(false)
914
    , m_isBuiltinFunction(false)
917
    , m_usesNonStrictEval(false)
915
    , m_usesNonStrictEval(false)
918
    , m_inTailPosition(false)
916
    , m_inTailPosition(false)
919
    , m_hasCachedVariablesUnderTDZ(false)
920
    , m_needsToUpdateArrowFunctionContext(moduleProgramNode->usesArrowFunction() || moduleProgramNode->usesEval())
917
    , m_needsToUpdateArrowFunctionContext(moduleProgramNode->usesArrowFunction() || moduleProgramNode->usesEval())
921
    , m_ecmaMode(ecmaMode)
918
    , m_ecmaMode(ecmaMode)
922
{
919
{
Lines 2170-2176 void BytecodeGenerator::popLexicalScopeI Source/JavaScriptCore/bytecompiler/BytecodeGenerator.cpp_sec6
2170
    }
2167
    }
2171
2168
2172
    m_TDZStack.removeLast();
2169
    m_TDZStack.removeLast();
2173
    m_cachedVariablesUnderTDZ = { };
2170
    m_cachedVariablesUnderTDZ.removeLast();
2174
}
2171
}
2175
2172
2176
void BytecodeGenerator::prepareLexicalScopeForNextForLoopIteration(VariableEnvironmentNode* node, RegisterID* loopSymbolTable)
2173
void BytecodeGenerator::prepareLexicalScopeForNextForLoopIteration(VariableEnvironmentNode* node, RegisterID* loopSymbolTable)
Lines 2880-2889 void BytecodeGenerator::liftTDZCheckIfPo Source/JavaScriptCore/bytecompiler/BytecodeGenerator.cpp_sec7
2880
    for (unsigned i = m_TDZStack.size(); i--;) {
2877
    for (unsigned i = m_TDZStack.size(); i--;) {
2881
        auto iter = m_TDZStack[i].find(identifier);
2878
        auto iter = m_TDZStack[i].find(identifier);
2882
        if (iter != m_TDZStack[i].end()) {
2879
        if (iter != m_TDZStack[i].end()) {
2883
            if (iter->value == TDZNecessityLevel::Optimize) {
2880
            if (iter->value == TDZNecessityLevel::Optimize)
2884
                m_cachedVariablesUnderTDZ = { };
2885
                iter->value = TDZNecessityLevel::NotNeeded;
2881
                iter->value = TDZNecessityLevel::NotNeeded;
2886
            }
2887
            break;
2882
            break;
2888
        }
2883
        }
2889
    }
2884
    }
Lines 2908-2966 void BytecodeGenerator::pushTDZVariables Source/JavaScriptCore/bytecompiler/BytecodeGenerator.cpp_sec8
2908
        map.add(entry.key, entry.value.isFunction() ? TDZNecessityLevel::NotNeeded : level);
2903
        map.add(entry.key, entry.value.isFunction() ? TDZNecessityLevel::NotNeeded : level);
2909
2904
2910
    m_TDZStack.append(WTFMove(map));
2905
    m_TDZStack.append(WTFMove(map));
2911
    m_cachedVariablesUnderTDZ = { };
2906
    m_cachedVariablesUnderTDZ.append({ });
2912
}
2907
}
2913
2908
2914
Optional<CompactVariableMap::Handle> BytecodeGenerator::getVariablesUnderTDZ()
2909
Optional<BytecodeGenerator::CachedTDZStack> BytecodeGenerator::getVariablesUnderTDZ()
2915
{
2910
{
2916
    if (m_cachedVariablesUnderTDZ) {
2911
    SuperSamplerScope superSamplerScope(false);
2917
        if (!m_hasCachedVariablesUnderTDZ) {
2912
2918
            ASSERT(m_cachedVariablesUnderTDZ.environment().toVariableEnvironment().isEmpty());
2913
    auto assertCacheIsCoherent = [&] {
2919
            return WTF::nullopt;
2914
#if ASSERT_ENABLED
2920
        }
2915
        for (size_t i = 0; i < m_cachedVariablesUnderTDZ.size(); ++i)
2916
            ASSERT(!!m_cachedVariablesUnderTDZ[i]);
2917
#endif
2918
    };
2919
2920
    RELEASE_ASSERT(m_TDZStack.size() == m_cachedVariablesUnderTDZ.size());
2921
2922
    if (m_cachedVariablesUnderTDZ.isEmpty())
2923
        return WTF::nullopt;
2924
2925
    if (m_cachedVariablesUnderTDZ.last()) {
2926
        assertCacheIsCoherent();
2921
        return m_cachedVariablesUnderTDZ;
2927
        return m_cachedVariablesUnderTDZ;
2922
    }
2928
    }
2923
2929
2924
    // We keep track of variablesThatDontNeedTDZ in this algorithm to prevent
2930
    for (size_t i = m_TDZStack.size(); i--;) {
2925
    // reporting that "x" is under TDZ if this function is called at "...".
2931
        if (m_cachedVariablesUnderTDZ[i])
2926
    //
2932
            break;
2927
    //     {
2933
2928
    //         {
2929
    //             let x;
2930
    //             ...
2931
    //         }
2932
    //         let x;
2933
    //     }
2934
    SmallPtrSet<UniquedStringImpl*, 16> variablesThatDontNeedTDZ;
2935
    VariableEnvironment environment;
2936
    for (unsigned i = m_TDZStack.size(); i--; ) {
2937
        auto& map = m_TDZStack[i];
2934
        auto& map = m_TDZStack[i];
2938
        for (auto& entry : map)  {
2935
        VariableEnvironment environment;
2939
            if (entry.value != TDZNecessityLevel::NotNeeded) {
2936
        for (auto& entry : map) {
2940
                if (!variablesThatDontNeedTDZ.contains(entry.key.get()))
2937
            if (entry.value != TDZNecessityLevel::NotNeeded)
2941
                    environment.add(entry.key.get());
2938
                environment.add(entry.key.get());
2942
            } else
2943
                variablesThatDontNeedTDZ.add(entry.key.get());
2944
        }
2939
        }
2940
        m_cachedVariablesUnderTDZ[i] = m_vm.m_compactVariableMap->get(environment);
2945
    }
2941
    }
2946
2942
2947
    m_cachedVariablesUnderTDZ = m_vm.m_compactVariableMap->get(environment);
2943
    assertCacheIsCoherent();
2948
    m_hasCachedVariablesUnderTDZ = !environment.isEmpty();
2949
    if (!m_hasCachedVariablesUnderTDZ)
2950
        return WTF::nullopt;
2951
2952
    return m_cachedVariablesUnderTDZ;
2944
    return m_cachedVariablesUnderTDZ;
2953
}
2945
}
2954
2946
2955
void BytecodeGenerator::preserveTDZStack(BytecodeGenerator::PreservedTDZStack& preservedStack)
2947
void BytecodeGenerator::preserveTDZStack(BytecodeGenerator::PreservedTDZStack& preservedStack)
2956
{
2948
{
2957
    preservedStack.m_preservedTDZStack = m_TDZStack;
2949
    preservedStack.m_preservedTDZStack = m_TDZStack;
2950
    preservedStack.m_cachedTDZStack = m_cachedVariablesUnderTDZ;
2958
}
2951
}
2959
2952
2960
void BytecodeGenerator::restoreTDZStack(const BytecodeGenerator::PreservedTDZStack& preservedStack)
2953
void BytecodeGenerator::restoreTDZStack(const BytecodeGenerator::PreservedTDZStack& preservedStack)
2961
{
2954
{
2962
    m_TDZStack = preservedStack.m_preservedTDZStack;
2955
    m_TDZStack = preservedStack.m_preservedTDZStack;
2963
    m_cachedVariablesUnderTDZ = { };
2956
    m_cachedVariablesUnderTDZ = preservedStack.m_cachedTDZStack;
2964
}
2957
}
2965
2958
2966
RegisterID* BytecodeGenerator::emitNewObject(RegisterID* dst)
2959
RegisterID* BytecodeGenerator::emitNewObject(RegisterID* dst)
Lines 3147-3153 RegisterID* BytecodeGenerator::emitNewIn Source/JavaScriptCore/bytecompiler/BytecodeGenerator.cpp_sec9
3147
        superBinding = SuperBinding::Needed;
3140
        superBinding = SuperBinding::Needed;
3148
    }
3141
    }
3149
3142
3150
    Optional<CompactVariableMap::Handle> variablesUnderTDZ = getVariablesUnderTDZ();
3143
    auto variablesUnderTDZ = getVariablesUnderTDZ();
3151
    SourceParseMode parseMode = SourceParseMode::InstanceFieldInitializerMode;
3144
    SourceParseMode parseMode = SourceParseMode::InstanceFieldInitializerMode;
3152
    ConstructAbility constructAbility = ConstructAbility::CannotConstruct;
3145
    ConstructAbility constructAbility = ConstructAbility::CannotConstruct;
3153
3146
- Source/JavaScriptCore/bytecompiler/BytecodeGenerator.h -5 / +6 lines
Lines 1185-1191 namespace JSC { Source/JavaScriptCore/bytecompiler/BytecodeGenerator.h_sec1
1185
                    newDerivedContextType = DerivedContextType::DerivedMethodContext;
1185
                    newDerivedContextType = DerivedContextType::DerivedMethodContext;
1186
            }
1186
            }
1187
1187
1188
            Optional<CompactVariableMap::Handle> optionalVariablesUnderTDZ = getVariablesUnderTDZ();
1188
            auto optionalVariablesUnderTDZ = getVariablesUnderTDZ();
1189
1189
1190
            // FIXME: These flags, ParserModes and propagation to XXXCodeBlocks should be reorganized.
1190
            // FIXME: These flags, ParserModes and propagation to XXXCodeBlocks should be reorganized.
1191
            // https://bugs.webkit.org/show_bug.cgi?id=151547
1191
            // https://bugs.webkit.org/show_bug.cgi?id=151547
Lines 1197-1203 namespace JSC { Source/JavaScriptCore/bytecompiler/BytecodeGenerator.h_sec2
1197
            return UnlinkedFunctionExecutable::create(m_vm, m_scopeNode->source(), metadata, isBuiltinFunction() ? UnlinkedBuiltinFunction : UnlinkedNormalFunction, constructAbility, scriptMode(), WTFMove(optionalVariablesUnderTDZ), newDerivedContextType, needsClassFieldInitializer);
1197
            return UnlinkedFunctionExecutable::create(m_vm, m_scopeNode->source(), metadata, isBuiltinFunction() ? UnlinkedBuiltinFunction : UnlinkedNormalFunction, constructAbility, scriptMode(), WTFMove(optionalVariablesUnderTDZ), newDerivedContextType, needsClassFieldInitializer);
1198
        }
1198
        }
1199
1199
1200
        Optional<CompactVariableMap::Handle> getVariablesUnderTDZ();
1200
        using CachedTDZStack = Vector<CompactVariableMap::Handle>;
1201
1202
        Optional<CachedTDZStack> getVariablesUnderTDZ();
1201
1203
1202
        RegisterID* emitConstructVarargs(RegisterID* dst, RegisterID* func, RegisterID* thisRegister, RegisterID* arguments, RegisterID* firstFreeRegister, int32_t firstVarArgOffset, const JSTextPosition& divot, const JSTextPosition& divotStart, const JSTextPosition& divotEnd, DebuggableCall);
1204
        RegisterID* emitConstructVarargs(RegisterID* dst, RegisterID* func, RegisterID* thisRegister, RegisterID* arguments, RegisterID* firstFreeRegister, int32_t firstVarArgOffset, const JSTextPosition& divot, const JSTextPosition& divotStart, const JSTextPosition& divotEnd, DebuggableCall);
1203
        template<typename CallOp>
1205
        template<typename CallOp>
Lines 1231-1236 namespace JSC { Source/JavaScriptCore/bytecompiler/BytecodeGenerator.h_sec3
1231
        class PreservedTDZStack {
1233
        class PreservedTDZStack {
1232
        private:
1234
        private:
1233
            Vector<TDZMap> m_preservedTDZStack;
1235
            Vector<TDZMap> m_preservedTDZStack;
1236
            CachedTDZStack m_cachedTDZStack;
1234
            friend class BytecodeGenerator;
1237
            friend class BytecodeGenerator;
1235
        };
1238
        };
1236
1239
Lines 1263-1268 namespace JSC { Source/JavaScriptCore/bytecompiler/BytecodeGenerator.h_sec4
1263
        Vector<LexicalScopeStackEntry> m_lexicalScopeStack;
1266
        Vector<LexicalScopeStackEntry> m_lexicalScopeStack;
1264
1267
1265
        Vector<TDZMap> m_TDZStack;
1268
        Vector<TDZMap> m_TDZStack;
1269
        CachedTDZStack m_cachedVariablesUnderTDZ;
1266
        Optional<size_t> m_varScopeLexicalScopeStackIndex;
1270
        Optional<size_t> m_varScopeLexicalScopeStackIndex;
1267
        void pushTDZVariables(const VariableEnvironment&, TDZCheckOptimization, TDZRequirement);
1271
        void pushTDZVariables(const VariableEnvironment&, TDZCheckOptimization, TDZRequirement);
1268
1272
Lines 1344-1356 namespace JSC { Source/JavaScriptCore/bytecompiler/BytecodeGenerator.h_sec5
1344
        bool m_isBuiltinFunction { false };
1348
        bool m_isBuiltinFunction { false };
1345
        bool m_usesNonStrictEval { false };
1349
        bool m_usesNonStrictEval { false };
1346
        bool m_inTailPosition { false };
1350
        bool m_inTailPosition { false };
1347
        bool m_hasCachedVariablesUnderTDZ { false };
1348
        bool m_needsToUpdateArrowFunctionContext : 1;
1351
        bool m_needsToUpdateArrowFunctionContext : 1;
1349
        ECMAMode m_ecmaMode;
1352
        ECMAMode m_ecmaMode;
1350
        DerivedContextType m_derivedContextType { DerivedContextType::None };
1353
        DerivedContextType m_derivedContextType { DerivedContextType::None };
1351
1354
1352
        CompactVariableMap::Handle m_cachedVariablesUnderTDZ;
1353
1354
        struct CatchEntry {
1355
        struct CatchEntry {
1355
            TryData* tryData;
1356
            TryData* tryData;
1356
            VirtualRegister exceptionRegister;
1357
            VirtualRegister exceptionRegister;
- Source/JavaScriptCore/parser/VariableEnvironment.cpp +37 lines
Lines 61-66 void VariableEnvironment::markAllVariabl Source/JavaScriptCore/parser/VariableEnvironment.cpp_sec1
61
        value.setIsCaptured();
61
        value.setIsCaptured();
62
}
62
}
63
63
64
void VariableEnvironment::markAllVariablesAsCapturedWithMapValuesAlreadyMarkedAsCaptured()
65
{
66
    if (m_isEverythingCaptured)
67
        return;
68
69
    m_isEverythingCaptured = true; // For fast queries.
70
#if ASSERT_ENABLED
71
    // Every entry must be marked as captured for when we iterate through m_map and entry.isCaptured() is called.
72
    for (auto& value : m_map.values())
73
        ASSERT(value.isCaptured());
74
#endif
75
}
76
64
bool VariableEnvironment::hasCapturedVariables() const
77
bool VariableEnvironment::hasCapturedVariables() const
65
{
78
{
66
    if (m_isEverythingCaptured)
79
    if (m_isEverythingCaptured)
Lines 217-220 CompactVariableMap::Handle::Handle(Compa Source/JavaScriptCore/parser/VariableEnvironment.cpp_sec2
217
{ 
230
{ 
218
}
231
}
219
232
233
VariableEnvironment variableEnvironmentFromCompactHandleStack(const Vector<CompactVariableMap::Handle>& handles)
234
{
235
    VariableEnvironment result;
236
    bool everythingIsCaptured = true;
237
    for (size_t i = handles.size(); i--; ) {
238
        const CompactVariableEnvironment& compactEnvironment = handles[i].environment();
239
        for (size_t j = 0; j < compactEnvironment.variables().size(); ++j) {
240
            auto addResult = result.add(compactEnvironment.variables()[j]);
241
            if (!addResult.isNewEntry)
242
                continue;
243
            auto entry = compactEnvironment.variableMetadata()[j];
244
            if (compactEnvironment.isEverythingCaptured())
245
                entry.setIsCaptured();
246
            everythingIsCaptured &= entry.isCaptured();
247
            addResult.iterator->value = entry;
248
        }
249
    }
250
251
    if (everythingIsCaptured)
252
        result.markAllVariablesAsCapturedWithMapValuesAlreadyMarkedAsCaptured();
253
254
    return result;
255
}
256
220
} // namespace JSC
257
} // namespace JSC
- Source/JavaScriptCore/parser/VariableEnvironment.h +7 lines
Lines 154-159 public: Source/JavaScriptCore/parser/VariableEnvironment.h_sec1
154
    void markVariableAsCapturedIfDefined(const RefPtr<UniquedStringImpl>& identifier);
154
    void markVariableAsCapturedIfDefined(const RefPtr<UniquedStringImpl>& identifier);
155
    void markVariableAsCaptured(const RefPtr<UniquedStringImpl>& identifier);
155
    void markVariableAsCaptured(const RefPtr<UniquedStringImpl>& identifier);
156
    void markAllVariablesAsCaptured();
156
    void markAllVariablesAsCaptured();
157
    void markAllVariablesAsCapturedWithMapValuesAlreadyMarkedAsCaptured();
157
    bool hasCapturedVariables() const;
158
    bool hasCapturedVariables() const;
158
    bool captures(UniquedStringImpl* identifier) const;
159
    bool captures(UniquedStringImpl* identifier) const;
159
    void markVariableAsImported(const RefPtr<UniquedStringImpl>& identifier);
160
    void markVariableAsImported(const RefPtr<UniquedStringImpl>& identifier);
Lines 275-280 public: Source/JavaScriptCore/parser/VariableEnvironment.h_sec2
275
    bool operator==(const CompactVariableEnvironment&) const;
276
    bool operator==(const CompactVariableEnvironment&) const;
276
    unsigned hash() const { return m_hash; }
277
    unsigned hash() const { return m_hash; }
277
278
279
    const Vector<PackedRefPtr<UniquedStringImpl>>& variables() const { return m_variables; }
280
    const Vector<VariableEnvironmentEntry>& variableMetadata() const { return m_variableMetadata; }
281
    bool isEverythingCaptured() const { return m_isEverythingCaptured; }
282
278
private:
283
private:
279
    CompactVariableEnvironment() = default;
284
    CompactVariableEnvironment() = default;
280
285
Lines 404-407 private: Source/JavaScriptCore/parser/VariableEnvironment.h_sec3
404
    HashMap<CompactVariableMapKey, unsigned> m_map;
409
    HashMap<CompactVariableMapKey, unsigned> m_map;
405
};
410
};
406
411
412
VariableEnvironment variableEnvironmentFromCompactHandleStack(const Vector<CompactVariableMap::Handle>&);
413
407
} // namespace JSC
414
} // namespace JSC
- Source/JavaScriptCore/runtime/CachedTypes.cpp -2 / +2 lines
Lines 1744-1750 public: Source/JavaScriptCore/runtime/CachedTypes.cpp_sec1
1744
    void encode(Encoder& encoder, const UnlinkedFunctionExecutable::RareData& rareData)
1744
    void encode(Encoder& encoder, const UnlinkedFunctionExecutable::RareData& rareData)
1745
    {
1745
    {
1746
        m_classSource.encode(encoder, rareData.m_classSource);
1746
        m_classSource.encode(encoder, rareData.m_classSource);
1747
        m_parentScopeTDZVariables.encode(encoder, rareData.m_parentScopeTDZVariables);
1747
        m_parentScopeTDZVariables.encode(encoder, rareData.m_parentScopeTDZVariables); 
1748
    }
1748
    }
1749
1749
1750
    UnlinkedFunctionExecutable::RareData* decode(Decoder& decoder) const
1750
    UnlinkedFunctionExecutable::RareData* decode(Decoder& decoder) const
Lines 1758-1764 public: Source/JavaScriptCore/runtime/CachedTypes.cpp_sec2
1758
1758
1759
private:
1759
private:
1760
    CachedSourceCodeWithoutProvider m_classSource;
1760
    CachedSourceCodeWithoutProvider m_classSource;
1761
    CachedCompactVariableMapHandle m_parentScopeTDZVariables;
1761
    CachedVector<CachedCompactVariableMapHandle> m_parentScopeTDZVariables;
1762
};
1762
};
1763
1763
1764
class CachedFunctionExecutable : public CachedObject<UnlinkedFunctionExecutable> {
1764
class CachedFunctionExecutable : public CachedObject<UnlinkedFunctionExecutable> {

Return to Bug 199866