Skip to content

Commit 0e32bb0

Browse files
authored
Compile with warnings and fix exiting warnings (#227)
* v8go.cc: Remove unused rtn variable * v8go.cc: Fix missing braces around initialization of subobject compiler warnings * Fix comparison of integer expressions of different signess gcc warnings * Compile with compiler warnings * Fail CI on a compiler warning
1 parent a582436 commit 0e32bb0

File tree

6 files changed

+28
-27
lines changed

6 files changed

+28
-27
lines changed

.github/workflows/test.yml

+2
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ jobs:
3131
run: echo "C:\msys64\mingw64\bin" >> $GITHUB_PATH
3232
shell: bash
3333
- name: Go Test
34+
env:
35+
CGO_CXXFLAGS: "-Werror"
3436
run: go test -v -coverprofile c.out ./...
3537
- name: Upload coverage to Codecov
3638
uses: codecov/codecov-action@v1

cgo.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ package v8go
66

77
//go:generate clang-format -i --verbose -style=Chromium v8go.h v8go.cc
88

9-
// #cgo CXXFLAGS: -fno-rtti -fpic -std=c++14 -DV8_COMPRESS_POINTERS -DV8_31BIT_SMIS_ON_64BIT_ARCH -I${SRCDIR}/deps/include
9+
// #cgo CXXFLAGS: -fno-rtti -fpic -std=c++14 -DV8_COMPRESS_POINTERS -DV8_31BIT_SMIS_ON_64BIT_ARCH -I${SRCDIR}/deps/include -Wall
1010
// #cgo LDFLAGS: -pthread -lv8
1111
// #cgo darwin,amd64 LDFLAGS: -L${SRCDIR}/deps/darwin_x86_64
1212
// #cgo darwin,arm64 LDFLAGS: -L${SRCDIR}/deps/darwin_arm64

object.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ func (o *Object) SetInternalField(idx uint32, val interface{}) error {
9393
return err
9494
}
9595

96-
inserted := C.ObjectSetInternalField(o.ptr, C.uint32_t(idx), value.ptr)
96+
inserted := C.ObjectSetInternalField(o.ptr, C.int(idx), value.ptr)
9797

9898
if inserted == 0 {
9999
panic(fmt.Errorf("index out of range [%v] with length %v", idx, o.InternalFieldCount()))
@@ -121,7 +121,7 @@ func (o *Object) Get(key string) (*Value, error) {
121121
// or the JS undefined value if the index hadn't been set.
122122
// Panics if given an out of range index.
123123
func (o *Object) GetInternalField(idx uint32) *Value {
124-
rtn := C.ObjectGetInternalField(o.ptr, C.uint32_t(idx))
124+
rtn := C.ObjectGetInternalField(o.ptr, C.int(idx))
125125
if rtn == nil {
126126
panic(fmt.Errorf("index out of range [%v] with length %v", idx, o.InternalFieldCount()))
127127
}

object_template.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ func (o *ObjectTemplate) NewInstance(ctx *Context) (*Object, error) {
6363
// SetInternalFieldCount sets the number of internal fields that instances of this
6464
// template will have.
6565
func (o *ObjectTemplate) SetInternalFieldCount(fieldCount uint32) {
66-
C.ObjectTemplateSetInternalFieldCount(o.ptr, C.uint32_t(fieldCount))
66+
C.ObjectTemplateSetInternalFieldCount(o.ptr, C.int(fieldCount))
6767
}
6868

6969
// InternalFieldCount returns the number of internal fields that instances of this

v8go.cc

+19-20
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,7 @@ RtnValue ObjectTemplateNewInstance(TemplatePtr ptr, ContextPtr ctx) {
360360
Local<Context> local_ctx = ctx->ptr.Get(iso);
361361
Context::Scope context_scope(local_ctx);
362362

363-
RtnValue rtn = {nullptr, nullptr};
363+
RtnValue rtn = {};
364364

365365
Local<ObjectTemplate> obj_tmpl = tmpl.As<ObjectTemplate>();
366366
Local<Object> obj;
@@ -378,7 +378,7 @@ RtnValue ObjectTemplateNewInstance(TemplatePtr ptr, ContextPtr ctx) {
378378
}
379379

380380
void ObjectTemplateSetInternalFieldCount(TemplatePtr ptr,
381-
uint32_t field_count) {
381+
int field_count) {
382382
LOCAL_TEMPLATE(ptr);
383383

384384
Local<ObjectTemplate> obj_tmpl = tmpl.As<ObjectTemplate>();
@@ -460,7 +460,7 @@ RtnValue FunctionTemplateGetFunction(TemplatePtr ptr, ContextPtr ctx) {
460460
Context::Scope context_scope(local_ctx);
461461

462462
Local<FunctionTemplate> fn_tmpl = tmpl.As<FunctionTemplate>();
463-
RtnValue rtn = {nullptr, nullptr};
463+
RtnValue rtn = {};
464464
Local<Function> fn;
465465
if (!fn_tmpl->GetFunction(local_ctx).ToLocal(&fn)) {
466466
rtn.error = ExceptionError(try_catch, iso, local_ctx);
@@ -531,7 +531,7 @@ void ContextFree(ContextPtr ctx) {
531531
RtnValue RunScript(ContextPtr ctx, const char* source, const char* origin) {
532532
LOCAL_CONTEXT(ctx);
533533

534-
RtnValue rtn = {nullptr, nullptr};
534+
RtnValue rtn = {};
535535

536536
MaybeLocal<String> maybeSrc =
537537
String::NewFromUtf8(iso, source, NewStringType::kNormal);
@@ -565,7 +565,7 @@ RtnValue RunScript(ContextPtr ctx, const char* source, const char* origin) {
565565

566566
RtnValue JSONParse(ContextPtr ctx, const char* str) {
567567
LOCAL_CONTEXT(ctx);
568-
RtnValue rtn = {nullptr, nullptr};
568+
RtnValue rtn = {};
569569

570570
Local<String> v8Str;
571571
if (!String::NewFromUtf8(iso, str, NewStringType::kNormal).ToLocal(&v8Str)) {
@@ -679,7 +679,7 @@ ValuePtr NewValueIntegerFromUnsigned(IsolatePtr iso, uint32_t v) {
679679
RtnValue NewValueString(IsolatePtr iso, const char* v) {
680680
ISOLATE_SCOPE_INTERNAL_CONTEXT(iso);
681681
TryCatch try_catch(iso);
682-
RtnValue rtn = {nullptr, nullptr};
682+
RtnValue rtn = {};
683683
Local<String> str;
684684
if (!String::NewFromUtf8(iso, v).ToLocal(&str)) {
685685
rtn.error = ExceptionError(try_catch, iso, ctx->ptr.Get(iso));
@@ -760,7 +760,7 @@ RtnValue NewValueBigIntFromWords(IsolatePtr iso,
760760
TryCatch try_catch(iso);
761761
Local<Context> local_ctx = ctx->ptr.Get(iso);
762762

763-
RtnValue rtn = {nullptr, nullptr};
763+
RtnValue rtn = {};
764764
Local<BigInt> bigint;
765765
if (!BigInt::NewFromWords(local_ctx, sign_bit, word_count, words)
766766
.ToLocal(&bigint)) {
@@ -809,7 +809,7 @@ double ValueToNumber(ValuePtr ptr) {
809809

810810
RtnString ValueToDetailString(ValuePtr ptr) {
811811
LOCAL_VALUE(ptr);
812-
RtnString rtn = {nullptr, nullptr};
812+
RtnString rtn = {0};
813813
Local<String> str;
814814
if (!value->ToDetailString(local_ctx).ToLocal(&str)) {
815815
rtn.error = ExceptionError(try_catch, iso, local_ctx);
@@ -852,7 +852,7 @@ ValueBigInt ValueToBigInt(ValuePtr ptr) {
852852

853853
RtnValue ValueToObject(ValuePtr ptr) {
854854
LOCAL_VALUE(ptr);
855-
RtnValue rtn = {nullptr, nullptr};
855+
RtnValue rtn = {};
856856
Local<Object> obj;
857857
if (!value->ToObject(local_ctx).ToLocal(&obj)) {
858858
rtn.error = ExceptionError(try_catch, iso, local_ctx);
@@ -1163,7 +1163,7 @@ void ObjectSetIdx(ValuePtr ptr, uint32_t idx, ValuePtr prop_val) {
11631163
obj->Set(local_ctx, idx, prop_val->ptr.Get(iso)).Check();
11641164
}
11651165

1166-
int ObjectSetInternalField(ValuePtr ptr, uint32_t idx, ValuePtr val_ptr) {
1166+
int ObjectSetInternalField(ValuePtr ptr, int idx, ValuePtr val_ptr) {
11671167
LOCAL_OBJECT(ptr);
11681168
m_value* prop_val = static_cast<m_value*>(val_ptr);
11691169

@@ -1183,7 +1183,7 @@ int ObjectInternalFieldCount(ValuePtr ptr) {
11831183

11841184
RtnValue ObjectGet(ValuePtr ptr, const char* key) {
11851185
LOCAL_OBJECT(ptr);
1186-
RtnValue rtn = {nullptr, nullptr};
1186+
RtnValue rtn = {};
11871187

11881188
Local<String> key_val;
11891189
if (!String::NewFromUtf8(iso, key, NewStringType::kNormal)
@@ -1206,7 +1206,7 @@ RtnValue ObjectGet(ValuePtr ptr, const char* key) {
12061206
return rtn;
12071207
}
12081208

1209-
ValuePtr ObjectGetInternalField(ValuePtr ptr, uint32_t idx) {
1209+
ValuePtr ObjectGetInternalField(ValuePtr ptr, int idx) {
12101210
LOCAL_OBJECT(ptr);
12111211

12121212
if (idx >= obj->InternalFieldCount()) {
@@ -1226,7 +1226,7 @@ ValuePtr ObjectGetInternalField(ValuePtr ptr, uint32_t idx) {
12261226

12271227
RtnValue ObjectGetIdx(ValuePtr ptr, uint32_t idx) {
12281228
LOCAL_OBJECT(ptr);
1229-
RtnValue rtn = {nullptr, nullptr};
1229+
RtnValue rtn = {};
12301230

12311231
Local<Value> result;
12321232
if (!obj->Get(local_ctx, idx).ToLocal(&result)) {
@@ -1271,7 +1271,7 @@ int ObjectDeleteIdx(ValuePtr ptr, uint32_t idx) {
12711271

12721272
RtnValue NewPromiseResolver(ContextPtr ctx) {
12731273
LOCAL_CONTEXT(ctx);
1274-
RtnValue rtn = {nullptr, nullptr};
1274+
RtnValue rtn = {};
12751275
Local<Promise::Resolver> resolver;
12761276
if (!Promise::Resolver::New(local_ctx).ToLocal(&resolver)) {
12771277
rtn.error = ExceptionError(try_catch, iso, local_ctx);
@@ -1317,7 +1317,7 @@ int PromiseState(ValuePtr ptr) {
13171317

13181318
RtnValue PromiseThen(ValuePtr ptr, int callback_ref) {
13191319
LOCAL_VALUE(ptr)
1320-
RtnValue rtn = {nullptr, nullptr};
1320+
RtnValue rtn = {};
13211321
Local<Promise> promise = value.As<Promise>();
13221322
Local<Integer> cbData = Integer::New(iso, callback_ref);
13231323
Local<Function> func;
@@ -1342,7 +1342,7 @@ RtnValue PromiseThen(ValuePtr ptr, int callback_ref) {
13421342

13431343
RtnValue PromiseThen2(ValuePtr ptr, int on_fulfilled_ref, int on_rejected_ref) {
13441344
LOCAL_VALUE(ptr)
1345-
RtnValue rtn = {nullptr, nullptr};
1345+
RtnValue rtn = {};
13461346
Local<Promise> promise = value.As<Promise>();
13471347
Local<Integer> onFulfilledData = Integer::New(iso, on_fulfilled_ref);
13481348
Local<Function> onFulfilledFunc;
@@ -1375,7 +1375,7 @@ RtnValue PromiseThen2(ValuePtr ptr, int on_fulfilled_ref, int on_rejected_ref) {
13751375

13761376
RtnValue PromiseCatch(ValuePtr ptr, int callback_ref) {
13771377
LOCAL_VALUE(ptr)
1378-
RtnValue rtn = {nullptr, nullptr};
1378+
RtnValue rtn = {};
13791379
Local<Promise> promise = value.As<Promise>();
13801380
Local<Integer> cbData = Integer::New(iso, callback_ref);
13811381
Local<Function> func;
@@ -1424,7 +1424,7 @@ static void buildCallArguments(Isolate* iso,
14241424
RtnValue FunctionCall(ValuePtr ptr, ValuePtr recv, int argc, ValuePtr args[]) {
14251425
LOCAL_VALUE(ptr)
14261426

1427-
RtnValue rtn = {nullptr, nullptr};
1427+
RtnValue rtn = {};
14281428
Local<Function> fn = Local<Function>::Cast(value);
14291429
Local<Value> argv[argc];
14301430
buildCallArguments(iso, argv, argc, args);
@@ -1446,7 +1446,7 @@ RtnValue FunctionCall(ValuePtr ptr, ValuePtr recv, int argc, ValuePtr args[]) {
14461446

14471447
RtnValue FunctionNewInstance(ValuePtr ptr, int argc, ValuePtr args[]) {
14481448
LOCAL_VALUE(ptr)
1449-
RtnValue rtn = {nullptr, nullptr};
1449+
RtnValue rtn = {};
14501450
Local<Function> fn = Local<Function>::Cast(value);
14511451
Local<Value> argv[argc];
14521452
buildCallArguments(iso, argv, argc, args);
@@ -1465,7 +1465,6 @@ RtnValue FunctionNewInstance(ValuePtr ptr, int argc, ValuePtr args[]) {
14651465

14661466
ValuePtr FunctionSourceMapUrl(ValuePtr ptr) {
14671467
LOCAL_VALUE(ptr)
1468-
RtnValue rtn = {nullptr, nullptr};
14691468
Local<Function> fn = Local<Function>::Cast(value);
14701469
Local<Value> result = fn->GetScriptOrigin().SourceMapUrl();
14711470
m_value* rtnval = new m_value;

v8go.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ extern void TemplateSetTemplate(TemplatePtr ptr,
145145
extern TemplatePtr NewObjectTemplate(IsolatePtr iso_ptr);
146146
extern RtnValue ObjectTemplateNewInstance(TemplatePtr ptr, ContextPtr ctx_ptr);
147147
extern void ObjectTemplateSetInternalFieldCount(TemplatePtr ptr,
148-
uint32_t field_count);
148+
int field_count);
149149
extern int ObjectTemplateInternalFieldCount(TemplatePtr ptr);
150150

151151
extern TemplatePtr NewFunctionTemplate(IsolatePtr iso_ptr, int callback_ref);
@@ -233,11 +233,11 @@ int ValueIsModuleNamespaceObject(ValuePtr ptr);
233233

234234
extern void ObjectSet(ValuePtr ptr, const char* key, ValuePtr val_ptr);
235235
extern void ObjectSetIdx(ValuePtr ptr, uint32_t idx, ValuePtr val_ptr);
236-
extern int ObjectSetInternalField(ValuePtr ptr, uint32_t idx, ValuePtr val_ptr);
236+
extern int ObjectSetInternalField(ValuePtr ptr, int idx, ValuePtr val_ptr);
237237
extern int ObjectInternalFieldCount(ValuePtr ptr);
238238
extern RtnValue ObjectGet(ValuePtr ptr, const char* key);
239239
extern RtnValue ObjectGetIdx(ValuePtr ptr, uint32_t idx);
240-
extern ValuePtr ObjectGetInternalField(ValuePtr ptr, uint32_t idx);
240+
extern ValuePtr ObjectGetInternalField(ValuePtr ptr, int idx);
241241
int ObjectHas(ValuePtr ptr, const char* key);
242242
int ObjectHasIdx(ValuePtr ptr, uint32_t idx);
243243
int ObjectDelete(ValuePtr ptr, const char* key);

0 commit comments

Comments
 (0)