Skip to content

Commit 5e02fd1

Browse files
committed
Remove LegacyNativeDictionaryRequiredInterfaceNullability infrastructure
https://bugs.webkit.org/show_bug.cgi?id=305410 rdar://168520792 Reviewed by Chris Dumez. It's no longer used by any code. Canonical link: https://commits.webkit.org/311349@main
1 parent 34da51f commit 5e02fd1

6 files changed

Lines changed: 6 additions & 528 deletions

Source/WebCore/bindings/scripts/CodeGeneratorJS.pm

Lines changed: 6 additions & 276 deletions
Original file line numberDiff line numberDiff line change
@@ -3028,147 +3028,6 @@ sub GenerateConvertDictionary
30283028
return $result
30293029
}
30303030

3031-
sub GenerateConvertDictionaryForLegacyNativeDictionaryRequiredInterfaceNullability
3032-
{
3033-
my ($dictionary, $dictionaries, $className, $interface) = @_;
3034-
3035-
my $name = $dictionary->type->name;
3036-
my $typeScope = $interface || $dictionary;
3037-
3038-
my $result = "";
3039-
3040-
# https://webidl.spec.whatwg.org/#es-dictionary
3041-
$result .= "template<> ConversionResult<IDLDictionary<${className}>> convertDictionary<$className>(JSGlobalObject& lexicalGlobalObject, JSValue value)\n";
3042-
$result .= "{\n";
3043-
$result .= " SUPPRESS_UNCOUNTED_LOCAL auto& vm = JSC::getVM(&lexicalGlobalObject);\n";
3044-
$result .= " auto throwScope = DECLARE_THROW_SCOPE(vm);\n";
3045-
$result .= " bool isNullOrUndefined = value.isUndefinedOrNull();\n";
3046-
$result .= " auto* object = isNullOrUndefined ? nullptr : value.getObject();\n";
3047-
3048-
# 1. If Type(V) is not Undefined, Null or Object, then throw a TypeError.
3049-
$result .= " if (!isNullOrUndefined && !object) [[unlikely]] {\n";
3050-
$result .= " throwTypeError(&lexicalGlobalObject, throwScope);\n";
3051-
$result .= " return ConversionResultException { };\n";
3052-
$result .= " }\n";
3053-
3054-
# 2. Let dict be an empty dictionary value of type D; every dictionary member is initially considered to be not present.
3055-
$result .= " $className result;\n";
3056-
3057-
# 3. Let dictionaries be a list consisting of D and all of D’s inherited dictionaries, in order from least to most derived.
3058-
#
3059-
# Done above so it can be shared with the `convertDictionaryToJS` implementation.
3060-
3061-
# 4. For each dictionary dictionary in dictionaries, in order:
3062-
foreach my $dictionary (@$dictionaries) {
3063-
# For each dictionary member member declared on dictionary, in lexicographical order:
3064-
my @sortedMembers = sort { $a->name cmp $b->name } @{$dictionary->members};
3065-
foreach my $member (@sortedMembers) {
3066-
$member->default("undefined") if $member->type->name eq "any" and !defined($member->default); # Use undefined as default value for member of type 'any' unless specified otherwise.
3067-
my $conditional = $member->extendedAttributes->{Conditional};
3068-
3069-
my $type = $member->type;
3070-
AddToImplIncludesForIDLType($type, $conditional);
3071-
3072-
if ($conditional) {
3073-
my $conditionalString = $codeGenerator->GenerateConditionalStringFromAttributeValue($conditional);
3074-
$result .= "#if ${conditionalString}\n";
3075-
}
3076-
3077-
my $needsRuntimeCheck = NeedsRuntimeCheck($dictionary, $member);
3078-
my $indent = "";
3079-
if ($needsRuntimeCheck) {
3080-
my $runtimeEnableConditionalString = GenerateRuntimeEnableConditionalString($dictionary, $member, "&lexicalGlobalObject");
3081-
$result .= " if (${runtimeEnableConditionalString}) {\n";
3082-
$indent = " ";
3083-
}
3084-
3085-
# 4.1. Let key be the identifier of member.
3086-
my $key = $member->name;
3087-
my $implementedAsKey = $member->extendedAttributes->{ImplementedAs} || $key;
3088-
3089-
# 4.2. Let value be an ECMAScript value, depending on Type(V):
3090-
$result .= "${indent} JSValue ${key}Value;\n";
3091-
$result .= "${indent} if (isNullOrUndefined)\n";
3092-
$result .= "${indent} ${key}Value = jsUndefined();\n";
3093-
$result .= "${indent} else {\n";
3094-
$result .= "${indent} ${key}Value = object->get(&lexicalGlobalObject, Identifier::fromString(vm, \"${key}\"_s));\n";
3095-
$result .= "${indent} RETURN_IF_EXCEPTION(throwScope, ConversionResultException { });\n";
3096-
$result .= "${indent} }\n";
3097-
3098-
my $IDLType = GetIDLType($typeScope, $type);
3099-
3100-
# 4.3. If value is not undefined, then:
3101-
# 4.4. Otherwise, if value is undefined but the dictionary member has a default value, then:
3102-
# 4.5. Otherwise, if value is undefined and the dictionary member is a required dictionary member, then throw a TypeError.
3103-
3104-
if ($member->isRequired) {
3105-
my $conversion = JSValueToNative($typeScope, $member, "${key}Value", $conditional, "&lexicalGlobalObject", "lexicalGlobalObject", "", "*jsCast<JSDOMGlobalObject*>(&lexicalGlobalObject)", undef, undef, undef, undef);
3106-
3107-
$result .= "${indent} if (${key}Value.isUndefined()) {\n";
3108-
$result .= "${indent} throwRequiredMemberTypeError(lexicalGlobalObject, throwScope, \"". $member->name ."\"_s, \"$name\"_s, \"". GetTypeNameForDisplayInException($type) ."\"_s);\n";
3109-
$result .= "${indent} return ConversionResultException { };\n";
3110-
$result .= "${indent} }\n";
3111-
3112-
$result .= "${indent} auto ${implementedAsKey}ConversionResult = ${conversion};\n";
3113-
$result .= "${indent} if (${implementedAsKey}ConversionResult.hasException(throwScope)) [[unlikely]]\n";
3114-
$result .= "${indent} return ConversionResultException { };\n";
3115-
$result .= "${indent} result.$implementedAsKey = ${implementedAsKey}ConversionResult.releaseReturnValue();\n";
3116-
} elsif (defined $member->default) {
3117-
if ($member->extendedAttributes->{PermissiveInvalidValue} && $codeGenerator->IsEnumType($type)) {
3118-
my ($enumClassName, $defaultValue) = GetPermissiveEnumDefault($typeScope, $member);
3119-
$result .= "${indent} if (${key}Value.isUndefined())\n";
3120-
$result .= "${indent} result.$implementedAsKey = ${defaultValue};\n";
3121-
$result .= "${indent} else {\n";
3122-
$result .= "${indent} auto ${implementedAsKey}ParseResult = parseEnumeration<${enumClassName}>(lexicalGlobalObject, ${key}Value);\n";
3123-
$result .= "${indent} RETURN_IF_EXCEPTION(throwScope, ConversionResultException { });\n";
3124-
$result .= "${indent} result.$implementedAsKey = ${implementedAsKey}ParseResult.value_or(${defaultValue});\n";
3125-
$result .= "${indent} }\n";
3126-
} else {
3127-
my $defaultValueFunctor = GetDictionaryMemberDefaultValueFunctor($typeScope, $member);
3128-
my $optional = !WillConvertUndefinedToDefaultParameterValue($member->type, $member->default);
3129-
my $conversion = JSValueToNative($typeScope, $member, "${key}Value", $conditional, "&lexicalGlobalObject", "lexicalGlobalObject", "", "*jsCast<JSDOMGlobalObject*>(&lexicalGlobalObject)", undef, undef, $optional, $defaultValueFunctor);
3130-
3131-
$result .= "${indent} auto ${implementedAsKey}ConversionResult = ${conversion};\n";
3132-
$result .= "${indent} if (${implementedAsKey}ConversionResult.hasException(throwScope)) [[unlikely]]\n";
3133-
$result .= "${indent} return ConversionResultException { };\n";
3134-
$result .= "${indent} result.$implementedAsKey = ${implementedAsKey}ConversionResult.releaseReturnValue();\n";
3135-
}
3136-
} else {
3137-
if ($member->extendedAttributes->{PermissiveInvalidValue} && $codeGenerator->IsEnumType($type)) {
3138-
my ($enumClassName, $defaultValue) = GetPermissiveEnumDefault($typeScope, $member);
3139-
$result .= "${indent} if (!${key}Value.isUndefined()) {\n";
3140-
$result .= "${indent} auto ${implementedAsKey}ParseResult = parseEnumeration<${enumClassName}>(lexicalGlobalObject, ${key}Value);\n";
3141-
$result .= "${indent} RETURN_IF_EXCEPTION(throwScope, ConversionResultException { });\n";
3142-
$result .= "${indent} if (${implementedAsKey}ParseResult)\n";
3143-
$result .= "${indent} result.$implementedAsKey = *${implementedAsKey}ParseResult;\n";
3144-
$result .= "${indent} }\n";
3145-
} else {
3146-
my $conversion = JSValueToNative($typeScope, $member, "${key}Value", $conditional, "&lexicalGlobalObject", "lexicalGlobalObject", "", "*jsCast<JSDOMGlobalObject*>(&lexicalGlobalObject)", undef, undef, undef, undef);
3147-
3148-
$result .= "${indent} if (!${key}Value.isUndefined()) {\n";
3149-
$result .= "${indent} auto ${implementedAsKey}ConversionResult = ${conversion};\n";
3150-
$result .= "${indent} if (${implementedAsKey}ConversionResult.hasException(throwScope)) [[unlikely]]\n";
3151-
$result .= "${indent} return ConversionResultException { };\n";
3152-
$result .= "${indent} result.$implementedAsKey = ${implementedAsKey}ConversionResult.releaseReturnValue();\n";
3153-
$result .= "${indent} }\n";
3154-
}
3155-
}
3156-
3157-
if ($needsRuntimeCheck) {
3158-
$result .= " }\n";
3159-
}
3160-
3161-
$result .= "#endif\n" if $conditional;
3162-
}
3163-
}
3164-
3165-
# 5. Return dict.
3166-
$result .= " return result;\n";
3167-
$result .= "}\n\n";
3168-
3169-
return $result
3170-
}
3171-
31723031
sub GenerateConvertDictionaryToJS
31733032
{
31743033
my ($dictionary, $dictionaries, $className, $interface) = @_;
@@ -3260,97 +3119,6 @@ sub GenerateConvertDictionaryToJS
32603119
return $result
32613120
}
32623121

