Bug 1151899 - Add code to run both URL parsers at the same time
MozReview-Commit-ID: Jd2RgPmdPrn
--- a/netwerk/base/nsStandardURL.cpp
+++ b/netwerk/base/nsStandardURL.cpp
@@ -22,16 +22,47 @@
#include "mozilla/MemoryReporting.h"
#include "mozilla/ipc/URIUtils.h"
#include <algorithm>
#include "mozilla/dom/EncodingUtils.h"
#include "nsContentUtils.h"
#include "prprf.h"
#include "nsReadableUtils.h"
+#ifdef MOZ_RUST_URLPARSE
+
+#include "RustURL.h"
+
+#define CALL_RUST_SETTER(func, ...) \
+do { \
+ mRustURL->func(__VA_ARGS__); \
+ nsAutoCString rustSpec; \
+ mRustURL->GetSpec(rustSpec); \
+ if (mSpec != rustSpec) { \
+ printf("Spec diff detected after setter (%s): rust: %s standard-url: %s\n", #func, rustSpec.get(), mSpec.get()); \
+ } \
+} while (0)
+
+#define CALL_RUST_GETTER_STR(result, func, ...) \
+do { \
+ nsAutoCString backup(result); \
+ mRustURL->func(__VA_ARGS__); \
+ if (backup != result) { \
+ printf("Diff detected calling getter (%s): rust: %s standard-url: %s\n", #func, result.BeginReading() , backup.BeginReading()); \
+ result = backup; \
+ } \
+} while (0)
+
+#else
+
+#define CALL_RUST_SETTER(func, ...)
+#define CALL_RUST_GETTER_STR(expected, func, ...)
+
+#endif // MOZ_RUST_URLPARSE
+
using mozilla::dom::EncodingUtils;
using namespace mozilla::ipc;
namespace mozilla {
namespace net {
static NS_DEFINE_CID(kThisImplCID, NS_THIS_STANDARDURL_IMPL_CID);
static NS_DEFINE_CID(kStandardURLCID, NS_STANDARDURL_CID);
@@ -272,16 +303,20 @@ nsStandardURL::nsStandardURL(bool aSuppo
if (NS_IsMainThread()) {
if (aTrackURL) {
PR_APPEND_LINK(&mDebugCList, &gAllURLs);
} else {
PR_INIT_CLIST(&mDebugCList);
}
}
#endif
+
+#ifdef MOZ_RUST_URLPARSE
+ mRustURL = new RustURL();
+#endif
}
nsStandardURL::~nsStandardURL()
{
LOG(("Destroying nsStandardURL @%p\n", this));
if (mHostA) {
free(mHostA);
@@ -1199,16 +1234,17 @@ NS_INTERFACE_MAP_END
// result may contain unescaped UTF-8 characters
NS_IMETHODIMP
nsStandardURL::GetSpec(nsACString &result)
{
MOZ_ASSERT(mSpec.Length() <= (uint32_t) net_GetURLMaxLength(),
"The spec should never be this long, we missed a check.");
result = mSpec;
+ CALL_RUST_GETTER_STR(result, GetSpec, result);
return NS_OK;
}
// result may contain unescaped UTF-8 characters
NS_IMETHODIMP
nsStandardURL::GetSensitiveInfoHiddenSpec(nsACString &result)
{
result = mSpec;
@@ -1495,16 +1531,18 @@ nsStandardURL::SetSpec(const nsACString
LOG((" path = (%u,%d)\n", mPath.mPos, mPath.mLen));
LOG((" filepath = (%u,%d)\n", mFilepath.mPos, mFilepath.mLen));
LOG((" directory = (%u,%d)\n", mDirectory.mPos, mDirectory.mLen));
LOG((" basename = (%u,%d)\n", mBasename.mPos, mBasename.mLen));
LOG((" extension = (%u,%d)\n", mExtension.mPos, mExtension.mLen));
LOG((" query = (%u,%d)\n", mQuery.mPos, mQuery.mLen));
LOG((" ref = (%u,%d)\n", mRef.mPos, mRef.mLen));
}
+
+ CALL_RUST_SETTER(SetSpec, input);
return rv;
}
NS_IMETHODIMP
nsStandardURL::SetScheme(const nsACString &input)
{
ENSURE_MUTABLE();
--- a/netwerk/base/nsStandardURL.h
+++ b/netwerk/base/nsStandardURL.h
@@ -16,16 +16,17 @@
#include "nsURLHelper.h"
#include "nsIClassInfo.h"
#include "nsISizeOf.h"
#include "prclist.h"
#include "mozilla/Attributes.h"
#include "mozilla/MemoryReporting.h"
#include "nsIIPCSerializableURI.h"
#include "nsISensitiveInfoHiddenURI.h"
+#include "RustURL.h"
#ifdef NS_BUILD_REFCNT_LOGGING
#define DEBUG_DUMP_URLS_AT_SHUTDOWN
#endif
class nsIBinaryInputStream;
class nsIBinaryOutputStream;
class nsIIDNService;
@@ -304,16 +305,20 @@ private:
static bool gAlwaysEncodeInUTF8;
static bool gEncodeQueryInUTF8;
public:
#ifdef DEBUG_DUMP_URLS_AT_SHUTDOWN
PRCList mDebugCList;
void PrintSpec() const { printf(" %s\n", mSpec.get()); }
#endif
+
+#ifdef MOZ_RUST_URLPARSE
+ RefPtr<RustURL> mRustURL;
+#endif
};
#define NS_THIS_STANDARDURL_IMPL_CID \
{ /* b8e3e97b-1ccd-4b45-af5a-79596770f5d7 */ \
0xb8e3e97b, \
0x1ccd, \
0x4b45, \
{0xaf, 0x5a, 0x79, 0x59, 0x67, 0x70, 0xf5, 0xd7} \