JavaScriptCore:
authormjs@apple.com <mjs@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 27 May 2008 02:10:23 +0000 (02:10 +0000)
committermjs@apple.com <mjs@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 27 May 2008 02:10:23 +0000 (02:10 +0000)
2008-05-26  Maciej Stachowiak  <mjs@apple.com>

        Reviewed by Anders.

        - make addStaticGlobals protected instead of private so subclasses can use it

        * JavaScriptCore.exp:
        * kjs/JSGlobalObject.h:

WebCore:

2008-05-25  Maciej Stachowiak  <mjs@apple.com>

        Reviewed by Anders.

        - bind the window's "document" and "window" properties to static slots
        1.7% speedup on Acid3 test 26

        Only the "document" part matters for Acid3, but since I was doing
        this anyway, "window" also seemed like a good one to optimize.

        * bindings/js/JSDOMWindowBase.cpp:
        (WebCore::JSDOMWindowBase::JSDOMWindowBase): Allocate variable
        slots for document and window; but just put null in the document
        slot for now.
        (WebCore::JSDOMWindowBase::updateDocument): Fill in the document
        slot.
        (WebCore::JSDOMWindowBase::~JSDOMWindowBase): Make our shell stop
        tracking us.
        * bindings/js/JSDOMWindowBase.h:
        * bindings/js/JSDOMWindowShell.cpp:
        (WebCore::JSDOMWindowShell::JSDOMWindowShell): Allocate HashSet
        for our still-not-dead inner windows.
        (WebCore::JSDOMWindowShell::updateDocument): Update all our
        inner windows ever (to make sure the update to the document
        property shows up everywhere).
        * bindings/js/JSDOMWindowShell.h:
        (WebCore::JSDOMWindowShell::setWindow): Update our hash.
        (WebCore::JSDOMWindowShell::clearFormerWindow): Ditto.
        * bindings/js/JSDocumentCustom.cpp:
        (WebCore::toJS): Don't set self as a property map property of
        the window, this is no longer necessary.
        * bindings/js/kjs_proxy.cpp:
        (WebCore::KJSProxy::initScript): Update document for the
        newly created window.
        * bindings/js/kjs_proxy.h:
        * page/Frame.cpp:
        (WebCore::Frame::setDocument): If the document is not null,
        update our window.

LayoutTests:

2008-05-26  Maciej Stachowiak  <mjs@apple.com>

        Reviewed by Anders.

        - update test result for document/window being allocated to var slots

        * http/tests/security/cross-frame-access-put-expected.txt:

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@34143 268f45cc-cd09-0410-ab3c-d52691b4dbfc

14 files changed:
JavaScriptCore/ChangeLog
JavaScriptCore/JavaScriptCore.exp
JavaScriptCore/kjs/JSGlobalObject.h
LayoutTests/ChangeLog
LayoutTests/http/tests/security/cross-frame-access-put-expected.txt
WebCore/ChangeLog
WebCore/bindings/js/JSDOMWindowBase.cpp
WebCore/bindings/js/JSDOMWindowBase.h
WebCore/bindings/js/JSDOMWindowShell.cpp
WebCore/bindings/js/JSDOMWindowShell.h
WebCore/bindings/js/JSDocumentCustom.cpp
WebCore/bindings/js/kjs_proxy.cpp
WebCore/bindings/js/kjs_proxy.h
WebCore/page/Frame.cpp

index 01e9a6cf2391224d3ae6bebe4ad2d6e0c1e3e697..97eb0ea11b8dfa45a2d02f54274234379e06ca57 100644 (file)
@@ -1,3 +1,12 @@
+2008-05-26  Maciej Stachowiak  <mjs@apple.com>
+
+        Reviewed by Anders.
+        
+        - make addStaticGlobals protected instead of private so subclasses can use it
+
+        * JavaScriptCore.exp:
+        * kjs/JSGlobalObject.h:
+
 2008-05-26  Geoffrey Garen  <ggaren@apple.com>
 
         Reviewed by Darin Adler.
