michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this file, michael@0: * You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: addOnPreMain(function() { michael@0: michael@0: onmessage = function(aMsg){ michael@0: michael@0: // Convert the string to an array of UTF8 bytes. michael@0: var encoder = new TextEncoder(); michael@0: encoder['encoding'] = "utf-8"; michael@0: var utf8Array = encoder['encode'](aMsg.data); michael@0: michael@0: // Copy the UTF8 byte array to the heap. michael@0: var strLength = utf8Array.length; michael@0: var ptr = Module['_malloc'](strLength + 1); michael@0: var heap = Module['HEAPU8']; michael@0: new Uint8Array(heap.buffer, ptr, strLength).set(utf8Array); michael@0: // Add a \0 at the end of the C string. michael@0: heap[ptr + strLength] = 0; michael@0: michael@0: var lang = Pointer_stringify(_detectLangCode(ptr)); michael@0: var confident = !!Module['ccall']("lastResultReliable", "number"); michael@0: postMessage({'language': lang, michael@0: 'confident': confident}); michael@0: michael@0: Module['_free'](ptr); michael@0: }; michael@0: michael@0: postMessage("ready"); michael@0: michael@0: });