2 # Copyright (C) 2005, 2006, 2007, 2008 Nikolas Zimmermann <zimmermann@kde.org>
3 # Copyright (C) 2006 Anders Carlsson <andersca@mac.com>
4 # Copyright (C) 2006, 2007 Samuel Weinig <sam@webkit.org>
5 # Copyright (C) 2006 Alexey Proskuryakov <ap@webkit.org>
6 # Copyright (C) 2006, 2007, 2008, 2009 Apple Inc. All rights reserved.
7 # Copyright (C) 2009 Cameron McCormack <cam@mcc.id.au>
9 # This library is free software; you can redistribute it and/or
10 # modify it under the terms of the GNU Library General Public
11 # License as published by the Free Software Foundation; either
12 # version 2 of the License, or (at your option) any later version.
14 # This library is distributed in the hope that it will be useful,
15 # but WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 # Library General Public License for more details.
19 # You should have received a copy of the GNU Library General Public License
20 # along with this library; see the file COPYING.LIB. If not, write to
21 # the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
22 # Boston, MA 02110-1301, USA.
24 package CodeGeneratorJS;
30 my $writeDependencies = 0;
32 my @headerContentHeader = ();
33 my @headerContent = ();
34 my %headerIncludes = ();
35 my %headerTrailingIncludes = ();
37 my @implContentHeader = ();
39 my %implIncludes = ();
41 my $numCachedAttributes = 0;
42 my $currentCachedAttribute = 0;
45 my $headerTemplate = << "EOF";
47 This file is part of the WebKit open source project.
48 This file has been generated by generate-bindings.pl. DO NOT MODIFY!
50 This library is free software; you can redistribute it and/or
51 modify it under the terms of the GNU Library General Public
52 License as published by the Free Software Foundation; either
53 version 2 of the License, or (at your option) any later version.
55 This library is distributed in the hope that it will be useful,
56 but WITHOUT ANY WARRANTY; without even the implied warranty of
57 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
58 Library General Public License for more details.
60 You should have received a copy of the GNU Library General Public License
61 along with this library; see the file COPYING.LIB. If not, write to
62 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
63 Boston, MA 02110-1301, USA.
73 $codeGenerator = shift;
75 shift; # $useLayerOnTop
76 shift; # $preprocessor
77 $writeDependencies = shift;
79 bless($reference, $object);
92 my ($value, $distance) = @_;
93 return (($value << $distance) & 0xFFFFFFFF);
96 # Params: 'domClass' struct
100 my $dataNode = shift;
103 # Start actual generation
104 if ($dataNode->extendedAttributes->{"Callback"}) {
105 $object->GenerateCallbackHeader($dataNode);
106 $object->GenerateCallbackImplementation($dataNode);
108 $object->GenerateHeader($dataNode);
109 $object->GenerateImplementation($dataNode);
112 my $name = $dataNode->name;
114 # Open files for writing
115 my $headerFileName = "$outputDir/JS$name.h";
116 my $implFileName = "$outputDir/JS$name.cpp";
117 my $depsFileName = "$outputDir/JS$name.dep";
119 # Remove old dependency file.
120 unlink($depsFileName);
122 open($IMPL, ">$implFileName") || die "Couldn't open file $implFileName";
123 open($HEADER, ">$headerFileName") || die "Couldn't open file $headerFileName";
125 open($DEPS, ">$depsFileName") || die "Couldn't open file $depsFileName";
129 sub GenerateEventListenerCall
131 my $className = shift;
132 my $functionName = shift;
133 my $passRefPtrHandling = ($functionName eq "add") ? "" : ".get()";
135 $implIncludes{"JSEventListener.h"} = 1;
137 my @GenerateEventListenerImpl = ();
138 push(@GenerateEventListenerImpl, <<END);
139 JSValue listener = args.at(1);
140 if (!listener.isObject())
141 return jsUndefined();
142 imp->${functionName}EventListener(ustringToAtomicString(args.at(0).toString(exec)), JSEventListener::create(asObject(listener), castedThis, false, currentWorld(exec))$passRefPtrHandling, args.at(2).toBoolean(exec));
143 return jsUndefined();
145 return @GenerateEventListenerImpl;
148 # Params: 'idlDocument' struct
152 my $dataNode = shift;
154 $module = $dataNode->module;
157 sub GetParentClassName
159 my $dataNode = shift;
161 return $dataNode->extendedAttributes->{"LegacyParent"} if $dataNode->extendedAttributes->{"LegacyParent"};
162 return "DOMObjectWithGlobalPointer" if (@{$dataNode->parents} eq 0);
163 return "JS" . $codeGenerator->StripModule($dataNode->parents(0));
166 sub GetVisibleClassName
168 my $className = shift;
170 return "DOMException" if $className eq "DOMCoreException";
171 return "FormData" if $className eq "DOMFormData";
175 sub AvoidInclusionOfType
179 # Special case: SVGRect.h / SVGPoint.h / SVGNumber.h / SVGMatrix.h do not exist.
180 return 1 if $type eq "SVGRect" or $type eq "SVGPoint" or $type eq "SVGNumber" or $type eq "SVGMatrix";
184 sub IndexGetterReturnsStrings
188 return 1 if $type eq "CSSStyleDeclaration" or $type eq "MediaList" or $type eq "CSSVariablesDeclaration";
192 sub AddIncludesForType
194 my $type = $codeGenerator->StripModule(shift);
195 my $isCallback = @_ ? shift : 0;
197 # When we're finished with the one-file-per-class
198 # reorganization, we won't need these special cases.
199 if ($codeGenerator->IsPrimitiveType($type) or AvoidInclusionOfType($type)
200 or $type eq "DOMString" or $type eq "DOMObject" or $type eq "Array") {
201 } elsif ($type =~ /SVGPathSeg/) {
203 $joinedName =~ s/Abs|Rel//;
204 $implIncludes{"${joinedName}.h"} = 1;
205 } elsif ($type eq "XPathNSResolver") {
206 $implIncludes{"JSXPathNSResolver.h"} = 1;
207 $implIncludes{"JSCustomXPathNSResolver.h"} = 1;
208 } elsif ($isCallback) {
209 $implIncludes{"JS${type}.h"} = 1;
211 # default, include the same named file
212 $implIncludes{"${type}.h"} = 1;
215 # additional includes (things needed to compile the bindings but not the header)
217 if ($type eq "CanvasRenderingContext2D") {
218 $implIncludes{"CanvasGradient.h"} = 1;
219 $implIncludes{"CanvasPattern.h"} = 1;
220 $implIncludes{"CanvasStyle.h"} = 1;
223 if ($type eq "CanvasGradient" or $type eq "XPathNSResolver" or $type eq "MessagePort") {
224 $implIncludes{"PlatformString.h"} = 1;
227 if ($type eq "Document") {
228 $implIncludes{"NodeFilter.h"} = 1;
232 sub AddIncludesForSVGAnimatedType
235 $type =~ s/SVGAnimated//;
237 if ($type eq "Point" or $type eq "Rect") {
238 $implIncludes{"Float$type.h"} = 1;
239 } elsif ($type eq "String") {
240 $implIncludes{"PlatformString.h"} = 1;
244 sub IsScriptProfileType
247 return 1 if ($type eq "ScriptProfile" or $type eq "ScriptProfileNode");
251 sub AddTypedefForScriptProfileType
254 (my $jscType = $type) =~ s/Script//;
256 push(@headerContent, "typedef JSC::$jscType $type;\n\n");
259 sub AddClassForwardIfNeeded
261 my $implClassName = shift;
263 # SVGAnimatedLength/Number/etc. are typedefs to SVGAnimatedTemplate, so don't use class forwards for them!
264 unless ($codeGenerator->IsSVGAnimatedType($implClassName) or IsScriptProfileType($implClassName)) {
265 push(@headerContent, "class $implClassName;\n\n");
266 # ScriptProfile and ScriptProfileNode are typedefs to JSC::Profile and JSC::ProfileNode.
267 } elsif (IsScriptProfileType($implClassName)) {
268 AddTypedefForScriptProfileType($implClassName);
272 sub IsSVGTypeNeedingContextParameter
274 my $implClassName = shift;
276 return 0 unless $implClassName =~ /SVG/;
277 return 0 if $implClassName =~ /Element/;
278 my @noContextNeeded = ("SVGPaint", "SVGColor", "SVGDocument", "SVGZoomEvent");
279 foreach (@noContextNeeded) {
280 return 0 if $implClassName eq $_;
285 sub HashValueForClassAndName
290 # SVG Filter enums live in WebCore namespace (platform/graphics/)
291 if ($class =~ /^SVGFE*/ or $class =~ /^SVGComponentTransferFunctionElement$/) {
292 return "WebCore::$name";
295 return "${class}::$name";
298 sub hashTableAccessor
300 my $noStaticTables = shift;
301 my $className = shift;
302 if ($noStaticTables) {
303 return "get${className}Table(exec)";
305 return "&${className}Table";
309 sub prototypeHashTableAccessor
311 my $noStaticTables = shift;
312 my $className = shift;
313 if ($noStaticTables) {
314 return "get${className}PrototypeTable(exec)";
316 return "&${className}PrototypeTable";
320 sub GenerateConditionalStringFromAttributeValue
322 my $conditional = shift;
323 if ($conditional =~ /&/) {
324 return "ENABLE(" . join(") && ENABLE(", split(/&/, $conditional)) . ")";
325 } elsif ($conditional =~ /\|/) {
326 return "ENABLE(" . join(") || ENABLE(", split(/\|/, $conditional)) . ")";
328 return "ENABLE(" . $conditional . ")";
332 sub GenerateConditionalString
335 my $conditional = $node->extendedAttributes->{"Conditional"};
337 return GenerateConditionalStringFromAttributeValue($conditional);
343 sub GenerateGetOwnPropertySlotBody
345 my ($dataNode, $interfaceName, $className, $implClassName, $hasAttributes, $inlined) = @_;
347 my $namespaceMaybe = ($inlined ? "JSC::" : "");
349 my @getOwnPropertySlotImpl = ();
351 if ($interfaceName eq "NamedNodeMap" or $interfaceName eq "HTMLCollection" or $interfaceName eq "HTMLAllCollection") {
352 push(@getOwnPropertySlotImpl, " ${namespaceMaybe}JSValue proto = prototype();\n");
353 push(@getOwnPropertySlotImpl, " if (proto.isObject() && static_cast<${namespaceMaybe}JSObject*>(asObject(proto))->hasProperty(exec, propertyName))\n");
354 push(@getOwnPropertySlotImpl, " return false;\n\n");
357 my $manualLookupGetterGeneration = sub {
358 my $requiresManualLookup = $dataNode->extendedAttributes->{"HasIndexGetter"} || $dataNode->extendedAttributes->{"HasNameGetter"};
359 if ($requiresManualLookup) {
360 push(@getOwnPropertySlotImpl, " const ${namespaceMaybe}HashEntry* entry = ${className}Table.entry(exec, propertyName);\n");
361 push(@getOwnPropertySlotImpl, " if (entry) {\n");
362 push(@getOwnPropertySlotImpl, " slot.setCustom(this, entry->propertyGetter());\n");
363 push(@getOwnPropertySlotImpl, " return true;\n");
364 push(@getOwnPropertySlotImpl, " }\n");
368 if (!$dataNode->extendedAttributes->{"HasOverridingNameGetter"}) {
369 &$manualLookupGetterGeneration();
372 if ($dataNode->extendedAttributes->{"HasIndexGetter"} || $dataNode->extendedAttributes->{"HasCustomIndexGetter"} || $dataNode->extendedAttributes->{"HasNumericIndexGetter"}) {
373 push(@getOwnPropertySlotImpl, " bool ok;\n");
374 push(@getOwnPropertySlotImpl, " unsigned index = propertyName.toUInt32(&ok, false);\n");
376 # If the item function returns a string then we let the ConvertNullStringTo handle the cases
377 # where the index is out of range.
378 if (IndexGetterReturnsStrings($implClassName)) {
379 push(@getOwnPropertySlotImpl, " if (ok) {\n");
381 push(@getOwnPropertySlotImpl, " if (ok && index < static_cast<$implClassName*>(impl())->length()) {\n");
383 if ($dataNode->extendedAttributes->{"HasCustomIndexGetter"} || $dataNode->extendedAttributes->{"HasNumericIndexGetter"}) {
384 push(@getOwnPropertySlotImpl, " slot.setValue(getByIndex(exec, index));\n");
386 push(@getOwnPropertySlotImpl, " slot.setCustomIndex(this, index, indexGetter);\n");
388 push(@getOwnPropertySlotImpl, " return true;\n");
389 push(@getOwnPropertySlotImpl, " }\n");
392 if ($dataNode->extendedAttributes->{"HasNameGetter"} || $dataNode->extendedAttributes->{"HasOverridingNameGetter"}) {
393 push(@getOwnPropertySlotImpl, " if (canGetItemsForName(exec, static_cast<$implClassName*>(impl()), propertyName)) {\n");
394 push(@getOwnPropertySlotImpl, " slot.setCustom(this, nameGetter);\n");
395 push(@getOwnPropertySlotImpl, " return true;\n");
396 push(@getOwnPropertySlotImpl, " }\n");
398 $headerIncludes{"AtomicString.h"} = 1;
400 $implIncludes{"AtomicString.h"} = 1;
404 if ($dataNode->extendedAttributes->{"HasOverridingNameGetter"}) {
405 &$manualLookupGetterGeneration();
408 if ($dataNode->extendedAttributes->{"DelegatingGetOwnPropertySlot"}) {
409 push(@getOwnPropertySlotImpl, " if (getOwnPropertySlotDelegate(exec, propertyName, slot))\n");
410 push(@getOwnPropertySlotImpl, " return true;\n");
413 if ($hasAttributes) {
415 die "Cannot inline if NoStaticTables is set." if ($dataNode->extendedAttributes->{"NoStaticTables"});
416 push(@getOwnPropertySlotImpl, " return ${namespaceMaybe}getStaticValueSlot<$className, Base>(exec, s_info.staticPropHashTable, this, propertyName, slot);\n");
418 push(@getOwnPropertySlotImpl, " return ${namespaceMaybe}getStaticValueSlot<$className, Base>(exec, " . hashTableAccessor($dataNode->extendedAttributes->{"NoStaticTables"}, $className) . ", this, propertyName, slot);\n");
421 push(@getOwnPropertySlotImpl, " return Base::getOwnPropertySlot(exec, propertyName, slot);\n");
424 return @getOwnPropertySlotImpl;
427 sub GenerateGetOwnPropertyDescriptorBody
429 my ($dataNode, $interfaceName, $className, $implClassName, $hasAttributes, $inlined) = @_;
431 my $namespaceMaybe = ($inlined ? "JSC::" : "");
433 my @getOwnPropertyDescriptorImpl = ();
434 if ($dataNode->extendedAttributes->{"CheckDomainSecurity"}) {
435 if ($interfaceName eq "DOMWindow") {
436 push(@implContent, " if (!static_cast<$className*>(thisObject)->allowsAccessFrom(exec))\n");
438 push(@implContent, " if (!allowsAccessFromFrame(exec, static_cast<$className*>(thisObject)->impl()->frame()))\n");
440 push(@implContent, " return false;\n");
443 if ($interfaceName eq "NamedNodeMap" or $interfaceName eq "HTMLCollection" or $interfaceName eq "HTMLAllCollection") {
444 push(@getOwnPropertyDescriptorImpl, " ${namespaceMaybe}JSValue proto = prototype();\n");
445 push(@getOwnPropertyDescriptorImpl, " if (proto.isObject() && static_cast<${namespaceMaybe}JSObject*>(asObject(proto))->hasProperty(exec, propertyName))\n");
446 push(@getOwnPropertyDescriptorImpl, " return false;\n\n");
449 my $manualLookupGetterGeneration = sub {
450 my $requiresManualLookup = $dataNode->extendedAttributes->{"HasIndexGetter"} || $dataNode->extendedAttributes->{"HasNameGetter"};
451 if ($requiresManualLookup) {
452 push(@getOwnPropertyDescriptorImpl, " const ${namespaceMaybe}HashEntry* entry = ${className}Table.entry(exec, propertyName);\n");
453 push(@getOwnPropertyDescriptorImpl, " if (entry) {\n");
454 push(@getOwnPropertyDescriptorImpl, " PropertySlot slot;\n");
455 push(@getOwnPropertyDescriptorImpl, " slot.setCustom(this, entry->propertyGetter());\n");
456 push(@getOwnPropertyDescriptorImpl, " descriptor.setDescriptor(slot.getValue(exec, propertyName), entry->attributes());\n");
457 push(@getOwnPropertyDescriptorImpl, " return true;\n");
458 push(@getOwnPropertyDescriptorImpl, " }\n");
462 if (!$dataNode->extendedAttributes->{"HasOverridingNameGetter"}) {
463 &$manualLookupGetterGeneration();
466 if ($dataNode->extendedAttributes->{"HasIndexGetter"} || $dataNode->extendedAttributes->{"HasCustomIndexGetter"} || $dataNode->extendedAttributes->{"HasNumericIndexGetter"}) {
467 push(@getOwnPropertyDescriptorImpl, " bool ok;\n");
468 push(@getOwnPropertyDescriptorImpl, " unsigned index = propertyName.toUInt32(&ok, false);\n");
469 push(@getOwnPropertyDescriptorImpl, " if (ok && index < static_cast<$implClassName*>(impl())->length()) {\n");
470 if ($dataNode->extendedAttributes->{"HasCustomIndexGetter"} || $dataNode->extendedAttributes->{"HasNumericIndexGetter"}) {
471 # Assume that if there's a setter, the index will be writable
472 if ($dataNode->extendedAttributes->{"HasIndexSetter"} || $dataNode->extendedAttributes->{"HasCustomIndexSetter"}) {
473 push(@getOwnPropertyDescriptorImpl, " descriptor.setDescriptor(getByIndex(exec, index), ${namespaceMaybe}DontDelete);\n");
475 push(@getOwnPropertyDescriptorImpl, " descriptor.setDescriptor(getByIndex(exec, index), ${namespaceMaybe}DontDelete | ${namespaceMaybe}ReadOnly);\n");
478 push(@getOwnPropertyDescriptorImpl, " ${namespaceMaybe}PropertySlot slot;\n");
479 push(@getOwnPropertyDescriptorImpl, " slot.setCustomIndex(this, index, indexGetter);\n");
480 # Assume that if there's a setter, the index will be writable
481 if ($dataNode->extendedAttributes->{"HasIndexSetter"} || $dataNode->extendedAttributes->{"HasCustomIndexSetter"}) {
482 push(@getOwnPropertyDescriptorImpl, " descriptor.setDescriptor(slot.getValue(exec, propertyName), ${namespaceMaybe}DontDelete);\n");
484 push(@getOwnPropertyDescriptorImpl, " descriptor.setDescriptor(slot.getValue(exec, propertyName), ${namespaceMaybe}DontDelete | ${namespaceMaybe}ReadOnly);\n");
487 push(@getOwnPropertyDescriptorImpl, " return true;\n");
488 push(@getOwnPropertyDescriptorImpl, " }\n");
491 if ($dataNode->extendedAttributes->{"HasNameGetter"} || $dataNode->extendedAttributes->{"HasOverridingNameGetter"}) {
492 push(@getOwnPropertyDescriptorImpl, " if (canGetItemsForName(exec, static_cast<$implClassName*>(impl()), propertyName)) {\n");
493 push(@getOwnPropertyDescriptorImpl, " ${namespaceMaybe}PropertySlot slot;\n");
494 push(@getOwnPropertyDescriptorImpl, " slot.setCustom(this, nameGetter);\n");
495 push(@getOwnPropertyDescriptorImpl, " descriptor.setDescriptor(slot.getValue(exec, propertyName), ReadOnly | DontDelete | DontEnum);\n");
496 push(@getOwnPropertyDescriptorImpl, " return true;\n");
497 push(@getOwnPropertyDescriptorImpl, " }\n");
499 $headerIncludes{"AtomicString.h"} = 1;
501 $implIncludes{"AtomicString.h"} = 1;
505 if ($dataNode->extendedAttributes->{"HasOverridingNameGetter"}) {
506 &$manualLookupGetterGeneration();
509 if ($dataNode->extendedAttributes->{"DelegatingGetOwnPropertySlot"}) {
510 push(@getOwnPropertyDescriptorImpl, " if (getOwnPropertyDescriptorDelegate(exec, propertyName, descriptor))\n");
511 push(@getOwnPropertyDescriptorImpl, " return true;\n");
514 if ($hasAttributes) {
516 die "Cannot inline if NoStaticTables is set." if ($dataNode->extendedAttributes->{"NoStaticTables"});
517 push(@getOwnPropertyDescriptorImpl, " return ${namespaceMaybe}getStaticValueDescriptor<$className, Base>(exec, s_info.staticPropHashTable, this, propertyName, descriptor);\n");
519 push(@getOwnPropertyDescriptorImpl, " return ${namespaceMaybe}getStaticValueDescriptor<$className, Base>(exec, " . hashTableAccessor($dataNode->extendedAttributes->{"NoStaticTables"}, $className) . ", this, propertyName, descriptor);\n");
522 push(@getOwnPropertyDescriptorImpl, " return Base::getOwnPropertyDescriptor(exec, propertyName, descriptor);\n");
525 return @getOwnPropertyDescriptorImpl;
528 sub GenerateHeaderContentHeader
530 my $dataNode = shift;
531 my $className = "JS" . $dataNode->name;
533 my @headerContentHeader = split("\r", $headerTemplate);
535 # - Add header protection
536 push(@headerContentHeader, "\n#ifndef $className" . "_h");
537 push(@headerContentHeader, "\n#define $className" . "_h\n\n");
539 my $conditionalString = GenerateConditionalString($dataNode);
540 push(@headerContentHeader, "#if ${conditionalString}\n\n") if $conditionalString;
541 return @headerContentHeader;
544 sub GenerateImplementationContentHeader
546 my $dataNode = shift;
547 my $className = "JS" . $dataNode->name;
549 my @implContentHeader = split("\r", $headerTemplate);
551 push(@implContentHeader, "\n#include \"config.h\"\n");
552 my $conditionalString = GenerateConditionalString($dataNode);
553 push(@implContentHeader, "\n#if ${conditionalString}\n\n") if $conditionalString;
554 push(@implContentHeader, "#include \"$className.h\"\n\n");
555 return @implContentHeader;
561 my $dataNode = shift;
563 my $interfaceName = $dataNode->name;
564 my $className = "JS$interfaceName";
565 my $implClassName = $interfaceName;
566 my @ancestorInterfaceNames = ();
567 my %structureFlags = ();
569 # We only support multiple parents with SVG (for now).
570 if (@{$dataNode->parents} > 1) {
571 die "A class can't have more than one parent" unless $interfaceName =~ /SVG/;
572 $codeGenerator->AddMethodsConstantsAndAttributesFromParentClasses($dataNode, \@ancestorInterfaceNames);
575 my $hasLegacyParent = $dataNode->extendedAttributes->{"LegacyParent"};
576 my $hasRealParent = @{$dataNode->parents} > 0;
577 my $hasParent = $hasLegacyParent || $hasRealParent;
578 my $parentClassName = GetParentClassName($dataNode);
579 my $eventTarget = $dataNode->extendedAttributes->{"EventTarget"};
580 my $needsMarkChildren = $dataNode->extendedAttributes->{"CustomMarkFunction"} || $dataNode->extendedAttributes->{"EventTarget"};
582 # - Add default header template and header protection
583 push(@headerContentHeader, GenerateHeaderContentHeader($dataNode));
586 $headerIncludes{"$parentClassName.h"} = 1;
588 $headerIncludes{"JSDOMBinding.h"} = 1;
589 $headerIncludes{"<runtime/JSGlobalObject.h>"} = 1;
590 $headerIncludes{"<runtime/ObjectPrototype.h>"} = 1;
593 if ($dataNode->extendedAttributes->{"CustomCall"}) {
594 $headerIncludes{"<runtime/CallData.h>"} = 1;
597 if ($dataNode->extendedAttributes->{"InlineGetOwnPropertySlot"}) {
598 $headerIncludes{"<runtime/Lookup.h>"} = 1;
599 $headerIncludes{"<wtf/AlwaysInline.h>"} = 1;
602 if ($hasParent && $dataNode->extendedAttributes->{"GenerateNativeConverter"}) {
603 $headerIncludes{"$implClassName.h"} = 1;
606 $headerIncludes{"SVGElement.h"} = 1 if $className =~ /^JSSVG/;
608 # Get correct pass/store types respecting PODType flag
609 my $podType = $dataNode->extendedAttributes->{"PODType"};
610 my $implType = $podType ? "JSSVGPODTypeWrapper<$podType> " : $implClassName;
612 $headerIncludes{"$podType.h"} = 1 if $podType and $podType ne "float";
614 $headerIncludes{"JSSVGPODTypeWrapper.h"} = 1 if $podType;
616 my $numConstants = @{$dataNode->constants};
617 my $numAttributes = @{$dataNode->attributes};
618 my $numFunctions = @{$dataNode->functions};
620 push(@headerContent, "\nnamespace WebCore {\n\n");
622 # Implementation class forward declaration
623 AddClassForwardIfNeeded($implClassName) unless $podType;
624 AddClassForwardIfNeeded("JSDOMWindowShell") if $interfaceName eq "DOMWindow";
627 push(@headerContent, "class $className : public $parentClassName {\n");
628 push(@headerContent, " typedef $parentClassName Base;\n");
629 push(@headerContent, "public:\n");
632 if ($interfaceName eq "DOMWindow") {
633 push(@headerContent, " $className(NonNullPassRefPtr<JSC::Structure>, PassRefPtr<$implType>, JSDOMWindowShell*);\n");
634 } elsif ($dataNode->extendedAttributes->{"IsWorkerContext"}) {
635 push(@headerContent, " $className(NonNullPassRefPtr<JSC::Structure>, PassRefPtr<$implType>);\n");
637 push(@headerContent, " $className(NonNullPassRefPtr<JSC::Structure>, JSDOMGlobalObject*, PassRefPtr<$implType>);\n");
641 push(@headerContent, " virtual ~$className();\n") if (!$hasParent or $eventTarget or $interfaceName eq "DOMWindow");
644 push(@headerContent, " static JSC::JSObject* createPrototype(JSC::ExecState*, JSC::JSGlobalObject*);\n") unless ($dataNode->extendedAttributes->{"ExtendsDOMGlobalObject"});
646 $headerTrailingIncludes{"${className}Custom.h"} = 1 if $dataNode->extendedAttributes->{"CustomHeader"};
648 $implIncludes{"${className}Custom.h"} = 1 if !$dataNode->extendedAttributes->{"CustomHeader"} && ($dataNode->extendedAttributes->{"CustomPutFunction"} || $dataNode->extendedAttributes->{"DelegatingPutFunction"});
650 my $hasGetter = $numAttributes > 0
651 || !($dataNode->extendedAttributes->{"OmitConstructor"}
652 || $dataNode->extendedAttributes->{"CustomConstructor"})
653 || $dataNode->extendedAttributes->{"HasIndexGetter"}
654 || $dataNode->extendedAttributes->{"HasCustomIndexGetter"}
655 || $dataNode->extendedAttributes->{"HasNumericIndexGetter"}
656 || $dataNode->extendedAttributes->{"CustomGetOwnPropertySlot"}
657 || $dataNode->extendedAttributes->{"DelegatingGetOwnPropertySlot"}
658 || $dataNode->extendedAttributes->{"HasNameGetter"}
659 || $dataNode->extendedAttributes->{"HasOverridingNameGetter"};
663 push(@headerContent, " virtual bool getOwnPropertySlot(JSC::ExecState*, const JSC::Identifier& propertyName, JSC::PropertySlot&);\n");
664 push(@headerContent, " virtual bool getOwnPropertyDescriptor(JSC::ExecState*, const JSC::Identifier& propertyName, JSC::PropertyDescriptor&);\n");
665 push(@headerContent, " virtual bool getOwnPropertySlot(JSC::ExecState*, unsigned propertyName, JSC::PropertySlot&);\n") if ($dataNode->extendedAttributes->{"HasIndexGetter"} || $dataNode->extendedAttributes->{"HasCustomIndexGetter"} || $dataNode->extendedAttributes->{"HasNumericIndexGetter"}) && !$dataNode->extendedAttributes->{"HasOverridingNameGetter"};
666 push(@headerContent, " bool getOwnPropertySlotDelegate(JSC::ExecState*, const JSC::Identifier&, JSC::PropertySlot&);\n") if $dataNode->extendedAttributes->{"DelegatingGetOwnPropertySlot"};
667 push(@headerContent, " bool getOwnPropertyDescriptorDelegate(JSC::ExecState*, const JSC::Identifier&, JSC::PropertyDescriptor&);\n") if $dataNode->extendedAttributes->{"DelegatingGetOwnPropertySlot"};
668 $structureFlags{"JSC::OverridesGetOwnPropertySlot"} = 1;
671 # Check if we have any writable properties
672 my $hasReadWriteProperties = 0;
673 foreach (@{$dataNode->attributes}) {
674 if ($_->type !~ /^readonly\ attribute$/) {
675 $hasReadWriteProperties = 1;
679 my $hasSetter = $hasReadWriteProperties
680 || $dataNode->extendedAttributes->{"CustomPutFunction"}
681 || $dataNode->extendedAttributes->{"DelegatingPutFunction"}
682 || $dataNode->extendedAttributes->{"HasCustomIndexSetter"};
686 push(@headerContent, " virtual void put(JSC::ExecState*, const JSC::Identifier& propertyName, JSC::JSValue, JSC::PutPropertySlot&);\n");
687 push(@headerContent, " virtual void put(JSC::ExecState*, unsigned propertyName, JSC::JSValue);\n") if $dataNode->extendedAttributes->{"HasCustomIndexSetter"};
688 push(@headerContent, " bool putDelegate(JSC::ExecState*, const JSC::Identifier&, JSC::JSValue, JSC::PutPropertySlot&);\n") if $dataNode->extendedAttributes->{"DelegatingPutFunction"};
692 push(@headerContent, " virtual const JSC::ClassInfo* classInfo() const { return &s_info; }\n");
693 push(@headerContent, " static const JSC::ClassInfo s_info;\n\n");
696 if ($interfaceName eq "DOMWindow") {
697 $structureFlags{"JSC::ImplementsHasInstance"} = 1;
698 $structureFlags{"JSC::NeedsThisConversion"} = 1;
701 " static PassRefPtr<JSC::Structure> createStructure(JSC::JSValue prototype)\n" .
703 " return JSC::Structure::create(prototype, JSC::TypeInfo(JSC::ObjectType, StructureFlags), AnonymousSlotCount);\n" .
706 # markChildren function
707 if ($needsMarkChildren) {
708 push(@headerContent, " virtual void markChildren(JSC::MarkStack&);\n\n");
709 $structureFlags{"JSC::OverridesMarkChildren"} = 1;
712 # Custom pushEventHandlerScope function
713 push(@headerContent, " virtual void pushEventHandlerScope(JSC::ExecState*, JSC::ScopeChain&) const;\n\n") if $dataNode->extendedAttributes->{"CustomPushEventHandlerScope"};
715 # Custom call functions
716 push(@headerContent, " virtual JSC::CallType getCallData(JSC::CallData&);\n\n") if $dataNode->extendedAttributes->{"CustomCall"};
718 # Custom deleteProperty function
719 push(@headerContent, " virtual bool deleteProperty(JSC::ExecState*, const JSC::Identifier&);\n") if $dataNode->extendedAttributes->{"CustomDeleteProperty"};
721 # Custom getPropertyNames function exists on DOMWindow
722 if ($interfaceName eq "DOMWindow") {
723 push(@headerContent, " virtual void getPropertyNames(JSC::ExecState*, JSC::PropertyNameArray&, JSC::EnumerationMode mode = JSC::ExcludeDontEnumProperties);\n");
724 $structureFlags{"JSC::OverridesGetPropertyNames"} = 1;
727 # Custom defineProperty function exists on DOMWindow
728 push(@headerContent, " virtual bool defineOwnProperty(JSC::ExecState*, const JSC::Identifier& propertyName, JSC::PropertyDescriptor&, bool shouldThrow);\n") if $interfaceName eq "DOMWindow";
730 # Custom getOwnPropertyNames function
731 if ($dataNode->extendedAttributes->{"CustomGetPropertyNames"} || $dataNode->extendedAttributes->{"HasIndexGetter"} || $dataNode->extendedAttributes->{"HasCustomIndexGetter"} || $dataNode->extendedAttributes->{"HasNumericIndexGetter"}) {
732 push(@headerContent, " virtual void getOwnPropertyNames(JSC::ExecState*, JSC::PropertyNameArray&, JSC::EnumerationMode mode = JSC::ExcludeDontEnumProperties);\n");
733 $structureFlags{"JSC::OverridesGetPropertyNames"} = 1;
736 # Custom defineGetter function
737 push(@headerContent, " virtual void defineGetter(JSC::ExecState*, const JSC::Identifier& propertyName, JSC::JSObject* getterFunction, unsigned attributes);\n") if $dataNode->extendedAttributes->{"CustomDefineGetter"};
739 # Custom defineSetter function
740 push(@headerContent, " virtual void defineSetter(JSC::ExecState*, const JSC::Identifier& propertyName, JSC::JSObject* setterFunction, unsigned attributes);\n") if $dataNode->extendedAttributes->{"CustomDefineSetter"};
742 # Custom lookupGetter function
743 push(@headerContent, " virtual JSC::JSValue lookupGetter(JSC::ExecState*, const JSC::Identifier& propertyName);\n") if $dataNode->extendedAttributes->{"CustomLookupGetter"};
745 # Custom lookupSetter function
746 push(@headerContent, " virtual JSC::JSValue lookupSetter(JSC::ExecState*, const JSC::Identifier& propertyName);\n") if $dataNode->extendedAttributes->{"CustomLookupSetter"};
748 # Override toBoolean to return false for objects that want to 'MasqueradesAsUndefined'.
749 if ($dataNode->extendedAttributes->{"MasqueradesAsUndefined"}) {
750 push(@headerContent, " virtual bool toBoolean(JSC::ExecState*) const { return false; };\n");
751 $structureFlags{"JSC::MasqueradesAsUndefined"} = 1;
754 # Constructor object getter
755 push(@headerContent, " static JSC::JSValue getConstructor(JSC::ExecState*, JSC::JSGlobalObject*);\n") if (!($dataNode->extendedAttributes->{"OmitConstructor"} || $dataNode->extendedAttributes->{"CustomConstructor"}));
757 my $numCustomFunctions = 0;
758 my $numCustomAttributes = 0;
760 # Attribute and function enums
761 if ($numAttributes > 0) {
762 foreach (@{$dataNode->attributes}) {
764 $numCustomAttributes++ if $attribute->signature->extendedAttributes->{"Custom"} || $attribute->signature->extendedAttributes->{"JSCCustom"};
765 $numCustomAttributes++ if $attribute->signature->extendedAttributes->{"CustomGetter"} || $attribute->signature->extendedAttributes->{"JSCCustomGetter"};
766 $numCustomAttributes++ if $attribute->signature->extendedAttributes->{"CustomSetter"} || $attribute->signature->extendedAttributes->{"JSCCustomSetter"};
767 if ($attribute->signature->extendedAttributes->{"CachedAttribute"}) {
768 push(@headerContent, " static const unsigned " . $attribute->signature->name . "Slot = $numCachedAttributes + Base::AnonymousSlotCount;\n");
769 $numCachedAttributes++;
774 if ($numCachedAttributes > 0) {
775 push(@headerContent, " using $parentClassName" . "::putAnonymousValue;\n");
776 push(@headerContent, " using $parentClassName" . "::getAnonymousValue;\n");
778 if ($numCustomAttributes > 0) {
779 push(@headerContent, "\n // Custom attributes\n");
781 foreach my $attribute (@{$dataNode->attributes}) {
782 if ($attribute->signature->extendedAttributes->{"Custom"} || $attribute->signature->extendedAttributes->{"JSCCustom"}) {
783 push(@headerContent, " JSC::JSValue " . $codeGenerator->WK_lcfirst($attribute->signature->name) . "(JSC::ExecState*) const;\n");
784 if ($attribute->type !~ /^readonly/) {
785 push(@headerContent, " void set" . $codeGenerator->WK_ucfirst($attribute->signature->name) . "(JSC::ExecState*, JSC::JSValue);\n");
787 } elsif ($attribute->signature->extendedAttributes->{"CustomGetter"} || $attribute->signature->extendedAttributes->{"JSCCustomGetter"}) {
788 push(@headerContent, " JSC::JSValue " . $codeGenerator->WK_lcfirst($attribute->signature->name) . "(JSC::ExecState*) const;\n");
789 } elsif ($attribute->signature->extendedAttributes->{"CustomSetter"} || $attribute->signature->extendedAttributes->{"JSCCustomSetter"}) {
790 if ($attribute->type !~ /^readonly/) {
791 push(@headerContent, " void set" . $codeGenerator->WK_ucfirst($attribute->signature->name) . "(JSC::ExecState*, JSC::JSValue);\n");
797 foreach my $function (@{$dataNode->functions}) {
798 $numCustomFunctions++ if $function->signature->extendedAttributes->{"Custom"} || $function->signature->extendedAttributes->{"JSCCustom"};
801 if ($numCustomFunctions > 0) {
802 push(@headerContent, "\n // Custom functions\n");
803 foreach my $function (@{$dataNode->functions}) {
804 if ($function->signature->extendedAttributes->{"Custom"} || $function->signature->extendedAttributes->{"JSCCustom"}) {
805 my $functionImplementationName = $function->signature->extendedAttributes->{"ImplementationFunction"} || $codeGenerator->WK_lcfirst($function->signature->name);
806 push(@headerContent, " JSC::JSValue " . $functionImplementationName . "(JSC::ExecState*, const JSC::ArgList&);\n");
812 # Extra space after JSSVGPODTypeWrapper<> to make RefPtr<Wrapper<> > compile.
813 my $implType = $podType ? "JSSVGPODTypeWrapper<$podType> " : $implClassName;
814 push(@headerContent, " $implType* impl() const { return m_impl.get(); }\n\n");
815 push(@headerContent, "private:\n");
816 push(@headerContent, " RefPtr<$implType> m_impl;\n");
817 } elsif ($dataNode->extendedAttributes->{"GenerateNativeConverter"}) {
818 push(@headerContent, " $implClassName* impl() const\n");
819 push(@headerContent, " {\n");
820 push(@headerContent, " return static_cast<$implClassName*>(Base::impl());\n");
821 push(@headerContent, " }\n");
825 if ($numCachedAttributes) {
826 push(@headerContent, "public:\n");
827 push(@headerContent, " static const unsigned AnonymousSlotCount = $numCachedAttributes + Base::AnonymousSlotCount;\n");
831 push(@headerContent, "protected:\n");
832 push(@headerContent, " static const unsigned StructureFlags = ");
833 foreach my $structureFlag (keys %structureFlags) {
834 push(@headerContent, $structureFlag . " | ");
836 push(@headerContent, "Base::StructureFlags;\n");
839 if ($dataNode->extendedAttributes->{"HasIndexGetter"}) {
840 push(@headerContent, " static JSC::JSValue indexGetter(JSC::ExecState*, JSC::JSValue, unsigned);\n");
842 if ($dataNode->extendedAttributes->{"HasCustomIndexGetter"} || $dataNode->extendedAttributes->{"HasNumericIndexGetter"}) {
843 push(@headerContent, " JSC::JSValue getByIndex(JSC::ExecState*, unsigned index);\n");
848 if ($dataNode->extendedAttributes->{"HasCustomIndexSetter"}) {
849 push(@headerContent, " void indexSetter(JSC::ExecState*, unsigned index, JSC::JSValue);\n");
852 if ($dataNode->extendedAttributes->{"HasNameGetter"} || $dataNode->extendedAttributes->{"HasOverridingNameGetter"}) {
853 push(@headerContent, "private:\n");
854 push(@headerContent, " static bool canGetItemsForName(JSC::ExecState*, $implClassName*, const JSC::Identifier&);\n");
855 push(@headerContent, " static JSC::JSValue nameGetter(JSC::ExecState*, JSC::JSValue, const JSC::Identifier&);\n");
858 push(@headerContent, "};\n\n");
860 if ($dataNode->extendedAttributes->{"InlineGetOwnPropertySlot"} && !$dataNode->extendedAttributes->{"CustomGetOwnPropertySlot"}) {
861 push(@headerContent, "ALWAYS_INLINE bool ${className}::getOwnPropertySlot(JSC::ExecState* exec, const JSC::Identifier& propertyName, JSC::PropertySlot& slot)\n");
862 push(@headerContent, "{\n");
863 push(@headerContent, GenerateGetOwnPropertySlotBody($dataNode, $interfaceName, $className, $implClassName, $numAttributes > 0, 1));
864 push(@headerContent, "}\n\n");
865 push(@headerContent, "ALWAYS_INLINE bool ${className}::getOwnPropertyDescriptor(JSC::ExecState* exec, const JSC::Identifier& propertyName, JSC::PropertyDescriptor& descriptor)\n");
866 push(@headerContent, "{\n");
867 push(@headerContent, GenerateGetOwnPropertyDescriptorBody($dataNode, $interfaceName, $className, $implClassName, $numAttributes > 0, 1));
868 push(@headerContent, "}\n\n");
871 if (!$hasParent || $dataNode->extendedAttributes->{"GenerateToJS"} || $dataNode->extendedAttributes->{"CustomToJS"}) {
873 push(@headerContent, "JSC::JSValue toJS(JSC::ExecState*, JSDOMGlobalObject*, JSSVGPODTypeWrapper<$podType>*, SVGElement*);\n");
874 } elsif (IsSVGTypeNeedingContextParameter($implClassName)) {
875 push(@headerContent, "JSC::JSValue toJS(JSC::ExecState*, JSDOMGlobalObject*, $implType*, SVGElement* context);\n");
877 push(@headerContent, "JSC::JSValue toJS(JSC::ExecState*, JSDOMGlobalObject*, $implType*);\n");
880 if (!$hasParent || $dataNode->extendedAttributes->{"GenerateNativeConverter"}) {
882 push(@headerContent, "$podType to${interfaceName}(JSC::JSValue);\n");
883 } elsif ($interfaceName eq "NodeFilter") {
884 push(@headerContent, "PassRefPtr<NodeFilter> toNodeFilter(JSC::JSValue);\n");
886 push(@headerContent, "$implClassName* to${interfaceName}(JSC::JSValue);\n");
889 if ($interfaceName eq "Node" or $interfaceName eq "Element" or $interfaceName eq "Text" or $interfaceName eq "CDATASection") {
890 push(@headerContent, "JSC::JSValue toJSNewlyCreated(JSC::ExecState*, JSDOMGlobalObject*, $interfaceName*);\n");
893 push(@headerContent, "\n");
895 # Add prototype declaration.
896 %structureFlags = ();
897 push(@headerContent, "class ${className}Prototype : public JSC::JSObject {\n");
898 push(@headerContent, " typedef JSC::JSObject Base;\n");
899 push(@headerContent, "public:\n");
900 if ($interfaceName eq "DOMWindow") {
901 push(@headerContent, " void* operator new(size_t);\n");
902 } elsif ($dataNode->extendedAttributes->{"IsWorkerContext"}) {
903 push(@headerContent, " void* operator new(size_t, JSC::JSGlobalData*);\n");
905 push(@headerContent, " static JSC::JSObject* self(JSC::ExecState*, JSC::JSGlobalObject*);\n");
907 push(@headerContent, " virtual const JSC::ClassInfo* classInfo() const { return &s_info; }\n");
908 push(@headerContent, " static const JSC::ClassInfo s_info;\n");
909 if ($numFunctions > 0 || $numConstants > 0 || $dataNode->extendedAttributes->{"DelegatingPrototypeGetOwnPropertySlot"}) {
910 push(@headerContent, " virtual bool getOwnPropertySlot(JSC::ExecState*, const JSC::Identifier&, JSC::PropertySlot&);\n");
911 push(@headerContent, " virtual bool getOwnPropertyDescriptor(JSC::ExecState*, const JSC::Identifier&, JSC::PropertyDescriptor&);\n");
912 push(@headerContent, " bool getOwnPropertySlotDelegate(JSC::ExecState*, const JSC::Identifier&, JSC::PropertySlot&);\n") if $dataNode->extendedAttributes->{"DelegatingPrototypeGetOwnPropertySlot"};
913 push(@headerContent, " bool getOwnPropertyDescriptorDelegate(JSC::ExecState*, const JSC::Identifier&, JSC::PropertyDescriptor&);\n") if $dataNode->extendedAttributes->{"DelegatingPrototypeGetOwnPropertySlot"};
914 $structureFlags{"JSC::OverridesGetOwnPropertySlot"} = 1;
916 if ($dataNode->extendedAttributes->{"CustomMarkFunction"} or $needsMarkChildren) {
917 $structureFlags{"JSC::OverridesMarkChildren"} = 1;
920 " static PassRefPtr<JSC::Structure> createStructure(JSC::JSValue prototype)\n" .
922 " return JSC::Structure::create(prototype, JSC::TypeInfo(JSC::ObjectType, StructureFlags), AnonymousSlotCount);\n" .
924 if ($dataNode->extendedAttributes->{"DelegatingPrototypePutFunction"}) {
925 push(@headerContent, " virtual void put(JSC::ExecState*, const JSC::Identifier& propertyName, JSC::JSValue, JSC::PutPropertySlot&);\n");
926 push(@headerContent, " bool putDelegate(JSC::ExecState*, const JSC::Identifier&, JSC::JSValue, JSC::PutPropertySlot&);\n");
929 # Custom defineGetter function
930 push(@headerContent, " virtual void defineGetter(JSC::ExecState*, const JSC::Identifier& propertyName, JSC::JSObject* getterFunction, unsigned attributes);\n") if $dataNode->extendedAttributes->{"CustomPrototypeDefineGetter"};
932 push(@headerContent, " ${className}Prototype(NonNullPassRefPtr<JSC::Structure> structure) : JSC::JSObject(structure) { }\n");
935 push(@headerContent, "protected:\n");
936 push(@headerContent, " static const unsigned StructureFlags = ");
937 foreach my $structureFlag (keys %structureFlags) {
938 push(@headerContent, $structureFlag . " | ");
940 push(@headerContent, "Base::StructureFlags;\n");
942 push(@headerContent, "};\n\n");
944 if ($numFunctions > 0) {
945 push(@headerContent,"// Functions\n\n");
946 foreach my $function (@{$dataNode->functions}) {
947 my $functionName = $codeGenerator->WK_lcfirst($className) . "PrototypeFunction" . $codeGenerator->WK_ucfirst($function->signature->name);
948 push(@headerContent, "JSC::JSValue JSC_HOST_CALL ${functionName}(JSC::ExecState*, JSC::JSObject*, JSC::JSValue, const JSC::ArgList&);\n");
952 if ($numAttributes > 0 || !($dataNode->extendedAttributes->{"OmitConstructor"} || $dataNode->extendedAttributes->{"CustomConstructor"})) {
953 push(@headerContent,"// Attributes\n\n");
954 foreach my $attribute (@{$dataNode->attributes}) {
955 my $getter = "js" . $interfaceName . $codeGenerator->WK_ucfirst($attribute->signature->name) . ($attribute->signature->type =~ /Constructor$/ ? "Constructor" : "");
956 push(@headerContent, "JSC::JSValue ${getter}(JSC::ExecState*, JSC::JSValue, const JSC::Identifier&);\n");
957 unless ($attribute->type =~ /readonly/) {
958 my $setter = "setJS" . $interfaceName . $codeGenerator->WK_ucfirst($attribute->signature->name) . ($attribute->signature->type =~ /Constructor$/ ? "Constructor" : "");
959 push(@headerContent, "void ${setter}(JSC::ExecState*, JSC::JSObject*, JSC::JSValue);\n");
963 if (!($dataNode->extendedAttributes->{"OmitConstructor"} || $dataNode->extendedAttributes->{"CustomConstructor"})) {
964 my $getter = "js" . $interfaceName . "Constructor";
965 push(@headerContent, "JSC::JSValue ${getter}(JSC::ExecState*, JSC::JSValue, const JSC::Identifier&);\n");
969 if ($numConstants > 0) {
970 push(@headerContent,"// Constants\n\n");
971 foreach my $constant (@{$dataNode->constants}) {
972 my $getter = "js" . $interfaceName . $codeGenerator->WK_ucfirst($constant->name);
973 push(@headerContent, "JSC::JSValue ${getter}(JSC::ExecState*, JSC::JSValue, const JSC::Identifier&);\n");
977 my $conditionalString = GenerateConditionalString($dataNode);
978 push(@headerContent, "\n} // namespace WebCore\n\n");
979 push(@headerContent, "#endif // ${conditionalString}\n\n") if $conditionalString;
980 push(@headerContent, "#endif\n");
982 # - Generate dependencies.
983 if ($writeDependencies && @ancestorInterfaceNames) {
984 push(@depsContent, "$className.h : ", join(" ", map { "$_.idl" } @ancestorInterfaceNames), "\n");
985 push(@depsContent, map { "$_.idl :\n" } @ancestorInterfaceNames);
989 sub GenerateAttributesHashTable($$)
991 my ($object, $dataNode) = @_;
993 # FIXME: These should be functions on $dataNode.
994 my $interfaceName = $dataNode->name;
995 my $className = "JS$interfaceName";
997 # - Add all attributes in a hashtable definition
998 my $numAttributes = @{$dataNode->attributes};
999 $numAttributes++ if (!($dataNode->extendedAttributes->{"OmitConstructor"} || $dataNode->extendedAttributes->{"CustomConstructor"}));
1001 return 0 if !$numAttributes;
1003 my $hashSize = $numAttributes;
1004 my $hashName = $className . "Table";
1007 my @hashSpecials = ();
1008 my @hashValue1 = ();
1009 my @hashValue2 = ();
1010 my %conditionals = ();
1014 foreach my $attribute (@{$dataNode->attributes}) {
1015 my $name = $attribute->signature->name;
1016 push(@hashKeys, $name);
1019 push(@specials, "DontDelete") unless $attribute->signature->extendedAttributes->{"Deletable"};
1020 push(@specials, "DontEnum") if $attribute->signature->extendedAttributes->{"DontEnum"};
1021 push(@specials, "ReadOnly") if $attribute->type =~ /readonly/;
1022 my $special = (@specials > 0) ? join("|", @specials) : "0";
1023 push(@hashSpecials, $special);
1025 my $getter = "js" . $interfaceName . $codeGenerator->WK_ucfirst($attribute->signature->name) . ($attribute->signature->type =~ /Constructor$/ ? "Constructor" : "");
1026 push(@hashValue1, $getter);
1028 if ($attribute->type =~ /readonly/) {
1029 push(@hashValue2, "0");
1031 my $setter = "setJS" . $interfaceName . $codeGenerator->WK_ucfirst($attribute->signature->name) . ($attribute->signature->type =~ /Constructor$/ ? "Constructor" : "");
1032 push(@hashValue2, $setter);
1035 my $conditional = $attribute->signature->extendedAttributes->{"Conditional"};
1037 $conditionals{$name} = $conditional;
1041 if (!($dataNode->extendedAttributes->{"OmitConstructor"} || $dataNode->extendedAttributes->{"CustomConstructor"})) {
1042 push(@hashKeys, "constructor");
1043 my $getter = "js" . $interfaceName . "Constructor";
1044 push(@hashValue1, $getter);
1045 push(@hashValue2, "0");
1046 push(@hashSpecials, "DontEnum|ReadOnly"); # FIXME: Setting the constructor should be possible.
1049 $object->GenerateHashTable($hashName, $hashSize,
1050 \@hashKeys, \@hashSpecials,
1051 \@hashValue1, \@hashValue2,
1053 return $numAttributes;
1056 sub GenerateImplementation
1058 my ($object, $dataNode) = @_;
1060 my $interfaceName = $dataNode->name;
1061 my $className = "JS$interfaceName";
1062 my $implClassName = $interfaceName;
1064 my $hasLegacyParent = $dataNode->extendedAttributes->{"LegacyParent"};
1065 my $hasRealParent = @{$dataNode->parents} > 0;
1066 my $hasParent = $hasLegacyParent || $hasRealParent;
1067 my $parentClassName = GetParentClassName($dataNode);
1068 my $visibleClassName = GetVisibleClassName($interfaceName);
1069 my $eventTarget = $dataNode->extendedAttributes->{"EventTarget"};
1070 my $needsMarkChildren = $dataNode->extendedAttributes->{"CustomMarkFunction"} || $dataNode->extendedAttributes->{"EventTarget"};
1072 # - Add default header template
1073 push(@implContentHeader, GenerateImplementationContentHeader($dataNode));
1075 AddIncludesForSVGAnimatedType($interfaceName) if $className =~ /^JSSVGAnimated/;
1077 $implIncludes{"<wtf/GetPtr.h>"} = 1;
1078 $implIncludes{"<runtime/PropertyNameArray.h>"} = 1 if $dataNode->extendedAttributes->{"HasIndexGetter"} || $dataNode->extendedAttributes->{"HasCustomIndexGetter"} || $dataNode->extendedAttributes->{"HasNumericIndexGetter"};
1080 AddIncludesForType($interfaceName);
1084 push(@implContent, "\nusing namespace JSC;\n\n");
1085 push(@implContent, "namespace WebCore {\n\n");
1087 push(@implContent, "ASSERT_CLASS_FITS_IN_CELL($className);\n\n");
1089 my $numAttributes = GenerateAttributesHashTable($object, $dataNode);
1091 my $numConstants = @{$dataNode->constants};
1092 my $numFunctions = @{$dataNode->functions};
1094 # - Add all constants
1095 if (!($dataNode->extendedAttributes->{"OmitConstructor"} || $dataNode->extendedAttributes->{"CustomConstructor"})) {
1096 $hashSize = $numConstants;
1097 $hashName = $className . "ConstructorTable";
1104 # FIXME: we should not need a function for every constant.
1105 foreach my $constant (@{$dataNode->constants}) {
1106 push(@hashKeys, $constant->name);
1107 my $getter = "js" . $interfaceName . $codeGenerator->WK_ucfirst($constant->name);
1108 push(@hashValue1, $getter);
1109 push(@hashValue2, "0");
1110 push(@hashSpecials, "DontDelete|ReadOnly");
1113 $object->GenerateHashTable($hashName, $hashSize,
1114 \@hashKeys, \@hashSpecials,
1115 \@hashValue1, \@hashValue2);
1118 $protoClassName = "${className}Prototype";
1120 push(@implContent, constructorFor($className, $protoClassName, $interfaceName, $visibleClassName, $dataNode));
1123 # - Add functions and constants to a hashtable definition
1124 $hashSize = $numFunctions + $numConstants;
1125 $hashName = $className . "PrototypeTable";
1132 # FIXME: we should not need a function for every constant.
1133 foreach my $constant (@{$dataNode->constants}) {
1134 push(@hashKeys, $constant->name);
1135 my $getter = "js" . $interfaceName . $codeGenerator->WK_ucfirst($constant->name);
1136 push(@hashValue1, $getter);
1137 push(@hashValue2, "0");
1138 push(@hashSpecials, "DontDelete|ReadOnly");
1141 foreach my $function (@{$dataNode->functions}) {
1142 my $name = $function->signature->name;
1143 push(@hashKeys, $name);
1145 my $value = $codeGenerator->WK_lcfirst($className) . "PrototypeFunction" . $codeGenerator->WK_ucfirst($name);
1146 push(@hashValue1, $value);
1148 my $numParameters = @{$function->parameters};
1149 push(@hashValue2, $numParameters);
1152 push(@specials, "DontDelete") unless $function->signature->extendedAttributes->{"Deletable"};
1153 push(@specials, "DontEnum") if $function->signature->extendedAttributes->{"DontEnum"};
1154 push(@specials, "Function");
1155 my $special = (@specials > 0) ? join("|", @specials) : "0";
1156 push(@hashSpecials, $special);
1159 $object->GenerateHashTable($hashName, $hashSize,
1160 \@hashKeys, \@hashSpecials,
1161 \@hashValue1, \@hashValue2);
1163 if ($dataNode->extendedAttributes->{"NoStaticTables"}) {
1164 push(@implContent, "static const HashTable* get${className}PrototypeTable(ExecState* exec)\n");
1165 push(@implContent, "{\n");
1166 push(@implContent, " return getHashTableForGlobalData(exec->globalData(), &${className}PrototypeTable);\n");
1167 push(@implContent, "}\n");
1168 push(@implContent, "const ClassInfo ${className}Prototype::s_info = { \"${visibleClassName}Prototype\", 0, 0, get${className}PrototypeTable };\n\n");
1170 push(@implContent, "const ClassInfo ${className}Prototype::s_info = { \"${visibleClassName}Prototype\", 0, &${className}PrototypeTable, 0 };\n\n");
1172 if ($interfaceName eq "DOMWindow") {
1173 push(@implContent, "void* ${className}Prototype::operator new(size_t size)\n");
1174 push(@implContent, "{\n");
1175 push(@implContent, " return JSDOMWindow::commonJSGlobalData()->heap.allocate(size);\n");
1176 push(@implContent, "}\n\n");
1177 } elsif ($dataNode->extendedAttributes->{"IsWorkerContext"}) {
1178 push(@implContent, "void* ${className}Prototype::operator new(size_t size, JSGlobalData* globalData)\n");
1179 push(@implContent, "{\n");
1180 push(@implContent, " return globalData->heap.allocate(size);\n");
1181 push(@implContent, "}\n\n");
1183 push(@implContent, "JSObject* ${className}Prototype::self(ExecState* exec, JSGlobalObject* globalObject)\n");
1184 push(@implContent, "{\n");
1185 push(@implContent, " return getDOMPrototype<${className}>(exec, globalObject);\n");
1186 push(@implContent, "}\n\n");
1188 if ($numConstants > 0 || $numFunctions > 0 || $dataNode->extendedAttributes->{"DelegatingPrototypeGetOwnPropertySlot"}) {
1189 push(@implContent, "bool ${className}Prototype::getOwnPropertySlot(ExecState* exec, const Identifier& propertyName, PropertySlot& slot)\n");
1190 push(@implContent, "{\n");
1192 if ($dataNode->extendedAttributes->{"DelegatingPrototypeGetOwnPropertySlot"}) {
1193 push(@implContent, " if (getOwnPropertySlotDelegate(exec, propertyName, slot))\n");
1194 push(@implContent, " return true;\n");
1197 if ($numConstants eq 0 && $numFunctions eq 0) {
1198 push(@implContent, " return Base::getOwnPropertySlot(exec, propertyName, slot);\n");
1199 } elsif ($numConstants eq 0) {
1200 push(@implContent, " return getStaticFunctionSlot<JSObject>(exec, " . prototypeHashTableAccessor($dataNode->extendedAttributes->{"NoStaticTables"}, $className) . ", this, propertyName, slot);\n");
1201 } elsif ($numFunctions eq 0) {
1202 push(@implContent, " return getStaticValueSlot<${className}Prototype, JSObject>(exec, " . prototypeHashTableAccessor($dataNode->extendedAttributes->{"NoStaticTables"}, $className) . ", this, propertyName, slot);\n");
1204 push(@implContent, " return getStaticPropertySlot<${className}Prototype, JSObject>(exec, " . prototypeHashTableAccessor($dataNode->extendedAttributes->{"NoStaticTables"}, $className) . ", this, propertyName, slot);\n");
1206 push(@implContent, "}\n\n");
1208 push(@implContent, "bool ${className}Prototype::getOwnPropertyDescriptor(ExecState* exec, const Identifier& propertyName, PropertyDescriptor& descriptor)\n");
1209 push(@implContent, "{\n");
1211 if ($dataNode->extendedAttributes->{"DelegatingPrototypeGetOwnPropertySlot"}) {
1212 push(@implContent, " if (getOwnPropertyDescriptorDelegate(exec, propertyName, descriptor))\n");
1213 push(@implContent, " return true;\n");
1216 if ($numConstants eq 0 && $numFunctions eq 0) {
1217 push(@implContent, " return Base::getOwnPropertyDescriptor(exec, propertyName, descriptor);\n");
1218 } elsif ($numConstants eq 0) {
1219 push(@implContent, " return getStaticFunctionDescriptor<JSObject>(exec, " . prototypeHashTableAccessor($dataNode->extendedAttributes->{"NoStaticTables"}, $className) . ", this, propertyName, descriptor);\n");
1220 } elsif ($numFunctions eq 0) {
1221 push(@implContent, " return getStaticValueDescriptor<${className}Prototype, JSObject>(exec, " . prototypeHashTableAccessor($dataNode->extendedAttributes->{"NoStaticTables"}, $className) . ", this, propertyName, descriptor);\n");
1223 push(@implContent, " return getStaticPropertyDescriptor<${className}Prototype, JSObject>(exec, " . prototypeHashTableAccessor($dataNode->extendedAttributes->{"NoStaticTables"}, $className) . ", this, propertyName, descriptor);\n");
1225 push(@implContent, "}\n\n");
1228 if ($dataNode->extendedAttributes->{"DelegatingPrototypePutFunction"}) {
1229 push(@implContent, "void ${className}Prototype::put(ExecState* exec, const Identifier& propertyName, JSValue value, PutPropertySlot& slot)\n");
1230 push(@implContent, "{\n");
1231 push(@implContent, " if (putDelegate(exec, propertyName, value, slot))\n");
1232 push(@implContent, " return;\n");
1233 push(@implContent, " Base::put(exec, propertyName, value, slot);\n");
1234 push(@implContent, "}\n\n");
1237 # - Initialize static ClassInfo object
1238 if ($numAttributes > 0 && $dataNode->extendedAttributes->{"NoStaticTables"}) {
1239 push(@implContent, "static const HashTable* get${className}Table(ExecState* exec)\n");
1240 push(@implContent, "{\n");
1241 push(@implContent, " return getHashTableForGlobalData(exec->globalData(), &${className}Table);\n");
1242 push(@implContent, "}\n");
1244 push(@implContent, "const ClassInfo $className" . "::s_info = { \"${visibleClassName}\", ");
1246 push(@implContent, "&" . $parentClassName . "::s_info, ");
1248 push(@implContent, "0, ");
1251 if ($numAttributes > 0 && !$dataNode->extendedAttributes->{"NoStaticTables"}) {
1252 push(@implContent, "&${className}Table");
1254 push(@implContent, "0");
1256 if ($numAttributes > 0 && $dataNode->extendedAttributes->{"NoStaticTables"}) {
1257 push(@implContent, ", get${className}Table ");
1259 push(@implContent, ", 0 ");
1261 push(@implContent, "};\n\n");
1263 # Get correct pass/store types respecting PODType flag
1264 my $podType = $dataNode->extendedAttributes->{"PODType"};
1265 my $implType = $podType ? "JSSVGPODTypeWrapper<$podType> " : $implClassName;
1268 if ($interfaceName eq "DOMWindow") {
1269 AddIncludesForType("JSDOMWindowShell");
1270 push(@implContent, "${className}::$className(NonNullPassRefPtr<Structure> structure, PassRefPtr<$implType> impl, JSDOMWindowShell* shell)\n");
1271 push(@implContent, " : $parentClassName(structure, impl, shell)\n");
1272 } elsif ($dataNode->extendedAttributes->{"IsWorkerContext"}) {
1273 AddIncludesForType($interfaceName);
1274 push(@implContent, "${className}::$className(NonNullPassRefPtr<Structure> structure, PassRefPtr<$implType> impl)\n");
1275 push(@implContent, " : $parentClassName(structure, impl)\n");
1277 push(@implContent, "${className}::$className(NonNullPassRefPtr<Structure> structure, JSDOMGlobalObject* globalObject, PassRefPtr<$implType> impl)\n");
1279 push(@implContent, " : $parentClassName(structure, globalObject, impl)\n");
1281 push(@implContent, " : $parentClassName(structure, globalObject)\n");
1282 push(@implContent, " , m_impl(impl)\n");
1285 push(@implContent, "{\n");
1286 if ($numCachedAttributes > 0) {
1287 push(@implContent, " for (unsigned i = Base::AnonymousSlotCount; i < AnonymousSlotCount; i++)\n");
1288 push(@implContent, " putAnonymousValue(i, JSValue());\n");
1290 push(@implContent, "}\n\n");
1293 if (!$hasParent || $eventTarget) {
1294 push(@implContent, "${className}::~$className()\n");
1295 push(@implContent, "{\n");
1298 $implIncludes{"RegisteredEventListener.h"} = 1;
1299 push(@implContent, " impl()->invalidateJSEventListeners(this);\n");
1302 if (!$dataNode->extendedAttributes->{"ExtendsDOMGlobalObject"}) {
1303 if ($interfaceName eq "Node") {
1304 push(@implContent, " forgetDOMNode(this, impl(), impl()->document());\n");
1306 push(@implContent, " forgetDOMObject(this, impl());\n");
1309 push(@implContent, " JSSVGContextCache::forgetWrapper(this);\n") if IsSVGTypeNeedingContextParameter($implClassName);
1312 push(@implContent, "}\n\n");
1315 if ($needsMarkChildren && !$dataNode->extendedAttributes->{"CustomMarkFunction"}) {
1316 push(@implContent, "void ${className}::markChildren(MarkStack& markStack)\n");
1317 push(@implContent, "{\n");
1318 push(@implContent, " Base::markChildren(markStack);\n");
1319 push(@implContent, " impl()->markJSEventListeners(markStack);\n");
1320 push(@implContent, "}\n\n");
1323 if (!$dataNode->extendedAttributes->{"ExtendsDOMGlobalObject"}) {
1324 push(@implContent, "JSObject* ${className}::createPrototype(ExecState* exec, JSGlobalObject* globalObject)\n");
1325 push(@implContent, "{\n");
1326 if ($hasParent && $parentClassName ne "JSC::DOMNodeFilter") {
1327 push(@implContent, " return new (exec) ${className}Prototype(${className}Prototype::createStructure(${parentClassName}Prototype::self(exec, globalObject)));\n");
1329 push(@implContent, " return new (exec) ${className}Prototype(${className}Prototype::createStructure(globalObject->objectPrototype()));\n");
1331 push(@implContent, "}\n\n");
1334 my $hasGetter = $numAttributes > 0
1335 || !($dataNode->extendedAttributes->{"OmitConstructor"}
1336 || $dataNode->extendedAttributes->{"CustomConstructor"})
1337 || $dataNode->extendedAttributes->{"HasIndexGetter"}
1338 || $dataNode->extendedAttributes->{"HasCustomIndexGetter"}
1339 || $dataNode->extendedAttributes->{"HasNumericIndexGetter"}
1340 || $dataNode->extendedAttributes->{"DelegatingGetOwnPropertySlot"}
1341 || $dataNode->extendedAttributes->{"CustomGetOwnPropertySlot"}
1342 || $dataNode->extendedAttributes->{"HasNameGetter"}
1343 || $dataNode->extendedAttributes->{"HasOverridingNameGetter"};
1347 if (!$dataNode->extendedAttributes->{"InlineGetOwnPropertySlot"} && !$dataNode->extendedAttributes->{"CustomGetOwnPropertySlot"}) {
1348 push(@implContent, "bool ${className}::getOwnPropertySlot(ExecState* exec, const Identifier& propertyName, PropertySlot& slot)\n");
1349 push(@implContent, "{\n");
1350 push(@implContent, GenerateGetOwnPropertySlotBody($dataNode, $interfaceName, $className, $implClassName, $numAttributes > 0, 0));
1351 push(@implContent, "}\n\n");
1352 push(@implContent, "bool ${className}::getOwnPropertyDescriptor(ExecState* exec, const Identifier& propertyName, PropertyDescriptor& descriptor)\n");
1353 push(@implContent, "{\n");
1354 push(@implContent, GenerateGetOwnPropertyDescriptorBody($dataNode, $interfaceName, $className, $implClassName, $numAttributes > 0, 0));
1355 push(@implContent, "}\n\n");
1358 if (($dataNode->extendedAttributes->{"HasIndexGetter"} || $dataNode->extendedAttributes->{"HasCustomIndexGetter"} || $dataNode->extendedAttributes->{"HasNumericIndexGetter"})
1359 && !$dataNode->extendedAttributes->{"HasOverridingNameGetter"}) {
1360 push(@implContent, "bool ${className}::getOwnPropertySlot(ExecState* exec, unsigned propertyName, PropertySlot& slot)\n");
1361 push(@implContent, "{\n");
1362 push(@implContent, " if (propertyName < static_cast<$implClassName*>(impl())->length()) {\n");
1363 if ($dataNode->extendedAttributes->{"HasCustomIndexGetter"} || $dataNode->extendedAttributes->{"HasNumericIndexGetter"}) {
1364 push(@implContent, " slot.setValue(getByIndex(exec, propertyName));\n");
1366 push(@implContent, " slot.setCustomIndex(this, propertyName, indexGetter);\n");
1368 push(@implContent, " return true;\n");
1369 push(@implContent, " }\n");
1370 push(@implContent, " return getOwnPropertySlot(exec, Identifier::from(exec, propertyName), slot);\n");
1371 push(@implContent, "}\n\n");
1374 if ($numAttributes > 0) {
1375 foreach my $attribute (@{$dataNode->attributes}) {
1376 my $name = $attribute->signature->name;
1377 my $type = $codeGenerator->StripModule($attribute->signature->type);
1378 my $getFunctionName = "js" . $interfaceName . $codeGenerator->WK_ucfirst($attribute->signature->name) . ($attribute->signature->type =~ /Constructor$/ ? "Constructor" : "");
1379 my $implGetterFunctionName = $codeGenerator->WK_lcfirst($name);
1381 my $attributeConditionalString = GenerateConditionalString($attribute->signature);
1382 push(@implContent, "#if ${attributeConditionalString}\n") if $attributeConditionalString;
1384 push(@implContent, "JSValue ${getFunctionName}(ExecState* exec, JSValue slotBase, const Identifier&)\n");
1385 push(@implContent, "{\n");
1386 push(@implContent, " ${className}* castedThis = static_cast<$className*>(asObject(slotBase));\n");
1388 my $implClassNameForValueConversion = "";
1389 if (!$podType and ($codeGenerator->IsSVGAnimatedType($implClassName) or $attribute->type !~ /^readonly/)) {
1390 $implClassNameForValueConversion = $implClassName;
1393 if ($dataNode->extendedAttributes->{"CheckDomainSecurity"} &&
1394 !$attribute->signature->extendedAttributes->{"DoNotCheckDomainSecurity"} &&
1395 !$attribute->signature->extendedAttributes->{"DoNotCheckDomainSecurityOnGet"}) {
1396 push(@implContent, " if (!castedThis->allowsAccessFrom(exec))\n");
1397 push(@implContent, " return jsUndefined();\n");
1400 if ($attribute->signature->extendedAttributes->{"Custom"} || $attribute->signature->extendedAttributes->{"JSCCustom"} || $attribute->signature->extendedAttributes->{"CustomGetter"} || $attribute->signature->extendedAttributes->{"JSCCustomGetter"}) {
1401 push(@implContent, " return castedThis->$implGetterFunctionName(exec);\n");
1402 } elsif ($attribute->signature->extendedAttributes->{"CheckNodeSecurity"}) {
1403 $implIncludes{"JSDOMBinding.h"} = 1;
1404 push(@implContent, " $implClassName* imp = static_cast<$implClassName*>(castedThis->impl());\n");
1405 push(@implContent, " return checkNodeSecurity(exec, imp->$implGetterFunctionName()) ? " . NativeToJSValue($attribute->signature, 0, $implClassName, $implClassNameForValueConversion, "imp->$implGetterFunctionName()", "castedThis") . " : jsUndefined();\n");
1406 } elsif ($attribute->signature->extendedAttributes->{"CheckFrameSecurity"}) {
1407 $implIncludes{"Document.h"} = 1;
1408 $implIncludes{"JSDOMBinding.h"} = 1;
1409 push(@implContent, " $implClassName* imp = static_cast<$implClassName*>(castedThis->impl());\n");
1410 push(@implContent, " return checkNodeSecurity(exec, imp->contentDocument()) ? " . NativeToJSValue($attribute->signature, 0, $implClassName, $implClassNameForValueConversion, "imp->$implGetterFunctionName()", "castedThis") . " : jsUndefined();\n");
1411 } elsif ($type eq "EventListener") {
1412 $implIncludes{"EventListener.h"} = 1;
1413 push(@implContent, " UNUSED_PARAM(exec);\n");
1414 push(@implContent, " $implClassName* imp = static_cast<$implClassName*>(castedThis->impl());\n");
1415 push(@implContent, " if (EventListener* listener = imp->$implGetterFunctionName()) {\n");
1416 push(@implContent, " if (const JSEventListener* jsListener = JSEventListener::cast(listener)) {\n");
1417 if ($implClassName eq "Document" || $implClassName eq "WorkerContext" || $implClassName eq "SharedWorkerContext" || $implClassName eq "DedicatedWorkerContext") {
1418 push(@implContent, " if (JSObject* jsFunction = jsListener->jsFunction(imp))\n");
1420 push(@implContent, " if (JSObject* jsFunction = jsListener->jsFunction(imp->scriptExecutionContext()))\n");
1422 push(@implContent, " return jsFunction;\n");
1423 push(@implContent, " }\n");
1424 push(@implContent, " }\n");
1425 push(@implContent, " return jsNull();\n");
1426 } elsif ($attribute->signature->type =~ /Constructor$/) {
1427 my $constructorType = $codeGenerator->StripModule($attribute->signature->type);
1428 $constructorType =~ s/Constructor$//;
1429 # Constructor attribute is only used by DOMWindow.idl, so it's correct to pass castedThis as the global object
1430 # Once DOMObjects have a back-pointer to the globalObject we can pass castedThis->globalObject()
1431 push(@implContent, " return JS" . $constructorType . "::getConstructor(exec, castedThis);\n");
1432 } elsif (!@{$attribute->getterExceptions}) {
1433 push(@implContent, " UNUSED_PARAM(exec);\n");
1435 if ($attribute->signature->extendedAttributes->{"CachedAttribute"}) {
1436 $cacheIndex = $currentCachedAttribute;
1437 $currentCachedAttribute++;
1438 push(@implContent, " if (JSValue cachedValue = castedThis->getAnonymousValue(" . $className . "::" . $attribute->signature->name . "Slot))\n");
1439 push(@implContent, " return cachedValue;\n");
1442 push(@implContent, " $podType imp(*castedThis->impl());\n");
1443 if ($podType eq "float") { # Special case for JSSVGNumber
1444 push(@implContent, " JSValue result = " . NativeToJSValue($attribute->signature, 0, $implClassName, "", "imp", "castedThis") . ";\n");
1446 push(@implContent, " JSValue result = " . NativeToJSValue($attribute->signature, 0, $implClassName, "", "imp.$implGetterFunctionName()", "castedThis") . ";\n");
1449 push(@implContent, " $implClassName* imp = static_cast<$implClassName*>(castedThis->impl());\n");
1451 my $reflect = $attribute->signature->extendedAttributes->{"Reflect"};
1452 my $reflectURL = $attribute->signature->extendedAttributes->{"ReflectURL"};
1453 if ($reflect || $reflectURL) {
1454 my $contentAttributeName = (($reflect || $reflectURL) eq "1") ? $name : ($reflect || $reflectURL);
1455 my $namespace = $codeGenerator->NamespaceForAttributeName($interfaceName, $contentAttributeName);
1456 $implIncludes{"${namespace}.h"} = 1;
1457 my $getAttributeFunctionName = $reflectURL ? "getURLAttribute" : "getAttribute";
1458 $value = "imp->$getAttributeFunctionName(${namespace}::${contentAttributeName}Attr)"
1460 $value = "imp->$implGetterFunctionName()";
1462 my $jsType = NativeToJSValue($attribute->signature, 0, $implClassName, $implClassNameForValueConversion, $value, "castedThis");
1463 if ($codeGenerator->IsSVGAnimatedType($type)) {
1464 push(@implContent, " RefPtr<$type> obj = $jsType;\n");
1465 push(@implContent, " JSValue result = toJS(exec, castedThis->globalObject(), obj.get(), imp);\n");
1467 push(@implContent, " JSValue result = $jsType;\n");
1471 push(@implContent, " castedThis->putAnonymousValue(" . $className . "::" . $attribute->signature->name . "Slot, result);\n") if ($attribute->signature->extendedAttributes->{"CachedAttribute"});
1472 push(@implContent, " return result;\n");
1475 push(@implContent, " ExceptionCode ec = 0;\n");
1477 push(@implContent, " $podType imp(*castedThis->impl());\n");
1478 push(@implContent, " JSC::JSValue result = " . NativeToJSValue($attribute->signature, 0, $implClassName, "", "imp.$implGetterFunctionName(ec)", "castedThis") . ";\n");
1480 push(@implContent, " $implClassName* imp = static_cast<$implClassName*>(castedThis->impl());\n");
1481 push(@implContent, " JSC::JSValue result = " . NativeToJSValue($attribute->signature, 0, $implClassName, $implClassNameForValueConversion, "imp->$implGetterFunctionName(ec)", "castedThis") . ";\n");
1484 push(@implContent, " setDOMException(exec, ec);\n");
1485 push(@implContent, " return result;\n");
1488 push(@implContent, "}\n");
1490 push(@implContent, "#endif\n") if $attributeConditionalString;
1492 push(@implContent, "\n");
1495 if (!($dataNode->extendedAttributes->{"OmitConstructor"} || $dataNode->extendedAttributes->{"CustomConstructor"})) {
1496 my $constructorFunctionName = "js" . $interfaceName . "Constructor";
1498 push(@implContent, "JSValue ${constructorFunctionName}(ExecState* exec, JSValue slotBase, const Identifier&)\n");
1499 push(@implContent, "{\n");
1500 push(@implContent, " ${className}* domObject = static_cast<$className*>(asObject(slotBase));\n");
1501 push(@implContent, " return ${className}::getConstructor(exec, domObject->globalObject());\n");
1502 push(@implContent, "}\n");
1506 # Check if we have any writable attributes
1507 my $hasReadWriteProperties = 0;
1508 foreach my $attribute (@{$dataNode->attributes}) {
1509 $hasReadWriteProperties = 1 if $attribute->type !~ /^readonly/;
1512 my $hasSetter = $hasReadWriteProperties
1513 || $dataNode->extendedAttributes->{"DelegatingPutFunction"}
1514 || $dataNode->extendedAttributes->{"HasCustomIndexSetter"};
1517 if (!$dataNode->extendedAttributes->{"CustomPutFunction"}) {
1518 push(@implContent, "void ${className}::put(ExecState* exec, const Identifier& propertyName, JSValue value, PutPropertySlot& slot)\n");
1519 push(@implContent, "{\n");
1520 if ($dataNode->extendedAttributes->{"HasCustomIndexSetter"}) {
1521 push(@implContent, " bool ok;\n");
1522 push(@implContent, " unsigned index = propertyName.toUInt32(&ok, false);\n");
1523 push(@implContent, " if (ok) {\n");
1524 push(@implContent, " indexSetter(exec, index, value);\n");
1525 push(@implContent, " return;\n");
1526 push(@implContent, " }\n");
1528 if ($dataNode->extendedAttributes->{"DelegatingPutFunction"}) {
1529 push(@implContent, " if (putDelegate(exec, propertyName, value, slot))\n");
1530 push(@implContent, " return;\n");
1533 if ($hasReadWriteProperties) {
1534 push(@implContent, " lookupPut<$className, Base>(exec, propertyName, value, " . hashTableAccessor($dataNode->extendedAttributes->{"NoStaticTables"}, $className) . ", this, slot);\n");
1536 push(@implContent, " Base::put(exec, propertyName, value, slot);\n");
1538 push(@implContent, "}\n\n");
1541 if ($dataNode->extendedAttributes->{"HasCustomIndexSetter"}) {
1542 push(@implContent, "void ${className}::put(ExecState* exec, unsigned propertyName, JSValue value)\n");
1543 push(@implContent, "{\n");
1544 push(@implContent, " indexSetter(exec, propertyName, value);\n");
1545 push(@implContent, " return;\n");
1546 push(@implContent, "}\n\n");
1549 if ($hasReadWriteProperties) {
1550 foreach my $attribute (@{$dataNode->attributes}) {
1551 if ($attribute->type !~ /^readonly/) {
1552 my $name = $attribute->signature->name;
1553 my $type = $codeGenerator->StripModule($attribute->signature->type);
1554 my $putFunctionName = "setJS" . $interfaceName . $codeGenerator->WK_ucfirst($name) . ($attribute->signature->type =~ /Constructor$/ ? "Constructor" : "");
1555 my $implSetterFunctionName = $codeGenerator->WK_ucfirst($name);
1557 my $attributeConditionalString = GenerateConditionalString($attribute->signature);
1558 push(@implContent, "#if ${attributeConditionalString}\n") if $attributeConditionalString;
1560 push(@implContent, "void ${putFunctionName}(ExecState* exec, JSObject* thisObject, JSValue value)\n");
1561 push(@implContent, "{\n");
1563 if ($dataNode->extendedAttributes->{"CheckDomainSecurity"} && !$attribute->signature->extendedAttributes->{"DoNotCheckDomainSecurity"}) {
1564 if ($interfaceName eq "DOMWindow") {
1565 push(@implContent, " if (!static_cast<$className*>(thisObject)->allowsAccessFrom(exec))\n");
1567 push(@implContent, " if (!allowsAccessFromFrame(exec, static_cast<$className*>(thisObject)->impl()->frame()))\n");
1569 push(@implContent, " return;\n");
1572 if ($attribute->signature->extendedAttributes->{"Custom"} || $attribute->signature->extendedAttributes->{"JSCCustom"} || $attribute->signature->extendedAttributes->{"CustomSetter"} || $attribute->signature->extendedAttributes->{"JSCCustomSetter"}) {
1573 push(@implContent, " static_cast<$className*>(thisObject)->set$implSetterFunctionName(exec, value);\n");
1574 } elsif ($type eq "EventListener") {
1575 $implIncludes{"JSEventListener.h"} = 1;
1576 push(@implContent, " UNUSED_PARAM(exec);\n");
1577 my $windowEventListener = $attribute->signature->extendedAttributes->{"WindowEventListener"};
1578 if ($windowEventListener) {
1579 push(@implContent, " ${className}* castedThis = static_cast<${className}*>(thisObject);\n");
1580 push(@implContent, " JSDOMGlobalObject* globalObject = castedThis->globalObject();\n");
1582 push(@implContent, " $implClassName* imp = static_cast<$implClassName*>(static_cast<$className*>(thisObject)->impl());\n");
1583 if ($interfaceName eq "WorkerContext" and $name eq "onerror") {
1584 $implIncludes{"JSWorkerContextErrorHandler.h"} = 1;
1585 push(@implContent, " imp->set$implSetterFunctionName(createJSWorkerContextErrorHandler(exec, value, thisObject));\n");
1587 if ($windowEventListener) {
1588 push(@implContent, " imp->set$implSetterFunctionName(createJSAttributeEventListener(exec, value, globalObject));\n");
1590 push(@implContent, " imp->set$implSetterFunctionName(createJSAttributeEventListener(exec, value, thisObject));\n");
1593 } elsif ($attribute->signature->type =~ /Constructor$/) {
1594 my $constructorType = $attribute->signature->type;
1595 $constructorType =~ s/Constructor$//;
1596 if ($constructorType ne "DOMObject") {
1597 $implIncludes{"JS" . $constructorType . ".h"} = 1;
1599 push(@implContent, " // Shadowing a built-in constructor\n");
1600 push(@implContent, " static_cast<$className*>(thisObject)->putDirect(Identifier(exec, \"$name\"), value);\n");
1601 } elsif ($attribute->signature->extendedAttributes->{"Replaceable"}) {
1602 push(@implContent, " // Shadowing a built-in object\n");
1603 push(@implContent, " static_cast<$className*>(thisObject)->putDirect(Identifier(exec, \"$name\"), value);\n");
1605 push(@implContent, " $className* castedThis = static_cast<$className*>(thisObject);\n");
1606 push(@implContent, " $implType* imp = static_cast<$implType*>(castedThis->impl());\n");
1608 push(@implContent, " $podType podImp(*imp);\n");
1609 if ($podType eq "float") { # Special case for JSSVGNumber
1610 push(@implContent, " podImp = " . JSValueToNative($attribute->signature, "value") . ";\n");
1612 push(@implContent, " podImp.set$implSetterFunctionName(" . JSValueToNative($attribute->signature, "value") . ");\n");
1614 push(@implContent, " imp->commitChange(podImp, castedThis);\n");
1616 my $nativeValue = JSValueToNative($attribute->signature, "value");
1617 push(@implContent, " ExceptionCode ec = 0;\n") if @{$attribute->setterExceptions};
1618 my $reflect = $attribute->signature->extendedAttributes->{"Reflect"};
1619 my $reflectURL = $attribute->signature->extendedAttributes->{"ReflectURL"};
1620 if ($reflect || $reflectURL) {
1621 my $contentAttributeName = (($reflect || $reflectURL) eq "1") ? $name : ($reflect || $reflectURL);
1622 my $namespace = $codeGenerator->NamespaceForAttributeName($interfaceName, $contentAttributeName);
1623 $implIncludes{"${namespace}.h"} = 1;
1624 push(@implContent, " imp->setAttribute(${namespace}::${contentAttributeName}Attr, $nativeValue");
1626 push(@implContent, " imp->set$implSetterFunctionName($nativeValue");
1628 push(@implContent, ", ec") if @{$attribute->setterExceptions};
1629 push(@implContent, ");\n");
1630 push(@implContent, " setDOMException(exec, ec);\n") if @{$attribute->setterExceptions};
1631 if (IsSVGTypeNeedingContextParameter($implClassName)) {
1632 push(@implContent, " JSSVGContextCache::propagateSVGDOMChange(castedThis, imp->associatedAttributeName());\n");
1637 push(@implContent, "}\n");
1639 push(@implContent, "#endif\n") if $attributeConditionalString;
1641 push(@implContent, "\n");
1648 if (($dataNode->extendedAttributes->{"HasIndexGetter"} || $dataNode->extendedAttributes->{"HasCustomIndexGetter"} || $dataNode->extendedAttributes->{"HasNumericIndexGetter"}) && !$dataNode->extendedAttributes->{"CustomGetPropertyNames"}) {
1649 push(@implContent, "void ${className}::getOwnPropertyNames(ExecState* exec, PropertyNameArray& propertyNames, EnumerationMode mode)\n");
1650 push(@implContent, "{\n");
1651 if ($dataNode->extendedAttributes->{"HasIndexGetter"} || $dataNode->extendedAttributes->{"HasCustomIndexGetter"} || $dataNode->extendedAttributes->{"HasNumericIndexGetter"}) {
1652 push(@implContent, " for (unsigned i = 0; i < static_cast<${implClassName}*>(impl())->length(); ++i)\n");
1653 push(@implContent, " propertyNames.add(Identifier::from(exec, i));\n");
1655 push(@implContent, " Base::getOwnPropertyNames(exec, propertyNames, mode);\n");
1656 push(@implContent, "}\n\n");
1659 if (!($dataNode->extendedAttributes->{"OmitConstructor"} || $dataNode->extendedAttributes->{"CustomConstructor"})) {
1660 push(@implContent, "JSValue ${className}::getConstructor(ExecState* exec, JSGlobalObject* globalObject)\n{\n");
1661 push(@implContent, " return getDOMConstructor<${className}Constructor>(exec, static_cast<JSDOMGlobalObject*>(globalObject));\n");
1662 push(@implContent, "}\n\n");
1666 if ($numFunctions > 0) {
1667 foreach my $function (@{$dataNode->functions}) {
1668 AddIncludesForType($function->signature->type);
1670 my $functionName = $codeGenerator->WK_lcfirst($className) . "PrototypeFunction" . $codeGenerator->WK_ucfirst($function->signature->name);
1671 my $functionImplementationName = $function->signature->extendedAttributes->{"ImplementationFunction"} || $codeGenerator->WK_lcfirst($function->signature->name);
1673 push(@implContent, "JSValue JSC_HOST_CALL ${functionName}(ExecState* exec, JSObject*, JSValue thisValue, const ArgList& args)\n");
1674 push(@implContent, "{\n");
1675 push(@implContent, " UNUSED_PARAM(args);\n");
1677 $implIncludes{"<runtime/Error.h>"} = 1;
1679 if ($interfaceName eq "DOMWindow") {
1680 push(@implContent, " $className* castedThis = toJSDOMWindow(thisValue.toThisObject(exec));\n");
1681 push(@implContent, " if (!castedThis)\n");
1682 push(@implContent, " return throwError(exec, TypeError);\n");
1683 } elsif ($dataNode->extendedAttributes->{"IsWorkerContext"}) {
1684 push(@implContent, " $className* castedThis = to${className}(thisValue.toThisObject(exec));\n");
1685 push(@implContent, " if (!castedThis)\n");
1686 push(@implContent, " return throwError(exec, TypeError);\n");
1688 push(@implContent, " if (!thisValue.inherits(&${className}::s_info))\n");
1689 push(@implContent, " return throwError(exec, TypeError);\n");
1690 push(@implContent, " $className* castedThis = static_cast<$className*>(asObject(thisValue));\n");
1693 if ($dataNode->extendedAttributes->{"CheckDomainSecurity"} &&
1694 !$function->signature->extendedAttributes->{"DoNotCheckDomainSecurity"}) {
1695 push(@implContent, " if (!castedThis->allowsAccessFrom(exec))\n");
1696 push(@implContent, " return jsUndefined();\n");
1699 # Special case for JSSVGLengthList / JSSVGTransformList / JSSVGPointList / JSSVGNumberList
1700 # Instead of having JSSVG*Custom.cpp implementations for the SVGList interface for all of these
1701 # classes, we directly forward the calls to JSSVGPODListCustom, which centralizes the otherwise
1702 # duplicated code for the JSSVG*List classes mentioned above.
1704 if ($implClassName =~ /SVG.*List/) {
1705 $svgPODListType = $implClassName;
1706 $svgPODListType =~ s/List$//;
1707 $svgPODListType = "" unless $codeGenerator->IsPodType($svgPODListType);
1709 # Ignore additional (non-SVGList) SVGTransformList methods, that are not handled through JSSVGPODListCustom
1710 $svgPODListType = "" if $functionImplementationName =~ /createSVGTransformFromMatrix/;
1711 $svgPODListType = "" if $functionImplementationName =~ /consolidate/;
1714 if ($function->signature->extendedAttributes->{"Custom"} || $function->signature->extendedAttributes->{"JSCCustom"}) {
1715 push(@implContent, " return castedThis->" . $functionImplementationName . "(exec, args);\n");
1716 } elsif ($svgPODListType) {
1717 $implIncludes{"JS${svgPODListType}.h"} = 1;
1718 $implIncludes{"JSSVGPODListCustom.h"} = 1;
1719 push(@implContent, " return JSSVGPODListCustom::$functionImplementationName<$className, " . GetNativeType($svgPODListType)
1720 . ">(castedThis, exec, args, to" . $svgPODListType . ");\n");
1722 push(@implContent, " $implType* imp = static_cast<$implType*>(castedThis->impl());\n");
1723 push(@implContent, " $podType podImp(*imp);\n") if $podType;
1725 my $numParameters = @{$function->parameters};
1727 if ($function->signature->extendedAttributes->{"RequiresAllArguments"}) {
1728 push(@implContent, " if (args.size() < $numParameters)\n");
1729 push(@implContent, " return jsUndefined();\n");
1732 if (@{$function->raisesExceptions}) {
1733 push(@implContent, " ExceptionCode ec = 0;\n");
1736 if ($function->signature->extendedAttributes->{"SVGCheckSecurityDocument"}) {
1737 push(@implContent, " if (!checkNodeSecurity(exec, imp->getSVGDocument(" . (@{$function->raisesExceptions} ? "ec" : "") .")))\n");
1738 push(@implContent, " return jsUndefined();\n");
1739 $implIncludes{"JSDOMBinding.h"} = 1;
1742 if ($function->signature->name eq "addEventListener") {
1743 push(@implContent, GenerateEventListenerCall($className, "add"));
1744 } elsif ($function->signature->name eq "removeEventListener") {
1745 push(@implContent, GenerateEventListenerCall($className, "remove"));
1748 my $functionString = ($podType ? "podImp." : "imp->") . $functionImplementationName . "(";
1750 my $hasOptionalArguments = 0;
1752 if ($function->signature->extendedAttributes->{"CustomArgumentHandling"}) {
1753 push(@implContent, " ScriptCallStack callStack(exec, args, $numParameters);\n");
1754 $implIncludes{"ScriptCallStack.h"} = 1;
1757 my $callWith = $function->signature->extendedAttributes->{"CallWith"};
1759 my $callWithArg = "COMPILE_ASSERT(false)";
1760 if ($callWith eq "DynamicFrame") {
1761 push(@implContent, " Frame* dynamicFrame = toDynamicFrame(exec);\n");
1762 push(@implContent, " if (!dynamicFrame)\n");
1763 push(@implContent, " return jsUndefined();\n");
1764 $callWithArg = "dynamicFrame";
1765 } elsif ($callWith eq "ScriptState") {
1766 $callWithArg = "exec";
1768 $functionString .= ", " if $paramIndex;
1769 $functionString .= $callWithArg;
1773 foreach my $parameter (@{$function->parameters}) {
1774 if (!$hasOptionalArguments && $parameter->extendedAttributes->{"Optional"}) {
1775 push(@implContent, "\n int argsCount = args.size();\n");
1776 $hasOptionalArguments = 1;
1779 if ($hasOptionalArguments) {
1780 push(@implContent, " if (argsCount < " . ($paramIndex + 1) . ") {\n");
1781 GenerateImplementationFunctionCall($function, $functionString, $paramIndex, " " x 2, $podType, $implClassName);
1782 push(@implContent, " }\n\n");
1785 my $name = $parameter->name;
1787 if ($parameter->type eq "XPathNSResolver") {
1788 push(@implContent, " RefPtr<XPathNSResolver> customResolver;\n");
1789 push(@implContent, " XPathNSResolver* resolver = toXPathNSResolver(args.at($paramIndex));\n");
1790 push(@implContent, " if (!resolver) {\n");
1791 push(@implContent, " customResolver = JSCustomXPathNSResolver::create(exec, args.at($paramIndex));\n");
1792 push(@implContent, " if (exec->hadException())\n");
1793 push(@implContent, " return jsUndefined();\n");
1794 push(@implContent, " resolver = customResolver.get();\n");
1795 push(@implContent, " }\n");
1797 push(@implContent, " " . GetNativeTypeFromSignature($parameter) . " $name = " . JSValueToNative($parameter, "args.at($paramIndex)") . ";\n");
1799 # If a parameter is "an index" and it's negative it should throw an INDEX_SIZE_ERR exception.
1800 # But this needs to be done in the bindings, because the type is unsigned and the fact that it
1801 # was negative will be lost by the time we're inside the DOM.
1802 if ($parameter->extendedAttributes->{"IsIndex"}) {
1803 $implIncludes{"ExceptionCode.h"} = 1;
1804 push(@implContent, " if ($name < 0) {\n");
1805 push(@implContent, " setDOMException(exec, INDEX_SIZE_ERR);\n");
1806 push(@implContent, " return jsUndefined();\n");
1807 push(@implContent, " }\n");
1811 $functionString .= ", " if $paramIndex;
1813 if ($parameter->type eq "NodeFilter") {
1814 $functionString .= "$name.get()";
1816 $functionString .= $name;
1821 if ($function->signature->extendedAttributes->{"NeedsUserGestureCheck"}) {
1822 $functionString .= ", " if $paramIndex;
1823 $functionString .= "processingUserGesture(exec)";
1827 push(@implContent, "\n");
1828 GenerateImplementationFunctionCall($function, $functionString, $paramIndex, " ", $podType, $implClassName);
1831 push(@implContent, "}\n\n");
1835 if ($numConstants > 0) {
1836 push(@implContent, "// Constant getters\n\n");
1838 foreach my $constant (@{$dataNode->constants}) {
1839 my $getter = "js" . $interfaceName . $codeGenerator->WK_ucfirst($constant->name);
1841 # FIXME: this casts into int to match our previous behavior which turned 0xFFFFFFFF in -1 for NodeFilter.SHOW_ALL
1842 push(@implContent, "JSValue ${getter}(ExecState* exec, JSValue, const Identifier&)\n");
1843 push(@implContent, "{\n");
1844 push(@implContent, " return jsNumber(exec, static_cast<int>(" . $constant->value . "));\n");
1845 push(@implContent, "}\n\n");
1849 if ($dataNode->extendedAttributes->{"HasIndexGetter"}) {
1850 push(@implContent, "\nJSValue ${className}::indexGetter(ExecState* exec, JSValue slotBase, unsigned index)\n");
1851 push(@implContent, "{\n");
1852 push(@implContent, " ${className}* thisObj = static_cast<$className*>(asObject(slotBase));\n");
1853 if (IndexGetterReturnsStrings($implClassName)) {
1854 $implIncludes{"KURL.h"} = 1;
1855 push(@implContent, " return jsStringOrNull(exec, thisObj->impl()->item(index));\n");
1857 push(@implContent, " return toJS(exec, thisObj->globalObject(), static_cast<$implClassName*>(thisObj->impl())->item(index));\n");
1859 push(@implContent, "}\n");
1860 if ($interfaceName eq "HTMLCollection" or $interfaceName eq "HTMLAllCollection") {
1861 $implIncludes{"JSNode.h"} = 1;
1862 $implIncludes{"Node.h"} = 1;
1866 if ($dataNode->extendedAttributes->{"HasNumericIndexGetter"}) {
1867 push(@implContent, "\nJSValue ${className}::getByIndex(ExecState* exec, unsigned index)\n");
1868 push(@implContent, "{\n");
1869 push(@implContent, " return jsNumber(exec, static_cast<$implClassName*>(impl())->item(index));\n");
1870 push(@implContent, "}\n");
1871 if ($interfaceName eq "HTMLCollection" or $interfaceName eq "HTMLAllCollection") {
1872 $implIncludes{"JSNode.h"} = 1;
1873 $implIncludes{"Node.h"} = 1;
1877 if ((!$hasParent or $dataNode->extendedAttributes->{"GenerateToJS"}) and !$dataNode->extendedAttributes->{"CustomToJS"}) {
1879 push(@implContent, "JSC::JSValue toJS(JSC::ExecState* exec, JSDOMGlobalObject* globalObject, JSSVGPODTypeWrapper<$podType>* object, SVGElement* context)\n");
1880 } elsif (IsSVGTypeNeedingContextParameter($implClassName)) {
1881 push(@implContent, "JSC::JSValue toJS(JSC::ExecState* exec, JSDOMGlobalObject* globalObject, $implType* object, SVGElement* context)\n");
1883 push(@implContent, "JSC::JSValue toJS(JSC::ExecState* exec, JSDOMGlobalObject* globalObject, $implType* object)\n");
1885 push(@implContent, "{\n");
1887 push(@implContent, " return getDOMObjectWrapper<$className, JSSVGPODTypeWrapper<$podType> >(exec, globalObject, object, context);\n");
1888 } elsif (IsSVGTypeNeedingContextParameter($implClassName)) {
1889 push(@implContent, " return getDOMObjectWrapper<$className>(exec, globalObject, object, context);\n");
1891 push(@implContent, " return getDOMObjectWrapper<$className>(exec, globalObject, object);\n");
1893 push(@implContent, "}\n");
1896 if ((!$hasParent or $dataNode->extendedAttributes->{"GenerateNativeConverter"}) and !$dataNode->extendedAttributes->{"CustomNativeConverter"}) {
1898 push(@implContent, "$podType to${interfaceName}(JSC::JSValue value)\n");
1900 push(@implContent, "$implClassName* to${interfaceName}(JSC::JSValue value)\n");
1903 push(@implContent, "{\n");
1905 push(@implContent, " return value.inherits(&${className}::s_info) ? " . ($podType ? "($podType) *" : "") . "static_cast<$className*>(asObject(value))->impl() : ");
1906 if ($podType and $podType ne "float") {
1907 push(@implContent, "$podType();\n}\n");
1909 push(@implContent, "0;\n}\n");
1913 push(@implContent, "\n}\n");
1915 my $conditionalString = GenerateConditionalString($dataNode);
1916 push(@implContent, "\n#endif // ${conditionalString}\n") if $conditionalString;
1919 sub GenerateCallbackHeader
1922 my $dataNode = shift;
1924 my $interfaceName = $dataNode->name;
1925 my $className = "JS$interfaceName";
1927 # - Add default header template and header protection
1928 push(@headerContentHeader, GenerateHeaderContentHeader($dataNode));
1930 $headerIncludes{"$interfaceName.h"} = 1;
1931 $headerIncludes{"JSCallbackData.h"} = 1;
1932 $headerIncludes{"<wtf/Forward.h>"} = 1;
1934 push(@headerContent, "\nnamespace WebCore {\n\n");
1935 push(@headerContent, "class $className : public $interfaceName {\n");
1936 push(@headerContent, "public:\n");
1938 # The static create() method.
1939 push(@headerContent, " static PassRefPtr<$className> create(JSC::JSObject* callback, JSDOMGlobalObject* globalObject)\n");
1940 push(@headerContent, " {\n");
1941 push(@headerContent, " return adoptRef(new $className(callback, globalObject));\n");
1942 push(@headerContent, " }\n\n");
1945 push(@headerContent, " virtual ~$className();\n");
1948 my $numFunctions = @{$dataNode->functions};
1949 if ($numFunctions > 0) {
1950 push(@headerContent, "\n // Functions\n");
1951 foreach my $function (@{$dataNode->functions}) {
1952 my @params = @{$function->parameters};
1953 if (!$function->signature->extendedAttributes->{"Custom"} &&
1954 !(GetNativeType($function->signature->type) eq "bool")) {
1955 push(@headerContent, " COMPILE_ASSERT(false)");
1958 push(@headerContent, " virtual " . GetNativeType($function->signature->type) . " " . $function->signature->name . "(ScriptExecutionContext*");
1959 foreach my $param (@params) {
1960 push(@headerContent, ", " . GetNativeType($param->type) . " " . $param->name);
1963 push(@headerContent, ");\n");
1967 push(@headerContent, "\nprivate:\n");
1970 push(@headerContent, " $className(JSC::JSObject* callback, JSDOMGlobalObject*);\n\n");
1973 push(@headerContent, " JSCallbackData* m_data;\n");
1974 push(@headerContent, " RefPtr<DOMWrapperWorld> m_isolatedWorld;\n");
1975 push(@headerContent, "};\n\n");
1977 push(@headerContent, "} // namespace WebCore\n\n");
1978 my $conditionalString = GenerateConditionalString($dataNode);
1979 push(@headerContent, "#endif // ${conditionalString}\n\n") if $conditionalString;
1980 push(@headerContent, "#endif\n");
1983 sub GenerateCallbackImplementation
1985 my ($object, $dataNode) = @_;
1987 my $interfaceName = $dataNode->name;
1988 my $className = "JS$interfaceName";
1990 # - Add default header template
1991 push(@implContentHeader, GenerateImplementationContentHeader($dataNode));
1993 $implIncludes{"ScriptExecutionContext.h"} = 1;
1994 $implIncludes{"<runtime/JSLock.h>"} = 1;
1995 $implIncludes{"<wtf/MainThread.h>"} = 1;
1999 push(@implContent, "\nusing namespace JSC;\n\n");
2000 push(@implContent, "namespace WebCore {\n\n");
2003 push(@implContent, "${className}::${className}(JSObject* callback, JSDOMGlobalObject* globalObject)\n");
2004 push(@implContent, " : m_data(new JSCallbackData(callback, globalObject))\n");
2005 push(@implContent, " , m_isolatedWorld(globalObject->world())\n");
2006 push(@implContent, "{\n");
2007 push(@implContent, "}\n\n");
2010 push(@implContent, "${className}::~${className}()\n");
2011 push(@implContent, "{\n");
2012 push(@implContent, " callOnMainThread(JSCallbackData::deleteData, m_data);\n");
2013 push(@implContent, "#ifndef NDEBUG\n");
2014 push(@implContent, " m_data = 0;\n");
2015 push(@implContent, "#endif\n");
2016 push(@implContent, "}\n");
2019 my $numFunctions = @{$dataNode->functions};
2020 if ($numFunctions > 0) {
2021 push(@implContent, "\n// Functions\n");
2022 foreach my $function (@{$dataNode->functions}) {
2023 my @params = @{$function->parameters};
2024 if ($function->signature->extendedAttributes->{"Custom"} ||
2025 !(GetNativeType($function->signature->type) eq "bool")) {
2029 AddIncludesForType($function->signature->type);
2030 push(@implContent, "\n" . GetNativeType($function->signature->type) . " ${className}::" . $function->signature->name . "(ScriptExecutionContext* context");
2032 foreach my $param (@params) {
2033 AddIncludesForType($param->type, 1);
2034 push(@implContent, ", " . GetNativeType($param->type) . " " . $param->name);
2037 push(@implContent, ")\n");
2039 push(@implContent, "{\n");
2040 push(@implContent, " ASSERT(m_data);\n");
2041 push(@implContent, " ASSERT(context);\n\n");
2042 push(@implContent, " RefPtr<$className> protect(this);\n\n");
2043 push(@implContent, " JSLock lock(SilenceAssertionsOnly);\n\n");
2044 push(@implContent, " JSDOMGlobalObject* globalObject = toJSDOMGlobalObject(context, m_isolatedWorld.get());\n");
2045 push(@implContent, " if (!globalObject)\n");
2046 push(@implContent, " return true;\n\n");
2047 push(@implContent, " ExecState* exec = globalObject->globalExec();\n");
2048 push(@implContent, " MarkedArgumentBuffer args;\n");
2050 foreach my $param (@params) {
2051 my $paramName = $param->name;
2052 push(@implContent, " args.append(toJS(exec, ${paramName}));\n");
2055 push(@implContent, "\n bool raisedException = false;\n");
2056 push(@implContent, " m_data->invokeCallback(args, &raisedException);\n");
2057 push(@implContent, " return !raisedException;\n");
2058 push(@implContent, "}\n");
2062 push(@implContent, "\n}\n");
2063 my $conditionalString = GenerateConditionalString($dataNode);
2064 push(@implContent, "\n#endif // ${conditionalString}\n") if $conditionalString;
2067 sub GenerateImplementationFunctionCall()
2069 my $function = shift;
2070 my $functionString = shift;
2071 my $paramIndex = shift;
2073 my $podType = shift;
2074 my $implClassName = shift;
2076 if ($function->signature->extendedAttributes->{"CustomArgumentHandling"}) {
2077 $functionString .= ", " if $paramIndex;
2079 $functionString .= "&callStack";
2082 if (@{$function->raisesExceptions}) {
2083 $functionString .= ", " if $paramIndex;
2084 $functionString .= "ec";
2086 $functionString .= ")";
2088 if ($function->signature->type eq "void") {
2089 push(@implContent, $indent . "$functionString;\n");
2090 push(@implContent, $indent . "setDOMException(exec, ec);\n") if @{$function->raisesExceptions};
2091 push(@implContent, $indent . "imp->commitChange(podImp, castedThis);\n") if $podType;
2092 push(@implContent, $indent . "return jsUndefined();\n");
2094 push(@implContent, "\n" . $indent . "JSC::JSValue result = " . NativeToJSValue($function->signature, 1, $implClassName, "", $functionString, "castedThis") . ";\n");
2095 push(@implContent, $indent . "setDOMException(exec, ec);\n") if @{$function->raisesExceptions};
2097 $callWith = $function->signature->extendedAttributes->{"CallWith"};
2098 if ($callWith and $callWith eq "ScriptState") {
2099 push(@implContent, $indent . "if (exec->hadException())\n");
2100 push(@implContent, $indent . " return jsUndefined();\n");
2103 if ($podType and not $function->signature->extendedAttributes->{"Immutable"}) {
2104 # Immutable methods do not commit changes back to the instance, thus producing
2105 # a new instance rather than mutating existing one.
2106 push(@implContent, $indent . "imp->commitChange(podImp, castedThis);\n");
2109 push(@implContent, $indent . "return result;\n");
2113 sub GetNativeTypeFromSignature
2115 my $signature = shift;
2116 my $type = $codeGenerator->StripModule($signature->type);
2118 if ($type eq "unsigned long" and $signature->extendedAttributes->{"IsIndex"}) {
2119 # Special-case index arguments because we need to check that they aren't < 0.
2123 return GetNativeType($type);
2127 "CompareHow" => "Range::CompareHow",
2128 "DOMString" => "const String&",
2129 "DOMObject" => "ScriptValue",
2130 "NodeFilter" => "RefPtr<NodeFilter>",
2131 "SerializedScriptValue" => "RefPtr<SerializedScriptValue>",
2132 "SVGAngle" => "SVGAngle",
2133 "SVGLength" => "SVGLength",
2134 "SVGMatrix" => "AffineTransform",
2135 "SVGNumber" => "float",
2136 "SVGPaintType" => "SVGPaint::SVGPaintType",
2137 "SVGPreserveAspectRatio" => "SVGPreserveAspectRatio",
2138 "SVGPoint" => "FloatPoint",
2139 "SVGRect" => "FloatRect",
2140 "SVGTransform" => "SVGTransform",
2141 "boolean" => "bool",
2142 "double" => "double",
2145 "unsigned long" => "unsigned",
2146 "unsigned short" => "unsigned short",
2147 "long long" => "long long",
2148 "unsigned long long" => "unsigned long long",
2155 return $nativeType{$type} if exists $nativeType{$type};
2157 # For all other types, the native type is a pointer with same type name as the IDL type.
2163 my $signature = shift;
2166 my $type = $codeGenerator->StripModule($signature->type);
2168 return "$value.toBoolean(exec)" if $type eq "boolean";
2169 return "$value.toNumber(exec)" if $type eq "double";
2170 return "$value.toFloat(exec)" if $type eq "float" or $type eq "SVGNumber";
2171 return "$value.toInt32(exec)" if $type eq "unsigned long" or $type eq "long" or $type eq "unsigned short";
2172 return "static_cast<$type>($value.toInteger(exec))" if $type eq "long long" or $type eq "unsigned long long";
2174 return "valueToDate(exec, $value)" if $type eq "Date";
2175 return "static_cast<Range::CompareHow>($value.toInt32(exec))" if $type eq "CompareHow";
2176 return "static_cast<SVGPaint::SVGPaintType>($value.toInt32(exec))" if $type eq "SVGPaintType";
2178 if ($type eq "DOMString") {
2179 return "valueToStringWithNullCheck(exec, $value)" if $signature->extendedAttributes->{"ConvertNullToNullString"};
2180 return "valueToStringWithUndefinedOrNullCheck(exec, $value)" if $signature->extendedAttributes->{"ConvertUndefinedOrNullToNullString"};
2181 return "ustringToString($value.toString(exec))";
2184 if ($type eq "DOMObject") {
2188 if ($type eq "SerializedScriptValue" or $type eq "any") {
2189 $implIncludes{"SerializedScriptValue.h"} = 1;
2190 return "SerializedScriptValue::create(exec, $value)";
2193 $implIncludes{"FloatPoint.h"} = 1 if $type eq "SVGPoint";
2194 $implIncludes{"FloatRect.h"} = 1 if $type eq "SVGRect";
2195 $implIncludes{"HTMLOptionElement.h"} = 1 if $type eq "HTMLOptionElement";
2196 $implIncludes{"JSCustomVoidCallback.h"} = 1 if $type eq "VoidCallback";
2197 $implIncludes{"Event.h"} = 1 if $type eq "Event";
2199 # Default, assume autogenerated type conversion routines
2200 $implIncludes{"JS$type.h"} = 1;
2201 return "to$type($value)";
2206 my $signature = shift;
2207 my $inFunctionCall = shift;
2208 my $implClassName = shift;
2209 my $implClassNameForValueConversion = shift;
2211 my $thisValue = shift;
2213 my $type = $codeGenerator->StripModule($signature->type);
2215 return "jsBoolean($value)" if $type eq "boolean";
2217 # Need to check Date type before IsPrimitiveType().
2218 if ($type eq "Date") {
2219 return "jsDateOrNull(exec, $value)";
2221 if ($codeGenerator->IsPrimitiveType($type) or $type eq "SVGPaintType" or $type eq "DOMTimeStamp") {
2222 $implIncludes{"<runtime/JSNumberCell.h>"} = 1;
2223 return "jsNumber(exec, $value)";
2226 if ($codeGenerator->IsStringType($type)) {
2227 $implIncludes{"KURL.h"} = 1;
2228 my $conv = $signature->extendedAttributes->{"ConvertNullStringTo"};
2229 if (defined $conv) {
2230 return "jsStringOrNull(exec, $value)" if $conv eq "Null";
2231 return "jsStringOrUndefined(exec, $value)" if $conv eq "Undefined";
2232 return "jsStringOrFalse(exec, $value)" if $conv eq "False";
2234 die "Unknown value for ConvertNullStringTo extended attribute";
2236 $conv = $signature->extendedAttributes->{"ConvertScriptString"};
2237 return "jsOwnedStringOrNull(exec, $value)" if $conv;
2238 $implIncludes{"<runtime/JSString.h>"} = 1;
2239 return "jsString(exec, $value)";
2242 my $globalObject = "$thisValue->globalObject()";
2243 if ($codeGenerator->IsPodType($type)) {
2244 $implIncludes{"JS$type.h"} = 1;
2246 my $nativeType = GetNativeType($type);
2248 my $getter = $value;
2249 $getter =~ s/imp->//;
2250 $getter =~ s/\(\)//;
2252 my $setter = "set" . $codeGenerator->WK_ucfirst($getter);
2254 # Function calls will never return 'modifyable' POD types (ie. SVGRect getBBox()) - no need to keep track changes to the returned SVGRect
2255 if ($inFunctionCall eq 0
2256 and not $codeGenerator->IsSVGAnimatedType($implClassName)
2257 and $codeGenerator->IsPodTypeWithWriteableProperties($type)
2258 and not defined $signature->extendedAttributes->{"Immutable"}) {
2259 if ($codeGenerator->IsPodType($implClassName)) {
2260 return "toJS(exec, $globalObject, JSSVGStaticPODTypeWrapperWithPODTypeParent<$nativeType, $implClassName>::create($value, $thisValue->impl()).get(), JSSVGContextCache::svgContextForDOMObject(castedThis))";
2262 return "toJS(exec, $globalObject, JSSVGStaticPODTypeWrapperWithParent<$nativeType, $implClassName>::create(imp, &${implClassName}::$getter, &${implClassName}::$setter).get(), imp)";
2266 if ($implClassNameForValueConversion eq "") {
2267 return "toJS(exec, $globalObject, JSSVGStaticPODTypeWrapper<$nativeType>::create($value).get(), 0 /* no context on purpose */)";
2269 return "toJS(exec, $globalObject, JSSVGDynamicPODTypeWrapperCache<$nativeType, $implClassNameForValueConversion>::lookupOrCreateWrapper(imp, &${implClassNameForValueConversion}::$getter, &${implClassNameForValueConversion}::$setter).get(), JSSVGContextCache::svgContextForDOMObject(castedThis));"
2273 if ($codeGenerator->IsSVGAnimatedType($type)) {
2274 # Some SVGFE*Element.idl use 'operator' as attribute name, rewrite as '_operator' to avoid clashes with C/C++
2275 $value =~ s/operator\(\)/_operator\(\)/ if ($value =~ /operator/);
2277 $value .= "Animated()";
2280 if ($type eq "CSSStyleDeclaration") {
2281 $implIncludes{"CSSMutableStyleDeclaration.h"} = 1;
2284 if ($type eq "NodeList") {
2285 $implIncludes{"NameNodeList.h"} = 1;
2288 if ($type eq "DOMObject") {
2289 if ($implClassName eq "Document") {
2290 $implIncludes{"JSCanvasRenderingContext2D.h"} = 1;
2292 return "$value.jsValue();";
2294 } elsif ($type =~ /SVGPathSeg/) {
2295 $implIncludes{"JS$type.h"} = 1;
2296 $joinedName = $type;
2297 $joinedName =~ s/Abs|Rel//;
2298 $implIncludes{"$joinedName.h"} = 1;
2299 } elsif ($type eq "SerializedScriptValue" or $type eq "any") {
2300 $implIncludes{"SerializedScriptValue.h"} = 1;
2301 return "$value ? $value->deserialize(exec, castedThis->globalObject()) : jsNull()";
2303 # Default, include header with same name.
2304 $implIncludes{"JS$type.h"} = 1;
2305 $implIncludes{"$type.h"} = 1;
2308 return $value if $codeGenerator->IsSVGAnimatedType($type);
2310 if (IsSVGTypeNeedingContextParameter($type)) {
2311 my $contextPtr = IsSVGTypeNeedingContextParameter($implClassName) ? "JSSVGContextCache::svgContextForDOMObject(castedThis)" : "imp";
2312 return "toJS(exec, $globalObject, WTF::getPtr($value), $contextPtr)";
2315 if ($signature->extendedAttributes->{"ReturnsNew"}) {
2316 return "toJSNewlyCreated(exec, $globalObject, WTF::getPtr($value))";
2319 return "toJS(exec, $globalObject, WTF::getPtr($value))";
2322 sub ceilingToPowerOf2
2327 while ($size > $powerOf2) {
2335 sub GenerateHashTable
2342 my $specials = shift;
2345 my $conditionals = shift;
2347 # Generate size data for two hash tables
2348 # - The 'perfect' size makes a table large enough for perfect hashing
2349 # - The 'compact' size uses the legacy table format for smaller table sizes
2353 foreach my $key (@{$keys}) {
2354 push @hashes, $object->GenerateHashValue($key);
2361 my $compactSize = ceilingToPowerOf2($size * 2);
2365 my $numEntries = $compactSize;
2368 foreach (@{$keys}) {
2370 my $h = $object->GenerateHashValue($_) % $numEntries;
2372 while (defined($table[$h])) {
2373 if (defined($links[$h])) {
2378 $links[$h] = $compactSize;
2387 $maxDepth = $depth if ($depth > $maxDepth);
2390 # Collect hashtable information
2393 for ($perfectSize = ceilingToPowerOf2(scalar @{$keys}); ; $perfectSize += $perfectSize) {
2396 foreach my $hash (@hashes) {
2397 my $h = $hash % $perfectSize;
2398 next tableSizeLoop if defined $table[$h];
2404 # Start outputing the hashtables
2405 my $nameEntries = "${name}Values";
2406 $nameEntries =~ s/:/_/g;
2408 if (($name =~ /Prototype/) or ($name =~ /Constructor/)) {
2412 if ($name =~ /Prototype/) {
2413 $type =~ s/Prototype.*//;
2414 $implClass = $type; $implClass =~ s/Wrapper$//;
2415 push(@implContent, "/* Hash table for prototype */\n");
2417 $type =~ s/Constructor.*//;
2418 $implClass = $type; $implClass =~ s/Constructor$//;
2419 push(@implContent, "/* Hash table for constructor */\n");
2422 push(@implContent, "/* Hash table */\n");
2425 # Dump the hash table
2426 my $count = scalar @{$keys} + 1;
2427 push(@implContent, "#if ENABLE(JIT)\n");
2428 push(@implContent, "#define THUNK_GENERATOR(generator) , generator\n");
2429 push(@implContent, "#else\n");
2430 push(@implContent, "#define THUNK_GENERATOR(generator)\n");
2431 push(@implContent, "#endif\n");
2432 push(@implContent, "\nstatic const HashTableValue $nameEntries\[$count\] =\n\{\n");
2434 foreach my $key (@{$keys}) {
2438 if ($conditionals) {
2439 $conditional = $conditionals->{$key};
2442 my $conditionalString = GenerateConditionalStringFromAttributeValue($conditional);
2443 push(@implContent, "#if ${conditionalString}\n");
2446 if ("@$specials[$i]" =~ m/Function/) {
2447 $targetType = "static_cast<NativeFunction>";
2449 $targetType = "static_cast<PropertySlot::GetValueFunc>";
2451 push(@implContent, " { \"$key\", @$specials[$i], (intptr_t)" . $targetType . "(@$value1[$i]), (intptr_t)@$value2[$i] THUNK_GENERATOR(0) },\n");
2453 push(@implContent, "#endif\n");
2457 push(@implContent, " { 0, 0, 0, 0 THUNK_GENERATOR(0) }\n");
2458 push(@implContent, "};\n\n");
2459 push(@implContent, "#undef THUNK_GENERATOR\n");
2460 my $perfectSizeMask = $perfectSize - 1;
2461 my $compactSizeMask = $numEntries - 1;
2462 push(@implContent, "static JSC_CONST_HASHTABLE HashTable $name =\n");
2463 push(@implContent, "#if ENABLE(PERFECT_HASH_SIZE)\n");
2464 push(@implContent, " { $perfectSizeMask, $nameEntries, 0 };\n");
2465 push(@implContent, "#else\n");
2466 push(@implContent, " { $compactSize, $compactSizeMask, $nameEntries, 0 };\n");
2467 push(@implContent, "#endif\n\n");
2471 sub GenerateHashValue
2475 @chars = split(/ */, $_[0]);
2477 # This hash is designed to work on 16-bit chunks at a time. But since the normal case
2478 # (above) is to hash UTF-16 characters, we just treat the 8-bit chars as if they
2479 # were 16-bit chunks, which should give matching results
2481 my $EXP2_32 = 4294967296;
2483 my $hash = 0x9e3779b9;
2484 my $l = scalar @chars; #I wish this was in Ruby --- Maks
2491 for (; $l > 0; $l--) {
2492 $hash += ord($chars[$s]);
2493 my $tmp = leftShift(ord($chars[$s+1]), 11) ^ $hash;
2494 $hash = (leftShift($hash, 16)% $EXP2_32) ^ $tmp;
2496 $hash += $hash >> 11;
2502 $hash += ord($chars[$s]);
2503 $hash ^= (leftShift($hash, 11)% $EXP2_32);
2504 $hash += $hash >> 17;
2507 # Force "avalanching" of final 127 bits
2508 $hash ^= leftShift($hash, 3);
2509 $hash += ($hash >> 5);
2510 $hash = ($hash% $EXP2_32);
2511 $hash ^= (leftShift($hash, 2)% $EXP2_32);
2512 $hash += ($hash >> 15);
2513 $hash = $hash% $EXP2_32;
2514 $hash ^= (leftShift($hash, 10)% $EXP2_32);
2516 # this avoids ever returning a hash code of 0, since that is used to
2517 # signal "hash not computed yet", using a value that is likely to be
2518 # effectively the same as 0 when the low bits are masked
2519 $hash = 0x80000000 if ($hash == 0);
2527 if (defined($IMPL)) {
2528 # Write content to file.
2529 print $IMPL @implContentHeader;
2532 foreach my $include (keys %implIncludes) {
2533 my $checkType = $include;
2534 $checkType =~ s/\.h//;
2535 next if $codeGenerator->IsSVGAnimatedType($checkType);
2537 $include = "\"$include\"" unless $include =~ /^["<]/; # "
2538 push @includes, $include;
2540 foreach my $include (sort @includes) {
2541 print $IMPL "#include $include\n";
2544 print $IMPL @implContent;
2548 @implContentHeader = ();
2553 if (defined($HEADER)) {
2554 # Write content to file.
2555 print $HEADER @headerContentHeader;
2558 foreach my $include (keys %headerIncludes) {
2559 $include = "\"$include\"" unless $include =~ /^["<]/; # "
2560 push @includes, $include;
2562 foreach my $include (sort @includes) {
2563 print $HEADER "#include $include\n";
2566 print $HEADER @headerContent;
2569 foreach my $include (keys %headerTrailingIncludes) {
2570 $include = "\"$include\"" unless $include =~ /^["<]/; # "
2571 push @includes, $include;
2573 foreach my $include (sort @includes) {
2574 print $HEADER "#include $include\n";
2580 @headerContentHeader = ();
2581 @headerContent = ();
2582 %headerIncludes = ();
2583 %headerTrailingIncludes = ();
2586 if (defined($DEPS)) {
2587 # Write dependency file.
2588 print $DEPS @depsContent;
2598 my $className = shift;
2599 my $protoClassName = shift;
2600 my $interfaceName = shift;
2601 my $visibleClassName = shift;
2602 my $dataNode = shift;
2603 my $constructorClassName = "${className}Constructor";
2604 my $canConstruct = $dataNode->extendedAttributes->{"CanBeConstructed"};
2605 my $callWith = $dataNode->extendedAttributes->{"CallWith"};
2607 my $implContent = << "EOF";
2608 class ${constructorClassName} : public DOMConstructorObject {
2610 ${constructorClassName}(ExecState* exec, JSDOMGlobalObject* globalObject)
2611 : DOMConstructorObject(${constructorClassName}::createStructure(globalObject->objectPrototype()), globalObject)
2613 putDirect(exec->propertyNames().prototype, ${protoClassName}::self(exec, globalObject), None);
2615 virtual bool getOwnPropertySlot(ExecState*, const Identifier&, PropertySlot&);
2616 virtual bool getOwnPropertyDescriptor(ExecState*, const Identifier&, PropertyDescriptor&);
2617 virtual const ClassInfo* classInfo() const { return &s_info; }
2618 static const ClassInfo s_info;
2620 static PassRefPtr<Structure> createStructure(JSValue proto)
2622 return Structure::create(proto, TypeInfo(ObjectType, StructureFlags), AnonymousSlotCount);
2626 static const unsigned StructureFlags = OverridesGetOwnPropertySlot | ImplementsHasInstance | DOMConstructorObject::StructureFlags;
2629 if ($canConstruct) {
2630 $implContent .= << "EOF";
2631 static JSObject* construct${interfaceName}(ExecState* exec, JSObject* constructor, const ArgList&)
2635 my $constructorArg = "";
2636 if ($callWith and $callWith eq "ScriptExecutionContext") {
2637 $constructorArg = "context";
2638 $implContent .= << "EOF";
2639 ScriptExecutionContext* context = static_cast<${constructorClassName}*>(constructor)->scriptExecutionContext();
2641 return throwError(exec, ReferenceError);
2645 $implContent .= << "EOF";
2646 return asObject(toJS(exec, static_cast<${constructorClassName}*>(constructor)->globalObject(), ${interfaceName}::create(${constructorArg})));
2648 virtual ConstructType getConstructData(ConstructData& constructData)
2650 constructData.native.function = construct${interfaceName};
2651 return ConstructTypeHost;
2656 $implContent .= << "EOF";
2659 const ClassInfo ${constructorClassName}::s_info = { "${visibleClassName}Constructor", 0, &${constructorClassName}Table, 0 };
2661 bool ${constructorClassName}::getOwnPropertySlot(ExecState* exec, const Identifier& propertyName, PropertySlot& slot)
2663 return getStaticValueSlot<${constructorClassName}, DOMObject>(exec, &${constructorClassName}Table, this, propertyName, slot);
2666 bool ${constructorClassName}::getOwnPropertyDescriptor(ExecState* exec, const Identifier& propertyName, PropertyDescriptor& descriptor)
2668 return getStaticValueDescriptor<${constructorClassName}, DOMObject>(exec, &${constructorClassName}Table, this, propertyName, descriptor);
2673 $implJSCInclude{"JSNumberCell.h"} = 1; # FIXME: What is this for?
2675 return $implContent;