OLD | NEW |
| (Empty) |
1 /* | |
2 * Copyright (c) 2008, Google Inc. | |
3 * All rights reserved. | |
4 * | |
5 * Redistribution and use in source and binary forms, with or without | |
6 * modification, are permitted provided that the following conditions are | |
7 * met: | |
8 * | |
9 * * Redistributions of source code must retain the above copyright | |
10 * notice, this list of conditions and the following disclaimer. | |
11 * * Redistributions in binary form must reproduce the above | |
12 * copyright notice, this list of conditions and the following disclaimer | |
13 * in the documentation and/or other materials provided with the | |
14 * distribution. | |
15 * * Neither the name of Google Inc. nor the names of its | |
16 * contributors may be used to endorse or promote products derived from | |
17 * this software without specific prior written permission. | |
18 * | |
19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | |
20 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | |
21 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | |
22 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | |
23 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |
24 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |
25 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | |
26 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | |
27 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |
29 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
30 */ | |
31 | |
32 #ifndef ScriptValue_h | |
33 #define ScriptValue_h | |
34 | |
35 #include "v8.h" | |
36 | |
37 #ifndef NDEBUG | |
38 #include "v8_proxy.h" // for register and unregister global handles. | |
39 #endif | |
40 | |
41 namespace WebCore { | |
42 | |
43 class String; | |
44 | |
45 class ScriptValue { | |
46 public: | |
47 ScriptValue() {} | |
48 | |
49 ScriptValue(v8::Handle<v8::Value> value) | |
50 { | |
51 if (!value.IsEmpty()) { | |
52 m_value = v8::Persistent<v8::Value>::New(value); | |
53 #ifndef NDEBUG | |
54 V8Proxy::RegisterGlobalHandle(SCRIPTVALUE, this, m_value); | |
55 #endif | |
56 } | |
57 } | |
58 | |
59 ScriptValue(const ScriptValue& value) | |
60 { | |
61 if (!value.m_value.IsEmpty()) { | |
62 m_value = v8::Persistent<v8::Value>::New(value.m_value); | |
63 #ifndef NDEBUG | |
64 V8Proxy::RegisterGlobalHandle(SCRIPTVALUE, this, m_value); | |
65 #endif | |
66 } | |
67 } | |
68 | |
69 ScriptValue& operator=(const ScriptValue& value) | |
70 { | |
71 if (this == &value) | |
72 return *this; | |
73 | |
74 clear(); | |
75 if (!value.m_value.IsEmpty()) { | |
76 m_value = v8::Persistent<v8::Value>::New(value.m_value); | |
77 #ifndef NDEBUG | |
78 V8Proxy::RegisterGlobalHandle(SCRIPTVALUE, this, m_value); | |
79 #endif | |
80 } | |
81 | |
82 return *this; | |
83 } | |
84 | |
85 bool operator==(const ScriptValue value) const | |
86 { | |
87 return m_value == value.m_value; | |
88 } | |
89 | |
90 bool operator!=(const ScriptValue value) const | |
91 { | |
92 return !operator==(value); | |
93 } | |
94 | |
95 bool isNull() const | |
96 { | |
97 return m_value->IsNull(); | |
98 } | |
99 | |
100 bool isUndefined() const | |
101 { | |
102 return m_value->IsUndefined(); | |
103 } | |
104 | |
105 void clear() { | |
106 if (!m_value.IsEmpty()) { | |
107 #ifndef NDEBUG | |
108 V8Proxy::UnregisterGlobalHandle(this, m_value); | |
109 #endif | |
110 m_value.Dispose(); | |
111 m_value.Clear(); | |
112 } | |
113 } | |
114 | |
115 ~ScriptValue() | |
116 { | |
117 clear(); | |
118 } | |
119 | |
120 v8::Handle<v8::Value> v8Value() const { return m_value; } | |
121 bool getString(String& result) const; | |
122 | |
123 private: | |
124 mutable v8::Persistent<v8::Value> m_value; | |
125 }; | |
126 | |
127 } // namespace WebCore | |
128 | |
129 #endif // ScriptValue_h | |
OLD | NEW |