【问题标题】:AngularJS $LogProvider throws Illegal access errorAngularJS $LogProvider 抛出非法访问错误
【发布时间】:2014-01-17 21:45:22
【问题描述】:

我有一个使用 cordova + AngularJS 1.2.4 的移动应用程序,它在我测试的每个平台上都能完美运行,除了一些 Android 2.3.X 设备会抛出一个神秘的 illegal access 异常。以下是引发错误的代码部分。准确地说,return logFn.apply(console, args); 这行似乎是罪魁祸首。如果我删除参数args 代码工作正常。这似乎很奇怪,因为变量args 是在函数顶部定义的。我不明白是什么真正导致了这个illegal access 错误?有人遇到过类似的问题吗?任何想法如何解决它?

ps:请查看内联 cmets 以更好地理解问题。在那里,我调试并报告了一些案例。

    function consoleLog(type) {
      var console = $window.console || {},
          logFn = console[type] || console.log || noop;
      if (logFn.apply) {
        return function() {
          var args = [];
          forEach(arguments, function(arg) {
            args.push(formatError(arg));
            // console.log(typeof arg); -> prints string
            // console.log(arg.toString); -> prints function
            // console.log(arg); -> throws illegal access error
            // console.log(arg.toString()); -> throws illegal access error
          });
          // console.log(args); -> throws illegal access error
          // return logFn.apply(console); -> works fine w/o `args`
          return logFn.apply(console, args); -> throws illegal access error
        };
      }

      // we are IE which either doesn't have window.console => this is noop and we do nothing,
      // or we are IE where console.log doesn't have apply so we log at least first 2 args
      return function(arg1, arg2) {
        logFn(arg1, arg2 == null ? '' : arg2);
      };
    }

【问题讨论】:

  • 您知道,这条日志消息中究竟包含什么内容吗?是否有成功记录的消息?
  • 很遗憾没有。引导应用程序后立即在控制台中显示错误。我不知道调用者和传递的参数。
  • 这似乎也是 Firefox OS 的问题。我正在尝试解决同样的问题。
  • @Aleyna 你能找到解决办法吗?
  • 我也想知道...

标签: javascript android angularjs android-webview firefox-os


【解决方案1】:

您发布的代码不是问题所在。这是 Angular 内置的异常处理。我犯了同样的错误并试图在这里挖掘,但 Angular 的异常处理工作正常。

但是在 1.2.4 中有一个关于 Android 2.3.x 和 Firefox OS 的reported Issue (Github),他们在 1.2.5 中修复了它

也许你应该尝试更高的 AngularJS 版本

【讨论】:

    猜你喜欢
    • 2016-04-25
    • 1970-01-01
    • 1970-01-01
    • 2013-04-07
    • 1970-01-01
    • 2013-08-12
    • 2012-01-22
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多