index 62c4da181a135a5e9fa847fe75d62338635b84f7..2acf16027bf534f90ed48619b7baa32b892eabaa 100644 (file)
@@ -109,6 +109,7 @@ __ZN3KJS11PropertyMap5clearEv
 __ZN3KJS11PropertyMapD1Ev
 __ZN3KJS12DateInstance4infoE
 __ZN3KJS12PropertySlot15undefinedGetterEPNS_9ExecStateEPNS_8JSObjectERKNS_10IdentifierERKS0_
+__ZN3KJS12RegisterFile14addGlobalSlotsEm
 __ZN3KJS13ArrayInstance4infoE
 __ZN3KJS13CodeGenerator21setDumpsGeneratedCodeEb
 __ZN3KJS13StatementNode6setLocEii
index 3fa29c89452627a99d49176bb1f3dd4f4f825ed4..bd96c8fa4f04048183a6f2bdac49cd80e12a94c5 100644 (file)
@@ -264,11 +264,11 @@ namespace KJS {
         // Initialize and/or retrieve per-thread hash tables - use perThreadData() for faster access instead.
         static ThreadClassInfoHashTables* threadClassInfoHashTables();
 
-    private:
         void init(JSObject* thisValue);
         
         JSGlobalObjectData* d() const { return static_cast<JSGlobalObjectData*>(JSVariableObject::d); }
 
+    protected:
         struct GlobalPropertyInfo {
             GlobalPropertyInfo(const Identifier& i, JSValue* v, unsigned a)
                 : identifier(i)
@@ -283,6 +283,7 @@ namespace KJS {
         };
         void addStaticGlobals(GlobalPropertyInfo*, int count);
 
+    private:
         bool checkTimeout();
         void resetTimeoutCheck();
 
index b06bdd31b53abdea8be41a880fb1d8c7f47cade9..ce3767dacef486c63b643e5498195449006044ba 100644 (file)
@@ -1,3 +1,11 @@
+2008-05-26  Maciej Stachowiak  <mjs@apple.com>
+
+        Reviewed by Anders.
+        
+        - update test result for document/window being allocated to var slots
+
+        * http/tests/security/cross-frame-access-put-expected.txt:
+
 2008-05-26  James Ren  <jamesjren@gmail.com>
 
         Reviewed by Sam Weinig, landed by Collin Jackson.
index 45367d16aa7379339ff3a217dc97cf4f744a69cc..6f481acb71f40a9cd6d1862bf58016f8481168e8 100644 (file)
@@ -364,6 +364,8 @@ CONSOLE MESSAGE: line 1: Unsafe JavaScript attempt to access frame with URL http
 
 CONSOLE MESSAGE: line 1: Unsafe JavaScript attempt to access frame with URL http://localhost:8000/security/resources/cross-frame-iframe-for-put-test.html from frame with URL http://127.0.0.1:8000/security/cross-frame-access-put.html. Domains, protocols and ports must match.
 
+CONSOLE MESSAGE: line 1: Unsafe JavaScript attempt to access frame with URL http://localhost:8000/security/resources/cross-frame-iframe-for-put-test.html from frame with URL http://127.0.0.1:8000/security/cross-frame-access-put.html. Domains, protocols and ports must match.
+
 ALERT: PASS: window.Attr should be '[object AttrConstructor]' and is.
 ALERT: PASS: window.CDATASection should be '[object CDATASectionConstructor]' and is.
 ALERT: PASS: window.CharacterData should be '[object CharacterDataConstructor]' and is.
index 646af37e7f74d890dc8c3afc2a382e03875e133e..a885c6e95b0148fe45c90ec06f02a09277ffbbaf 100644 (file)
@@ -1,3 +1,42 @@
+2008-05-25  Maciej Stachowiak  <mjs@apple.com>
+
+        Reviewed by Anders.
+
+        - bind the window's "document" and "window" properties to static slots
+        1.7% speedup on Acid3 test 26
+        
+        Only the "document" part matters for Acid3, but since I was doing
+        this anyway, "window" also seemed like a good one to optimize.
+
+        * bindings/js/JSDOMWindowBase.cpp:
+        (WebCore::JSDOMWindowBase::JSDOMWindowBase): Allocate variable
+        slots for document and window; but just put null in the document
+        slot for now.
+        (WebCore::JSDOMWindowBase::updateDocument): Fill in the document
+        slot.        
+        (WebCore::JSDOMWindowBase::~JSDOMWindowBase): Make our shell stop
+        tracking us.
+        * bindings/js/JSDOMWindowBase.h:
+        * bindings/js/JSDOMWindowShell.cpp:
+        (WebCore::JSDOMWindowShell::JSDOMWindowShell): Allocate HashSet
+        for our still-not-dead inner windows.
+        (WebCore::JSDOMWindowShell::updateDocument): Update all our
+        inner windows ever (to make sure the update to the document
+        property shows up everywhere).
+        * bindings/js/JSDOMWindowShell.h:
+        (WebCore::JSDOMWindowShell::setWindow): Update our hash.
+        (WebCore::JSDOMWindowShell::clearFormerWindow): Ditto.
+        * bindings/js/JSDocumentCustom.cpp:
+        (WebCore::toJS): Don't set self as a property map property of
+        the window, this is no longer necessary.
+        * bindings/js/kjs_proxy.cpp:
+        (WebCore::KJSProxy::initScript): Update document for the
+        newly created window.
+        * bindings/js/kjs_proxy.h:
+        * page/Frame.cpp:
+        (WebCore::Frame::setDocument): If the document is not null,
+        update our window.
+
 2008-05-26  Anders Carlsson  <andersca@apple.com>
 
         Reviewed by Sam.
index 9b1f86c846650bccd39c32fce25f292d2930d12d..fa9e925d1dcc7cd50038ceabd21c864218583431 100644 (file)
@@ -184,10 +184,26 @@ JSDOMWindowBase::JSDOMWindowBase(JSObject* prototype, DOMWindow* window, JSDOMWi
 
     // Time in milliseconds before the script timeout handler kicks in.
     setTimeoutTime(10000);
+
+    GlobalPropertyInfo staticGlobals[] = {
+        GlobalPropertyInfo("document", jsNull(), DontDelete | ReadOnly),
+        GlobalPropertyInfo("window", d->m_shell, DontDelete | ReadOnly)
+    };
+    
+    addStaticGlobals(staticGlobals, sizeof(staticGlobals) / sizeof(GlobalPropertyInfo));
+}
+
+void JSDOMWindowBase::updateDocument()
+{
+    ASSERT(m_impl->document());
+    ExecState* exec = globalExec();
+    symbolTablePutWithAttributes("document", toJS(exec, m_impl->document()), DontDelete | ReadOnly);
 }
 
 JSDOMWindowBase::~JSDOMWindowBase()
 {
+    d->m_shell->clearFormerWindow(asJSDOMWindow(this));
+
     clearAllTimeouts();
 
     // Clear any backpointers to the window
index ef193f5a3f113c034026ea0c7a26f799666692e7..aac9d9a9f6a039cd12d5ff1bb4d4c810a0eb0ba8 100644 (file)
@@ -54,6 +54,8 @@ namespace WebCore {
     public:
         virtual ~JSDOMWindowBase();
 
+        void updateDocument();
+
         DOMWindow* impl() const { return m_impl.get(); }
 
         void disconnectFrame();
index 9d1b6f1cbfa7739dcc12a8eb526469f9ca5258b2..00220ba14e22af30a0f930ac6d0ea21416a53c09 100644 (file)
@@ -44,6 +44,7 @@ const ClassInfo JSDOMWindowShell::s_info = { "JSDOMWindowShell", 0, 0, 0 };
 JSDOMWindowShell::JSDOMWindowShell(DOMWindow* domWindow)
     : Base(jsNull())
     , m_window(0)
+    , m_liveFormerWindows(new HashSet<JSDOMWindow*>)
 {
     m_window = new JSDOMWindow(domWindow, this);
     setPrototype(m_window->prototype());
@@ -143,6 +144,15 @@ void JSDOMWindowShell::clear()
     m_window->clear();
 }
 
+
+void JSDOMWindowShell::updateDocument()
+{
+    m_window->updateDocument();
+    HashSet<JSDOMWindow*>::iterator end = m_liveFormerWindows->end();
+    for (HashSet<JSDOMWindow*>::iterator it = m_liveFormerWindows->begin(); it != end; ++it)
+        (*it)->updateDocument();
+}
+
 // ----
 // Conversion methods
 // ----
index 398001006256528e24b0c9d46090b7a5b21ea906..57c272ce792bbfb43c6bb021ebff5d5fc26413a7 100644 (file)
@@ -47,6 +47,7 @@ namespace WebCore {
         void setWindow(JSDOMWindow* window)
         {
             ASSERT_ARG(window, window);
+            m_liveFormerWindows->add(m_window);
             m_window = window;
             setPrototype(window->prototype());
         }
@@ -75,9 +76,13 @@ namespace WebCore {
         DOMWindow* impl() const;
         void disconnectFrame();
         void clear();
+        void updateDocument();
+
+        void clearFormerWindow(JSDOMWindow* window) { m_liveFormerWindows->remove(window); }
 
     private:
         JSDOMWindow* m_window;
+        HashSet<JSDOMWindow*>* m_liveFormerWindows;
     };
 
     KJS::JSValue* toJS(KJS::ExecState*, Frame*);
index bbfe5eb65be4d3f8973f01890cd66f075b99ecfa..e6dfa932fbc723dd712db53e0829766f3c4e069b 100644 (file)
@@ -92,9 +92,7 @@ JSValue* toJS(ExecState* exec, Document* doc)
 
     // Make sure the document is kept around by the window object, and works right with the
     // back/forward cache.
-    if (doc->frame())
-        toJSDOMWindowShell(doc->frame())->window()->putDirect("document", ret, DontDelete|ReadOnly);
-    else {
+    if (!doc->frame()) {
         size_t nodeCount = 0;
         for (Node* n = doc; n; n = n->traverseNextNode())
             nodeCount++;
index 4fda02e8df872700c13bf71a0218d2e3733a7cb1..bb11460b522ae2694ad7b087b6921bc6bd686862 100644 (file)
@@ -155,6 +155,7 @@ void KJSProxy::initScript()
     JSLock lock;
 
     m_windowShell = new JSDOMWindowShell(m_frame->domWindow());
+    m_windowShell->updateDocument();
 
     if (Page* page = m_frame->page()) {
         attachDebugger(page->debugger());
@@ -164,15 +165,6 @@ void KJSProxy::initScript()
     m_frame->loader()->dispatchWindowObjectAvailable();
 }
 
-void KJSProxy::clearDocumentWrapper() 
-{
-    if (!m_windowShell)
-        return;
-
-    JSLock lock;
-    m_windowShell->window()->removeDirect("document");
-}
-
 bool KJSProxy::processingUserGesture() const
 {
     if (!m_windowShell)
index 63a613489c37072f9ce4b2f6aaf7af8527084468..b74b196036247a43903f3082898f7a5bbab656ac 100644 (file)
@@ -67,8 +67,6 @@ public:
     void finishedWithEvent(Event*);
     void setEventHandlerLineno(int lineno) { m_handlerLineno = lineno; }
 
-    void clearDocumentWrapper();
-
     void setProcessingTimerCallback(bool b) { m_processingTimerCallback = b; }
     bool processingUserGesture() const;
 
index 40a78863d2cf3104c24f84d7bcd62d9c6563e964..1311121291d1d6932733b486355ea66e9729f8e6 100644 (file)
@@ -258,8 +258,11 @@ void Frame::setDocument(PassRefPtr<Document> newDoc)
     if (d->m_doc && !d->m_doc->attached())
         d->m_doc->attach();
 
-    // Remove the cached 'document' property, which is now stale.
-    d->m_jscript.clearDocumentWrapper();
+    // Update the cached 'document' property, which is now stale.
+    if (d->m_doc && d->m_jscript.haveWindowShell()) {
+        JSLock lock;
+        d->m_jscript.windowShell()->updateDocument();
+    }
 }
 
 Settings* Frame::settings() const