diff --git a/services/sync/modules/record.js b/services/sync/modules/record.js index d078f12128c..c76e76380b2 100644 --- a/services/sync/modules/record.js +++ b/services/sync/modules/record.js @@ -88,8 +88,11 @@ WBORecord.prototype = { // Take a base URI string, with trailing slash, and return the URI of this // WBO based on collection and ID. uri: function(base) { - if (this.collection && this.id) - return Utils.makeURL(base + this.collection + "/" + this.id); + if (this.collection && this.id) { + let url = Utils.makeURI(base + this.collection + "/" + this.id); + url.QueryInterface(Ci.nsIURL); + return url; + } return null; }, diff --git a/services/sync/modules/util.js b/services/sync/modules/util.js index efe7ee09d90..0c46457b8ab 100644 --- a/services/sync/modules/util.js +++ b/services/sync/modules/util.js @@ -207,28 +207,6 @@ let Utils = { return !!guid && this._base64url_regex.test(guid); }, - ensureOneOpen: let (windows = {}) function ensureOneOpen(window) { - // Close the other window if it exists - let url = window.location.href; - let other = windows[url]; - if (other != null) - other.close(); - - // Save the new window for future closure - windows[url] = window; - - // Actively clean up when the window is closed - window.addEventListener("unload", function() windows[url] = null, false); - }, - - // Returns a nsILocalFile representing a file relative to the current - // user's profile directory. The argument should be a string with - // unix-style slashes for directory names (these slashes are automatically - // converted to platform-specific path separators). - getProfileFile: function getProfileFile(path) { - return FileUtils.getFile("ProfD", path.split("/"), true); - }, - /** * Add a simple getter/setter to an object that defers access of a property * to an inner property. @@ -292,70 +270,46 @@ let Utils = { return true; }, - deepCopy: function Weave_deepCopy(thing, noSort) { - if (typeof(thing) != "object" || thing == null) - return thing; - let ret; - - if (Array.isArray(thing)) { - ret = []; - for (let i = 0; i < thing.length; i++) - ret.push(Utils.deepCopy(thing[i], noSort)); - - } else { - ret = {}; - let props = [p for (p in thing)]; - if (!noSort) - props = props.sort(); - props.forEach(function(k) ret[k] = Utils.deepCopy(thing[k], noSort)); - } - - return ret; - }, - - // Works on frames or exceptions, munges file:// URIs to shorten the paths - // FIXME: filename munging is sort of hackish, might be confusing if - // there are multiple extensions with similar filenames - formatFrame: function Utils_formatFrame(frame) { - let tmp = ""; - - let file = frame.filename || frame.fileName; - if (file) - tmp = file.replace(/^(?:chrome|file):.*?([^\/\.]+\.\w+)$/, "$1"); - - if (frame.lineNumber) - tmp += ":" + frame.lineNumber; - if (frame.name) - tmp = frame.name + "()@" + tmp; - - return tmp; - }, - exceptionStr: function Weave_exceptionStr(e) { let message = e.message ? e.message : e; return message + " " + Utils.stackTrace(e); }, - - stackTraceFromFrame: function Weave_stackTraceFromFrame(frame) { - let output = []; - while (frame) { - let str = Utils.formatFrame(frame); - if (str) - output.push(str); - frame = frame.caller; - } - return output.join(" < "); - }, - + stackTrace: function Weave_stackTrace(e) { // Wrapped nsIException - if (e.location) - return "Stack trace: " + Utils.stackTraceFromFrame(e.location); + if (e.location){ + let frame = e.location; + let output = []; + while (frame) { + // Works on frames or exceptions, munges file:// URIs to shorten the paths + // FIXME: filename munging is sort of hackish, might be confusing if + // there are multiple extensions with similar filenames + let str = ""; + let file = frame.filename || frame.fileName; + if (file){ + str = file.replace(/^(?:chrome|file):.*?([^\/\.]+\.\w+)$/, "$1"); + } + + if (frame.lineNumber){ + str += ":" + frame.lineNumber; + } + if (frame.name){ + str = frame.name + "()@" + str; + } + + if (str){ + output.push(str); + } + frame = frame.caller; + } + return "Stack trace: " + output.join(" < "); + } // Standard JS exception - if (e.stack) + if (e.stack){ return "JS Stack trace: " + e.stack.trim().replace(/\n/g, " < "). replace(/@[^@]*?([^\/\.]+\.\w+:)/g, "@$1"); + } return "No traceback available"; }, @@ -891,12 +845,6 @@ let Utils = { } }, - makeURL: function Weave_makeURL(URIString) { - let url = Utils.makeURI(URIString); - url.QueryInterface(Ci.nsIURL); - return url; - }, - /** * Load a json object from disk * @@ -912,7 +860,7 @@ let Utils = { if (that._log) that._log.trace("Loading json from disk: " + filePath); - let file = Utils.getProfileFile(filePath); + let file = FileUtils.getFile("ProfD", filePath.split("/"), true); if (!file.exists()) { callback.call(that); return; @@ -957,7 +905,7 @@ let Utils = { if (that._log) that._log.trace("Saving json to disk: " + filePath); - let file = Utils.getProfileFile(filePath); + let file = FileUtils.getFile("ProfD", filePath.split("/"), true); let json = typeof obj == "function" ? obj.call(that) : obj; let out = JSON.stringify(json); diff --git a/services/sync/tests/unit/head_helpers.js b/services/sync/tests/unit/head_helpers.js index cee2ec034ed..09e9d8878ff 100644 --- a/services/sync/tests/unit/head_helpers.js +++ b/services/sync/tests/unit/head_helpers.js @@ -456,3 +456,26 @@ RotaryEngine.prototype = { } } }; + +deepCopy: function deepCopy(thing, noSort) { + if (typeof(thing) != "object" || thing == null){ + return thing; + } + let ret; + + if (Array.isArray(thing)) { + ret = []; + for (let i = 0; i < thing.length; i++){ + ret.push(deepCopy(thing[i], noSort)); + } + } else { + ret = {}; + let props = [p for (p in thing)]; + if (!noSort){ + props = props.sort(); + } + props.forEach(function(k) ret[k] = deepCopy(thing[k], noSort)); + } + + return ret; +}; \ No newline at end of file diff --git a/services/sync/tests/unit/test_bookmark_livemarks.js b/services/sync/tests/unit/test_bookmark_livemarks.js index dabcf91af26..db69d50fe35 100644 --- a/services/sync/tests/unit/test_bookmark_livemarks.js +++ b/services/sync/tests/unit/test_bookmark_livemarks.js @@ -56,7 +56,7 @@ store.wipe(); function makeLivemark(p, mintGUID) { let b = new Livemark("bookmarks", p.id); // Copy here, because tests mutate the contents. - b.cleartext = Utils.deepCopy(p); + b.cleartext = deepCopy(p); if (mintGUID) b.id = Utils.makeGUID(); diff --git a/services/sync/tests/unit/test_resource.js b/services/sync/tests/unit/test_resource.js index 2663a761fc6..88aa67124a7 100644 --- a/services/sync/tests/unit/test_resource.js +++ b/services/sync/tests/unit/test_resource.js @@ -495,8 +495,10 @@ function run_test() { let query = "?" + args.join("&"); - let uri1 = Utils.makeURL("http://foo/" + query); - let uri2 = Utils.makeURL("http://foo/"); + let uri1 = Utils.makeURI("http://foo/" + query) + .QueryInterface(Ci.nsIURL); + let uri2 = Utils.makeURI("http://foo/") + .QueryInterface(Ci.nsIURL); uri2.query = query; do_check_eq(uri1.query, uri2.query); server.stop(do_test_finished); diff --git a/services/sync/tests/unit/test_resource_async.js b/services/sync/tests/unit/test_resource_async.js index 423ada72b24..582d3a43fb5 100644 --- a/services/sync/tests/unit/test_resource_async.js +++ b/services/sync/tests/unit/test_resource_async.js @@ -661,8 +661,10 @@ add_test(function test_uri_construction() { let query = "?" + args.join("&"); - let uri1 = Utils.makeURL("http://foo/" + query); - let uri2 = Utils.makeURL("http://foo/"); + let uri1 = Utils.makeURI("http://foo/" + query) + .QueryInterface(Ci.nsIURL); + let uri2 = Utils.makeURI("http://foo/") + .QueryInterface(Ci.nsIURL); uri2.query = query; do_check_eq(uri1.query, uri2.query); diff --git a/services/sync/tests/unit/test_tab_store.js b/services/sync/tests/unit/test_tab_store.js index 34f0375bfa8..26219027146 100644 --- a/services/sync/tests/unit/test_tab_store.js +++ b/services/sync/tests/unit/test_tab_store.js @@ -80,7 +80,7 @@ function fakeSessionSvc(url, numtabs) { if (numtabs) { let tabs = obj.windows[0].tabs; for (let i = 0; i < numtabs-1; i++) - tabs.push(Utils.deepCopy(tabs[0])); + tabs.push(deepCopy(tabs[0])); } return JSON.stringify(obj); } diff --git a/services/sync/tests/unit/test_utils_deepCopy.js b/services/sync/tests/unit/test_utils_deepCopy.js index 70d4791d3f7..54454097e74 100644 --- a/services/sync/tests/unit/test_utils_deepCopy.js +++ b/services/sync/tests/unit/test_utils_deepCopy.js @@ -2,7 +2,7 @@ Cu.import("resource://services-sync/util.js"); function run_test() { let thing = {o: {foo: "foo", bar: ["bar"]}, a: ["foo", {bar: "bar"}]}; - let ret = Utils.deepCopy(thing); + let ret = deepCopy(thing); do_check_neq(ret, thing) do_check_neq(ret.o, thing.o); do_check_neq(ret.o.bar, thing.o.bar); diff --git a/services/sync/tests/unit/test_utils_json.js b/services/sync/tests/unit/test_utils_json.js index 5a1d4914f89..264dacceed7 100644 --- a/services/sync/tests/unit/test_utils_json.js +++ b/services/sync/tests/unit/test_utils_json.js @@ -69,7 +69,8 @@ add_test(function test_load_logging() { _("Verify that reads and read errors are logged."); // Write a file with some invalid JSON - let file = Utils.getProfileFile("weave/log.json"); + let filePath = "weave/log.json"; + let file = FileUtils.getFile("ProfD", filePath.split("/"), true); let fos = Cc["@mozilla.org/network/file-output-stream;1"] .createInstance(Ci.nsIFileOutputStream); let flags = FileUtils.MODE_WRONLY | FileUtils.MODE_CREATE diff --git a/services/sync/tests/unit/test_utils_makeURI.js b/services/sync/tests/unit/test_utils_makeURI.js index a7a94d48eda..a99d29a959b 100644 --- a/services/sync/tests/unit/test_utils_makeURI.js +++ b/services/sync/tests/unit/test_utils_makeURI.js @@ -65,35 +65,3 @@ function _test_makeURI() { do_check_eq(Utils.makeURI("chrome://badstuff"), undefined); do_check_eq(Utils.makeURI("this is a test"), undefined); } - -function _test_makeURL() { - _("Check http uri"); - let uri = "http://mozillalabs.com/"; - do_check_true(Utils.makeURL(uri) instanceof Ci.nsIURL); - - _("Check https uri"); - let uris = "https://mozillalabs.com/"; - do_check_true(Utils.makeURL(uris) instanceof Ci.nsIURL); - - let uric = "chrome://browser/content/browser.xul"; - do_check_true(Utils.makeURL(uric) instanceof Ci.nsIURL); - - _("Check about uri"); - let uria = "about:weave"; - let except1; - try { - Utils.makeURL(uria); - } catch(e) { - except1 = e; - } - do_check_true(!!except1); - - _("Check invalid uri"); - let except2; - try { - Utils.makeURL("mozillalabs.com"); - } catch(e) { - except2 = e; - } - do_check_true(!!except2); -}