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

Side by Side Diff: third_party/WebKit/Source/bindings/core/v8/ScriptFunctionCall.cpp

Issue 1638563002: DevTools: migrate ScriptFunctionCall off ScriptValue (to be inlined into the InjectedScript.cpp). (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 11 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
1 /* 1 /*
2 * Copyright (C) 2009 Google Inc. All rights reserved. 2 * Copyright (C) 2009 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 12 matching lines...) Expand all
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 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. 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */ 29 */
30 30
31 #include "bindings/core/v8/ScriptFunctionCall.h" 31 #include "bindings/core/v8/ScriptFunctionCall.h"
32 32
33 #include "bindings/core/v8/ScriptController.h" 33 #include "core/inspector/v8/V8DebuggerClient.h"
34 #include "bindings/core/v8/ScriptState.h" 34 #include "wtf/PassOwnPtr.h"
35 #include "bindings/core/v8/ScriptValue.h"
36 #include "bindings/core/v8/V8Binding.h"
37 #include "bindings/core/v8/V8ObjectConstructor.h"
38 #include "bindings/core/v8/V8ScriptRunner.h"
39 35
40 #include <v8.h> 36 #include <v8.h>
41 37
42 namespace blink { 38 namespace blink {
43 39
44 void ScriptCallArgumentHandler::appendArgument(v8::Local<v8::Value> value) 40 static v8::Local<v8::String> v8String(v8::Isolate* isolate, const String& string )
45 { 41 {
46 m_arguments.append(ScriptValue(m_scriptState.get(), value)); 42 v8::Local<v8::String> result;
43 bool success = v8::String::NewFromUtf8(isolate, string.utf8().data(), v8::Ne wStringType::kNormal).ToLocal(&result);
44 ASSERT_UNUSED(success, success);
45 return result;
47 } 46 }
48 47
49 void ScriptCallArgumentHandler::appendArgument(const ScriptValue& argument) 48 ScriptFunctionCall::ScriptFunctionCall(V8DebuggerClient* client, v8::Local<v8::C ontext> context, v8::Local<v8::Value> value, const String& name)
50 { 49 : m_client(client)
51 if (argument.scriptState() != m_scriptState) { 50 , m_context(context)
52 appendUndefinedArgument(); 51 , m_name(v8String(context->GetIsolate(), name))
53 return; 52 , m_value(value)
54 }
55 m_arguments.append(argument);
56 }
57
58 void ScriptCallArgumentHandler::appendArgument(const String& argument)
59 {
60 v8::Isolate* isolate = m_scriptState->isolate();
61 ScriptState::Scope scope(m_scriptState.get());
62 m_arguments.append(ScriptValue(m_scriptState.get(), v8String(isolate, argume nt)));
63 }
64
65 void ScriptCallArgumentHandler::appendArgument(int argument)
66 {
67 v8::Isolate* isolate = m_scriptState->isolate();
68 ScriptState::Scope scope(m_scriptState.get());
69 m_arguments.append(ScriptValue(m_scriptState.get(), v8::Number::New(isolate, argument)));
70 }
71
72 void ScriptCallArgumentHandler::appendArgument(bool argument)
73 {
74 v8::Isolate* isolate = m_scriptState->isolate();
75 m_arguments.append(ScriptValue(m_scriptState.get(), v8Boolean(argument, isol ate)));
76 }
77
78 void ScriptCallArgumentHandler::appendUndefinedArgument()
79 {
80 v8::Isolate* isolate = m_scriptState->isolate();
81 m_arguments.append(ScriptValue(m_scriptState.get(), v8::Undefined(isolate))) ;
82 }
83
84 ScriptFunctionCall::ScriptFunctionCall(const ScriptValue& thisObject, const Stri ng& name)
85 : ScriptCallArgumentHandler(thisObject.scriptState())
86 , m_thisObject(thisObject)
87 , m_name(name)
88 { 53 {
89 } 54 }
90 55
91 ScriptValue ScriptFunctionCall::call(bool& hadException, bool reportExceptions) 56 void ScriptFunctionCall::appendArgument(v8::Local<v8::Value> value)
92 { 57 {
93 ScriptState::Scope scope(m_scriptState.get()); 58 m_arguments.append(value);
94 v8::TryCatch tryCatch(m_scriptState->isolate()); 59 }
60
61 void ScriptFunctionCall::appendArgument(const String& argument)
62 {
63 m_arguments.append(v8String(m_context->GetIsolate(), argument));
64 }
65
66 void ScriptFunctionCall::appendArgument(int argument)
67 {
68 m_arguments.append(v8::Number::New(m_context->GetIsolate(), argument));
69 }
70
71 void ScriptFunctionCall::appendArgument(bool argument)
72 {
73 m_arguments.append(argument ? v8::True(m_context->GetIsolate()) : v8::False( m_context->GetIsolate()));
74 }
75
76 void ScriptFunctionCall::appendUndefinedArgument()
77 {
78 m_arguments.append(v8::Undefined(m_context->GetIsolate()));
79 }
80
81 v8::Local<v8::Value> ScriptFunctionCall::call(bool& hadException, bool reportExc eptions)
82 {
83 v8::TryCatch tryCatch(m_context->GetIsolate());
95 tryCatch.SetVerbose(reportExceptions); 84 tryCatch.SetVerbose(reportExceptions);
96 85
97 ScriptValue result = callWithoutExceptionHandling(); 86 v8::Local<v8::Value> result = callWithoutExceptionHandling();
98 hadException = tryCatch.HasCaught(); 87 hadException = tryCatch.HasCaught();
99 return result; 88 return result;
100 } 89 }
101 90
102 ScriptValue ScriptFunctionCall::call() 91 v8::Local<v8::Value> ScriptFunctionCall::call()
103 { 92 {
104 bool hadException = false; 93 bool hadException = false;
105 return call(hadException); 94 return call(hadException);
106 } 95 }
107 96
108 ScriptValue ScriptFunctionCall::callWithoutExceptionHandling() 97 v8::Local<v8::Value> ScriptFunctionCall::callWithoutExceptionHandling()
109 { 98 {
110 ScriptState::Scope scope(m_scriptState.get()); 99 v8::Local<v8::Object> thisObject = v8::Local<v8::Object>::Cast(m_value);
111 v8::Local<v8::Object> thisObject = v8::Local<v8::Object>::Cast(m_thisObject. v8Value());
112 v8::Local<v8::Value> value; 100 v8::Local<v8::Value> value;
113 if (!thisObject->Get(m_scriptState->context(), v8String(m_scriptState->isola te(), m_name)).ToLocal(&value)) 101 if (!thisObject->Get(m_context, m_name).ToLocal(&value))
114 return ScriptValue(); 102 return v8::Local<v8::Value>();
115 103
116 ASSERT(value->IsFunction()); 104 ASSERT(value->IsFunction());
117 105
118 v8::Local<v8::Function> function = v8::Local<v8::Function>::Cast(value); 106 v8::Local<v8::Function> function = v8::Local<v8::Function>::Cast(value);
119 OwnPtr<v8::Local<v8::Value>[]> info = adoptArrayPtr(new v8::Local<v8::Value> [m_arguments.size()]); 107 OwnPtr<v8::Local<v8::Value>[]> info = adoptArrayPtr(new v8::Local<v8::Value> [m_arguments.size()]);
120 for (size_t i = 0; i < m_arguments.size(); ++i) { 108 for (size_t i = 0; i < m_arguments.size(); ++i) {
121 info[i] = m_arguments[i].v8Value(); 109 info[i] = m_arguments[i];
122 ASSERT(!info[i].IsEmpty()); 110 ASSERT(!info[i].IsEmpty());
123 } 111 }
124 112
125 v8::Local<v8::Value> result; 113 v8::Local<v8::Value> result;
126 if (!V8ScriptRunner::callFunction(function, m_scriptState->executionContext( ), thisObject, m_arguments.size(), info.get(), m_scriptState->isolate()).ToLocal (&result)) 114 if (!m_client->callFunction(function, m_context, thisObject, m_arguments.siz e(), info.get()).ToLocal(&result))
127 return ScriptValue(); 115 return v8::Local<v8::Value>();
128 return ScriptValue(m_scriptState.get(), result); 116 return result;
129 } 117 }
130 118
131 v8::Local<v8::Function> ScriptFunctionCall::function() 119 v8::Local<v8::Function> ScriptFunctionCall::function()
132 { 120 {
133 v8::TryCatch tryCatch(m_scriptState->isolate()); 121 v8::TryCatch tryCatch(m_context->GetIsolate());
134 v8::Local<v8::Object> thisObject = v8::Local<v8::Object>::Cast(m_thisObject. v8Value()); 122 v8::Local<v8::Object> thisObject = v8::Local<v8::Object>::Cast(m_value);
135 v8::Local<v8::Value> value; 123 v8::Local<v8::Value> value;
136 if (!thisObject->Get(m_scriptState->context(), v8String(m_scriptState->isola te(), m_name)).ToLocal(&value)) 124 if (!thisObject->Get(m_context, m_name).ToLocal(&value))
137 return v8::Local<v8::Function>(); 125 return v8::Local<v8::Function>();
138 126
139 ASSERT(value->IsFunction()); 127 ASSERT(value->IsFunction());
140 return v8::Local<v8::Function>::Cast(value); 128 return v8::Local<v8::Function>::Cast(value);
141 } 129 }
142 130
143
144 } // namespace blink 131 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698