Files
sousa-gecko/editor/spellchecker/tests/test_suggest.html
T
Ryan VanderMeulen a876ac1f03 Bug 2037089 - Update vendored Hunspell to v1.7.3. r=masayuki,pbone
Patches:
- bug1410214.patch: regenerated for v1.7.3 filemgr.hxx (minor upstream
  cleanup: <cstdio> instead of <stdio.h>, = delete instead of private).
- bug1653659.patch: regenerated for v1.7.3 csutil.cxx/.hxx; also adds a
  MOZILLA_CLIENT stub for unicodeisalpha (returns 0; the function is never
  reached on the RLBox sandbox path but needs to compile without
  utf_info.hxx, which is excluded from MOZILLA_CLIENT builds).
- bug1739761.patch: refactored, see below.
- bug1838113.patch: dropped; upstream incorporated the change in v1.7.3.
- bug2037089-build-fixes.patch: new; backports two upstream build fixes
  needed for Firefox's hazard build.

Rebased bug1739761.patch against v1.7.3's significantly restructured
HashMgr. v1.7.3 converted several malloc-heavy paths to std::vector and
added the H_OPT_OWNFLAGS bit and a release_flags() helper, requiring a
non-trivial port.

Key invariant: arena_alloc'd memory must only ever see arena_free() (a
no-op); calling free()/delete[] on arena interior pointers will crash wasm
dlmalloc since they are interior pointers into arena chunks, not the starts
of malloc'd blocks.

The arena (std::vector<std::unique_ptr<uint8_t[]>>, 64KB chunks) covers
hentry structs, flag vectors from decode_flags, flags2 in
add_hidden_capitalized_word, and aliasm strings. Runtime additions via
add/add_with_affix/remove continue to use new[]/delete[] with
H_OPT_OWNFLAGS, which is handled correctly by release_flags.

Each arena_alloc call passes its required alignment (alignof(T)), and the
allocator pads the bump pointer accordingly. Chunk sizes are rounded up to
alignof(std::max_align_t) so that an oversized request (num_bytes >= 64KB)
cannot leave a non-aligned current_chunk_size, which would let a later
aligned_offset overshoot and underflow the remaining-space check.

Differential Revision: https://phabricator.services.mozilla.com/D298926
2026-05-23 22:06:37 +00:00

46 lines
1.6 KiB
HTML

<!DOCTYPE html>
<html>
<head>
<title>Test for nsIEditorSpellChecker.suggest</title>
<script src="/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" href="/tests/SimpleTest/test.css" />
</head>
<body>
<p id="display"></p>
<div contenteditable id="en-US" lang="en-US">missspelled</div>
<pre id="test">
<script class="testbody" type="text/javascript">
add_task(async function() {
await new Promise(resolve => SimpleTest.waitForFocus(resolve));
let { maybeOnSpellCheck } = SpecialPowers.ChromeUtils.importESModule(
"resource://testing-common/AsyncSpellCheckTestHelper.sys.mjs"
);
let element = document.getElementById("en-US");
element.focus();
await new Promise(resolve => maybeOnSpellCheck(element, resolve));
let editingSession = SpecialPowers.wrap(window).docShell.editingSession;
let editor = editingSession.getEditorForWindow(window);
let spellchecker = SpecialPowers.Cu.createSpellChecker();
spellchecker.setFilterType(spellchecker.FILTERTYPE_NORMAL);
await new Promise(resolve => spellchecker.InitSpellChecker(editor, false, resolve));
let suggestions = await spellchecker.suggest("misspelled", 5);
is(suggestions.length, 0, "\"misspelled\" is correct word");
// Hunspell 1.7.3 switched suggestion timeouts from CPU time (clock()) to wall
// time (std::chrono::steady_clock). On slower builds (sanitizers, 32-bit) the
// 100ms limit is hit before all 5 suggestions are generated.
suggestions = await spellchecker.suggest("missspelled", 5);
ok(suggestions.length >= 3 && suggestions.length <= 5, "\"missspelled\" isn't correct word");
});
</script>
</pre>
</body>
</html>