| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "gin/test/file.h" | 5 #include "gin/test/file.h" |
| 6 | 6 |
| 7 #include <iostream> | 7 #include <iostream> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/files/file_enumerator.h" | 10 #include "base/files/file_enumerator.h" |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 52 const base::FilePath& path = base::FilePath::FromUTF8Unsafe(filename); | 52 const base::FilePath& path = base::FilePath::FromUTF8Unsafe(filename); |
| 53 if (!base::DirectoryExists(path)) | 53 if (!base::DirectoryExists(path)) |
| 54 return v8::Null(args->isolate()); | 54 return v8::Null(args->isolate()); |
| 55 | 55 |
| 56 std::vector<std::string> names; | 56 std::vector<std::string> names; |
| 57 base::FileEnumerator e(path, false, base::FileEnumerator::FILES); | 57 base::FileEnumerator e(path, false, base::FileEnumerator::FILES); |
| 58 for (base::FilePath name = e.Next(); !name.empty(); name = e.Next()) { | 58 for (base::FilePath name = e.Next(); !name.empty(); name = e.Next()) { |
| 59 names.push_back(name.BaseName().AsUTF8Unsafe()); | 59 names.push_back(name.BaseName().AsUTF8Unsafe()); |
| 60 } | 60 } |
| 61 | 61 |
| 62 return gin::Converter<std::vector<std::string> >::ToV8(args->isolate(), | 62 v8::Local<v8::Value> v8_names; |
| 63 names); | 63 if (!TryConvertToV8(args->isolate(), names, &v8_names)) |
| 64 return v8::Null(args->isolate()); |
| 65 return v8_names; |
| 64 } | 66 } |
| 65 | 67 |
| 66 gin::WrapperInfo g_wrapper_info = { gin::kEmbedderNativeGin }; | 68 gin::WrapperInfo g_wrapper_info = { gin::kEmbedderNativeGin }; |
| 67 | 69 |
| 68 } // namespace | 70 } // namespace |
| 69 | 71 |
| 70 const char File::kModuleName[] = "file"; | 72 const char File::kModuleName[] = "file"; |
| 71 | 73 |
| 72 v8::Local<v8::Value> File::GetModule(v8::Isolate* isolate) { | 74 v8::Local<v8::Value> File::GetModule(v8::Isolate* isolate) { |
| 73 gin::PerIsolateData* data = gin::PerIsolateData::From(isolate); | 75 gin::PerIsolateData* data = gin::PerIsolateData::From(isolate); |
| 74 v8::Local<ObjectTemplate> templ = data->GetObjectTemplate(&g_wrapper_info); | 76 v8::Local<ObjectTemplate> templ = data->GetObjectTemplate(&g_wrapper_info); |
| 75 if (templ.IsEmpty()) { | 77 if (templ.IsEmpty()) { |
| 76 templ = gin::ObjectTemplateBuilder(isolate) | 78 templ = gin::ObjectTemplateBuilder(isolate) |
| 77 .SetMethod("readFileToString", ReadFileToString) | 79 .SetMethod("readFileToString", ReadFileToString) |
| 78 .SetMethod("getFilesInDirectory", GetFilesInDirectory) | 80 .SetMethod("getFilesInDirectory", GetFilesInDirectory) |
| 79 .SetMethod("getSourceRootDirectory", GetSourceRootDirectory) | 81 .SetMethod("getSourceRootDirectory", GetSourceRootDirectory) |
| 80 .Build(); | 82 .Build(); |
| 81 data->SetObjectTemplate(&g_wrapper_info, templ); | 83 data->SetObjectTemplate(&g_wrapper_info, templ); |
| 82 } | 84 } |
| 83 return templ->NewInstance(); | 85 return templ->NewInstance(); |
| 84 } | 86 } |
| 85 | 87 |
| 86 } // namespace gin | 88 } // namespace gin |
| OLD | NEW |