3263-
sub GenerateConvertDictionaryToJSForLegacyNativeDictionaryRequiredInterfaceNullability
3264-
{
3265-
my ($dictionary, $dictionaries, $className, $interface) = @_;
3266-
3267-
AddToImplIncludes("JSDOMGlobalObject.h");
3268-
AddToImplIncludes("<JavaScriptCore/ObjectConstructor.h>");
3269-
3270-
my $hasUnconditionalMember = 0;
3271-
my $typeScope = $interface || $dictionary;
3272-
3273-
my $result = "";
3274-
3275-
$result .= "JSC::JSObject* convertDictionaryToJS(JSC::JSGlobalObject& lexicalGlobalObject, JSDOMGlobalObject& globalObject, const ${className}& dictionary)\n";
3276-
$result .= "{\n";
3277-
$result .= " SUPPRESS_UNCOUNTED_LOCAL auto& vm = JSC::getVM(&lexicalGlobalObject);\n";
3278-
$result .= " auto throwScope = DECLARE_THROW_SCOPE(vm);\n\n";
3279-
3280-
# 1. Let O be ! ObjectCreate(%ObjectPrototype%).
3281-
$result .= " auto result = constructEmptyObject(&lexicalGlobalObject, globalObject.objectPrototype());\n\n";
3282-
3283-
# 2. Let dictionaries be a list consisting of D and all of D’s inherited dictionaries,
3284-
# in order from least to most derived.
3285-
#
3286-
# Done above so it can be shared with the `convertDictionary` implementation.
3287-
3288-
# 3. For each dictionary dictionary in dictionaries, in order:
3289-
foreach my $dictionary (@$dictionaries) {
3290-
# 3.1. For each dictionary member member declared on dictionary, in lexicographical order:
3291-
my @sortedMembers = sort { $a->name cmp $b->name } @{$dictionary->members};
3292-
foreach my $member (@sortedMembers) {
3293-
my $key = $member->name;
3294-
my $implementedAsKey = $member->extendedAttributes->{ImplementedAs} || $key;
3295-
my $valueExpression = "dictionary.${implementedAsKey}";
3296-
3297-
my $conditional = $member->extendedAttributes->{Conditional};
3298-
if ($conditional) {
3299-
my $conditionalString = $codeGenerator->GenerateConditionalStringFromAttributeValue($conditional);
3300-
$result .= "#if ${conditionalString}\n";
3301-
} else {
3302-
$hasUnconditionalMember = 1;
3303-
}
3304-
3305-
# 1. Let key be the identifier of member.
3306-
# 2. If the dictionary member named key is present in V, then:
3307-
# 1. Let idlValue be the value of member on V.
3308-
# 2. Let value be the result of converting idlValue to an ECMAScript value.
3309-
# 3. Perform ! CreateDataProperty(O, key, value).
3310-
3311-
my $needsRuntimeCheck = NeedsRuntimeCheck($dictionary, $member);
3312-
my $indent = "";
3313-
if ($needsRuntimeCheck) {
3314-
my $runtimeEnableConditionalString = GenerateRuntimeEnableConditionalString($dictionary, $member, "&globalObject");
3315-
$result .= " if (${runtimeEnableConditionalString}) {\n";
3316-
$indent = " ";
3317-
}
3318-
3319-
if (!$member->isRequired && not defined $member->default) {
3320-
my $IDLType = GetIDLType($typeScope, $member->type);
3321-
my $conversionExpression = NativeToJSValueUsingReferences($member, $typeScope, "${IDLType}::extractValueFromNullable(${valueExpression})", "globalObject");
3322-
3323-
$result .= "${indent} if (!${IDLType}::isNullValue(${valueExpression})) {\n";
3324-
$result .= "${indent} auto ${key}Value = ${conversionExpression};\n";
3325-
$result .= "${indent} RETURN_IF_EXCEPTION(throwScope, { });\n";
3326-
$result .= "${indent} result->putDirect(vm, JSC::Identifier::fromString(vm, \"${key}\"_s), ${key}Value);\n";
3327-
$result .= "${indent} }\n";
3328-
} else {
3329-
my $conversionExpression = NativeToJSValueUsingReferencesWrappingInterfacesAndBufferSourcesInNullable($member, $typeScope, $valueExpression, "globalObject");
3330-
3331-
$result .= "${indent} auto ${key}Value = ${conversionExpression};\n";
3332-
$result .= "${indent} RETURN_IF_EXCEPTION(throwScope, { });\n";
3333-
$result .= "${indent} result->putDirect(vm, JSC::Identifier::fromString(vm, \"${key}\"_s), ${key}Value);\n";
3334-
}
3335-
if ($needsRuntimeCheck) {
3336-
$result .= " }\n";
3337-
}
3338-
3339-
$result .= "#endif\n" if $conditional;
3340-
}
3341-
}
3342-
3343-
if (!$hasUnconditionalMember) {
3344-
$result .= " UNUSED_PARAM(dictionary);\n";
3345-
$result .= " UNUSED_VARIABLE(throwScope);\n\n";
3346-
}
3347-
3348-
$result .= " return result;\n";
3349-
$result .= "}\n\n";
3350-
3351-
return $result
3352-
}
3353-
33543122
sub GenerateDictionaryImplementationContent
33553123
{
33563124
my ($dictionary, $className, $interface) = @_;
@@ -3376,25 +3144,11 @@ sub GenerateDictionaryImplementationContent
33763144
$parentType = $parentDictionary->parentType;
33773145
}
33783146

