Components.returnCode 编辑

 

Components.returnCode is a property which can hold an XPCOM return code additionally to the value returned by the return statement.

Note that Components.returnCode is currently non-functional due to bug 287107. This problem was introduced in Mozilla 1.4.

Usage

Components.returnCode is a property that can be used to indicate to an XPCOM caller of the JavaScript method that the method is returning a specific nsresult code.

Generally, XPConnect does a fine job of making it unnecessary for JavaScript code to worry about nsresult codes. By default the successful completion of the JavaScript method will cause XPConnect to return a result code of NS_OK to the caller. If the JavaScript code needs to signal failure then that is done by throwing an exception. However, there are a very few XPCOM interfaces that specify success code return values. Components.returnCode exists in order to make it possible to implement these rare interfaces in JavaScript.

Example

var foo = {
  bar: function(i) {
    if (yada_yada)
      Components.returnCode = 5;

    return i * 2;
  }
};

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据

词条统计

浏览:92 次

字数:1735

最后编辑:7年前

编辑次数:0 次

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文