1/* 2 * Copyright (c) 2008, Google Inc. 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 are 6 * met: 7 * 8 * * Redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer. 10 * * Redistributions in binary form must reproduce the above 11 * copyright notice, this list of conditions and the following disclaimer 12 * in the documentation and/or other materials provided with the 13 * distribution. 14 * * Neither the name of Google Inc. nor the names of its 15 * contributors may be used to endorse or promote products derived from 16 * this software without specific prior written permission. 17 * 18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 */ 30 31#ifndef ScriptSourceCode_h 32#define ScriptSourceCode_h 33 34#include "CachedResourceHandle.h" 35#include "CachedScript.h" 36#include "CachedScriptSourceProvider.h" 37#include "KURL.h" 38#include <parser/SourceProvider.h> 39#include <wtf/text/TextPosition.h> 40#include <wtf/RefPtr.h> 41 42namespace WebCore { 43 44class ScriptSourceCode { 45public: 46 ScriptSourceCode(const String& source, const KURL& url = KURL(), const TextPosition& startPosition = TextPosition::minimumPosition()) 47 : m_provider(JSC::StringSourceProvider::create(source, url.isNull() ? String() : url.string(), startPosition)) 48 , m_code(m_provider, startPosition.m_line.oneBasedInt(), startPosition.m_column.oneBasedInt()) 49 , m_url(url) 50 { 51 } 52 53 explicit ScriptSourceCode(CachedScript* cachedScript) 54 : m_provider(CachedScriptSourceProvider::create(cachedScript)) 55 , m_code(m_provider) 56 , m_cachedScript(cachedScript) 57 { 58 } 59 60 bool isEmpty() const { return m_code.length() == 0; } 61 62 const JSC::SourceCode& jsSourceCode() const { return m_code; } 63 64 const String& source() const { return m_provider->source(); } 65 66 int startLine() const { return m_code.firstLine(); } 67 68 CachedScript* cachedScript() const { return m_cachedScript.get(); } 69 70 const KURL& url() const { return m_url; } 71 72private: 73 RefPtr<JSC::SourceProvider> m_provider; 74 75 JSC::SourceCode m_code; 76 77 CachedResourceHandle<CachedScript> m_cachedScript; 78 79 KURL m_url; 80 81}; 82 83} // namespace WebCore 84 85#endif // ScriptSourceCode_h 86