OLD | NEW |
(Empty) | |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "mojo/public/bindings/js/v8_string.h" |
| 6 |
| 7 namespace mojo { |
| 8 namespace js { |
| 9 |
| 10 v8::Handle<v8::String> Wrapper<std::string>::ToObject(v8::Isolate* isolate, |
| 11 std::string native) { |
| 12 return v8::String::NewFromUtf8(isolate, |
| 13 native.data(), |
| 14 v8::String::kNormalString, |
| 15 native.length()); |
| 16 } |
| 17 |
| 18 std::string Wrapper<std::string>::ToNative(v8::Handle<v8::Value> value) { |
| 19 if (!value->IsString()) |
| 20 return std::string(); |
| 21 v8::Handle<v8::String> string = v8::Handle<v8::String>::Cast(value); |
| 22 int length = string->Utf8Length(); |
| 23 std::string result; |
| 24 result.resize(length); |
| 25 string->WriteUtf8(&result[0], length, NULL, v8::String::NO_NULL_TERMINATION); |
| 26 return result; |
| 27 } |
| 28 |
| 29 } // namespace js |
| 30 } // namespace mojo |
OLD | NEW |