Chromium Code Reviews| Index: third_party/WebKit/Source/core/inspector/v8/V8StringUtil.cpp |
| diff --git a/third_party/WebKit/Source/core/inspector/v8/V8StringUtil.cpp b/third_party/WebKit/Source/core/inspector/v8/V8StringUtil.cpp |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..8c2d1504172d6a78b39f1aed796e85bd67265061 |
| --- /dev/null |
| +++ b/third_party/WebKit/Source/core/inspector/v8/V8StringUtil.cpp |
| @@ -0,0 +1,36 @@ |
| +// Copyright 2016 The Chromium 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 "core/inspector/v8/V8StringUtil.h" |
| + |
| +namespace blink { |
| + |
| +v8::Local<v8::String> toV8String(v8::Isolate* isolate, const String& string) |
| +{ |
| + return v8::String::NewFromUtf8(isolate, string.utf8().data(), v8::NewStringType::kNormal).ToLocalChecked(); |
| +} |
| + |
| +v8::Local<v8::String> toV8StringInternalized(v8::Isolate* isolate, const String& string) |
| +{ |
| + return v8::String::NewFromUtf8(isolate, string.utf8().data(), v8::NewStringType::kInternalized).ToLocalChecked(); |
| +} |
| + |
| +String toWTFString(v8::Local<v8::String> value) |
| +{ |
| + if (value.IsEmpty() || value->IsNull() || value->IsUndefined()) |
| + return String(); |
| + UChar* buffer; |
| + String result = String::createUninitialized(value->Length(), buffer); |
|
dgozman
2016/01/30 16:36:39
This signature made me dig up who is allocating th
pfeldman
2016/01/31 16:04:13
That's the way we do it in bindings and other v8 c
|
| + value->Write(reinterpret_cast<uint16_t*>(buffer), 0, value->Length()); |
| + return result; |
| +} |
| + |
| +String toWTFStringWithTypeCheck(v8::Local<v8::Value> value) |
| +{ |
| + if (value.IsEmpty() || !value->IsString()) |
| + return String(); |
| + return toWTFString(value.As<v8::String>()); |
| +} |
| + |
| +} // namespace blink |