diff options
Diffstat (limited to 'src/parser/contexts.h')
-rw-r--r-- | src/parser/contexts.h | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/src/parser/contexts.h b/src/parser/contexts.h index 8b59ab40b..0979461a0 100644 --- a/src/parser/contexts.h +++ b/src/parser/contexts.h @@ -22,6 +22,7 @@ #include "lexer.h" #include "support/name.h" #include "support/result.h" +#include "support/string.h" #include "wasm-builder.h" #include "wasm-ir-builder.h" #include "wasm.h" @@ -2491,7 +2492,13 @@ struct ParseDefsCtx : TypeParserCtx<ParseDefsCtx> { Result<> makeStringConst(Index pos, const std::vector<Annotation>& annotations, std::string_view str) { - return withLoc(pos, irBuilder.makeStringConst(Name(str))); + // Re-encode from WTF-8 to WTF-16. + std::stringstream wtf16; + if (!String::convertWTF8ToWTF16(wtf16, str)) { + return in.err(pos, "invalid string constant"); + } + // TODO: Use wtf16.view() once we have C++20. + return withLoc(pos, irBuilder.makeStringConst(wtf16.str())); } Result<> makeStringMeasure(Index pos, |