Modified: trunk/Source/WebCore/bindings/scripts/CodeGeneratorJS.pm (200554 => 200555)
--- trunk/Source/WebCore/bindings/scripts/CodeGeneratorJS.pm 2016-05-08 15:22:36 UTC (rev 200554)
+++ trunk/Source/WebCore/bindings/scripts/CodeGeneratorJS.pm 2016-05-08 16:54:09 UTC (rev 200555)
@@ -958,8 +958,27 @@
# FIXME: A little ugly to have this be a side effect instead of a return value.
AddToImplIncludes("JSDOMConvert.h");
+ my $defaultValues = "";
+ my $comma = "";
+ foreach my $member (@{$dictionary->members}) {
+ if (!$member->isOptional) {
+ $defaultValues = "";
+ last;
+ }
+ $defaultValues .= $comma . (defined $member->default ? $member->default : "Nullopt");
+ $comma = ", ";
+ }
+
$result .= "template<> $className convert<$className>(ExecState& state, JSValue value)\n";
$result .= "{\n";
+ $result .= " if (value.isUndefinedOrNull())\n" if $defaultValues;
+ $result .= " return { " . $defaultValues . " };\n" if $defaultValues;
+ $result .= " auto* object = value.getObject();\n";
+ $result .= " if (UNLIKELY(!object || object->type() == RegExpObjectType)) {\n";
+ $result .= " throwTypeError(&state);\n";
+ $result .= " return { };\n";
+ $result .= " }\n";
+
my $needExceptionCheck = 0;
foreach my $member (@{$dictionary->members}) {
if ($needExceptionCheck) {
@@ -970,16 +989,18 @@
my $function = $member->isOptional ? "convertOptional" : "convert";
my $defaultValueWithLeadingComma = $member->isOptional && defined $member->default ? ", " . $member->default : "";
$result .= " auto " . $member->name . " = " . $function . "<" . GetNativeTypeFromSignature($interface, $member) . ">"
- . "(state, propertyValue(state, value, \"" . $member->name . "\")" . $defaultValueWithLeadingComma . ");\n";
+ . "(state, object->get(&state, Identifier::fromString(&state, \"" . $member->name . "\"))" . $defaultValueWithLeadingComma . ");\n";
$needExceptionCheck = 1;
}
- $result .= " return { ";
- my $comma = "";
+
+ my $arguments = "";
+ $comma = "";
foreach my $member (@{$dictionary->members}) {
- $result .= $comma . "WTFMove(" . $member->name . ")";
+ $arguments .= $comma . "WTFMove(" . $member->name . ")";
$comma = ", ";
}
- $result .= " };\n";
+
+ $result .= " return { " . $arguments . " };\n";
$result .= "}\n\n";
$result .= "#endif\n\n" if $conditionalString;
@@ -3592,90 +3613,90 @@
$implIncludes{"ExceptionCode.h"} = 1;
$implIncludes{"JSDOMBinding.h"} = 1;
- my $argsIndex = 0;
+ my $argumentIndex = 0;
foreach my $parameter (@{$function->parameters}) {
- my $argType = $parameter->type;
+ my $type = $parameter->type;
- die "Optional parameters of non-nullable wrapper types are not supported" if $parameter->isOptional && !$parameter->isNullable && $codeGenerator->IsWrapperType($argType);
+ die "Optional parameters of non-nullable wrapper types are not supported" if $parameter->isOptional && !$parameter->isNullable && $codeGenerator->IsWrapperType($type);
if ($parameter->isOptional && !defined($parameter->default)) {
# As per Web IDL, optional dictionary parameters are always considered to have a default value of an empty dictionary, unless otherwise specified.
- $parameter->default("[]") if $argType eq "Dictionary";
-
+ $parameter->default("[]") if $type eq "Dictionary" or $codeGenerator->IsDictionaryType($type);
+
# We use undefined as default value for optional parameters of type 'any' unless specified otherwise.
- $parameter->default("undefined") if $argType eq "any";
+ $parameter->default("undefined") if $type eq "any";
# We use the null string as default value for parameters of type DOMString unless specified otherwise.
- $parameter->default("null") if $argType eq "DOMString";
+ $parameter->default("null") if $type eq "DOMString";
# As per Web IDL, passing undefined for a nullable parameter is treated as null. Therefore, use null as
# default value for nullable parameters unless otherwise specified.
$parameter->default("null") if $parameter->isNullable;
# For callback parameters, the generated bindings treat undefined as null, so use null as implicit default value.
- $parameter->default("null") if $codeGenerator->IsCallbackInterface($argType);
+ $parameter->default("null") if $codeGenerator->IsCallbackInterface($type);
}
my $name = $parameter->name;
my $value = $name;
- if ($codeGenerator->IsCallbackInterface($argType)) {
- my $callbackClassName = GetCallbackClassName($argType);
+ if ($codeGenerator->IsCallbackInterface($type)) {
+ my $callbackClassName = GetCallbackClassName($type);
$implIncludes{"$callbackClassName.h"} = 1;
if ($parameter->isOptional) {
- push(@$outputArray, " RefPtr<$argType> $name;\n");
- push(@$outputArray, " if (!state->argument($argsIndex).isUndefinedOrNull()) {\n");
- if ($codeGenerator->IsFunctionOnlyCallbackInterface($argType)) {
- push(@$outputArray, " if (!state->uncheckedArgument($argsIndex).isFunction())\n");
+ push(@$outputArray, " RefPtr<$type> $name;\n");
+ push(@$outputArray, " if (!state->argument($argumentIndex).isUndefinedOrNull()) {\n");
+ if ($codeGenerator->IsFunctionOnlyCallbackInterface($type)) {
+ push(@$outputArray, " if (!state->uncheckedArgument($argumentIndex).isFunction())\n");
} else {
- push(@$outputArray, " if (!state->uncheckedArgument($argsIndex).isObject())\n");
+ push(@$outputArray, " if (!state->uncheckedArgument($argumentIndex).isObject())\n");
}
- push(@$outputArray, " return throwArgumentMustBeFunctionError(*state, $argsIndex, \"$name\", \"$interfaceName\", $quotedFunctionName);\n");
+ push(@$outputArray, " return throwArgumentMustBeFunctionError(*state, $argumentIndex, \"$name\", \"$interfaceName\", $quotedFunctionName);\n");
if ($function->isStatic) {
AddToImplIncludes("CallbackFunction.h");
- push(@$outputArray, " $name = createFunctionOnlyCallback<${callbackClassName}>(state, jsCast<JSDOMGlobalObject*>(state->lexicalGlobalObject()), state->uncheckedArgument($argsIndex));\n");
+ push(@$outputArray, " $name = createFunctionOnlyCallback<${callbackClassName}>(state, jsCast<JSDOMGlobalObject*>(state->lexicalGlobalObject()), state->uncheckedArgument($argumentIndex));\n");
} else {
- push(@$outputArray, " $name = ${callbackClassName}::create(asObject(state->uncheckedArgument($argsIndex)), castedThis->globalObject());\n");
+ push(@$outputArray, " $name = ${callbackClassName}::create(asObject(state->uncheckedArgument($argumentIndex)), castedThis->globalObject());\n");
}
push(@$outputArray, " }\n");
} else {
- if ($codeGenerator->IsFunctionOnlyCallbackInterface($argType)) {
- push(@$outputArray, " if (UNLIKELY(!state->argument($argsIndex).isFunction()))\n");
+ if ($codeGenerator->IsFunctionOnlyCallbackInterface($type)) {
+ push(@$outputArray, " if (UNLIKELY(!state->argument($argumentIndex).isFunction()))\n");
} else {
- push(@$outputArray, " if (UNLIKELY(!state->argument($argsIndex).isObject()))\n");
+ push(@$outputArray, " if (UNLIKELY(!state->argument($argumentIndex).isObject()))\n");
}
- push(@$outputArray, " return throwArgumentMustBeFunctionError(*state, $argsIndex, \"$name\", \"$interfaceName\", $quotedFunctionName);\n");
+ push(@$outputArray, " return throwArgumentMustBeFunctionError(*state, $argumentIndex, \"$name\", \"$interfaceName\", $quotedFunctionName);\n");
if ($function->isStatic) {
AddToImplIncludes("CallbackFunction.h");
- push(@$outputArray, " RefPtr<$argType> $name = createFunctionOnlyCallback<${callbackClassName}>(state, jsCast<JSDOMGlobalObject*>(state->lexicalGlobalObject()), state->uncheckedArgument($argsIndex));\n");
+ push(@$outputArray, " RefPtr<$type> $name = createFunctionOnlyCallback<${callbackClassName}>(state, jsCast<JSDOMGlobalObject*>(state->lexicalGlobalObject()), state->uncheckedArgument($argumentIndex));\n");
} else {
- push(@$outputArray, " RefPtr<$argType> $name = ${callbackClassName}::create(asObject(state->uncheckedArgument($argsIndex)), castedThis->globalObject());\n");
+ push(@$outputArray, " RefPtr<$type> $name = ${callbackClassName}::create(asObject(state->uncheckedArgument($argumentIndex)), castedThis->globalObject());\n");
}
}
$value = "WTFMove($name)";
} elsif ($parameter->isVariadic) {
my $nativeElementType;
- if ($argType eq "DOMString") {
+ if ($type eq "DOMString") {
$nativeElementType = "String";
} else {
- $nativeElementType = GetNativeType($interface, $argType);
+ $nativeElementType = GetNativeType($interface, $type);
}
- if (!IsNativeType($argType)) {
+ if (!IsNativeType($type)) {
push(@$outputArray, " Vector<$nativeElementType> $name;\n");
- push(@$outputArray, " for (unsigned i = $argsIndex, count = state->argumentCount(); i < count; ++i) {\n");
- push(@$outputArray, " if (!state->uncheckedArgument(i).inherits(JS${argType}::info()))\n");
- push(@$outputArray, " return throwArgumentTypeError(*state, i, \"$name\", \"$interfaceName\", $quotedFunctionName, \"$argType\");\n");
- push(@$outputArray, " $name.append(JS${argType}::toWrapped(state->uncheckedArgument(i)));\n");
+ push(@$outputArray, " for (unsigned i = $argumentIndex, count = state->argumentCount(); i < count; ++i) {\n");
+ push(@$outputArray, " if (!state->uncheckedArgument(i).inherits(JS${type}::info()))\n");
+ push(@$outputArray, " return throwArgumentTypeError(*state, i, \"$name\", \"$interfaceName\", $quotedFunctionName, \"$type\");\n");
+ push(@$outputArray, " $name.append(JS${type}::toWrapped(state->uncheckedArgument(i)));\n");
push(@$outputArray, " }\n")
} else {
- push(@$outputArray, " Vector<$nativeElementType> $name = toNativeArguments<$nativeElementType>(state, $argsIndex);\n");
+ push(@$outputArray, " Vector<$nativeElementType> $name = toNativeArguments<$nativeElementType>(state, $argumentIndex);\n");
# Check if the type conversion succeeded.
push(@$outputArray, " if (UNLIKELY(state->hadException()))\n");
push(@$outputArray, " return JSValue::encode(jsUndefined());\n");
}
- } elsif ($codeGenerator->IsEnumType($argType)) {
- my $className = GetEnumerationClassName($interface, $argType);
+ } elsif ($codeGenerator->IsEnumType($type)) {
+ my $className = GetEnumerationClassName($interface, $type);
$implIncludes{"<runtime/Error.h>"} = 1;
@@ -3690,7 +3711,7 @@
$defineOptionalValue = $name;
}
- push(@$outputArray, " auto ${name}Value = state->argument($argsIndex);\n");
+ push(@$outputArray, " auto ${name}Value = state->argument($argumentIndex);\n");
push(@$outputArray, " $nativeType $name;\n");
if ($parameter->isOptional) {
@@ -3707,7 +3728,7 @@
push(@$outputArray, "$indent if (UNLIKELY(state->hadException()))\n");
push(@$outputArray, "$indent return JSValue::encode(jsUndefined());\n");
push(@$outputArray, "$indent if (UNLIKELY(!$optionalValue))\n");
- push(@$outputArray, "$indent return throwArgumentMustBeEnumError(*state, $argsIndex, \"$name\", \"$interfaceName\", $quotedFunctionName, expectedEnumerationValues<$className>());\n");
+ push(@$outputArray, "$indent return throwArgumentMustBeEnumError(*state, $argumentIndex, \"$name\", \"$interfaceName\", $quotedFunctionName, expectedEnumerationValues<$className>());\n");
push(@$outputArray, "$indent $name = optionalValue.value();\n") if $optionalValue ne $name;
push(@$outputArray, " }\n") if $indent ne "";
@@ -3720,16 +3741,16 @@
if ($function->signature->extendedAttributes->{"StrictTypeChecking"}) {
$implIncludes{"<runtime/Error.h>"} = 1;
- my $argValue = "state->argument($argsIndex)";
- if ($codeGenerator->IsWrapperType($argType)) {
- push(@$outputArray, " if (UNLIKELY(!${argValue}.isUndefinedOrNull() && !${argValue}.inherits(JS${argType}::info())))\n");
- push(@$outputArray, " return throwArgumentTypeError(*state, $argsIndex, \"$name\", \"$interfaceName\", $quotedFunctionName, \"$argType\");\n");
+ my $argValue = "state->argument($argumentIndex)";
+ if ($codeGenerator->IsWrapperType($type)) {
+ push(@$outputArray, " if (UNLIKELY(!${argValue}.isUndefinedOrNull() && !${argValue}.inherits(JS${type}::info())))\n");
+ push(@$outputArray, " return throwArgumentTypeError(*state, $argumentIndex, \"$name\", \"$interfaceName\", $quotedFunctionName, \"$type\");\n");
}
}
if ($parameter->extendedAttributes->{"RequiresExistingAtomicString"}) {
# FIXME: This could be made slightly more efficient if we added an AtomicString(RefPtr<AtomicStringImpl>&&) constructor and removed the call to get() here.
- push(@$outputArray, " AtomicString $name = state->argument($argsIndex).toString(state)->toExistingAtomicString(state).get();\n");
+ push(@$outputArray, " AtomicString $name = state->argument($argumentIndex).toString(state)->toExistingAtomicString(state).get();\n");
push(@$outputArray, " if ($name.isNull())\n");
push(@$outputArray, " return JSValue::encode(jsNull());\n");
push(@$outputArray, " if (UNLIKELY(state->hadException()))\n");
@@ -3739,11 +3760,11 @@
my $inner;
my $nativeType = GetNativeTypeFromSignature($interface, $parameter);
- if ($parameter->isOptional && defined($parameter->default) && !WillConvertUndefinedToDefaultParameterValue($parameter->type, $parameter->default)) {
+ if ($parameter->isOptional && defined($parameter->default) && !WillConvertUndefinedToDefaultParameterValue($type, $parameter->default)) {
my $defaultValue = $parameter->default;
# String-related optimizations.
- if ($parameter->type eq "DOMString") {
+ if ($type eq "DOMString") {
my $useAtomicString = $parameter->extendedAttributes->{"AtomicString"};
if ($defaultValue eq "null") {
$defaultValue = $useAtomicString ? "nullAtom" : "String()";
@@ -3759,16 +3780,15 @@
$defaultValue = "JSValue::JSUndefined" if $defaultValue eq "undefined";
}
- $outer = "state->argument($argsIndex).isUndefined() ? $defaultValue : ";
- $inner = "state->uncheckedArgument($argsIndex)";
+ $outer = "state->argument($argumentIndex).isUndefined() ? $defaultValue : ";
+ $inner = "state->uncheckedArgument($argumentIndex)";
} elsif ($parameter->isOptional && !defined($parameter->default)) {
- # Use WTF::Optional<>() for optional parameters that are missing or undefined and that do not have
- # a default value in the IDL.
- $outer = "state->argument($argsIndex).isUndefined() ? Optional<$nativeType>() : ";
- $inner = "state->uncheckedArgument($argsIndex)";
+ # Use WTF::Optional<>() for optional parameters that are missing or undefined and that do not have a default value in the IDL.
+ $outer = "state->argument($argumentIndex).isUndefined() ? Optional<$nativeType>() : ";
+ $inner = "state->uncheckedArgument($argumentIndex)";
} else {
$outer = "";
- $inner = "state->argument($argsIndex)";
+ $inner = "state->argument($argumentIndex)";
}
my ($nativeValue, $mayThrowException) = JSValueToNative($interface, $parameter, $inner, $function->signature->extendedAttributes->{"Conditional"});
push(@$outputArray, " auto $name = ${outer}${nativeValue};\n");
@@ -3779,7 +3799,7 @@
}
}
- my $isTearOff = $codeGenerator->IsSVGTypeNeedingTearOff($argType) && $interfaceName !~ /List$/;
+ my $isTearOff = $codeGenerator->IsSVGTypeNeedingTearOff($type) && $interfaceName !~ /List$/;
my $shouldPassByReference = ShouldPassWrapperByReference($parameter, $interface);
if ($isTearOff or $shouldPassByReference) {
push(@$outputArray, " if (UNLIKELY(!$name))\n");
@@ -3787,13 +3807,13 @@
$value = $isTearOff ? "$name->propertyReference()" : "*$name";
}
- if ($codeGenerator->IsTypedArrayType($argType) and $argType ne "ArrayBuffer") {
+ if ($codeGenerator->IsTypedArrayType($type) and $parameter->type ne "ArrayBuffer") {
$value = $shouldPassByReference ? "$name.releaseNonNull()" : "WTFMove($name)";
}
}
push(@arguments, $value);
- $argsIndex++;
+ $argumentIndex++;
}
push @arguments, GenerateReturnParameters($function);
Modified: trunk/Source/WebCore/bindings/scripts/test/JS/JSTestObj.cpp (200554 => 200555)
--- trunk/Source/WebCore/bindings/scripts/test/JS/JSTestObj.cpp 2016-05-08 15:22:36 UTC (rev 200554)
+++ trunk/Source/WebCore/bindings/scripts/test/JS/JSTestObj.cpp 2016-05-08 16:54:09 UTC (rev 200555)
@@ -486,28 +486,47 @@
template<> TestObj::ShadowRootInit convert<TestObj::ShadowRootInit>(ExecState& state, JSValue value)
{
- auto mode = convert<TestObj::ShadowRootMode>(state, propertyValue(state, value, "mode"));
+ auto* object = value.getObject();
+ if (UNLIKELY(!object || object->type() == RegExpObjectType)) {
+ throwTypeError(&state);
+ return { };
+ }
+ auto mode = convert<TestObj::ShadowRootMode>(state, object->get(&state, Identifier::fromString(&state, "mode")));
return { WTFMove(mode) };
}
template<> TestObj::FontFaceDescriptors convert<TestObj::FontFaceDescriptors>(ExecState& state, JSValue value)
{
- auto style = convertOptional<String>(state, propertyValue(state, value, "style"), "normal");
+ if (value.isUndefinedOrNull())
+ return { "normal", "U+0-10FFFF" };
+ auto* object = value.getObject();
+ if (UNLIKELY(!object || object->type() == RegExpObjectType)) {
+ throwTypeError(&state);
+ return { };
+ }
+ auto style = convertOptional<String>(state, object->get(&state, Identifier::fromString(&state, "style")), "normal");
if (UNLIKELY(state.hadException()))
return { };
- auto unicodeRange = convertOptional<String>(state, propertyValue(state, value, "unicodeRange"), "U+0-10FFFF");
+ auto unicodeRange = convertOptional<String>(state, object->get(&state, Identifier::fromString(&state, "unicodeRange")), "U+0-10FFFF");
return { WTFMove(style), WTFMove(unicodeRange) };
}
template<> TestObj::MutationObserverInit convert<TestObj::MutationObserverInit>(ExecState& state, JSValue value)
{
- auto childList = convertOptional<bool>(state, propertyValue(state, value, "childList"), false);
+ if (value.isUndefinedOrNull())
+ return { false, Nullopt, Nullopt };
+ auto* object = value.getObject();
+ if (UNLIKELY(!object || object->type() == RegExpObjectType)) {
+ throwTypeError(&state);
+ return { };
+ }
+ auto childList = convertOptional<bool>(state, object->get(&state, Identifier::fromString(&state, "childList")), false);
if (UNLIKELY(state.hadException()))
return { };
- auto attributes = convertOptional<bool>(state, propertyValue(state, value, "attributes"));
+ auto attributes = convertOptional<bool>(state, object->get(&state, Identifier::fromString(&state, "attributes")));
if (UNLIKELY(state.hadException()))
return { };
- auto attributeFilter = convertOptional<Vector<String>>(state, propertyValue(state, value, "attributeFilter"));
+ auto attributeFilter = convertOptional<Vector<String>>(state, object->get(&state, Identifier::fromString(&state, "attributeFilter")));
return { WTFMove(childList), WTFMove(attributes), WTFMove(attributeFilter) };
}
Modified: trunk/Source/WebCore/css/FontFace.cpp (200554 => 200555)
--- trunk/Source/WebCore/css/FontFace.cpp 2016-05-08 15:22:36 UTC (rev 200554)
+++ trunk/Source/WebCore/css/FontFace.cpp 2016-05-08 16:54:09 UTC (rev 200555)
@@ -36,7 +36,7 @@
namespace WebCore {
-RefPtr<FontFace> FontFace::create(JSC::ExecState& state, Document& document, const String& family, JSC::JSValue source, const Optional<Descriptors>& descriptors, ExceptionCode& ec)
+RefPtr<FontFace> FontFace::create(JSC::ExecState& state, Document& document, const String& family, JSC::JSValue source, const Descriptors& descriptors, ExceptionCode& ec)
{
auto result = adoptRef(*new FontFace(document.fontSelector()));
@@ -54,26 +54,24 @@
CSSFontFace::appendSources(result->backing(), downcast<CSSValueList>(*value), &document, false);
}
- if (descriptors) {
- result->setStyle(descriptors->style, ec);
- if (ec)
- return nullptr;
- result->setWeight(descriptors->weight, ec);
- if (ec)
- return nullptr;
- result->setStretch(descriptors->stretch, ec);
- if (ec)
- return nullptr;
- result->setUnicodeRange(descriptors->unicodeRange, ec);
- if (ec)
- return nullptr;
- result->setVariant(descriptors->variant, ec);
- if (ec)
- return nullptr;
- result->setFeatureSettings(descriptors->featureSettings, ec);
- if (ec)
- return nullptr;
- }
+ result->setStyle(descriptors.style, ec);
+ if (ec)
+ return nullptr;
+ result->setWeight(descriptors.weight, ec);
+ if (ec)
+ return nullptr;
+ result->setStretch(descriptors.stretch, ec);
+ if (ec)
+ return nullptr;
+ result->setUnicodeRange(descriptors.unicodeRange, ec);
+ if (ec)
+ return nullptr;
+ result->setVariant(descriptors.variant, ec);
+ if (ec)
+ return nullptr;
+ result->setFeatureSettings(descriptors.featureSettings, ec);
+ if (ec)
+ return nullptr;
return WTFMove(result);
}