Index: src/wasm/utf8.cc |
diff --git a/src/wasm/utf8.cc b/src/wasm/utf8.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..1ae58d4e17100639a1f7cc54f183336714d735bc |
--- /dev/null |
+++ b/src/wasm/utf8.cc |
@@ -0,0 +1,42 @@ |
+// Copyright 2016 the V8 project authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "src/wasm/utf8.h" |
+ |
+#include "src/base/logging.h" |
+ |
+#include "unicode/utf8.h" |
+ |
+namespace { |
+ |
+inline bool IsValidCharacter(uint32_t code_point) { |
+ // Excludes non-characters (U+FDD0..U+FDEF, and all codepoints ending in |
+ // 0xFFFE or 0xFFFF) from the set of valid code points. |
+ return code_point < 0xD800u || |
+ (code_point >= 0xE000u && code_point < 0xFDD0u) || |
+ (code_point > 0xFDEFu && code_point <= 0x10FFFFu && |
+ (code_point & 0xFFFEu) != 0xFFFEu); |
+} |
+ |
+} // namespace |
+ |
+namespace v8 { |
+namespace internal { |
+namespace wasm { |
+ |
+bool IsValidUtf8(const uint8_t *buf, int32_t len) { |
+ int32_t char_index = 0; |
+ DCHECK(len >= 0); |
+ |
+ while (char_index < len) { |
+ int32_t code_point; |
+ U8_NEXT(buf, char_index, len, code_point); |
+ if (!IsValidCharacter(code_point)) return false; |
+ } |
+ return true; |
+} |
+ |
+} // namespace wasm |
+} // namespace internal |
+} // namespace v8 |