Skip to content

Commit

Permalink
fix: better error checking
Browse files Browse the repository at this point in the history
  • Loading branch information
codebytere committed Jun 10, 2020
1 parent 842abf9 commit 1179d24
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 10 deletions.
8 changes: 3 additions & 5 deletions binding.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@
"sources": [ ],
"conditions": [
['OS=="mac"', {
"xcode_settings": {
"MACOSX_DEPLOYMENT_TARGET": "10.12"
},
"sources": [
"src/defaults.mm",
"src/json_formatter.h",
Expand All @@ -23,8 +20,9 @@
],
'defines': [ 'NAPI_DISABLE_CPP_EXCEPTIONS' ],
"xcode_settings": {
"OTHER_CPLUSPLUSFLAGS": ["-std=c++14", "-stdlib=libc++"],
"OTHER_LDFLAGS": ["-framework CoreFoundation -framework Cocoa -framework Carbon"]
"OTHER_CPLUSPLUSFLAGS": ["-std=c++17", "-stdlib=libc++", "-Wextra"],
"OTHER_LDFLAGS": ["-framework CoreFoundation -framework Cocoa -framework Carbon"],
"MACOSX_DEPLOYMENT_TARGET": "10.12"
}
}]
}
17 changes: 12 additions & 5 deletions src/defaults.mm
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,13 @@
[mutable_array addObject:ToNSString(str)];
} else if (val.IsArray()) {
Napi::Array sub_array = val.As<Napi::Array>();
[mutable_array addObject:NapiArrayToNSArray(sub_array)];
if (NSArray *ns_arr = NapiArrayToNSArray(sub_array)) {
[mutable_array addObject:ns_arr];
}
} else if (val.IsObject()) {
NSDictionary *dict = NapiObjectToNSDictionary(val);
[mutable_array addObject:dict];
if (NSDictionary *dict = NapiObjectToNSDictionary(val)) {
[mutable_array addObject:dict];
}
}
}

Expand Down Expand Up @@ -207,10 +210,14 @@ void SetUserDefault(const Napi::CallbackInfo &info) {
[defaults setURL:url forKey:default_key];
} else if (type == "array") {
Napi::Array array = info[2].As<Napi::Array>();
[defaults setObject:NapiArrayToNSArray(array) forKey:default_key];
if (NSArray *ns_arr = NapiArrayToNSArray(array)) {
[defaults setObject:ns_arr forKey:default_key];
}
} else if (type == "dictionary") {
Napi::Value value = info[2].As<Napi::Value>();
[defaults setObject:NapiObjectToNSDictionary(value) forKey:default_key];
if (NSDictionary* dict = NapiObjectToNSDictionary(value)) {
[defaults setObject:dict forKey:default_key];
}
}
}

Expand Down

0 comments on commit 1179d24

Please sign in to comment.