CommonSlowPathsInlines.h [plain text]
#pragma once
#include "BytecodeStructs.h"
#include "CommonSlowPaths.h"
namespace JSC {
namespace CommonSlowPaths {
inline void tryCachePutToScopeGlobal(
JSGlobalObject* globalObject, CodeBlock* codeBlock, OpPutToScope& bytecode, JSObject* scope,
PutPropertySlot& slot, const Identifier& ident)
{
auto& metadata = bytecode.metadata(codeBlock);
ResolveType resolveType = metadata.m_getPutInfo.resolveType();
switch (resolveType) {
case UnresolvedProperty:
case UnresolvedPropertyWithVarInjectionChecks: {
if (scope->isGlobalObject()) {
ResolveType newResolveType = needsVarInjectionChecks(resolveType) ? GlobalPropertyWithVarInjectionChecks : GlobalProperty;
resolveType = newResolveType; ConcurrentJSLocker locker(codeBlock->m_lock);
metadata.m_getPutInfo = GetPutInfo(metadata.m_getPutInfo.resolveMode(), newResolveType, metadata.m_getPutInfo.initializationMode(), metadata.m_getPutInfo.ecmaMode());
break;
}
FALLTHROUGH;
}
case GlobalProperty:
case GlobalPropertyWithVarInjectionChecks: {
if (scope->isGlobalLexicalEnvironment()) {
JSGlobalLexicalEnvironment* globalLexicalEnvironment = jsCast<JSGlobalLexicalEnvironment*>(scope);
ResolveType newResolveType = needsVarInjectionChecks(resolveType) ? GlobalLexicalVarWithVarInjectionChecks : GlobalLexicalVar;
SymbolTableEntry entry = globalLexicalEnvironment->symbolTable()->get(ident.impl());
ASSERT(!entry.isNull());
ConcurrentJSLocker locker(codeBlock->m_lock);
metadata.m_getPutInfo = GetPutInfo(metadata.m_getPutInfo.resolveMode(), newResolveType, metadata.m_getPutInfo.initializationMode(), metadata.m_getPutInfo.ecmaMode());
metadata.m_watchpointSet = entry.watchpointSet();
metadata.m_operand = reinterpret_cast<uintptr_t>(globalLexicalEnvironment->variableAt(entry.scopeOffset()).slot());
return;
}
break;
}
default:
return;
}
if (resolveType == GlobalProperty || resolveType == GlobalPropertyWithVarInjectionChecks) {
VM& vm = getVM(globalObject);
JSGlobalObject* globalObject = codeBlock->globalObject();
ASSERT(globalObject == scope || globalObject->varInjectionWatchpoint()->hasBeenInvalidated());
if (!slot.isCacheablePut()
|| slot.base() != scope
|| scope != globalObject
|| !scope->structure(vm)->propertyAccessesAreCacheable())
return;
if (slot.type() == PutPropertySlot::NewProperty) {
return;
}
scope->structure(vm)->didCachePropertyReplacement(vm, slot.cachedOffset());
ConcurrentJSLocker locker(codeBlock->m_lock);
metadata.m_structure.set(vm, codeBlock, scope->structure(vm));
metadata.m_operand = slot.cachedOffset();
}
}
inline void tryCacheGetFromScopeGlobal(
JSGlobalObject* globalObject, CodeBlock* codeBlock, VM& vm, OpGetFromScope& bytecode, JSObject* scope, PropertySlot& slot, const Identifier& ident)
{
auto& metadata = bytecode.metadata(codeBlock);
ResolveType resolveType = metadata.m_getPutInfo.resolveType();
switch (resolveType) {
case UnresolvedProperty:
case UnresolvedPropertyWithVarInjectionChecks: {
if (scope->isGlobalObject()) {
ResolveType newResolveType = needsVarInjectionChecks(resolveType) ? GlobalPropertyWithVarInjectionChecks : GlobalProperty;
resolveType = newResolveType; ConcurrentJSLocker locker(codeBlock->m_lock);
metadata.m_getPutInfo = GetPutInfo(metadata.m_getPutInfo.resolveMode(), newResolveType, metadata.m_getPutInfo.initializationMode(), metadata.m_getPutInfo.ecmaMode());
break;
}
FALLTHROUGH;
}
case GlobalProperty:
case GlobalPropertyWithVarInjectionChecks: {
if (scope->isGlobalLexicalEnvironment()) {
JSGlobalLexicalEnvironment* globalLexicalEnvironment = jsCast<JSGlobalLexicalEnvironment*>(scope);
ResolveType newResolveType = needsVarInjectionChecks(resolveType) ? GlobalLexicalVarWithVarInjectionChecks : GlobalLexicalVar;
SymbolTableEntry entry = globalLexicalEnvironment->symbolTable()->get(ident.impl());
ASSERT(!entry.isNull());
ConcurrentJSLocker locker(codeBlock->m_lock);
metadata.m_getPutInfo = GetPutInfo(metadata.m_getPutInfo.resolveMode(), newResolveType, metadata.m_getPutInfo.initializationMode(), metadata.m_getPutInfo.ecmaMode());
metadata.m_watchpointSet = entry.watchpointSet();
metadata.m_operand = reinterpret_cast<uintptr_t>(globalLexicalEnvironment->variableAt(entry.scopeOffset()).slot());
return;
}
break;
}
default:
return;
}
if (resolveType == GlobalProperty || resolveType == GlobalPropertyWithVarInjectionChecks) {
ASSERT(scope == globalObject || globalObject->varInjectionWatchpoint()->hasBeenInvalidated());
if (slot.isCacheableValue() && slot.slotBase() == scope && scope == globalObject && scope->structure(vm)->propertyAccessesAreCacheable()) {
Structure* structure = scope->structure(vm);
{
ConcurrentJSLocker locker(codeBlock->m_lock);
metadata.m_structure.set(vm, codeBlock, structure);
metadata.m_operand = slot.cachedOffset();
}
structure->startWatchingPropertyForReplacements(vm, slot.cachedOffset());
}
}
}
}}