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

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

Issue 64683006: [svg] TearOffs dynamically hold on to the current contextElement(). (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: gchack Created 7 years, 1 month 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 449 matching lines...) Expand 10 before | Expand all | Expand 10 after
460 my $idlFilename = Cwd::abs_path(IDLFileForInterface($interfaceName)) or die("Could NOT find IDL file for interface \"$interfaceName\" $!\n"); 460 my $idlFilename = Cwd::abs_path(IDLFileForInterface($interfaceName)) or die("Could NOT find IDL file for interface \"$interfaceName\" $!\n");
461 my $idlRelPath = File::Spec->abs2rel($idlFilename, $sourceRoot); 461 my $idlRelPath = File::Spec->abs2rel($idlFilename, $sourceRoot);
462 push(@includes, dirname($idlRelPath) . "/" . $implClassName . ".h"); 462 push(@includes, dirname($idlRelPath) . "/" . $implClassName . ".h");
463 } 463 }
464 return @includes; 464 return @includes;
465 } 465 }
466 466
467 sub NeedsResolveWrapperReachability 467 sub NeedsResolveWrapperReachability
468 { 468 {
469 my $interface = shift; 469 my $interface = shift;
470 return $interface->extendedAttributes->{"GenerateIsReachable"} || $interface ->extendedAttributes->{"CustomIsReachable"} || $interface->extendedAttributes->{ "SetReference"}; 470 return $interface->extendedAttributes->{"GenerateIsReachable"} || $interface ->extendedAttributes->{"CustomIsReachable"} || $interface->extendedAttributes->{ "SetReference"} || SVGTypeNeedsToHoldContextElement($interface->name);
471 } 471 }
472 472
473 sub GenerateResolveWrapperReachability 473 sub GenerateResolveWrapperReachability
474 { 474 {
475 my $interface = shift; 475 my $interface = shift;
476 my $implClassName = GetImplName($interface); 476 my $implClassName = GetImplName($interface);
477 my $v8ClassName = GetV8ClassName($interface); 477 my $v8ClassName = GetV8ClassName($interface);
478 478
479 if ($interface->extendedAttributes->{"CustomIsReachable"}) { 479 if ($interface->extendedAttributes->{"CustomIsReachable"}) {
480 return; 480 return;
481 } 481 }
482 482
483 my $nativeType = GetNativeTypeForConversions($interface);
483 my $code = <<END; 484 my $code = <<END;
484 void ${v8ClassName}::resolveWrapperReachability(void* object, const v8::Persiste nt<v8::Object>& wrapper, v8::Isolate* isolate) 485 void ${v8ClassName}::resolveWrapperReachability(void* object, const v8::Persiste nt<v8::Object>& wrapper, v8::Isolate* isolate)
485 { 486 {
486 ${implClassName}* impl = fromInternalPointer(object); 487 ${nativeType}* impl = fromInternalPointer(object);
487 END 488 END
488 if ($interface->extendedAttributes->{"SetReference"}) { 489 my $needSetWrapperReferenceContext = SVGTypeNeedsToHoldContextElement($inter face->name) || $interface->extendedAttributes->{"SetReference"};
490 if ($needSetWrapperReferenceContext) {
489 $code .= <<END; 491 $code .= <<END;
490 v8::Local<v8::Object> creationContext = v8::Local<v8::Object>::New(isolate, wrapper); 492 v8::Local<v8::Object> creationContext = v8::Local<v8::Object>::New(isolate, wrapper);
491 V8WrapperInstantiationScope scope(creationContext, isolate); 493 V8WrapperInstantiationScope scope(creationContext, isolate);
492 END 494 END
493 } 495 }
496 if (SVGTypeNeedsToHoldContextElement($interface->name)) {
497 AddToImplIncludes("V8SVGPathElement.h");
498 $code .= <<END;
499 if (impl->contextElement()) {
500 if (!DOMDataStore::containsWrapper<V8SVGElement>(impl->contextElement(), isolate))
501 wrap(impl->contextElement(), creationContext, isolate);
502 DOMDataStore::setWrapperReference<V8SVGElement>(wrapper, impl->contextEl ement(), isolate);
503 }
504 END
505 }
494 for my $setReference (@{$interface->extendedAttributes->{"SetReference"}}) { 506 for my $setReference (@{$interface->extendedAttributes->{"SetReference"}}) {
495 my $setReferenceType = $setReference->type; 507 my $setReferenceType = $setReference->type;
496 my $setReferenceName = $setReference->name; 508 my $setReferenceName = $setReference->name;
497 my $setReferenceV8Type = "V8".$setReferenceType; 509 my $setReferenceV8Type = "V8".$setReferenceType;
498 510
499 AddIncludesForType($setReferenceType); 511 AddIncludesForType($setReferenceType);
500 $code .= <<END; 512 $code .= <<END;
501 ${setReferenceType}* ${setReferenceName} = impl->${setReferenceName}(); 513 ${setReferenceType}* ${setReferenceName} = impl->${setReferenceName}();
502 if (${setReferenceName}) { 514 if (${setReferenceName}) {
503 if (!DOMDataStore::containsWrapper<${setReferenceV8Type}>(${setReference Name}, isolate)) 515 if (!DOMDataStore::containsWrapper<${setReferenceV8Type}>(${setReference Name}, isolate))
(...skipping 3704 matching lines...) Expand 10 before | Expand all | Expand 10 after
4208 ASSERT(impl); 4220 ASSERT(impl);
4209 v8::Handle<v8::Object> wrapper = ${v8ClassName}::createWrapper(impl, creatio nContext, isolate); 4221 v8::Handle<v8::Object> wrapper = ${v8ClassName}::createWrapper(impl, creatio nContext, isolate);
4210 if (!wrapper.IsEmpty()) 4222 if (!wrapper.IsEmpty())
4211 wrapper->SetIndexedPropertiesToExternalArrayData(impl->baseAddress(), $a rrayType, impl->length()); 4223 wrapper->SetIndexedPropertiesToExternalArrayData(impl->baseAddress(), $a rrayType, impl->length());
4212 return wrapper; 4224 return wrapper;
4213 } 4225 }
4214 4226
4215 END 4227 END
4216 } 4228 }
4217 4229
4218 # Add strong reference from TearOff to SVGElement, so that SVGElement would never get GC-ed while the TearOff is alive. We do this in V8-side to avoid circu lar reference on Blink side.
4219 if (SVGTypeNeedsToHoldContextElement($interface->name)) {
4220 # below include needed for SVGPathSegListPropertyTearOff
4221 AddToImplIncludes("V8SVGPathElement.h");
4222 AddToImplIncludes("bindings/v8/V8HiddenPropertyName.h");
4223 $implementation{nameSpaceWebCore}->add(<<END);
4224 v8::Handle<v8::Object> wrap($nativeType* impl, v8::Handle<v8::Object> creationCo ntext, v8::Isolate* isolate)
4225 {
4226 ASSERT(impl);
4227 ASSERT(!DOMDataStore::containsWrapper<${v8ClassName}>(impl, isolate));
4228 v8::Handle<v8::Object> wrapper = ${v8ClassName}::createWrapper(impl, creatio nContext, isolate);
4229 if (impl->contextElement())
4230 V8HiddenPropertyName::setNamedHiddenReference(wrapper, "contextElement", toV8(impl->contextElement(), creationContext, isolate));
4231 return wrapper;
4232 }
4233
4234 END
4235 }
4236
4237 my @perContextEnabledFunctions; 4230 my @perContextEnabledFunctions;
4238 my @normalFunctions; 4231 my @normalFunctions;
4239 my $needsDomainSafeFunctionSetter = 0; 4232 my $needsDomainSafeFunctionSetter = 0;
4240 # Generate methods for functions. 4233 # Generate methods for functions.
4241 foreach my $function (@{$interface->functions}) { 4234 foreach my $function (@{$interface->functions}) {
4242 next if $function->name eq ""; 4235 next if $function->name eq "";
4243 GenerateFunction($function, $interface, ""); 4236 GenerateFunction($function, $interface, "");
4244 if ($function->extendedAttributes->{"PerWorldBindings"}) { 4237 if ($function->extendedAttributes->{"PerWorldBindings"}) {
4245 GenerateFunction($function, $interface, "ForMainWorld"); 4238 GenerateFunction($function, $interface, "ForMainWorld");
4246 } 4239 }
(...skipping 2038 matching lines...) Expand 10 before | Expand all | Expand 10 after
6285 return $found; 6278 return $found;
6286 } 6279 }
6287 6280
6288 sub NeedsSpecialWrap 6281 sub NeedsSpecialWrap
6289 { 6282 {
6290 my $interface = shift; 6283 my $interface = shift;
6291 6284
6292 return 1 if $interface->extendedAttributes->{"CustomToV8"}; 6285 return 1 if $interface->extendedAttributes->{"CustomToV8"};
6293 return 1 if $interface->extendedAttributes->{"SpecialWrapFor"}; 6286 return 1 if $interface->extendedAttributes->{"SpecialWrapFor"};
6294 return 1 if InheritsInterface($interface, "Document"); 6287 return 1 if InheritsInterface($interface, "Document");
6295 return 1 if SVGTypeNeedsToHoldContextElement($interface->name);
6296 6288
6297 return 0; 6289 return 0;
6298 } 6290 }
6299 6291
6300 1; 6292 1;
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698