OLD | NEW |
(Empty) | |
| 1 /* |
| 2 * Copyright (C) 2008, 2009 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 ScriptValue_h |
| 32 #define ScriptValue_h |
| 33 |
| 34 #include <v8.h> |
| 35 |
| 36 #ifndef NDEBUG |
| 37 #include "V8Proxy.h" // for register and unregister global handles. |
| 38 #endif |
| 39 |
| 40 namespace WebCore { |
| 41 |
| 42 class String; |
| 43 |
| 44 class ScriptValue { |
| 45 public: |
| 46 ScriptValue() {} |
| 47 |
| 48 ScriptValue(v8::Handle<v8::Value> value) |
| 49 { |
| 50 if (value.IsEmpty()) |
| 51 return; |
| 52 |
| 53 m_value = v8::Persistent<v8::Value>::New(value); |
| 54 #ifndef NDEBUG |
| 55 V8Proxy::RegisterGlobalHandle(SCRIPTVALUE, this, m_value); |
| 56 #endif |
| 57 } |
| 58 |
| 59 ScriptValue(const ScriptValue& value) |
| 60 { |
| 61 if (value.m_value.IsEmpty()) |
| 62 return; |
| 63 |
| 64 m_value = v8::Persistent<v8::Value>::New(value.m_value); |
| 65 #ifndef NDEBUG |
| 66 V8Proxy::RegisterGlobalHandle(SCRIPTVALUE, this, m_value); |
| 67 #endif |
| 68 } |
| 69 |
| 70 ScriptValue& operator=(const ScriptValue& value) |
| 71 { |
| 72 if (this == &value) |
| 73 return *this; |
| 74 |
| 75 clear(); |
| 76 |
| 77 if (value.m_value.IsEmpty()) |
| 78 return *this; |
| 79 |
| 80 m_value = v8::Persistent<v8::Value>::New(value.m_value); |
| 81 #ifndef NDEBUG |
| 82 V8Proxy::RegisterGlobalHandle(SCRIPTVALUE, this, m_value); |
| 83 #endif |
| 84 |
| 85 return *this; |
| 86 } |
| 87 |
| 88 bool operator==(const ScriptValue value) const |
| 89 { |
| 90 return m_value == value.m_value; |
| 91 } |
| 92 |
| 93 bool operator!=(const ScriptValue value) const |
| 94 { |
| 95 return !operator==(value); |
| 96 } |
| 97 |
| 98 bool isNull() const |
| 99 { |
| 100 return m_value->IsNull(); |
| 101 } |
| 102 |
| 103 bool isUndefined() const |
| 104 { |
| 105 return m_value->IsUndefined(); |
| 106 } |
| 107 |
| 108 void clear() |
| 109 { |
| 110 if (!m_value.IsEmpty()) |
| 111 return; |
| 112 |
| 113 #ifndef NDEBUG |
| 114 V8Proxy::UnregisterGlobalHandle(this, m_value); |
| 115 #endif |
| 116 m_value.Dispose(); |
| 117 m_value.Clear(); |
| 118 } |
| 119 |
| 120 ~ScriptValue() |
| 121 { |
| 122 clear(); |
| 123 } |
| 124 |
| 125 v8::Handle<v8::Value> v8Value() const { return m_value; } |
| 126 bool getString(String& result) const; |
| 127 |
| 128 private: |
| 129 mutable v8::Persistent<v8::Value> m_value; |
| 130 }; |
| 131 |
| 132 } // namespace WebCore |
| 133 |
| 134 #endif // ScriptValue_h |
OLD | NEW |