- Revision
- 145765
- Author
- commit-qu...@webkit.org
- Date
- 2013-03-13 15:50:09 -0700 (Wed, 13 Mar 2013)
Log Message
[V8] Get rid of more function-level static FunctionTemplates and ObjectTemplates in bindings
https://bugs.webkit.org/show_bug.cgi?id=112262
Patch by Marja Hölttä <ma...@chromium.org> on 2013-03-13
Reviewed by Jochen Eisinger.
In the future we'll create and store function templates for main world
and non-main worlds separately (see bug 111724), having function
templates and object templates as static variables inside functions will
break the functionality.
No new tests (no changes in functionality yet; existing bindings
tests still pass).
* bindings/scripts/CodeGeneratorV8.pm:
(GenerateHeader):
(GenerateImplementation):
* bindings/v8/V8DOMWindowShell.cpp:
(WebCore::V8DOMWindowShell::createContext):
* bindings/v8/V8PerIsolateData.cpp:
(WebCore::V8PerIsolateData::hasPrivateTemplate):
(WebCore):
* bindings/v8/V8PerIsolateData.h:
(V8PerIsolateData):
* bindings/v8/custom/V8HTMLDocumentCustom.cpp:
(WebCore::V8HTMLDocument::wrapInShadowObject):
Modified Paths
Diff
Modified: trunk/Source/WebCore/ChangeLog (145764 => 145765)
--- trunk/Source/WebCore/ChangeLog 2013-03-13 22:34:12 UTC (rev 145764)
+++ trunk/Source/WebCore/ChangeLog 2013-03-13 22:50:09 UTC (rev 145765)
@@ -1,3 +1,31 @@
+2013-03-13 Marja Hölttä <ma...@chromium.org>
+
+ [V8] Get rid of more function-level static FunctionTemplates and ObjectTemplates in bindings
+ https://bugs.webkit.org/show_bug.cgi?id=112262
+
+ Reviewed by Jochen Eisinger.
+
+ In the future we'll create and store function templates for main world
+ and non-main worlds separately (see bug 111724), having function
+ templates and object templates as static variables inside functions will
+ break the functionality.
+
+ No new tests (no changes in functionality yet; existing bindings
+ tests still pass).
+
+ * bindings/scripts/CodeGeneratorV8.pm:
+ (GenerateHeader):
+ (GenerateImplementation):
+ * bindings/v8/V8DOMWindowShell.cpp:
+ (WebCore::V8DOMWindowShell::createContext):
+ * bindings/v8/V8PerIsolateData.cpp:
+ (WebCore::V8PerIsolateData::hasPrivateTemplate):
+ (WebCore):
+ * bindings/v8/V8PerIsolateData.h:
+ (V8PerIsolateData):
+ * bindings/v8/custom/V8HTMLDocumentCustom.cpp:
+ (WebCore::V8HTMLDocument::wrapInShadowObject):
+
2013-03-13 Julien Chaffraix <jchaffr...@webkit.org>
[CSS Grid Layout] Refactor GridCoordinate to hold GridSpans
Modified: trunk/Source/WebCore/bindings/scripts/CodeGeneratorV8.pm (145764 => 145765)
--- trunk/Source/WebCore/bindings/scripts/CodeGeneratorV8.pm 2013-03-13 22:34:12 UTC (rev 145764)
+++ trunk/Source/WebCore/bindings/scripts/CodeGeneratorV8.pm 2013-03-13 22:50:09 UTC (rev 145765)
@@ -384,7 +384,7 @@
if ($interfaceName eq "DOMWindow") {
push(@headerContent, <<END);
- static v8::Persistent<v8::ObjectTemplate> GetShadowObjectTemplate(v8::Isolate*);
+ static v8::Persistent<v8::ObjectTemplate> GetShadowObjectTemplate(v8::Isolate*, WrapperWorldType);
END
}
@@ -3260,14 +3260,23 @@
if ($interfaceName eq "DOMWindow") {
push(@implContent, <<END);
-v8::Persistent<v8::ObjectTemplate> V8DOMWindow::GetShadowObjectTemplate(v8::Isolate* isolate)
+v8::Persistent<v8::ObjectTemplate> V8DOMWindow::GetShadowObjectTemplate(v8::Isolate* isolate, WrapperWorldType currentWorldType)
{
- static v8::Persistent<v8::ObjectTemplate> V8DOMWindowShadowObjectCache;
- if (V8DOMWindowShadowObjectCache.IsEmpty()) {
- V8DOMWindowShadowObjectCache = v8::Persistent<v8::ObjectTemplate>::New(isolate, v8::ObjectTemplate::New());
- ConfigureShadowObjectTemplate(V8DOMWindowShadowObjectCache, isolate);
+ if (currentWorldType == MainWorld) {
+ static v8::Persistent<v8::ObjectTemplate> V8DOMWindowShadowObjectCacheForMainWorld;
+ if (V8DOMWindowShadowObjectCacheForMainWorld.IsEmpty()) {
+ V8DOMWindowShadowObjectCacheForMainWorld = v8::Persistent<v8::ObjectTemplate>::New(isolate, v8::ObjectTemplate::New());
+ ConfigureShadowObjectTemplate(V8DOMWindowShadowObjectCacheForMainWorld, isolate);
+ }
+ return V8DOMWindowShadowObjectCacheForMainWorld;
+ } else {
+ static v8::Persistent<v8::ObjectTemplate> V8DOMWindowShadowObjectCacheForNonMainWorld;
+ if (V8DOMWindowShadowObjectCacheForNonMainWorld.IsEmpty()) {
+ V8DOMWindowShadowObjectCacheForNonMainWorld = v8::Persistent<v8::ObjectTemplate>::New(isolate, v8::ObjectTemplate::New());
+ ConfigureShadowObjectTemplate(V8DOMWindowShadowObjectCacheForNonMainWorld, isolate);
+ }
+ return V8DOMWindowShadowObjectCacheForNonMainWorld;
}
- return V8DOMWindowShadowObjectCache;
}
END
Modified: trunk/Source/WebCore/bindings/v8/V8DOMWindowShell.cpp (145764 => 145765)
--- trunk/Source/WebCore/bindings/v8/V8DOMWindowShell.cpp 2013-03-13 22:34:12 UTC (rev 145764)
+++ trunk/Source/WebCore/bindings/v8/V8DOMWindowShell.cpp 2013-03-13 22:50:09 UTC (rev 145765)
@@ -281,7 +281,7 @@
// Create a new environment using an empty template for the shadow
// object. Reuse the global object if one has been created earlier.
- v8::Persistent<v8::ObjectTemplate> globalTemplate = V8DOMWindow::GetShadowObjectTemplate(m_isolate);
+ v8::Persistent<v8::ObjectTemplate> globalTemplate = V8DOMWindow::GetShadowObjectTemplate(m_isolate, m_world->isMainWorld() ? MainWorld : IsolatedWorld);
if (globalTemplate.IsEmpty())
return;
Modified: trunk/Source/WebCore/bindings/v8/V8PerIsolateData.cpp (145764 => 145765)
--- trunk/Source/WebCore/bindings/v8/V8PerIsolateData.cpp 2013-03-13 22:34:12 UTC (rev 145764)
+++ trunk/Source/WebCore/bindings/v8/V8PerIsolateData.cpp 2013-03-13 22:50:09 UTC (rev 145765)
@@ -122,6 +122,11 @@
info.ignoreMember(m_auxiliaryContext);
}
+bool V8PerIsolateData::hasPrivateTemplate(WrapperWorldType, void* privatePointer)
+{
+ return m_templates.find(privatePointer) != m_templates.end();
+}
+
v8::Persistent<v8::FunctionTemplate> V8PerIsolateData::privateTemplate(WrapperWorldType, void* privatePointer, v8::InvocationCallback callback, v8::Handle<v8::Value> data, v8::Handle<v8::Signature> signature, int length)
{
v8::Persistent<v8::FunctionTemplate> privateTemplate;
Modified: trunk/Source/WebCore/bindings/v8/V8PerIsolateData.h (145764 => 145765)
--- trunk/Source/WebCore/bindings/v8/V8PerIsolateData.h 2013-03-13 22:34:12 UTC (rev 145764)
+++ trunk/Source/WebCore/bindings/v8/V8PerIsolateData.h 2013-03-13 22:50:09 UTC (rev 145765)
@@ -128,6 +128,7 @@
void clearShouldCollectGarbageSoon() { m_shouldCollectGarbageSoon = false; }
bool shouldCollectGarbageSoon() const { return m_shouldCollectGarbageSoon; }
+ bool hasPrivateTemplate(WrapperWorldType, void* privatePointer);
v8::Persistent<v8::FunctionTemplate> privateTemplate(WrapperWorldType, void* privatePointer, v8::InvocationCallback, v8::Handle<v8::Value> data, v8::Handle<v8::Signature>, int length = 0);
v8::Persistent<v8::FunctionTemplate> rawTemplate(WrapperTypeInfo*);
Modified: trunk/Source/WebCore/bindings/v8/custom/V8HTMLDocumentCustom.cpp (145764 => 145765)
--- trunk/Source/WebCore/bindings/v8/custom/V8HTMLDocumentCustom.cpp 2013-03-13 22:34:12 UTC (rev 145764)
+++ trunk/Source/WebCore/bindings/v8/custom/V8HTMLDocumentCustom.cpp 2013-03-13 22:50:09 UTC (rev 145765)
@@ -54,16 +54,20 @@
v8::Local<v8::Object> V8HTMLDocument::wrapInShadowObject(v8::Local<v8::Object> wrapper, Node* impl, v8::Isolate* isolate)
{
- DEFINE_STATIC_LOCAL(v8::Persistent<v8::FunctionTemplate>, shadowTemplate, ());
- if (shadowTemplate.IsEmpty()) {
+ // This is only for getting a unique pointer which we can pass to privateTemplate.
+ static const char* shadowTemplateUniqueKey = "wrapInShadowObjectShadowTemplate";
+ WrapperWorldType currentWorldType = worldType(isolate);
+ v8::Persistent<v8::FunctionTemplate> shadowTemplate;
+ if (!V8PerIsolateData::from(isolate)->hasPrivateTemplate(currentWorldType, &shadowTemplateUniqueKey)) {
shadowTemplate = v8::Persistent<v8::FunctionTemplate>::New(isolate, v8::FunctionTemplate::New());
if (shadowTemplate.IsEmpty())
return v8::Local<v8::Object>();
shadowTemplate->SetClassName(v8::String::NewSymbol("HTMLDocument"));
- shadowTemplate->Inherit(V8HTMLDocument::GetTemplate(isolate, worldTypeInMainThread(isolate)));
+ shadowTemplate->Inherit(V8HTMLDocument::GetTemplate(isolate, currentWorldType));
shadowTemplate->InstanceTemplate()->SetInternalFieldCount(V8HTMLDocument::internalFieldCount);
+ } else {
+ shadowTemplate = V8PerIsolateData::from(isolate)->privateTemplate(currentWorldType, &shadowTemplateUniqueKey, 0, v8::Handle<v8::Value>(), v8::Handle<v8::Signature>());
}
-
v8::Local<v8::Function> shadowConstructor = shadowTemplate->GetFunction();
if (shadowConstructor.IsEmpty())
return v8::Local<v8::Object>();