diff --git a/netwerk/base/src/ProxyAutoConfig.cpp b/netwerk/base/src/ProxyAutoConfig.cpp index 5fbb4e15a4c9..3e6bec303b5d 100644 --- a/netwerk/base/src/ProxyAutoConfig.cpp +++ b/netwerk/base/src/ProxyAutoConfig.cpp @@ -586,6 +586,7 @@ ProxyAutoConfig::SetupJS() JSAutoRequest ar(mJSRuntime->Context()); + sRunning = this; JSScript *script = JS_CompileScript(mJSRuntime->Context(), mJSRuntime->Global(), mPACScript.get(), mPACScript.Length(), @@ -595,8 +596,10 @@ ProxyAutoConfig::SetupJS() nsString alertMessage(NS_LITERAL_STRING("PAC file failed to install from ")); alertMessage += NS_ConvertUTF8toUTF16(mPACURI); PACLogToConsole(alertMessage); + sRunning = nullptr; return NS_ERROR_FAILURE; } + sRunning = nullptr; mJSRuntime->SetOK(); nsString alertMessage(NS_LITERAL_STRING("PAC file installed from ")); diff --git a/netwerk/test/unit/test_protocolproxyservice.js b/netwerk/test/unit/test_protocolproxyservice.js index cbd0887f9417..b03778464f59 100644 --- a/netwerk/test/unit/test_protocolproxyservice.js +++ b/netwerk/test/unit/test_protocolproxyservice.js @@ -597,7 +597,41 @@ function myipaddress_callback(pi) do_check_neq(pi.host, null); do_check_neq(pi.host, "127.0.0.1"); do_check_neq(pi.host, "::1"); + + run_myipaddress_test_2(); +} +function run_myipaddress_test_2() +{ + // test that myIPAddress() can be used outside of the scope of + // FindProxyForURL(). bug 829646. + + var pac = 'data:text/plain,' + + 'var myaddr = myIpAddress(); ' + + 'function FindProxyForURL(url, host) {' + + ' return "PROXY " + myaddr + ":5678";' + + '}'; + + var uri = ios.newURI("http://www.mozilla.org/", null, null); + prefs.setIntPref("network.proxy.type", 2); + prefs.setCharPref("network.proxy.autoconfig_url", pac); + + var cb = new resolveCallback(); + cb.nextFunction = myipaddress2_callback; + var req = pps.asyncResolve(uri, 0, cb); +} + +function myipaddress2_callback(pi) +{ + do_check_neq(pi, null); + do_check_eq(pi.type, "http"); + do_check_eq(pi.port, 5678); + + // make sure we didn't return localhost + do_check_neq(pi.host, null); + do_check_neq(pi.host, "127.0.0.1"); + do_check_neq(pi.host, "::1"); + run_failed_script_test(); }