Modified: trunk/Source/WebCore/bindings/scripts/CodeGeneratorJS.pm (101420 => 101421)
--- trunk/Source/WebCore/bindings/scripts/CodeGeneratorJS.pm 2011-11-29 21:55:35 UTC (rev 101420)
+++ trunk/Source/WebCore/bindings/scripts/CodeGeneratorJS.pm 2011-11-29 21:58:18 UTC (rev 101421)
@@ -648,6 +648,14 @@
"TouchList" => 1
);
+sub GetFunctionName
+{
+ my ($className, $function) = @_;
+ my $isStatic = $function->signature->extendedAttributes->{"ClassMethod"};
+ my $kind = $isStatic ? "Constructor" : "Prototype";
+ return $codeGenerator->WK_lcfirst($className) . $kind . "Function" . $codeGenerator->WK_ucfirst($function->signature->name);
+}
+
sub GenerateHeader
{
my $object = shift;
@@ -1086,7 +1094,7 @@
push(@headerContent,"// Functions\n\n");
foreach my $function (@{$dataNode->functions}) {
next if $function->{overloadIndex} && $function->{overloadIndex} > 1;
- my $functionName = $codeGenerator->WK_lcfirst($className) . "PrototypeFunction" . $codeGenerator->WK_ucfirst($function->signature->name);
+ my $functionName = GetFunctionName($className, $function);
push(@headerContent, "JSC::EncodedJSValue JSC_HOST_CALL ${functionName}(JSC::ExecState*);\n");
}
}
@@ -1274,7 +1282,7 @@
return (join(" || ", @orExpression), @neededArguments);
}
-sub GenerateOverloadedPrototypeFunction
+sub GenerateOverloadedFunction
{
my $function = shift;
my $dataNode = shift;
@@ -1286,7 +1294,9 @@
# overload is applicable, precedence is given according to the order of
# declaration in the IDL.
- my $functionName = "js${implClassName}PrototypeFunction" . $codeGenerator->WK_ucfirst($function->signature->name);
+ my $isStatic = $function->signature->extendedAttributes->{"ClassMethod"};
+ my $kind = $isStatic ? "Constructor" : "Prototype";
+ my $functionName = "js${implClassName}${kind}Function" . $codeGenerator->WK_ucfirst($function->signature->name);
push(@implContent, "EncodedJSValue JSC_HOST_CALL ${functionName}(ExecState* exec)\n");
push(@implContent, <<END);
@@ -1379,6 +1389,31 @@
}
}
+ foreach my $function (@{$dataNode->functions}) {
+ next unless ($function->signature->extendedAttributes->{"ClassMethod"});
+ next if $function->{overloadIndex} && $function->{overloadIndex} > 1;
+ my $name = $function->signature->name;
+ push(@hashKeys, $name);
+
+ my $functionName = GetFunctionName($className, $function);
+ push(@hashValue1, $functionName);
+
+ my $numParameters = @{$function->parameters};
+ push(@hashValue2, $numParameters);
+
+ my @specials = ();
+ push(@specials, "DontDelete") unless $function->signature->extendedAttributes->{"Deletable"};
+ push(@specials, "DontEnum") if $function->signature->extendedAttributes->{"DontEnum"};
+ push(@specials, "Function");
+ my $special = (@specials > 0) ? join(" | ", @specials) : "0";
+ push(@hashSpecials, $special);
+
+ my $conditional = $function->signature->extendedAttributes->{"Conditional"};
+ if ($conditional) {
+ $conditionals{$name} = $conditional;
+ }
+ }
+
$object->GenerateHashTable($hashName, $hashSize,
\@hashKeys, \@hashSpecials,
\@hashValue1, \@hashValue2,
@@ -1416,12 +1451,13 @@
}
foreach my $function (@{$dataNode->functions}) {
+ next if ($function->signature->extendedAttributes->{"ClassMethod"});
next if $function->{overloadIndex} && $function->{overloadIndex} > 1;
my $name = $function->signature->name;
push(@hashKeys, $name);
- my $value = $codeGenerator->WK_lcfirst($className) . "PrototypeFunction" . $codeGenerator->WK_ucfirst($name);
- push(@hashValue1, $value);
+ my $functionName = GetFunctionName($className, $function);
+ push(@hashValue1, $functionName);
my $numParameters = @{$function->parameters};
push(@hashValue2, $numParameters);
@@ -1979,12 +2015,13 @@
foreach my $function (@{$dataNode->functions}) {
AddIncludesForTypeInImpl($function->signature->type);
- my $functionName = $codeGenerator->WK_lcfirst($className) . "PrototypeFunction" . $codeGenerator->WK_ucfirst($function->signature->name);
my $isCustom = $function->signature->extendedAttributes->{"Custom"} || $function->signature->extendedAttributes->{"JSCCustom"};
my $isOverloaded = $function->{overloads} && @{$function->{overloads}} > 1;
next if $isCustom && $isOverloaded && $function->{overloadIndex} > 1;
+ my $functionName = GetFunctionName($className, $function);
+
if (!$isCustom && $isOverloaded) {
# Append a number to an overloaded method's name to make it unique:
$functionName = $functionName . $function->{overloadIndex};
@@ -2006,6 +2043,8 @@
$implIncludes{"<runtime/Error.h>"} = 1;
+ my $isStatic = $function->signature->extendedAttributes->{"ClassMethod"};
+
if ($interfaceName eq "DOMWindow") {
push(@implContent, " $className* castedThis = toJSDOMWindow(exec->hostThisValue().toThisObject(exec));\n");
push(@implContent, " if (!castedThis)\n");
@@ -2014,25 +2053,27 @@
push(@implContent, " $className* castedThis = to${className}(exec->hostThisValue().toThisObject(exec));\n");
push(@implContent, " if (!castedThis)\n");
push(@implContent, " return throwVMTypeError(exec);\n");
- } else {
+ } elsif (!$isStatic) {
push(@implContent, " JSValue thisValue = exec->hostThisValue();\n");
push(@implContent, " if (!thisValue.inherits(&${className}::s_info))\n");
push(@implContent, " return throwVMTypeError(exec);\n");
push(@implContent, " $className* castedThis = static_cast<$className*>(asObject(thisValue));\n");
}
- push(@implContent, " ASSERT_GC_OBJECT_INHERITS(castedThis, &${className}::s_info);\n");
- if ($dataNode->extendedAttributes->{"CheckDomainSecurity"} &&
- !$function->signature->extendedAttributes->{"DoNotCheckDomainSecurity"}) {
+ push(@implContent, " ASSERT_GC_OBJECT_INHERITS(castedThis, &${className}::s_info);\n") unless ($isStatic);
+
+ if ($dataNode->extendedAttributes->{"CheckDomainSecurity"} and
+ !$function->signature->extendedAttributes->{"DoNotCheckDomainSecurity"} and
+ !$isStatic) {
push(@implContent, " if (!castedThis->allowsAccessFrom(exec))\n");
push(@implContent, " return JSValue::encode(jsUndefined());\n");
}
if ($isCustom) {
- push(@implContent, " return JSValue::encode(castedThis->" . $functionImplementationName . "(exec));\n");
+ push(@implContent, " return JSValue::encode(castedThis->" . $functionImplementationName . "(exec));\n") unless ($isStatic);
} else {
- push(@implContent, " $implType* imp = static_cast<$implType*>(castedThis->impl());\n");
- if ($svgPropertyType) {
+ push(@implContent, " $implType* imp = static_cast<$implType*>(castedThis->impl());\n") unless ($isStatic);
+ if ($svgPropertyType and !$isStatic) {
push(@implContent, " if (imp->role() == AnimValRole) {\n");
push(@implContent, " setDOMException(exec, NO_MODIFICATION_ALLOWED_ERR);\n");
push(@implContent, " return JSValue::encode(jsUndefined());\n");
@@ -2047,7 +2088,7 @@
push(@implContent, " ExceptionCode ec = 0;\n");
}
- if ($function->signature->extendedAttributes->{"SVGCheckSecurityDocument"}) {
+ if ($function->signature->extendedAttributes->{"SVGCheckSecurityDocument"} and !$isStatic) {
push(@implContent, " if (!checkNodeSecurity(exec, imp->getSVGDocument(" . (@{$function->raisesExceptions} ? "ec" : "") .")))\n");
push(@implContent, " return JSValue::encode(jsUndefined());\n");
$implIncludes{"JSDOMBinding.h"} = 1;
@@ -2068,7 +2109,7 @@
if (!$isCustom && $isOverloaded && $function->{overloadIndex} == @{$function->{overloads}}) {
# Generate a function dispatching call to the rest of the overloads.
- GenerateOverloadedPrototypeFunction($function, $dataNode, $implClassName);
+ GenerateOverloadedFunction($function, $dataNode, $implClassName);
}
push(@implContent, "#endif\n\n") if $conditional;
@@ -2297,10 +2338,19 @@
my $paramIndex = 0;
my $argsIndex = 0;
my $hasOptionalArguments = 0;
+ my $isStatic = $function->signature->extendedAttributes->{"ClassMethod"};
- my $functionString = (($svgPropertyOrListPropertyType and !$svgListPropertyType) ? "podImp." : "imp->") . $functionImplementationName . "(";
+ my $functionBase = "";
+ if ($isStatic) {
+ $functionBase = "${implClassName}::";
+ } elsif ($svgPropertyOrListPropertyType and !$svgListPropertyType) {
+ $functionBase = "podImp.";
+ } else {
+ $functionBase = "imp->";
+ }
+ my $functionString = "$functionBase$functionImplementationName(";
- if ($function->signature->extendedAttributes->{"CustomArgumentHandling"}) {
+ if ($function->signature->extendedAttributes->{"CustomArgumentHandling"} and !$isStatic) {
push(@$outputArray, " RefPtr<ScriptArguments> scriptArguments(createScriptArguments(exec, $numParameters));\n");
push(@$outputArray, " size_t maxStackSize = imp->shouldCaptureFullStackTrace() ? ScriptCallStack::maxCallStackSizeToCapture : 1;\n");
push(@$outputArray, " RefPtr<ScriptCallStack> callStack(createScriptCallStack(exec, maxStackSize));\n");
@@ -2629,11 +2679,13 @@
}
$functionString .= ")";
+ my $isStatic = $function->signature->extendedAttributes->{"ClassMethod"};
+
if ($function->signature->type eq "void") {
push(@implContent, $indent . "$functionString;\n");
push(@implContent, $indent . "setDOMException(exec, ec);\n") if @{$function->raisesExceptions};
- if ($svgPropertyType) {
+ if ($svgPropertyType and !$isStatic) {
if (@{$function->raisesExceptions}) {
push(@implContent, $indent . "if (!ec)\n");
push(@implContent, $indent . " imp->commitChange();\n");
@@ -3287,14 +3339,24 @@
push(@$outputArray, " putDirect(exec->globalData(), exec->propertyNames().length, jsNumber(${numberOfconstructParameters}), ReadOnly | DontDelete | DontEnum);\n") if $numberOfconstructParameters;
push(@$outputArray, "}\n\n");
+ my $hasStaticFunctions = 0;
+ foreach my $function (@{$dataNode->functions}) {
+ if ($function->signature->extendedAttributes->{"ClassMethod"}) {
+ $hasStaticFunctions = 1;
+ last;
+ }
+ }
+
+ my $kind = $hasStaticFunctions ? "Property" : "Value";
+
push(@$outputArray, "bool ${constructorClassName}::getOwnPropertySlot(JSCell* cell, ExecState* exec, const Identifier& propertyName, PropertySlot& slot)\n");
push(@$outputArray, "{\n");
- push(@$outputArray, " return getStaticValueSlot<${constructorClassName}, JSDOMWrapper>(exec, &${constructorClassName}Table, static_cast<${constructorClassName}*>(cell), propertyName, slot);\n");
+ push(@$outputArray, " return getStatic${kind}Slot<${constructorClassName}, JSDOMWrapper>(exec, &${constructorClassName}Table, static_cast<${constructorClassName}*>(cell), propertyName, slot);\n");
push(@$outputArray, "}\n\n");
push(@$outputArray, "bool ${constructorClassName}::getOwnPropertyDescriptor(JSObject* object, ExecState* exec, const Identifier& propertyName, PropertyDescriptor& descriptor)\n");
push(@$outputArray, "{\n");
- push(@$outputArray, " return getStaticValueDescriptor<${constructorClassName}, JSDOMWrapper>(exec, &${constructorClassName}Table, static_cast<${constructorClassName}*>(object), propertyName, descriptor);\n");
+ push(@$outputArray, " return getStatic${kind}Descriptor<${constructorClassName}, JSDOMWrapper>(exec, &${constructorClassName}Table, static_cast<${constructorClassName}*>(object), propertyName, descriptor);\n");
push(@$outputArray, "}\n\n");
if (IsConstructable($dataNode)) {
Modified: trunk/Source/WebCore/bindings/scripts/test/JS/JSTestObj.cpp (101420 => 101421)
--- trunk/Source/WebCore/bindings/scripts/test/JS/JSTestObj.cpp 2011-11-29 21:55:35 UTC (rev 101420)
+++ trunk/Source/WebCore/bindings/scripts/test/JS/JSTestObj.cpp 2011-11-29 21:58:18 UTC (rev 101421)
@@ -162,11 +162,13 @@
{ "CONST_VALUE_13", DontDelete | ReadOnly, (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsTestObjCONST_VALUE_13), (intptr_t)0 THUNK_GENERATOR(0) INTRINSIC(DFG::NoIntrinsic) },
{ "CONST_VALUE_14", DontDelete | ReadOnly, (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsTestObjCONST_VALUE_14), (intptr_t)0 THUNK_GENERATOR(0) INTRINSIC(DFG::NoIntrinsic) },
{ "CONST_JAVASCRIPT", DontDelete | ReadOnly, (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsTestObjCONST_JAVASCRIPT), (intptr_t)0 THUNK_GENERATOR(0) INTRINSIC(DFG::NoIntrinsic) },
+ { "classMethod", DontDelete | Function, (intptr_t)static_cast<NativeFunction>(jsTestObjConstructorFunctionClassMethod), (intptr_t)0 THUNK_GENERATOR(0) INTRINSIC(DFG::NoIntrinsic) },
+ { "classMethodWithOptional", DontDelete | Function, (intptr_t)static_cast<NativeFunction>(jsTestObjConstructorFunctionClassMethodWithOptional), (intptr_t)1 THUNK_GENERATOR(0) INTRINSIC(DFG::NoIntrinsic) },
{ 0, 0, 0, 0 THUNK_GENERATOR(0) INTRINSIC(DFG::NoIntrinsic) }
};
#undef THUNK_GENERATOR
-static const HashTable JSTestObjConstructorTable = { 33, 31, JSTestObjConstructorTableValues, 0 };
+static const HashTable JSTestObjConstructorTable = { 35, 31, JSTestObjConstructorTableValues, 0 };
#if ENABLE(Condition1)
COMPILE_ASSERT(0 == TestObj::CONDITIONAL_CONST, TestObjEnumCONDITIONAL_CONSTIsWrongUseDontCheckEnums);
@@ -200,12 +202,12 @@
bool JSTestObjConstructor::getOwnPropertySlot(JSCell* cell, ExecState* exec, const Identifier& propertyName, PropertySlot& slot)
{
- return getStaticValueSlot<JSTestObjConstructor, JSDOMWrapper>(exec, &JSTestObjConstructorTable, static_cast<JSTestObjConstructor*>(cell), propertyName, slot);
+ return getStaticPropertySlot<JSTestObjConstructor, JSDOMWrapper>(exec, &JSTestObjConstructorTable, static_cast<JSTestObjConstructor*>(cell), propertyName, slot);
}
bool JSTestObjConstructor::getOwnPropertyDescriptor(JSObject* object, ExecState* exec, const Identifier& propertyName, PropertyDescriptor& descriptor)
{
- return getStaticValueDescriptor<JSTestObjConstructor, JSDOMWrapper>(exec, &JSTestObjConstructorTable, static_cast<JSTestObjConstructor*>(object), propertyName, descriptor);
+ return getStaticPropertyDescriptor<JSTestObjConstructor, JSDOMWrapper>(exec, &JSTestObjConstructorTable, static_cast<JSTestObjConstructor*>(object), propertyName, descriptor);
}
EncodedJSValue JSC_HOST_CALL JSTestObjConstructor::constructJSTestObj(ExecState* exec)
@@ -292,8 +294,6 @@
{ "conditionalMethod3", DontDelete | Function, (intptr_t)static_cast<NativeFunction>(jsTestObjPrototypeFunctionConditionalMethod3), (intptr_t)0 THUNK_GENERATOR(0) INTRINSIC(DFG::NoIntrinsic) },
#endif
{ "overloadedMethod", DontDelete | Function, (intptr_t)static_cast<NativeFunction>(jsTestObjPrototypeFunctionOverloadedMethod), (intptr_t)2 THUNK_GENERATOR(0) INTRINSIC(DFG::NoIntrinsic) },
- { "classMethod", DontDelete | Function, (intptr_t)static_cast<NativeFunction>(jsTestObjPrototypeFunctionClassMethod), (intptr_t)0 THUNK_GENERATOR(0) INTRINSIC(DFG::NoIntrinsic) },
- { "classMethodWithOptional", DontDelete | Function, (intptr_t)static_cast<NativeFunction>(jsTestObjPrototypeFunctionClassMethodWithOptional), (intptr_t)1 THUNK_GENERATOR(0) INTRINSIC(DFG::NoIntrinsic) },
{ 0, 0, 0, 0 THUNK_GENERATOR(0) INTRINSIC(DFG::NoIntrinsic) }
};
@@ -1866,31 +1866,19 @@
return throwVMTypeError(exec);
}
-EncodedJSValue JSC_HOST_CALL jsTestObjPrototypeFunctionClassMethod(ExecState* exec)
+EncodedJSValue JSC_HOST_CALL jsTestObjConstructorFunctionClassMethod(ExecState* exec)
{
- JSValue thisValue = exec->hostThisValue();
- if (!thisValue.inherits(&JSTestObj::s_info))
- return throwVMTypeError(exec);
- JSTestObj* castedThis = static_cast<JSTestObj*>(asObject(thisValue));
- ASSERT_GC_OBJECT_INHERITS(castedThis, &JSTestObj::s_info);
- TestObj* imp = static_cast<TestObj*>(castedThis->impl());
- imp->classMethod();
+ TestObj::classMethod();
return JSValue::encode(jsUndefined());
}
-EncodedJSValue JSC_HOST_CALL jsTestObjPrototypeFunctionClassMethodWithOptional(ExecState* exec)
+EncodedJSValue JSC_HOST_CALL jsTestObjConstructorFunctionClassMethodWithOptional(ExecState* exec)
{
- JSValue thisValue = exec->hostThisValue();
- if (!thisValue.inherits(&JSTestObj::s_info))
- return throwVMTypeError(exec);
- JSTestObj* castedThis = static_cast<JSTestObj*>(asObject(thisValue));
- ASSERT_GC_OBJECT_INHERITS(castedThis, &JSTestObj::s_info);
- TestObj* imp = static_cast<TestObj*>(castedThis->impl());
size_t argsCount = exec->argumentCount();
if (argsCount <= 0) {
- JSC::JSValue result = jsNumber(imp->classMethodWithOptional());
+ JSC::JSValue result = jsNumber(TestObj::classMethodWithOptional());
return JSValue::encode(result);
}
@@ -1898,7 +1886,7 @@
if (exec->hadException())
return JSValue::encode(jsUndefined());
- JSC::JSValue result = jsNumber(imp->classMethodWithOptional(arg));
+ JSC::JSValue result = jsNumber(TestObj::classMethodWithOptional(arg));
return JSValue::encode(result);
}