Skip to content

Commit 3a5fe1d

Browse files
committed
Lint C++ code.
1 parent 78b7159 commit 3a5fe1d

File tree

6 files changed

+32
-21
lines changed

6 files changed

+32
-21
lines changed

BUILD.gn

+1-1
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,6 @@ executable("deno_cctest") {
129129
"cctest.cc",
130130
]
131131
deps = [
132-
"v8/third_party/googletest:gtest",
132+
"//testing/gtest:gtest",
133133
]
134134
}

cctest.cc

+6-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
1-
#include "deno.h"
2-
#include "v8/third_party/googletest/src/googletest/include/gtest/gtest.h"
1+
// Copyright 2018 Ryan Dahl <[email protected]>
2+
// All rights reserved. MIT License.
3+
#include "testing/gtest/include/gtest/gtest.h"
4+
5+
#include "./deno.h"
36

47
TEST(SnapshotTest, InitializesCorrectly) {
58
EXPECT_TRUE(true);
6-
// TODO add actual tests
9+
// TODO(ry) add actual tests
710
}
811

912
int main(int argc, char** argv) {

deno.cc

+3-3
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@ IN THE SOFTWARE.
2828
#include "v8/include/libplatform/libplatform.h"
2929
#include "v8/include/v8.h"
3030

31-
#include "deno.h"
31+
#include "./deno.h"
3232

33-
#define CHECK(x) assert(x) // TODO use V8's CHECK.
33+
#define CHECK(x) assert(x) // TODO(ry) use V8's CHECK.
3434

3535
// Extracts a C string from a v8::V8 Utf8Value.
3636
const char* ToCString(const v8::String::Utf8Value& value) {
@@ -118,7 +118,7 @@ void Print(const v8::FunctionCallbackInfo<v8::Value>& args) {
118118
// Sets the recv callback.
119119
void Recv(const v8::FunctionCallbackInfo<v8::Value>& args) {
120120
v8::Isolate* isolate = args.GetIsolate();
121-
Deno* d = (Deno*)isolate->GetData(0);
121+
Deno* d = reinterpret_cast<Deno*>(isolate->GetData(0));
122122
assert(d->isolate == isolate);
123123

124124
v8::HandleScope handle_scope(isolate);

deno.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Copyright 2018 Ryan Dahl <[email protected]>
22
// All rights reserved. MIT License.
3-
#ifndef DENO_H
4-
#define DENO_H
3+
#ifndef DENO_H_
4+
#define DENO_H_
55

66
#include <string>
77
#include "v8/include/v8.h"
@@ -52,4 +52,4 @@ const char* deno_last_exception(Deno* d);
5252
void deno_dispose(Deno* d);
5353
void deno_terminate_execution(Deno* d);
5454

55-
#endif // DENO_H
55+
#endif // DENO_H_

main.cc

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1+
// Copyright 2018 Ryan Dahl <[email protected]>
2+
// All rights reserved. MIT License.
13
#include <assert.h>
24
#include <stdio.h>
35

46
#include "v8/include/v8.h"
57

6-
#include "deno.h"
8+
#include "./deno.h"
79
#include "natives_deno.cc"
810
#include "snapshot_deno.cc"
911

snapshot_creator.cc

+16-10
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// Copyright 2018 Ryan Dahl <[email protected]>
2+
// All rights reserved. MIT License.
13
#include <assert.h>
24
#include <stdio.h>
35
#include <string.h>
@@ -7,7 +9,7 @@
79

810
#include "v8/include/v8.h"
911

10-
#include "deno.h"
12+
#include "./deno.h"
1113

1214
class StartupDataCppWriter {
1315
public:
@@ -39,9 +41,10 @@ class StartupDataCppWriter {
3941

4042
void WriteSuffix() {
4143
char buffer[500];
42-
sprintf(buffer, "const v8::StartupData* StartupBlob_%s() {\n", name_);
44+
snprintf(buffer, sizeof(buffer),
45+
"const v8::StartupData* StartupBlob_%s() {\n", name_);
4346
file_ << buffer;
44-
sprintf(buffer, " return &%s_blob;\n", name_);
47+
snprintf(buffer, sizeof(buffer), " return &%s_blob;\n", name_);
4548
file_ << buffer;
4649
file_ << "}\n\n";
4750
}
@@ -51,25 +54,28 @@ class StartupDataCppWriter {
5154
for (int i = 0; i < sd_.raw_size; i++) {
5255
if ((i & 0x1F) == 0x1F) file_ << "\n";
5356
if (i > 0) file_ << ",";
54-
sprintf(buffer, "%u", static_cast<unsigned char>(sd_.data[i]));
57+
snprintf(buffer, sizeof(buffer), "%u",
58+
static_cast<unsigned char>(sd_.data[i]));
5559
file_ << buffer;
5660
}
5761
file_ << "\n";
5862
}
5963

6064
void WriteData() {
6165
char buffer[500];
62-
sprintf(buffer, "static const char %s_blob_data[] = {\n", name_);
66+
snprintf(buffer, sizeof(buffer), "static const char %s_blob_data[] = {\n",
67+
name_);
6368
file_ << buffer;
6469
WriteBinaryContentsAsCArray();
6570
file_ << "};\n";
66-
sprintf(buffer, "static const int %s_blob_size = %d;\n", name_,
67-
sd_.raw_size);
71+
snprintf(buffer, sizeof(buffer), "static const int %s_blob_size = %d;\n",
72+
name_, sd_.raw_size);
6873
file_ << buffer;
69-
sprintf(buffer, "static const v8::StartupData %s_blob =\n", name_);
74+
snprintf(buffer, sizeof(buffer), "static const v8::StartupData %s_blob =\n",
75+
name_);
7076
file_ << buffer;
71-
sprintf(buffer, "{ (const char*) %s_blob_data, %s_blob_size };\n", name_,
72-
name_);
77+
snprintf(buffer, sizeof(buffer),
78+
"{ (const char*) %s_blob_data, %s_blob_size };\n", name_, name_);
7379
file_ << buffer;
7480
}
7581

0 commit comments

Comments
 (0)