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

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: SetReference 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 NeedsResolveWrapperReachability
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->{ "SetReference"};
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->{"SetReference"}) {
479 $code .= " v8::Local<v8::Object> creationContext = v8::Local<v8::Obje ct>::New(isolate, wrapper);\n";
480 }
481 for my $setReference (@{$interface->extendedAttributes->{"SetReference"}}) {
482 my $setReferenceType = $setReference->type;
483 my $setReferenceName = $setReference->name;
484 my $setReferenceV8Type = "V8".$setReferenceType;
485
486 AddIncludesForType($setReferenceType);
487 $code .= <<END;
488 ${setReferenceType}* ${setReferenceName} = impl->${setReferenceName}();
489 if (${setReferenceName}) {
490 if(!DOMDataStore::containsWrapper<${setReferenceV8Type}>(${setReferenceN ame}, isolate))
491 wrap(${setReferenceName}, creationContext, isolate);
492 DOMDataStore::setWrapperReference<${setReferenceV8Type}>(wrapper, ${setR eferenceName}, isolate);
493 }
494 END
495 }
496
478 my $isReachableMethod = $interface->extendedAttributes->{"GenerateIsReachabl e"}; 497 my $isReachableMethod = $interface->extendedAttributes->{"GenerateIsReachabl e"};
479 if ($isReachableMethod) { 498 if ($isReachableMethod) {
480 AddToImplIncludes("bindings/v8/V8GCController.h"); 499 AddToImplIncludes("bindings/v8/V8GCController.h");
481 AddToImplIncludes("core/dom/Element.h"); 500 AddToImplIncludes("core/dom/Element.h");
482 $code .= <<END; 501 $code .= <<END;
483 if (Node* owner = impl->${isReachableMethod}()) 502 if (Node* owner = impl->${isReachableMethod}()) {
484 return V8GCController::opaqueRootForGC(owner, isolate); 503 setObjectGroup(V8GCController::opaqueRootForGC(owner, isolate), wrapper, isolate);
504 return;
505 }
485 END 506 END
486 } 507 }
487 508
488 $code .= <<END; 509 $code .= <<END;
489 return object; 510 setObjectGroup(object, wrapper, isolate);
490 } 511 }
491 512
492 END 513 END
493 $implementation{nameSpaceWebCore}->add($code); 514 $implementation{nameSpaceWebCore}->add($code);
494 } 515 }
495 516
496 sub GetSVGPropertyTypes 517 sub GetSVGPropertyTypes
497 { 518 {
498 my $implType = shift; 519 my $implType = shift;
499 520
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after
662 static bool HasInstanceInAnyWorld(v8::Handle<v8::Value>, v8::Isolate*); 683 static bool HasInstanceInAnyWorld(v8::Handle<v8::Value>, v8::Isolate*);
663 static v8::Handle<v8::FunctionTemplate> GetTemplate(v8::Isolate*, WrapperWor ldType); 684 static v8::Handle<v8::FunctionTemplate> GetTemplate(v8::Isolate*, WrapperWor ldType);
664 static ${nativeType}* toNative(v8::Handle<v8::Object> object) 685 static ${nativeType}* toNative(v8::Handle<v8::Object> object)
665 { 686 {
666 return fromInternalPointer(object->GetAlignedPointerFromInternalField(v8 DOMWrapperObjectIndex)); 687 return fromInternalPointer(object->GetAlignedPointerFromInternalField(v8 DOMWrapperObjectIndex));
667 } 688 }
668 static void derefObject(void*); 689 static void derefObject(void*);
669 static WrapperTypeInfo info; 690 static WrapperTypeInfo info;
670 END 691 END
671 692
672 if (NeedsOpaqueRootForGC($interface)) { 693 if (NeedsResolveWrapperReachability($interface)) {
673 $header{classPublic}->add(" static void* opaqueRootForGC(void*, v8::I solate*);\n"); 694 $header{classPublic}->add(" static void resolveWrapperReachability(vo id*, const v8::Persistent<v8::Object>&, v8::Isolate*);\n");
674 } 695 }
675 696
676 if (InheritsExtendedAttribute($interface, "ActiveDOMObject")) { 697 if (InheritsExtendedAttribute($interface, "ActiveDOMObject")) {
677 $header{classPublic}->add(" static ActiveDOMObject* toActiveDOMObject (v8::Handle<v8::Object>);\n"); 698 $header{classPublic}->add(" static ActiveDOMObject* toActiveDOMObject (v8::Handle<v8::Object>);\n");
678 } 699 }
679 700
680 if (InheritsInterface($interface, "EventTarget")) { 701 if (InheritsInterface($interface, "EventTarget")) {
681 $header{classPublic}->add(" static EventTarget* toEventTarget(v8::Han dle<v8::Object>);\n"); 702 $header{classPublic}->add(" static EventTarget* toEventTarget(v8::Han dle<v8::Object>);\n");
682 } 703 }
683 704
(...skipping 3311 matching lines...) Expand 10 before | Expand all | Expand 10 after
3995 AddToImplIncludes("bindings/v8/V8DOMWrapper.h"); 4016 AddToImplIncludes("bindings/v8/V8DOMWrapper.h");
3996 AddToImplIncludes("core/dom/ContextFeatures.h"); 4017 AddToImplIncludes("core/dom/ContextFeatures.h");
3997 AddToImplIncludes("core/dom/Document.h"); 4018 AddToImplIncludes("core/dom/Document.h");
3998 AddToImplIncludes("RuntimeEnabledFeatures.h"); 4019 AddToImplIncludes("RuntimeEnabledFeatures.h");
3999 AddToImplIncludes("platform/TraceEvent.h"); 4020 AddToImplIncludes("platform/TraceEvent.h");
4000 4021
4001 AddIncludesForType($interfaceName); 4022 AddIncludesForType($interfaceName);
4002 4023
4003 my $toActiveDOMObject = InheritsExtendedAttribute($interface, "ActiveDOMObje ct") ? "${v8ClassName}::toActiveDOMObject" : "0"; 4024 my $toActiveDOMObject = InheritsExtendedAttribute($interface, "ActiveDOMObje ct") ? "${v8ClassName}::toActiveDOMObject" : "0";
4004 my $toEventTarget = InheritsInterface($interface, "EventTarget") ? "${v8Clas sName}::toEventTarget" : "0"; 4025 my $toEventTarget = InheritsInterface($interface, "EventTarget") ? "${v8Clas sName}::toEventTarget" : "0";
4005 my $rootForGC = NeedsOpaqueRootForGC($interface) ? "${v8ClassName}::opaqueRo otForGC" : "0"; 4026 my $resolveWrapperReachability = NeedsResolveWrapperReachability($interface) ? "${v8ClassName}::resolveWrapperReachability" : "0";
4006 4027
4007 # Find the super descriptor. 4028 # Find the super descriptor.
4008 my $parentClass = ""; 4029 my $parentClass = "";
4009 my $parentClassTemplate = ""; 4030 my $parentClassTemplate = "";
4010 if ($interface->parent) { 4031 if ($interface->parent) {
4011 my $parent = $interface->parent; 4032 my $parent = $interface->parent;
4012 AddToImplIncludes("V8${parent}.h"); 4033 AddToImplIncludes("V8${parent}.h");
4013 $parentClass = "V8" . $parent; 4034 $parentClass = "V8" . $parent;
4014 $parentClassTemplate = $parentClass . "::GetTemplate(isolate, currentWor ldType)"; 4035 $parentClassTemplate = $parentClass . "::GetTemplate(isolate, currentWor ldType)";
4015 } 4036 }
(...skipping 29 matching lines...) Expand all
4045 { 4066 {
4046 WebCore::initializeScriptWrappableForInterface(object); 4067 WebCore::initializeScriptWrappableForInterface(object);
4047 } 4068 }
4048 4069
4049 namespace WebCore { 4070 namespace WebCore {
4050 END 4071 END
4051 $implementation{nameSpaceWebCore}->addHeader($code); 4072 $implementation{nameSpaceWebCore}->addHeader($code);
4052 } 4073 }
4053 4074
4054 my $code = "WrapperTypeInfo ${v8ClassName}::info = { ${v8ClassName}::GetTemp late, ${v8ClassName}::derefObject, $toActiveDOMObject, $toEventTarget, "; 4075 my $code = "WrapperTypeInfo ${v8ClassName}::info = { ${v8ClassName}::GetTemp late, ${v8ClassName}::derefObject, $toActiveDOMObject, $toEventTarget, ";
4055 $code .= "$rootForGC, ${v8ClassName}::installPerContextPrototypeProperties, $parentClassInfo, $WrapperTypePrototype };\n"; 4076 $code .= "$resolveWrapperReachability, ${v8ClassName}::installPerContextProt otypeProperties, $parentClassInfo, $WrapperTypePrototype };\n";
4056 $implementation{nameSpaceWebCore}->addHeader($code); 4077 $implementation{nameSpaceWebCore}->addHeader($code);
4057 4078
4058 $implementation{nameSpaceInternal}->add("template <typename T> void V8_USE(T ) { }\n\n"); 4079 $implementation{nameSpaceInternal}->add("template <typename T> void V8_USE(T ) { }\n\n");
4059 4080
4060 my $hasConstructors = 0; 4081 my $hasConstructors = 0;
4061 my $hasReplaceable = 0; 4082 my $hasReplaceable = 0;
4062 4083
4063 # Generate property accessors for attributes. 4084 # Generate property accessors for attributes.
4064 for (my $index = 0; $index < @{$interface->attributes}; $index++) { 4085 for (my $index = 0; $index < @{$interface->attributes}; $index++) {
4065 my $attribute = @{$interface->attributes}[$index]; 4086 my $attribute = @{$interface->attributes}[$index];
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
4102 4123
4103 if ($hasConstructors) { 4124 if ($hasConstructors) {
4104 GenerateConstructorGetter($interface); 4125 GenerateConstructorGetter($interface);
4105 } 4126 }
4106 4127
4107 if ($hasConstructors || $hasReplaceable) { 4128 if ($hasConstructors || $hasReplaceable) {
4108 GenerateReplaceableAttributeSetter($interface); 4129 GenerateReplaceableAttributeSetter($interface);
4109 GenerateReplaceableAttributeSetterCallback($interface); 4130 GenerateReplaceableAttributeSetterCallback($interface);
4110 } 4131 }
4111 4132
4112 if (NeedsOpaqueRootForGC($interface)) { 4133 if (NeedsResolveWrapperReachability($interface)) {
4113 GenerateOpaqueRootForGC($interface); 4134 GenerateResolveWrapperReachability($interface);
4114 } 4135 }
4115 4136
4116 if ($interface->extendedAttributes->{"CheckSecurity"} && $interface->name ne "Window") { 4137 if ($interface->extendedAttributes->{"CheckSecurity"} && $interface->name ne "Window") {
4117 GenerateSecurityCheckFunctions($interface); 4138 GenerateSecurityCheckFunctions($interface);
4118 } 4139 }
4119 4140
4120 if (IsConstructorTemplate($interface, "TypedArray")) { 4141 if (IsConstructorTemplate($interface, "TypedArray")) {
4121 my ($nativeType, $arrayType) = GetNativeTypeOfTypedArray($interface); 4142 my ($nativeType, $arrayType) = GetNativeTypeOfTypedArray($interface);
4122 $implementation{nameSpaceWebCore}->add(<<END); 4143 $implementation{nameSpaceWebCore}->add(<<END);
4123 v8::Handle<v8::Object> wrap($implClassName* impl, v8::Handle<v8::Object> creatio nContext, v8::Isolate* isolate) 4144 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
4912 GenerateSpecialWrap($interface, $v8ClassName, $nativeType); 4933 GenerateSpecialWrap($interface, $v8ClassName, $nativeType);
4913 4934
4914 my $createWrapperArgumentType = GetPassRefPtrType($nativeType); 4935 my $createWrapperArgumentType = GetPassRefPtrType($nativeType);
4915 my $baseType = BaseInterfaceName($interface); 4936 my $baseType = BaseInterfaceName($interface);
4916 4937
4917 # FIXME: Do we really need to treat "GenerateIsReachable", "CustomIsReachabl e" and /SVG/ 4938 # FIXME: Do we really need to treat "GenerateIsReachable", "CustomIsReachabl e" and /SVG/
4918 # as dependent DOM objects? 4939 # as dependent DOM objects?
4919 my $wrapperConfiguration = "WrapperConfiguration::Independent"; 4940 my $wrapperConfiguration = "WrapperConfiguration::Independent";
4920 if (InheritsExtendedAttribute($interface, "ActiveDOMObject") 4941 if (InheritsExtendedAttribute($interface, "ActiveDOMObject")
4921 || InheritsExtendedAttribute($interface, "DependentLifetime") 4942 || InheritsExtendedAttribute($interface, "DependentLifetime")
4922 || InheritsExtendedAttribute($interface, "GenerateIsReachable") 4943 || NeedsResolveWrapperReachability($interface)
4923 || InheritsExtendedAttribute($interface, "CustomIsReachable")
4924 || $v8ClassName =~ /SVG/) { 4944 || $v8ClassName =~ /SVG/) {
4925 $wrapperConfiguration = "WrapperConfiguration::Dependent"; 4945 $wrapperConfiguration = "WrapperConfiguration::Dependent";
4926 } 4946 }
4927 4947
4928 my $code = ""; 4948 my $code = "";
4929 $code .= <<END; 4949 $code .= <<END;
4930 v8::Handle<v8::Object> ${v8ClassName}::createWrapper(${createWrapperArgumentType } impl, v8::Handle<v8::Object> creationContext, v8::Isolate* isolate) 4950 v8::Handle<v8::Object> ${v8ClassName}::createWrapper(${createWrapperArgumentType } impl, v8::Handle<v8::Object> creationContext, v8::Isolate* isolate)
4931 { 4951 {
4932 ASSERT(impl); 4952 ASSERT(impl);
4933 ASSERT(!DOMDataStore::containsWrapper<${v8ClassName}>(impl.get(), isolate)); 4953 ASSERT(!DOMDataStore::containsWrapper<${v8ClassName}>(impl.get(), isolate));
(...skipping 1285 matching lines...) Expand 10 before | Expand all | Expand 10 after
6219 my $interface = shift; 6239 my $interface = shift;
6220 6240
6221 return 1 if $interface->extendedAttributes->{"CustomToV8"}; 6241 return 1 if $interface->extendedAttributes->{"CustomToV8"};
6222 return 1 if $interface->extendedAttributes->{"SpecialWrapFor"}; 6242 return 1 if $interface->extendedAttributes->{"SpecialWrapFor"};
6223 return 1 if InheritsInterface($interface, "Document"); 6243 return 1 if InheritsInterface($interface, "Document");
6224 6244
6225 return 0; 6245 return 0;
6226 } 6246 }
6227 6247
6228 1; 6248 1;
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698