3379-
if (!$dictionary->extendedAttributes->{LegacyNativeDictionaryRequiredInterfaceNullability}) {
3380-
$result .= GenerateDictionaryChecks($dictionary, \@dictionaries, $className, $interface);
3381-
}
3147+
$result .= GenerateDictionaryChecks($dictionary, \@dictionaries, $className, $interface);
33823148

3383-
if (ShouldGenerateConvertDictionary($dictionary)) {
3384-
if ($dictionary->extendedAttributes->{LegacyNativeDictionaryRequiredInterfaceNullability}) {
3385-
$result .= GenerateConvertDictionaryForLegacyNativeDictionaryRequiredInterfaceNullability($dictionary, \@dictionaries, $className, $interface);
3386-
} else {
3387-
$result .= GenerateConvertDictionary($dictionary, \@dictionaries, $className, $interface);
3388-
}
3389-
}
3149+
$result .= GenerateConvertDictionary($dictionary, \@dictionaries, $className, $interface) if ShouldGenerateConvertDictionary($dictionary);
33903150

3391-
if (ShouldGenerateConvertDictionaryToJS($dictionary)) {
3392-
if ($dictionary->extendedAttributes->{LegacyNativeDictionaryRequiredInterfaceNullability}) {
3393-
$result .= GenerateConvertDictionaryToJSForLegacyNativeDictionaryRequiredInterfaceNullability($dictionary, \@dictionaries, $className, $interface);
3394-
} else {
3395-
$result .= GenerateConvertDictionaryToJS($dictionary, \@dictionaries, $className, $interface);
3396-
}
3397-
}
3151+
$result .= GenerateConvertDictionaryToJS($dictionary, \@dictionaries, $className, $interface) if ShouldGenerateConvertDictionaryToJS($dictionary);
33983152

