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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « Source/bindings/scripts/IDLAttributes.txt ('k') | Source/bindings/tests/results/V8Float64Array.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/bindings/scripts/code_generator_v8.pm
diff --git a/Source/bindings/scripts/code_generator_v8.pm b/Source/bindings/scripts/code_generator_v8.pm
index 867e653790dc0a635d5877009dde6a8a6c713f37..d3ac179256e3044f15d80af71b71c6f6740b62f8 100644
--- a/Source/bindings/scripts/code_generator_v8.pm
+++ b/Source/bindings/scripts/code_generator_v8.pm
@@ -454,13 +454,13 @@ sub HeaderFilesForInterface
return @includes;
}
-sub NeedsOpaqueRootForGC
+sub NeedResolveWrapperReachability
{
my $interface = shift;
- return $interface->extendedAttributes->{"GenerateIsReachable"} || $interface->extendedAttributes->{"CustomIsReachable"};
+ return $interface->extendedAttributes->{"GenerateIsReachable"} || $interface->extendedAttributes->{"CustomIsReachable"} || $interface->extendedAttributes->{"ReachableTo"};
}
-sub GenerateOpaqueRootForGC
+sub GenerateResolveWrapperReachability
{
my $interface = shift;
my $implClassName = GetImplName($interface);
@@ -471,22 +471,41 @@ sub GenerateOpaqueRootForGC
}
my $code = <<END;
-void* ${v8ClassName}::opaqueRootForGC(void* object, v8::Isolate* isolate)
+void ${v8ClassName}::resolveWrapperReachability(void* object, const v8::Persistent<v8::Object>& wrapper, v8::Isolate* isolate)
{
${implClassName}* impl = fromInternalPointer(object);
END
+ if ($interface->extendedAttributes->{"ReachableTo"}) {
+ $code .= " v8::Local<v8::Object> creationContext = v8::Local<v8::Object>::New(isolate, wrapper);\n";
+ }
+ for my $reachableTo (@{$interface->extendedAttributes->{"ReachableTo"}}) {
+ my $reachableToType = $reachableTo->type;
+ my $reachableToName = $reachableTo->name;
+
+ AddIncludesForType($reachableToType);
+ $code .= <<END;
+ ${reachableToType}* ${reachableToName} = impl->${reachableToName}();
+ if (filter) {
+ UnsafePersistent<v8::Object> target = toV8Persistent(${reachableToName}, creationContext, isolate);
+ isolate->SetReference(wrapper, *reinterpret_cast<v8::Persistent<v8::Value>*>(target.persistent()));
+ }
+END
+ }
+
my $isReachableMethod = $interface->extendedAttributes->{"GenerateIsReachable"};
if ($isReachableMethod) {
AddToImplIncludes("bindings/v8/V8GCController.h");
AddToImplIncludes("core/dom/Element.h");
$code .= <<END;
- if (Node* owner = impl->${isReachableMethod}())
- return V8GCController::opaqueRootForGC(owner, isolate);
+ if (Node* owner = impl->${isReachableMethod}()) {
+ setObjectGroup(V8GCController::opaqueRootForGC(owner, isolate), wrapper, isolate);
+ return;
+ }
END
}
$code .= <<END;
- return object;
+ setObjectGroup(object, wrapper, isolate);
}
END
@@ -669,8 +688,8 @@ END
static WrapperTypeInfo info;
END
- if (NeedsOpaqueRootForGC($interface)) {
- $header{classPublic}->add(" static void* opaqueRootForGC(void*, v8::Isolate*);\n");
+ if (NeedResolveWrapperReachability($interface)) {
+ $header{classPublic}->add(" static void resolveWrapperReachability(void*, const v8::Persistent<v8::Object>&, v8::Isolate*);\n");
}
if (InheritsExtendedAttribute($interface, "ActiveDOMObject")) {
@@ -895,6 +914,21 @@ inline v8::Handle<v8::Value> toV8(${nativeType}* impl, v8::Handle<v8::Object> cr
return wrap(impl, creationContext, isolate);
}
+inline UnsafePersistent<v8::Object> toV8Persistent(${nativeType}* impl, v8::Handle<v8::Object> creationContext, v8::Isolate* isolate)
jochen (gone - plz use gerrit) 2013/10/15 05:26:43 we shouldn't introduce code using UnsafePersistent
+{
+ ASSERT(impl);
+
+ UnsafePersistent<v8::Object> wrapperPersistent = DOMDataStore::getWrapperPersistent<${v8ClassName}>(impl, isolate);
+ if (LIKELY(!wrapperPersistent.isEmpty()))
+ return wrapperPersistent;
+
+ wrap(impl, creationContext, isolate);
+
+ wrapperPersistent = DOMDataStore::getWrapperPersistent<${v8ClassName}>(impl, isolate);
+ ASSERT(!wrapperPersistent.isEmpty());
+ return wrapperPersistent;
+}
+
template<typename CallbackInfo>
inline void v8SetReturnValue(const CallbackInfo& callbackInfo, ${nativeType}* impl, v8::Handle<v8::Object> creationContext)
{
@@ -3962,7 +3996,7 @@ sub GenerateImplementation
my $toActiveDOMObject = InheritsExtendedAttribute($interface, "ActiveDOMObject") ? "${v8ClassName}::toActiveDOMObject" : "0";
my $toEventTarget = InheritsInterface($interface, "EventTarget") ? "${v8ClassName}::toEventTarget" : "0";
- my $rootForGC = NeedsOpaqueRootForGC($interface) ? "${v8ClassName}::opaqueRootForGC" : "0";
+ my $resolveWrapperReachability = NeedResolveWrapperReachability($interface) ? "${v8ClassName}::resolveWrapperReachability" : "0";
# Find the super descriptor.
my $parentClass = "";
@@ -4012,7 +4046,7 @@ END
}
my $code = "WrapperTypeInfo ${v8ClassName}::info = { ${v8ClassName}::GetTemplate, ${v8ClassName}::derefObject, $toActiveDOMObject, $toEventTarget, ";
- $code .= "$rootForGC, ${v8ClassName}::installPerContextPrototypeProperties, $parentClassInfo, $WrapperTypePrototype };\n";
+ $code .= "$resolveWrapperReachability, ${v8ClassName}::installPerContextPrototypeProperties, $parentClassInfo, $WrapperTypePrototype };\n";
$implementation{nameSpaceWebCore}->addHeader($code);
$implementation{nameSpaceInternal}->add("template <typename T> void V8_USE(T) { }\n\n");
@@ -4069,8 +4103,8 @@ END
GenerateReplaceableAttributeSetterCallback($interface);
}
- if (NeedsOpaqueRootForGC($interface)) {
- GenerateOpaqueRootForGC($interface);
+ if (NeedResolveWrapperReachability($interface)) {
+ GenerateResolveWrapperReachability($interface);
}
if ($interface->extendedAttributes->{"CheckSecurity"} && $interface->name ne "Window") {
@@ -4879,8 +4913,7 @@ sub GenerateToV8Converters
my $wrapperConfiguration = "WrapperConfiguration::Independent";
if (InheritsExtendedAttribute($interface, "ActiveDOMObject")
|| InheritsExtendedAttribute($interface, "DependentLifetime")
- || InheritsExtendedAttribute($interface, "GenerateIsReachable")
- || InheritsExtendedAttribute($interface, "CustomIsReachable")
+ || NeedResolveWrapperReachability($interface)
|| $v8ClassName =~ /SVG/) {
$wrapperConfiguration = "WrapperConfiguration::Dependent";
}
« 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