browser/components/translation/cld2/post.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/browser/components/translation/cld2/post.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,32 @@
     1.4 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.5 + * License, v. 2.0. If a copy of the MPL was not distributed with this file,
     1.6 + * You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.7 +
     1.8 +addOnPreMain(function() {
     1.9 +
    1.10 +  onmessage = function(aMsg){
    1.11 +
    1.12 +    // Convert the string to an array of UTF8 bytes.
    1.13 +    var encoder = new TextEncoder();
    1.14 +    encoder['encoding'] = "utf-8";
    1.15 +    var utf8Array = encoder['encode'](aMsg.data);
    1.16 +
    1.17 +    // Copy the UTF8 byte array to the heap.
    1.18 +    var strLength = utf8Array.length;
    1.19 +    var ptr = Module['_malloc'](strLength + 1);
    1.20 +    var heap = Module['HEAPU8'];
    1.21 +    new Uint8Array(heap.buffer, ptr, strLength).set(utf8Array);
    1.22 +    // Add a \0 at the end of the C string.
    1.23 +    heap[ptr + strLength] = 0;
    1.24 +
    1.25 +    var lang = Pointer_stringify(_detectLangCode(ptr));
    1.26 +    var confident = !!Module['ccall']("lastResultReliable", "number");
    1.27 +    postMessage({'language': lang,
    1.28 +                 'confident': confident});
    1.29 +
    1.30 +    Module['_free'](ptr);
    1.31 +  };
    1.32 +
    1.33 +  postMessage("ready");
    1.34 +
    1.35 +});

mercurial