Changeset 151951 in webkit


Ignore:
Timestamp:
Jun 24, 2013 7:38:54 PM (11 years ago)
Author:
kangil.han@samsung.com
Message:

Add support for document.currentScript
https://bugs.webkit.org/show_bug.cgi?id=104221

Reviewed by Ryosuke Niwa.

Merge http://src.chromium.org/viewvc/blink?view=revision&revision=152230
document.currentScript reflects the script that is currently being executed.

Merge http://src.chromium.org/viewvc/blink?view=revision&revision=152237
Following up patch for code clean-up.

Source/WebCore:

Tests: fast/dom/Document/document-current-script-async.html

fast/dom/Document/document-current-script.html

  • dom/Document.cpp:

(WebCore::Document::pushCurrentScript):
(WebCore::Document::popCurrentScript):

  • dom/Document.h:

(WebCore::Document::currentScript):

  • dom/Document.idl:
  • dom/ScriptElement.cpp:

(WebCore::isHTMLScriptElement):
(WebCore::isSVGScriptElement):
(WebCore::ScriptElement::executeScript):
(WebCore::toScriptElementIfPossible):

  • html/HTMLScriptElement.h:

(WebCore::toHTMLScriptElement):

  • svg/SVGScriptElement.cpp:
  • svg/SVGScriptElement.h:

(WebCore::toSVGScriptElement):

LayoutTests:

  • fast/dom/Document/document-current-script-async-expected.txt: Added.
  • fast/dom/Document/document-current-script-async.html: Added.
  • fast/dom/Document/document-current-script-expected.txt: Added.
  • fast/dom/Document/document-current-script.html: Added.
  • fast/dom/Document/resources/log-current-script-b.js: Added.
  • fast/dom/Document/resources/log-current-script-d.js: Added.
  • fast/dom/Document/resources/log-current-script-f.js: Added.
  • fast/dom/Document/resources/log-current-script.js: Added.
