From 72a4d80ad1ea71a4c7fb2b9907611a657211b476 Mon Sep 17 00:00:00 2001 From: Kris Maglione Date: Mon, 18 May 2015 14:22:34 -0700 Subject: [PATCH] Fix NS_ERROR_NOT_INITIALIZED on some :write filename completions. --- common/modules/base.jsm | 18 +++++++++++++++--- common/modules/buffer.jsm | 7 ++++++- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/common/modules/base.jsm b/common/modules/base.jsm index 6e67abd2..bf858128 100644 --- a/common/modules/base.jsm +++ b/common/modules/base.jsm @@ -46,6 +46,18 @@ jsmodules.jsmodules = jsmodules; function toString() "[module-global " + this.NAME + "]"; +function objToString(obj) { + try { + return objproto.toString.call(obj); + } + catch (e) { + var type_ = typeof obj; + if (e == null) + type_ = String(e); + return "[non-object " + type_ + "]"; + } +} + let use = {}; let loaded = {}; let currentModule; @@ -635,7 +647,7 @@ function isinstance(object, interfaces) { return Array.concat(interfaces).some(function isinstance_some(iface) { if (typeof iface === "string") { - if (objproto.toString.call(object) === "[object " + iface + "]") + if (objToString(object) === "[object " + iface + "]") return true; } else if (typeof object === "object" && "isinstance" in object && object.isinstance !== isinstance) { @@ -674,7 +686,7 @@ var isArray = * functions containing the 'yield' statement and generator * statements such as (x for (x in obj)). */ -function isGenerator(val) objproto.toString.call(val) == "[object Generator]"; +function isGenerator(val) objToString(val) == "[object Generator]"; /** * Returns true if and only if its sole argument is a String, @@ -683,7 +695,7 @@ function isGenerator(val) objproto.toString.call(val) == "[object Generator]"; * namespace, or execution context, which is not the case when * using (obj instanceof String) or (typeof obj == "string"). */ -function isString(val) objproto.toString.call(val) == "[object String]"; +function isString(val) objToString(val) == "[object String]"; /** * Returns true if and only if its sole argument may be called diff --git a/common/modules/buffer.jsm b/common/modules/buffer.jsm index 7a2cbded..532bf848 100644 --- a/common/modules/buffer.jsm +++ b/common/modules/buffer.jsm @@ -1517,7 +1517,12 @@ var Buffer = Module("Buffer", { if (type === "text/plain") ext = "." + (currExt || "txt"); else - ext = "." + services.mime.getPrimaryExtension(type, currExt); + try { + ext = "." + services.mime.getPrimaryExtension(type, currExt); + } + catch (e) { + ext = currExt ? "." + curExt : ""; + } } else if (currExt) ext = "." + currExt;