Var CrossSite::MarshalFrameDisplay(ScriptContext* scriptContext, FrameDisplay *display) { TTD_XSITE_LOG(scriptContext, "MarshalFrameDisplay", nullptr); uint16 length = display->GetLength(); FrameDisplay *newDisplay = RecyclerNewPlus(scriptContext->GetRecycler(), length * sizeof(Var), FrameDisplay, length); for (uint16 i = 0; i < length; i++) { Var value = display->GetItem(i); if (WithScopeObject::Is(value)) { // Here we are marshalling the wrappedObject and then ReWrapping th object in the new context. RecyclableObject* wrappedObject = WithScopeObject::FromVar(value)->GetWrappedObject(); ScriptContext* wrappedObjectScriptContext = wrappedObject->GetScriptContext(); value = JavascriptOperators::ToWithObject(CrossSite::MarshalVar(scriptContext, wrappedObject, wrappedObjectScriptContext), scriptContext); } else { value = CrossSite::MarshalVar(scriptContext, value); } newDisplay->SetItem(i, value); } return (Var)newDisplay; }
BOOL CrossSite::NeedMarshalVar(Var instance, ScriptContext * requestContext) { if (TaggedNumber::Is(instance)) { return FALSE; } RecyclableObject * object = RecyclableObject::UnsafeFromVar(instance); if (object->GetScriptContext() == requestContext) { return FALSE; } if (DynamicType::Is(object->GetTypeId())) { return !DynamicObject::UnsafeFromVar(object)->IsCrossSiteObject() && !object->IsExternal(); } return TRUE; }