2019-12-26 14:45:42 -05:00
|
|
|
// Copyright Epic Games, Inc. All Rights Reserved.
|
2016-09-23 17:31:51 -04:00
|
|
|
|
2018-09-05 04:55:55 -04:00
|
|
|
#include "MobileJSStructSerializerBackend.h"
|
2018-06-26 08:42:47 -04:00
|
|
|
|
2018-09-05 04:55:55 -04:00
|
|
|
#if PLATFORM_ANDROID || PLATFORM_IOS
|
2018-06-26 08:42:47 -04:00
|
|
|
|
2018-09-05 04:55:55 -04:00
|
|
|
#include "MobileJSScripting.h"
|
Copying //UE4/Dev-Build to //UE4/Dev-Main (Source: //UE4/Dev-Build @ 3209340)
#lockdown Nick.Penwarden
#rb none
==========================
MAJOR FEATURES + CHANGES
==========================
Change 3209340 on 2016/11/23 by Ben.Marsh
Convert UE4 codebase to an "include what you use" model - where every header just includes the dependencies it needs, rather than every source file including large monolithic headers like Engine.h and UnrealEd.h.
Measured full rebuild times around 2x faster using XGE on Windows, and improvements of 25% or more for incremental builds and full rebuilds on most other platforms.
* Every header now includes everything it needs to compile.
* There's a CoreMinimal.h header that gets you a set of ubiquitous types from Core (eg. FString, FName, TArray, FVector, etc...). Most headers now include this first.
* There's a CoreTypes.h header that sets up primitive UE4 types and build macros (int32, PLATFORM_WIN64, etc...). All headers in Core include this first, as does CoreMinimal.h.
* Every .cpp file includes its matching .h file first.
* This helps validate that each header is including everything it needs to compile.
* No engine code includes a monolithic header such as Engine.h or UnrealEd.h any more.
* You will get a warning if you try to include one of these from the engine. They still exist for compatibility with game projects and do not produce warnings when included there.
* There have only been minor changes to our internal games down to accommodate these changes. The intent is for this to be as seamless as possible.
* No engine code explicitly includes a precompiled header any more.
* We still use PCHs, but they're force-included on the compiler command line by UnrealBuildTool instead. This lets us tune what they contain without breaking any existing include dependencies.
* PCHs are generated by a tool to get a statistical amount of coverage for the source files using it, and I've seeded the new shared PCHs to contain any header included by > 15% of source files.
Tool used to generate this transform is at Engine\Source\Programs\IncludeTool.
[CL 3209342 by Ben Marsh in Main branch]
2016-11-23 15:48:37 -05:00
|
|
|
#include "UObject/UnrealType.h"
|
|
|
|
|
#include "UObject/PropertyPortFlags.h"
|
|
|
|
|
#include "Templates/Casts.h"
|
2016-09-23 17:31:51 -04:00
|
|
|
|
2018-09-05 04:55:55 -04:00
|
|
|
void FMobileJSStructSerializerBackend::WriteProperty(const FStructSerializerState& State, int32 ArrayIndex)
|
2016-09-23 17:31:51 -04:00
|
|
|
{
|
|
|
|
|
// The parent class serialzes UObjects as NULLs
|
2021-02-03 12:08:22 -04:00
|
|
|
if (FObjectProperty* ObjectProperty = CastField<FObjectProperty>(State.ValueProperty))
|
2016-09-23 17:31:51 -04:00
|
|
|
{
|
2021-02-03 12:08:22 -04:00
|
|
|
WriteUObject(State, ObjectProperty->GetPropertyValue_InContainer(State.ValueData, ArrayIndex));
|
2016-09-23 17:31:51 -04:00
|
|
|
}
|
|
|
|
|
// basic property type (json serializable)
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
FJsonStructSerializerBackend::WriteProperty(State, ArrayIndex);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-09-05 04:55:55 -04:00
|
|
|
void FMobileJSStructSerializerBackend::WriteUObject(const FStructSerializerState& State, UObject* Value)
|
2016-09-23 17:31:51 -04:00
|
|
|
{
|
|
|
|
|
// Note this function uses WriteRawJSONValue to append non-json data to the output stream.
|
|
|
|
|
FString RawValue = Scripting->ConvertObject(Value);
|
2019-12-13 11:07:03 -05:00
|
|
|
if ((State.ValueProperty == nullptr) || (State.ValueProperty->ArrayDim > 1) || (State.ValueProperty->GetOwner<FArrayProperty>() != nullptr))
|
2016-09-23 17:31:51 -04:00
|
|
|
{
|
|
|
|
|
GetWriter()->WriteRawJSONValue(RawValue);
|
|
|
|
|
}
|
|
|
|
|
else if (State.KeyProperty != nullptr)
|
|
|
|
|
{
|
|
|
|
|
FString KeyString;
|
2022-02-25 10:39:39 -05:00
|
|
|
State.KeyProperty->ExportTextItem_Direct(KeyString, State.KeyData, nullptr, nullptr, PPF_None);
|
2016-09-23 17:31:51 -04:00
|
|
|
GetWriter()->WriteRawJSONValue(KeyString, RawValue);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
Copying //UE4/Portal-Staging to //UE4/Dev-Main (Source: //Portal/Main @ 3216504)
#lockdown Nick.Penwarden
#rb no one
==========================
MAJOR FEATURES + CHANGES
==========================
Change 3216141 on 2016/11/30 by Justin.Sargent
Completed first ready to use pass of the new AutomationDriver module and new Spec test type.
Change 3213288 on 2016/11/29 by Leigh.Swift
#jira OPP-6353: CEF FName Javascript PROBLEM
Removing deprecation of IWebBrowserSingleton::SetJSBindingToLoweringEnabled for now.
Change 3212796 on 2016/11/29 by Leigh.Swift
#jira OPP-6353: CEF FName Javascript PROBLEM
Added SetJSBindingToLoweringEnabled to IWebBrowserSingleton so that the to-lowering of binding names can be disabled.
Deprecated SetJSBindingToLoweringEnabled since 4.15. In future the to-lowering will always occurr.
Adding GetBindingName helper to FWebJSScripting, which returns a to-lowered name for a UField, unless disabled.
Updated all current binding code to use GetBindingName when building from UObjects/UStructs. This affects Windows, Mac, Linux, and Android.
Portal currently disables to-lowering unless a commandline -LowercaseJS is provided.
Change 3200370 on 2016/11/16 by Richard.Fawcett
Ensure we always get the latest version of the user content catalog when promoting marketplace items.
Change 3192974 on 2016/11/10 by Leigh.Swift
#jira OPP-6365: Crash during shutdown if a manifest is still being downloaded
This is because of the OnPreExit core delegate being used to null out the Data uobject member on a manifest, also being the only sensible way to ensure threads complete in a safe and clean manner.
Refactoring BuildPatchServices manifest class to not permanently hold any UObject and simply just use one while serialising.
This removes the reliance on the OnPreExit delegate from manifest class, making it generally safer behaviour for shutdown.
Change 3187028 on 2016/11/04 by Leigh.Swift
PortalPublishingTool: Adding UE_Main app to UnrealEngine project
Change 3186788 on 2016/11/04 by Richard.Fawcett
Change C# wrapper for BuildPatchTool patch generation to prevent clobbering manifest files by default, unless we specifically pass in an optional flag to allow this.
#jira OPP-6355
Change 3186779 on 2016/11/04 by Richard.Fawcett
Add support to automation tool testing framework for the following assertions:
Assert.AreNotEqual(a, b, optionalFailureMessage)
Assert.ThrowsError(actionToCarryOut, expectedExceptionType, optionalExceptionMessageContainsString)
Moved attribute-based expected exception declarations to their own attribute, TestThrowsExceptionAttribute, which can now accept an optional parameter for a string which should be contained within the exception message.
Fixed a bug where a test method with an attribute-based expected exception would not count towards the success total if the exception was encountered as expected.
Fixed a bug where NOT throwing an exception when we were expecting one would count as a success.
Added an internal property bDoNotLogTestFailsAsError which we can set to true to suppress logging of UAT errors when a test fails (but still count them in our failure results), to allow us to deliberately cause test failures to test the test framework!
Added a suite of unit tests for the test framework itself, in TestRunner.Automation.Tests.cs.
Change 3185411 on 2016/11/03 by Richard.Fawcett
Allow Rocket_PromoteBuild changelist to be overridden by a changelist read from a file.
Change 3184843 on 2016/11/03 by Richard.Fawcett
Ensure catalog file synced during user content generation is always the latest one.
Change 3184752 on 2016/11/03 by Richard.Fawcett
Ensure we log reading changelist from specified file.
Change 3184744 on 2016/11/03 by Richard.Fawcett
Ensure directory is created for Changelist file if it doesn't already exist.
Change 3184738 on 2016/11/03 by Richard.Fawcett
Ensure we use latest CL from all of Perforce when generating build versions for user content
Because of the nature of the build farm, where separate parts of the job are executed on different build agents at different times, this changelist is serialized to the filesystem during execution of a node dedicated to this task, and then made available to all future nodes, so that they're working with a consistent build version. In the case of an execution where we're updating Perforce with new content, this calculation of the changelist occurs AFTER we've updated Perforce with the new content.
Have also optimized the build graph scripts to enable Mac and Windows user generated content to execute simultaneously.
#jira OPP-6274
Change 3181456 on 2016/11/01 by Andrew.Brown
SExpandable area has been modified as the Portal settings mocks weren't able to be achieved with default functionality.
Added BodyBorderImage arguement and BodyBorderBackgroundColor attribute so we can specify a different brush/color to use for the expanded area compared with the title area. Additional care was made to ensure that rounded corners still appear correctly if the developer doesn't want to specify a different look to the body.
Added AreaTitlePadding attribute, to be able to specify padding between the expand/collapse icon and the header content.
Added MinWidth arguement, to ensure that the areas meet a minimum width requirement.
Change 3181285 on 2016/11/01 by Richard.Fawcett
Ensure user content generated using latest changelist submitted to Perforce, rather than using portal's latest changelist
#jira OPP-6274
Change 3177758 on 2016/10/28 by Leigh.Swift
#jira OPP-6247: Portal needs Social Plugin integration v1.2
Copying //Portal/Dev-Social to Dev-Main (//Portal/Dev-Main)
Change 3175889 on 2016/10/26 by Wes.Fudala
Web browser tooltips will no longer continue to appear when the mouse leaves the browser window.
#jira: OPP-5895 The Mouseover info in Recent Additions (Marketplace) anchors itself to the mouse pointer over other Browser windows
rb: Justin.Sargent
Change 3171388 on 2016/10/22 by Leigh.Swift
#jira OPP-6343: Launcher crashes patching from 2.12.13 Main to 2.12.13 Release-Live
BPS: FBuildPatchAppManifest needs to listen for FCoreDelegates::OnPreExit in order to clean up references to it's UObject which is about to be destroyed.
Change 3170373 on 2016/10/21 by Leigh.Swift
#jira: OPP-6340: Portal builds fail on audit nodes.
Reducing platform regex to only match pre-defined possibilities.
[CL 3219291 by Justin Sargent in Main branch]
2016-12-02 13:27:02 -05:00
|
|
|
GetWriter()->WriteRawJSONValue(Scripting->GetBindingName(State.ValueProperty), RawValue);
|
2016-09-23 17:31:51 -04:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-09-05 04:55:55 -04:00
|
|
|
FString FMobileJSStructSerializerBackend::ToString()
|
2016-09-23 17:31:51 -04:00
|
|
|
{
|
|
|
|
|
ReturnBuffer.Add(0);
|
Allow FString instances containing code units outside of the basic multilingual plane to be losslessly processed regardless of whether TCHAR is 2 or 4 bytes.
Most UE4 platforms use a 2-byte TCHAR, however some still use a 4-byte TCHAR. The platforms that use a 4-byte TCHAR expect their string data to be UTF-32, however there are parts of UE4 that serialize FString data as a series of UCS2CHAR, simply narrowing or widening each TCHAR in turn. This can result in invalid or corrupted UTF-32 strings (either UTF-32 strings containing UTF-16 surrogates, or UTF-32 code points that have been truncated to 2-bytes), which leads to either odd behavior or crashes.
This change updates the parts of UE4 that process FString data as a series of 2-byte values to do so on the correct UTF-16 interpretation of the data, converting to/from UTF-32 as required on platforms that use a 4-byte TCHAR. This conversion is a no-op on platforms that use a 2-byte TCHAR as the string is already assumed to be valid UTF-16 data. It should also be noted that while FString may contain UTF-16 code units on platforms using a 2-byte TCHAR, this change doesn't do anything to make FString represent a Unicode string on those platforms (ie, a string that understands and works on code points), but is rather just a bag of code units.
Two new variable-width string converters have be added to facilitate the conversion (modelled after the TCHAR<->UTF-8 converters), TUTF16ToUTF32_Convert and TUTF32ToUTF16_Convert. These are used for both TCHAR<->UTF16CHAR conversion when needed, but also for TCHAR<->wchar_t conversion on platforms that use char16_t for TCHAR along with having a 4-byte wchar_t (as defined by the new PLATFORM_WCHAR_IS_4_BYTES option).
These conversion routines are accessed either via the conversion macros (TCHAR_TO_UTF16, UTF16_TO_TCHAR, TCHAR_TO_WCHAR, and WCHAR_TO_TCHAR), or by using a conversion struct (FTCHARToUTF16, FUTF16ToTCHAR, FTCHARToWChar, and FWCharToTCHAR), which is the same pattern as the existing TCHAR<->UTF-8 conversion. Both the macros and the structs are defined as no-ops when the conversion isn't needed, but always exist so that code can be written in a portable way.
Very little code actually needed updating to use UTF-16, as the vast majority makes no assumptions about the size of TCHAR, nor how FString should be serialized. The main places were the FString archive serialization and the JSON reader/writer, along with some minor fixes to the UTF-8 conversion logic for platforms using a 4-byte TCHAR.
Tests have been added to verify that an FString representing a UTF-32 code point can be losslessly converted to/from UTF-8 and UTF-16, and serialized to/from an archive.
#jira
#rb Steve.Robb, Josh.Adams
#ROBOMERGE-SOURCE: CL 8676728 via CL 8687863
#ROBOMERGE-BOT: (v421-8677696)
[CL 8688048 by jamie dale in Main branch]
2019-09-16 05:44:11 -04:00
|
|
|
ReturnBuffer.Add(0); // Add two as we're dealing with UTF-16, so 2 bytes
|
|
|
|
|
return UTF16_TO_TCHAR((UTF16CHAR*)ReturnBuffer.GetData());
|
2016-09-23 17:31:51 -04:00
|
|
|
}
|
|
|
|
|
|
2018-09-05 04:55:55 -04:00
|
|
|
FMobileJSStructSerializerBackend::FMobileJSStructSerializerBackend(TSharedRef<class FMobileJSScripting> InScripting)
|
2019-01-10 17:26:53 -05:00
|
|
|
: FJsonStructSerializerBackend(Writer, EStructSerializerBackendFlags::Legacy)
|
2018-09-06 14:36:13 -04:00
|
|
|
, Scripting(InScripting)
|
2016-09-23 17:31:51 -04:00
|
|
|
, ReturnBuffer()
|
|
|
|
|
, Writer(ReturnBuffer)
|
|
|
|
|
{
|
|
|
|
|
}
|
2018-06-26 08:42:47 -04:00
|
|
|
|
2018-09-05 04:55:55 -04:00
|
|
|
#endif // PLATFORM_ANDROID || PLATFORM_IOS
|