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

Side by Side Diff: sky/engine/bindings/core/v8/ScriptValue.h

Issue 922053002: Remove unused V8 integration code in Sky (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 5 years, 10 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
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 SKY_ENGINE_BINDINGS_CORE_V8_SCRIPTVALUE_H_
32 #define SKY_ENGINE_BINDINGS_CORE_V8_SCRIPTVALUE_H_
33
34 #include "sky/engine/bindings/core/v8/ScriptState.h"
35 #include "sky/engine/bindings/core/v8/SharedPersistent.h"
36 #include "sky/engine/wtf/PassRefPtr.h"
37 #include "sky/engine/wtf/RefPtr.h"
38 #include "sky/engine/wtf/text/WTFString.h"
39 #include "v8/include/v8.h"
40
41 namespace blink {
42
43 class JSONValue;
44
45 class ScriptValue final {
46 public:
47 ScriptValue() { }
48
49 ScriptValue(ScriptState* scriptState, v8::Handle<v8::Value> value)
50 : m_scriptState(scriptState)
51 , m_value(value.IsEmpty() ? nullptr : SharedPersistent<v8::Value>::creat e(value, scriptState->isolate()))
52 {
53 ASSERT(isEmpty() || m_scriptState);
54 }
55
56 ScriptValue(const ScriptValue& value)
57 : m_scriptState(value.m_scriptState)
58 , m_value(value.m_value)
59 {
60 ASSERT(isEmpty() || m_scriptState);
61 }
62
63 static ScriptValue createEmptyObject(ScriptState* scriptState)
64 {
65 return ScriptValue(scriptState, v8::Object::New(scriptState->isolate())) ;
66 }
67
68 ScriptState* scriptState() const
69 {
70 return m_scriptState.get();
71 }
72
73 v8::Isolate* isolate() const
74 {
75 return m_scriptState ? m_scriptState->isolate() : v8::Isolate::GetCurren t();
76 }
77
78 ScriptValue& operator=(const ScriptValue& value)
79 {
80 if (this != &value) {
81 m_scriptState = value.m_scriptState;
82 m_value = value.m_value;
83 }
84 return *this;
85 }
86
87 bool operator==(const ScriptValue& value) const
88 {
89 if (isEmpty())
90 return value.isEmpty();
91 if (value.isEmpty())
92 return false;
93 return *m_value == *value.m_value;
94 }
95
96 bool operator!=(const ScriptValue& value) const
97 {
98 return !operator==(value);
99 }
100
101 // This creates a new local Handle; Don't use this in performance-sensitive places.
102 bool isFunction() const
103 {
104 ASSERT(!isEmpty());
105 v8::Handle<v8::Value> value = v8Value();
106 return !value.IsEmpty() && value->IsFunction();
107 }
108
109 // This creates a new local Handle; Don't use this in performance-sensitive places.
110 bool isNull() const
111 {
112 ASSERT(!isEmpty());
113 v8::Handle<v8::Value> value = v8Value();
114 return !value.IsEmpty() && value->IsNull();
115 }
116
117 // This creates a new local Handle; Don't use this in performance-sensitive places.
118 bool isUndefined() const
119 {
120 ASSERT(!isEmpty());
121 v8::Handle<v8::Value> value = v8Value();
122 return !value.IsEmpty() && value->IsUndefined();
123 }
124
125 // This creates a new local Handle; Don't use this in performance-sensitive places.
126 bool isObject() const
127 {
128 ASSERT(!isEmpty());
129 v8::Handle<v8::Value> value = v8Value();
130 return !value.IsEmpty() && value->IsObject();
131 }
132
133 bool isEmpty() const
134 {
135 return !m_value.get() || m_value->isEmpty();
136 }
137
138 void clear()
139 {
140 m_value = nullptr;
141 }
142
143 v8::Handle<v8::Value> v8Value() const;
144 v8::Handle<v8::Value> v8ValueUnsafe() const;
145
146 bool toString(String&) const;
147 PassRefPtr<JSONValue> toJSONValue(ScriptState*) const;
148
149 private:
150 RefPtr<ScriptState> m_scriptState;
151 RefPtr<SharedPersistent<v8::Value> > m_value;
152 };
153
154 } // namespace blink
155
156 #endif // SKY_ENGINE_BINDINGS_CORE_V8_SCRIPTVALUE_H_
OLDNEW
« no previous file with comments | « sky/engine/bindings/core/v8/ScriptString.cpp ('k') | sky/engine/bindings/core/v8/ScriptValue.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698