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

Side by Side Diff: gin/test/file.cc

Issue 1152653004: Re-land: gin: Use V8 Maybe APIs (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 6 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 unified diff | Download patch
« no previous file with comments | « gin/shell_runner.cc ('k') | gin/try_catch.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
OLDNEW
« no previous file with comments | « gin/shell_runner.cc ('k') | gin/try_catch.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698