OLD | NEW |
(Empty) | |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "config.h" |
| 6 #include "bindings/core/v8/ScriptSourceCode.h" |
| 7 |
| 8 namespace blink { |
| 9 |
| 10 ScriptSourceCode::ScriptSourceCode() |
| 11 : m_resource(0) |
| 12 , m_startPosition(TextPosition::minimumPosition()) |
| 13 { |
| 14 } |
| 15 |
| 16 ScriptSourceCode::ScriptSourceCode(const String& source, const KURL& url, const
TextPosition& startPosition) |
| 17 : m_source(source) |
| 18 , m_resource(0) |
| 19 , m_url(url) |
| 20 , m_startPosition(startPosition) |
| 21 { |
| 22 treatNullSourceAsEmpty(); |
| 23 if (!m_url.isEmpty()) |
| 24 m_url.removeFragmentIdentifier(); |
| 25 } |
| 26 |
| 27 ScriptSourceCode::ScriptSourceCode(ScriptResource* resource) |
| 28 : m_source(resource->script()) |
| 29 , m_resource(resource) |
| 30 , m_startPosition(TextPosition::minimumPosition()) |
| 31 { |
| 32 treatNullSourceAsEmpty(); |
| 33 } |
| 34 |
| 35 ScriptSourceCode::ScriptSourceCode(PassRefPtrWillBeRawPtr<ScriptStreamer> stream
er, ScriptResource* resource) |
| 36 : m_source(resource->script()) |
| 37 , m_resource(resource) |
| 38 , m_streamer(streamer) |
| 39 , m_startPosition(TextPosition::minimumPosition()) |
| 40 { |
| 41 treatNullSourceAsEmpty(); |
| 42 } |
| 43 |
| 44 ScriptSourceCode::~ScriptSourceCode() |
| 45 { |
| 46 } |
| 47 |
| 48 void ScriptSourceCode::trace(Visitor* visitor) |
| 49 { |
| 50 visitor->trace(m_streamer); |
| 51 } |
| 52 |
| 53 const KURL& ScriptSourceCode::url() const |
| 54 { |
| 55 if (m_url.isEmpty() && m_resource) { |
| 56 m_url = m_resource->response().url(); |
| 57 if (!m_url.isEmpty()) |
| 58 m_url.removeFragmentIdentifier(); |
| 59 } |
| 60 return m_url; |
| 61 } |
| 62 |
| 63 void ScriptSourceCode::treatNullSourceAsEmpty() |
| 64 { |
| 65 // ScriptSourceCode allows for the representation of the null/not-there-real
ly ScriptSourceCode value. |
| 66 // Encoded by way of a m_source.isNull() being true, with the nullary constr
uctor to be used to |
| 67 // construct such a value. |
| 68 // |
| 69 // Should the other constructors be passed a null string, that is interprete
d as representing |
| 70 // the empty script. Consequently, we need to disambiguate between such null
string occurrences. |
| 71 // Do that by converting the latter case's null strings into empty ones. |
| 72 if (m_source.isNull()) |
| 73 m_source = ""; |
| 74 } |
| 75 |
| 76 } // namespace blink |
OLD | NEW |