Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(216)

Side by Side Diff: webkit/port/bindings/scripts/CodeGeneratorV8.pm

Issue 3195: Use static type information from IDL to streamline the wrapping and unwrappin... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 12 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 1
2 # Copyright (C) 2005, 2006 Nikolas Zimmermann <zimmermann@kde.org> 2 # Copyright (C) 2005, 2006 Nikolas Zimmermann <zimmermann@kde.org>
3 # Copyright (C) 2006 Anders Carlsson <andersca@mac.com> 3 # Copyright (C) 2006 Anders Carlsson <andersca@mac.com>
4 # Copyright (C) 2006 Samuel Weinig <sam.weinig@gmail.com> 4 # Copyright (C) 2006 Samuel Weinig <sam.weinig@gmail.com>
5 # Copyright (C) 2006 Alexey Proskuryakov <ap@webkit.org> 5 # Copyright (C) 2006 Alexey Proskuryakov <ap@webkit.org>
6 # Copyright (C) 2006 Apple Computer, Inc. 6 # Copyright (C) 2006 Apple Computer, Inc.
7 # Copyright (C) 2007 Google Inc. 7 # Copyright (C) 2007 Google Inc.
8 # 8 #
9 # This file is part of the KDE project 9 # This file is part of the KDE project
10 # 10 #
(...skipping 20 matching lines...) Expand all
31 my $module = ""; 31 my $module = "";
32 my $outputDir = ""; 32 my $outputDir = "";
33 33
34 my @headerContent = (); 34 my @headerContent = ();
35 my @implContentHeader = (); 35 my @implContentHeader = ();
36 my @implFixedHeader = (); 36 my @implFixedHeader = ();
37 my @implContent = (); 37 my @implContent = ();
38 my @implContentDecls = (); 38 my @implContentDecls = ();
39 my %implIncludes = (); 39 my %implIncludes = ();
40 40
41 my @allParents = ();
42
41 # Default .h template 43 # Default .h template
42 my $headerTemplate = << "EOF"; 44 my $headerTemplate = << "EOF";
43 /* 45 /*
44 This file is part of the WebKit open source project. 46 This file is part of the WebKit open source project.
45 This file has been generated by generate-bindings.pl. DO NOT MODIFY! 47 This file has been generated by generate-bindings.pl. DO NOT MODIFY!
46 48
47 This library is free software; you can redistribute it and/or 49 This library is free software; you can redistribute it and/or
48 modify it under the terms of the GNU Library General Public 50 modify it under the terms of the GNU Library General Public
49 License as published by the Free Software Foundation; either 51 License as published by the Free Software Foundation; either
50 version 2 of the License, or (at your option) any later version. 52 version 2 of the License, or (at your option) any later version.
(...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after
303 my $result = ""; 305 my $result = "";
304 306
305 $result .= $indent . "if (ec != 0) {\n"; 307 $result .= $indent . "if (ec != 0) {\n";
306 $result .= $indent . " V8Proxy::SetDOMException(ec);\n"; 308 $result .= $indent . " V8Proxy::SetDOMException(ec);\n";
307 $result .= $indent . " return v8::Handle<v8::Value>();\n"; 309 $result .= $indent . " return v8::Handle<v8::Value>();\n";
308 $result .= $indent . "}\n"; 310 $result .= $indent . "}\n";
309 311
310 return $result; 312 return $result;
311 } 313 }
312 314
315 sub IsNodeSubType
316 {
317 my $dataNode = shift;
318 return 1 if ($dataNode->name eq "Node");
319 foreach (@allParents) {
320 my $parent = $codeGenerator->StripModule($_);
321 return 1 if $parent eq "Node";
322 }
323 return 0;
324 }
325
326 sub HolderToNative
327 {
328 my $dataNode = shift;
329 my $implClassName = shift;
330 my $classIndex = shift;
331
332 if (IsNodeSubType($dataNode)) {
333 push(@implContentDecls, <<END);
334 $implClassName* imp = V8Proxy::DOMWrapperToNode<$implClassName>(holder);
335 END
336
337 } else {
338 push(@implContentDecls, <<END);
339 $implClassName* imp = V8Proxy::ToNativeObject<$implClassName>(V8ClassIndex:: $classIndex, holder);
340 END
341
342 }
343 }
313 344
314 sub GenerateDomainSafeFunctionGetter 345 sub GenerateDomainSafeFunctionGetter
315 { 346 {
316 my $function = shift; 347 my $function = shift;
317 my $dataNode = shift; 348 my $dataNode = shift;
318 my $classIndex = shift; 349 my $classIndex = shift;
319 my $implClassName = shift; 350 my $implClassName = shift;
320 351
321 my $className = "V8" . $dataNode->name; 352 my $className = "V8" . $dataNode->name;
322 my $funcName = $function->signature->name; 353 my $funcName = $function->signature->name;
(...skipping 12 matching lines...) Expand all
335 INC_STATS(L\"DOM.$implClassName.$funcName._get\"); 366 INC_STATS(L\"DOM.$implClassName.$funcName._get\");
336 static v8::Persistent<v8::FunctionTemplate> private_template = 367 static v8::Persistent<v8::FunctionTemplate> private_template =
337 v8::Persistent<v8::FunctionTemplate>::New($newTemplateString); 368 v8::Persistent<v8::FunctionTemplate>::New($newTemplateString);
338 v8::Handle<v8::Object> holder = V8Proxy::LookupDOMWrapper(V8ClassIndex::$cla ssIndex, info.This()); 369 v8::Handle<v8::Object> holder = V8Proxy::LookupDOMWrapper(V8ClassIndex::$cla ssIndex, info.This());
339 if (holder.IsEmpty()) { 370 if (holder.IsEmpty()) {
340 // can only reach here by 'object.__proto__.func', and it should passed 371 // can only reach here by 'object.__proto__.func', and it should passed
341 // domain security check already 372 // domain security check already
342 373
343 return private_template->GetFunction(); 374 return private_template->GetFunction();
344 } 375 }
376 END
345 377
346 $implClassName* imp = V8Proxy::FastToNativeObject<$implClassName>(V8ClassInd ex::$classIndex, holder); 378 HolderToNative($dataNode, $implClassName, $classIndex);
379
380 push(@implContentDecls, <<END);
347 if (!V8Proxy::IsFromSameOrigin(imp->frame(), false)) { 381 if (!V8Proxy::IsFromSameOrigin(imp->frame(), false)) {
348 static v8::Persistent<v8::FunctionTemplate> shared_template = 382 static v8::Persistent<v8::FunctionTemplate> shared_template =
349 v8::Persistent<v8::FunctionTemplate>::New($newTemplateString); 383 v8::Persistent<v8::FunctionTemplate>::New($newTemplateString);
350 return shared_template->GetFunction(); 384 return shared_template->GetFunction();
351 385
352 } else { 386 } else {
353 return private_template->GetFunction(); 387 return private_template->GetFunction();
354 } 388 }
355 } 389 }
356 390
357
358 END 391 END
359 } 392 }
360 393
361 sub GenerateConstructorGetter 394 sub GenerateConstructorGetter
362 { 395 {
363 my $implClassName = shift; 396 my $implClassName = shift;
364 397
365 push(@implContentDecls, <<END); 398 push(@implContentDecls, <<END);
366 static v8::Handle<v8::Value> ${implClassName}ConstructorGetter(v8::Local<v8::S tring> name, const v8::AccessorInfo& info) { 399 static v8::Handle<v8::Value> ${implClassName}ConstructorGetter(v8::Local<v8::S tring> name, const v8::AccessorInfo& info) {
367 INC_STATS(L\"DOM.$implClassName.constructors._get\"); 400 INC_STATS(L\"DOM.$implClassName.constructors._get\");
368 v8::Handle<v8::Value> data = info.Data(); 401 v8::Handle<v8::Value> data = info.Data();
369 ASSERT(data->IsNumber()); 402 ASSERT(data->IsNumber());
370 403
371 V8ClassIndex::V8WrapperType type = V8ClassIndex::FromInt(data->Int32Value()) ; 404 V8ClassIndex::V8WrapperType type = V8ClassIndex::FromInt(data->Int32Value()) ;
372 405
373 v8::Handle<v8::FunctionTemplate> desc = V8Proxy::GetTemplate(type); 406 v8::Handle<v8::FunctionTemplate> desc = V8Proxy::GetTemplate(type);
374 v8::Handle<v8::Function> func = desc->GetFunction(); 407 v8::Handle<v8::Function> func = desc->GetFunction();
375 ASSERT(func->IsFunction()); 408 ASSERT(func->IsFunction());
376 return func; 409 return func;
377 } 410 }
378 411
379 END 412 END
380 } 413 }
381 414
382 sub GenerateNormalAttrGetter 415 sub GenerateNormalAttrGetter
383 { 416 {
384 my $attribute = shift; 417 my $attribute = shift;
418 my $dataNode = shift;
385 my $classIndex = shift; 419 my $classIndex = shift;
386 my $implClassName = shift; 420 my $implClassName = shift;
387 421
388 my $attrExt = $attribute->signature->extendedAttributes; 422 my $attrExt = $attribute->signature->extendedAttributes;
389 423
390 my $attrName = $attribute->signature->name; 424 my $attrName = $attribute->signature->name;
391 $implIncludes{"v8_proxy.h"} = 1; 425 $implIncludes{"v8_proxy.h"} = 1;
392 426
393 my $attrType = $codeGenerator->StripModule($attribute->signature->type); 427 my $attrType = $codeGenerator->StripModule($attribute->signature->type);
394 my $attrIsPodType = $codeGenerator->IsPodType($attrType); 428 my $attrIsPodType = $codeGenerator->IsPodType($attrType);
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
428 my $getterStringUsesImp = $implClassName ne "double"; 462 my $getterStringUsesImp = $implClassName ne "double";
429 463
430 # Getter 464 # Getter
431 push(@implContentDecls, <<END); 465 push(@implContentDecls, <<END);
432 static v8::Handle<v8::Value> ${attrName}AttrGetter(v8::Local<v8::String> name, const v8::AccessorInfo& info) { 466 static v8::Handle<v8::Value> ${attrName}AttrGetter(v8::Local<v8::String> name, const v8::AccessorInfo& info) {
433 INC_STATS(L\"DOM.$implClassName.$attrName._get\"); 467 INC_STATS(L\"DOM.$implClassName.$attrName._get\");
434 END 468 END
435 469
436 if ($isPodType) { 470 if ($isPodType) {
437 push(@implContentDecls, <<END); 471 push(@implContentDecls, <<END);
438 V8SVGPODTypeWrapper<$implClassName>* imp_wrapper = V8Proxy::FastToNativeObje ct<V8SVGPODTypeWrapper<$implClassName> >(V8ClassIndex::$classIndex, info.Holder( )); 472 V8SVGPODTypeWrapper<$implClassName>* imp_wrapper = V8Proxy::ToNativeObject<V 8SVGPODTypeWrapper<$implClassName> >(V8ClassIndex::$classIndex, info.Holder());
439 $implClassName imp_instance = *imp_wrapper; 473 $implClassName imp_instance = *imp_wrapper;
440 END 474 END
441 if ($getterStringUsesImp) { 475 if ($getterStringUsesImp) {
442 push(@implContentDecls, <<END); 476 push(@implContentDecls, <<END);
443 $implClassName* imp = &imp_instance; 477 $implClassName* imp = &imp_instance;
444 END 478 END
445 } 479 }
446 480
447 } elsif ($attrExt->{"v8OnProto"}) { 481 } elsif ($attrExt->{"v8OnProto"}) {
448 # perform lookup first 482 # perform lookup first
449 push(@implContentDecls, <<END); 483 push(@implContentDecls, <<END);
450 v8::Handle<v8::Object> holder = V8Proxy::LookupDOMWrapper(V8ClassIndex::$cla ssIndex, info.This()); 484 v8::Handle<v8::Object> holder = V8Proxy::LookupDOMWrapper(V8ClassIndex::$cla ssIndex, info.This());
451 if (holder.IsEmpty()) return v8::Undefined(); 485 if (holder.IsEmpty()) return v8::Undefined();
452
453 $implClassName* imp = V8Proxy::FastToNativeObject<$implClassName>(V8ClassInd ex::$classIndex, holder);
454 END 486 END
455 487 HolderToNative($dataNode, $implClassName, $classIndex);
456 } else { 488 } else {
457 push(@implContentDecls, " $implClassName* imp = V8Proxy::FastToNativeObje ct<$implClassName>(V8ClassIndex::$classIndex, info.Holder());\n"); 489 push(@implContentDecls, <<END);
490 v8::Handle<v8::Object> holder = info.Holder();
491 END
492 HolderToNative($dataNode, $implClassName, $classIndex);
458 } 493 }
459 494
460 # Generate security checks if necessary 495 # Generate security checks if necessary
461 if ($attribute->signature->extendedAttributes->{"CheckNodeSecurity"}) { 496 if ($attribute->signature->extendedAttributes->{"CheckNodeSecurity"}) {
462 push(@implContentDecls, " if (!V8Proxy::CheckNodeSecurity(imp->$attrName( ))) return v8::Undefined();\n\n"); 497 push(@implContentDecls, " if (!V8Proxy::CheckNodeSecurity(imp->$attrName( ))) return v8::Undefined();\n\n");
463 } elsif ($attribute->signature->extendedAttributes->{"CheckFrameSecurity"}) { 498 } elsif ($attribute->signature->extendedAttributes->{"CheckFrameSecurity"}) {
464 push(@implContentDecls, " if (!V8Proxy::CheckNodeSecurity(imp->contentDoc ument())) return v8::Undefined();\n\n"); 499 push(@implContentDecls, " if (!V8Proxy::CheckNodeSecurity(imp->contentDoc ument())) return v8::Undefined();\n\n");
465 } 500 }
466 501
467 my $useExceptions = 1 if @{$attribute->getterExceptions} and !($isPodType); 502 my $useExceptions = 1 if @{$attribute->getterExceptions} and !($isPodType);
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
556 push(@implContentDecls, " v8::Local<v8::String> ${attrName}_string = v8::St ring::New(\"${attrName}\");\n"); 591 push(@implContentDecls, " v8::Local<v8::String> ${attrName}_string = v8::St ring::New(\"${attrName}\");\n");
557 push(@implContentDecls, " info.Holder()->Delete(${attrName}_string);\n"); 592 push(@implContentDecls, " info.Holder()->Delete(${attrName}_string);\n");
558 push(@implContentDecls, " info.This()->Set(${attrName}_string, value);\n"); 593 push(@implContentDecls, " info.This()->Set(${attrName}_string, value);\n");
559 push(@implContentDecls, " }\n\n"); 594 push(@implContentDecls, " }\n\n");
560 } 595 }
561 596
562 597
563 sub GenerateNormalAttrSetter 598 sub GenerateNormalAttrSetter
564 { 599 {
565 my $attribute = shift; 600 my $attribute = shift;
601 my $dataNode = shift;
566 my $classIndex = shift; 602 my $classIndex = shift;
567 my $implClassName = shift; 603 my $implClassName = shift;
568 604
569 my $attrExt = $attribute->signature->extendedAttributes; 605 my $attrExt = $attribute->signature->extendedAttributes;
570 606
571 $implIncludes{"v8_proxy.h"} = 1; 607 $implIncludes{"v8_proxy.h"} = 1;
572 608
573 push(@implContentDecls, 609 push(@implContentDecls,
574 " static void ${attrName}AttrSetter(v8::Local<v8::String> name," . 610 " static void ${attrName}AttrSetter(v8::Local<v8::String> name," .
575 " v8::Local<v8::Value> value, const v8::AccessorInfo& info) {\n"); 611 " v8::Local<v8::Value> value, const v8::AccessorInfo& info) {\n");
576 612
577 push(@implContentDecls, " INC_STATS(L\"DOM.$implClassName.$attrName._set\") ;\n"); 613 push(@implContentDecls, " INC_STATS(L\"DOM.$implClassName.$attrName._set\") ;\n");
578 614
579 my $isPodType = $codeGenerator->IsPodType($implClassName); 615 my $isPodType = $codeGenerator->IsPodType($implClassName);
580 616
581 if ($isPodType) { 617 if ($isPodType) {
582 $implClassName = GetNativeType($implClassName); 618 $implClassName = GetNativeType($implClassName);
583 $implIncludes{"V8SVGPODTypeWrapper.h"} = 1; 619 $implIncludes{"V8SVGPODTypeWrapper.h"} = 1;
584 push(@implContentDecls, " V8SVGPODTypeWrapper<$implClassName>* wrapper = V8Proxy::FastToNativeObject<V8SVGPODTypeWrapper<$implClassName> >(V8ClassIndex:: $classIndex, info.Holder());\n"); 620 push(@implContentDecls, " V8SVGPODTypeWrapper<$implClassName>* wrapper = V8Proxy::ToNativeObject<V8SVGPODTypeWrapper<$implClassName> >(V8ClassIndex::$cla ssIndex, info.Holder());\n");
585 push(@implContentDecls, " $implClassName imp_instance = *wrapper;\n"); 621 push(@implContentDecls, " $implClassName imp_instance = *wrapper;\n");
586 push(@implContentDecls, " $implClassName* imp = &imp_instance;\n"); 622 push(@implContentDecls, " $implClassName* imp = &imp_instance;\n");
587 623
588 } elsif ($attrExt->{"v8OnProto"}) { 624 } elsif ($attrExt->{"v8OnProto"}) {
589 # perform lookup first 625 # perform lookup first
590 push(@implContentDecls, <<END); 626 push(@implContentDecls, <<END);
591 v8::Handle<v8::Object> holder = V8Proxy::LookupDOMWrapper(V8ClassIndex::$cla ssIndex, info.This()); 627 v8::Handle<v8::Object> holder = V8Proxy::LookupDOMWrapper(V8ClassIndex::$cla ssIndex, info.This());
592 if (holder.IsEmpty()) return v8::Undefined(); 628 if (holder.IsEmpty()) return v8::Undefined();
593
594 $implClassName* imp = V8Proxy::FastToNativeObject<$implClassName>(V8ClassInd ex::$classIndex, holder);
595 END 629 END
596 630 HolderToNative($dataNode, $implClassName, $classIndex);
597 } else { 631 } else {
598 push(@implContentDecls, " $implClassName* imp = V8Proxy::FastToNativeObje ct<$implClassName>(V8ClassIndex::$classIndex, info.Holder());\n"); 632 push(@implContentDecls, <<END);
633 v8::Handle<v8::Object> holder = info.Holder();
634 END
635 HolderToNative($dataNode, $implClassName, $classIndex);
599 } 636 }
600 637
601 my $nativeType = GetNativeTypeFromSignature($attribute->signature, 0); 638 my $nativeType = GetNativeTypeFromSignature($attribute->signature, 0);
602 push(@implContentDecls, " $nativeType v = " . JSValueToNative($attribute->s ignature, "value") . ";\n"); 639 push(@implContentDecls, " $nativeType v = " . JSValueToNative($attribute->s ignature, "value") . ";\n");
603 640
604 my $result = ""; 641 my $result = "";
605 if ($nativeType eq "int" and $attribute->signature->extendedAttributes->{"Conv ertFromString"}) { 642 if ($nativeType eq "int" and $attribute->signature->extendedAttributes->{"Conv ertFromString"}) {
606 $result .= "WebCore::String::number("; 643 $result .= "WebCore::String::number(";
607 } 644 }
608 $result .= "v"; 645 $result .= "v";
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
690 727
691 my $numParameters = @{$function->parameters}; 728 my $numParameters = @{$function->parameters};
692 729
693 if ($function->signature->extendedAttributes->{"RequiresAllArguments"}) { 730 if ($function->signature->extendedAttributes->{"RequiresAllArguments"}) {
694 push(@implContentDecls, 731 push(@implContentDecls,
695 " if (args.Length() < $numParameters) return v8::Undefined();\n"); 732 " if (args.Length() < $numParameters) return v8::Undefined();\n");
696 } 733 }
697 734
698 if ($codeGenerator->IsPodType($implClassName)) { 735 if ($codeGenerator->IsPodType($implClassName)) {
699 my $nativeClassName = GetNativeType($implClassName); 736 my $nativeClassName = GetNativeType($implClassName);
700 push(@implContentDecls, " V8SVGPODTypeWrapper<$nativeClassName>* imp_wrap per = V8Proxy::FastToNativeObject<V8SVGPODTypeWrapper<$nativeClassName> >(V8Clas sIndex::$classIndex, args.Holder());\n"); 737 push(@implContentDecls, " V8SVGPODTypeWrapper<$nativeClassName>* imp_wrap per = V8Proxy::ToNativeObject<V8SVGPODTypeWrapper<$nativeClassName> >(V8ClassInd ex::$classIndex, args.Holder());\n");
701 push(@implContentDecls, " $nativeClassName imp_instance = *imp_wrapper;\n "); 738 push(@implContentDecls, " $nativeClassName imp_instance = *imp_wrapper;\n ");
702 push(@implContentDecls, " $nativeClassName* imp = &imp_instance;\n"); 739 push(@implContentDecls, " $nativeClassName* imp = &imp_instance;\n");
703 } else { 740 } else {
704 push(@implContentDecls, " $implClassName* imp = V8Proxy::FastToNativeObje ct<$implClassName>(V8ClassIndex::$classIndex, args.Holder());\n"); 741 push(@implContentDecls, <<END);
742 v8::Handle<v8::Value> holder = args.Holder();
743 END
744 HolderToNative($dataNode, $implClassName, $classIndex);
705 } 745 }
706 746
707 # Check domain security if needed 747 # Check domain security if needed
708 if (($dataNode->extendedAttributes->{"CheckDomainSecurity"} 748 if (($dataNode->extendedAttributes->{"CheckDomainSecurity"}
709 || $interfaceName eq "DOMWindow") 749 || $interfaceName eq "DOMWindow")
710 && !$function->signature->extendedAttributes->{"DoNotCheckDomainSecurity"}) { 750 && !$function->signature->extendedAttributes->{"DoNotCheckDomainSecurity"}) {
711 # We have not find real use cases yet. 751 # We have not find real use cases yet.
712 push(@implContentDecls, 752 push(@implContentDecls,
713 " if (!V8Proxy::IsFromSameOrigin(imp->frame(), true)) {\n". 753 " if (!V8Proxy::IsFromSameOrigin(imp->frame(), true)) {\n".
714 " return v8::Undefined();\n" . 754 " return v8::Undefined();\n" .
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
774 my $object = shift; 814 my $object = shift;
775 my $dataNode = shift; 815 my $dataNode = shift;
776 my $interfaceName = $dataNode->name; 816 my $interfaceName = $dataNode->name;
777 my $className = "V8$interfaceName"; 817 my $className = "V8$interfaceName";
778 my $implClassName = GetImplementationClassName($interfaceName); 818 my $implClassName = GetImplementationClassName($interfaceName);
779 my $classIndex = uc($codeGenerator->StripModule($interfaceName)); 819 my $classIndex = uc($codeGenerator->StripModule($interfaceName));
780 820
781 my $hasLegacyParent = $dataNode->extendedAttributes->{"LegacyParent"}; 821 my $hasLegacyParent = $dataNode->extendedAttributes->{"LegacyParent"};
782 my $conditional = $dataNode->extendedAttributes->{"Conditional"}; 822 my $conditional = $dataNode->extendedAttributes->{"Conditional"};
783 823
824 @allParents = $codeGenerator->FindParentsRecursively($dataNode);
825
784 # - Add default header template 826 # - Add default header template
785 @implContentHeader = split("\r", $headerTemplate); 827 @implContentHeader = split("\r", $headerTemplate);
786 828
787 push(@implFixedHeader, 829 push(@implFixedHeader,
788 "#include \"config.h\"\n" . 830 "#include \"config.h\"\n" .
789 "#include \"v8_proxy.h\"\n" . 831 "#include \"v8_proxy.h\"\n" .
790 "#include \"v8_binding.h\"\n\n" . 832 "#include \"v8_binding.h\"\n\n" .
791 "#undef LOG\n\n"); 833 "#undef LOG\n\n");
792 834
793 if ($className =~ /^V8SVG/) { 835 if ($className =~ /^V8SVG/) {
(...skipping 28 matching lines...) Expand all
822 864
823 # Do not generate accessor if this is a custom attribute. The 865 # Do not generate accessor if this is a custom attribute. The
824 # call will be forwarded to a hand-written accessor 866 # call will be forwarded to a hand-written accessor
825 # implementation. 867 # implementation.
826 if ($attribute->signature->extendedAttributes->{"Custom"}) { 868 if ($attribute->signature->extendedAttributes->{"Custom"}) {
827 $implIncludes{"v8_custom.h"} = 1; 869 $implIncludes{"v8_custom.h"} = 1;
828 next; 870 next;
829 } 871 }
830 872
831 # Generate the accessor. 873 # Generate the accessor.
832 GenerateNormalAttrGetter($attribute, $classIndex, $implClassName); 874 GenerateNormalAttrGetter($attribute, $dataNode, $classIndex, $implClassNam e);
833 if ($attribute->signature->extendedAttributes->{"CustomSetter"}) { 875 if ($attribute->signature->extendedAttributes->{"CustomSetter"}) {
834 $implIncludes{"v8_custom.h"} = 1; 876 $implIncludes{"v8_custom.h"} = 1;
835 } elsif ($attribute->signature->extendedAttributes->{"Replaceable"}) { 877 } elsif ($attribute->signature->extendedAttributes->{"Replaceable"}) {
836 $interfaceName eq "DOMWindow" || die "Replaceable attribute can only be used in DOMWindow interface!"; 878 $interfaceName eq "DOMWindow" || die "Replaceable attribute can only be used in DOMWindow interface!";
837 # GenerateReplaceableAttrSetter($implClassName); 879 # GenerateReplaceableAttrSetter($implClassName);
838 } elsif ($attribute->type !~ /^readonly/) { 880 } elsif ($attribute->type !~ /^readonly/) {
839 GenerateNormalAttrSetter($attribute, $classIndex, $implClassName); 881 GenerateNormalAttrSetter($attribute, $dataNode, $classIndex, $implClassN ame);
840 } 882 }
841 } 883 }
842 884
843 if ($hasConstructors) { 885 if ($hasConstructors) {
844 GenerateConstructorGetter($implClassName); 886 GenerateConstructorGetter($implClassName);
845 } 887 }
846 888
847 # Generate methods for functions. 889 # Generate methods for functions.
848 foreach my $function (@{$dataNode->functions}) { 890 foreach my $function (@{$dataNode->functions}) {
849 # hack for addEventListener/RemoveEventListener 891 # hack for addEventListener/RemoveEventListener
(...skipping 366 matching lines...) Expand 10 before | Expand all | Expand 10 after
1216 1258
1217 if ($nodeToReturn) { 1259 if ($nodeToReturn) {
1218 # Special case for insertBefore, replaceChild, removeChild and 1260 # Special case for insertBefore, replaceChild, removeChild and
1219 # appendChild functions from Node. 1261 # appendChild functions from Node.
1220 $result .= $indent . "bool success = $functionString;\n"; 1262 $result .= $indent . "bool success = $functionString;\n";
1221 if (@{$function->raisesExceptions}) { 1263 if (@{$function->raisesExceptions}) {
1222 $result .= GenerateSetDOMException($indent); 1264 $result .= GenerateSetDOMException($indent);
1223 } 1265 }
1224 $result .= $indent . "if (success)\n"; 1266 $result .= $indent . "if (success)\n";
1225 $result .= $indent . " " . 1267 $result .= $indent . " " .
1226 "return V8Proxy::ToV8Object(V8ClassIndex::NODE, $nodeToReturn);\n"; 1268 "return V8Proxy::NodeToV8Object($nodeToReturn);\n";
1227 $result .= $indent . "return v8::Null();\n"; 1269 $result .= $indent . "return v8::Null();\n";
1228 return $result; 1270 return $result;
1229 } elsif ($returnType eq "void") { 1271 } elsif ($returnType eq "void") {
1230 $result .= $indent . "$functionString;\n"; 1272 $result .= $indent . "$functionString;\n";
1231 } elsif ($copyFirst) { 1273 } elsif ($copyFirst) {
1232 $result .= 1274 $result .=
1233 $indent . GetNativeType($returnType, 0) . " result = *imp;\n" . 1275 $indent . GetNativeType($returnType, 0) . " result = *imp;\n" .
1234 $indent . "$functionString;\n"; 1276 $indent . "$functionString;\n";
1235 } elsif ($returnsListItemPodType) { 1277 } elsif ($returnsListItemPodType) {
1236 $result .= $indent . "RefPtr<SVGPODListItem<$nativeReturnType> > result = $f unctionString;\n"; 1278 $result .= $indent . "RefPtr<SVGPODListItem<$nativeReturnType> > result = $f unctionString;\n";
1237 } else { 1279 } else {
1238 $result .= $indent . $nativeReturnType . " result = $functionString;\n"; 1280 $result .= $indent . $nativeReturnType . " result = $functionString;\n";
1239 } 1281 }
1240 1282
1241 if (@{$function->raisesExceptions}) { 1283 if (@{$function->raisesExceptions}) {
1242 $result .= GenerateSetDOMException($indent); 1284 $result .= GenerateSetDOMException($indent);
1243 } 1285 }
1244 1286
1245 my $return = "result"; 1287 my $return = "result";
1246 if (IsRefPtrType($returnType) || $returnsListItemPodType) { 1288 if (IsRefPtrType($returnType) || $returnsListItemPodType) {
1247 $implIncludes{"wtf/GetPtr.h"} = 1; 1289 $implIncludes{"wtf/GetPtr.h"} = 1;
1248 $return = "WTF::getPtr(" . $return . ")"; 1290 $return = "WTF::getPtr(" . $return . ")";
1249 } 1291 }
1250 1292
1251 # If the return type is a POD type, separate out the wrapper generation 1293 # If the return type is a POD type, separate out the wrapper generation
1252 if ($returnsListItemPodType) { 1294 if ($returnsListItemPodType) {
1253 $result .= $indent . "V8SVGPODTypeWrapperCreatorForList<" . $nativeReturnTyp e . ">* wrapper = new "; 1295 $result .= $indent . "V8SVGPODTypeWrapper<" . $nativeReturnType . ">* wrappe r = new ";
1254 $result .= "V8SVGPODTypeWrapperCreatorForList<" . $nativeReturnType . ">($re turn, imp->associatedAttributeName());\n"; 1296 $result .= "V8SVGPODTypeWrapperCreatorForList<" . $nativeReturnType . ">($re turn, imp->associatedAttributeName());\n";
1255 $return = "wrapper"; 1297 $return = "wrapper";
1256 } elsif ($returnsPodType) { 1298 } elsif ($returnsPodType) {
1257 $result .= $indent . "V8SVGPODTypeWrapperCreatorReadOnly<" . $nativeReturnTy pe . ">* wrapper = "; 1299 $result .= $indent . "V8SVGPODTypeWrapper<" . $nativeReturnType . ">* wrappe r = ";
1258 $result .= GenerateReadOnlyPodTypeWrapper($returnType, $return) . ";\n"; 1300 $result .= GenerateReadOnlyPodTypeWrapper($returnType, $return) . ";\n";
1259 $return = "wrapper"; 1301 $return = "wrapper";
1260 } 1302 }
1261 1303
1262 my $generatedSVGContextRetrieval = 0; 1304 my $generatedSVGContextRetrieval = 0;
1263 # If the return type needs an SVG context, output it 1305 # If the return type needs an SVG context, output it
1264 if (IsSVGTypeNeedingContextParameter($returnType)) { 1306 if (IsSVGTypeNeedingContextParameter($returnType)) {
1265 $result .= GenerateSVGContextAssignment($implClassName, $return, $indent); 1307 $result .= GenerateSVGContextAssignment($implClassName, $return, $indent);
1266 $generatedSVGContextRetrieval = 1; 1308 $generatedSVGContextRetrieval = 1;
1267 } 1309 }
(...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after
1507 if ($type eq "SVGPoint") { 1549 if ($type eq "SVGPoint") {
1508 $implIncludes{"FloatPoint.h"} = 1; 1550 $implIncludes{"FloatPoint.h"} = 1;
1509 } 1551 }
1510 1552
1511 # Default, assume autogenerated type conversion routines 1553 # Default, assume autogenerated type conversion routines
1512 $implIncludes{"v8_proxy.h"} = 1; 1554 $implIncludes{"v8_proxy.h"} = 1;
1513 if ($type eq "EventTarget") { 1555 if ($type eq "EventTarget") {
1514 $implIncludes{"V8Node.h"} = 1; 1556 $implIncludes{"V8Node.h"} = 1;
1515 1557
1516 # EventTarget is not in DOM hierarchy, but all Nodes are EventTarget. 1558 # EventTarget is not in DOM hierarchy, but all Nodes are EventTarget.
1517 return "V8Node::HasInstance($value) ? V8Proxy::FastToNativeObject<EventTar getNode>(V8ClassIndex::NODE, $value) : 0"; 1559 return "V8Node::HasInstance($value) ? V8Proxy::DOMWrapperToNode<EventTarge tNode>($value) : 0";
1518 } 1560 }
1519 1561
1520 AddIncludesForType($type); 1562 AddIncludesForType($type);
1521 # $implIncludes{"$type.h"} = 1 unless AvoidInclusionOfType($type); 1563 # $implIncludes{"$type.h"} = 1 unless AvoidInclusionOfType($type);
1522 1564
1523 if (IsDOMNodeType($type)) { 1565 if (IsDOMNodeType($type)) {
1524 $implIncludes{"V8${type}.h"} = 1; 1566 $implIncludes{"V8${type}.h"} = 1;
1525 1567
1526 # Perform type checks on the parameter, if it is expected Node type, 1568 # Perform type checks on the parameter, if it is expected Node type,
1527 # return NULL. 1569 # return NULL.
1528 return "V8${type}::HasInstance($value) ? V8Proxy::FastToNativeObject<${typ e}>(V8ClassIndex::NODE, $value) : 0"; 1570 return "V8${type}::HasInstance($value) ? V8Proxy::DOMWrapperToNode<${type} >($value) : 0";
1529 1571
1530 } else { 1572 } else {
1531 # TODO: Temporary to avoid Window name conflict. 1573 # TODO: Temporary to avoid Window name conflict.
1532 my $classIndex = uc($type); 1574 my $classIndex = uc($type);
1533 my $implClassName = GetImplementationClassName(${type}); 1575 my $implClassName = GetImplementationClassName(${type});
1534 1576
1535 $implIncludes{"V8$type.h"} = 1; 1577 $implIncludes{"V8$type.h"} = 1;
1536 1578
1537 if ($codeGenerator->IsPodType($type)) { 1579 if ($codeGenerator->IsPodType($type)) {
1538 my $nativeType = GetNativeType($type); 1580 my $nativeType = GetNativeType($type);
1539 $implIncludes{"V8SVGPODTypeWrapper.h"} = 1; 1581 $implIncludes{"V8SVGPODTypeWrapper.h"} = 1;
1540 1582
1541 # TODO(jhass): perform type checking like others??? 1583 # TODO(jhass): perform type checking like others???
1542 return "*V8Proxy::ToNativeObject<V8SVGPODTypeWrapper<${nativeType}> >(V8 ClassIndex::${classIndex}, $value)" 1584 return "*V8Proxy::ToNativeObject<V8SVGPODTypeWrapper<${nativeType}> >(V8 ClassIndex::${classIndex}, $value)"
1543 } 1585 }
1544 1586
1545 $implIncludes{"V8${type}.h"} = 1; 1587 $implIncludes{"V8${type}.h"} = 1;
1546 1588
1547 # Perform type checks on the parameter, if it is expected Node type, 1589 # Perform type checks on the parameter, if it is expected Node type,
1548 # return NULL. 1590 # return NULL.
1549 return "V8${type}::HasInstance($value) ? V8Proxy::FastToNativeObject<${imp lClassName}>(V8ClassIndex::${classIndex}, $value) : 0"; 1591 return "V8${type}::HasInstance($value) ? V8Proxy::ToNativeObject<${implCla ssName}>(V8ClassIndex::${classIndex}, $value) : 0";
1550 } 1592 }
1551 } 1593 }
1552 1594
1553 1595
1554 sub GetV8HeaderName 1596 sub GetV8HeaderName
1555 { 1597 {
1556 my $type = shift; 1598 my $type = shift;
1557 return "V8" . GetImplementationFileName($type); 1599 return "V8" . GetImplementationFileName($type);
1558 } 1600 }
1559 1601
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
1626 'EventListener' => 1 1668 'EventListener' => 1
1627 ); 1669 );
1628 1670
1629 1671
1630 sub IsWrapperType 1672 sub IsWrapperType
1631 { 1673 {
1632 my $type = $codeGenerator->StripModule(shift); 1674 my $type = $codeGenerator->StripModule(shift);
1633 return !($non_wrapper_types{$type}); 1675 return !($non_wrapper_types{$type});
1634 } 1676 }
1635 1677
1636
1637 sub IsDOMNodeType 1678 sub IsDOMNodeType
1638 { 1679 {
1639 my $type = shift; 1680 my $type = shift;
1640 1681
1641 return 1 if $type eq 'Attr'; 1682 return 1 if $type eq 'Attr';
1642 return 1 if $type eq 'CDATASection'; 1683 return 1 if $type eq 'CDATASection';
1643 return 1 if $type eq 'Comment'; 1684 return 1 if $type eq 'Comment';
1644 return 1 if $type eq 'Document'; 1685 return 1 if $type eq 'Document';
1645 return 1 if $type eq 'DocumentFragment'; 1686 return 1 if $type eq 'DocumentFragment';
1646 return 1 if $type eq 'DocumentType'; 1687 return 1 if $type eq 'DocumentType';
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
1694 return "v8String($value)"; 1735 return "v8String($value)";
1695 } 1736 }
1696 1737
1697 # V8 specific. 1738 # V8 specific.
1698 my $implClassName = GetImplementationClassName($type); 1739 my $implClassName = GetImplementationClassName($type);
1699 AddIncludesForType($type); 1740 AddIncludesForType($type);
1700 # $implIncludes{GetImplementationFileName($type)} = 1 unless AvoidInclusionO fType($type); 1741 # $implIncludes{GetImplementationFileName($type)} = 1 unless AvoidInclusionO fType($type);
1701 1742
1702 # special case for non-DOM node interfaces 1743 # special case for non-DOM node interfaces
1703 if (IsDOMNodeType($type)) { 1744 if (IsDOMNodeType($type)) {
1704 return "V8Proxy::ToV8Object(V8ClassIndex::NODE, $value)"; 1745 return "V8Proxy::NodeToV8Object($value)";
1705 } 1746 }
1706 1747
1707 if ($type eq "EventTarget" or $type eq "SVGElementInstance") { 1748 if ($type eq "EventTarget" or $type eq "SVGElementInstance") {
1708 return "V8Proxy::EventTargetToV8Object($value)"; 1749 return "V8Proxy::EventTargetToV8Object($value)";
1709 } 1750 }
1710 1751
1711 if ($type eq "Event") { 1752 if ($type eq "Event") {
1712 return "V8Proxy::EventToV8Object($value)"; 1753 return "V8Proxy::EventToV8Object($value)";
1713 } 1754 }
1714 1755
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after
1891 return 0; 1932 return 0;
1892 } 1933 }
1893 1934
1894 sub DebugPrint 1935 sub DebugPrint
1895 { 1936 {
1896 my $output = shift; 1937 my $output = shift;
1897 1938
1898 print $output; 1939 print $output;
1899 print "\n"; 1940 print "\n";
1900 } 1941 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698