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

Side by Side Diff: webkit/port/bindings/v8/v8_proxy.cpp

Issue 13224: This is a cleaned up fix of Christian's original patch in ... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 12 years 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
« no previous file with comments | « webkit/port/bindings/v8/v8_proxy.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2008, Google Inc. 1 // Copyright (c) 2008, Google Inc.
2 // All rights reserved. 2 // All rights reserved.
3 // 3 //
4 // Redistribution and use in source and binary forms, with or without 4 // Redistribution and use in source and binary forms, with or without
5 // modification, are permitted provided that the following conditions are 5 // modification, are permitted provided that the following conditions are
6 // met: 6 // met:
7 // 7 //
8 // * Redistributions of source code must retain the above copyright 8 // * Redistributions of source code must retain the above copyright
9 // notice, this list of conditions and the following disclaimer. 9 // notice, this list of conditions and the following disclaimer.
10 // * Redistributions in binary form must reproduce the above 10 // * Redistributions in binary form must reproduce the above
(...skipping 1335 matching lines...) Expand 10 before | Expand all | Expand 10 after
1346 result = function->Call(receiver, argc, args); 1346 result = function->Call(receiver, argc, args);
1347 } 1347 }
1348 1348
1349 if (v8::V8::IsDead()) 1349 if (v8::V8::IsDead())
1350 HandleFatalErrorInV8(); 1350 HandleFatalErrorInV8();
1351 1351
1352 return result; 1352 return result;
1353 } 1353 }
1354 1354
1355 1355
1356 v8::Local<v8::Function> V8Proxy::GetConstructor(V8ClassIndex::V8WrapperType t)
1357 {
1358 ASSERT(ContextInitialized());
1359 v8::Local<v8::Value> cached =
1360 m_dom_constructor_cache->Get(v8::Integer::New(V8ClassIndex::ToInt(t)));
1361 if (cached->IsFunction()) {
1362 return v8::Local<v8::Function>::Cast(cached);
1363 }
1364
1365 // Not in cache.
1366 {
1367 v8::Handle<v8::FunctionTemplate> templ = GetTemplate(t);
1368 v8::TryCatch try_catch;
1369 // This might fail if we're running out of stack or memory.
1370 v8::Local<v8::Function> value = templ->GetFunction();
1371 if (value.IsEmpty())
1372 return v8::Local<v8::Function>();
1373 m_dom_constructor_cache->Set(v8::Integer::New(t), value);
1374 // Hotmail fix, see comments in v8_proxy.h above
1375 // m_dom_constructor_cache.
1376 value->Set(v8::String::New("__proto__"), m_object_prototype);
1377 return value;
1378 }
1379 }
1380
1381
1356 v8::Persistent<v8::FunctionTemplate> V8Proxy::GetTemplate( 1382 v8::Persistent<v8::FunctionTemplate> V8Proxy::GetTemplate(
1357 V8ClassIndex::V8WrapperType type) 1383 V8ClassIndex::V8WrapperType type)
1358 { 1384 {
1359 v8::Persistent<v8::FunctionTemplate>* cache_cell = 1385 v8::Persistent<v8::FunctionTemplate>* cache_cell =
1360 V8ClassIndex::GetCache(type); 1386 V8ClassIndex::GetCache(type);
1361 if (!(*cache_cell).IsEmpty()) 1387 if (!(*cache_cell).IsEmpty())
1362 return *cache_cell; 1388 return *cache_cell;
1363 1389
1364 // not found 1390 // not found
1365 FunctionTemplateFactory factory = V8ClassIndex::GetFactory(type); 1391 FunctionTemplateFactory factory = V8ClassIndex::GetFactory(type);
(...skipping 430 matching lines...) Expand 10 before | Expand all | Expand 10 after
1796 if (!m_document.IsEmpty()) { 1822 if (!m_document.IsEmpty()) {
1797 #ifndef NDEBUG 1823 #ifndef NDEBUG
1798 UnregisterGlobalHandle(this, m_document); 1824 UnregisterGlobalHandle(this, m_document);
1799 #endif 1825 #endif
1800 m_document.Dispose(); 1826 m_document.Dispose();
1801 m_document.Clear(); 1827 m_document.Clear();
1802 } 1828 }
1803 } 1829 }
1804 1830
1805 1831
1832 void V8Proxy::DisposeContext() {
1833 ASSERT(!m_context.IsEmpty());
1834 m_context.Dispose();
1835 m_context.Clear();
1836
1837 #ifndef NDEBUG
1838 UnregisterGlobalHandle(this, m_object_prototype);
1839 UnregisterGlobalHandle(this, m_dom_constructor_cache);
1840 #endif
1841
1842 ASSERT(!m_dom_constructor_cache.IsEmpty());
1843 m_dom_constructor_cache.Dispose();
1844 m_dom_constructor_cache.Clear();
1845
1846 ASSERT(!m_object_prototype.IsEmpty());
1847 m_object_prototype.Dispose();
1848 m_object_prototype.Clear();
1849 }
1850
1806 void V8Proxy::clearForClose() 1851 void V8Proxy::clearForClose()
1807 { 1852 {
1808 if (!m_context.IsEmpty()) { 1853 if (!m_context.IsEmpty()) {
1809 v8::HandleScope handle_scope; 1854 v8::HandleScope handle_scope;
1810 1855
1811 ClearDocumentWrapper(); 1856 ClearDocumentWrapper();
1812 m_context.Dispose(); 1857 DisposeContext();
1813 m_context.Clear();
1814 } 1858 }
1815 } 1859 }
1816 1860
1817 1861
1818 void V8Proxy::clearForNavigation() 1862 void V8Proxy::clearForNavigation()
1819 { 1863 {
1820 if (!m_context.IsEmpty()) { 1864 if (!m_context.IsEmpty()) {
1821 v8::HandleScope handle; 1865 v8::HandleScope handle;
1822 ClearDocumentWrapper(); 1866 ClearDocumentWrapper();
1823 1867
1824 v8::Context::Scope context_scope(m_context); 1868 v8::Context::Scope context_scope(m_context);
1825 1869
1826 // Turn on access check on the old DOMWindow wrapper. 1870 // Turn on access check on the old DOMWindow wrapper.
1827 v8::Handle<v8::Object> wrapper = 1871 v8::Handle<v8::Object> wrapper =
1828 LookupDOMWrapper(V8ClassIndex::DOMWINDOW, m_global); 1872 LookupDOMWrapper(V8ClassIndex::DOMWINDOW, m_global);
1829 ASSERT(!wrapper.IsEmpty()); 1873 ASSERT(!wrapper.IsEmpty());
1830 wrapper->TurnOnAccessCheck(); 1874 wrapper->TurnOnAccessCheck();
1831 1875
1832 // Clear all timeouts. 1876 // Clear all timeouts.
1833 DOMWindow* domWindow = 1877 DOMWindow* domWindow =
1834 ToNativeObject<DOMWindow>(V8ClassIndex::DOMWINDOW, wrapper); 1878 ToNativeObject<DOMWindow>(V8ClassIndex::DOMWINDOW, wrapper);
1835 domWindow->clearAllTimeouts(); 1879 domWindow->clearAllTimeouts();
1836 1880
1837 // disconnect all event listeners 1881 // disconnect all event listeners
1838 DisconnectEventListeners(); 1882 DisconnectEventListeners();
1839 1883
1840 // Separate the context from its global object. 1884 // Separate the context from its global object.
1841 m_context->DetachGlobal(); 1885 m_context->DetachGlobal();
1842 1886
1843 m_context.Dispose(); 1887 DisposeContext();
1844 m_context.Clear();
1845 1888
1846 // Reinitialize the context so the global object points to 1889 // Reinitialize the context so the global object points to
1847 // the new DOM window. 1890 // the new DOM window.
1848 initContextIfNeeded(); 1891 initContextIfNeeded();
1849 } 1892 }
1850 } 1893 }
1851 1894
1852 1895
1853 void V8Proxy::SetSecurityToken() { 1896 void V8Proxy::SetSecurityToken() {
1854 Document* document = m_frame->document(); 1897 Document* document = m_frame->document();
(...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after
2089 v8::Context::Scope scope(context); 2132 v8::Context::Scope scope(context);
2090 2133
2091 // Store the first global object created so we can reuse it. 2134 // Store the first global object created so we can reuse it.
2092 if (m_global.IsEmpty()) { 2135 if (m_global.IsEmpty()) {
2093 m_global = v8::Persistent<v8::Object>::New(context->Global()); 2136 m_global = v8::Persistent<v8::Object>::New(context->Global());
2094 #ifndef NDEBUG 2137 #ifndef NDEBUG
2095 RegisterGlobalHandle(PROXY, this, m_global); 2138 RegisterGlobalHandle(PROXY, this, m_global);
2096 #endif 2139 #endif
2097 } 2140 }
2098 2141
2142 v8::Handle<v8::Object> object = v8::Handle<v8::Object>::Cast(
2143 m_global->Get(v8::String::New("Object")));
2144 m_object_prototype = v8::Persistent<v8::Value>::New(
2145 object->Get(v8::String::New("prototype")));
2146 m_dom_constructor_cache = v8::Persistent<v8::Array>::New(
2147 v8::Array::New(V8ClassIndex::WRAPPER_TYPE_COUNT));
2148 #ifndef NDEBUG
2149 RegisterGlobalHandle(PROXY, this, m_object_prototype);
2150 RegisterGlobalHandle(PROXY, this, m_dom_constructor_cache);
2151 #endif
2152
2099 // Create a new JS window object and use it as the prototype for the 2153 // Create a new JS window object and use it as the prototype for the
2100 // shadow global object. 2154 // shadow global object.
2101 v8::Persistent<v8::FunctionTemplate> window_descriptor = 2155 v8::Handle<v8::Function> window_constructor =
2102 GetTemplate(V8ClassIndex::DOMWINDOW); 2156 GetConstructor(V8ClassIndex::DOMWINDOW);
2103 v8::Local<v8::Object> js_window = 2157 v8::Local<v8::Object> js_window =
2104 SafeAllocation::NewInstance(window_descriptor->GetFunction()); 2158 SafeAllocation::NewInstance(window_constructor);
2105 if (js_window.IsEmpty()) 2159 if (js_window.IsEmpty())
2106 return; 2160 return;
2107 2161
2108 DOMWindow* window = m_frame->domWindow(); 2162 DOMWindow* window = m_frame->domWindow();
2109 2163
2110 // Wrap the window. 2164 // Wrap the window.
2111 SetDOMWrapper(js_window, 2165 SetDOMWrapper(js_window,
2112 V8ClassIndex::ToInt(V8ClassIndex::DOMWINDOW), 2166 V8ClassIndex::ToInt(V8ClassIndex::DOMWINDOW),
2113 window); 2167 window);
2114 2168
(...skipping 293 matching lines...) Expand 10 before | Expand all | Expand 10 after
2408 V8ClassIndex::V8WrapperType desc_type, 2462 V8ClassIndex::V8WrapperType desc_type,
2409 V8ClassIndex::V8WrapperType cptr_type, 2463 V8ClassIndex::V8WrapperType cptr_type,
2410 void* imp) 2464 void* imp)
2411 { 2465 {
2412 // Make a special case for document.all 2466 // Make a special case for document.all
2413 if (desc_type == V8ClassIndex::HTMLCOLLECTION && 2467 if (desc_type == V8ClassIndex::HTMLCOLLECTION &&
2414 static_cast<HTMLCollection*>(imp)->type() == HTMLCollection::DocAll) { 2468 static_cast<HTMLCollection*>(imp)->type() == HTMLCollection::DocAll) {
2415 desc_type = V8ClassIndex::UNDETECTABLEHTMLCOLLECTION; 2469 desc_type = V8ClassIndex::UNDETECTABLEHTMLCOLLECTION;
2416 } 2470 }
2417 2471
2418 v8::Persistent<v8::FunctionTemplate> desc = GetTemplate(desc_type); 2472 v8::Local<v8::Function> function;
2419 v8::Local<v8::Function> function = desc->GetFunction(); 2473 V8Proxy* proxy = V8Proxy::retrieve();
2474 if (proxy) {
2475 // Constructor is configured.
2476 function = proxy->GetConstructor(desc_type);
2477 } else {
2478 function = GetTemplate(desc_type)->GetFunction();
Mads Ager (chromium) 2008/12/06 19:03:36 When do we get in the situation that we cannot use
Feng Qian 2008/12/08 05:49:41 The problem is that it may not get proxy because t
2479 }
2420 v8::Local<v8::Object> instance = SafeAllocation::NewInstance(function); 2480 v8::Local<v8::Object> instance = SafeAllocation::NewInstance(function);
2421 if (!instance.IsEmpty()) { 2481 if (!instance.IsEmpty()) {
2422 // Avoid setting the DOM wrapper for failed allocations. 2482 // Avoid setting the DOM wrapper for failed allocations.
2423 SetDOMWrapper(instance, V8ClassIndex::ToInt(cptr_type), imp); 2483 SetDOMWrapper(instance, V8ClassIndex::ToInt(cptr_type), imp);
2424 } 2484 }
2425 return instance; 2485 return instance;
2426 } 2486 }
2427 2487
2428 v8::Handle<v8::Value> V8Proxy::CheckNewLegal(const v8::Arguments& args) 2488 v8::Handle<v8::Value> V8Proxy::CheckNewLegal(const v8::Arguments& args)
2429 { 2489 {
(...skipping 711 matching lines...) Expand 10 before | Expand all | Expand 10 after
3141 v8::Handle<v8::Object> global = context->Global(); 3201 v8::Handle<v8::Object> global = context->Global();
3142 global->Set(v8::String::New(name), instance); 3202 global->Set(v8::String::New(name), instance);
3143 } 3203 }
3144 3204
3145 void V8Proxy::ProcessConsoleMessages() 3205 void V8Proxy::ProcessConsoleMessages()
3146 { 3206 {
3147 ConsoleMessageManager::ProcessDelayedMessages(); 3207 ConsoleMessageManager::ProcessDelayedMessages();
3148 } 3208 }
3149 3209
3150 } // namespace WebCore 3210 } // namespace WebCore
OLDNEW
« no previous file with comments | « webkit/port/bindings/v8/v8_proxy.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698