Firefox扩展web worker中的语言环境字符串比较无法正常工作 [英] Locale string comparison does not work properly in Firefox extension web worker

查看:159
本文介绍了Firefox扩展web worker中的语言环境字符串比较无法正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

localeCompare()函数在Firefox扩展主代码和web worker(或者chrome worker)中的表现不一样。



例如,在主代码中,我有这样的代码:

  var array = [ École,Frère,frère,école]; 
array.sort(function(a,b){
return a.localeCompare(b);
});

console.log('Main:'+ array);

显示:

  Main: cole, cole,Fr re,fr re

这是正确的排序(编码是不是我的问题)。

在工人,我有这个代码:

  var array = [École,Frère,frère,école]; 
array.sort(function(a,b){
return a.localeCompare(b);
});

self.postMessage(array);

打印:

 Frère,frère,école, 0cole

这是错误的顺序再次,编码是不是我的问题)。

在主代码中的排序是好的,但不是在web工作人员。



我试图改变web worker中 localeCompare()函数的选项,但是它不会改变任何东西。



为什么网络工作人员的排序不同,以及如何在网络工作人员中正确使用?



,我无法将数据发送到主代码,进行排序并将其发回给网络工作人员,但我仍然得到了错误的命令(给了我$ école, 0cole,Frère,frère

感谢您的帮助。

解决方案

< Firefox Web Workers中仍然存在 localeCompare
弗拉基米尔提到了错误616841 ,这确实已经解决了它的问题。除了网络工作者,因为Intl后端(线程)不是线程安全的或其他线程安全问题而被打破的。相应的死胡同补丁从来没有审查,也没有检入。

我现在提交错误903780 ,基于你的代码的一个测试用例,所以 localeCompare 希望将来会被修复。


The localeCompare() function does not behave the same in a Firefox extension main code and in a web worker (or chrome worker).

For instance, in the main code, I have this code:

var array = ["École", "Frère", "frère", "école"];
array.sort(function(a, b) {
    return a.localeCompare(b);
});

console.log('Main: ' + array);

it shows:

Main: �cole,�cole,Fr�re,fr�re

Which is the right sorting (the encoding is not my problem).

In the worker, I have this code:

var array = ["École", "Frère", "frère", "école"];
array.sort(function(a, b) {
    return a.localeCompare(b);
});

self.postMessage(array);

it prints:

Frère,frère,école,�0cole

which is in the wrong order (once again, the encoding is not my problem).

The sorting in the main code is ok, but not the one in the web worker.

I tried to change the options of the localeCompare() function in the web worker, but it does not change anything.

Why is the sorting different in the web worker and how to get it right in the web worker?

(For some reason, I could not send the data to the main code, do the sorting and send it back to the web worker. I still got the wrong order (gives me école,�0cole,Frère,frère).)

Thanks for your help.

解决方案

localeCompare is still broken in Firefox Web Workers. Wladimir mentioned Bug 616841, which indeed fixed it almost everywhere... except for web workers, which were left broken because the Intl backend was (is?) not thread-safe, or some other thread-safety issues. The corresponding "Dead end" patch was never reviewed nor checked in.

I now filed Bug 903780, with a test case based on your code, so that localeCompare hopefully will be fixed in the future.

这篇关于Firefox扩展web worker中的语言环境字符串比较无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