Source/WebCore/ChangeLog

 12013-06-20 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 NOBODY (OOPS!).
 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-20 Ryosuke Niwa <rniwa@webkit.org>
235
336 REGRESSION(r145788): mouse drag on canvas shouldn't start selection

Source/WebCore/dom/CurrentScriptIncrementer.h

 1/*
 2 * Copyright (C) 2013 Samsung Electronics. All Rights Reserved.
 3 *
 4 * Redistribution and use in source and binary forms, with or without
 5 * modification, are permitted provided that the following conditions
 6 * are met:
 7 *
 8 * 1. Redistributions of source code must retain the above copyright
 9 * notice, this list of conditions and the following disclaimer.
 10 * 2. Redistributions in binary form must reproduce the above copyright
 11 * notice, this list of conditions and the following disclaimer in the
 12 * documentation and/or other materials provided with the distribution.
 13 * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of
 14 * its contributors may be used to endorse or promote products derived
 15 * from this software without specific prior written permission.
 16 *
 17 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
 18 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 19 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 20 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
 21 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 22 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 23 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
 24 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
 26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 27 */
 28
 29#ifndef CurrentScriptIncrementer_h
 30#define CurrentScriptIncrementer_h
 31
 32#include "Document.h"
 33#include "HTMLScriptElement.h"
 34
 35namespace WebCore {
 36
 37class CurrentScriptIncrementer {
 38 WTF_MAKE_NONCOPYABLE(CurrentScriptIncrementer);
 39public:
 40 CurrentScriptIncrementer(Document* document, Element* element)
 41 : m_document(document)
 42 , m_isHTMLScriptElement(isHTMLScriptElement(element))
 43 {
 44 if (m_isHTMLScriptElement)
 45 m_document->pushCurrentScript(toHTMLScriptElement(element));
 46 }
 47
 48 ~CurrentScriptIncrementer()
 49 {
 50 if (m_isHTMLScriptElement)
 51 m_document->popCurrentScript();
 52 }
 53
 54private:
 55 Document* m_document;
 56 bool m_isHTMLScriptElement;
 57};
 58
 59}
 60
 61#endif

Source/WebCore/dom/Document.cpp

9191#include "HTMLNames.h"
9292#include "HTMLParserIdioms.h"
9393#include "HTMLPlugInElement.h"
 94#include "HTMLScriptElement.h"
9495#include "HTMLStyleElement.h"
9596#include "HTMLTitleElement.h"
9697#include "HTTPParsers.h"

@@KURL Document::openSearchDescriptionURL()
42084209 return KURL();
42094210}
42104211
 4212void Document::pushCurrentScript(PassRefPtr<HTMLScriptElement> newCurrentScript)
 4213{
 4214 ASSERT(newCurrentScript);
 4215 m_currentScriptStack.append(newCurrentScript);
 4216}
 4217
 4218void Document::popCurrentScript()
 4219{
 4220 ASSERT(!m_currentScriptStack.isEmpty());
 4221 m_currentScriptStack.removeLast();
 4222}
 4223
42114224#if ENABLE(XSLT)
42124225
42134226void Document::applyXSLTransform(ProcessingInstruction* pi)

Source/WebCore/dom/Document.h

@@class HTMLHeadElement;
104104class HTMLIFrameElement;
105105class HTMLMapElement;
106106class HTMLNameCollection;
 107class HTMLScriptElement;
107108class HitTestRequest;
108109class HitTestResult;
109110class IntPoint;

@@public:
878879
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);
883888 PassRefPtr<Document> transformSourceDocument() { return m_transformSourceDocument; }

@@private:
14051410
14061411 OwnPtr<ScriptRunner> m_scriptRunner;
14071412
 1413 Vector<RefPtr<HTMLScriptElement> > m_currentScriptStack;
 1414
14081415#if ENABLE(XSLT)
14091416 OwnPtr<TransformSource> m_transformSource;
14101417 RefPtr<Document> m_transformSourceDocument;

Source/WebCore/dom/Document.idl

355355 // Security Policy API: http://dvcs.w3.org/hg/content-security-policy/raw-file/tip/csp-specification.dev.html#script-interfaces
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

Source/WebCore/dom/ScriptElement.cpp

2929#include "CachedResourceRequest.h"
3030#include "ContentSecurityPolicy.h"
3131#include "CrossOriginAccessControl.h"
 32#include "CurrentScriptIncrementer.h"
3233#include "Document.h"
3334#include "DocumentParser.h"
3435#include "Event.h"

