Browse Source

fix: correctly emplace optional values in the value converter (#21008)

* fix: correctly emplace optional values in the value converter

* chore: replace optional with nullopt when the conversion failed
trop[bot] 5 years ago
parent
commit
2e8349c520
1 changed files with 3 additions and 1 deletions
  1. 3 1
      shell/common/native_mate_converters/value_converter.h

+ 3 - 1
shell/common/native_mate_converters/value_converter.h

@@ -41,10 +41,12 @@ struct Converter<base::Optional<T>> {
                      v8::Local<v8::Value> val,
                      base::Optional<T>* out) {
     if (val->IsNull() || val->IsUndefined()) {
+      *out = base::nullopt;
       return true;
     }
     T converted;
-    if (Converter<T>::FromV8(isolate, val, &converted)) {
+    if (!Converter<T>::FromV8(isolate, val, &converted)) {
+      *out = base::nullopt;
       return true;
     }
     out->emplace(converted);