Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(96)

Unified Diff: third_party/WebKit/Source/bindings/core/v8/V8Binding.h

Issue 2142373002: Make v8AtomicString take a StringView. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Woops, pass the length. Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/bindings/core/v8/V8Binding.h
diff --git a/third_party/WebKit/Source/bindings/core/v8/V8Binding.h b/third_party/WebKit/Source/bindings/core/v8/V8Binding.h
index eabb4a2d8a8b1715e598c50351c53f928afd5af7..906fe6f715c54f79223922f25044149d1c456441 100644
--- a/third_party/WebKit/Source/bindings/core/v8/V8Binding.h
+++ b/third_party/WebKit/Source/bindings/core/v8/V8Binding.h
@@ -50,6 +50,7 @@
#include "platform/heap/Handle.h"
#include "platform/text/CompressibleString.h"
#include "wtf/text/AtomicString.h"
+#include "wtf/text/StringView.h"
#include <v8.h>
namespace blink {
@@ -421,16 +422,18 @@ inline v8::Local<v8::String> v8String(v8::Isolate* isolate, const CompressibleSt
return V8PerIsolateData::from(isolate)->getStringCache()->v8ExternalString(isolate, string);
}
-inline v8::Local<v8::String> v8AtomicString(v8::Isolate* isolate, const char* str, int length = -1)
+inline v8::Local<v8::String> v8AtomicString(v8::Isolate* isolate, const StringView& string)
{
- ASSERT(isolate);
- v8::Local<v8::String> value;
- if (LIKELY(v8::String::NewFromUtf8(isolate, str, v8::NewStringType::kInternalized, length).ToLocal(&value)))
- return value;
- // Immediately crashes when NewFromUtf8() fails because it only fails the
- // given str is too long.
- RELEASE_NOTREACHED();
- return v8::String::Empty(isolate);
+ DCHECK(isolate);
+ if (string.is8Bit())
+ return v8CallOrCrash(v8::String::NewFromOneByte(isolate, reinterpret_cast<const uint8_t*>(string.characters8()), v8::NewStringType::kInternalized, static_cast<int>(string.length())));
+ return v8CallOrCrash(v8::String::NewFromTwoByte(isolate, reinterpret_cast<const uint16_t*>(string.characters16()), v8::NewStringType::kInternalized, static_cast<int>(string.length())));
+}
+
+inline v8::Local<v8::String> v8StringFromUtf8(v8::Isolate* isolate, const char* bytes, int length)
+{
+ DCHECK(isolate);
+ return v8CallOrCrash(v8::String::NewFromUtf8(isolate, bytes, v8::NewStringType::kNormal, length));
}
inline v8::Local<v8::Value> v8Undefined()

Powered by Google App Engine
This is Rietveld 408576698