Skip to content

Commit 1179d24

Browse files
committed
fix: better error checking
1 parent 842abf9 commit 1179d24

File tree

2 files changed

+15
-10
lines changed

2 files changed

+15
-10
lines changed

binding.gyp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,6 @@
44
"sources": [ ],
55
"conditions": [
66
['OS=="mac"', {
7-
"xcode_settings": {
8-
"MACOSX_DEPLOYMENT_TARGET": "10.12"
9-
},
107
"sources": [
118
"src/defaults.mm",
129
"src/json_formatter.h",
@@ -23,8 +20,9 @@
2320
],
2421
'defines': [ 'NAPI_DISABLE_CPP_EXCEPTIONS' ],
2522
"xcode_settings": {
26-
"OTHER_CPLUSPLUSFLAGS": ["-std=c++14", "-stdlib=libc++"],
27-
"OTHER_LDFLAGS": ["-framework CoreFoundation -framework Cocoa -framework Carbon"]
23+
"OTHER_CPLUSPLUSFLAGS": ["-std=c++17", "-stdlib=libc++", "-Wextra"],
24+
"OTHER_LDFLAGS": ["-framework CoreFoundation -framework Cocoa -framework Carbon"],
25+
"MACOSX_DEPLOYMENT_TARGET": "10.12"
2826
}
2927
}]
3028
}

src/defaults.mm

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -84,10 +84,13 @@
8484
[mutable_array addObject:ToNSString(str)];
8585
} else if (val.IsArray()) {
8686
Napi::Array sub_array = val.As<Napi::Array>();
87-
[mutable_array addObject:NapiArrayToNSArray(sub_array)];
87+
if (NSArray *ns_arr = NapiArrayToNSArray(sub_array)) {
88+
[mutable_array addObject:ns_arr];
89+
}
8890
} else if (val.IsObject()) {
89-
NSDictionary *dict = NapiObjectToNSDictionary(val);
90-
[mutable_array addObject:dict];
91+
if (NSDictionary *dict = NapiObjectToNSDictionary(val)) {
92+
[mutable_array addObject:dict];
93+
}
9194
}
9295
}
9396

@@ -207,10 +210,14 @@ void SetUserDefault(const Napi::CallbackInfo &info) {
207210
[defaults setURL:url forKey:default_key];
208211
} else if (type == "array") {
209212
Napi::Array array = info[2].As<Napi::Array>();
210-
[defaults setObject:NapiArrayToNSArray(array) forKey:default_key];
213+
if (NSArray *ns_arr = NapiArrayToNSArray(array)) {
214+
[defaults setObject:ns_arr forKey:default_key];
215+
}
211216
} else if (type == "dictionary") {
212217
Napi::Value value = info[2].As<Napi::Value>();
213-
[defaults setObject:NapiObjectToNSDictionary(value) forKey:default_key];
218+
if (NSDictionary* dict = NapiObjectToNSDictionary(value)) {
219+
[defaults setObject:dict forKey:default_key];
220+
}
214221
}
215222
}
216223

0 commit comments

Comments
 (0)