Kaynağa Gözat

LibWeb: Return instead of throwing on unknown enums in attribute setters

I saw one site relying on this, where they are trying to set
XHR.responseType to "text/plain", which is not a valid responseType.
However, they also don't expect it to throw. The IDL spec special cases
enumerations to make it return instead of throwing in this case.
Luke Wilde 3 yıl önce
ebeveyn
işleme
885c6b6678

+ 9 - 1
Meta/Lagom/Tools/CodeGenerators/LibWeb/WrapperGenerator/IDLGenerators.cpp

@@ -605,10 +605,18 @@ static void generate_to_cpp(SourceGenerator& generator, ParameterType& parameter
 )~~~");
         }
 
-        enum_generator.append(R"~~~(
+        // NOTE: Attribute setters return undefined instead of throwing when the string doesn't match an enum value.
+        if constexpr (!IsSame<Attribute, RemoveConst<ParameterType>>) {
+            enum_generator.append(R"~~~(
     @else@
         return vm.throw_completion<JS::TypeError>(global_object, JS::ErrorType::InvalidEnumerationValue, @js_name.as_string@, "@parameter.type.name@");
 )~~~");
+        } else {
+            enum_generator.append(R"~~~(
+    @else@
+        return JS::js_undefined();
+)~~~");
+        }
 
         if (optional) {
             enum_generator.append(R"~~~(