Location:
trunk
Files:
9 added
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r151942 r151951  
     12013-06-24  Kangil Han  <kangil.han@samsung.com>
     2
     3        Add support for document.currentScript
     4        https://bugs.webkit.org/show_bug.cgi?id=104221
     5
     6        Reviewed by Ryosuke Niwa.
     7
     8        Merge http://src.chromium.org/viewvc/blink?view=revision&revision=152230
     9        document.currentScript reflects the script that is currently being executed.
     10
     11        Merge http://src.chromium.org/viewvc/blink?view=revision&revision=152237
     12        Following up patch for code clean-up.
     13
     14        * fast/dom/Document/document-current-script-async-expected.txt: Added.
     15        * fast/dom/Document/document-current-script-async.html: Added.
     16        * fast/dom/Document/document-current-script-expected.txt: Added.
     17        * fast/dom/Document/document-current-script.html: Added.
     18        * fast/dom/Document/resources/log-current-script-b.js: Added.
     19        * fast/dom/Document/resources/log-current-script-d.js: Added.
     20        * fast/dom/Document/resources/log-current-script-f.js: Added.
     21        * fast/dom/Document/resources/log-current-script.js: Added.
     22
    1232013-06-24  Jer Noble  <jer.noble@apple.com>
    224
  • trunk/Source/WebCore/ChangeLog

    r151949 r151951  
     12013-06-24  Kangil Han  <kangil.han@samsung.com>
     2
     3        Add support for document.currentScript
     4        https://bugs.webkit.org/show_bug.cgi?id=104221
     5
     6        Reviewed by Ryosuke Niwa.
     7
     8        Merge http://src.chromium.org/viewvc/blink?view=revision&revision=152230
     9        document.currentScript reflects the script that is currently being executed.
     10
     11        Merge http://src.chromium.org/viewvc/blink?view=revision&revision=152237
     12        Following up patch for code clean-up.
     13
     14        Tests: fast/dom/Document/document-current-script-async.html
     15               fast/dom/Document/document-current-script.html
     16
     17        * dom/Document.cpp:
     18        (WebCore::Document::pushCurrentScript):
     19        (WebCore::Document::popCurrentScript):
     20        * dom/Document.h:
     21        (WebCore::Document::currentScript):
     22        * dom/Document.idl:
     23        * dom/ScriptElement.cpp:
     24        (WebCore::isHTMLScriptElement):
     25        (WebCore::isSVGScriptElement):
     26        (WebCore::ScriptElement::executeScript):
     27        (WebCore::toScriptElementIfPossible):
     28        * html/HTMLScriptElement.h:
     29        (WebCore::toHTMLScriptElement):
     30        * svg/SVGScriptElement.cpp:
     31        * svg/SVGScriptElement.h:
     32        (WebCore::toSVGScriptElement):
     33
    1342013-06-24  Kangil Han  <kangil.han@samsung.com>
    235
  • trunk/Source/WebCore/dom/Document.cpp

    r151926 r151951  
    9292#include "HTMLParserIdioms.h"
    9393#include "HTMLPlugInElement.h"
     94#include "HTMLScriptElement.h"
    9495#include "HTMLStyleElement.h"
    9596#include "HTMLTitleElement.h"
     
    42204221}
    42214222
     4223void Document::pushCurrentScript(PassRefPtr<HTMLScriptElement> newCurrentScript)
     4224{
     4225    ASSERT(newCurrentScript);
     4226    m_currentScriptStack.append(newCurrentScript);
     4227}
     4228
     4229void Document::popCurrentScript()
     4230{
     4231    ASSERT(!m_currentScriptStack.isEmpty());
     4232    m_currentScriptStack.removeLast();
     4233}
     4234
    42224235#if ENABLE(XSLT)
    42234236
  • trunk/Source/WebCore/dom/Document.h

    r151466 r151951  
    105105class HTMLMapElement;
    106106class HTMLNameCollection;
     107class HTMLScriptElement;
    107108class HitTestRequest;
    108109class HitTestResult;
     
    879880    ScriptRunner* scriptRunner() { return m_scriptRunner.get(); }
    880881
     882    HTMLScriptElement* currentScript() const { return !m_currentScriptStack.isEmpty() ? m_currentScriptStack.last().get() : 0; }
     883    void pushCurrentScript(PassRefPtr<HTMLScriptElement>);
     884    void popCurrentScript();
     885
    881886#if ENABLE(XSLT)
    882887    void applyXSLTransform(ProcessingInstruction* pi);
     
    14061411    OwnPtr<ScriptRunner> m_scriptRunner;
    14071412
     1413    Vector<RefPtr<HTMLScriptElement> > m_currentScriptStack;
     1414
    14081415#if ENABLE(XSLT)
    14091416    OwnPtr<TransformSource> m_transformSource;
  • trunk/Source/WebCore/dom/Document.idl

    r151714 r151951  
    356356    [Conditional=CSP_NEXT] readonly attribute DOMSecurityPolicy securityPolicy;
    357357
     358    // currentscript API: http://www.whatwg.org/specs/web-apps/current-work/multipage/dom.html#dom-document-currentscript
     359    readonly attribute HTMLScriptElement currentScript;
    358360};
    359361
  • trunk/Source/WebCore/dom/ScriptElement.cpp

    r150957 r151951  
    3030#include "ContentSecurityPolicy.h"
    3131#include "CrossOriginAccessControl.h"
     32#include "CurrentScriptIncrementer.h"
    3233#include "Document.h"
    3334#include "DocumentParser.h"
     
    308309        {
    309310            IgnoreDestructiveWriteCountIncrementer ignoreDesctructiveWriteCountIncrementer(m_isExternalScript ? document.get() : 0);
     311            CurrentScriptIncrementer currentScriptIncrementer(document.get(), m_element);
     312
    310313            // Create a script from the script element node, using the script
    311314            // block's source and the script block's type.
     
    418421ScriptElement* toScriptElementIfPossible(Element* element)
    419422{
    420     if (element->isHTMLElement() && element->hasTagName(HTMLNames::scriptTag))
    421         return static_cast<HTMLScriptElement*>(element);
     423    if (isHTMLScriptElement(element))
     424        return toHTMLScriptElement(element);
    422425
    423426#if ENABLE(SVG)
    424     if (element->isSVGElement() && element->hasTagName(SVGNames::scriptTag))
    425         return static_cast<SVGScriptElement*>(element);
     427    if (isSVGScriptElement(element))
     428        return toSVGScriptElement(element);
    426429#endif
    427430
  • trunk/Source/WebCore/html/HTMLScriptElement.h

    r149960 r151951  
    2525#define HTMLScriptElement_h
    2626
     27#include "HTMLElement.h"
    2728#include "ScriptElement.h"
    28 #include "HTMLElement.h"
    2929
    3030namespace WebCore {
     
    6868};
    6969
     70inline bool isHTMLScriptElement(Node* node)
     71{
     72    return node->hasTagName(HTMLNames::scriptTag);
     73}
     74
     75inline HTMLScriptElement* toHTMLScriptElement(Node* node)
     76{
     77    ASSERT_WITH_SECURITY_IMPLICATION(!node || node->hasTagName(HTMLNames::scriptTag));
     78    return static_cast<HTMLScriptElement*>(node);
     79}
     80
    7081} //namespace
    7182
  • trunk/Source/WebCore/svg/SVGScriptElement.cpp

    r151800 r151951  
    3131#include "SVGAnimatedStaticPropertyTearOff.h"
    3232#include "SVGElementInstance.h"
    33 #include "SVGNames.h"
    3433#include "ScriptEventListener.h"
    3534
  • trunk/Source/WebCore/svg/SVGScriptElement.h

    r149960 r151951  
    2727#include "SVGElement.h"
    2828#include "SVGExternalResourcesRequired.h"
     29#include "SVGNames.h"
    2930#include "SVGURIReference.h"
    3031#include "ScriptElement.h"
     
    8788};
    8889
     90inline bool isSVGScriptElement(Node* node)
     91{
     92    return node->hasTagName(SVGNames::scriptTag);
     93}
     94
     95inline SVGScriptElement* toSVGScriptElement(Node* node)
     96{
     97    ASSERT_WITH_SECURITY_IMPLICATION(!node || node->hasTagName(SVGNames::scriptTag));
     98    return static_cast<SVGScriptElement*>(node);
     99}
     100
    89101} // namespace WebCore
    90102
Note: See TracChangeset for help on using the changeset viewer.