Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(480)

Side by Side Diff: Source/bindings/v8/ScriptValue.h

Issue 351423002: Moved files under Source/bindings/v8 to Source/bindings/core/v8. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « Source/bindings/v8/ScriptString.cpp ('k') | Source/bindings/v8/ScriptValue.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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 "bindings/v8/ScriptState.h"
35 #include "bindings/v8/SharedPersistent.h"
36 #include "wtf/PassRefPtr.h"
37 #include "wtf/RefPtr.h"
38 #include "wtf/text/WTFString.h"
39 #include <v8.h>
40
41 namespace WebCore {
42
43 class JSONValue;
44
45 class ScriptValue {
46 public:
47 ScriptValue()
48 : m_isolate(0)
49 , m_scriptState(nullptr)
50 {
51 }
52
53 virtual ~ScriptValue();
54
55 ScriptValue(ScriptState* scriptState, v8::Handle<v8::Value> value)
56 : m_isolate(scriptState->isolate())
57 , m_scriptState(scriptState)
58 , m_value(value.IsEmpty() ? nullptr : SharedPersistent<v8::Value>::creat e(value, scriptState->isolate()))
59 {
60 ASSERT(isEmpty() || m_scriptState);
61 }
62
63 ScriptValue(const ScriptValue& value)
64 : m_isolate(value.m_isolate)
65 , m_scriptState(value.m_scriptState)
66 , m_value(value.m_value)
67 {
68 ASSERT(isEmpty() || m_scriptState);
69 }
70
71 ScriptState* scriptState() const
72 {
73 return m_scriptState.get();
74 }
75
76 v8::Isolate* isolate() const
77 {
78 if (!m_isolate)
79 m_isolate = v8::Isolate::GetCurrent();
80 return m_isolate;
81 }
82
83 ScriptValue& operator=(const ScriptValue& value)
84 {
85 if (this != &value) {
86 m_isolate = value.m_isolate;
87 m_scriptState = value.m_scriptState;
88 m_value = value.m_value;
89 }
90 return *this;
91 }
92
93 bool operator==(const ScriptValue& value) const
94 {
95 if (isEmpty())
96 return value.isEmpty();
97 if (value.isEmpty())
98 return false;
99 return *m_value == *value.m_value;
100 }
101
102 bool operator!=(const ScriptValue& value) const
103 {
104 return !operator==(value);
105 }
106
107 // This creates a new local Handle; Don't use this in performance-sensitive places.
108 bool isFunction() const
109 {
110 ASSERT(!isEmpty());
111 v8::Handle<v8::Value> value = v8Value();
112 return !value.IsEmpty() && value->IsFunction();
113 }
114
115 // This creates a new local Handle; Don't use this in performance-sensitive places.
116 bool isNull() const
117 {
118 ASSERT(!isEmpty());
119 v8::Handle<v8::Value> value = v8Value();
120 return !value.IsEmpty() && value->IsNull();
121 }
122
123 // This creates a new local Handle; Don't use this in performance-sensitive places.
124 bool isUndefined() const
125 {
126 ASSERT(!isEmpty());
127 v8::Handle<v8::Value> value = v8Value();
128 return !value.IsEmpty() && value->IsUndefined();
129 }
130
131 // This creates a new local Handle; Don't use this in performance-sensitive places.
132 bool isObject() const
133 {
134 ASSERT(!isEmpty());
135 v8::Handle<v8::Value> value = v8Value();
136 return !value.IsEmpty() && value->IsObject();
137 }
138
139 bool isEmpty() const
140 {
141 return !m_value.get() || m_value->isEmpty();
142 }
143
144 void clear()
145 {
146 m_value = nullptr;
147 }
148
149 v8::Handle<v8::Value> v8Value() const;
150
151 bool toString(String&) const;
152 PassRefPtr<JSONValue> toJSONValue(ScriptState*) const;
153
154 private:
155 mutable v8::Isolate* m_isolate;
156 mutable RefPtr<ScriptState> m_scriptState;
157 RefPtr<SharedPersistent<v8::Value> > m_value;
158 };
159
160 } // namespace WebCore
161
162 #endif // ScriptValue_h
OLDNEW
« no previous file with comments | « Source/bindings/v8/ScriptString.cpp ('k') | Source/bindings/v8/ScriptValue.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698