33993153
$result .= "#endif\n\n" if $conditional;
34003154

@@ -8335,38 +8089,19 @@ sub NativeToJSValueDOMConvertNeedsGlobalObject
83358089
return 0;
83368090
}
83378091

8338-
sub NativeToJSValueDOMConvertNeedsNullableWrapper
8339-
{
8340-
my ($type) = @_;
8341-
8342-
return 0 if $type->isNullable;
8343-
return 1 if $codeGenerator->IsInterfaceType($type);
8344-
return 1 if $codeGenerator->IsBufferSourceType($type);
8345-
return 0;
8346-
}
8347-
8348-
# FIXME: This is needed to work around dictionaries storing non-nullable interfaces using RefPtr rather than Ref<>.
8349-
# See "Support using Ref for interfaces and buffer source types in IDL dictionaries (https://bugs.webkit.org/show_bug.cgi?id=305410)".
8350-
sub NativeToJSValueUsingReferencesWrappingInterfacesAndBufferSourcesInNullable
8351-
{
8352-
my ($context, $interface, $value, $globalObjectReference) = @_;
8353-
8354-
return NativeToJSValue($context, $interface, $value, "lexicalGlobalObject", $globalObjectReference, 1);
8355-
}
8356-
83578092
sub NativeToJSValueUsingReferences
83588093
{
83598094
my ($context, $interface, $value, $globalObjectReference) = @_;
83608095

8361-
return NativeToJSValue($context, $interface, $value, "lexicalGlobalObject", $globalObjectReference, 0);
8096+
return NativeToJSValue($context, $interface, $value, "lexicalGlobalObject", $globalObjectReference);
83628097
}
83638098

