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

Side by Side Diff: Source/bindings/scripts/code_generator_v8.pm

Issue 26792002: Reland: Reland: Implement new Blink IDL attribute [SetReference] (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: codegen impl Created 7 years, 2 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 # Copyright (C) 2005, 2006 Nikolas Zimmermann <zimmermann@kde.org> 1 # Copyright (C) 2005, 2006 Nikolas Zimmermann <zimmermann@kde.org>
2 # Copyright (C) 2006 Anders Carlsson <andersca@mac.com> 2 # Copyright (C) 2006 Anders Carlsson <andersca@mac.com>
3 # Copyright (C) 2006 Samuel Weinig <sam.weinig@gmail.com> 3 # Copyright (C) 2006 Samuel Weinig <sam.weinig@gmail.com>
4 # Copyright (C) 2006 Alexey Proskuryakov <ap@webkit.org> 4 # Copyright (C) 2006 Alexey Proskuryakov <ap@webkit.org>
5 # Copyright (C) 2006 Apple Computer, Inc. 5 # Copyright (C) 2006 Apple Computer, Inc.
6 # Copyright (C) 2007, 2008, 2009, 2012 Google Inc. 6 # Copyright (C) 2007, 2008, 2009, 2012 Google Inc.
7 # Copyright (C) 2009 Cameron McCormack <cam@mcc.id.au> 7 # Copyright (C) 2009 Cameron McCormack <cam@mcc.id.au>
8 # Copyright (C) Research In Motion Limited 2010. All rights reserved. 8 # Copyright (C) Research In Motion Limited 2010. All rights reserved.
9 # Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies) 9 # Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies)
10 # Copyright (C) 2012 Ericsson AB. All rights reserved. 10 # Copyright (C) 2012 Ericsson AB. All rights reserved.
(...skipping 436 matching lines...) Expand 10 before | Expand all | Expand 10 after
447 if (IsTypedArrayType($interfaceName)) { 447 if (IsTypedArrayType($interfaceName)) {
448 push(@includes, "wtf/${interfaceName}.h"); 448 push(@includes, "wtf/${interfaceName}.h");
449 } elsif (!SkipIncludeHeader($interfaceName)) { 449 } elsif (!SkipIncludeHeader($interfaceName)) {
450 my $idlFilename = Cwd::abs_path(IDLFileForInterface($interfaceName)) or die("Could NOT find IDL file for interface \"$interfaceName\" $!\n"); 450 my $idlFilename = Cwd::abs_path(IDLFileForInterface($interfaceName)) or die("Could NOT find IDL file for interface \"$interfaceName\" $!\n");
451 my $idlRelPath = File::Spec->abs2rel($idlFilename, $sourceRoot); 451 my $idlRelPath = File::Spec->abs2rel($idlFilename, $sourceRoot);
452 push(@includes, dirname($idlRelPath) . "/" . $implClassName . ".h"); 452 push(@includes, dirname($idlRelPath) . "/" . $implClassName . ".h");
453 } 453 }
454 return @includes; 454 return @includes;
455 } 455 }
456 456
457 sub NeedsOpaqueRootForGC 457 sub NeedResolveWrapperReachability
458 { 458 {
459 my $interface = shift; 459 my $interface = shift;
460 return $interface->extendedAttributes->{"GenerateIsReachable"} || $interface ->extendedAttributes->{"CustomIsReachable"}; 460 return $interface->extendedAttributes->{"GenerateIsReachable"} || $interface ->extendedAttributes->{"CustomIsReachable"} || $interface->extendedAttributes->{ "ReachableTo"};
461 } 461 }
462 462
463 sub GenerateOpaqueRootForGC 463 sub GenerateResolveWrapperReachability
464 { 464 {
465 my $interface = shift; 465 my $interface = shift;
466 my $implClassName = GetImplName($interface); 466 my $implClassName = GetImplName($interface);
467 my $v8ClassName = GetV8ClassName($interface); 467 my $v8ClassName = GetV8ClassName($interface);
468 468
469 if ($interface->extendedAttributes->{"CustomIsReachable"}) { 469 if ($interface->extendedAttributes->{"CustomIsReachable"}) {
470 return; 470 return;
471 } 471 }
472 472
473 my $code = <<END; 473 my $code = <<END;
474 void* ${v8ClassName}::opaqueRootForGC(void* object, v8::Isolate* isolate) 474 void ${v8ClassName}::resolveWrapperReachability(void* object, const v8::Persiste nt<v8::Object>& wrapper, v8::Isolate* isolate)
475 { 475 {
476 ${implClassName}* impl = fromInternalPointer(object); 476 ${implClassName}* impl = fromInternalPointer(object);
477 END 477 END
478 if ($interface->extendedAttributes->{"ReachableTo"}) {
479 $code .= " v8::Local<v8::Object> creationContext = v8::Local<v8::Obje ct>::New(isolate, wrapper);\n";
480 }
481 for my $reachableTo (@{$interface->extendedAttributes->{"ReachableTo"}}) {
482 my $reachableToType = $reachableTo->type;
483 my $reachableToName = $reachableTo->name;
484
485 AddIncludesForType($reachableToType);
486 $code .= <<END;
487 ${reachableToType}* ${reachableToName} = impl->${reachableToName}();
488 if (filter) {
489 UnsafePersistent<v8::Object> target = toV8Persistent(${reachableToName}, creationContext, isolate);
490 isolate->SetReference(wrapper, *reinterpret_cast<v8::Persistent<v8::Valu e>*>(target.persistent()));
491 }
492 END
493 }
494
478 my $isReachableMethod = $interface->extendedAttributes->{"GenerateIsReachabl e"}; 495 my $isReachableMethod = $interface->extendedAttributes->{"GenerateIsReachabl e"};
479 if ($isReachableMethod) { 496 if ($isReachableMethod) {
480 AddToImplIncludes("bindings/v8/V8GCController.h"); 497 AddToImplIncludes("bindings/v8/V8GCController.h");
481 AddToImplIncludes("core/dom/Element.h"); 498 AddToImplIncludes("core/dom/Element.h");
482 $code .= <<END; 499 $code .= <<END;
483 if (Node* owner = impl->${isReachableMethod}()) 500 if (Node* owner = impl->${isReachableMethod}()) {
484 return V8GCController::opaqueRootForGC(owner, isolate); 501 setObjectGroup(V8GCController::opaqueRootForGC(owner, isolate), wrapper, isolate);
502 return;
503 }
485 END 504 END
486 } 505 }
487 506
488 $code .= <<END; 507 $code .= <<END;
489 return object; 508 setObjectGroup(object, wrapper, isolate);
490 } 509 }
491 510
492 END 511 END
493 $implementation{nameSpaceWebCore}->add($code); 512 $implementation{nameSpaceWebCore}->add($code);
494 } 513 }
495 514
496 sub GetSVGPropertyTypes 515 sub GetSVGPropertyTypes
497 { 516 {
498 my $implType = shift; 517 my $implType = shift;
499 518
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after
662 static bool HasInstanceInAnyWorld(v8::Handle<v8::Value>, v8::Isolate*); 681 static bool HasInstanceInAnyWorld(v8::Handle<v8::Value>, v8::Isolate*);
663 static v8::Handle<v8::FunctionTemplate> GetTemplate(v8::Isolate*, WrapperWor ldType); 682 static v8::Handle<v8::FunctionTemplate> GetTemplate(v8::Isolate*, WrapperWor ldType);
664 static ${nativeType}* toNative(v8::Handle<v8::Object> object) 683 static ${nativeType}* toNative(v8::Handle<v8::Object> object)
665 { 684 {
666 return fromInternalPointer(object->GetAlignedPointerFromInternalField(v8 DOMWrapperObjectIndex)); 685 return fromInternalPointer(object->GetAlignedPointerFromInternalField(v8 DOMWrapperObjectIndex));
667 } 686 }
668 static void derefObject(void*); 687 static void derefObject(void*);
669 static WrapperTypeInfo info; 688 static WrapperTypeInfo info;
670 END 689 END
671 690
672 if (NeedsOpaqueRootForGC($interface)) { 691 if (NeedResolveWrapperReachability($interface)) {
673 $header{classPublic}->add(" static void* opaqueRootForGC(void*, v8::I solate*);\n"); 692 $header{classPublic}->add(" static void resolveWrapperReachability(vo id*, const v8::Persistent<v8::Object>&, v8::Isolate*);\n");
674 } 693 }
675 694
676 if (InheritsExtendedAttribute($interface, "ActiveDOMObject")) { 695 if (InheritsExtendedAttribute($interface, "ActiveDOMObject")) {
677 $header{classPublic}->add(" static ActiveDOMObject* toActiveDOMObject (v8::Handle<v8::Object>);\n"); 696 $header{classPublic}->add(" static ActiveDOMObject* toActiveDOMObject (v8::Handle<v8::Object>);\n");
678 } 697 }
679 698
680 if (InheritsInterface($interface, "EventTarget")) { 699 if (InheritsInterface($interface, "EventTarget")) {
681 $header{classPublic}->add(" static EventTarget* toEventTarget(v8::Han dle<v8::Object>);\n"); 700 $header{classPublic}->add(" static EventTarget* toEventTarget(v8::Han dle<v8::Object>);\n");
682 } 701 }
683 702
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after
888 inline v8::Handle<v8::Value> toV8(${nativeType}* impl, v8::Handle<v8::Object> cr eationContext, v8::Isolate* isolate) 907 inline v8::Handle<v8::Value> toV8(${nativeType}* impl, v8::Handle<v8::Object> cr eationContext, v8::Isolate* isolate)
889 { 908 {
890 if (UNLIKELY(!impl)) 909 if (UNLIKELY(!impl))
891 return v8NullWithCheck(isolate); 910 return v8NullWithCheck(isolate);
892 v8::Handle<v8::Value> wrapper = DOMDataStore::getWrapper<${v8ClassName}>(imp l, isolate); 911 v8::Handle<v8::Value> wrapper = DOMDataStore::getWrapper<${v8ClassName}>(imp l, isolate);
893 if (!wrapper.IsEmpty()) 912 if (!wrapper.IsEmpty())
894 return wrapper; 913 return wrapper;
895 return wrap(impl, creationContext, isolate); 914 return wrap(impl, creationContext, isolate);
896 } 915 }
897 916
917 inline UnsafePersistent<v8::Object> toV8Persistent(${nativeType}* impl, v8::Hand le<v8::Object> creationContext, v8::Isolate* isolate)
jochen (gone - plz use gerrit) 2013/10/15 05:26:43 we shouldn't introduce code using UnsafePersistent
918 {
919 ASSERT(impl);
920
921 UnsafePersistent<v8::Object> wrapperPersistent = DOMDataStore::getWrapperPer sistent<${v8ClassName}>(impl, isolate);
922 if (LIKELY(!wrapperPersistent.isEmpty()))
923 return wrapperPersistent;
924
925 wrap(impl, creationContext, isolate);
926
927 wrapperPersistent = DOMDataStore::getWrapperPersistent<${v8ClassName}>(impl, isolate);
928 ASSERT(!wrapperPersistent.isEmpty());
929 return wrapperPersistent;
930 }
931
898 template<typename CallbackInfo> 932 template<typename CallbackInfo>
899 inline void v8SetReturnValue(const CallbackInfo& callbackInfo, ${nativeType}* im pl, v8::Handle<v8::Object> creationContext) 933 inline void v8SetReturnValue(const CallbackInfo& callbackInfo, ${nativeType}* im pl, v8::Handle<v8::Object> creationContext)
900 { 934 {
901 if (UNLIKELY(!impl)) { 935 if (UNLIKELY(!impl)) {
902 v8SetReturnValueNull(callbackInfo); 936 v8SetReturnValueNull(callbackInfo);
903 return; 937 return;
904 } 938 }
905 if (DOMDataStore::setReturnValueFromWrapper<${v8ClassName}>(callbackInfo.Get ReturnValue(), impl)) 939 if (DOMDataStore::setReturnValueFromWrapper<${v8ClassName}>(callbackInfo.Get ReturnValue(), impl))
906 return; 940 return;
907 v8::Handle<v8::Object> wrapper = wrap(impl, creationContext, callbackInfo.Ge tIsolate()); 941 v8::Handle<v8::Object> wrapper = wrap(impl, creationContext, callbackInfo.Ge tIsolate());
(...skipping 3047 matching lines...) Expand 10 before | Expand all | Expand 10 after
3955 AddToImplIncludes("bindings/v8/V8DOMWrapper.h"); 3989 AddToImplIncludes("bindings/v8/V8DOMWrapper.h");
3956 AddToImplIncludes("core/dom/ContextFeatures.h"); 3990 AddToImplIncludes("core/dom/ContextFeatures.h");
3957 AddToImplIncludes("core/dom/Document.h"); 3991 AddToImplIncludes("core/dom/Document.h");
3958 AddToImplIncludes("RuntimeEnabledFeatures.h"); 3992 AddToImplIncludes("RuntimeEnabledFeatures.h");
3959 AddToImplIncludes("platform/TraceEvent.h"); 3993 AddToImplIncludes("platform/TraceEvent.h");
3960 3994
3961 AddIncludesForType($interfaceName); 3995 AddIncludesForType($interfaceName);
3962 3996
3963 my $toActiveDOMObject = InheritsExtendedAttribute($interface, "ActiveDOMObje ct") ? "${v8ClassName}::toActiveDOMObject" : "0"; 3997 my $toActiveDOMObject = InheritsExtendedAttribute($interface, "ActiveDOMObje ct") ? "${v8ClassName}::toActiveDOMObject" : "0";
3964 my $toEventTarget = InheritsInterface($interface, "EventTarget") ? "${v8Clas sName}::toEventTarget" : "0"; 3998 my $toEventTarget = InheritsInterface($interface, "EventTarget") ? "${v8Clas sName}::toEventTarget" : "0";
3965 my $rootForGC = NeedsOpaqueRootForGC($interface) ? "${v8ClassName}::opaqueRo otForGC" : "0"; 3999 my $resolveWrapperReachability = NeedResolveWrapperReachability($interface) ? "${v8ClassName}::resolveWrapperReachability" : "0";
3966 4000
3967 # Find the super descriptor. 4001 # Find the super descriptor.
3968 my $parentClass = ""; 4002 my $parentClass = "";
3969 my $parentClassTemplate = ""; 4003 my $parentClassTemplate = "";
3970 if ($interface->parent) { 4004 if ($interface->parent) {
3971 my $parent = $interface->parent; 4005 my $parent = $interface->parent;
3972 AddToImplIncludes("V8${parent}.h"); 4006 AddToImplIncludes("V8${parent}.h");
3973 $parentClass = "V8" . $parent; 4007 $parentClass = "V8" . $parent;
3974 $parentClassTemplate = $parentClass . "::GetTemplate(isolate, currentWor ldType)"; 4008 $parentClassTemplate = $parentClass . "::GetTemplate(isolate, currentWor ldType)";
3975 } 4009 }
(...skipping 29 matching lines...) Expand all
4005 { 4039 {
4006 WebCore::initializeScriptWrappableForInterface(object); 4040 WebCore::initializeScriptWrappableForInterface(object);
4007 } 4041 }
4008 4042
4009 namespace WebCore { 4043 namespace WebCore {
4010 END 4044 END
4011 $implementation{nameSpaceWebCore}->addHeader($code); 4045 $implementation{nameSpaceWebCore}->addHeader($code);
4012 } 4046 }
4013 4047
4014 my $code = "WrapperTypeInfo ${v8ClassName}::info = { ${v8ClassName}::GetTemp late, ${v8ClassName}::derefObject, $toActiveDOMObject, $toEventTarget, "; 4048 my $code = "WrapperTypeInfo ${v8ClassName}::info = { ${v8ClassName}::GetTemp late, ${v8ClassName}::derefObject, $toActiveDOMObject, $toEventTarget, ";
4015 $code .= "$rootForGC, ${v8ClassName}::installPerContextPrototypeProperties, $parentClassInfo, $WrapperTypePrototype };\n"; 4049 $code .= "$resolveWrapperReachability, ${v8ClassName}::installPerContextProt otypeProperties, $parentClassInfo, $WrapperTypePrototype };\n";
4016 $implementation{nameSpaceWebCore}->addHeader($code); 4050 $implementation{nameSpaceWebCore}->addHeader($code);
4017 4051
4018 $implementation{nameSpaceInternal}->add("template <typename T> void V8_USE(T ) { }\n\n"); 4052 $implementation{nameSpaceInternal}->add("template <typename T> void V8_USE(T ) { }\n\n");
4019 4053
4020 my $hasConstructors = 0; 4054 my $hasConstructors = 0;
4021 my $hasReplaceable = 0; 4055 my $hasReplaceable = 0;
4022 4056
4023 # Generate property accessors for attributes. 4057 # Generate property accessors for attributes.
4024 for (my $index = 0; $index < @{$interface->attributes}; $index++) { 4058 for (my $index = 0; $index < @{$interface->attributes}; $index++) {
4025 my $attribute = @{$interface->attributes}[$index]; 4059 my $attribute = @{$interface->attributes}[$index];
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
4062 4096
4063 if ($hasConstructors) { 4097 if ($hasConstructors) {
4064 GenerateConstructorGetter($interface); 4098 GenerateConstructorGetter($interface);
4065 } 4099 }
4066 4100
4067 if ($hasConstructors || $hasReplaceable) { 4101 if ($hasConstructors || $hasReplaceable) {
4068 GenerateReplaceableAttributeSetter($interface); 4102 GenerateReplaceableAttributeSetter($interface);
4069 GenerateReplaceableAttributeSetterCallback($interface); 4103 GenerateReplaceableAttributeSetterCallback($interface);
4070 } 4104 }
4071 4105
4072 if (NeedsOpaqueRootForGC($interface)) { 4106 if (NeedResolveWrapperReachability($interface)) {
4073 GenerateOpaqueRootForGC($interface); 4107 GenerateResolveWrapperReachability($interface);
4074 } 4108 }
4075 4109
4076 if ($interface->extendedAttributes->{"CheckSecurity"} && $interface->name ne "Window") { 4110 if ($interface->extendedAttributes->{"CheckSecurity"} && $interface->name ne "Window") {
4077 GenerateSecurityCheckFunctions($interface); 4111 GenerateSecurityCheckFunctions($interface);
4078 } 4112 }
4079 4113
4080 if (IsConstructorTemplate($interface, "TypedArray")) { 4114 if (IsConstructorTemplate($interface, "TypedArray")) {
4081 my ($nativeType, $arrayType) = GetNativeTypeOfTypedArray($interface); 4115 my ($nativeType, $arrayType) = GetNativeTypeOfTypedArray($interface);
4082 $implementation{nameSpaceWebCore}->add(<<END); 4116 $implementation{nameSpaceWebCore}->add(<<END);
4083 v8::Handle<v8::Object> wrap($implClassName* impl, v8::Handle<v8::Object> creatio nContext, v8::Isolate* isolate) 4117 v8::Handle<v8::Object> wrap($implClassName* impl, v8::Handle<v8::Object> creatio nContext, v8::Isolate* isolate)
(...skipping 788 matching lines...) Expand 10 before | Expand all | Expand 10 after
4872 GenerateSpecialWrap($interface, $v8ClassName, $nativeType); 4906 GenerateSpecialWrap($interface, $v8ClassName, $nativeType);
4873 4907
4874 my $createWrapperArgumentType = GetPassRefPtrType($nativeType); 4908 my $createWrapperArgumentType = GetPassRefPtrType($nativeType);
4875 my $baseType = BaseInterfaceName($interface); 4909 my $baseType = BaseInterfaceName($interface);
4876 4910
4877 # FIXME: Do we really need to treat "GenerateIsReachable", "CustomIsReachabl e" and /SVG/ 4911 # FIXME: Do we really need to treat "GenerateIsReachable", "CustomIsReachabl e" and /SVG/
4878 # as dependent DOM objects? 4912 # as dependent DOM objects?
4879 my $wrapperConfiguration = "WrapperConfiguration::Independent"; 4913 my $wrapperConfiguration = "WrapperConfiguration::Independent";
4880 if (InheritsExtendedAttribute($interface, "ActiveDOMObject") 4914 if (InheritsExtendedAttribute($interface, "ActiveDOMObject")
4881 || InheritsExtendedAttribute($interface, "DependentLifetime") 4915 || InheritsExtendedAttribute($interface, "DependentLifetime")
4882 || InheritsExtendedAttribute($interface, "GenerateIsReachable") 4916 || NeedResolveWrapperReachability($interface)
4883 || InheritsExtendedAttribute($interface, "CustomIsReachable")
4884 || $v8ClassName =~ /SVG/) { 4917 || $v8ClassName =~ /SVG/) {
4885 $wrapperConfiguration = "WrapperConfiguration::Dependent"; 4918 $wrapperConfiguration = "WrapperConfiguration::Dependent";
4886 } 4919 }
4887 4920
4888 my $code = ""; 4921 my $code = "";
4889 $code .= <<END; 4922 $code .= <<END;
4890 v8::Handle<v8::Object> ${v8ClassName}::createWrapper(${createWrapperArgumentType } impl, v8::Handle<v8::Object> creationContext, v8::Isolate* isolate) 4923 v8::Handle<v8::Object> ${v8ClassName}::createWrapper(${createWrapperArgumentType } impl, v8::Handle<v8::Object> creationContext, v8::Isolate* isolate)
4891 { 4924 {
4892 ASSERT(impl); 4925 ASSERT(impl);
4893 ASSERT(!DOMDataStore::containsWrapper<${v8ClassName}>(impl.get(), isolate)); 4926 ASSERT(!DOMDataStore::containsWrapper<${v8ClassName}>(impl.get(), isolate));
(...skipping 1283 matching lines...) Expand 10 before | Expand all | Expand 10 after
6177 my $interface = shift; 6210 my $interface = shift;
6178 6211
6179 return 1 if $interface->extendedAttributes->{"CustomToV8"}; 6212 return 1 if $interface->extendedAttributes->{"CustomToV8"};
6180 return 1 if $interface->extendedAttributes->{"SpecialWrapFor"}; 6213 return 1 if $interface->extendedAttributes->{"SpecialWrapFor"};
6181 return 1 if InheritsInterface($interface, "Document"); 6214 return 1 if InheritsInterface($interface, "Document");
6182 6215
6183 return 0; 6216 return 0;
6184 } 6217 }
6185 6218
6186 1; 6219 1;
OLDNEW
« no previous file with comments | « Source/bindings/scripts/IDLAttributes.txt ('k') | Source/bindings/tests/results/V8Float64Array.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698