Commit aeca5512 authored by Ehsan Akhgari's avatar Ehsan Akhgari
Browse files

Bug 1535877 - Fail explicitly when creating a second instance of the effective TLD service; r=nika

parent 78e96d22
Loading
Loading
Loading
Loading
+8 −2
Original line number Diff line number Diff line
@@ -42,11 +42,14 @@ nsEffectiveTLDService::nsEffectiveTLDService()
    : mIDNService(), mGraph(etld_dafsa::kDafsa) {}

nsresult nsEffectiveTLDService::Init() {
  if (gService) {
    return NS_ERROR_ALREADY_INITIALIZED;
  }

  nsresult rv;
  mIDNService = do_GetService(NS_IDNSERVICE_CONTRACTID, &rv);
  if (NS_FAILED(rv)) return rv;

  MOZ_ASSERT(!gService);
  gService = this;
  RegisterWeakMemoryReporter(this);

@@ -55,8 +58,11 @@ nsresult nsEffectiveTLDService::Init() {

nsEffectiveTLDService::~nsEffectiveTLDService() {
  UnregisterWeakMemoryReporter(this);
  if (mIDNService) {
    // Only clear gService if Init() finished successfully.
    gService = nullptr;
  }
}

// static
nsEffectiveTLDService *nsEffectiveTLDService::GetInstance() {
+1 −0
Original line number Diff line number Diff line
@@ -5,6 +5,7 @@ support-files =
  redirect.sjs

[browser_about_cache.js]
[browser_bug1535877.js]
[browser_NetUtil.js]
[browser_child_resource.js]
skip-if = !crashreporter || (e10s && debug && os == "linux" && bits == 64) || debug # Bug 1370783
+11 −0
Original line number Diff line number Diff line
"use strict";

add_task(_ => {
  try {
    Cc["@mozilla.org/network/effective-tld-service;1"]
      .createInstance(Ci.nsISupports);
  } catch (e) {
    is(e.result, Cr.NS_ERROR_XPC_CI_RETURNED_FAILURE,
       "Component creation as an instance fails with expected code");
  }
});