83648099
# FIXME: We should remove NativeToJSValueUsingPointers and combine NativeToJSValueUsingReferences and NativeToJSValue
83658100
sub NativeToJSValueUsingPointers
83668101
{
83678102
my ($context, $interface, $value, $globalObjectReference) = @_;
83688103

8369-
return NativeToJSValue($context, $interface, $value, "*lexicalGlobalObject", $globalObjectReference, 0);
8104+
return NativeToJSValue($context, $interface, $value, "*lexicalGlobalObject", $globalObjectReference);
83708105
}
83718106

83728107
sub IsValidContextForNativeToJSValue
@@ -8384,7 +8119,7 @@ sub NativeToJSValueMayThrow
83848119

83858120
sub NativeToJSValue
83868121
{
8387-
my ($context, $interface, $value, $lexicalGlobalObjectReference, $globalObjectReference, $wrapInterfacesAndArrayBufferSourcesInNullable) = @_;
8122+
my ($context, $interface, $value, $lexicalGlobalObjectReference, $globalObjectReference) = @_;
83888123

83898124
assert("Invalid context type") if !IsValidContextForNativeToJSValue($context);
83908125

@@ -8417,11 +8152,6 @@ sub NativeToJSValue
84178152

84188153
my $IDLType = GetIDLType($interface, $type);
84198154

8420-
# FIXME: This is a hack used by the dictionary code while storing interfaces and buffer source types via Ref<> is not supported. Once that is supported, this should be removed.
8421-
if ($wrapInterfacesAndArrayBufferSourcesInNullable and NativeToJSValueDOMConvertNeedsNullableWrapper($type)) {
8422-
$IDLType = "IDLNullable<" . $IDLType . ">";
8423-
}
8424-
84258155
# FIXME: Not all promise types require the functor wrapping (some attribute getters actually return a value)
84268156
# but wrapping is a no-op, so fixing this would purely be a stylistic / compile time fix.
84278157
my $needsFunctorWrapping = $type->name eq "undefined" || $codeGenerator->IsPromiseType($type) || $context->extendedAttributes->{ReturnsPromisePair};

Source/WebCore/bindings/scripts/IDLAttributes.json

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -379,9 +379,6 @@
379379
},
380380
"unsupported": true
381381
},
382-
"LegacyNativeDictionaryRequiredInterfaceNullability": {
383-
"contextsAllowed": ["dictionary"]
384-
},
385382
"LegacyNoInterfaceObject": {
386383
"contextsAllowed": ["interface"],
387384
"standard": {

0 commit comments

Comments
 (0)