为什么 GWT 应用程序在黑莓 OS7 上崩溃?

发布于 2024-12-15 01:33:03 字数 653 浏览 2 评论 0原文

我在黑莓 OS7 浏览器上尝试了以下代码:

<html>
<body>
test page
<script>
i = 0;
if(i < -2147483647) {
   alert("very low")
} 

if(i < -2147483648) {
   alert("very very low")
} 

if(i < -2147483649) {
    alert("very very very low")
}
</script></body></html>

令人惊讶的是它的结果非常非常低!

我认为 javascript 中的整数应该支持更多。当然,这段代码在其他浏览器上运行良好......

棘手的是,我发现尝试在黑莓上运行 gwt 应用程序。它在 OS6 上运行良好,但在 OS7 上不行。我调试了 GWT 编译的代码,碰巧 Integer.parseInt 的 javascript 实现有一个使用 int 的极高和极低的测试。由于 OS7 浏览器似乎无法正确支持这些极端值(位溢出?),我收到异常,我的应用程序无法启动...

我正在尝试为此找到解决方案。我正在考虑仅为黑莓重写 GWT integer.parseInt 实现。你怎么认为?还有其他想法吗?

I tried the following code on a blackberry os7 browser:

<html>
<body>
test page
<script>
i = 0;
if(i < -2147483647) {
   alert("very low")
} 

if(i < -2147483648) {
   alert("very very low")
} 

if(i < -2147483649) {
    alert("very very very low")
}
</script></body></html>

And surprisingly it came out with very very low!!

I thought that integers in javascript were supposed to support more than that. Of course this code works well on other browsers...

The tricky thing is, I discovered that trying to run a gwt app on a blackberry. It worked fine on OS6 but not on OS7. I debugged my code compiled by GWT and it happens that the javascript implementation of Integer.parseInt has a test using the extreme high and extreme low of an int. As OS7 browser doesn't seem to support those extreme values properly (bit overflow?) I get an exception and my app doesn't start...

I'm trying to find a solution for that. I'm thinking about rewriting the GWT integer.parseInt implementation just for blackberry. what do you think? Any other ideas?

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

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

上课铃就是安魂曲 2024-12-22 01:33:03

如果有人在寻找答案时偶然发现这个旧线程:

在我看来,该错误出在 JS 引擎的编译器部分。

代码段 1:

var i = 0;
if (i < -2147483648) {
  console.log("less");
} else {
  console.log("greater");
}

代码段 2:

var i = 0;
var j = i < -2147483648;
if (j) {
  console.log("less");
} else {
  console.log("greater");
}

代码段 1 通过记录“less”来显示错误,而代码段 2 则不会。

因此,为了解决该错误,我们检查了 GWT 源代码并使用此补丁编译了我们自己的 SDK。从那以后我们就没有遇到过 Integer.parseInt 的问题了。

diff --git a/gwt240/source/user/super/com/google/gwt/emul/java/lang/Number.java         b/gwt240/source/user/super/com/google/gwt/emul/java/lang/Number.java
index 04a85e1..abb3e5c 100644
--- a/gwt240/source/user/super/com/google/gwt/emul/java/lang/Number.java
+++ b/gwt240/source/user/super/com/google/gwt/emul/java/lang/Number.java
@@ -221,9 +221,10 @@ public abstract class Number implements Serializable {
     }

     int toReturn = __parseInt(s, radix);
+    boolean isTooLow = toReturn < lowerBound;
     if (__isNaN(toReturn)) {
       throw NumberFormatException.forInputString(s);
-    } else if (toReturn < lowerBound || toReturn > upperBound) {
+    } else if (isTooLow || toReturn > upperBound) {
       throw NumberFormatException.forInputString(s);
     }

GWT 错误报告链接:http://code.google .com/p/google-web-toolkit/issues/detail?id=7291

In case anyone stumbles upon this old thread in search for answers:

It seems to me the bug is in the compiler part of the JS-engine.

Snippet 1:

var i = 0;
if (i < -2147483648) {
  console.log("less");
} else {
  console.log("greater");
}

Snippet 2:

var i = 0;
var j = i < -2147483648;
if (j) {
  console.log("less");
} else {
  console.log("greater");
}

While snippet 1 displays the bug by logging "less", snippet 2 does not.

So to get around the bug, we checked out the GWT sources and compiled our own SDK with this patch applied. We haven't had problems with Integer.parseInt since.

diff --git a/gwt240/source/user/super/com/google/gwt/emul/java/lang/Number.java         b/gwt240/source/user/super/com/google/gwt/emul/java/lang/Number.java
index 04a85e1..abb3e5c 100644
--- a/gwt240/source/user/super/com/google/gwt/emul/java/lang/Number.java
+++ b/gwt240/source/user/super/com/google/gwt/emul/java/lang/Number.java
@@ -221,9 +221,10 @@ public abstract class Number implements Serializable {
     }

     int toReturn = __parseInt(s, radix);
+    boolean isTooLow = toReturn < lowerBound;
     if (__isNaN(toReturn)) {
       throw NumberFormatException.forInputString(s);
-    } else if (toReturn < lowerBound || toReturn > upperBound) {
+    } else if (isTooLow || toReturn > upperBound) {
       throw NumberFormatException.forInputString(s);
     }

Link to GWT bug report: http://code.google.com/p/google-web-toolkit/issues/detail?id=7291

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