Skip to content
This repository has been archived by the owner on Oct 15, 2020. It is now read-only.

Commit

Permalink
[Merge chakra-core/ChakraCore@79c13b4641] [1.6>1.7] [MERGE #3464 @ane…
Browse files Browse the repository at this point in the history
…eshdk] Handle strict mode in console scope

Merge pull request #3464 from aneeshdk:ConsoleScopeStrictModeIssue

For store operations we were not checking for strict mode in console scope. Added a new opcode to handle strict mode in console scope.
  • Loading branch information
chakrabot authored and kfarnung committed Aug 10, 2017
1 parent 19468aa commit 1d4d95b
Show file tree
Hide file tree
Showing 11 changed files with 22 additions and 11 deletions.
1 change: 1 addition & 0 deletions deps/chakrashim/core/lib/Backend/IRBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4316,6 +4316,7 @@ IRBuilder::BuildElementP(Js::OpCode newOpcode, uint32 offset, Js::RegSlot regSlo
case Js::OpCode::ScopedStFld:
case Js::OpCode::ConsoleScopedStFld:
case Js::OpCode::ScopedStFldStrict:
case Js::OpCode::ConsoleScopedStFldStrict:
{
Assert(!isProfiled);

Expand Down
3 changes: 2 additions & 1 deletion deps/chakrashim/core/lib/Backend/Lower.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -548,12 +548,13 @@ Lowerer::LowerRange(IR::Instr *instrStart, IR::Instr *instrEnd, bool defaultDoFa
break;

case Js::OpCode::ConsoleScopedStFld:
case Js::OpCode::ConsoleScopedStFldStrict:
{
if (!noFieldFastPath)
{
m_lowererMD.GenerateFastScopedStFld(instr);
}
Js::PropertyOperationFlags flags = static_cast<Js::PropertyOperationFlags>(Js::PropertyOperation_None | Js::PropertyOperation_AllowUndeclInConsoleScope);
Js::PropertyOperationFlags flags = static_cast<Js::PropertyOperationFlags>((instr->m_opcode == Js::OpCode::ConsoleScopedStFld ? Js::PropertyOperation_None : Js::PropertyOperation_StrictMode) | Js::PropertyOperation_AllowUndeclInConsoleScope);
instrPrev = this->LowerScopedStFld(instr, IR::HelperOp_ConsolePatchSetPropertyScoped, true, true, flags);
break;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -936,6 +936,7 @@ namespace Js
case OpCode::ScopedStFld:
case OpCode::ConsoleScopedStFld:
case OpCode::ScopedStFldStrict:
case OpCode::ConsoleScopedStFldStrict:
Output::Print(_u(" %s = R%d, R%d #%d"), pPropertyName->GetBuffer(), data->Value,
Js::FunctionBody::RootObjectRegSlot, data->inlineCacheIndex);
break;
Expand Down
6 changes: 3 additions & 3 deletions deps/chakrashim/core/lib/Runtime/ByteCode/ByteCodeEmitter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5108,17 +5108,17 @@ void ByteCodeGenerator::EmitPropStore(Js::RegSlot rhsLocation, Symbol *sym, Iden
if (sym == nullptr || sym->GetIsGlobal())
{
Js::PropertyId propertyId = sym ? sym->EnsurePosition(this) : pid->GetPropertyId();
bool isConsoleScopeLetConst = this->IsConsoleScopeEval() && (isLetDecl || isConstDecl);
if (this->flags & fscrEval)
{
if (funcInfo->byteCodeFunction->GetIsStrictMode() && funcInfo->IsGlobalFunction())
{
uint cacheId = funcInfo->FindOrAddInlineCacheId(funcInfo->frameDisplayRegister, propertyId, false, true);
this->m_writer.ElementP(GetScopedStFldOpCode(funcInfo), rhsLocation, cacheId);
this->m_writer.ElementP(GetScopedStFldOpCode(funcInfo, isConsoleScopeLetConst), rhsLocation, cacheId);
}
else
{
uint cacheId = funcInfo->FindOrAddInlineCacheId(funcInfo->GetEnvRegister(), propertyId, false, true);
bool isConsoleScopeLetConst = this->IsConsoleScopeEval() && (isLetDecl || isConstDecl);
// In "eval", store to a symbol with unknown scope goes through the closure environment.
this->m_writer.ElementP(GetScopedStFldOpCode(funcInfo, isConsoleScopeLetConst), rhsLocation, cacheId);
}
Expand All @@ -5128,7 +5128,7 @@ void ByteCodeGenerator::EmitPropStore(Js::RegSlot rhsLocation, Symbol *sym, Iden
uint cacheId = funcInfo->FindOrAddInlineCacheId(funcInfo->GetEnvRegister(), propertyId, false, true);

// In "eval", store to a symbol with unknown scope goes through the closure environment.
this->m_writer.ElementP(GetScopedStFldOpCode(funcInfo), rhsLocation, cacheId);
this->m_writer.ElementP(GetScopedStFldOpCode(funcInfo, isConsoleScopeLetConst), rhsLocation, cacheId);
}
else
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1915,11 +1915,7 @@ Js::OpCode ByteCodeGenerator::GetStFldOpCode(FuncInfo* funcInfo, bool isRoot, bo
/* static */
Js::OpCode ByteCodeGenerator::GetScopedStFldOpCode(FuncInfo* funcInfo, bool isConsoleScopeLetConst)
{
if (isConsoleScopeLetConst)
{
return Js::OpCode::ConsoleScopedStFld;
}
return GetScopedStFldOpCode(funcInfo->GetIsStrictMode());
return GetScopedStFldOpCode(funcInfo->GetIsStrictMode(), isConsoleScopeLetConst);
}

/* static */
Expand Down
6 changes: 4 additions & 2 deletions deps/chakrashim/core/lib/Runtime/ByteCode/ByteCodeGenerator.h
Original file line number Diff line number Diff line change
Expand Up @@ -338,9 +338,11 @@ class ByteCodeGenerator
isRoot ? Js::OpCode::StRootFld : Js::OpCode::StFld;
}
static Js::OpCode GetStFldOpCode(FuncInfo* funcInfo, bool isRoot, bool isLetDecl, bool isConstDecl, bool isClassMemberInit);
static Js::OpCode GetScopedStFldOpCode(bool isStrictMode)
static Js::OpCode GetScopedStFldOpCode(bool isStrictMode, bool isConsoleScope = false)
{
return isStrictMode ? Js::OpCode::ScopedStFldStrict : Js::OpCode::ScopedStFld;
return isStrictMode ?
(isConsoleScope ? Js::OpCode::ConsoleScopedStFldStrict : Js::OpCode::ScopedStFldStrict) :
(isConsoleScope ? Js::OpCode::ConsoleScopedStFld : Js::OpCode::ScopedStFld);
}
static Js::OpCode GetScopedStFldOpCode(FuncInfo* funcInfo, bool isConsoleScopeLetConst = false);
static Js::OpCode GetStElemIOpCode(bool isStrictMode)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1944,6 +1944,7 @@ namespace Js
case OpCode::ScopedStFld:
case OpCode::ConsoleScopedStFld:
case OpCode::ScopedStFldStrict:
case OpCode::ConsoleScopedStFldStrict:
break;

case OpCode::LdLocalFld:
Expand Down
1 change: 1 addition & 0 deletions deps/chakrashim/core/lib/Runtime/ByteCode/OpCodes.h
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,7 @@ MACRO_WMS( ScopedInitFunc, ElementScopedC, OpSideEffect
MACRO_WMS( ScopedStFld, ElementP, OpSideEffect|OpHasImplicitCall|OpPostOpDbgBailOut) // Store to function's scope stack
MACRO_EXTEND_WMS( ConsoleScopedStFld, ElementP, OpSideEffect|OpHasImplicitCall|OpPostOpDbgBailOut) // Store to function's scope stack
MACRO_WMS( ScopedStFldStrict, ElementP, OpSideEffect|OpHasImplicitCall|OpPostOpDbgBailOut) // Store to function's scope stack
MACRO_EXTEND_WMS( ConsoleScopedStFldStrict, ElementP, OpSideEffect|OpHasImplicitCall|OpPostOpDbgBailOut) // Store to function's scope stack in strict mode for console scope
MACRO_WMS( ScopedDeleteFld, ElementScopedC, OpSideEffect|OpHasImplicitCall|OpPostOpDbgBailOut) // Remove a property through a stack of scopes
MACRO_WMS( ScopedDeleteFldStrict, ElementScopedC, OpSideEffect|OpHasImplicitCall|OpPostOpDbgBailOut) // Remove a property through a stack of scopes in strict mode
MACRO_WMS_PROFILED( LdSlot, ElementSlot, OpTempNumberSources)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,7 @@ EXDEF3_WMS(CUSTOM_L_Value, ScopedLdFldForTypeOf, OP_GetPropertyFo
DEF3_WMS(CUSTOM, ScopedStFld, OP_SetPropertyScoped, ElementP)
EXDEF3_WMS(CUSTOM, ConsoleScopedStFld, OP_ConsoleSetPropertyScoped, ElementP)
DEF3_WMS(CUSTOM, ScopedStFldStrict, OP_SetPropertyScopedStrict, ElementP)
EXDEF3_WMS(CUSTOM, ConsoleScopedStFldStrict, OP_ConsoleSetPropertyScopedStrict, ElementP)
DEF2_WMS(GET_ELEM_IMem, DeleteElemI_A, JavascriptOperators::OP_DeleteElementI)
DEF2_WMS(GET_ELEM_IMem_Strict, DeleteElemIStrict_A, JavascriptOperators::OP_DeleteElementI)
DEF3_WMS(CUSTOM_L_Value, ScopedLdInst, OP_ScopedLdInst, ElementScopedC2)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4471,6 +4471,12 @@ namespace Js
OP_SetPropertyScoped(playout, PropertyOperation_AllowUndeclInConsoleScope);
}

template <class T>
void InterpreterStackFrame::OP_ConsoleSetPropertyScopedStrict(unaligned T* playout)
{
OP_SetPropertyScoped(playout, (PropertyOperationFlags)(PropertyOperation_StrictMode | PropertyOperation_AllowUndeclInConsoleScope));
}

template <class T>
inline bool InterpreterStackFrame::TrySetPropertyLocalFastPath(unaligned T* playout, PropertyId pid, Var instance, InlineCache*& inlineCache, PropertyOperationFlags flags)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -541,6 +541,7 @@ namespace Js
template <class T> void OP_SetPropertyScoped_NoFastPath(unaligned T* playout, PropertyOperationFlags flags);
template <class T> void OP_SetPropertyScopedStrict(unaligned T* playout);
template <class T> void OP_ConsoleSetPropertyScoped(unaligned T* playout);
template <class T> void OP_ConsoleSetPropertyScopedStrict(unaligned T* playout);

template <class T> void DoSetProperty(unaligned T* playout, Var instance, PropertyOperationFlags flags);
template <class T> void DoSetSuperProperty(unaligned T* playout, Var instance, PropertyOperationFlags flags);
Expand Down

0 comments on commit 1d4d95b

Please sign in to comment.