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

Side by Side Diff: sky/engine/bindings/core/v8/ScriptFunctionCall.cpp

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) 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 #include "sky/engine/config.h"
32 #include "sky/engine/bindings/core/v8/ScriptFunctionCall.h"
33
34 #include "sky/engine/bindings/core/v8/ScriptController.h"
35 #include "sky/engine/bindings/core/v8/ScriptState.h"
36 #include "sky/engine/bindings/core/v8/ScriptValue.h"
37 #include "sky/engine/bindings/core/v8/V8Binding.h"
38 #include "sky/engine/bindings/core/v8/V8ObjectConstructor.h"
39 #include "sky/engine/bindings/core/v8/V8ScriptRunner.h"
40 #include "v8/include/v8.h"
41
42 namespace blink {
43
44 void ScriptCallArgumentHandler::appendArgument(const ScriptValue& argument)
45 {
46 if (argument.scriptState() != m_scriptState) {
47 appendUndefinedArgument();
48 return;
49 }
50 m_arguments.append(argument);
51 }
52
53 void ScriptCallArgumentHandler::appendArgument(const String& argument)
54 {
55 v8::Isolate* isolate = m_scriptState->isolate();
56 ScriptState::Scope scope(m_scriptState.get());
57 m_arguments.append(ScriptValue(m_scriptState.get(), v8String(isolate, argume nt)));
58 }
59
60 void ScriptCallArgumentHandler::appendArgument(const char* argument)
61 {
62 v8::Isolate* isolate = m_scriptState->isolate();
63 ScriptState::Scope scope(m_scriptState.get());
64 m_arguments.append(ScriptValue(m_scriptState.get(), v8String(isolate, argume nt)));
65 }
66
67 void ScriptCallArgumentHandler::appendArgument(long argument)
68 {
69 v8::Isolate* isolate = m_scriptState->isolate();
70 ScriptState::Scope scope(m_scriptState.get());
71 m_arguments.append(ScriptValue(m_scriptState.get(), v8::Number::New(isolate, argument)));
72 }
73
74 void ScriptCallArgumentHandler::appendArgument(long long argument)
75 {
76 v8::Isolate* isolate = m_scriptState->isolate();
77 ScriptState::Scope scope(m_scriptState.get());
78 m_arguments.append(ScriptValue(m_scriptState.get(), v8::Number::New(isolate, argument)));
79 }
80
81 void ScriptCallArgumentHandler::appendArgument(unsigned argument)
82 {
83 v8::Isolate* isolate = m_scriptState->isolate();
84 ScriptState::Scope scope(m_scriptState.get());
85 m_arguments.append(ScriptValue(m_scriptState.get(), v8::Number::New(isolate, argument)));
86 }
87
88 void ScriptCallArgumentHandler::appendArgument(unsigned long argument)
89 {
90 v8::Isolate* isolate = m_scriptState->isolate();
91 ScriptState::Scope scope(m_scriptState.get());
92 m_arguments.append(ScriptValue(m_scriptState.get(), v8::Number::New(isolate, argument)));
93 }
94
95 void ScriptCallArgumentHandler::appendArgument(int argument)
96 {
97 v8::Isolate* isolate = m_scriptState->isolate();
98 ScriptState::Scope scope(m_scriptState.get());
99 m_arguments.append(ScriptValue(m_scriptState.get(), v8::Number::New(isolate, argument)));
100 }
101
102 void ScriptCallArgumentHandler::appendArgument(bool argument)
103 {
104 v8::Isolate* isolate = m_scriptState->isolate();
105 m_arguments.append(ScriptValue(m_scriptState.get(), v8Boolean(argument, isol ate)));
106 }
107
108 void ScriptCallArgumentHandler::appendArgument(const Vector<ScriptValue>& argume nt)
109 {
110 v8::Isolate* isolate = m_scriptState->isolate();
111 ScriptState::Scope scope(m_scriptState.get());
112 v8::Handle<v8::Array> result = v8::Array::New(isolate, argument.size());
113 for (size_t i = 0; i < argument.size(); ++i) {
114 if (argument[i].scriptState() != m_scriptState)
115 result->Set(v8::Integer::New(isolate, i), v8::Undefined(isolate));
116 else
117 result->Set(v8::Integer::New(isolate, i), argument[i].v8Value());
118 }
119 m_arguments.append(ScriptValue(m_scriptState.get(), result));
120 }
121
122 void ScriptCallArgumentHandler::appendUndefinedArgument()
123 {
124 v8::Isolate* isolate = m_scriptState->isolate();
125 m_arguments.append(ScriptValue(m_scriptState.get(), v8::Undefined(isolate))) ;
126 }
127
128 ScriptFunctionCall::ScriptFunctionCall(const ScriptValue& thisObject, const Stri ng& name)
129 : ScriptCallArgumentHandler(thisObject.scriptState())
130 , m_thisObject(thisObject)
131 , m_name(name)
132 {
133 }
134
135 ScriptValue ScriptFunctionCall::call(bool& hadException, bool reportExceptions)
136 {
137 ScriptState::Scope scope(m_scriptState.get());
138 v8::TryCatch tryCatch;
139 tryCatch.SetVerbose(reportExceptions);
140
141 v8::Handle<v8::Object> thisObject = v8::Handle<v8::Object>::Cast(m_thisObjec t.v8Value());
142 v8::Local<v8::Value> value = thisObject->Get(v8String(m_scriptState->isolate (), m_name));
143 if (tryCatch.HasCaught()) {
144 hadException = true;
145 return ScriptValue();
146 }
147
148 ASSERT(value->IsFunction());
149
150 v8::Local<v8::Function> function = v8::Local<v8::Function>::Cast(value);
151 OwnPtr<v8::Handle<v8::Value>[]> info = adoptArrayPtr(new v8::Handle<v8::Valu e>[m_arguments.size()]);
152 for (size_t i = 0; i < m_arguments.size(); ++i) {
153 info[i] = m_arguments[i].v8Value();
154 ASSERT(!info[i].IsEmpty());
155 }
156
157 v8::Local<v8::Value> result = V8ScriptRunner::callFunction(function, m_scrip tState->executionContext(), thisObject, m_arguments.size(), info.get(), m_script State->isolate());
158 if (tryCatch.HasCaught()) {
159 hadException = true;
160 return ScriptValue();
161 }
162
163 return ScriptValue(m_scriptState.get(), result);
164 }
165
166 ScriptValue ScriptFunctionCall::call()
167 {
168 bool hadException = false;
169 return call(hadException);
170 }
171
172 ScriptValue ScriptFunctionCall::construct(bool& hadException, bool reportExcepti ons)
173 {
174 ScriptState::Scope scope(m_scriptState.get());
175 v8::TryCatch tryCatch;
176 tryCatch.SetVerbose(reportExceptions);
177
178 v8::Handle<v8::Object> thisObject = v8::Handle<v8::Object>::Cast(m_thisObjec t.v8Value());
179 v8::Local<v8::Value> value = thisObject->Get(v8String(m_scriptState->isolate (), m_name));
180 if (tryCatch.HasCaught()) {
181 hadException = true;
182 return ScriptValue();
183 }
184
185 ASSERT(value->IsFunction());
186
187 v8::Local<v8::Function> constructor = v8::Local<v8::Function>::Cast(value);
188 OwnPtr<v8::Handle<v8::Value>[]> info = adoptArrayPtr(new v8::Handle<v8::Valu e>[m_arguments.size()]);
189 for (size_t i = 0; i < m_arguments.size(); ++i)
190 info[i] = m_arguments[i].v8Value();
191
192 v8::Local<v8::Object> result = V8ObjectConstructor::newInstance(m_scriptStat e->isolate(), constructor, m_arguments.size(), info.get());
193 if (tryCatch.HasCaught()) {
194 hadException = true;
195 return ScriptValue();
196 }
197
198 return ScriptValue(m_scriptState.get(), result);
199 }
200
201 } // namespace blink
OLDNEW
« no previous file with comments | « sky/engine/bindings/core/v8/ScriptFunctionCall.h ('k') | sky/engine/bindings/core/v8/ScriptGCEvent.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698