Changeset 264201 in webkit
- Timestamp:
- Jul 9, 2020, 3:41:21 PM (5 years ago)
- Location:
- trunk/Source/WebCore
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r264199 r264201 1 2020-07-09 Chris Dumez <cdumez@apple.com> 2 3 [Bindings] Add default value support for union types in dictionary members 4 https://bugs.webkit.org/show_bug.cgi?id=214160 5 6 Reviewed by Sam Weinig. 7 8 Add default value support for union types in dictionary members. This is needed for the WebAudio specification: 9 - https://www.w3.org/TR/webaudio/#AudioContextOptions 10 """ 11 (AudioContextLatencyCategory or double) latencyHint = "interactive"; 12 """ 13 14 * bindings/scripts/CodeGeneratorJS.pm: 15 (GenerateDefaultValue): 16 * bindings/scripts/test/JS/JSTestObj.cpp: 17 (WebCore::jsTestObjPrototypeFunctionOverloadWithOptionalUnion1Body): 18 * bindings/scripts/test/JS/JSTestStandaloneDictionary.cpp: 19 (WebCore::convertDictionary<DictionaryImplName>): 20 (WebCore::convertDictionaryToJS): 21 * bindings/scripts/test/TestStandaloneDictionary.idl: 22 1 23 2020-07-09 Per Arne Vollan <pvollan@apple.com> 2 24 -
trunk/Source/WebCore/bindings/scripts/CodeGeneratorJS.pm
r263638 r264201 2211 2211 my ($typeScope, $context, $type, $defaultValue) = @_; 2212 2212 2213 if ($codeGenerator->IsStringType($type)) {2214 my $useAtomString = $type->extendedAttributes->{AtomString};2215 if ($defaultValue eq "null") {2216 return $useAtomString ? "nullAtom()" : "String()";2217 } elsif ($defaultValue eq "\"\"") {2218 return $useAtomString ? "emptyAtom()" : "emptyString()";2219 } else {2220 return $useAtomString ? "AtomString(${defaultValue}, AtomString::ConstructFromLiteral)" : "${defaultValue}_s";2221 }2222 }2223 2224 if ($codeGenerator->IsEnumType($type)) {2225 # FIXME: Would be nice to report an error if the value does not have quote marks around it.2226 # FIXME: Would be nice to report an error if the value is not one of the enumeration values.2227 if ($defaultValue eq "null") {2228 die if !$type->isNullable;2229 return "WTF::nullopt";2230 }2231 my $className = GetEnumerationClassName($type, $typeScope);2232 my $enumerationValueName = GetEnumerationValueName(substr($defaultValue, 1, -1));2233 return $className . "::" . $enumerationValueName;2234 }2235 2213 if ($defaultValue eq "null") { 2236 2214 if ($type->isUnion) { … … 2243 2221 return "jsNull()" if $type->name eq "any"; 2244 2222 return "nullptr" if $codeGenerator->IsWrapperType($type) || $codeGenerator->IsBufferSourceType($type); 2245 return "String()" if $codeGenerator->IsStringType($type); 2223 if ($codeGenerator->IsStringType($type)) { 2224 my $useAtomString = $type->extendedAttributes->{AtomString}; 2225 return $useAtomString ? "nullAtom()" : "String()"; 2226 } 2246 2227 return "WTF::nullopt"; 2247 2228 } … … 2254 2235 return "jsUndefined()" if $defaultValue eq "undefined"; 2255 2236 return "PNaN" if $defaultValue eq "NaN"; 2237 2238 if (substr($defaultValue, 0, 1) eq "\"") { 2239 # Default value is a quoted string so the type should be a DOMString or an enumeration. 2240 if ($type->isUnion) { 2241 foreach my $memberType (GetFlattenedMemberTypes($type)) { 2242 if ($codeGenerator->IsStringType($memberType) || $codeGenerator->IsEnumType($memberType)) { 2243 $type = $memberType; 2244 last; 2245 } 2246 } 2247 } 2248 if ($codeGenerator->IsStringType($type)) { 2249 my $useAtomString = $type->extendedAttributes->{AtomString}; 2250 if ($defaultValue eq "\"\"") { 2251 return $useAtomString ? "emptyAtom()" : "emptyString()"; 2252 } else { 2253 return $useAtomString ? "AtomString(${defaultValue}, AtomString::ConstructFromLiteral)" : "${defaultValue}_s"; 2254 } 2255 } 2256 2257 if ($codeGenerator->IsEnumType($type)) { 2258 my $className = GetEnumerationClassName($type, $typeScope); 2259 my $enumerationValueName = GetEnumerationValueName(substr($defaultValue, 1, -1)); 2260 return $className . "::" . $enumerationValueName; 2261 } 2262 } 2256 2263 2257 2264 return $defaultValue; -
trunk/Source/WebCore/bindings/scripts/test/JS/JSTestCallTracer.cpp
r260992 r264201 513 513 auto& impl = castedThis->wrapped(); 514 514 EnsureStillAliveScope argument0 = callFrame->argument(0); 515 auto variantDefaultArg = argument0.value().isUndefined() ? "": convert<IDLUnion<IDLBoolean, IDLFloat, IDLDOMString>>(*lexicalGlobalObject, argument0.value());515 auto variantDefaultArg = argument0.value().isUndefined() ? emptyString() : convert<IDLUnion<IDLBoolean, IDLFloat, IDLDOMString>>(*lexicalGlobalObject, argument0.value()); 516 516 RETURN_IF_EXCEPTION(throwScope, encodedJSValue()); 517 517 if (UNLIKELY(impl.callTracingActive())) -
trunk/Source/WebCore/bindings/scripts/test/JS/JSTestStandaloneDictionary.cpp
r251425 r264201 28 28 #include "JSDOMConvertBoolean.h" 29 29 #include "JSDOMConvertCallbacks.h" 30 #include "JSDOMConvertNullable.h" 30 31 #include "JSDOMConvertNumbers.h" 31 32 #include "JSDOMConvertStrings.h" 33 #include "JSDOMConvertUnion.h" 32 34 #include "JSDOMGlobalObject.h" 33 35 #include "JSVoidCallback.h" … … 37 39 #include <JavaScriptCore/ObjectConstructor.h> 38 40 #include <wtf/NeverDestroyed.h> 41 #include <wtf/Variant.h> 39 42 40 43 … … 88 91 RETURN_IF_EXCEPTION(throwScope, { }); 89 92 } 93 JSValue nullableUnionWithNullDefaultValueValue; 94 if (isNullOrUndefined) 95 nullableUnionWithNullDefaultValueValue = jsUndefined(); 96 else { 97 nullableUnionWithNullDefaultValueValue = object->get(&lexicalGlobalObject, Identifier::fromString(vm, "nullableUnionWithNullDefaultValue")); 98 RETURN_IF_EXCEPTION(throwScope, { }); 99 } 100 if (!nullableUnionWithNullDefaultValueValue.isUndefined()) { 101 result.nullableUnionWithNullDefaultValue = convert<IDLNullable<IDLUnion<IDLDOMString, IDLBoolean>>>(lexicalGlobalObject, nullableUnionWithNullDefaultValueValue); 102 RETURN_IF_EXCEPTION(throwScope, { }); 103 } else 104 result.nullableUnionWithNullDefaultValue = WTF::nullopt; 90 105 #if ENABLE(Conditional13) || ENABLE(Conditional14) 91 106 JSValue partialBooleanMemberValue; … … 206 221 RETURN_IF_EXCEPTION(throwScope, { }); 207 222 } 223 JSValue unionMemberWithDefaultValueValue; 224 if (isNullOrUndefined) 225 unionMemberWithDefaultValueValue = jsUndefined(); 226 else { 227 unionMemberWithDefaultValueValue = object->get(&lexicalGlobalObject, Identifier::fromString(vm, "unionMemberWithDefaultValue")); 228 RETURN_IF_EXCEPTION(throwScope, { }); 229 } 230 if (!unionMemberWithDefaultValueValue.isUndefined()) { 231 result.unionMemberWithDefaultValue = convert<IDLUnion<IDLEnumeration<TestStandaloneDictionary::EnumInStandaloneDictionaryFile>, IDLDouble>>(lexicalGlobalObject, unionMemberWithDefaultValueValue); 232 RETURN_IF_EXCEPTION(throwScope, { }); 233 } else 234 result.unionMemberWithDefaultValue = TestStandaloneDictionary::EnumInStandaloneDictionaryFile::EnumValue1; 208 235 return result; 209 236 } … … 227 254 result->putDirect(vm, JSC::Identifier::fromString(vm, "enumMember"), enumMemberValue); 228 255 } 256 auto nullableUnionWithNullDefaultValueValue = toJS<IDLNullable<IDLUnion<IDLDOMString, IDLBoolean>>>(lexicalGlobalObject, globalObject, dictionary.nullableUnionWithNullDefaultValue); 257 result->putDirect(vm, JSC::Identifier::fromString(vm, "nullableUnionWithNullDefaultValue"), nullableUnionWithNullDefaultValueValue); 229 258 #if ENABLE(Conditional13) || ENABLE(Conditional14) 230 259 if (!IDLBoolean::isNullValue(dictionary.partialBooleanMember)) { … … 279 308 result->putDirect(vm, JSC::Identifier::fromString(vm, "stringMember"), stringMemberValue); 280 309 } 310 auto unionMemberWithDefaultValueValue = toJS<IDLUnion<IDLEnumeration<TestStandaloneDictionary::EnumInStandaloneDictionaryFile>, IDLDouble>>(lexicalGlobalObject, globalObject, dictionary.unionMemberWithDefaultValue); 311 result->putDirect(vm, JSC::Identifier::fromString(vm, "unionMemberWithDefaultValue"), unionMemberWithDefaultValueValue); 281 312 return result; 282 313 } -
trunk/Source/WebCore/bindings/scripts/test/TestStandaloneDictionary.idl
r248275 r264201 39 39 TestEnumInStandaloneDictionaryFile enumMember; 40 40 VoidCallback callbackMember; 41 (TestEnumInStandaloneDictionaryFile or double) unionMemberWithDefaultValue = "enumValue1"; 42 (DOMString or boolean)? nullableUnionWithNullDefaultValue = null; 41 43 };
Note:
See TracChangeset
for help on using the changeset viewer.