Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
pleath authored and rajeshpeter committed Apr 9, 2020
1 parent 9298227 commit cd58e8e
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 18 deletions.
52 changes: 37 additions & 15 deletions lib/Runtime/ByteCode/ByteCodeEmitter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4262,21 +4262,33 @@ void ByteCodeGenerator::EmitLoadInstance(Symbol *sym, IdentPtr pid, Js::RegSlot
funcInfo->FindOrAddReferencedPropertyId(propertyId),
envIndex + Js::FrameDisplay::GetOffsetOfScopes() / sizeof(Js::Var));

Js::RegSlot tmpReg = funcInfo->AcquireTmpRegister();

AssertOrFailFast(scope->GetIsObject());
this->m_writer.SlotI1(Js::OpCode::LdEnvObj, tmpReg,
envIndex + Js::FrameDisplay::GetOffsetOfScopes() / sizeof(Js::Var));

Js::OpCode op = unwrapWithObj ? Js::OpCode::UnwrapWithObj : Js::OpCode::Ld_A;

this->m_writer.Reg2(op, instLocation, tmpReg);
if (thisLocation != Js::Constants::NoRegister)
if (unwrapWithObj)
{
this->m_writer.Reg2(op, thisLocation, tmpReg);
Js::RegSlot tmpReg = funcInfo->AcquireTmpRegister();

this->m_writer.SlotI1(Js::OpCode::LdEnvObj, tmpReg,
envIndex + Js::FrameDisplay::GetOffsetOfScopes() / sizeof(Js::Var));

this->m_writer.Reg2(Js::OpCode::UnwrapWithObj, instLocation, tmpReg);
if (thisLocation != Js::Constants::NoRegister)
{
this->m_writer.Reg2(Js::OpCode::UnwrapWithObj, thisLocation, tmpReg);
}

funcInfo->ReleaseTmpRegister(tmpReg);
}
else
{
this->m_writer.SlotI1(Js::OpCode::LdEnvObj, instLocation,
envIndex + Js::FrameDisplay::GetOffsetOfScopes() / sizeof(Js::Var));

funcInfo->ReleaseTmpRegister(tmpReg);
if (thisLocation != Js::Constants::NoRegister)
{
this->m_writer.Reg2(Js::OpCode::Ld_A, thisLocation, funcInfo->undefinedConstantRegister);
}
}
}
else if (scopeLocation != Js::Constants::NoRegister && scopeLocation == funcInfo->frameObjRegister)
{
Expand All @@ -4288,19 +4300,29 @@ void ByteCodeGenerator::EmitLoadInstance(Symbol *sym, IdentPtr pid, Js::RegSlot
this->m_writer.Reg1(Js::OpCode::LdLocalObj, instLocation);
if (thisLocation != Js::Constants::NoRegister)
{
this->m_writer.Reg1(Js::OpCode::LdLocalObj, thisLocation);
this->m_writer.Reg2(Js::OpCode::Ld_A, thisLocation, funcInfo->undefinedConstantRegister);
}
}
else
{
this->m_writer.BrProperty(Js::OpCode::BrOnNoProperty, nextLabel, scopeLocation,
funcInfo->FindOrAddReferencedPropertyId(propertyId));

Js::OpCode op = unwrapWithObj ? Js::OpCode::UnwrapWithObj : Js::OpCode::Ld_A;
this->m_writer.Reg2(op, instLocation, scopeLocation);
if (thisLocation != Js::Constants::NoRegister)
if (unwrapWithObj)
{
this->m_writer.Reg2(op, thisLocation, scopeLocation);
this->m_writer.Reg2(Js::OpCode::UnwrapWithObj, instLocation, scopeLocation);
if (thisLocation != Js::Constants::NoRegister)
{
this->m_writer.Reg2(Js::OpCode::UnwrapWithObj, thisLocation, scopeLocation);
}
}
else
{
this->m_writer.Reg2(Js::OpCode::Ld_A, instLocation, scopeLocation);
if (thisLocation != Js::Constants::NoRegister)
{
this->m_writer.Reg2(Js::OpCode::Ld_A, thisLocation, funcInfo->undefinedConstantRegister);
}
}
}

Expand Down
3 changes: 1 addition & 2 deletions lib/Runtime/Language/JavascriptOperators.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2072,8 +2072,7 @@ using namespace Js;
// HasProperty will call UnscopablesWrapperObject's HasProperty which will do the filtering
// All we have to do here is unwrap the object hence the api call

*thisVar = obj->GetThisObjectOrUnWrap();
return *thisVar;
return obj->GetThisAndUnwrappedInstance(thisVar);
}
}

Expand Down
6 changes: 6 additions & 0 deletions lib/Runtime/Types/RecyclableObject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,12 @@ namespace Js
return this;
}

RecyclableObject* RecyclableObject::GetThisAndUnwrappedInstance(Var* thisVar) const
{
*thisVar = this->GetLibrary()->GetUndefined();
return (RecyclableObject*)this;
}

// In order to avoid a branch, every object has an entry point if it gets called like a
// function - however, if it can't be called like a function, it's set to DefaultEntryPoint
// which will emit an error.
Expand Down
1 change: 1 addition & 0 deletions lib/Runtime/Types/RecyclableObject.h
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,7 @@ namespace Js {
virtual uint GetSpecialPropertyCount() const { return 0; }
virtual PropertyId const * GetSpecialPropertyIds() const { return nullptr; }
virtual RecyclableObject* GetThisObjectOrUnWrap(); // Due to the withScope object there are times we need to unwrap
virtual RecyclableObject* GetThisAndUnwrappedInstance(Var* thisVar) const;

virtual BOOL HasInstance(Var instance, ScriptContext* scriptContext, IsInstInlineCache* inlineCache = NULL);

Expand Down
6 changes: 6 additions & 0 deletions lib/Runtime/Types/UnscopablesWrapperObject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@ namespace Js
return static_cast<UnscopablesWrapperObject*>(aValue);
}

RecyclableObject * UnscopablesWrapperObject::GetThisAndUnwrappedInstance(Var* thisVar) const
{
*thisVar = this->GetWrappedObject();
return this->GetWrappedObject();
}

PropertyQueryFlags UnscopablesWrapperObject::HasPropertyQuery(PropertyId propertyId, _Inout_opt_ PropertyValueInfo* info)
{
return JavascriptConversion::BooleanToPropertyQueryFlags(JavascriptOperators::HasPropertyUnscopables(wrappedObject, propertyId));
Expand Down
3 changes: 2 additions & 1 deletion lib/Runtime/Types/UnscopablesWrapperObject.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ namespace Js
static bool Is(Var aValue);
static UnscopablesWrapperObject* FromVar(Var value);
static UnscopablesWrapperObject* UnsafeFromVar(Var value);
RecyclableObject *GetWrappedObject() { return wrappedObject; }
RecyclableObject *GetWrappedObject() const { return wrappedObject; }
virtual RecyclableObject* GetThisAndUnwrappedInstance(Var* thisVar) const override;
virtual PropertyQueryFlags HasPropertyQuery(PropertyId propertyId, _Inout_opt_ PropertyValueInfo* info) override;
virtual BOOL HasOwnProperty(PropertyId propertyId) override;
virtual BOOL SetProperty(PropertyId propertyId, Var value, PropertyOperationFlags flags, PropertyValueInfo* info) override;
Expand Down

0 comments on commit cd58e8e

Please sign in to comment.