2 # Copyright (C) 2005, 2006 Nikolas Zimmermann <zimmermann@kde.org>
3 # Copyright (C) 2006 Anders Carlsson <andersca@mac.com>
4 # Copyright (C) 2006 Samuel Weinig <sam.weinig@gmail.com>
5 # Copyright (C) 2006 Alexey Proskuryakov <ap@webkit.org>
6 # Copyright (C) 2006 Apple Computer, Inc.
7 # Copyright (C) 2007, 2008, 2009 Google Inc.
8 # Copyright (C) 2009 Cameron McCormack <cam@mcc.id.au>
10 # This library is free software; you can redistribute it and/or
11 # modify it under the terms of the GNU Library General Public
12 # License as published by the Free Software Foundation; either
13 # version 2 of the License, or (at your option) any later version.
15 # This library is distributed in the hope that it will be useful,
16 # but WITHOUT ANY WARRANTY; without even the implied warranty of
17 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 # Library General Public License for more details.
20 # You should have received a copy of the GNU Library General Public License
21 # along with this library; see the file COPYING.LIB. If not, write to
22 # the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
23 # Boston, MA 02111-1307, USA.
26 package CodeGeneratorV8;
33 my $outputHeadersDir = "";
35 my @headerContent = ();
36 my @implContentHeader = ();
37 my @implFixedHeader = ();
39 my @implContentDecls = ();
40 my %implIncludes = ();
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., 59 Temple Place - Suite 330,
63 Boston, MA 02111-1307, USA.
73 $codeGenerator = shift;
75 $outputHeadersDir = shift;
77 bless($reference, $object);
89 # Workaround for V8 bindings difference where RGBColor is not a POD type.
93 return $codeGenerator->IsPodType($type);
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 = "$outputHeadersDir/V8$name.h";
116 my $implFileName = "$outputDir/V8$name.cpp";
118 open($IMPL, ">$implFileName") || die "Couldn't open file $implFileName";
119 open($HEADER, ">$headerFileName") || die "Couldn't open file $headerFileName";
122 # Params: 'idlDocument' struct
126 my $dataNode = shift;
128 $module = $dataNode->module;
131 sub AvoidInclusionOfType
135 # Special case: SVGRect.h / SVGPoint.h / SVGNumber.h / SVGMatrix.h do not exist.
136 return 1 if $type eq "SVGRect" or $type eq "SVGPoint" or $type eq "SVGNumber" or $type eq "SVGMatrix";
140 sub AddIncludesForType
142 my $type = $codeGenerator->StripModule(shift);
144 # When we're finished with the one-file-per-class
145 # reorganization, we won't need these special cases.
146 if (!$codeGenerator->IsPrimitiveType($type) and !AvoidInclusionOfType($type) and $type ne "Date") {
147 # default, include the same named file
148 $implIncludes{GetV8HeaderName(${type})} = 1;
150 if ($type =~ /SVGPathSeg/) {
152 $joinedName =~ s/Abs|Rel//;
153 $implIncludes{"${joinedName}.h"} = 1;
157 # additional includes (things needed to compile the bindings but not the header)
159 if ($type eq "CanvasRenderingContext2D") {
160 $implIncludes{"CanvasGradient.h"} = 1;
161 $implIncludes{"CanvasPattern.h"} = 1;
162 $implIncludes{"CanvasStyle.h"} = 1;
165 if ($type eq "CanvasGradient" or $type eq "XPathNSResolver") {
166 $implIncludes{"PlatformString.h"} = 1;
169 if ($type eq "CSSStyleDeclaration") {
170 $implIncludes{"CSSMutableStyleDeclaration.h"} = 1;
173 if ($type eq "Plugin" or $type eq "PluginArray" or $type eq "MimeTypeArray") {
174 # So we can get String -> AtomicString conversion for namedItem().
175 $implIncludes{"AtomicString.h"} = 1;
179 sub AddIncludesForSVGAnimatedType
182 $type =~ s/SVGAnimated//;
184 if ($type eq "Point" or $type eq "Rect") {
185 $implIncludes{"Float$type.h"} = 1;
186 } elsif ($type eq "String") {
187 $implIncludes{"PlatformString.h"} = 1;
190 $implIncludes{"SVGAnimatedTemplate.h"} = 1;
193 # If the node has a [Conditional=XXX] attribute, returns an "ENABLE(XXX)" string for use in an #if.
194 sub GenerateConditionalString
197 my $conditional = $node->extendedAttributes->{"Conditional"};
199 if ($conditional =~ /&/) {
200 return "ENABLE(" . join(") && ENABLE(", split(/&/, $conditional)) . ")";
201 } elsif ($conditional =~ /\|/) {
202 return "ENABLE(" . join(") || ENABLE(", split(/\|/, $conditional)) . ")";
204 return "ENABLE(" . $conditional . ")";
214 my $dataNode = shift;
216 my $interfaceName = $dataNode->name;
217 my $className = "V8$interfaceName";
218 my $implClassName = $interfaceName;
220 # Copy contents of parent classes except the first parent or if it is
222 $codeGenerator->AddMethodsConstantsAndAttributesFromParentClasses($dataNode, \@allParents, 1);
224 my $hasLegacyParent = $dataNode->extendedAttributes->{"LegacyParent"};
226 # - Add default header template
227 push(@headerContent, GenerateHeaderContentHeader($dataNode));
229 # Get correct pass/store types respecting PODType flag
230 my $podType = $dataNode->extendedAttributes->{"PODType"};
232 my %headerInclues = ();
233 $headerIncludes{"$podType.h"} = 1 if $podType and ($podType ne "double" and $podType ne "float" and $podType ne "RGBA32");
234 $headerIncludes{"StringHash.h"} = 1;
235 $headerIncludes{"WrapperTypeInfo.h"} = 1;
236 my $headerClassInclude = GetHeaderClassInclude($implClassName);
237 $headerIncludes{$headerClassInclude} = 1 if $headerClassInclude ne "";
239 foreach my $headerInclude (sort keys(%headerIncludes)) {
240 push(@headerContent, "#include \"${headerInclude}\"\n");
243 push(@headerContent, "#include <v8.h>\n");
244 push(@headerContent, "#include <wtf/HashMap.h>\n");
246 push(@headerContent, "\nnamespace WebCore {\n");
248 push(@headerContent, "\ntemplate<typename PODType> class V8SVGPODTypeWrapper;\n");
250 push(@headerContent, "\nclass $className {\n");
252 my $nativeType = GetNativeTypeForConversions($interfaceName);
254 $nativeType = "V8SVGPODTypeWrapper<${nativeType} >";
256 my $forceNewObjectParameter = IsDOMNodeType($interfaceName) ? ", bool forceNewObject = false" : "";
257 push(@headerContent, <<END);
260 static bool HasInstance(v8::Handle<v8::Value> value);
261 static v8::Persistent<v8::FunctionTemplate> GetRawTemplate();
262 static v8::Persistent<v8::FunctionTemplate> GetTemplate();
263 static ${nativeType}* toNative(v8::Handle<v8::Object>);
264 static v8::Handle<v8::Object> wrap(${nativeType}*${forceNewObjectParameter});
265 static void derefObject(void*);
266 static WrapperTypeInfo info;
268 if (IsActiveDomType($implClassName)) {
269 push(@headerContent, " static ActiveDOMObject* toActiveDOMObject(v8::Handle<v8::Object>);\n");
272 if ($implClassName eq "DOMWindow") {
273 push(@headerContent, <<END);
274 static v8::Persistent<v8::ObjectTemplate> GetShadowObjectTemplate();
278 my @enabledAtRuntime;
279 foreach my $function (@{$dataNode->functions}) {
280 my $name = $function->signature->name;
281 my $attrExt = $function->signature->extendedAttributes;
283 if ($attrExt->{"Custom"} || $attrExt->{"V8Custom"}) {
284 push(@headerContent, <<END);
285 static v8::Handle<v8::Value> ${name}Callback(const v8::Arguments&);
289 if ($attrExt->{"EnabledAtRuntime"}) {
290 push(@enabledAtRuntime, $function);
294 if ($dataNode->extendedAttributes->{"CustomConstructor"} || $dataNode->extendedAttributes->{"V8CustomConstructor"} || $dataNode->extendedAttributes->{"CanBeConstructed"}) {
295 push(@headerContent, <<END);
296 static v8::Handle<v8::Value> constructorCallback(const v8::Arguments& args);
300 foreach my $attribute (@{$dataNode->attributes}) {
301 my $name = $attribute->signature->name;
302 my $attrExt = $attribute->signature->extendedAttributes;
303 if ($attrExt->{"V8CustomGetter"} || $attrExt->{"CustomGetter"}
304 || $attrExt->{"V8Custom"} || $attrExt->{"Custom"}) {
305 push(@headerContent, <<END);
306 static v8::Handle<v8::Value> ${name}AccessorGetter(v8::Local<v8::String> name, const v8::AccessorInfo& info);
309 if ($attrExt->{"V8CustomSetter"} || $attrExt->{"CustomSetter"}
310 || $attrExt->{"V8Custom"} || $attrExt->{"Custom"}) {
311 push(@headerContent, <<END);
312 static void ${name}AccessorSetter(v8::Local<v8::String> name, v8::Local<v8::Value> value, const v8::AccessorInfo& info);
315 if ($attrExt->{"EnabledAtRuntime"}) {
316 push(@enabledAtRuntime, $attribute);
320 GenerateHeaderNamedAndIndexedPropertyAccessors($dataNode);
321 GenerateHeaderCustomCall($dataNode);
322 GenerateHeaderCustomInternalFieldIndices($dataNode);
324 if ($dataNode->extendedAttributes->{"CheckDomainSecurity"}) {
325 push(@headerContent, <<END);
326 static bool namedSecurityCheck(v8::Local<v8::Object> host, v8::Local<v8::Value> key, v8::AccessType, v8::Local<v8::Value> data);
327 static bool indexedSecurityCheck(v8::Local<v8::Object> host, uint32_t index, v8::AccessType, v8::Local<v8::Value> data);
331 push(@headerContent, <<END);
334 v8::Handle<v8::Value> toV8(${nativeType}*${forceNewObjectParameter});
336 if (IsRefPtrType($implClassName)) {
337 push(@headerContent, <<END);
338 v8::Handle<v8::Value> toV8(PassRefPtr<${nativeType} >${forceNewObjectParameter});
342 push(@headerContent, "}\n\n");
343 push(@headerContent, "#endif // $className" . "_h\n");
345 my $conditionalString = GenerateConditionalString($dataNode);
346 push(@headerContent, "#endif // ${conditionalString}\n\n") if $conditionalString;
349 sub GetInternalFields
351 my $dataNode = shift;
352 my $name = $dataNode->name;
354 my @customInternalFields = ();
356 # We can't ask whether a parent type has a given extendedAttribute, so special-case Node, AbstractWorker and WorkerContext to include all sub-types.
357 # FIXME: SVGElementInstance should probably have the EventTarget extended attribute, but doesn't.
358 if ($dataNode->extendedAttributes->{"EventTarget"} || IsNodeSubType($dataNode) || IsSubType($dataNode, "AbstractWorker") || IsSubType($dataNode, "WorkerContext")
359 || $name eq "SVGElementInstance") {
360 push(@customInternalFields, "eventListenerCacheIndex");
363 if (IsSubType($dataNode, "Document")) {
364 push(@customInternalFields, "implementationIndex");
365 if ($name eq "HTMLDocument") {
366 push(@customInternalFields, ("markerIndex", "shadowIndex"));
368 } elsif ($name eq "DOMWindow") {
369 push(@customInternalFields, "enteredIsolatedWorldIndex");
371 return @customInternalFields;
374 sub GetHeaderClassInclude
376 my $className = shift;
377 if ($className =~ /SVGPathSeg/) {
378 $className =~ s/Abs|Rel//;
380 return "" if (AvoidInclusionOfType($className));
381 return "SVGAnimatedTemplate.h" if ($codeGenerator->IsSVGAnimatedType($className));
382 return "${className}.h";
385 sub GenerateHeaderCustomInternalFieldIndices
387 my $dataNode = shift;
388 my @customInternalFields = GetInternalFields($dataNode);
389 my $customFieldCounter = 0;
390 foreach my $customInternalField (@customInternalFields) {
391 push(@headerContent, <<END);
392 static const int ${customInternalField} = v8DefaultWrapperInternalFieldCount + ${customFieldCounter};
394 $customFieldCounter++;
396 push(@headerContent, <<END);
397 static const int internalFieldCount = v8DefaultWrapperInternalFieldCount + ${customFieldCounter};
401 my %indexerSpecialCases = (
403 "HTMLAppletElement" => 1,
405 "HTMLEmbedElement" => 1,
406 "HTMLObjectElement" => 1
409 sub GenerateHeaderNamedAndIndexedPropertyAccessors
411 my $dataNode = shift;
412 my $interfaceName = $dataNode->name;
413 my $hasCustomIndexedGetter = $dataNode->extendedAttributes->{"HasIndexGetter"} || $dataNode->extendedAttributes->{"CustomGetOwnPropertySlot"};
414 my $hasCustomIndexedSetter = $dataNode->extendedAttributes->{"HasCustomIndexSetter"} && !$dataNode->extendedAttributes->{"HasNumericIndexGetter"};
415 my $hasCustomNamedGetter = $dataNode->extendedAttributes->{"HasNameGetter"} || $dataNode->extendedAttributes->{"HasOverridingNameGetter"} || $dataNode->extendedAttributes->{"CustomGetOwnPropertySlot"};
416 my $hasCustomNamedSetter = $dataNode->extendedAttributes->{"DelegatingPutFunction"};
417 my $hasCustomDeleters = $dataNode->extendedAttributes->{"CustomDeleteProperty"};
418 my $hasCustomEnumerator = $dataNode->extendedAttributes->{"CustomGetPropertyNames"};
419 if ($interfaceName eq "HTMLOptionsCollection") {
420 $interfaceName = "HTMLCollection";
421 $hasCustomIndexedGetter = 1;
422 $hasCustomNamedGetter = 1;
424 if ($interfaceName eq "DOMWindow") {
425 $hasCustomDeleterr = 0;
428 if ($interfaceName eq "HTMLSelectElement" || $interfaceName eq "HTMLAppletElement" || $interfaceName eq "HTMLEmbedElement" || $interfaceName eq "HTMLObjectElement") {
429 $hasCustomNamedGetter = 1;
431 my $isIndexerSpecialCase = exists $indexerSpecialCases{$interfaceName};
433 if ($hasCustomIndexedGetter || $isIndexerSpecialCase) {
434 push(@headerContent, <<END);
435 static v8::Handle<v8::Value> indexedPropertyGetter(uint32_t, const v8::AccessorInfo&);
439 if ($isIndexerSpecialCase || $hasCustomIndexedSetter) {
440 push(@headerContent, <<END);
441 static v8::Handle<v8::Value> indexedPropertySetter(uint32_t, v8::Local<v8::Value>, const v8::AccessorInfo&);
444 if ($hasCustomDeleters) {
445 push(@headerContent, <<END);
446 static v8::Handle<v8::Boolean> indexedPropertyDeleter(uint32_t, const v8::AccessorInfo&);
449 if ($hasCustomNamedGetter) {
450 push(@headerContent, <<END);
451 static v8::Handle<v8::Value> namedPropertyGetter(v8::Local<v8::String>, const v8::AccessorInfo&);
454 if ($hasCustomNamedSetter) {
455 push(@headerContent, <<END);
456 static v8::Handle<v8::Value> namedPropertySetter(v8::Local<v8::String>, v8::Local<v8::Value>, const v8::AccessorInfo&);
459 if ($hasCustomDeleters || $interfaceName eq "HTMLDocument") {
460 push(@headerContent, <<END);
461 static v8::Handle<v8::Boolean> namedPropertyDeleter(v8::Local<v8::String>, const v8::AccessorInfo&);
464 if ($hasCustomEnumerator) {
465 push(@headerContent, <<END);
466 static v8::Handle<v8::Array> namedPropertyEnumerator(const v8::AccessorInfo&);
467 static v8::Handle<v8::Integer> namedPropertyQuery(v8::Local<v8::String>, const v8::AccessorInfo&);
472 sub GenerateHeaderCustomCall
474 my $dataNode = shift;
476 if ($dataNode->extendedAttributes->{"CustomCall"}) {
477 push(@headerContent, " static v8::Handle<v8::Value> callAsFunctionCallback(const v8::Arguments&);\n");
479 if ($dataNode->name eq "Event") {
480 push(@headerContent, " static v8::Handle<v8::Value> dataTransferAccessorGetter(v8::Local<v8::String> name, const v8::AccessorInfo& info);\n");
481 push(@headerContent, " static void valueAccessorSetter(v8::Local<v8::String> name, v8::Local<v8::Value> value, const v8::AccessorInfo& info);\n");
483 if ($dataNode->name eq "Location") {
484 push(@headerContent, " static v8::Handle<v8::Value> assignAccessorGetter(v8::Local<v8::String> name, const v8::AccessorInfo& info);\n");
485 push(@headerContent, " static v8::Handle<v8::Value> reloadAccessorGetter(v8::Local<v8::String> name, const v8::AccessorInfo& info);\n");
486 push(@headerContent, " static v8::Handle<v8::Value> replaceAccessorGetter(v8::Local<v8::String> name, const v8::AccessorInfo& info);\n");
490 sub GenerateSetDOMException
495 $result .= $indent . "if (UNLIKELY(ec)) {\n";
496 $result .= $indent . " V8Proxy::setDOMException(ec);\n";
497 $result .= $indent . " return v8::Handle<v8::Value>();\n";
498 $result .= $indent . "}\n";
505 my $dataNode = shift;
506 my $parentType = shift;
507 return 1 if ($dataNode->name eq $parentType);
508 foreach (@allParents) {
509 my $parent = $codeGenerator->StripModule($_);
510 return 1 if $parent eq $parentType;
517 my $dataNode = shift;
518 return IsSubType($dataNode, "Node");
521 sub GenerateDomainSafeFunctionGetter
523 my $function = shift;
524 my $implClassName = shift;
526 my $className = "V8" . $implClassName;
527 my $funcName = $function->signature->name;
529 my $signature = "v8::Signature::New(" . $className . "::GetRawTemplate())";
530 if ($function->signature->extendedAttributes->{"V8DoNotCheckSignature"}) {
531 $signature = "v8::Local<v8::Signature>()";
534 my $newTemplateString = GenerateNewFunctionTemplate($function, $implClassName, $signature);
536 push(@implContentDecls, <<END);
537 static v8::Handle<v8::Value> ${funcName}AttrGetter(v8::Local<v8::String> name, const v8::AccessorInfo& info)
539 INC_STATS(\"DOM.$implClassName.$funcName._get\");
540 static v8::Persistent<v8::FunctionTemplate> privateTemplate = v8::Persistent<v8::FunctionTemplate>::New($newTemplateString);
541 v8::Handle<v8::Object> holder = V8DOMWrapper::lookupDOMWrapper(${className}::GetTemplate(), info.This());
542 if (holder.IsEmpty()) {
543 // can only reach here by 'object.__proto__.func', and it should passed
544 // domain security check already
545 return privateTemplate->GetFunction();
547 ${implClassName}* imp = ${className}::toNative(holder);
548 if (!V8BindingSecurity::canAccessFrame(V8BindingState::Only(), imp->frame(), false)) {
549 static v8::Persistent<v8::FunctionTemplate> sharedTemplate = v8::Persistent<v8::FunctionTemplate>::New($newTemplateString);
550 return sharedTemplate->GetFunction();
552 return privateTemplate->GetFunction();
558 sub GenerateConstructorGetter
560 my $implClassName = shift;
562 push(@implContentDecls, <<END);
563 static v8::Handle<v8::Value> ${implClassName}ConstructorGetter(v8::Local<v8::String> name, const v8::AccessorInfo& info)
565 INC_STATS(\"DOM.$implClassName.constructors._get\");
566 v8::Handle<v8::Value> data = info.Data();
567 ASSERT(data->IsExternal() || data->IsNumber());
568 WrapperTypeInfo* type = WrapperTypeInfo::unwrap(data);
571 if ($implClassName eq "DOMWindow") {
572 push(@implContentDecls, <<END);
573 // Get the proxy corresponding to the DOMWindow if possible to
574 // make sure that the constructor function is constructed in the
575 // context of the DOMWindow and not in the context of the caller.
576 return V8DOMWrapper::getConstructor(type, V8DOMWindow::toNative(info.Holder()));
578 } elsif ($implClassName eq "DedicatedWorkerContext" or $implClassName eq "WorkerContext" or $implClassName eq "SharedWorkerContext") {
579 push(@implContentDecls, <<END);
580 return V8DOMWrapper::getConstructor(type, V8WorkerContext::toNative(info.Holder()));
583 push(@implContentDecls, " return v8::Handle<v8::Value>();");
586 push(@implContentDecls, <<END);
592 sub GenerateNormalAttrGetter
594 my $attribute = shift;
595 my $dataNode = shift;
596 my $implClassName = shift;
597 my $interfaceName = shift;
599 my $attrExt = $attribute->signature->extendedAttributes;
601 my $attrName = $attribute->signature->name;
603 my $attrType = GetTypeFromSignature($attribute->signature);
604 my $attrIsPodType = IsPodType($attrType);
606 my $nativeType = GetNativeTypeFromSignature($attribute->signature, -1);
607 my $isPodType = IsPodType($implClassName);
611 $implClassName = GetNativeType($implClassName);
612 $implIncludes{"V8SVGPODTypeWrapper.h"} = 1;
615 # Special case: SVGZoomEvent's attributes are all read-only
616 if ($implClassName eq "SVGZoomEvent") {
621 # Special case: SVGSVGEelement::viewport is read-only
622 if (($implClassName eq "SVGSVGElement") and ($attrName eq "viewport")) {
627 # Special case for SVGColor
628 if (($implClassName eq "SVGColor") and ($attrName eq "rgbColor")) {
632 my $getterStringUsesImp = $implClassName ne "float";
635 my $conditionalString = GenerateConditionalString($attribute->signature);
636 push(@implContentDecls, "#if ${conditionalString}\n\n") if $conditionalString;
638 push(@implContentDecls, <<END);
639 static v8::Handle<v8::Value> ${attrName}AttrGetter(v8::Local<v8::String> name, const v8::AccessorInfo& info)
641 INC_STATS(\"DOM.$implClassName.$attrName._get\");
645 push(@implContentDecls, <<END);
646 V8SVGPODTypeWrapper<$implClassName>* impWrapper = V8SVGPODTypeWrapper<$implClassName>::toNative(info.Holder());
647 $implClassName impInstance = *impWrapper;
649 if ($getterStringUsesImp) {
650 push(@implContentDecls, <<END);
651 $implClassName* imp = &impInstance;
655 } elsif ($attrExt->{"v8OnProto"} || $attrExt->{"V8DisallowShadowing"}) {
656 if ($interfaceName eq "DOMWindow") {
657 push(@implContentDecls, <<END);
658 v8::Handle<v8::Object> holder = info.Holder();
661 # perform lookup first
662 push(@implContentDecls, <<END);
663 v8::Handle<v8::Object> holder = V8DOMWrapper::lookupDOMWrapper(V8${interfaceName}::GetTemplate(), info.This());
664 if (holder.IsEmpty())
665 return v8::Handle<v8::Value>();
668 push(@implContentDecls, <<END);
669 ${implClassName}* imp = V8${implClassName}::toNative(holder);
672 my $reflect = $attribute->signature->extendedAttributes->{"Reflect"};
673 my $url = $attribute->signature->extendedAttributes->{"URL"};
674 if ($getterStringUsesImp && $reflect && !$url && IsNodeSubType($dataNode) && $codeGenerator->IsStringType($attrType)) {
675 # Generate super-compact call for regular attribute getter:
676 my $contentAttributeName = $reflect eq "1" ? lc $attrName : $reflect;
677 my $namespace = $codeGenerator->NamespaceForAttributeName($interfaceName, $contentAttributeName);
678 $implIncludes{"${namespace}.h"} = 1;
679 push(@implContentDecls, " return getElementStringAttr(info, ${namespace}::${contentAttributeName}Attr);\n");
680 push(@implContentDecls, "}\n\n");
681 push(@implContentDecls, "#endif // ${conditionalString}\n\n") if $conditionalString;
683 # Skip the rest of the function!
685 push(@implContentDecls, <<END);
686 ${implClassName}* imp = V8${implClassName}::toNative(info.Holder());
690 # Generate security checks if necessary
691 if ($attribute->signature->extendedAttributes->{"CheckNodeSecurity"}) {
692 push(@implContentDecls, " if (!V8BindingSecurity::checkNodeSecurity(V8BindingState::Only(), imp->$attrName()))\n return v8::Handle<v8::Value>();\n\n");
693 } elsif ($attribute->signature->extendedAttributes->{"CheckFrameSecurity"}) {
694 push(@implContentDecls, " if (!V8BindingSecurity::checkNodeSecurity(V8BindingState::Only(), imp->contentDocument()))\n return v8::Handle<v8::Value>();\n\n");
697 my $useExceptions = 1 if @{$attribute->getterExceptions} and !($isPodType);
698 if ($useExceptions) {
699 $implIncludes{"ExceptionCode.h"} = 1;
700 push(@implContentDecls, " ExceptionCode ec = 0;\n");
703 if ($attribute->signature->extendedAttributes->{"v8referenceattr"}) {
704 $attrName = $attribute->signature->extendedAttributes->{"v8referenceattr"};
707 my $returnType = GetTypeFromSignature($attribute->signature);
710 if ($getterStringUsesImp) {
711 $getterString = "imp->" . $codeGenerator->GetterExpressionPrefix(\%implIncludes, $interfaceName, $attribute);
712 $getterString .= "ec" if $useExceptions;
713 $getterString .= ")";
715 $getterString = "impInstance";
721 if ($attrIsPodType) {
722 $implIncludes{"V8SVGPODTypeWrapper.h"} = 1;
724 my $getter = $getterString;
725 $getter =~ s/imp->//;
727 my $setter = "set" . $codeGenerator->WK_ucfirst($getter);
729 my $implClassIsAnimatedType = $codeGenerator->IsSVGAnimatedType($implClassName);
730 if (not $implClassIsAnimatedType and $codeGenerator->IsPodTypeWithWriteableProperties($attrType) and not defined $attribute->signature->extendedAttributes->{"Immutable"}) {
731 if (IsPodType($implClassName)) {
732 my $wrapper = "V8SVGStaticPODTypeWrapperWithPODTypeParent<$nativeType, $implClassName>::create($getterString, impWrapper)";
733 push(@implContentDecls, " RefPtr<V8SVGStaticPODTypeWrapperWithPODTypeParent<$nativeType, $implClassName> > wrapper = $wrapper;\n");
735 my $wrapper = "V8SVGStaticPODTypeWrapperWithParent<$nativeType, $implClassName>::create(imp, &${implClassName}::$getter, &${implClassName}::$setter)";
736 push(@implContentDecls, " RefPtr<V8SVGStaticPODTypeWrapperWithParent<$nativeType, $implClassName> > wrapper = $wrapper;\n");
739 if ($implClassIsAnimatedType) {
740 # We can't hash member function pointers, so instead generate
741 # some hashing material based on the names of the methods.
742 my $hashhex = substr(Digest::MD5::md5_hex("${implClassName}::$getter ${implClassName}::$setter)"), 0, 8);
743 my $wrapper = "V8SVGDynamicPODTypeWrapperCache<$nativeType, $implClassName>::lookupOrCreateWrapper(imp, &${implClassName}::$getter, &${implClassName}::$setter, 0x$hashhex)";
744 push(@implContentDecls, " RefPtr<V8SVGPODTypeWrapper<" . $nativeType . "> > wrapper = $wrapper;\n");
746 my $wrapper = GenerateSVGStaticPodTypeWrapper($returnType, $getterString);
747 push(@implContentDecls, " RefPtr<V8SVGStaticPODTypeWrapper<" . $nativeType . "> > wrapper = $wrapper;\n");
752 if ($attribute->signature->type eq "EventListener" && $dataNode->name eq "DOMWindow") {
753 push(@implContentDecls, " if (!imp->document())\n");
754 push(@implContentDecls, " return v8::Handle<v8::Value>();\n");
757 if ($useExceptions) {
758 push(@implContentDecls, " $nativeType v = ");
759 push(@implContentDecls, "$getterString;\n");
760 push(@implContentDecls, GenerateSetDOMException(" "));
762 $result .= ".release()" if (IsRefPtrType($returnType));
764 # Can inline the function call into the return statement to avoid overhead of using a Ref<> temporary
765 $result = $getterString;
768 # Special case for readonly or Replaceable attributes (with a few exceptions). This attempts to ensure that JS wrappers don't get
769 # garbage-collected prematurely when their lifetime is strongly tied to their owner. We accomplish this by inserting a reference to
770 # the newly created wrapper into an internal field of the holder object.
771 if (!IsNodeSubType($dataNode) && $attrName ne "self" && (IsWrapperType($returnType) && ($attribute->type =~ /^readonly/ || $attribute->signature->extendedAttributes->{"Replaceable"})
772 && $returnType ne "EventTarget" && $returnType ne "SerializedScriptValue" && $returnType ne "DOMWindow"
773 && $returnType !~ /SVG/ && $returnType !~ /HTML/ && !IsDOMNodeType($returnType))) {
774 AddIncludesForType($returnType);
775 my $domMapFunction = GetDomMapFunction(0, $returnType);
776 # Check for a wrapper in the wrapper cache. If there is one, we know that a hidden reference has already
777 # been created. If we don't find a wrapper, we create both a wrapper and a hidden reference.
778 push(@implContentDecls, " RefPtr<$returnType> result = ${getterString};\n");
779 push(@implContentDecls, " v8::Handle<v8::Value> wrapper = result.get() ? ${domMapFunction}.get(result.get()) : v8::Handle<v8::Value>();\n");
780 push(@implContentDecls, " if (wrapper.IsEmpty()) {\n");
781 push(@implContentDecls, " wrapper = toV8(result.get());\n");
782 push(@implContentDecls, " if (!wrapper.IsEmpty())\n");
783 if ($dataNode->name eq "DOMWindow") {
784 push(@implContentDecls, " V8DOMWrapper::setHiddenWindowReference(imp->frame(), wrapper);\n");
786 push(@implContentDecls, " V8DOMWrapper::setHiddenReference(info.Holder(), wrapper);\n");
788 push(@implContentDecls, " }\n");
789 push(@implContentDecls, " return wrapper;\n");
790 push(@implContentDecls, "}\n\n");
791 push(@implContentDecls, "#endif // ${conditionalString}\n\n") if $conditionalString;
796 if (IsSVGTypeNeedingContextParameter($attrType) && !$skipContext) {
797 if ($attrIsPodType) {
798 push(@implContentDecls, GenerateSVGContextAssignment($implClassName, "wrapper.get()", " "));
800 push(@implContentDecls, GenerateSVGContextRetrieval($implClassName, " "));
801 # The templating associated with passing withSVGContext()'s return value directly into toV8 can get compilers confused,
802 # so just manually set the return value to a PassRefPtr of the expected type.
803 push(@implContentDecls, " PassRefPtr<$attrType> resultAsPassRefPtr = V8Proxy::withSVGContext($result, context);\n");
804 $result = "resultAsPassRefPtr";
808 if ($attrIsPodType) {
809 $implIncludes{"V8${attrType}.h"} = 1;
810 push(@implContentDecls, " return toV8(wrapper.release().get());\n");
812 push(@implContentDecls, " " . ReturnNativeToJSValue($attribute->signature, $result, " ").";\n");
815 push(@implContentDecls, "}\n\n"); # end of getter
816 push(@implContentDecls, "#endif // ${conditionalString}\n\n") if $conditionalString;
819 sub GenerateNormalAttrSetter
821 my $attribute = shift;
822 my $dataNode = shift;
823 my $implClassName = shift;
824 my $interfaceName = shift;
826 my $attrExt = $attribute->signature->extendedAttributes;
828 my $conditionalString = GenerateConditionalString($attribute->signature);
829 push(@implContentDecls, "#if ${conditionalString}\n\n") if $conditionalString;
831 push(@implContentDecls, "static void ${attrName}AttrSetter(v8::Local<v8::String> name, v8::Local<v8::Value> value, const v8::AccessorInfo& info)\n{\n");
832 push(@implContentDecls, " INC_STATS(\"DOM.$implClassName.$attrName._set\");\n");
834 my $isPodType = IsPodType($implClassName);
837 $implClassName = GetNativeType($implClassName);
838 $implIncludes{"V8SVGPODTypeWrapper.h"} = 1;
839 push(@implContentDecls, " V8SVGPODTypeWrapper<$implClassName>* wrapper = V8SVGPODTypeWrapper<$implClassName>::toNative(info.Holder());\n");
840 push(@implContentDecls, " $implClassName impInstance = *wrapper;\n");
841 push(@implContentDecls, " $implClassName* imp = &impInstance;\n");
843 } elsif ($attrExt->{"v8OnProto"}) {
844 if ($interfaceName eq "DOMWindow") {
845 push(@implContentDecls, <<END);
846 v8::Handle<v8::Object> holder = info.Holder();
849 # perform lookup first
850 push(@implContentDecls, <<END);
851 v8::Handle<v8::Object> holder = V8DOMWrapper::lookupDOMWrapper(V8${interfaceName}::GetTemplate(), info.This());
852 if (holder.IsEmpty())
856 push(@implContentDecls, <<END);
857 ${implClassName}* imp = V8${implClassName}::toNative(holder);
860 my $attrType = GetTypeFromSignature($attribute->signature);
861 my $reflect = $attribute->signature->extendedAttributes->{"Reflect"};
862 if ($reflect && IsNodeSubType($dataNode) && $codeGenerator->IsStringType($attrType)) {
863 # Generate super-compact call for regular attribute setter:
864 my $contentAttributeName = $reflect eq "1" ? lc $attrName : $reflect;
865 my $namespace = $codeGenerator->NamespaceForAttributeName($interfaceName, $contentAttributeName);
866 $implIncludes{"${namespace}.h"} = 1;
867 push(@implContentDecls, " setElementStringAttr(info, ${namespace}::${contentAttributeName}Attr, value);\n");
868 push(@implContentDecls, "}\n\n");
869 push(@implContentDecls, "#endif // ${conditionalString}\n\n") if $conditionalString;
871 # Skip the rest of the function!
874 push(@implContentDecls, <<END);
875 ${implClassName}* imp = V8${implClassName}::toNative(info.Holder());
879 my $nativeType = GetNativeTypeFromSignature($attribute->signature, 0);
880 if ($attribute->signature->type eq "EventListener") {
881 if ($dataNode->name eq "DOMWindow") {
882 push(@implContentDecls, " if (!imp->document())\n");
883 push(@implContentDecls, " return;\n");
886 push(@implContentDecls, " $nativeType v = " . JSValueToNative($attribute->signature, "value") . ";\n");
890 my $returnType = GetTypeFromSignature($attribute->signature);
891 if (IsRefPtrType($returnType)) {
892 $result = "WTF::getPtr(" . $result . ")";
895 my $useExceptions = 1 if @{$attribute->setterExceptions} and !($isPodType);
897 if ($useExceptions) {
898 $implIncludes{"ExceptionCode.h"} = 1;
899 push(@implContentDecls, " ExceptionCode ec = 0;\n");
902 if ($implClassName eq "float") {
903 push(@implContentDecls, " *imp = $result;\n");
905 if ($attribute->signature->type eq "EventListener") {
906 my $implSetterFunctionName = $codeGenerator->WK_ucfirst($attrName);
907 $implIncludes{"V8AbstractEventListener.h"} = 1;
908 push(@implContentDecls, " transferHiddenDependency(info.Holder(), imp->$attrName(), value, V8${interfaceName}::eventListenerCacheIndex);\n");
909 if ($interfaceName eq "WorkerContext" and $attribute->signature->name eq "onerror") {
910 $implIncludes{"V8EventListenerList.h"} = 1;
911 $implIncludes{"V8WorkerContextErrorHandler.h"} = 1;
912 push(@implContentDecls, " imp->set$implSetterFunctionName(V8EventListenerList::findOrCreateWrapper<V8WorkerContextErrorHandler>(value, true)");
914 push(@implContentDecls, " imp->set$implSetterFunctionName(V8DOMWrapper::getEventListener(value, true, ListenerFindOrCreate)");
917 my $setterExpressionPrefix = $codeGenerator->SetterExpressionPrefix(\%implIncludes, $interfaceName, $attribute);
918 push(@implContentDecls, " imp->$setterExpressionPrefix$result");
920 push(@implContentDecls, ", ec") if $useExceptions;
921 push(@implContentDecls, ");\n");
924 if ($useExceptions) {
925 push(@implContentDecls, " if (UNLIKELY(ec))\n");
926 push(@implContentDecls, " V8Proxy::setDOMException(ec);\n");
930 push(@implContentDecls, " wrapper->commitChange(*imp, V8Proxy::svgContext(wrapper));\n");
931 } elsif (IsSVGTypeNeedingContextParameter($implClassName)) {
932 $implIncludes{"SVGElement.h"} = 1;
934 my $currentObject = "imp";
936 $currentObject = "wrapper";
939 push(@implContentDecls, " if (SVGElement* context = V8Proxy::svgContext($currentObject))\n");
940 push(@implContentDecls, " context->svgAttributeChanged(imp->associatedAttributeName());\n");
943 push(@implContentDecls, " return;\n");
944 push(@implContentDecls, "}\n\n"); # end of setter
945 push(@implContentDecls, "#endif // ${conditionalString}\n\n") if $conditionalString;
948 sub GetFunctionTemplateCallbackName
951 $interfaceName = shift;
953 my $name = $function->signature->name;
955 if ($function->signature->extendedAttributes->{"Custom"} ||
956 $function->signature->extendedAttributes->{"V8Custom"}) {
957 if ($function->signature->extendedAttributes->{"Custom"} &&
958 $function->signature->extendedAttributes->{"V8Custom"}) {
959 die "Custom and V8Custom should be mutually exclusive!"
961 return "V8${interfaceName}::${name}Callback";
963 return "${interfaceName}Internal::${name}Callback";
967 sub GenerateNewFunctionTemplate
970 $interfaceName = shift;
973 my $callback = GetFunctionTemplateCallbackName($function, $interfaceName);
974 return "v8::FunctionTemplate::New($callback, v8::Handle<v8::Value>(), $signature)";
977 sub GenerateEventListenerCallback
979 my $implClassName = shift;
980 my $functionName = shift;
981 my $lookupType = ($functionName eq "add") ? "OrCreate" : "Only";
982 my $passRefPtrHandling = ($functionName eq "add") ? "" : ".get()";
983 my $hiddenDependencyAction = ($functionName eq "add") ? "create" : "remove";
985 push(@implContentDecls, <<END);
986 static v8::Handle<v8::Value> ${functionName}EventListenerCallback(const v8::Arguments& args)
988 INC_STATS("DOM.${implClassName}.${functionName}EventListener()");
989 RefPtr<EventListener> listener = V8DOMWrapper::getEventListener(args[1], false, ListenerFind${lookupType});
991 V8${implClassName}::toNative(args.Holder())->${functionName}EventListener(v8ValueToAtomicWebCoreString(args[0]), listener${passRefPtrHandling}, args[2]->BooleanValue());
992 ${hiddenDependencyAction}HiddenDependency(args.Holder(), args[1], V8${implClassName}::eventListenerCacheIndex);
994 return v8::Undefined();
1000 sub GenerateParametersCheckExpression
1002 my $numParameters = shift;
1003 my $function = shift;
1005 my @andExpression = ();
1006 push(@andExpression, "args.Length() == $numParameters");
1007 my $parameterIndex = 0;
1008 foreach $parameter (@{$function->parameters}) {
1009 last if $parameterIndex >= $numParameters;
1010 my $value = "args[$parameterIndex]";
1011 my $type = GetTypeFromSignature($parameter);
1013 # Only DOMString or wrapper types are checked.
1014 # For DOMString, Null, Undefined and any Object are accepted too, as
1015 # these are acceptable values for a DOMString argument (any Object can
1016 # be converted to a string via .toString).
1017 push(@andExpression, "(${value}->IsNull() || ${value}->IsUndefined() || ${value}->IsString() || ${value}->IsObject())") if $codeGenerator->IsStringType($type);
1018 push(@andExpression, "(${value}->IsNull() || V8${type}::HasInstance($value))") if IsWrapperType($type);
1022 my $res = join(" && ", @andExpression);
1023 $res = "($res)" if @andExpression > 1;
1027 sub GenerateFunctionParametersCheck
1029 my $function = shift;
1031 my @orExpression = ();
1032 my $numParameters = 0;
1033 foreach $parameter (@{$function->parameters}) {
1034 if ($parameter->extendedAttributes->{"Optional"}) {
1035 push(@orExpression, GenerateParametersCheckExpression($numParameters, $function));
1039 push(@orExpression, GenerateParametersCheckExpression($numParameters, $function));
1040 return join(" || ", @orExpression);
1043 sub GenerateOverloadedFunctionCallback
1045 my $function = shift;
1046 my $dataNode = shift;
1047 my $implClassName = shift;
1049 # Generate code for choosing the correct overload to call. Overloads are
1050 # chosen based on the total number of arguments passed and the type of
1051 # values passed in non-primitive argument slots. When more than a single
1052 # overload is applicable, precedence is given according to the order of
1053 # declaration in the IDL.
1055 my $name = $function->signature->name;
1056 push(@implContentDecls, <<END);
1057 static v8::Handle<v8::Value> ${name}Callback(const v8::Arguments& args)
1059 INC_STATS(\"DOM.$implClassName.$name\");
1062 foreach my $overload (@{$function->{overloads}}) {
1063 my $parametersCheck = GenerateFunctionParametersCheck($overload);
1064 push(@implContentDecls, " if ($parametersCheck)\n");
1065 push(@implContentDecls, " return ${name}$overload->{overloadIndex}Callback(args);\n");
1067 push(@implContentDecls, <<END);
1068 V8Proxy::throwTypeError();
1069 return notHandledByInterceptor();
1071 push(@implContentDecls, "}\n\n");
1074 sub GenerateFunctionCallback
1076 my $function = shift;
1077 my $dataNode = shift;
1078 my $implClassName = shift;
1080 my $interfaceName = $dataNode->name;
1081 my $name = $function->signature->name;
1083 if (@{$function->{overloads}} > 1) {
1084 # Append a number to an overloaded method's name to make it unique:
1085 $name = $name . $function->{overloadIndex};
1088 # Adding and removing event listeners are not standard callback behavior,
1089 # but they are extremely consistent across the various classes that take event listeners,
1090 # so we can generate them as a "special case".
1091 if ($name eq "addEventListener") {
1092 GenerateEventListenerCallback($implClassName, "add");
1094 } elsif ($name eq "removeEventListener") {
1095 GenerateEventListenerCallback($implClassName, "remove");
1099 push(@implContentDecls, <<END);
1100 static v8::Handle<v8::Value> ${name}Callback(const v8::Arguments& args)
1102 INC_STATS(\"DOM.$implClassName.$name\");
1105 my $numParameters = @{$function->parameters};
1107 my $requiresAllArguments = $function->signature->extendedAttributes->{"RequiresAllArguments"};
1108 if ($requiresAllArguments) {
1109 push(@implContentDecls, " if (args.Length() < $numParameters)\n");
1110 if ($requiresAllArguments eq "Raise") {
1111 push(@implContentDecls, " return throwError(\"Not enough arguments\", V8Proxy::SyntaxError);\n");
1113 push(@implContentDecls, " return v8::Handle<v8::Value>();\n");
1117 if (IsPodType($implClassName)) {
1118 my $nativeClassName = GetNativeType($implClassName);
1119 push(@implContentDecls, " V8SVGPODTypeWrapper<$nativeClassName>* impWrapper = V8SVGPODTypeWrapper<$nativeClassName>::toNative(args.Holder());\n");
1120 push(@implContentDecls, " $nativeClassName impInstance = *impWrapper;\n");
1121 push(@implContentDecls, " $nativeClassName* imp = &impInstance;\n");
1123 push(@implContentDecls, <<END);
1124 ${implClassName}* imp = V8${implClassName}::toNative(args.Holder());
1128 # Check domain security if needed
1129 if (($dataNode->extendedAttributes->{"CheckDomainSecurity"}
1130 || $interfaceName eq "DOMWindow")
1131 && !$function->signature->extendedAttributes->{"DoNotCheckDomainSecurity"}) {
1132 # We have not find real use cases yet.
1133 push(@implContentDecls, <<END);
1134 if (!V8BindingSecurity::canAccessFrame(V8BindingState::Only(), imp->frame(), true))
1135 return v8::Handle<v8::Value>();
1139 my $raisesExceptions = @{$function->raisesExceptions};
1140 if (!$raisesExceptions) {
1141 foreach my $parameter (@{$function->parameters}) {
1142 if (TypeCanFailConversion($parameter) or $parameter->extendedAttributes->{"IsIndex"}) {
1143 $raisesExceptions = 1;
1148 if ($raisesExceptions) {
1149 $implIncludes{"ExceptionCode.h"} = 1;
1150 push(@implContentDecls, " ExceptionCode ec = 0;\n");
1151 push(@implContentDecls, " {\n");
1152 # The brace here is needed to prevent the ensuing 'goto fail's from jumping past constructors
1153 # of objects (like Strings) declared later, causing compile errors. The block scope ends
1154 # right before the label 'fail:'.
1157 if ($function->signature->extendedAttributes->{"CustomArgumentHandling"}) {
1158 push(@implContentDecls, <<END);
1159 OwnPtr<ScriptCallStack> callStack(ScriptCallStack::create(args, $numParameters));
1161 return v8::Undefined();
1163 $implIncludes{"ScriptCallStack.h"} = 1;
1165 if ($function->signature->extendedAttributes->{"SVGCheckSecurityDocument"}) {
1166 push(@implContentDecls, <<END);
1167 if (!V8BindingSecurity::checkNodeSecurity(V8BindingState::Only(), imp->getSVGDocument(ec)))
1168 return v8::Handle<v8::Value>();
1173 foreach my $parameter (@{$function->parameters}) {
1174 TranslateParameter($parameter);
1176 my $parameterName = $parameter->name;
1178 if ($parameter->extendedAttributes->{"Optional"}) {
1179 # Generate early call if there are not enough parameters.
1180 push(@implContentDecls, " if (args.Length() <= $paramIndex) {\n");
1181 my $functionCall = GenerateFunctionCallString($function, $paramIndex, " " x 2, $implClassName);
1182 push(@implContentDecls, $functionCall);
1183 push(@implContentDecls, " }\n");
1186 if ($parameter->type eq "SerializedScriptValue") {
1187 $implIncludes{"SerializedScriptValue.h"} = 1;
1188 push(@implContentDecls, " bool ${parameterName}DidThrow = false;\n");
1189 } elsif (BasicTypeCanFailConversion($parameter)) {
1190 push(@implContentDecls, " bool ${parameterName}Ok;\n");
1193 push(@implContentDecls, " " . GetNativeTypeFromSignature($parameter, $paramIndex) . " $parameterName = ");
1195 if ($parameter->type eq "SerializedScriptValue") {
1196 push(@implContentDecls, "SerializedScriptValue::create(args[$paramIndex], ${parameterName}DidThrow);\n");
1197 push(@implContentDecls, " if (${parameterName}DidThrow)\n");
1198 push(@implContentDecls, " return v8::Undefined();\n");
1200 push(@implContentDecls, JSValueToNative($parameter, "args[$paramIndex]",
1201 BasicTypeCanFailConversion($parameter) ? "${parameterName}Ok" : undef) . ";\n");
1204 if (TypeCanFailConversion($parameter)) {
1205 $implIncludes{"ExceptionCode.h"} = 1;
1206 push(@implContentDecls,
1207 " if (UNLIKELY(!$parameterName" . (BasicTypeCanFailConversion($parameter) ? "Ok" : "") . ")) {\n" .
1208 " ec = TYPE_MISMATCH_ERR;\n" .
1213 if ($parameter->extendedAttributes->{"IsIndex"}) {
1214 $implIncludes{"ExceptionCode.h"} = 1;
1215 push(@implContentDecls,
1216 " if (UNLIKELY($parameterName < 0)) {\n" .
1217 " ec = INDEX_SIZE_ERR;\n" .
1225 # Build the function call string.
1226 my $callString = GenerateFunctionCallString($function, $paramIndex, " ", $implClassName);
1227 push(@implContentDecls, "$callString");
1229 if ($raisesExceptions) {
1230 push(@implContentDecls, " }\n");
1231 push(@implContentDecls, " fail:\n");
1232 push(@implContentDecls, " V8Proxy::setDOMException(ec);\n");
1233 push(@implContentDecls, " return v8::Handle<v8::Value>();\n");
1236 push(@implContentDecls, "}\n\n");
1239 sub GenerateBatchedAttributeData
1241 my $dataNode = shift;
1242 my $interfaceName = $dataNode->name;
1243 my $attributes = shift;
1245 foreach my $attribute (@$attributes) {
1246 my $conditionalString = GenerateConditionalString($attribute->signature);
1247 push(@implContent, "#if ${conditionalString}\n") if $conditionalString;
1248 GenerateSingleBatchedAttribute($interfaceName, $attribute, ",", "");
1249 push(@implContent, "#endif // ${conditionalString}\n") if $conditionalString;
1253 sub GenerateSingleBatchedAttribute
1255 my $interfaceName = shift;
1256 my $attribute = shift;
1257 my $delimiter = shift;
1259 my $attrName = $attribute->signature->name;
1260 my $attrExt = $attribute->signature->extendedAttributes;
1262 # Attributes of type SerializedScriptValue are set in the
1263 # constructor and don't require callbacks.
1264 return if ($attribute->signature->type eq "SerializedScriptValue");
1266 my $accessControl = "v8::DEFAULT";
1267 if ($attrExt->{"DoNotCheckDomainSecurityOnGet"}) {
1268 $accessControl = "v8::ALL_CAN_READ";
1269 } elsif ($attrExt->{"DoNotCheckDomainSecurityOnSet"}) {
1270 $accessControl = "v8::ALL_CAN_WRITE";
1271 } elsif ($attrExt->{"DoNotCheckDomainSecurity"}) {
1272 $accessControl = "v8::ALL_CAN_READ";
1273 if (!($attribute->type =~ /^readonly/) && !($attrExt->{"V8ReadOnly"})) {
1274 $accessControl .= " | v8::ALL_CAN_WRITE";
1277 if ($attrExt->{"V8DisallowShadowing"}) {
1278 $accessControl .= " | v8::PROHIBITS_OVERWRITING";
1280 $accessControl = "static_cast<v8::AccessControl>(" . $accessControl . ")";
1282 my $customAccessor =
1283 $attrExt->{"Custom"} ||
1284 $attrExt->{"CustomSetter"} ||
1285 $attrExt->{"CustomGetter"} ||
1286 $attrExt->{"V8Custom"} ||
1287 $attrExt->{"V8CustomSetter"} ||
1288 $attrExt->{"V8CustomGetter"} ||
1290 if ($customAccessor eq 1) {
1291 # use the naming convension, interface + (capitalize) attr name
1292 $customAccessor = $interfaceName . "::" . $attrName;
1297 my $propAttr = "v8::None";
1298 my $hasCustomSetter = 0;
1301 if ($attrExt->{"DontEnum"}) {
1302 $propAttr .= " | v8::DontEnum";
1304 if ($attrExt->{"V8DisallowShadowing"}) {
1305 $propAttr .= " | v8::DontDelete";
1308 my $on_proto = "0 /* on instance */";
1309 my $data = "0 /* no data */";
1312 if ($attribute->signature->type =~ /Constructor$/) {
1313 my $constructorType = $codeGenerator->StripModule($attribute->signature->type);
1314 $constructorType =~ s/Constructor$//;
1315 $implIncludes{"V8${constructorType}.h"} = 1;
1316 if ($customAccessor) {
1317 $getter = "V8${customAccessor}AccessorGetter";
1319 $data = "&V8${constructorType}::info";
1320 $getter = "${interfaceName}Internal::${interfaceName}ConstructorGetter";
1323 $propAttr = "v8::ReadOnly";
1326 # Default Getter and Setter
1327 $getter = "${interfaceName}Internal::${attrName}AttrGetter";
1328 $setter = "${interfaceName}Internal::${attrName}AttrSetter";
1331 if ($attrExt->{"CustomSetter"} || $attrExt->{"V8CustomSetter"} || $attrExt->{"Custom"} || $attrExt->{"V8Custom"}) {
1332 $hasCustomSetter = 1;
1333 $setter = "V8${customAccessor}AccessorSetter";
1337 if ($attrExt->{"CustomGetter"} || $attrExt->{"V8CustomGetter"} || $attrExt->{"Custom"} || $attrExt->{"V8Custom"}) {
1338 $getter = "V8${customAccessor}AccessorGetter";
1343 if ($attrExt->{"Replaceable"} && !$hasCustomSetter) {
1345 # Handle the special case of window.top being marked as Replaceable.
1346 # FIXME: Investigate whether we could treat window.top as replaceable
1347 # and allow shadowing without it being a security hole.
1348 if (!($interfaceName eq "DOMWindow" and $attrName eq "top")) {
1349 $propAttr .= " | v8::ReadOnly";
1353 # Read only attributes
1354 if ($attribute->type =~ /^readonly/ || $attrExt->{"V8ReadOnly"}) {
1358 # An accessor can be installed on the proto
1359 if ($attrExt->{"v8OnProto"}) {
1360 $on_proto = "1 /* on proto */";
1363 my $commentInfo = "Attribute '$attrName' (Type: '" . $attribute->type .
1364 "' ExtAttr: '" . join(' ', keys(%{$attrExt})) . "')";
1366 push(@implContent, $indent . " \/\/ $commentInfo\n");
1367 push(@implContent, $indent . " {\"$attrName\", $getter, $setter, $data, $accessControl, static_cast<v8::PropertyAttribute>($propAttr), $on_proto}" . $delimiter . "\n");
1370 sub GenerateImplementationIndexer
1372 my $dataNode = shift;
1373 my $indexer = shift;
1374 my $interfaceName = $dataNode->name;
1376 # FIXME: Figure out what HasNumericIndexGetter is really supposed to do. Right now, it's only set on WebGL-related files.
1377 my $hasCustomSetter = $dataNode->extendedAttributes->{"HasCustomIndexSetter"} && !$dataNode->extendedAttributes->{"HasNumericIndexGetter"};
1378 my $hasGetter = $dataNode->extendedAttributes->{"HasIndexGetter"} || $dataNode->extendedAttributes->{"CustomGetOwnPropertySlot"};
1380 # FIXME: Find a way to not have to special-case HTMLOptionsCollection.
1381 if ($interfaceName eq "HTMLOptionsCollection") {
1384 # FIXME: If the parent interface of $dataNode already has
1385 # HasIndexGetter, we don't need to handle the getter here.
1386 if ($interfaceName eq "WebKitCSSTransformValue") {
1390 # FIXME: Investigate and remove this nastinesss. In V8, named property handling and indexer handling are apparently decoupled,
1391 # which means that object[X] where X is a number doesn't reach named property indexer. So we need to provide
1392 # simplistic, mirrored indexer handling in addition to named property handling.
1393 my $isSpecialCase = exists $indexerSpecialCases{$interfaceName};
1394 if ($isSpecialCase) {
1396 if ($dataNode->extendedAttributes->{"DelegatingPutFunction"}) {
1397 $hasCustomSetter = 1;
1405 $implIncludes{"V8Collection.h"} = 1;
1407 my $indexerType = $indexer ? $indexer->type : 0;
1409 # FIXME: Remove this once toV8 helper methods are implemented (see https://bugs.webkit.org/show_bug.cgi?id=32563).
1410 if ($interfaceName eq "WebKitCSSKeyframesRule") {
1411 $indexerType = "WebKitCSSKeyframeRule";
1414 if ($indexerType && !$hasCustomSetter) {
1415 if ($indexerType eq "DOMString") {
1416 my $conversion = $indexer->extendedAttributes->{"ConvertNullStringTo"};
1417 if ($conversion && $conversion eq "Null") {
1418 push(@implContent, <<END);
1419 setCollectionStringOrNullIndexedGetter<${interfaceName}>(desc);
1422 push(@implContent, <<END);
1423 setCollectionStringIndexedGetter<${interfaceName}>(desc);
1427 push(@implContent, <<END);
1428 setCollectionIndexedGetter<${interfaceName}, ${indexerType}>(desc);
1430 # Include the header for this indexer type, because setCollectionIndexedGetter() requires toV8() for this type.
1431 $implIncludes{"V8${indexerType}.h"} = 1;
1437 my $hasDeleter = $dataNode->extendedAttributes->{"CustomDeleteProperty"};
1438 my $hasEnumerator = !$isSpecialCase && IsNodeSubType($dataNode);
1439 my $setOn = "Instance";
1441 # V8 has access-check callback API (see ObjectTemplate::SetAccessCheckCallbacks) and it's used on DOMWindow
1442 # instead of deleters or enumerators. In addition, the getter should be set on prototype template, to
1443 # get implementation straight out of the DOMWindow prototype regardless of what prototype is actually set
1445 if ($interfaceName eq "DOMWindow") {
1446 $setOn = "Prototype";
1450 push(@implContent, " desc->${setOn}Template()->SetIndexedPropertyHandler(V8${interfaceName}::indexedPropertyGetter");
1451 push(@implContent, $hasCustomSetter ? ", V8${interfaceName}::indexedPropertySetter" : ", 0");
1452 push(@implContent, ", 0"); # IndexedPropertyQuery -- not being used at the moment.
1453 push(@implContent, $hasDeleter ? ", V8${interfaceName}::indexedPropertyDeleter" : ", 0");
1454 push(@implContent, ", nodeCollectionIndexedPropertyEnumerator<${interfaceName}>") if $hasEnumerator;
1455 push(@implContent, ");\n");
1458 sub GenerateImplementationNamedPropertyGetter
1460 my $dataNode = shift;
1461 my $namedPropertyGetter = shift;
1462 my $interfaceName = $dataNode->name;
1463 my $hasCustomGetter = $dataNode->extendedAttributes->{"HasOverridingNameGetter"} || $dataNode->extendedAttributes->{"CustomGetOwnPropertySlot"};
1465 # FIXME: Remove hard-coded HTMLOptionsCollection reference by changing HTMLOptionsCollection to not inherit
1466 # from HTMLCollection per W3C spec (http://www.w3.org/TR/2003/REC-DOM-Level-2-HTML-20030109/html.html#HTMLOptionsCollection).
1467 if ($interfaceName eq "HTMLOptionsCollection") {
1468 $interfaceName = "HTMLCollection";
1469 $hasCustomGetter = 1;
1472 if ($interfaceName eq "HTMLAppletElement" || $interfaceName eq "HTMLEmbedElement" || $interfaceName eq "HTMLObjectElement") {
1473 $hasCustomGetter = 1;
1476 my $hasGetter = $dataNode->extendedAttributes->{"HasNameGetter"} || $hasCustomGetter || $namedPropertyGetter;
1481 if ($namedPropertyGetter && $namedPropertyGetter->type ne "Node" && !$namedPropertyGetter->extendedAttributes->{"Custom"} && !$hasCustomGetter) {
1482 $implIncludes{"V8Collection.h"} = 1;
1483 my $type = $namedPropertyGetter->type;
1484 push(@implContent, <<END);
1485 setCollectionNamedGetter<${interfaceName}, ${type}>(desc);
1490 my $hasSetter = $dataNode->extendedAttributes->{"DelegatingPutFunction"};
1491 # FIXME: Try to remove hard-coded HTMLDocument reference by aligning handling of document.all with JSC bindings.
1492 my $hasDeleter = $dataNode->extendedAttributes->{"CustomDeleteProperty"} || $interfaceName eq "HTMLDocument";
1493 my $hasEnumerator = $dataNode->extendedAttributes->{"CustomGetPropertyNames"};
1494 my $setOn = "Instance";
1496 # V8 has access-check callback API (see ObjectTemplate::SetAccessCheckCallbacks) and it's used on DOMWindow
1497 # instead of deleters or enumerators. In addition, the getter should be set on prototype template, to
1498 # get implementation straight out of the DOMWindow prototype regardless of what prototype is actually set
1500 if ($interfaceName eq "DOMWindow") {
1501 $setOn = "Prototype";
1506 push(@implContent, " desc->${setOn}Template()->SetNamedPropertyHandler(V8${interfaceName}::namedPropertyGetter, ");
1507 push(@implContent, $hasSetter ? "V8${interfaceName}::namedPropertySetter, " : "0, ");
1508 # If there is a custom enumerator, there MUST be custom query to properly communicate property attributes.
1509 push(@implContent, $hasEnumerator ? "V8${interfaceName}::namedPropertyQuery, " : "0, ");
1510 push(@implContent, $hasDeleter ? "V8${interfaceName}::namedPropertyDeleter, " : "0, ");
1511 push(@implContent, $hasEnumerator ? "V8${interfaceName}::namedPropertyEnumerator" : "0");
1512 push(@implContent, ");\n");
1515 sub GenerateImplementationCustomCall
1517 my $dataNode = shift;
1518 my $interfaceName = $dataNode->name;
1519 my $hasCustomCall = $dataNode->extendedAttributes->{"CustomCall"};
1521 # FIXME: Remove hard-coded HTMLOptionsCollection reference.
1522 if ($interfaceName eq "HTMLOptionsCollection") {
1523 $interfaceName = "HTMLCollection";
1527 if ($hasCustomCall) {
1528 push(@implContent, " desc->InstanceTemplate()->SetCallAsFunctionHandler(V8${interfaceName}::callAsFunctionCallback);\n");
1532 sub GenerateImplementationMasqueradesAsUndefined
1534 my $dataNode = shift;
1535 if ($dataNode->extendedAttributes->{"MasqueradesAsUndefined"})
1537 push(@implContent, " desc->InstanceTemplate()->MarkAsUndetectable();\n");
1541 sub GenerateImplementation
1544 my $dataNode = shift;
1545 my $interfaceName = $dataNode->name;
1546 my $visibleInterfaceName = GetVisibleInterfaceName($interfaceName);
1547 my $className = "V8$interfaceName";
1548 my $implClassName = $interfaceName;
1550 my $hasLegacyParent = $dataNode->extendedAttributes->{"LegacyParent"};
1552 # - Add default header template
1553 push(@implFixedHeader, GenerateImplementationContentHeader($dataNode));
1555 $implIncludes{"RuntimeEnabledFeatures.h"} = 1;
1556 $implIncludes{"V8Proxy.h"} = 1;
1557 $implIncludes{"V8Binding.h"} = 1;
1558 $implIncludes{"V8BindingState.h"} = 1;
1559 $implIncludes{"V8DOMWrapper.h"} = 1;
1560 $implIncludes{"V8IsolatedContext.h"} = 1;
1562 if ($className =~ /^V8SVGAnimated/) {
1563 AddIncludesForSVGAnimatedType($interfaceName);
1566 AddIncludesForType($interfaceName);
1568 my $toActive = IsActiveDomType($interfaceName) ? "${className}::toActiveDOMObject" : "0";
1570 push(@implContentDecls, "namespace WebCore {\n\n");
1571 push(@implContentDecls, "WrapperTypeInfo ${className}::info = { ${className}::GetTemplate, ${className}::derefObject, ${toActive} };\n\n");
1572 push(@implContentDecls, "namespace ${interfaceName}Internal {\n\n");
1573 push(@implContentDecls, "template <typename T> void V8_USE(T) { }\n\n");
1575 my $hasConstructors = 0;
1576 my $serializedAttribute;
1577 # Generate property accessors for attributes.
1578 for ($index = 0; $index < @{$dataNode->attributes}; $index++) {
1579 $attribute = @{$dataNode->attributes}[$index];
1580 $attrName = $attribute->signature->name;
1581 $attrType = $attribute->signature->type;
1583 # Generate special code for the constructor attributes.
1584 if ($attrType =~ /Constructor$/) {
1585 if (!($attribute->signature->extendedAttributes->{"CustomGetter"} ||
1586 $attribute->signature->extendedAttributes->{"V8CustomGetter"})) {
1587 $hasConstructors = 1;
1592 if ($attrType eq "EventListener" && $interfaceName eq "DOMWindow") {
1593 $attribute->signature->extendedAttributes->{"v8OnProto"} = 1;
1596 # Attributes of type SerializedScriptValue are set in the
1597 # constructor and don't require callbacks.
1598 if ($attrType eq "SerializedScriptValue") {
1599 die "Only one attribute of type SerializedScriptValue supported" if $serializedAttribute;
1600 $implIncludes{"SerializedScriptValue.h"} = 1;
1601 $serializedAttribute = $attribute;
1605 # Do not generate accessor if this is a custom attribute. The
1606 # call will be forwarded to a hand-written accessor
1608 if ($attribute->signature->extendedAttributes->{"Custom"} ||
1609 $attribute->signature->extendedAttributes->{"V8Custom"}) {
1613 # Generate the accessor.
1614 if (!($attribute->signature->extendedAttributes->{"CustomGetter"} ||
1615 $attribute->signature->extendedAttributes->{"V8CustomGetter"})) {
1616 GenerateNormalAttrGetter($attribute, $dataNode, $implClassName, $interfaceName);
1618 if (!$attribute->signature->extendedAttributes->{"CustomSetter"} &&
1619 !$attribute->signature->extendedAttributes->{"V8CustomSetter"} &&
1620 !$attribute->signature->extendedAttributes->{"Replaceable"} &&
1621 $attribute->type !~ /^readonly/ &&
1622 !$attribute->signature->extendedAttributes->{"V8ReadOnly"}) {
1623 GenerateNormalAttrSetter($attribute, $dataNode, $implClassName, $interfaceName);
1627 if ($hasConstructors) {
1628 GenerateConstructorGetter($implClassName);
1631 $codeGenerator->LinkOverloadedFunctions($dataNode);
1634 my $namedPropertyGetter;
1635 # Generate methods for functions.
1636 foreach my $function (@{$dataNode->functions}) {
1637 if (!($function->signature->extendedAttributes->{"Custom"} || $function->signature->extendedAttributes->{"V8Custom"})) {
1638 GenerateFunctionCallback($function, $dataNode, $implClassName);
1639 if ($function->{overloadIndex} > 1 && $function->{overloadIndex} == @{$function->{overloads}}) {
1640 GenerateOverloadedFunctionCallback($function, $dataNode, $implClassName);
1644 if ($function->signature->name eq "item") {
1645 $indexer = $function->signature;
1648 if ($function->signature->name eq "namedItem") {
1649 $namedPropertyGetter = $function->signature;
1652 # If the function does not need domain security check, we need to
1653 # generate an access getter that returns different function objects
1654 # for different calling context.
1655 if (($dataNode->extendedAttributes->{"CheckDomainSecurity"} || ($interfaceName eq "DOMWindow")) && $function->signature->extendedAttributes->{"DoNotCheckDomainSecurity"}) {
1656 GenerateDomainSafeFunctionGetter($function, $implClassName);
1661 my $attributes = $dataNode->attributes;
1663 # For the DOMWindow interface we partition the attributes into the
1664 # ones that disallows shadowing and the rest.
1665 my @disallowsShadowing;
1666 # Also separate out attributes that are enabled at runtime so we can process them specially.
1667 my @enabledAtRuntime;
1669 foreach my $attribute (@$attributes) {
1671 if ($interfaceName eq "DOMWindow" && $attribute->signature->extendedAttributes->{"V8DisallowShadowing"}) {
1672 push(@disallowsShadowing, $attribute);
1673 } elsif ($attribute->signature->extendedAttributes->{"EnabledAtRuntime"}) {
1674 push(@enabledAtRuntime, $attribute);
1676 push(@normal, $attribute);
1679 $attributes = \@normal;
1680 # Put the attributes that disallow shadowing on the shadow object.
1681 if (@disallowsShadowing) {
1682 push(@implContent, "static const BatchedAttribute shadowAttrs[] = {\n");
1683 GenerateBatchedAttributeData($dataNode, \@disallowsShadowing);
1684 push(@implContent, "};\n");
1687 my $has_attributes = 0;
1689 $has_attributes = 1;
1690 push(@implContent, "static const BatchedAttribute ${interfaceName}Attrs[] = {\n");
1691 GenerateBatchedAttributeData($dataNode, $attributes);
1692 push(@implContent, "};\n");
1695 # Setup table of standard callback functions
1698 foreach my $function (@{$dataNode->functions}) {
1699 # Only one table entry is needed for overloaded methods:
1700 next if $function->{overloadIndex} > 1;
1702 my $attrExt = $function->signature->extendedAttributes;
1703 # Don't put any nonstandard functions into this table:
1704 if ($attrExt->{"V8OnInstance"}) {
1707 if ($attrExt->{"EnabledAtRuntime"} || RequiresCustomSignature($function) || $attrExt->{"V8DoNotCheckSignature"}) {
1710 if ($attrExt->{"DoNotCheckDomainSecurity"} &&
1711 ($dataNode->extendedAttributes->{"CheckDomainSecurity"} || $interfaceName eq "DOMWindow")) {
1714 if ($attrExt->{"DontEnum"} || $attrExt->{"V8ReadOnly"}) {
1717 if (!$has_callbacks) {
1719 push(@implContent, "static const BatchedCallback ${interfaceName}Callbacks[] = {\n");
1721 my $name = $function->signature->name;
1722 my $callback = GetFunctionTemplateCallbackName($function, $interfaceName);
1723 push(@implContent, <<END);
1724 {"$name", $callback},
1728 push(@implContent, "};\n") if $has_callbacks;
1731 my $has_constants = 0;
1732 if (@{$dataNode->constants}) {
1734 push(@implContent, "static const BatchedConstant ${interfaceName}Consts[] = {\n");
1736 foreach my $constant (@{$dataNode->constants}) {
1737 my $name = $constant->name;
1738 my $value = $constant->value;
1739 # FIXME: we need the static_cast here only because of one constant, NodeFilter.idl
1740 # defines "const unsigned long SHOW_ALL = 0xFFFFFFFF". It would be better if we
1741 # handled this here, and converted it to a -1 constant in the c++ output.
1742 push(@implContent, <<END);
1743 {"${name}", static_cast<signed int>($value)},
1746 if ($has_constants) {
1747 push(@implContent, "};\n");
1748 push(@implContent, $codeGenerator->GenerateCompileTimeCheckForEnumsIfNeeded($dataNode));
1751 push(@implContentDecls, "} // namespace ${interfaceName}Internal\n\n");
1753 # In namespace WebCore, add generated implementation for 'CanBeConstructed'.
1754 if ($dataNode->extendedAttributes->{"CanBeConstructed"} && !$dataNode->extendedAttributes->{"CustomConstructor"} && !$dataNode->extendedAttributes->{"V8CustomConstructor"}) {
1755 my $v8ConstructFunction;
1756 my $callWith = $dataNode->extendedAttributes->{"CallWith"};
1757 if ($callWith and $callWith eq "ScriptExecutionContext") {
1758 $v8ConstructFunction = "constructDOMObjectWithScriptExecutionContext";
1760 $v8ConstructFunction = "constructDOMObject";
1762 push(@implContent, <<END);
1763 v8::Handle<v8::Value> ${className}::constructorCallback(const v8::Arguments& args)
1765 INC_STATS("DOM.${interfaceName}.Contructor");
1766 return V8Proxy::${v8ConstructFunction}<$interfaceName>(args, &info);
1771 my $access_check = "";
1772 if ($dataNode->extendedAttributes->{"CheckDomainSecurity"} && !($interfaceName eq "DOMWindow")) {
1773 $access_check = "instance->SetAccessCheckCallbacks(V8${interfaceName}::namedSecurityCheck, V8${interfaceName}::indexedSecurityCheck, v8::External::Wrap(&V8${interfaceName}::info));";
1776 # For the DOMWindow interface, generate the shadow object template
1777 # configuration method.
1778 if ($implClassName eq "DOMWindow") {
1779 push(@implContent, <<END);
1780 static v8::Persistent<v8::ObjectTemplate> ConfigureShadowObjectTemplate(v8::Persistent<v8::ObjectTemplate> templ)
1782 batchConfigureAttributes(templ, v8::Handle<v8::ObjectTemplate>(), shadowAttrs, sizeof(shadowAttrs) / sizeof(*shadowAttrs));
1784 // Install a security handler with V8.
1785 templ->SetAccessCheckCallbacks(V8DOMWindow::namedSecurityCheck, V8DOMWindow::indexedSecurityCheck, v8::External::Wrap(&V8DOMWindow::info));
1786 templ->SetInternalFieldCount(V8DOMWindow::internalFieldCount);
1792 # find the super descriptor
1793 my $parentClassTemplate = "";
1794 foreach (@{$dataNode->parents}) {
1795 my $parent = $codeGenerator->StripModule($_);
1796 if ($parent eq "EventTarget") { next; }
1797 $implIncludes{"V8${parent}.h"} = 1;
1798 $parentClassTemplate = "V8" . $parent . "::GetTemplate()";
1801 if (!$parentClassTemplate) {
1802 $parentClassTemplate = "v8::Persistent<v8::FunctionTemplate>()";
1805 # Generate the template configuration method
1806 push(@implContent, <<END);
1807 static v8::Persistent<v8::FunctionTemplate> Configure${className}Template(v8::Persistent<v8::FunctionTemplate> desc)
1809 v8::Local<v8::Signature> defaultSignature = configureTemplate(desc, \"${visibleInterfaceName}\", $parentClassTemplate, V8${interfaceName}::internalFieldCount,
1811 # Set up our attributes if we have them
1812 if ($has_attributes) {
1813 push(@implContent, <<END);
1814 ${interfaceName}Attrs, sizeof(${interfaceName}Attrs) / sizeof(*${interfaceName}Attrs),
1817 push(@implContent, <<END);
1822 if ($has_callbacks) {
1823 push(@implContent, <<END);
1824 ${interfaceName}Callbacks, sizeof(${interfaceName}Callbacks) / sizeof(*${interfaceName}Callbacks));
1827 push(@implContent, <<END);
1832 if ($dataNode->extendedAttributes->{"CustomConstructor"} || $dataNode->extendedAttributes->{"V8CustomConstructor"} || $dataNode->extendedAttributes->{"CanBeConstructed"}) {
1833 push(@implContent, <<END);
1834 desc->SetCallHandler(V8${interfaceName}::constructorCallback);
1838 if ($access_check or @enabledAtRuntime or @{$dataNode->functions} or $has_constants) {
1839 push(@implContent, <<END);
1840 v8::Local<v8::ObjectTemplate> instance = desc->InstanceTemplate();
1841 v8::Local<v8::ObjectTemplate> proto = desc->PrototypeTemplate();
1845 push(@implContent, " $access_check\n");
1847 # Setup the enable-at-runtime attrs if we have them
1848 foreach my $runtime_attr (@enabledAtRuntime) {
1849 # A function named RuntimeEnabledFeatures::{methodName}Enabled() need to be written by hand.
1850 $enable_function = "RuntimeEnabledFeatures::" . $codeGenerator->WK_lcfirst($runtime_attr->signature->name) . "Enabled";
1851 my $conditionalString = GenerateConditionalString($runtime_attr->signature);
1852 push(@implContent, "\n#if ${conditionalString}\n") if $conditionalString;
1853 push(@implContent, " if (${enable_function}()) {\n");
1854 push(@implContent, " static const BatchedAttribute attrData =\\\n");
1855 GenerateSingleBatchedAttribute($interfaceName, $runtime_attr, ";", " ");
1856 push(@implContent, <<END);
1857 configureAttribute(instance, proto, attrData);
1860 push(@implContent, "\n#endif // ${conditionalString}\n") if $conditionalString;
1863 GenerateImplementationIndexer($dataNode, $indexer);
1864 GenerateImplementationNamedPropertyGetter($dataNode, $namedPropertyGetter);
1865 GenerateImplementationCustomCall($dataNode);
1866 GenerateImplementationMasqueradesAsUndefined($dataNode);
1868 # Define our functions with Set() or SetAccessor()
1869 $total_functions = 0;
1870 foreach my $function (@{$dataNode->functions}) {
1871 # Only one accessor is needed for overloaded methods:
1872 next if $function->{overloadIndex} > 1;
1875 my $attrExt = $function->signature->extendedAttributes;
1876 my $name = $function->signature->name;
1878 my $property_attributes = "v8::DontDelete";
1879 if ($attrExt->{"DontEnum"}) {
1880 $property_attributes .= " | v8::DontEnum";
1882 if ($attrExt->{"V8ReadOnly"}) {
1883 $property_attributes .= " | v8::ReadOnly";
1886 my $commentInfo = "Function '$name' (ExtAttr: '" . join(' ', keys(%{$attrExt})) . "')";
1888 my $template = "proto";
1889 if ($attrExt->{"V8OnInstance"}) {
1890 $template = "instance";
1893 my $conditional = "";
1894 if ($attrExt->{"EnabledAtRuntime"}) {
1895 # Only call Set()/SetAccessor() if this method should be enabled
1896 $enable_function = "RuntimeEnabledFeatures::" . $codeGenerator->WK_lcfirst($function->signature->name) . "Enabled";
1897 $conditional = "if (${enable_function}())\n ";
1900 if ($attrExt->{"DoNotCheckDomainSecurity"} &&
1901 ($dataNode->extendedAttributes->{"CheckDomainSecurity"} || $interfaceName eq "DOMWindow")) {
1902 # Mark the accessor as ReadOnly and set it on the proto object so
1903 # it can be shadowed. This is really a hack to make it work.
1904 # There are several sceneria to call into the accessor:
1905 # 1) from the same domain: "window.open":
1906 # the accessor finds the DOM wrapper in the proto chain;
1907 # 2) from the same domain: "window.__proto__.open":
1908 # the accessor will NOT find a DOM wrapper in the prototype chain
1909 # 3) from another domain: "window.open":
1910 # the access find the DOM wrapper in the prototype chain
1911 # "window.__proto__.open" from another domain will fail when
1912 # accessing '__proto__'
1914 # The solution is very hacky and fragile, it really needs to be replaced
1915 # by a better solution.
1916 $property_attributes .= " | v8::ReadOnly";
1917 push(@implContent, <<END);
1920 ${conditional}$template->SetAccessor(v8::String::New("$name"), ${interfaceName}Internal::${name}AttrGetter, 0, v8::Handle<v8::Value>(), v8::ALL_CAN_READ, static_cast<v8::PropertyAttribute>($property_attributes));
1926 my $signature = "defaultSignature";
1927 if ($attrExt->{"V8DoNotCheckSignature"}) {
1928 $signature = "v8::Local<v8::Signature>()";
1931 if (RequiresCustomSignature($function)) {
1932 $signature = "${name}Signature";
1933 push(@implContent, "\n // Custom Signature '$name'\n", CreateCustomSignature($function));
1936 # Normal function call is a template
1937 my $callback = GetFunctionTemplateCallbackName($function, $interfaceName);
1939 if ($property_attributes eq "v8::DontDelete") {
1940 $property_attributes = "";
1942 $property_attributes = ", static_cast<v8::PropertyAttribute>($property_attributes)";
1945 if ($template eq "proto" && $conditional eq "" && $signature eq "defaultSignature" && $property_attributes eq "") {
1946 # Standard type of callback, already created in the batch, so skip it here.
1950 push(@implContent, <<END);
1951 ${conditional}$template->Set(v8::String::New("$name"), v8::FunctionTemplate::New($callback, v8::Handle<v8::Value>(), ${signature})$property_attributes);
1956 die "Wrong number of callbacks generated for $interfaceName ($num_callbacks, should be $total_functions)" if $num_callbacks != $total_functions;
1958 if ($has_constants) {
1959 push(@implContent, <<END);
1960 batchConfigureConstants(desc, proto, ${interfaceName}Consts, sizeof(${interfaceName}Consts) / sizeof(*${interfaceName}Consts));
1965 if ($interfaceName eq "DOMWindow") {
1966 push(@implContent, <<END);
1968 proto->SetInternalFieldCount(V8DOMWindow::internalFieldCount);
1969 desc->SetHiddenPrototype(true);
1970 instance->SetInternalFieldCount(V8DOMWindow::internalFieldCount);
1971 // Set access check callbacks, but turned off initially.
1972 // When a context is detached from a frame, turn on the access check.
1973 // Turning on checks also invalidates inline caches of the object.
1974 instance->SetAccessCheckCallbacks(V8DOMWindow::namedSecurityCheck, V8DOMWindow::indexedSecurityCheck, v8::External::Wrap(&V8DOMWindow::info), false);
1977 if ($interfaceName eq "Location") {
1978 push(@implContent, <<END);
1980 // For security reasons, these functions are on the instance instead
1981 // of on the prototype object to ensure that they cannot be overwritten.
1982 instance->SetAccessor(v8::String::New("reload"), V8Location::reloadAccessorGetter, 0, v8::Handle<v8::Value>(), v8::ALL_CAN_READ, static_cast<v8::PropertyAttribute>(v8::DontDelete | v8::ReadOnly));
1983 instance->SetAccessor(v8::String::New("replace"), V8Location::replaceAccessorGetter, 0, v8::Handle<v8::Value>(), v8::ALL_CAN_READ, static_cast<v8::PropertyAttribute>(v8::DontDelete | v8::ReadOnly));
1984 instance->SetAccessor(v8::String::New("assign"), V8Location::assignAccessorGetter, 0, v8::Handle<v8::Value>(), v8::ALL_CAN_READ, static_cast<v8::PropertyAttribute>(v8::DontDelete | v8::ReadOnly));
1988 my $nativeType = GetNativeTypeForConversions($interfaceName);
1989 if ($dataNode->extendedAttributes->{"PODType"}) {
1990 $nativeType = "V8SVGPODTypeWrapper<${nativeType}>";
1992 push(@implContent, <<END);
1994 // Custom toString template
1995 desc->Set(getToStringName(), getToStringTemplate());
1999 v8::Persistent<v8::FunctionTemplate> ${className}::GetRawTemplate()
2001 static v8::Persistent<v8::FunctionTemplate> ${className}RawCache = createRawTemplate();
2002 return ${className}RawCache;
2005 v8::Persistent<v8::FunctionTemplate> ${className}::GetTemplate()\
2007 static v8::Persistent<v8::FunctionTemplate> ${className}Cache = Configure${className}Template(GetRawTemplate());
2008 return ${className}Cache;
2011 ${nativeType}* ${className}::toNative(v8::Handle<v8::Object> object)
2013 return reinterpret_cast<${nativeType}*>(object->GetPointerFromInternalField(v8DOMWrapperObjectIndex));
2016 bool ${className}::HasInstance(v8::Handle<v8::Value> value)
2018 return GetRawTemplate()->HasInstance(value);
2023 if (IsActiveDomType($interfaceName)) {
2024 # MessagePort is handled like an active dom object even though it doesn't inherit
2025 # from ActiveDOMObject, so don't try to cast it to ActiveDOMObject.
2026 my $returnValue = $interfaceName eq "MessagePort" ? "0" : "toNative(object)";
2027 push(@implContent, <<END);
2028 ActiveDOMObject* ${className}::toActiveDOMObject(v8::Handle<v8::Object> object)
2030 return ${returnValue};
2035 if ($implClassName eq "DOMWindow") {
2036 push(@implContent, <<END);
2037 v8::Persistent<v8::ObjectTemplate> V8DOMWindow::GetShadowObjectTemplate()
2039 static v8::Persistent<v8::ObjectTemplate> V8DOMWindowShadowObjectCache;
2040 if (V8DOMWindowShadowObjectCache.IsEmpty()) {
2041 V8DOMWindowShadowObjectCache = v8::Persistent<v8::ObjectTemplate>::New(v8::ObjectTemplate::New());
2042 ConfigureShadowObjectTemplate(V8DOMWindowShadowObjectCache);
2044 return V8DOMWindowShadowObjectCache;
2049 GenerateToV8Converters($dataNode, $interfaceName, $className, $nativeType, $serializedAttribute);
2051 push(@implContent, <<END);
2053 void ${className}::derefObject(void* object)
2057 if (IsRefPtrType($interfaceName)) {
2058 push(@implContent, <<END);
2059 static_cast<${nativeType}*>(object)->deref();
2063 push(@implContent, <<END);
2066 } // namespace WebCore
2069 my $conditionalString = GenerateConditionalString($dataNode);
2070 push(@implContent, "\n#endif // ${conditionalString}\n") if $conditionalString;
2072 # We've already added the header for this file in implFixedHeader, so remove
2073 # it from implIncludes to ensure we don't #include it twice.
2074 delete $implIncludes{"${className}.h"};
2077 sub GenerateHeaderContentHeader
2079 my $dataNode = shift;
2080 my $className = "V8" . $dataNode->name;
2081 my $conditionalString = GenerateConditionalString($dataNode);
2083 my @headerContentHeader = split("\r", $headerTemplate);
2085 push(@headerContentHeader, "\n#if ${conditionalString}\n") if $conditionalString;
2086 push(@headerContentHeader, "\n#ifndef ${className}" . "_h");
2087 push(@headerContentHeader, "\n#define ${className}" . "_h\n\n");
2088 return @headerContentHeader;
2091 sub GenerateImplementationContentHeader
2093 my $dataNode = shift;
2094 my $className = "V8" . $dataNode->name;
2095 my $conditionalString = GenerateConditionalString($dataNode);
2097 my @implContentHeader = split("\r", $headerTemplate);
2099 push(@implContentHeader, "\n#include \"config.h\"\n");
2100 push(@implContentHeader, "#include \"${className}.h\"\n\n");
2101 push(@implContentHeader, "#if ${conditionalString}\n\n") if $conditionalString;
2102 return @implContentHeader;
2105 sub GenerateCallbackHeader
2108 my $dataNode = shift;
2110 my $interfaceName = $dataNode->name;
2111 my $className = "V8$interfaceName";
2114 # - Add default header template
2115 push(@headerContent, GenerateHeaderContentHeader($dataNode));
2117 if ("$interfaceName.h" lt "WorldContextHandle.h") {
2118 push(@headerContent, "#include \"$interfaceName.h\"\n");
2119 push(@headerContent, "#include \"WorldContextHandle.h\"\n");
2121 push(@headerContent, "#include \"WorldContextHandle.h\"\n");
2122 push(@headerContent, "#include \"$interfaceName.h\"\n");
2124 push(@headerContent, "#include <v8.h>\n");
2125 push(@headerContent, "#include <wtf/Forward.h>\n");
2127 push(@headerContent, "\nnamespace WebCore {\n\n");
2128 push(@headerContent, "class $className : public $interfaceName {\n");
2130 push(@headerContent, <<END);
2132 static PassRefPtr<${className}> create(v8::Local<v8::Value> value)
2134 ASSERT(value->IsObject());
2135 return adoptRef(new ${className}(value->ToObject()));
2138 virtual ~${className}();
2143 my $numFunctions = @{$dataNode->functions};
2144 if ($numFunctions > 0) {
2145 push(@headerContent, " // Functions\n");
2146 foreach my $function (@{$dataNode->functions}) {
2147 my @params = @{$function->parameters};
2148 if (!$function->signature->extendedAttributes->{"Custom"} &&
2149 !(GetNativeType($function->signature->type) eq "bool")) {
2150 push(@headerContent, " COMPILE_ASSERT(false)");
2153 push(@headerContent, " virtual " . GetNativeTypeForCallbacks($function->signature->type) . " " . $function->signature->name . "(ScriptExecutionContext*");
2154 foreach my $param (@params) {
2155 push(@headerContent, ", " . GetNativeTypeForCallbacks($param->type) . " " . $param->name);
2158 push(@headerContent, ");\n");
2162 push(@headerContent, <<END);
2165 ${className}(v8::Local<v8::Object>);
2167 v8::Persistent<v8::Object> m_callback;
2168 WorldContextHandle m_worldContext;
2173 push(@headerContent, "}\n\n");
2174 push(@headerContent, "#endif // $className" . "_h\n\n");
2176 my $conditionalString = GenerateConditionalString($dataNode);
2177 push(@headerContent, "#endif // ${conditionalString}\n") if $conditionalString;
2180 sub GenerateCallbackImplementation
2183 my $dataNode = shift;
2184 my $interfaceName = $dataNode->name;
2185 my $className = "V8$interfaceName";
2187 # - Add default header template
2188 push(@implFixedHeader, GenerateImplementationContentHeader($dataNode));
2190 $implIncludes{"ScriptExecutionContext.h"} = 1;
2191 $implIncludes{"V8CustomVoidCallback.h"} = 1;
2192 $implIncludes{"V8Proxy.h"} = 1;
2194 push(@implContent, "#include <wtf/Assertions.h>\n\n");
2195 push(@implContent, "namespace WebCore {\n\n");
2196 push(@implContent, <<END);
2197 ${className}::${className}(v8::Local<v8::Object> callback)
2198 : m_callback(v8::Persistent<v8::Object>::New(callback))
2199 , m_worldContext(UseCurrentWorld)
2203 ${className}::~${className}()
2205 m_callback.Dispose();
2211 my $numFunctions = @{$dataNode->functions};
2212 if ($numFunctions > 0) {
2213 push(@implContent, "// Functions\n");
2214 foreach my $function (@{$dataNode->functions}) {
2215 my @params = @{$function->parameters};
2216 if ($function->signature->extendedAttributes->{"Custom"} ||
2217 !(GetNativeTypeForCallbacks($function->signature->type) eq "bool")) {
2221 AddIncludesForType($function->signature->type);
2222 push(@implContent, "\n" . GetNativeTypeForCallbacks($function->signature->type) . " ${className}::" . $function->signature->name . "(ScriptExecutionContext* context");
2224 foreach my $param (@params) {
2225 AddIncludesForType($param->type);
2226 push(@implContent, ", " . GetNativeTypeForCallbacks($param->type) . " " . $param->name);
2229 push(@implContent, ")\n");
2230 push(@implContent, "{\n");
2231 push(@implContent, " v8::HandleScope handleScope;\n\n");
2232 push(@implContent, " v8::Handle<v8::Context> v8Context = toV8Context(context, m_worldContext);\n");
2233 push(@implContent, " if (v8Context.IsEmpty())\n");
2234 push(@implContent, " return true;\n\n");
2235 push(@implContent, " v8::Context::Scope scope(v8Context);\n\n");
2238 foreach my $param (@params) {
2239 my $paramName = $param->name;
2240 push(@implContent, " v8::Handle<v8::Value> ${paramName}Handle = toV8(${paramName});\n");
2241 push(@implContent, " if (${paramName}Handle.IsEmpty()) {\n");
2242 push(@implContent, " CRASH();\n");
2243 push(@implContent, " return true;\n");
2244 push(@implContent, " }\n");
2245 push(@argvs, " ${paramName}Handle");
2248 push(@implContent, "\n v8::Handle<v8::Value> argv[] = {\n");
2249 push(@implContent, join(",\n", @argvs));
2250 push(@implContent, "\n };\n\n");
2251 push(@implContent, " bool callbackReturnValue = false;\n");
2252 push(@implContent, " return !invokeCallback(m_callback, " . scalar(@params) . ", argv, callbackReturnValue, context);\n");
2253 push(@implContent, "}\n");
2257 push(@implContent, "\n} // namespace WebCore\n\n");
2259 my $conditionalString = GenerateConditionalString($dataNode);
2260 push(@implContent, "#endif // ${conditionalString}\n") if $conditionalString;
2263 sub GenerateToV8Converters
2265 my $dataNode = shift;
2266 my $interfaceName = shift;
2267 my $className = shift;
2268 my $nativeType = shift;
2269 my $serializedAttribute = shift;
2271 my $domMapFunction = GetDomMapFunction($dataNode, $interfaceName);
2272 my $forceNewObjectInput = IsDOMNodeType($interfaceName) ? ", bool forceNewObject" : "";
2273 my $forceNewObjectCall = IsDOMNodeType($interfaceName) ? ", forceNewObject" : "";
2275 push(@implContent, <<END);
2277 v8::Handle<v8::Object> ${className}::wrap(${nativeType}* impl${forceNewObjectInput})
2279 v8::Handle<v8::Object> wrapper;
2283 if (IsNodeSubType($dataNode)) {
2284 push(@implContent, <<END);
2285 if (impl->document()) {
2286 proxy = V8Proxy::retrieve(impl->document()->frame());
2287 if (proxy && static_cast<Node*>(impl->document()) == static_cast<Node*>(impl))
2288 proxy->windowShell()->initContextIfNeeded();
2294 if ($domMapFunction) {
2295 push(@implContent, " if (!forceNewObject) {\n") if IsDOMNodeType($interfaceName);
2296 if (IsNodeSubType($dataNode)) {
2297 push(@implContent, " wrapper = V8DOMWrapper::getWrapper(impl);\n");
2299 push(@implContent, " wrapper = ${domMapFunction}.get(impl);\n");
2301 push(@implContent, <<END);
2302 if (!wrapper.IsEmpty())
2305 push(@implContent, " }\n") if IsDOMNodeType($interfaceName);
2307 if (IsNodeSubType($dataNode)) {
2308 push(@implContent, <<END);
2310 v8::Handle<v8::Context> context;
2312 context = proxy->context();
2314 // Enter the node's context and create the wrapper in that context.
2315 if (!context.IsEmpty())
2320 push(@implContent, <<END);
2321 wrapper = V8DOMWrapper::instantiateV8Object(proxy, &info, impl);
2323 if (IsNodeSubType($dataNode)) {
2324 push(@implContent, <<END);
2325 // Exit the node's context if it was entered.
2326 if (!context.IsEmpty())
2331 push(@implContent, <<END);
2332 if (wrapper.IsEmpty())
2335 push(@implContent, "\n impl->ref();\n") if IsRefPtrType($interfaceName);
2337 # Eagerly deserialize attributes of type SerializedScriptValue
2338 # while we're in the right context.
2339 if ($serializedAttribute) {
2340 die "Attribute of type SerializedScriptValue expected" if $serializedAttribute->signature->type ne "SerializedScriptValue";
2341 my $attrName = $serializedAttribute->signature->name;
2342 my $attrAttr = "v8::DontDelete";
2343 if ($serializedAttribute->type =~ /^readonly/) {
2344 $attrAttr .= " | v8::ReadOnly";
2346 $attrAttr = "static_cast<v8::PropertyAttribute>($attrAttr)";
2347 my $getterFunc = $codeGenerator->WK_lcfirst($attrName);
2348 push(@implContent, <<END);
2349 SerializedScriptValue::deserializeAndSetProperty(wrapper, "${attrName}", ${attrAttr}, impl->${getterFunc}());
2353 if ($domMapFunction) {
2354 push(@implContent, <<END);
2355 ${domMapFunction}.set(impl, v8::Persistent<v8::Object>::New(wrapper));
2359 push(@implContent, <<END);
2364 if (IsRefPtrType($interfaceName)) {
2365 push(@implContent, <<END);
2367 v8::Handle<v8::Value> toV8(PassRefPtr<${nativeType} > impl${forceNewObjectInput})
2369 return toV8(impl.get()${forceNewObjectCall});
2374 if (!HasCustomToV8Implementation($dataNode, $interfaceName)) {
2375 push(@implContent, <<END);
2377 v8::Handle<v8::Value> toV8(${nativeType}* impl${forceNewObjectInput})
2381 return ${className}::wrap(impl${forceNewObjectCall});
2387 sub HasCustomToV8Implementation {
2388 # FIXME: This subroutine is lame. Probably should be an .idl attribute (CustomToV8)?
2390 $interfaceName = shift;
2392 # We generate a custom converter (but JSC doesn't) for the following:
2393 return 1 if $interfaceName eq "CSSStyleSheet";
2394 return 1 if $interfaceName eq "CanvasPixelArray";
2395 return 1 if $interfaceName eq "DOMWindow";
2396 return 1 if $interfaceName eq "Element";
2397 return 1 if $interfaceName eq "HTMLDocument";
2398 return 1 if $interfaceName eq "HTMLElement";
2399 return 1 if $interfaceName eq "Location";
2400 return 1 if $interfaceName eq "NamedNodeMap";
2401 return 1 if $interfaceName eq "SVGDocument";
2402 return 1 if $interfaceName eq "SVGElement";
2403 return 1 if $interfaceName eq "ScriptProfile";
2404 return 1 if $interfaceName eq "ScriptProfileNode";
2405 return 1 if $interfaceName eq "WorkerContext";
2406 # We don't generate a custom converter (but JSC does) for the following:
2407 return 0 if $interfaceName eq "AbstractWorker";
2408 return 0 if $interfaceName eq "CanvasRenderingContext";
2409 return 0 if $interfaceName eq "ImageData";
2410 return 0 if $interfaceName eq "SVGElementInstance";
2412 # For everything else, do what JSC does.
2413 return $dataNode->extendedAttributes->{"CustomToJS"};
2416 sub GetDomMapFunction
2418 my $dataNode = shift;
2420 return "getDOMSVGElementInstanceMap()" if $type eq "SVGElementInstance";
2421 return "getDOMNodeMap()" if ($dataNode && IsNodeSubType($dataNode));
2422 # Only use getDOMSVGObjectWithContextMap() for non-node svg objects
2423 return "getDOMSVGObjectWithContextMap()" if $type =~ /SVG/;
2424 return "" if $type eq "DOMImplementation";
2425 return "getActiveDOMObjectMap()" if IsActiveDomType($type);
2426 return "getDOMObjectMap()";
2431 # FIXME: Consider making this an .idl attribute.
2433 return 1 if $type eq "EventSource";
2434 return 1 if $type eq "MessagePort";
2435 return 1 if $type eq "XMLHttpRequest";
2436 return 1 if $type eq "WebSocket";
2437 return 1 if $type eq "Worker";
2438 return 1 if $type eq "SharedWorker";
2439 return 1 if $type eq "IDBRequest";
2443 sub GetNativeTypeForConversions
2446 return "FloatRect" if $type eq "SVGRect";
2447 return "FloatPoint" if $type eq "SVGPoint";
2448 return "AffineTransform" if $type eq "SVGMatrix";
2449 return "float" if $type eq "SVGNumber";
2453 sub GenerateFunctionCallString()
2455 my $function = shift;
2456 my $numberOfParameters = shift;
2458 my $implClassName = shift;
2460 my $name = $function->signature->name;
2461 my $isPodType = IsPodType($implClassName);
2462 my $returnType = GetTypeFromSignature($function->signature);
2463 my $returnsPodType = IsPodType($returnType);
2464 my $nativeReturnType = GetNativeType($returnType, 0);
2467 # Special case: SVG matrix transform methods should not mutate
2468 # the matrix but return a copy
2470 if ($implClassName eq "SVGMatrix" && $function->signature->type eq "SVGMatrix") {
2474 if ($function->signature->extendedAttributes->{"v8implname"}) {
2475 $name = $function->signature->extendedAttributes->{"v8implname"};
2478 if ($function->signature->extendedAttributes->{"ImplementationFunction"}) {
2479 $name = $function->signature->extendedAttributes->{"ImplementationFunction"};
2482 my $functionString = "imp->${name}(";
2485 $functionString = "result.${name}(";
2488 my $returnsListItemPodType = 0;
2489 # SVG lists functions that return POD types require special handling
2490 if (IsSVGListTypeNeedingSpecialHandling($implClassName) && IsSVGListMethod($name) && $returnsPodType) {
2491 $returnsListItemPodType = 1;
2492 $result .= $indent . "SVGList<RefPtr<SVGPODListItem<$nativeReturnType> > >* listImp = imp;\n";
2493 $functionString = "listImp->${name}(";
2497 my $hasScriptState = 0;
2499 my $callWith = $function->signature->extendedAttributes->{"CallWith"};
2501 my $callWithArg = "COMPILE_ASSERT(false)";
2502 if ($callWith eq "DynamicFrame") {
2503 $result .= $indent . "Frame* enteredFrame = V8Proxy::retrieveFrameForEnteredContext();\n";
2504 $result .= $indent . "if (!enteredFrame)\n";
2505 $result .= $indent . " return v8::Undefined();\n";
2506 $callWithArg = "enteredFrame";
2507 } elsif ($callWith eq "ScriptState") {
2508 $result .= $indent . "EmptyScriptState state;\n";
2509 $callWithArg = "&state";
2510 $hasScriptState = 1;
2511 } elsif ($callWith eq "ScriptExecutionContext") {
2512 $result .= $indent . "ScriptExecutionContext* scriptContext = getScriptExecutionContext();\n";
2513 $result .= $indent . "if (!scriptContext)\n";
2514 $result .= $indent . " return v8::Undefined();\n";
2515 $callWithArg = "scriptContext";
2517 $functionString .= ", " if $index;
2518 $functionString .= $callWithArg;
2520 $numberOfParameters++
2523 foreach my $parameter (@{$function->parameters}) {
2524 if ($index eq $numberOfParameters) {
2527 $functionString .= ", " if $index;
2528 my $paramName = $parameter->name;
2529 my $paramType = $parameter->type;
2531 # This is a bit of a hack... we need to convert parameters to methods on SVG lists
2532 # of POD types which are items in the list to appropriate SVGList<> instances
2533 if ($returnsListItemPodType && $paramType . "List" eq $implClassName) {
2534 $paramName = "SVGPODListItem<" . GetNativeType($paramType, 1) . ">::copy($paramName)";
2537 if ($parameter->type eq "NodeFilter" || $parameter->type eq "XPathNSResolver") {
2538 $functionString .= "$paramName.get()";
2540 $functionString .= $paramName;
2545 if ($function->signature->extendedAttributes->{"CustomArgumentHandling"}) {
2546 $functionString .= ", " if $index;
2547 $functionString .= "callStack.get()";
2551 if ($function->signature->extendedAttributes->{"NeedsUserGestureCheck"}) {
2552 $functionString .= ", " if $index;
2553 # FIXME: We need to pass DOMWrapperWorld as a parameter.
2554 # See http://trac.webkit.org/changeset/54182
2555 $functionString .= "processingUserGesture()";
2559 if (@{$function->raisesExceptions}) {
2560 $functionString .= ", " if $index;
2561 $functionString .= "ec";
2564 $functionString .= ")";
2566 my $return = "result";
2567 my $returnIsRef = IsRefPtrType($returnType);
2569 if ($returnType eq "void") {
2570 $result .= $indent . "$functionString;\n";
2571 } elsif ($copyFirst) {
2572 $result .= $indent . GetNativeType($returnType, 0) . " result = *imp;\n" . $indent . "$functionString;\n";
2573 } elsif ($returnsListItemPodType) {
2574 $result .= $indent . "RefPtr<SVGPODListItem<$nativeReturnType> > result = $functionString;\n";
2575 } elsif ($hasScriptState or @{$function->raisesExceptions} or $returnsPodType or $isPodType or IsSVGTypeNeedingContextParameter($returnType)) {
2576 $result .= $indent . $nativeReturnType . " result = $functionString;\n";
2578 # Can inline the function call into the return statement to avoid overhead of using a Ref<> temporary
2579 $return = $functionString;
2583 if (@{$function->raisesExceptions}) {
2584 $result .= $indent . "if (UNLIKELY(ec))\n";
2585 $result .= $indent . " goto fail;\n";
2588 if ($hasScriptState) {
2589 $result .= $indent . "if (state.hadException())\n";
2590 $result .= $indent . " return throwError(state.exception());\n"
2593 # If the return type is a POD type, separate out the wrapper generation
2594 if ($returnsListItemPodType) {
2595 $result .= $indent . "RefPtr<V8SVGPODTypeWrapper<" . $nativeReturnType . "> > wrapper = ";
2596 $result .= "V8SVGPODTypeWrapperCreatorForList<" . $nativeReturnType . ">::create($return, imp->associatedAttributeName());\n";
2597 $return = "wrapper";
2598 } elsif ($returnsPodType) {
2599 $result .= $indent . "RefPtr<V8SVGPODTypeWrapper<" . $nativeReturnType . "> > wrapper = ";
2600 $result .= GenerateSVGStaticPodTypeWrapper($returnType, $return) . ";\n";
2601 $return = "wrapper";
2604 my $generatedSVGContextRetrieval = 0;
2605 # If the return type needs an SVG context, output it
2606 if (IsSVGTypeNeedingContextParameter($returnType)) {
2607 $result .= GenerateSVGContextAssignment($implClassName, $return . ".get()", $indent);
2608 $generatedSVGContextRetrieval = 1;
2611 if (IsSVGTypeNeedingContextParameter($implClassName) && $implClassName =~ /List$/ && IsSVGListMutator($name)) {
2612 if (!$generatedSVGContextRetrieval) {
2613 $result .= GenerateSVGContextRetrieval($implClassName, $indent);
2614 $generatedSVGContextRetrieval = 1;
2617 $result .= $indent . "context->svgAttributeChanged(imp->associatedAttributeName());\n";
2618 $implIncludes{"SVGElement.h"} = 1;
2621 # If the implementing class is a POD type, commit changes
2623 if (!$generatedSVGContextRetrieval) {
2624 $result .= GenerateSVGContextRetrieval($implClassName, $indent);
2625 $generatedSVGContextRetrieval = 1;
2628 $result .= $indent . "impWrapper->commitChange(impInstance, context);\n";
2631 if ($returnsPodType) {
2632 $implIncludes{"V8${returnType}.h"} = 1;
2633 $result .= $indent . "return toV8(wrapper.release());\n";
2635 $return .= ".release()" if ($returnIsRef);
2636 $result .= $indent . ReturnNativeToJSValue($function->signature, $return, $indent) . ";\n";
2643 sub GetTypeFromSignature
2645 my $signature = shift;
2647 return $codeGenerator->StripModule($signature->type);
2651 sub GetNativeTypeFromSignature
2653 my $signature = shift;
2654 my $parameterIndex = shift;
2656 my $type = GetTypeFromSignature($signature);
2658 if ($type eq "unsigned long" and $signature->extendedAttributes->{"IsIndex"}) {
2659 # Special-case index arguments because we need to check that they aren't < 0.
2663 $type = GetNativeType($type, $parameterIndex >= 0 ? 1 : 0);
2665 if ($parameterIndex >= 0 && $type eq "V8Parameter") {
2667 if ($signature->extendedAttributes->{"ConvertUndefinedOrNullToNullString"}) {
2668 $mode = "WithUndefinedOrNullCheck";
2669 } elsif ($signature->extendedAttributes->{"ConvertNullToNullString"} || $signature->extendedAttributes->{"Reflect"}) {
2670 $mode = "WithNullCheck";
2682 return 0 if $type eq "boolean";
2683 return 0 if $type eq "float";
2684 return 0 if $type eq "int";
2685 return 0 if $type eq "Date";
2686 return 0 if $type eq "DOMString";
2687 return 0 if $type eq "double";
2688 return 0 if $type eq "short";
2689 return 0 if $type eq "long";
2690 return 0 if $type eq "unsigned";
2691 return 0 if $type eq "unsigned long";
2692 return 0 if $type eq "unsigned short";
2693 return 0 if $type eq "SVGAnimatedPoints";
2701 my $isParameter = shift;
2703 if ($type eq "float" or $type eq "double") {
2707 return "V8Parameter" if ($type eq "DOMString" or $type eq "DOMUserData") and $isParameter;
2708 return "int" if $type eq "int";
2709 return "int" if $type eq "short" or $type eq "unsigned short";
2710 return "unsigned" if $type eq "unsigned long";
2711 return "int" if $type eq "long";
2712 return "long long" if $type eq "long long";
2713 return "unsigned long long" if $type eq "unsigned long long";
2714 return "bool" if $type eq "boolean";
2715 return "String" if $type eq "DOMString";
2716 return "Range::CompareHow" if $type eq "CompareHow";
2717 return "FloatRect" if $type eq "SVGRect";
2718 return "FloatPoint" if $type eq "SVGPoint";
2719 return "AffineTransform" if $type eq "SVGMatrix";
2720 return "SVGTransform" if $type eq "SVGTransform";
2721 return "SVGLength" if $type eq "SVGLength";
2722 return "SVGAngle" if $type eq "SVGAngle";
2723 return "float" if $type eq "SVGNumber";
2724 return "SVGPreserveAspectRatio" if $type eq "SVGPreserveAspectRatio";
2725 return "SVGPaint::SVGPaintType" if $type eq "SVGPaintType";
2726 return "DOMTimeStamp" if $type eq "DOMTimeStamp";
2727 return "unsigned" if $type eq "unsigned int";
2728 return "Node*" if $type eq "EventTarget" and $isParameter;
2729 return "double" if $type eq "Date";
2730 return "ScriptValue" if $type eq "DOMObject";
2732 return "String" if $type eq "DOMUserData"; # FIXME: Temporary hack?
2735 return "RefPtr<NodeFilter>" if $type eq "NodeFilter";
2737 return "RefPtr<SerializedScriptValue>" if $type eq "SerializedScriptValue";
2739 return "RefPtr<IDBKey>" if $type eq "IDBKey";
2741 # necessary as resolvers could be constructed on fly.
2742 return "RefPtr<XPathNSResolver>" if $type eq "XPathNSResolver";
2744 return "RefPtr<${type}>" if IsRefPtrType($type) and not $isParameter;
2746 # Default, assume native type is a pointer with same type name as idl type
2750 sub GetNativeTypeForCallbacks
2753 return "const String&" if $type eq "DOMString";
2755 # Callbacks use raw pointers, so pass isParameter = 1
2756 return GetNativeType($type, 1);
2759 sub TranslateParameter
2761 my $signature = shift;
2763 # The IDL uses some pseudo-types which don't really exist.
2764 if ($signature->type eq "TimeoutHandler") {
2765 $signature->type("DOMString");
2769 sub BasicTypeCanFailConversion
2771 my $signature = shift;
2772 my $type = GetTypeFromSignature($signature);
2774 return 1 if $type eq "SVGAngle";
2775 return 1 if $type eq "SVGLength";
2776 return 1 if $type eq "SVGMatrix";
2777 return 1 if $type eq "SVGPoint";
2778 return 1 if $type eq "SVGPreserveAspectRatio";
2779 return 1 if $type eq "SVGRect";
2780 return 1 if $type eq "SVGTransform";
2784 sub TypeCanFailConversion
2786 my $signature = shift;
2788 my $type = GetTypeFromSignature($signature);
2790 $implIncludes{"ExceptionCode.h"} = 1 if $type eq "Attr";
2791 return 1 if $type eq "Attr";
2792 return 1 if $type eq "VoidCallback";
2793 return BasicTypeCanFailConversion($signature);
2798 my $signature = shift;
2800 my $okParam = shift;
2801 my $maybeOkParam = $okParam ? ", ${okParam}" : "";
2803 my $type = GetTypeFromSignature($signature);
2805 return "$value" if $type eq "JSObject";
2806 return "$value->BooleanValue()" if $type eq "boolean";
2807 return "static_cast<$type>($value->NumberValue())" if $type eq "float" or $type eq "double";
2808 return "$value->NumberValue()" if $type eq "SVGNumber";
2810 return "toInt32($value${maybeOkParam})" if $type eq "unsigned long" or $type eq "unsigned short" or $type eq "long";
2811 return "toInt64($value)" if $type eq "unsigned long long" or $type eq "long long";
2812 return "static_cast<Range::CompareHow>($value->Int32Value())" if $type eq "CompareHow";
2813 return "static_cast<SVGPaint::SVGPaintType>($value->ToInt32()->Int32Value())" if $type eq "SVGPaintType";
2814 return "toWebCoreDate($value)" if $type eq "Date";
2816 if ($type eq "DOMString" or $type eq "DOMUserData") {
2820 die "Unexpected SerializedScriptValue" if $type eq "SerializedScriptValue";
2822 if ($type eq "IDBKey") {
2823 $implIncludes{"IDBBindingUtilities.h"} = 1;
2824 $implIncludes{"IDBKey.h"} = 1;
2825 return "createIDBKeyFromValue($value)";
2828 if ($type eq "DOMObject") {
2829 $implIncludes{"ScriptValue.h"} = 1;
2830 return "ScriptValue($value)";
2833 if ($type eq "NodeFilter") {
2834 return "V8DOMWrapper::wrapNativeNodeFilter($value)";
2837 if ($type eq "SVGRect") {
2838 $implIncludes{"FloatRect.h"} = 1;
2841 if ($type eq "SVGPoint") {
2842 $implIncludes{"FloatPoint.h"} = 1;
2845 # Default, assume autogenerated type conversion routines
2846 if ($type eq "EventTarget") {
2847 $implIncludes{"V8Node.h"} = 1;
2849 # EventTarget is not in DOM hierarchy, but all Nodes are EventTarget.
2850 return "V8Node::HasInstance($value) ? V8Node::toNative(v8::Handle<v8::Object>::Cast($value)) : 0";
2853 if ($type eq "XPathNSResolver") {
2854 return "V8DOMWrapper::getXPathNSResolver($value)";
2857 AddIncludesForType($type);
2859 if (IsDOMNodeType($type)) {
2860 $implIncludes{"V8${type}.h"} = 1;
2862 # Perform type checks on the parameter, if it is expected Node type,
2864 return "V8${type}::HasInstance($value) ? V8${type}::toNative(v8::Handle<v8::Object>::Cast($value)) : 0";
2866 $implIncludes{"V8$type.h"} = 1;
2868 if (IsPodType($type)) {
2869 my $nativeType = GetNativeType($type);
2870 $implIncludes{"V8SVGPODTypeWrapper.h"} = 1;
2872 return "V8SVGPODTypeUtil::toSVGPODType<${nativeType}>(&V8${type}::info, $value${maybeOkParam})"
2875 $implIncludes{"V8${type}.h"} = 1;
2877 # Perform type checks on the parameter, if it is expected Node type,
2879 return "V8${type}::HasInstance($value) ? V8${type}::toNative(v8::Handle<v8::Object>::Cast($value)) : 0";
2886 return "V8Event.h" if $type eq "DOMTimeStamp";
2887 return "EventListener.h" if $type eq "EventListener";
2888 return "EventTarget.h" if $type eq "EventTarget";
2889 return "SerializedScriptValue.h" if $type eq "SerializedScriptValue";
2890 return "ScriptValue.h" if $type eq "DOMObject";
2891 return "V8${type}.h";
2894 sub CreateCustomSignature
2896 my $function = shift;
2897 my $count = @{$function->parameters};
2898 my $name = $function->signature->name;
2899 my $result = " const int ${name}Argc = ${count};\n" .
2900 " v8::Handle<v8::FunctionTemplate> ${name}Argv[${name}Argc] = { ";
2902 foreach my $parameter (@{$function->parameters}) {
2903 if ($first) { $first = 0; }
2904 else { $result .= ", "; }
2905 if (IsWrapperType($parameter->type)) {
2906 if ($parameter->type eq "XPathNSResolver") {
2907 # Special case for XPathNSResolver. All other browsers accepts a callable,
2908 # so, even though it's against IDL, accept objects here.
2909 $result .= "v8::Handle<v8::FunctionTemplate>()";
2911 my $type = $parameter->type;
2912 my $header = GetV8HeaderName($type);
2913 $implIncludes{$header} = 1;
2914 $result .= "V8${type}::GetRawTemplate()";
2917 $result .= "v8::Handle<v8::FunctionTemplate>()";
2921 $result .= " v8::Handle<v8::Signature> ${name}Signature = v8::Signature::New(desc, ${name}Argc, ${name}Argv);\n";
2926 sub RequiresCustomSignature
2928 my $function = shift;
2929 # No signature needed for Custom function
2930 if ($function->signature->extendedAttributes->{"Custom"} ||
2931 $function->signature->extendedAttributes->{"V8Custom"}) {
2934 # No signature needed for overloaded function
2935 if (@{$function->{overloads}} > 1) {
2939 foreach my $parameter (@{$function->parameters}) {
2940 if ($parameter->extendedAttributes->{"Optional"}) {
2945 foreach my $parameter (@{$function->parameters}) {
2946 if (IsWrapperType($parameter->type)) {
2954 # FIXME: Sort this array.
2955 my %non_wrapper_types = (
2959 'unsigned int' => 1,
2961 'unsigned short' => 1,
2963 'unsigned long' => 1,
2966 'unsigned long long' => 1,
2969 'SerializedScriptValue' => 1,
2973 'SVGPreserveAspectRatio' => 1,
2975 'SVGTransform' => 1,
2978 'SVGPaintType' => 1,
2979 'DOMTimeStamp' => 1,
2984 'EventListener' => 1,
2991 my $type = $codeGenerator->StripModule(shift);
2992 return !($non_wrapper_types{$type});
2999 return 1 if $type eq 'Attr';
3000 return 1 if $type eq 'CDATASection';
3001 return 1 if $type eq 'Comment';
3002 return 1 if $type eq 'Document';
3003 return 1 if $type eq 'DocumentFragment';
3004 return 1 if $type eq 'DocumentType';
3005 return 1 if $type eq 'Element';
3006 return 1 if $type eq 'EntityReference';
3007 return 1 if $type eq 'HTMLCanvasElement';
3008 return 1 if $type eq 'HTMLDocument';
3009 return 1 if $type eq 'HTMLElement';
3010 return 1 if $type eq 'HTMLFormElement';
3011 return 1 if $type eq 'HTMLTableCaptionElement';
3012 return 1 if $type eq 'HTMLTableSectionElement';
3013 return 1 if $type eq 'Node';
3014 return 1 if $type eq 'ProcessingInstruction';
3015 return 1 if $type eq 'SVGElement';
3016 return 1 if $type eq 'SVGDocument';
3017 return 1 if $type eq 'SVGSVGElement';
3018 return 1 if $type eq 'SVGUseElement';
3019 return 1 if $type eq 'Text';
3025 sub ReturnNativeToJSValue
3027 my $signature = shift;
3030 my $type = GetTypeFromSignature($signature);
3032 return "return v8::Date::New(static_cast<double>($value))" if $type eq "DOMTimeStamp";
3033 return "return v8Boolean($value)" if $type eq "boolean";
3034 return "return v8::Handle<v8::Value>()" if $type eq "void"; # equivalent to v8::Undefined()
3036 # For all the types where we use 'int' as the representation type,
3037 # we use Integer::New which has a fast Smi conversion check.
3038 my $nativeType = GetNativeType($type);
3039 return "return v8::Integer::New($value)" if $nativeType eq "int";
3040 return "return v8::Integer::NewFromUnsigned($value)" if $nativeType eq "unsigned";
3042 return "return v8DateOrNull($value)" if $type eq "Date";
3043 # long long and unsigned long long are not representable in ECMAScript.
3044 return "return v8::Number::New(static_cast<double>($value))" if $type eq "long long" or $type eq "unsigned long long";
3045 return "return v8::Number::New($value)" if $codeGenerator->IsPrimitiveType($type) or $type eq "SVGPaintType";
3046 return "return $value.v8Value()" if $nativeType eq "ScriptValue";
3048 if ($codeGenerator->IsStringType($type)) {
3049 my $conv = $signature->extendedAttributes->{"ConvertNullStringTo"};
3050 if (defined $conv) {
3051 return "return v8StringOrNull($value)" if $conv eq "Null";
3052 return "return v8StringOrUndefined($value)" if $conv eq "Undefined";
3053 return "return v8StringOrFalse($value)" if $conv eq "False";
3055 die "Unknown value for ConvertNullStringTo extended attribute";
3057 $conv = $signature->extendedAttributes->{"ConvertScriptString"};
3058 return "return v8StringOrNull($value)" if $conv;
3059 return "return v8String($value)";
3062 AddIncludesForType($type);
3064 # special case for non-DOM node interfaces
3065 if (IsDOMNodeType($type)) {
3066 return "return toV8(${value}" . ($signature->extendedAttributes->{"ReturnsNew"} ? ", true)" : ")");
3069 if ($type eq "EventTarget") {
3070 return "return V8DOMWrapper::convertEventTargetToV8Object($value)";
3073 if ($type eq "EventListener") {
3074 $implIncludes{"V8AbstractEventListener.h"} = 1;
3075 return "return ${value} ? v8::Handle<v8::Value>(static_cast<V8AbstractEventListener*>(${value})->getListenerObject(imp->scriptExecutionContext())) : v8::Handle<v8::Value>(v8::Null())";
3078 if ($type eq "SerializedScriptValue") {
3079 $implIncludes{"$type.h"} = 1;
3080 return "return $value->deserialize()";
3083 $implIncludes{"wtf/RefCounted.h"} = 1;
3084 $implIncludes{"wtf/RefPtr.h"} = 1;
3085 $implIncludes{"wtf/GetPtr.h"} = 1;
3087 if (IsPodType($type)) {
3088 $value = GenerateSVGStaticPodTypeWrapper($type, $value) . ".get()";
3091 return "return toV8($value)";
3094 sub GenerateSVGStaticPodTypeWrapper {
3098 $implIncludes{"V8$type.h"}=1;
3099 $implIncludes{"V8SVGPODTypeWrapper.h"} = 1;
3101 my $nativeType = GetNativeType($type);
3102 return "V8SVGStaticPODTypeWrapper<$nativeType>::create($value)";
3108 if (defined($IMPL)) {
3109 # Write content to file.
3110 print $IMPL @implContentHeader;
3112 print $IMPL @implFixedHeader;
3114 foreach my $implInclude (sort keys(%implIncludes)) {
3115 my $checkType = $implInclude;
3116 $checkType =~ s/\.h//;
3118 if ($implInclude =~ /wtf/) {
3119 print $IMPL "#include \<$implInclude\>\n";
3121 print $IMPL "#include \"$implInclude\"\n" unless $codeGenerator->IsSVGAnimatedType($checkType);
3126 print $IMPL @implContentDecls;
3127 print $IMPL @implContent;
3132 @implFixedHeader = ();
3133 @implHeaderContent = ();
3134 @implContentDecls = ();
3138 if (defined($HEADER)) {
3139 # Write content to file.
3140 print $HEADER @headerContent;
3144 @headerContent = ();
3148 sub IsSVGTypeNeedingContextParameter
3150 my $implClassName = shift;
3152 if ($implClassName =~ /SVG/ and not $implClassName =~ /Element/) {
3153 return 1 unless $implClassName =~ /SVGPaint/ or $implClassName =~ /SVGColor/ or $implClassName =~ /SVGDocument/;
3159 sub GenerateSVGContextAssignment
3161 my $srcType = shift;
3165 $result = GenerateSVGContextRetrieval($srcType, $indent);
3166 $result .= $indent . "V8Proxy::setSVGContext($value, context);\n";
3171 sub GenerateSVGContextRetrieval
3173 my $srcType = shift;
3176 my $srcIsPodType = IsPodType($srcType);
3178 my $srcObject = "imp";
3179 if ($srcIsPodType) {
3180 $srcObject = "impWrapper";
3185 if (IsSVGTypeNeedingContextParameter($srcType)) {
3186 $contextDecl = "V8Proxy::svgContext($srcObject)";
3188 $contextDecl = $srcObject;
3191 return $indent . "SVGElement* context = $contextDecl;\n";
3194 sub IsSVGListMutator
3196 my $functionName = shift;
3198 return 1 if $functionName eq "clear";
3199 return 1 if $functionName eq "initialize";
3200 return 1 if $functionName eq "insertItemBefore";
3201 return 1 if $functionName eq "replaceItem";
3202 return 1 if $functionName eq "removeItem";
3203 return 1 if $functionName eq "appendItem";
3210 my $functionName = shift;
3212 return 1 if $functionName eq "getFirst";
3213 return 1 if $functionName eq "getLast";
3214 return 1 if $functionName eq "getItem";
3216 return IsSVGListMutator($functionName);
3219 sub IsSVGListTypeNeedingSpecialHandling
3221 my $className = shift;
3223 return 1 if $className eq "SVGPointList";
3224 return 1 if $className eq "SVGTransformList";
3229 sub GetVisibleInterfaceName
3231 my $interfaceName = shift;
3233 return "DOMException" if $interfaceName eq "DOMCoreException";
3234 return "FormData" if $interfaceName eq "DOMFormData";
3235 return $interfaceName;