@@void ScriptElement::executeScript(const ScriptSourceCode& sourceCode)
307308 if (Frame* frame = document->frame()) {
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.
312315 // Note: This is where the script is compiled and actually executed.

@@String ScriptElement::scriptContent() const
417420
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
428431 return 0;

Source/WebCore/html/HTMLScriptElement.h

2424#ifndef HTMLScriptElement_h
2525#define HTMLScriptElement_h
2626
27 #include "ScriptElement.h"
2827#include "HTMLElement.h"
 28#include "ScriptElement.h"
2929
3030namespace WebCore {
3131

@@private:
6767 virtual PassRefPtr<Element> cloneElementWithoutAttributesAndChildren();
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
7283#endif

Source/WebCore/svg/SVGScriptElement.cpp

3030#include "HTMLNames.h"
3131#include "SVGAnimatedStaticPropertyTearOff.h"
3232#include "SVGElementInstance.h"
33 #include "SVGNames.h"
3433#include "ScriptEventListener.h"
3534
3635namespace WebCore {

Source/WebCore/svg/SVGScriptElement.h

2626#include "SVGAnimatedString.h"
2727#include "SVGElement.h"
2828#include "SVGExternalResourcesRequired.h"
 29#include "SVGNames.h"
2930#include "SVGURIReference.h"
3031#include "ScriptElement.h"
3132

@@private:
8687 Timer<SVGElement> m_svgLoadEventTimer;
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
91103#endif // ENABLE(SVG)

LayoutTests/ChangeLog

 12013-06-20 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 NOBODY (OOPS!).
 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-20 Ryosuke Niwa <rniwa@webkit.org>
224
325 REGRESSION(r151808): fast/xmlhttprequest/xmlhttprequest-recursive-sync-event.html fails

LayoutTests/fast/dom/Document/document-current-script-async-expected.txt

 1Test usage of document.currentScript with async
 2
 3On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
 4
 5
 6PASS successfullyParsed is true
 7
 8TEST COMPLETE
 9

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

 1<!DOCTYPE html>
 2<script src="../../js/resources/js-test-pre.js"></script>
 3<script>
 4
 5jsTestIsAsync = true;
 6
 7description('Test usage of document.currentScript with async')
 8
 9var seenIds = [];
 10
 11function logCurrentScript(id) {
 12 // Don't print anything if pass since the execution order of script[async]
 13 // is non deterministic.
 14 if (id !== document.currentScript.id)
 15 shouldBeEqualToString('document.currentScript.id', id);
 16
 17 seenIds.push(document.currentScript.id);
 18 seenIds.sort();
 19 if (seenIds.join('') === expectedIds)
 20 finishJSTest();
 21}
 22
 23var expectedIds = 'abcdef';
 24
 25</script>
 26<script id="a">
 27logCurrentScript('a');
 28</script>
 29<script id="b" async src="resources/log-current-script-b.js"></script>
 30<script id="c">
 31logCurrentScript('c');
 32</script>
 33<script id="d" async src="resources/log-current-script-d.js"></script>
 34
 35<script id="e">
 36logCurrentScript('e');
 37
 38var script = document.createElement('script');
 39script.id = 'f'
 40script.async = true;
 41script.defer = false;
 42script.src = 'resources/log-current-script-f.js';
 43document.head.appendChild(script);
 44</script>
 45
 46<script src="../../js/resources/js-test-post.js"></script>
 47</body>
 48</html>
 49

LayoutTests/fast/dom/Document/document-current-script-expected.txt

 1Test basic usage of document.currentScript
 2
 3On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
 4
 5
 6<script id="a">
 7<script id="b">
 8<script id="c">
 9<script id="d">
 10<script id="c">
 11<script id="e" src="...">
 12<script id="f">
 13<script id="f">
 14<script id="g" src="...">
 15<script id="h">
 16<script id="h">
 17<script id="i">
 18<script id="j">
 19<script id="i">
 20<script id="defer-1" src="..." defer>
 21<script id="defer-2" src="..." defer>
 22PASS document.currentScript is null
 23PASS successfullyParsed is true
 24
 25TEST COMPLETE
 26

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

 1<!DOCTYPE html>
 2<body>
 3<script src="../../js/resources/js-test-pre.js"></script>
 4<script>
 5
 6jsTestIsAsync = true;
 7
 8description('Test basic usage of document.currentScript')
 9
 10function logCurrentScript() {
 11 var script = document.currentScript
 12 var s = '&lt;script id="' + script.id + '"';
 13 if (script.src)
 14 s += ' src="..."';
 15 if (script.defer)
 16 s += ' defer';
 17 if (script.async)
 18 s += ' async';
 19 s += '>';
 20 debug(s);
 21}
 22
 23</script>
 24<script id="a">
 25logCurrentScript();
 26</script>
 27<script id="b">
 28logCurrentScript();
 29</script>
 30<script id="c">
 31logCurrentScript();
 32document.write('<script id="d">logCurrentScript();<\/script>');
 33logCurrentScript();
 34</script>
 35
 36<script id="defer-1" defer src="resources/log-current-script.js"></script>
 37<script id="e" src="resources/log-current-script.js"></script>
 38
 39
 40<script id="f">
 41logCurrentScript();
 42document.write('<script id="g" src="resources/log-current-script.js"><\/script>');
 43logCurrentScript();
 44</script>
 45
 46<script id="h">
 47logCurrentScript();
 48document.write('<script id="defer-2" defer src="resources/log-current-script.js"><\/script>');
 49logCurrentScript();
 50</script>
 51
 52<script id="i">
 53logCurrentScript();
 54
 55var script = document.createElement('script');
 56script.id = 'j';
 57script.textContent = 'logCurrentScript();';
 58script.async = false;
 59script.defer = false;
 60document.head.appendChild(script);
 61
 62logCurrentScript();
 63</script>
 64
 65<script src="../../js/resources/js-test-post.js"></script>
 66<script>
 67window.onload = function() {
 68 shouldBeNull('document.currentScript');
 69 finishJSTest();
 70};
 71</script>
 72</body>
 73</html>
 74

LayoutTests/fast/dom/Document/resources/log-current-script-b.js

 1logCurrentScript('b');

LayoutTests/fast/dom/Document/resources/log-current-script-d.js

 1logCurrentScript('d');

LayoutTests/fast/dom/Document/resources/log-current-script-f.js

 1logCurrentScript('f');

LayoutTests/fast/dom/Document/resources/log-current-script.js

 1logCurrentScript();