diff options
-rw-r--r-- | webkit/glue/webkit_glue.cc | 7 | ||||
-rw-r--r-- | webkit/glue/webkit_glue.h | 1 | ||||
-rw-r--r-- | webkit/port/bindings/v8/ScriptController.cpp | 1 | ||||
-rw-r--r-- | webkit/port/bindings/v8/ScriptController.h | 15 | ||||
-rw-r--r-- | webkit/port/bindings/v8/v8_proxy.cpp | 19 | ||||
-rw-r--r-- | webkit/tools/test_shell/node_leak_test.cc | 2 | ||||
-rw-r--r-- | webkit/tools/test_shell/test_shell_main.cc | 2 |
7 files changed, 45 insertions, 2 deletions
diff --git a/webkit/glue/webkit_glue.cc b/webkit/glue/webkit_glue.cc index a1e7272..335c3b0 100644 --- a/webkit/glue/webkit_glue.cc +++ b/webkit/glue/webkit_glue.cc @@ -64,6 +64,13 @@ void SetRecordPlaybackMode(bool value) { #endif } + +void SetShouldExposeGCController(bool enable) { +#if USE(V8) + WebCore::ScriptController::setShouldExposeGCController(enable); +#endif +} + static bool layout_test_mode_ = false; void SetLayoutTestMode(bool enable) { diff --git a/webkit/glue/webkit_glue.h b/webkit/glue/webkit_glue.h index ccc3e06..6c685a8 100644 --- a/webkit/glue/webkit_glue.h +++ b/webkit/glue/webkit_glue.h @@ -57,6 +57,7 @@ namespace webkit_glue { // Functions implemented by JS engines. void SetJavaScriptFlags(const std::wstring& flags); void SetRecordPlaybackMode(bool value); +void SetShouldExposeGCController(bool enable); //----------------------------------------------------------------------------- // Functions implemented by WebKit, called by the embedder: diff --git a/webkit/port/bindings/v8/ScriptController.cpp b/webkit/port/bindings/v8/ScriptController.cpp index 6521a4d..7eda483 100644 --- a/webkit/port/bindings/v8/ScriptController.cpp +++ b/webkit/port/bindings/v8/ScriptController.cpp @@ -78,6 +78,7 @@ NPRuntimeFunctions npruntime_functions = { namespace WebCore { bool ScriptController::m_recordPlaybackMode = false; +bool ScriptController::m_shouldExposeGCController = false; void ScriptController::setFlags(const char* str, int length) { diff --git a/webkit/port/bindings/v8/ScriptController.h b/webkit/port/bindings/v8/ScriptController.h index 9c29a56..34de5f0 100644 --- a/webkit/port/bindings/v8/ScriptController.h +++ b/webkit/port/bindings/v8/ScriptController.h @@ -218,6 +218,20 @@ public: static bool RecordPlaybackMode() { return m_recordPlaybackMode; } static void setRecordPlaybackMode(bool value) { m_recordPlaybackMode = value; } + // Set/Get ShouldExposeGCController flag. + // Some WebKit layout test need window.GCController.collect() to + // trigger GC, this flag lets the binding code expose + // window.GCController.collect() to the JavaScript code. + // + // GCController.collect() needs V8 engine expose gc() function by passing + // '--expose-gc' flag to the engine. + static bool shouldExposeGCController() { + return m_shouldExposeGCController; + } + static void setShouldExposeGCController(bool value) { + m_shouldExposeGCController = value; + } + void finishedWithEvent(Event*); void setEventHandlerLineno(int lineno); @@ -245,6 +259,7 @@ public: private: static bool m_recordPlaybackMode; + static bool m_shouldExposeGCController; Frame* m_frame; const String* m_sourceURL; diff --git a/webkit/port/bindings/v8/v8_proxy.cpp b/webkit/port/bindings/v8/v8_proxy.cpp index 1176692..17ae8c1 100644 --- a/webkit/port/bindings/v8/v8_proxy.cpp +++ b/webkit/port/bindings/v8/v8_proxy.cpp @@ -1826,8 +1826,23 @@ void V8Proxy::initContextIfNeeded() V8Custom::v8DOMWindowIndexedSecurityCheck, v8::Integer::New(V8ClassIndex::DOMWINDOW)); - // Create a new context. - m_context = v8::Context::New(NULL, global_template, m_global); + if (ScriptController::shouldExposeGCController()) { + v8::RegisterExtension(new v8::Extension("v8/GCController", + "(function v8_GCController() {" + " var v8_gc;" + " if (gc) v8_gc = gc;" + " GCController = new Object();" + " GCController.collect =" + " function() {if (v8_gc) v8_gc(); };" + " })()")); + const char* extension_names[] = { "v8/GCController" }; + v8::ExtensionConfiguration extensions(1, extension_names); + // Create a new context. + m_context = v8::Context::New(&extensions, global_template, m_global); + } else { + m_context = v8::Context::New(NULL, global_template, m_global); + } + if (m_context.IsEmpty()) return; diff --git a/webkit/tools/test_shell/node_leak_test.cc b/webkit/tools/test_shell/node_leak_test.cc index ec5257b..32548c7 100644 --- a/webkit/tools/test_shell/node_leak_test.cc +++ b/webkit/tools/test_shell/node_leak_test.cc @@ -36,6 +36,8 @@ class NodeLeakTest : public TestShellTest { parsed_command_line.GetSwitchValue(test_shell::kJavaScriptFlags); CommandLine::AppendSwitch(&js_flags, L"expose-gc"); webkit_glue::SetJavaScriptFlags(js_flags); + // Expose GCController to JavaScript as well. + webkit_glue::SetShouldExposeGCController(true); std::wstring cache_path = parsed_command_line.GetSwitchValue(test_shell::kCacheDir); diff --git a/webkit/tools/test_shell/test_shell_main.cc b/webkit/tools/test_shell/test_shell_main.cc index a8f1fd4..f975ce3 100644 --- a/webkit/tools/test_shell/test_shell_main.cc +++ b/webkit/tools/test_shell/test_shell_main.cc @@ -293,6 +293,8 @@ int main(int argc, char* argv[]) { // Test shell always exposes the GC. CommandLine::AppendSwitch(&js_flags, L"expose-gc"); webkit_glue::SetJavaScriptFlags(js_flags); + // Also expose GCController to JavaScript. + webkit_glue::SetShouldExposeGCController(true); // load and initialize the stats table. StatsTable *table = new StatsTable(kStatsFile, kStatsFileThreads, kStatsFileCounters); |