Skip to content

Commit

Permalink
feat(languagecode): ensure unknown identifier match
Browse files Browse the repository at this point in the history
  • Loading branch information
kwonoj committed Jan 31, 2019
1 parent e65b7a9 commit b04f7ef
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/cldLoader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@ export const cldLoader = (asmModule: CldAsmModule, _environment?: ENVIRONMENT):
languageResultStructSize
});

// both identifier should match all time, check when initialize binary
if (unknownIdentifier !== LanguageCode.UNKNOWN) {
throw new Error(`cld3 binary unknownIdentifier constant does not match to LanguageCode enum`);
}

/**
* Wrapper function to read LanguageResult struct from pointer.
* After interop, pointer will be freed.
Expand Down Expand Up @@ -80,7 +85,6 @@ export const cldLoader = (asmModule: CldAsmModule, _environment?: ENVIRONMENT):
const cldPtr = cldInterface.create(minBytes, maxBytes);

return {
unknownIdentifier,
findLanguage: (text: string) => {
// `findLanguage` requires caller must allocate memory for return value.
const resultPtr = _malloc(languageResultStructSize);
Expand Down

0 comments on commit b04f7ef

Please sign in to comment.