| 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 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 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/ScriptController.h" | 30 #include "bindings/core/v8/ScriptController.h" |
| 31 #include "bindings/core/v8/V8ArrayBufferView.h" | 31 #include "bindings/core/v8/V8ArrayBufferView.h" |
| 32 #include "bindings/core/v8/V8Binding.h" | 32 #include "bindings/core/v8/V8Binding.h" |
| 33 #include "bindings/core/v8/V8BindingMacros.h" |
| 33 #include "bindings/core/v8/V8DOMError.h" | 34 #include "bindings/core/v8/V8DOMError.h" |
| 34 #include "bindings/core/v8/V8Element.h" | 35 #include "bindings/core/v8/V8Element.h" |
| 35 #include "bindings/core/v8/V8EventTarget.h" | 36 #include "bindings/core/v8/V8EventTarget.h" |
| 36 #include "bindings/core/v8/V8MessagePort.h" | 37 #include "bindings/core/v8/V8MessagePort.h" |
| 37 #include "bindings/core/v8/V8TextTrack.h" | 38 #include "bindings/core/v8/V8TextTrack.h" |
| 38 #include "bindings/core/v8/V8VoidCallback.h" | 39 #include "bindings/core/v8/V8VoidCallback.h" |
| 39 #include "bindings/core/v8/V8Window.h" | 40 #include "bindings/core/v8/V8Window.h" |
| 40 #include "core/html/track/TrackBase.h" | 41 #include "core/html/track/TrackBase.h" |
| 41 #include "wtf/MathExtras.h" | 42 #include "wtf/MathExtras.h" |
| 42 | 43 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 54 return !isUndefinedOrNull() && m_options->IsObject(); | 55 return !isUndefinedOrNull() && m_options->IsObject(); |
| 55 } | 56 } |
| 56 | 57 |
| 57 bool Dictionary::isUndefinedOrNull() const | 58 bool Dictionary::isUndefinedOrNull() const |
| 58 { | 59 { |
| 59 if (m_options.IsEmpty()) | 60 if (m_options.IsEmpty()) |
| 60 return true; | 61 return true; |
| 61 return blink::isUndefinedOrNull(m_options); | 62 return blink::isUndefinedOrNull(m_options); |
| 62 } | 63 } |
| 63 | 64 |
| 64 bool Dictionary::hasProperty(const String& key) const | 65 bool Dictionary::hasProperty(const StringView& key) const |
| 65 { | 66 { |
| 66 v8::Local<v8::Object> object; | 67 v8::Local<v8::Object> object; |
| 67 if (!toObject(object)) | 68 if (!toObject(object)) |
| 68 return false; | 69 return false; |
| 69 | 70 |
| 70 DCHECK(m_isolate); | 71 DCHECK(m_isolate); |
| 71 DCHECK_EQ(m_isolate, v8::Isolate::GetCurrent()); | 72 DCHECK_EQ(m_isolate, v8::Isolate::GetCurrent()); |
| 72 v8::Local<v8::String> v8Key = v8String(m_isolate, key); | 73 return v8CallBoolean(object->Has(v8Context(), v8String(m_isolate, key))); |
| 73 return v8CallBoolean(object->Has(v8Context(), v8Key)); | |
| 74 } | 74 } |
| 75 | 75 |
| 76 bool Dictionary::getKey(const String& key, v8::Local<v8::Value>& value) const | 76 bool Dictionary::get(const StringView& key, v8::Local<v8::Value>& value) const |
| 77 { | 77 { |
| 78 if (!m_isolate) | 78 if (!m_isolate) |
| 79 return false; | 79 return false; |
| 80 | |
| 81 return getInternal(v8String(m_isolate, key), value); | 80 return getInternal(v8String(m_isolate, key), value); |
| 82 } | 81 } |
| 83 | 82 |
| 84 DictionaryIterator Dictionary::getIterator(ExecutionContext* executionContext) c
onst | 83 DictionaryIterator Dictionary::getIterator(ExecutionContext* executionContext) c
onst |
| 85 { | 84 { |
| 86 v8::Local<v8::Value> iteratorGetter; | 85 v8::Local<v8::Value> iteratorGetter; |
| 87 // TODO(alancutter): Support callable objects as well as functions. | 86 // TODO(alancutter): Support callable objects as well as functions. |
| 88 if (!getInternal(v8::Symbol::GetIterator(m_isolate), iteratorGetter) || !ite
ratorGetter->IsFunction()) | 87 if (!getInternal(v8::Symbol::GetIterator(m_isolate), iteratorGetter) || !ite
ratorGetter->IsFunction()) |
| 89 return nullptr; | 88 return nullptr; |
| 90 v8::Local<v8::Value> iterator; | 89 v8::Local<v8::Value> iterator; |
| 91 if (!v8Call(V8ScriptRunner::callFunction(v8::Local<v8::Function>::Cast(itera
torGetter), executionContext, m_options, 0, nullptr, m_isolate), iterator)) | 90 if (!v8Call(V8ScriptRunner::callFunction(v8::Local<v8::Function>::Cast(itera
torGetter), executionContext, m_options, 0, nullptr, m_isolate), iterator)) |
| 92 return nullptr; | 91 return nullptr; |
| 93 if (!iterator->IsObject()) | 92 if (!iterator->IsObject()) |
| 94 return nullptr; | 93 return nullptr; |
| 95 return DictionaryIterator(v8::Local<v8::Object>::Cast(iterator), m_isolate); | 94 return DictionaryIterator(v8::Local<v8::Object>::Cast(iterator), m_isolate); |
| 96 } | 95 } |
| 97 | 96 |
| 98 bool Dictionary::get(const String& key, v8::Local<v8::Value>& value) const | 97 bool Dictionary::get(const StringView& key, Dictionary& value) const |
| 99 { | |
| 100 return getKey(key, value); | |
| 101 } | |
| 102 | |
| 103 bool Dictionary::get(const String& key, Dictionary& value) const | |
| 104 { | 98 { |
| 105 v8::Local<v8::Value> v8Value; | 99 v8::Local<v8::Value> v8Value; |
| 106 if (!getKey(key, v8Value)) | 100 if (!get(key, v8Value)) |
| 107 return false; | 101 return false; |
| 108 | 102 |
| 109 if (v8Value->IsObject()) { | 103 if (v8Value->IsObject()) { |
| 110 ASSERT(m_isolate); | 104 ASSERT(m_isolate); |
| 111 ASSERT(m_isolate == v8::Isolate::GetCurrent()); | 105 ASSERT(m_isolate == v8::Isolate::GetCurrent()); |
| 112 value = Dictionary(m_isolate, v8Value); | 106 value = Dictionary(m_isolate, v8Value); |
| 113 } | 107 } |
| 114 | 108 |
| 115 return true; | 109 return true; |
| 116 } | 110 } |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 185 | 179 |
| 186 return true; | 180 return true; |
| 187 } | 181 } |
| 188 | 182 |
| 189 bool Dictionary::toObject(v8::Local<v8::Object>& object) const | 183 bool Dictionary::toObject(v8::Local<v8::Object>& object) const |
| 190 { | 184 { |
| 191 return !isUndefinedOrNull() && m_options->ToObject(v8Context()).ToLocal(&obj
ect); | 185 return !isUndefinedOrNull() && m_options->ToObject(v8Context()).ToLocal(&obj
ect); |
| 192 } | 186 } |
| 193 | 187 |
| 194 } // namespace blink | 188 } // namespace blink |
| OLD | NEW |