我正在尝试从加载项中调用checkCurrentDictionary()
的方法nsIEditorSpellCheck
。我使用的相关代码是:
var editorSpellCheck = Cc["@mozilla.org/editor/editorspellchecker;1"].createInstance(Ci.nsIEditorSpellCheck);
editorSpellCheck.checkCurrentDictionary();
这会立即导致Fx崩溃。这里出了什么问题?
答案 0 :(得分:1)
所以这可能与nsIEditorSpellCheck
is not a scriptable interface。
基本上是scriptable interface is one that can be used from JavaScript。
如果您想访问拼写检查服务,您可以执行以下操作:
let editor = editableElement.editor;
if (!editor) {
let win = editableElement.ownerDocument.defaultView;
editor = win.QueryInterface(Ci.nsIInterfaceRequestor).
getInterface(Ci.nsIWebNavigation).
QueryInterface(Ci.nsIInterfaceRequestor).
getInterface(Ci.nsIEditingSession).
getEditorForWindow(win);
}
if (!editor)
throw new Error("Unable to find editor for element " + editableElement);
(以上来自http://dxr.mozilla.org/mozilla-central/source/editor/AsyncSpellCheckTestHelper.jsm,即MPL)。
然后你可以使用InlineSpellCheck.jsm做一些疯狂的事情。
我不确定你想做什么,所以也许你应该把更具体的问题作为一个新问题。