| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2010 Google Inc. All rights reserved. | 2 * Copyright (C) 2010 Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
| 6 * are met: | 6 * are met: |
| 7 * | 7 * |
| 8 * 1. Redistributions of source code must retain the above copyright | 8 * 1. Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * 2. Redistributions in binary form must reproduce the above copyright | 10 * 2. Redistributions in binary form must reproduce the above copyright |
| 11 * notice, this list of conditions and the following disclaimer in the | 11 * notice, this list of conditions and the following disclaimer in the |
| 12 * documentation and/or other materials provided with the distribution. | 12 * documentation and/or other materials provided with the distribution. |
| 13 * | 13 * |
| 14 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY | 14 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY |
| 15 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | 15 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
| 16 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | 16 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
| 17 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY | 17 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY |
| 18 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | 18 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
| 19 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | 19 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
| 20 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | 20 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND |
| 21 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 21 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
| 23 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 23 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 24 */ | 24 */ |
| 25 | 25 |
| 26 #include "bindings/core/v8/Dictionary.h" | 26 #include "bindings/core/v8/Dictionary.h" |
| 27 | 27 |
| 28 #include "bindings/core/v8/ArrayValue.h" | 28 #include "bindings/core/v8/ArrayValue.h" |
| 29 #include "bindings/core/v8/ExceptionMessages.h" | 29 #include "bindings/core/v8/ExceptionMessages.h" |
| 30 #include "bindings/core/v8/ExceptionState.h" | |
| 31 #include "bindings/core/v8/ScriptController.h" | 30 #include "bindings/core/v8/ScriptController.h" |
| 32 #include "bindings/core/v8/V8ArrayBufferView.h" | 31 #include "bindings/core/v8/V8ArrayBufferView.h" |
| 33 #include "bindings/core/v8/V8Binding.h" | 32 #include "bindings/core/v8/V8Binding.h" |
| 34 #include "bindings/core/v8/V8DOMError.h" | 33 #include "bindings/core/v8/V8DOMError.h" |
| 35 #include "bindings/core/v8/V8Element.h" | 34 #include "bindings/core/v8/V8Element.h" |
| 36 #include "bindings/core/v8/V8EventTarget.h" | 35 #include "bindings/core/v8/V8EventTarget.h" |
| 37 #include "bindings/core/v8/V8MessagePort.h" | 36 #include "bindings/core/v8/V8MessagePort.h" |
| 38 #include "bindings/core/v8/V8TextTrack.h" | 37 #include "bindings/core/v8/V8TextTrack.h" |
| 39 #include "bindings/core/v8/V8VoidCallback.h" | 38 #include "bindings/core/v8/V8VoidCallback.h" |
| 40 #include "bindings/core/v8/V8Window.h" | 39 #include "bindings/core/v8/V8Window.h" |
| 41 #include "core/html/track/TrackBase.h" | 40 #include "core/html/track/TrackBase.h" |
| 42 #include "wtf/MathExtras.h" | 41 #include "wtf/MathExtras.h" |
| 43 | 42 |
| 44 namespace blink { | 43 namespace blink { |
| 45 | 44 |
| 46 static ExceptionState& emptyExceptionState() | |
| 47 { | |
| 48 DEFINE_THREAD_SAFE_STATIC_LOCAL(WTF::ThreadSpecific<NonThrowableExceptionSta
te>, exceptionState, new ThreadSpecific<NonThrowableExceptionState>); | |
| 49 return *exceptionState; | |
| 50 } | |
| 51 | |
| 52 Dictionary::Dictionary() | |
| 53 : m_isolate(0) | |
| 54 , m_exceptionState(&emptyExceptionState()) | |
| 55 { | |
| 56 } | |
| 57 | |
| 58 Dictionary::Dictionary(const v8::Local<v8::Value>& options, v8::Isolate* isolate
, ExceptionState& exceptionState) | |
| 59 : m_options(options) | |
| 60 , m_isolate(isolate) | |
| 61 , m_exceptionState(&exceptionState) | |
| 62 { | |
| 63 ASSERT(m_isolate); | |
| 64 ASSERT(m_exceptionState); | |
| 65 #if ENABLE(ASSERT) | |
| 66 m_exceptionState->getOnStackObjectChecker().add(this); | |
| 67 #endif | |
| 68 } | |
| 69 | |
| 70 Dictionary::~Dictionary() | |
| 71 { | |
| 72 #if ENABLE(ASSERT) | |
| 73 if (m_exceptionState) | |
| 74 m_exceptionState->getOnStackObjectChecker().remove(this); | |
| 75 #endif | |
| 76 } | |
| 77 | |
| 78 Dictionary& Dictionary::operator=(const Dictionary& optionsObject) | 45 Dictionary& Dictionary::operator=(const Dictionary& optionsObject) |
| 79 { | 46 { |
| 80 m_options = optionsObject.m_options; | 47 m_options = optionsObject.m_options; |
| 81 m_isolate = optionsObject.m_isolate; | 48 m_isolate = optionsObject.m_isolate; |
| 82 #if ENABLE(ASSERT) | |
| 83 if (m_exceptionState) | |
| 84 m_exceptionState->getOnStackObjectChecker().remove(this); | |
| 85 #endif | |
| 86 m_exceptionState = optionsObject.m_exceptionState; | |
| 87 #if ENABLE(ASSERT) | |
| 88 if (m_exceptionState) | |
| 89 m_exceptionState->getOnStackObjectChecker().add(this); | |
| 90 #endif | |
| 91 return *this; | 49 return *this; |
| 92 } | 50 } |
| 93 | 51 |
| 94 bool Dictionary::isObject() const | 52 bool Dictionary::isObject() const |
| 95 { | 53 { |
| 96 return !isUndefinedOrNull() && m_options->IsObject(); | 54 return !isUndefinedOrNull() && m_options->IsObject(); |
| 97 } | 55 } |
| 98 | 56 |
| 99 bool Dictionary::isUndefinedOrNull() const | 57 bool Dictionary::isUndefinedOrNull() const |
| 100 { | 58 { |
| 101 if (m_options.IsEmpty()) | 59 if (m_options.IsEmpty()) |
| 102 return true; | 60 return true; |
| 103 return blink::isUndefinedOrNull(m_options); | 61 return blink::isUndefinedOrNull(m_options); |
| 104 } | 62 } |
| 105 | 63 |
| 106 bool Dictionary::hasProperty(const String& key) const | 64 bool Dictionary::hasProperty(const String& key) const |
| 107 { | 65 { |
| 108 v8::Local<v8::Object> object; | 66 v8::Local<v8::Object> object; |
| 109 if (!toObject(object)) | 67 if (!toObject(object)) |
| 110 return false; | 68 return false; |
| 111 | 69 |
| 112 ASSERT(m_isolate); | 70 DCHECK(m_isolate); |
| 113 ASSERT(m_isolate == v8::Isolate::GetCurrent()); | 71 DCHECK_EQ(m_isolate, v8::Isolate::GetCurrent()); |
| 114 ASSERT(m_exceptionState); | |
| 115 v8::Local<v8::String> v8Key = v8String(m_isolate, key); | 72 v8::Local<v8::String> v8Key = v8String(m_isolate, key); |
| 116 return v8CallBoolean(object->Has(v8Context(), v8Key)); | 73 return v8CallBoolean(object->Has(v8Context(), v8Key)); |
| 117 } | 74 } |
| 118 | 75 |
| 119 bool Dictionary::getKey(const String& key, v8::Local<v8::Value>& value) const | 76 bool Dictionary::getKey(const String& key, v8::Local<v8::Value>& value) const |
| 120 { | 77 { |
| 121 if (!m_isolate) | 78 if (!m_isolate) |
| 122 return false; | 79 return false; |
| 123 | 80 |
| 124 return getInternal(v8String(m_isolate, key), value); | 81 return getInternal(v8String(m_isolate, key), value); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 145 | 102 |
| 146 bool Dictionary::get(const String& key, Dictionary& value) const | 103 bool Dictionary::get(const String& key, Dictionary& value) const |
| 147 { | 104 { |
| 148 v8::Local<v8::Value> v8Value; | 105 v8::Local<v8::Value> v8Value; |
| 149 if (!getKey(key, v8Value)) | 106 if (!getKey(key, v8Value)) |
| 150 return false; | 107 return false; |
| 151 | 108 |
| 152 if (v8Value->IsObject()) { | 109 if (v8Value->IsObject()) { |
| 153 ASSERT(m_isolate); | 110 ASSERT(m_isolate); |
| 154 ASSERT(m_isolate == v8::Isolate::GetCurrent()); | 111 ASSERT(m_isolate == v8::Isolate::GetCurrent()); |
| 155 value = Dictionary(v8Value, m_isolate, *m_exceptionState); | 112 value = Dictionary(m_isolate, v8Value); |
| 156 } | 113 } |
| 157 | 114 |
| 158 return true; | 115 return true; |
| 159 } | 116 } |
| 160 | 117 |
| 161 bool Dictionary::getInternal(const v8::Local<v8::Value>& key, v8::Local<v8::Valu
e>& result) const | 118 bool Dictionary::getInternal(const v8::Local<v8::Value>& key, v8::Local<v8::Valu
e>& result) const |
| 162 { | 119 { |
| 163 v8::Local<v8::Object> object; | 120 v8::Local<v8::Object> object; |
| 164 if (!toObject(object)) | 121 if (!toObject(object)) |
| 165 return false; | 122 return false; |
| 166 | 123 |
| 167 ASSERT(m_isolate); | 124 DCHECK(m_isolate); |
| 168 ASSERT(m_isolate == v8::Isolate::GetCurrent()); | 125 DCHECK_EQ(m_isolate, v8::Isolate::GetCurrent()); |
| 169 ASSERT(m_exceptionState); | |
| 170 if (!v8CallBoolean(object->Has(v8Context(), key))) | 126 if (!v8CallBoolean(object->Has(v8Context(), key))) |
| 171 return false; | 127 return false; |
| 172 return object->Get(v8Context(), key).ToLocal(&result); | 128 return object->Get(v8Context(), key).ToLocal(&result); |
| 173 } | 129 } |
| 174 | 130 |
| 175 static inline bool propertyKey(v8::Local<v8::Context> v8Context, v8::Local<v8::A
rray> properties, uint32_t index, v8::Local<v8::String>& key) | 131 static inline bool propertyKey(v8::Local<v8::Context> v8Context, v8::Local<v8::A
rray> properties, uint32_t index, v8::Local<v8::String>& key) |
| 176 { | 132 { |
| 177 v8::Local<v8::Value> property; | 133 v8::Local<v8::Value> property; |
| 178 if (!properties->Get(v8Context, index).ToLocal(&property)) | 134 if (!properties->Get(v8Context, index).ToLocal(&property)) |
| 179 return false; | 135 return false; |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 229 | 185 |
| 230 return true; | 186 return true; |
| 231 } | 187 } |
| 232 | 188 |
| 233 bool Dictionary::toObject(v8::Local<v8::Object>& object) const | 189 bool Dictionary::toObject(v8::Local<v8::Object>& object) const |
| 234 { | 190 { |
| 235 return !isUndefinedOrNull() && m_options->ToObject(v8Context()).ToLocal(&obj
ect); | 191 return !isUndefinedOrNull() && m_options->ToObject(v8Context()).ToLocal(&obj
ect); |
| 236 } | 192 } |
| 237 | 193 |
| 238 } // namespace blink | 194 } // namespace blink |
| OLD | NEW |