@@ -308,14 +308,17 @@ void CustomExternalWrapperObject::SetPrototype(RecyclableObject* newPrototype)
308
308
return ;
309
309
}
310
310
311
+ // setting the value could be deferred and now we are on a different context from
312
+ // make sure the value has the same context as the containing object.
313
+ newPrototype = VarTo<RecyclableObject>(Js::CrossSite::MarshalVar (this ->GetScriptContext (), newPrototype));
311
314
DynamicObject::SetPrototype (newPrototype);
312
315
}
313
316
314
317
Js::Var CustomExternalWrapperObject::GetValueFromDescriptor (Js::Var instance, Js::PropertyDescriptor propertyDescriptor, Js::ScriptContext * requestContext)
315
318
{
316
319
if (propertyDescriptor.ValueSpecified ())
317
320
{
318
- return Js::CrossSite::MarshalVar (requestContext, propertyDescriptor.GetValue () );
321
+ return propertyDescriptor.GetValue ();
319
322
}
320
323
if (propertyDescriptor.GetterSpecified ())
321
324
{
@@ -588,11 +591,20 @@ BOOL CustomExternalWrapperObject::DefineOwnPropertyDescriptor(Js::RecyclableObje
588
591
Assert (!requestContext->IsHeapEnumInProgress ());
589
592
if (nullptr == defineOwnPropertyMethod)
590
593
{
594
+ Js::PropertyDescriptor desc = descriptor;
595
+
596
+ if (desc.ValueSpecified ())
597
+ {
598
+ // setting the value could be deferred and now we are on a different context from
599
+ // make sure the value has the same context as the containing object.
600
+ desc.SetValue (Js::CrossSite::MarshalVar (targetObj->GetScriptContext (), descriptor.GetValue ()));
601
+ }
602
+
591
603
PropertyDescriptor currentDescriptor;
592
604
BOOL isCurrentDescriptorDefined = JavascriptOperators::GetOwnPropertyDescriptor (obj, propId, requestContext, ¤tDescriptor);
593
605
594
606
bool isExtensible = !!obj->IsExtensible ();
595
- return Js::JavascriptOperators::ValidateAndApplyPropertyDescriptor<true >(obj, propId, descriptor , isCurrentDescriptorDefined ? ¤tDescriptor : nullptr , isExtensible, throwOnError, requestContext);
607
+ return Js::JavascriptOperators::ValidateAndApplyPropertyDescriptor<true >(obj, propId, desc , isCurrentDescriptorDefined ? ¤tDescriptor : nullptr , isExtensible, throwOnError, requestContext);
596
608
}
597
609
598
610
Js::Var descVar = descriptor.GetOriginal ();
@@ -651,6 +663,9 @@ BOOL CustomExternalWrapperObject::SetPropertyTrap(Js::Var receiver, SetPropertyT
651
663
};
652
664
auto fn = [&]()->BOOL
653
665
{
666
+ // setting the value could be deferred and now we are on a different context from
667
+ // make sure the value has the same context as the containing object.
668
+ newValue = Js::CrossSite::MarshalVar (this ->GetScriptContext (), newValue);
654
669
return DynamicObject::SetProperty (propertyNameString, newValue, propertyOperationFlags, nullptr );
655
670
};
656
671
return SetPropertyTrap (receiver, setPropertyTrapKind, getPropertyName, newValue, requestContext, propertyOperationFlags, FALSE , fn);
@@ -708,7 +723,6 @@ BOOL CustomExternalWrapperObject::SetPropertyTrap(Js::Var receiver, SetPropertyT
708
723
Js::PropertyQueryFlags CustomExternalWrapperObject::GetPropertyQuery (Js::Var originalInstance, Js::PropertyId propertyId, Js::Var* value, Js::PropertyValueInfo* info, Js::ScriptContext* requestContext)
709
724
{
710
725
if (!this ->VerifyObjectAlive ()) return Js::PropertyQueryFlags::Property_NotFound;
711
- originalInstance = Js::CrossSite::MarshalVar (GetScriptContext (), originalInstance);
712
726
Js::PropertyDescriptor result;
713
727
714
728
auto fn = [&](Js::RecyclableObject* object)-> BOOL {
@@ -735,7 +749,6 @@ Js::PropertyQueryFlags CustomExternalWrapperObject::GetPropertyQuery(Js::Var ori
735
749
Js::PropertyQueryFlags CustomExternalWrapperObject::GetPropertyQuery (Js::Var originalInstance, Js::JavascriptString* propertyNameString, Js::Var* value, Js::PropertyValueInfo* info, Js::ScriptContext* requestContext)
736
750
{
737
751
if (!this ->VerifyObjectAlive ()) return Js::PropertyQueryFlags::Property_NotFound;
738
- originalInstance = Js::CrossSite::MarshalVar (GetScriptContext (), originalInstance);
739
752
Js::PropertyDescriptor result;
740
753
741
754
auto fn = [&](Js::RecyclableObject* object)-> BOOL {
@@ -766,7 +779,6 @@ Js::PropertyQueryFlags CustomExternalWrapperObject::GetPropertyQuery(Js::Var ori
766
779
Js::PropertyQueryFlags CustomExternalWrapperObject::GetPropertyReferenceQuery (Js::Var originalInstance, Js::PropertyId propertyId, Js::Var* value, Js::PropertyValueInfo* info, Js::ScriptContext* requestContext)
767
780
{
768
781
if (!this ->VerifyObjectAlive ()) return Js::PropertyQueryFlags::Property_NotFound;
769
- originalInstance = Js::CrossSite::MarshalVar (GetScriptContext (), originalInstance);
770
782
Js::PropertyDescriptor result;
771
783
772
784
auto fn = [&](Js::RecyclableObject* object)-> BOOL {
@@ -826,7 +838,6 @@ BOOL CustomExternalWrapperObject::HasOwnItem(uint32 index)
826
838
Js::PropertyQueryFlags CustomExternalWrapperObject::GetItemQuery (Js::Var originalInstance, uint32 index, Js::Var* value, Js::ScriptContext * requestContext)
827
839
{
828
840
if (!this ->VerifyObjectAlive ()) return Js::PropertyQueryFlags::Property_NotFound;
829
- originalInstance = Js::CrossSite::MarshalVar (GetScriptContext (), originalInstance);
830
841
Js::PropertyDescriptor result;
831
842
832
843
auto fn = [&](Js::RecyclableObject* object)-> BOOL {
@@ -857,7 +868,6 @@ Js::PropertyQueryFlags CustomExternalWrapperObject::GetItemQuery(Js::Var origina
857
868
Js::PropertyQueryFlags CustomExternalWrapperObject::GetItemReferenceQuery (Js::Var originalInstance, uint32 index, Js::Var* value, Js::ScriptContext * requestContext)
858
869
{
859
870
if (!this ->VerifyObjectAlive ()) return Js::PropertyQueryFlags::Property_NotFound;
860
- originalInstance = Js::CrossSite::MarshalVar (GetScriptContext (), originalInstance);
861
871
862
872
Js::PropertyDescriptor result;
863
873
auto fn = [&](Js::RecyclableObject* object)-> BOOL {
@@ -898,11 +908,17 @@ BOOL CustomExternalWrapperObject::SetItem(uint32 index, Js::Var value, Js::Prope
898
908
899
909
auto fn = [&]()->BOOL
900
910
{
911
+ // setting the value could be deferred and now we are on a different context from
912
+ // make sure the value has the same context as the containing object.
913
+ value = Js::CrossSite::MarshalVar (this ->GetScriptContext (), value);
901
914
return DynamicObject::SetItem (index, value, flags);
902
915
};
903
916
BOOL trapResult = SetPropertyTrap (this , CustomExternalWrapperObject::SetPropertyTrapKind::SetItemKind, getPropertyName, value, GetScriptContext (), flags, FALSE , fn);
904
917
if (!trapResult)
905
918
{
919
+ // setting the value could be deferred and now we are on a different context from
920
+ // make sure the value has the same context as the containing object.
921
+ value = Js::CrossSite::MarshalVar (this ->GetScriptContext (), value);
906
922
return Js::DynamicObject::SetItem (index, value, flags);
907
923
}
908
924
@@ -1020,6 +1036,7 @@ BOOL CustomExternalWrapperObject::GetEnumerator(Js::JavascriptStaticEnumerator *
1020
1036
// if (desc.enumerable) yield key;
1021
1037
if (desc.IsEnumerable ())
1022
1038
{
1039
+ // TODO: (vsadov) not sure if should marshal here, it is "getting"
1023
1040
return VarTo<JavascriptString>(CrossSite::MarshalVar (
1024
1041
scriptContext, propertyName, propertyName->GetScriptContext ()));
1025
1042
}
@@ -1040,7 +1057,6 @@ BOOL CustomExternalWrapperObject::GetEnumerator(Js::JavascriptStaticEnumerator *
1040
1057
BOOL CustomExternalWrapperObject::SetProperty (Js::PropertyId propertyId, Js::Var value, Js::PropertyOperationFlags flags, Js::PropertyValueInfo* info)
1041
1058
{
1042
1059
if (!this ->VerifyObjectAlive ()) return FALSE ;
1043
- // value = Js::CrossSite::MarshalVar(GetScriptContext(), value);
1044
1060
PROBE_STACK (GetScriptContext (), Js::Constants::MinStackDefault);
1045
1061
1046
1062
auto getPropertyName = [&](Js::ScriptContext * requestContext, Js::Var * isPropertyNameNumeric, Js::Var * propertyNameNumericValue)->Js ::Var
@@ -1050,6 +1066,9 @@ BOOL CustomExternalWrapperObject::SetProperty(Js::PropertyId propertyId, Js::Var
1050
1066
1051
1067
auto fn = [&]()->BOOL
1052
1068
{
1069
+ // setting the value could be deferred and now we are on a different context from
1070
+ // make sure the value has the same context as the containing object.
1071
+ value = Js::CrossSite::MarshalVar (this ->GetScriptContext (), value);
1053
1072
return DynamicObject::SetProperty (propertyId, value, flags, info);
1054
1073
};
1055
1074
@@ -1068,6 +1087,9 @@ BOOL CustomExternalWrapperObject::SetProperty(Js::JavascriptString* propertyName
1068
1087
1069
1088
auto fn = [&]()->BOOL
1070
1089
{
1090
+ // setting the value could be deferred and now we are on a different context from
1091
+ // make sure the value has the same context as the containing object.
1092
+ value = Js::CrossSite::MarshalVar (this ->GetScriptContext (), value);
1071
1093
return DynamicObject::SetProperty (propertyNameString, value, flags, info);
1072
1094
};
1073
1095
@@ -1101,6 +1123,9 @@ BOOL CustomExternalWrapperObject::InitProperty(PropertyId propertyId, Var value,
1101
1123
return FALSE ;
1102
1124
}
1103
1125
1126
+ // setting the value could be deferred and now we are on a different context from
1127
+ // make sure the value has the same context as the containing object.
1128
+ value = Js::CrossSite::MarshalVar (this ->GetScriptContext (), value);
1104
1129
return DynamicObject::InitProperty (propertyId, value, flags, info);
1105
1130
}
1106
1131
0 commit comments