Skip to content

Commit 07207dd

Browse files
Fixed a pair of issues affecting GlobalMembers on V8.
1 parent ff7d454 commit 07207dd

2 files changed

Lines changed: 21 additions & 3 deletions

File tree

ClearScript/V8/ClearScriptV8/V8ContextImpl.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -697,7 +697,7 @@ void V8ContextImpl::GetGlobalProperty(Local<String> hName, const PropertyCallbac
697697
{
698698
for (auto it = stack.rbegin(); it != stack.rend(); it++)
699699
{
700-
if ((*it)->Has(hName))
700+
if ((*it)->HasOwnProperty(hName))
701701
{
702702
CALLBACK_RETURN((*it)->Get(hName));
703703
}
@@ -721,8 +721,9 @@ void V8ContextImpl::SetGlobalProperty(Local<String> hName, Local<Value> hValue,
721721
{
722722
for (auto it = stack.rbegin(); it != stack.rend(); it++)
723723
{
724-
if ((*it)->HasOwnProperty(hName) && (*it)->Set(hName, hValue))
724+
if ((*it)->HasOwnProperty(hName))
725725
{
726+
(*it)->Set(hName, hValue);
726727
CALLBACK_RETURN(hValue);
727728
}
728729
}
@@ -745,7 +746,7 @@ void V8ContextImpl::QueryGlobalProperty(Local<String> hName, const PropertyCallb
745746
{
746747
for (auto it = stack.rbegin(); it != stack.rend(); it++)
747748
{
748-
if ((*it)->Has(hName))
749+
if ((*it)->HasOwnProperty(hName))
749750
{
750751
CALLBACK_RETURN((*it)->GetPropertyAttributes(hName));
751752
}

ClearScriptTest/BugFixTest.cs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -790,6 +790,23 @@ public void BugFix_Resurrection_V8ScriptItem()
790790
}
791791
}
792792

793+
[TestMethod, TestCategory("BugFix")]
794+
public void BugFix_V8_GlobalMembers_ReadOnlyPropertyCrash()
795+
{
796+
// this test is for a crash that occurred only on debug V8 builds
797+
engine.AddHostObject("bag", HostItemFlags.GlobalMembers, new PropertyBag());
798+
engine.AddHostObject("test", HostItemFlags.GlobalMembers, new { foo = 123 });
799+
TestUtil.AssertException<ScriptEngineException>(() => engine.Execute("foo = 456"));
800+
}
801+
802+
[TestMethod, TestCategory("BugFix")]
803+
public void BugFix_V8_GlobalMembers_NativeFunctionHiding()
804+
{
805+
engine.Execute("function toString() { return 'ABC'; }");
806+
engine.AddHostObject("bag", HostItemFlags.GlobalMembers, new PropertyBag());
807+
Assert.AreEqual("ABC", engine.Evaluate("toString()"));
808+
}
809+
793810
// ReSharper restore InconsistentNaming
794811

795812
#endregion

0 commit comments

Comments
 (0)