| OLD | NEW |
| 1 /* | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 * Copyright (C) 2007-2011 Google Inc. All rights reserved. | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 * | 3 // found in the LICENSE file. |
| 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 | 4 |
| 31 #include "config.h" | 5 #include "config.h" |
| 32 #include "bindings/core/v8/V8InjectedScriptHost.h" | 6 #include "bindings/core/v8/inspector/V8InjectedScriptHost.h" |
| 33 | 7 |
| 34 #include "bindings/core/v8/BindingSecurity.h" | 8 #include "bindings/core/v8/BindingSecurity.h" |
| 35 #include "bindings/core/v8/ExceptionState.h" | 9 #include "bindings/core/v8/ExceptionState.h" |
| 36 #include "bindings/core/v8/ScriptValue.h" | 10 #include "bindings/core/v8/ScriptValue.h" |
| 37 #include "bindings/core/v8/V8AbstractEventListener.h" | 11 #include "bindings/core/v8/V8AbstractEventListener.h" |
| 38 #include "bindings/core/v8/V8Binding.h" | 12 #include "bindings/core/v8/V8Binding.h" |
| 39 #include "bindings/core/v8/V8DOMException.h" | 13 #include "bindings/core/v8/V8DOMException.h" |
| 40 #include "bindings/core/v8/V8DOMTokenList.h" | 14 #include "bindings/core/v8/V8DOMTokenList.h" |
| 41 #include "bindings/core/v8/V8Debugger.h" | 15 #include "bindings/core/v8/V8Debugger.h" |
| 42 #include "bindings/core/v8/V8Event.h" | 16 #include "bindings/core/v8/V8Event.h" |
| 43 #include "bindings/core/v8/V8EventTarget.h" | 17 #include "bindings/core/v8/V8EventTarget.h" |
| 44 #include "bindings/core/v8/V8EventTarget.h" | |
| 45 #include "bindings/core/v8/V8HTMLAllCollection.h" | 18 #include "bindings/core/v8/V8HTMLAllCollection.h" |
| 46 #include "bindings/core/v8/V8HTMLCollection.h" | 19 #include "bindings/core/v8/V8HTMLCollection.h" |
| 47 #include "bindings/core/v8/V8Node.h" | 20 #include "bindings/core/v8/V8Node.h" |
| 48 #include "bindings/core/v8/V8NodeList.h" | 21 #include "bindings/core/v8/V8NodeList.h" |
| 49 #include "bindings/core/v8/V8ScriptRunner.h" | 22 #include "bindings/core/v8/V8ScriptRunner.h" |
| 50 #include "core/events/EventTarget.h" | 23 #include "core/events/EventTarget.h" |
| 51 #include "core/inspector/EventListenerInfo.h" | 24 #include "core/inspector/EventListenerInfo.h" |
| 52 #include "core/inspector/InjectedScript.h" | 25 #include "core/inspector/InjectedScript.h" |
| 53 #include "core/inspector/InjectedScriptHost.h" | 26 #include "core/inspector/InjectedScriptHost.h" |
| 54 #include "core/inspector/JavaScriptCallFrame.h" | 27 #include "core/inspector/JavaScriptCallFrame.h" |
| 55 #include "platform/JSONValues.h" | 28 #include "platform/JSONValues.h" |
| 29 #include "wtf/RefPtr.h" |
| 56 | 30 |
| 57 namespace blink { | 31 namespace blink { |
| 58 | 32 |
| 59 Node* InjectedScriptHost::scriptValueAsNode(ScriptState* scriptState, ScriptValu
e value) | 33 Node* InjectedScriptHost::scriptValueAsNode(ScriptState* scriptState, ScriptValu
e value) |
| 60 { | 34 { |
| 61 ScriptState::Scope scope(scriptState); | 35 ScriptState::Scope scope(scriptState); |
| 62 if (!value.isObject() || value.isNull()) | 36 if (!value.isObject() || value.isNull()) |
| 63 return 0; | 37 return 0; |
| 64 return V8Node::toImpl(v8::Local<v8::Object>::Cast(value.v8Value())); | 38 return V8Node::toImpl(v8::Local<v8::Object>::Cast(value.v8Value())); |
| 65 } | 39 } |
| (...skipping 20 matching lines...) Expand all Loading... |
| 86 } | 60 } |
| 87 | 61 |
| 88 EventTarget* InjectedScriptHost::scriptValueAsEventTarget(ScriptState* scriptSta
te, ScriptValue value) | 62 EventTarget* InjectedScriptHost::scriptValueAsEventTarget(ScriptState* scriptSta
te, ScriptValue value) |
| 89 { | 63 { |
| 90 ScriptState::Scope scope(scriptState); | 64 ScriptState::Scope scope(scriptState); |
| 91 if (value.isNull() || !value.isObject()) | 65 if (value.isNull() || !value.isObject()) |
| 92 return nullptr; | 66 return nullptr; |
| 93 return eventTargetFromScriptValue(scriptState->isolate(), value.v8Value()); | 67 return eventTargetFromScriptValue(scriptState->isolate(), value.v8Value()); |
| 94 } | 68 } |
| 95 | 69 |
| 96 void V8InjectedScriptHost::inspectedObjectMethodCustom(const v8::FunctionCallbac
kInfo<v8::Value>& info) | 70 void V8InjectedScriptHost::clearConsoleMessagesCallback(const v8::FunctionCallba
ckInfo<v8::Value>& info) |
| 71 { |
| 72 InjectedScriptHost* impl = V8InjectedScriptHost::toImpl(info.Holder()); |
| 73 impl->clearConsoleMessages(); |
| 74 } |
| 75 |
| 76 void V8InjectedScriptHost::inspectedObjectCallback(const v8::FunctionCallbackInf
o<v8::Value>& info) |
| 97 { | 77 { |
| 98 if (info.Length() < 1) | 78 if (info.Length() < 1) |
| 99 return; | 79 return; |
| 100 | 80 |
| 101 if (!info[0]->IsInt32()) { | 81 if (!info[0]->IsInt32()) { |
| 102 V8ThrowException::throwTypeError(info.GetIsolate(), "argument has to be
an integer"); | 82 V8ThrowException::throwTypeError(info.GetIsolate(), "argument has to be
an integer"); |
| 103 return; | 83 return; |
| 104 } | 84 } |
| 105 | 85 |
| 106 InjectedScriptHost* host = V8InjectedScriptHost::toImpl(info.Holder()); | 86 InjectedScriptHost* host = V8InjectedScriptHost::toImpl(info.Holder()); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 118 if (value->IsString() && v8::Local<v8::String>::Cast(value)->Length()) | 98 if (value->IsString() && v8::Local<v8::String>::Cast(value)->Length()) |
| 119 return v8::Local<v8::String>::Cast(value); | 99 return v8::Local<v8::String>::Cast(value); |
| 120 | 100 |
| 121 value = function->GetInferredName(); | 101 value = function->GetInferredName(); |
| 122 if (value->IsString() && v8::Local<v8::String>::Cast(value)->Length()) | 102 if (value->IsString() && v8::Local<v8::String>::Cast(value)->Length()) |
| 123 return v8::Local<v8::String>::Cast(value); | 103 return v8::Local<v8::String>::Cast(value); |
| 124 | 104 |
| 125 return v8::Local<v8::String>(); | 105 return v8::Local<v8::String>(); |
| 126 } | 106 } |
| 127 | 107 |
| 128 void V8InjectedScriptHost::internalConstructorNameMethodCustom(const v8::Functio
nCallbackInfo<v8::Value>& info) | 108 void V8InjectedScriptHost::internalConstructorNameCallback(const v8::FunctionCal
lbackInfo<v8::Value>& info) |
| 129 { | 109 { |
| 130 if (info.Length() < 1 || !info[0]->IsObject()) | 110 if (info.Length() < 1 || !info[0]->IsObject()) |
| 131 return; | 111 return; |
| 132 | 112 |
| 133 v8::Local<v8::Object> object = info[0].As<v8::Object>(); | 113 v8::Local<v8::Object> object = info[0].As<v8::Object>(); |
| 134 v8::Local<v8::String> result = object->GetConstructorName(); | 114 v8::Local<v8::String> result = object->GetConstructorName(); |
| 135 | 115 |
| 136 if (!result.IsEmpty() && toCoreStringWithUndefinedOrNullCheck(result) == "Ob
ject") { | 116 if (!result.IsEmpty() && toCoreStringWithUndefinedOrNullCheck(result) == "Ob
ject") { |
| 137 v8::Local<v8::String> constructorSymbol = v8AtomicString(info.GetIsolate
(), "constructor"); | 117 v8::Local<v8::String> constructorSymbol = v8AtomicString(info.GetIsolate
(), "constructor"); |
| 138 if (object->HasRealNamedProperty(constructorSymbol) && !object->HasRealN
amedCallbackProperty(constructorSymbol)) { | 118 if (object->HasRealNamedProperty(constructorSymbol) && !object->HasRealN
amedCallbackProperty(constructorSymbol)) { |
| 139 v8::TryCatch tryCatch; | 119 v8::TryCatch tryCatch; |
| 140 v8::Local<v8::Value> constructor = object->GetRealNamedProperty(cons
tructorSymbol); | 120 v8::Local<v8::Value> constructor = object->GetRealNamedProperty(cons
tructorSymbol); |
| 141 if (!constructor.IsEmpty() && constructor->IsFunction()) { | 121 if (!constructor.IsEmpty() && constructor->IsFunction()) { |
| 142 v8::Local<v8::String> constructorName = functionDisplayName(v8::
Local<v8::Function>::Cast(constructor)); | 122 v8::Local<v8::String> constructorName = functionDisplayName(v8::
Local<v8::Function>::Cast(constructor)); |
| 143 if (!constructorName.IsEmpty() && !tryCatch.HasCaught()) | 123 if (!constructorName.IsEmpty() && !tryCatch.HasCaught()) |
| 144 result = constructorName; | 124 result = constructorName; |
| 145 } | 125 } |
| 146 } | 126 } |
| 147 if (toCoreStringWithUndefinedOrNullCheck(result) == "Object" && object->
IsFunction()) | 127 if (toCoreStringWithUndefinedOrNullCheck(result) == "Object" && object->
IsFunction()) |
| 148 result = v8AtomicString(info.GetIsolate(), "Function"); | 128 result = v8AtomicString(info.GetIsolate(), "Function"); |
| 149 } | 129 } |
| 150 | 130 |
| 151 v8SetReturnValue(info, result); | 131 v8SetReturnValue(info, result); |
| 152 } | 132 } |
| 153 | 133 |
| 154 void V8InjectedScriptHost::isDOMWrapperMethodCustom(const v8::FunctionCallbackIn
fo<v8::Value>& info) | 134 void V8InjectedScriptHost::isDOMWrapperCallback(const v8::FunctionCallbackInfo<v
8::Value>& info) |
| 155 { | 135 { |
| 156 if (info.Length() < 1) | 136 if (info.Length() < 1) |
| 157 return; | 137 return; |
| 158 | 138 |
| 159 v8SetReturnValue(info, V8DOMWrapper::isWrapper(info.GetIsolate(), info[0])); | 139 v8SetReturnValue(info, V8DOMWrapper::isWrapper(info.GetIsolate(), info[0])); |
| 160 } | 140 } |
| 161 | 141 |
| 162 void V8InjectedScriptHost::isHTMLAllCollectionMethodCustom(const v8::FunctionCal
lbackInfo<v8::Value>& info) | 142 void V8InjectedScriptHost::isHTMLAllCollectionCallback(const v8::FunctionCallbac
kInfo<v8::Value>& info) |
| 163 { | 143 { |
| 164 if (info.Length() < 1) | 144 if (info.Length() < 1) |
| 165 return; | 145 return; |
| 166 | 146 |
| 167 if (!info[0]->IsObject()) { | 147 if (!info[0]->IsObject()) { |
| 168 v8SetReturnValue(info, false); | 148 v8SetReturnValue(info, false); |
| 169 return; | 149 return; |
| 170 } | 150 } |
| 171 | 151 |
| 172 v8SetReturnValue(info, V8HTMLAllCollection::hasInstance(info[0], info.GetIso
late())); | 152 v8SetReturnValue(info, V8HTMLAllCollection::hasInstance(info[0], info.GetIso
late())); |
| 173 } | 153 } |
| 174 | 154 |
| 175 void V8InjectedScriptHost::isTypedArrayMethodCustom(const v8::FunctionCallbackIn
fo<v8::Value>& info) | 155 void V8InjectedScriptHost::isTypedArrayCallback(const v8::FunctionCallbackInfo<v
8::Value>& info) |
| 176 { | 156 { |
| 177 if (info.Length() < 1) | 157 if (info.Length() < 1) |
| 178 return; | 158 return; |
| 179 v8SetReturnValue(info, info[0]->IsTypedArray()); | 159 v8SetReturnValue(info, info[0]->IsTypedArray()); |
| 180 } | 160 } |
| 181 | 161 |
| 182 void V8InjectedScriptHost::subtypeMethodCustom(const v8::FunctionCallbackInfo<v8
::Value>& info) | 162 void V8InjectedScriptHost::subtypeCallback(const v8::FunctionCallbackInfo<v8::Va
lue>& info) |
| 183 { | 163 { |
| 184 if (info.Length() < 1) | 164 if (info.Length() < 1) |
| 185 return; | 165 return; |
| 186 v8::Isolate* isolate = info.GetIsolate(); | 166 v8::Isolate* isolate = info.GetIsolate(); |
| 187 | 167 |
| 188 v8::Local<v8::Value> value = info[0]; | 168 v8::Local<v8::Value> value = info[0]; |
| 189 if (value->IsArray() || value->IsTypedArray() || value->IsArgumentsObject())
{ | 169 if (value->IsArray() || value->IsTypedArray() || value->IsArgumentsObject())
{ |
| 190 v8SetReturnValue(info, v8AtomicString(isolate, "array")); | 170 v8SetReturnValue(info, v8AtomicString(isolate, "array")); |
| 191 return; | 171 return; |
| 192 } | 172 } |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 224 || V8HTMLAllCollection::hasInstance(value, isolate)) { | 204 || V8HTMLAllCollection::hasInstance(value, isolate)) { |
| 225 v8SetReturnValue(info, v8AtomicString(isolate, "array")); | 205 v8SetReturnValue(info, v8AtomicString(isolate, "array")); |
| 226 return; | 206 return; |
| 227 } | 207 } |
| 228 if (value->IsNativeError() || V8DOMException::hasInstance(value, isolate)) { | 208 if (value->IsNativeError() || V8DOMException::hasInstance(value, isolate)) { |
| 229 v8SetReturnValue(info, v8AtomicString(isolate, "error")); | 209 v8SetReturnValue(info, v8AtomicString(isolate, "error")); |
| 230 return; | 210 return; |
| 231 } | 211 } |
| 232 } | 212 } |
| 233 | 213 |
| 234 void V8InjectedScriptHost::functionDetailsMethodCustom(const v8::FunctionCallbac
kInfo<v8::Value>& info) | 214 void V8InjectedScriptHost::functionDetailsCallback(const v8::FunctionCallbackInf
o<v8::Value>& info) |
| 235 { | 215 { |
| 236 if (info.Length() < 1 || !info[0]->IsFunction()) | 216 if (info.Length() < 1 || !info[0]->IsFunction()) |
| 237 return; | 217 return; |
| 238 | 218 |
| 239 v8::Local<v8::Function> function = v8::Local<v8::Function>::Cast(info[0]); | 219 v8::Local<v8::Function> function = v8::Local<v8::Function>::Cast(info[0]); |
| 240 int lineNumber = function->GetScriptLineNumber(); | 220 int lineNumber = function->GetScriptLineNumber(); |
| 241 int columnNumber = function->GetScriptColumnNumber(); | 221 int columnNumber = function->GetScriptColumnNumber(); |
| 242 | 222 |
| 243 v8::Isolate* isolate = info.GetIsolate(); | 223 v8::Isolate* isolate = info.GetIsolate(); |
| 244 v8::Local<v8::Object> location = v8::Object::New(isolate); | 224 v8::Local<v8::Object> location = v8::Object::New(isolate); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 256 | 236 |
| 257 InjectedScriptHost* host = V8InjectedScriptHost::toImpl(info.Holder()); | 237 InjectedScriptHost* host = V8InjectedScriptHost::toImpl(info.Holder()); |
| 258 V8Debugger& debugger = host->debugger(); | 238 V8Debugger& debugger = host->debugger(); |
| 259 v8::Local<v8::Value> scopes = debugger.functionScopes(function); | 239 v8::Local<v8::Value> scopes = debugger.functionScopes(function); |
| 260 if (!scopes.IsEmpty() && scopes->IsArray()) | 240 if (!scopes.IsEmpty() && scopes->IsArray()) |
| 261 result->Set(v8AtomicString(isolate, "rawScopes"), scopes); | 241 result->Set(v8AtomicString(isolate, "rawScopes"), scopes); |
| 262 | 242 |
| 263 v8SetReturnValue(info, result); | 243 v8SetReturnValue(info, result); |
| 264 } | 244 } |
| 265 | 245 |
| 266 void V8InjectedScriptHost::generatorObjectDetailsMethodCustom(const v8::Function
CallbackInfo<v8::Value>& info) | 246 void V8InjectedScriptHost::generatorObjectDetailsCallback(const v8::FunctionCall
backInfo<v8::Value>& info) |
| 267 { | 247 { |
| 268 if (info.Length() < 1 || !info[0]->IsObject()) | 248 if (info.Length() < 1 || !info[0]->IsObject()) |
| 269 return; | 249 return; |
| 270 | 250 |
| 271 v8::Local<v8::Object> object = v8::Local<v8::Object>::Cast(info[0]); | 251 v8::Local<v8::Object> object = v8::Local<v8::Object>::Cast(info[0]); |
| 272 | 252 |
| 273 InjectedScriptHost* host = V8InjectedScriptHost::toImpl(info.Holder()); | 253 InjectedScriptHost* host = V8InjectedScriptHost::toImpl(info.Holder()); |
| 274 V8Debugger& debugger = host->debugger(); | 254 V8Debugger& debugger = host->debugger(); |
| 275 v8SetReturnValue(info, debugger.generatorObjectDetails(object)); | 255 v8SetReturnValue(info, debugger.generatorObjectDetails(object)); |
| 276 } | 256 } |
| 277 | 257 |
| 278 void V8InjectedScriptHost::collectionEntriesMethodCustom(const v8::FunctionCallb
ackInfo<v8::Value>& info) | 258 void V8InjectedScriptHost::collectionEntriesCallback(const v8::FunctionCallbackI
nfo<v8::Value>& info) |
| 279 { | 259 { |
| 280 if (info.Length() < 1 || !info[0]->IsObject()) | 260 if (info.Length() < 1 || !info[0]->IsObject()) |
| 281 return; | 261 return; |
| 282 | 262 |
| 283 v8::Local<v8::Object> object = v8::Local<v8::Object>::Cast(info[0]); | 263 v8::Local<v8::Object> object = v8::Local<v8::Object>::Cast(info[0]); |
| 284 | 264 |
| 285 InjectedScriptHost* host = V8InjectedScriptHost::toImpl(info.Holder()); | 265 InjectedScriptHost* host = V8InjectedScriptHost::toImpl(info.Holder()); |
| 286 V8Debugger& debugger = host->debugger(); | 266 V8Debugger& debugger = host->debugger(); |
| 287 v8SetReturnValue(info, debugger.collectionEntries(object)); | 267 v8SetReturnValue(info, debugger.collectionEntries(object)); |
| 288 } | 268 } |
| 289 | 269 |
| 290 void V8InjectedScriptHost::getInternalPropertiesMethodCustom(const v8::FunctionC
allbackInfo<v8::Value>& info) | 270 void V8InjectedScriptHost::getInternalPropertiesCallback(const v8::FunctionCallb
ackInfo<v8::Value>& info) |
| 291 { | 271 { |
| 292 if (info.Length() < 1 || !info[0]->IsObject()) | 272 if (info.Length() < 1 || !info[0]->IsObject()) |
| 293 return; | 273 return; |
| 294 | 274 |
| 295 v8::Local<v8::Object> object = v8::Local<v8::Object>::Cast(info[0]); | 275 v8::Local<v8::Object> object = v8::Local<v8::Object>::Cast(info[0]); |
| 296 v8::MaybeLocal<v8::Array> properties = v8::Debug::GetInternalProperties(info
.GetIsolate(), object); | 276 v8::MaybeLocal<v8::Array> properties = v8::Debug::GetInternalProperties(info
.GetIsolate(), object); |
| 297 v8SetReturnValue(info, properties); | 277 v8SetReturnValue(info, properties); |
| 298 } | 278 } |
| 299 | 279 |
| 300 static v8::Local<v8::Array> getJSListenerFunctions(v8::Isolate* isolate, Executi
onContext* executionContext, const EventListenerInfo& listenerInfo) | 280 static v8::Local<v8::Array> getJSListenerFunctions(v8::Isolate* isolate, Executi
onContext* executionContext, const EventListenerInfo& listenerInfo) |
| (...skipping 21 matching lines...) Expand all Loading... |
| 322 } | 302 } |
| 323 ASSERT(!function.IsEmpty()); | 303 ASSERT(!function.IsEmpty()); |
| 324 v8::Local<v8::Object> listenerEntry = v8::Object::New(isolate); | 304 v8::Local<v8::Object> listenerEntry = v8::Object::New(isolate); |
| 325 listenerEntry->Set(v8AtomicString(isolate, "listener"), function); | 305 listenerEntry->Set(v8AtomicString(isolate, "listener"), function); |
| 326 listenerEntry->Set(v8AtomicString(isolate, "useCapture"), v8::Boolean::N
ew(isolate, listenerInfo.eventListenerVector[i].useCapture)); | 306 listenerEntry->Set(v8AtomicString(isolate, "useCapture"), v8::Boolean::N
ew(isolate, listenerInfo.eventListenerVector[i].useCapture)); |
| 327 result->Set(v8::Number::New(isolate, outputIndex++), listenerEntry); | 307 result->Set(v8::Number::New(isolate, outputIndex++), listenerEntry); |
| 328 } | 308 } |
| 329 return result; | 309 return result; |
| 330 } | 310 } |
| 331 | 311 |
| 332 void V8InjectedScriptHost::getEventListenersMethodCustom(const v8::FunctionCallb
ackInfo<v8::Value>& info) | 312 void V8InjectedScriptHost::getEventListenersCallback(const v8::FunctionCallbackI
nfo<v8::Value>& info) |
| 333 { | 313 { |
| 334 if (info.Length() < 1) | 314 if (info.Length() < 1) |
| 335 return; | 315 return; |
| 336 | 316 |
| 337 EventTarget* target = eventTargetFromScriptValue(info.GetIsolate(), info[0])
; | 317 EventTarget* target = eventTargetFromScriptValue(info.GetIsolate(), info[0])
; |
| 338 if (!target) | 318 if (!target) |
| 339 return; | 319 return; |
| 340 InjectedScriptHost* host = V8InjectedScriptHost::toImpl(info.Holder()); | 320 InjectedScriptHost* host = V8InjectedScriptHost::toImpl(info.Holder()); |
| 341 Vector<EventListenerInfo> listenersArray; | 321 Vector<EventListenerInfo> listenersArray; |
| 342 host->getEventListenersImpl(target, listenersArray); | 322 host->getEventListenersImpl(target, listenersArray); |
| 343 | 323 |
| 344 v8::Local<v8::Object> result = v8::Object::New(info.GetIsolate()); | 324 v8::Local<v8::Object> result = v8::Object::New(info.GetIsolate()); |
| 345 for (size_t i = 0; i < listenersArray.size(); ++i) { | 325 for (size_t i = 0; i < listenersArray.size(); ++i) { |
| 346 v8::Local<v8::Array> listeners = getJSListenerFunctions(info.GetIsolate(
), target->executionContext(), listenersArray[i]); | 326 v8::Local<v8::Array> listeners = getJSListenerFunctions(info.GetIsolate(
), target->executionContext(), listenersArray[i]); |
| 347 if (!listeners->Length()) | 327 if (!listeners->Length()) |
| 348 continue; | 328 continue; |
| 349 AtomicString eventType = listenersArray[i].eventType; | 329 AtomicString eventType = listenersArray[i].eventType; |
| 350 result->Set(v8String(info.GetIsolate(), eventType), listeners); | 330 result->Set(v8String(info.GetIsolate(), eventType), listeners); |
| 351 } | 331 } |
| 352 | 332 |
| 353 v8SetReturnValue(info, result); | 333 v8SetReturnValue(info, result); |
| 354 } | 334 } |
| 355 | 335 |
| 356 void V8InjectedScriptHost::inspectMethodCustom(const v8::FunctionCallbackInfo<v8
::Value>& info) | 336 void V8InjectedScriptHost::inspectCallback(const v8::FunctionCallbackInfo<v8::Va
lue>& info) |
| 357 { | 337 { |
| 358 if (info.Length() < 2) | 338 if (info.Length() < 2) |
| 359 return; | 339 return; |
| 360 | 340 |
| 361 InjectedScriptHost* host = V8InjectedScriptHost::toImpl(info.Holder()); | 341 InjectedScriptHost* host = V8InjectedScriptHost::toImpl(info.Holder()); |
| 362 ScriptState* scriptState = ScriptState::current(info.GetIsolate()); | 342 ScriptState* scriptState = ScriptState::current(info.GetIsolate()); |
| 363 ScriptValue object(scriptState, info[0]); | 343 ScriptValue object(scriptState, info[0]); |
| 364 ScriptValue hints(scriptState, info[1]); | 344 ScriptValue hints(scriptState, info[1]); |
| 365 host->inspectImpl(toJSONValue(object), toJSONValue(hints)); | 345 host->inspectImpl(toJSONValue(object), toJSONValue(hints)); |
| 366 } | 346 } |
| 367 | 347 |
| 368 void V8InjectedScriptHost::evalMethodCustom(const v8::FunctionCallbackInfo<v8::V
alue>& info) | 348 void V8InjectedScriptHost::evalCallback(const v8::FunctionCallbackInfo<v8::Value
>& info) |
| 369 { | 349 { |
| 370 v8::Isolate* isolate = info.GetIsolate(); | 350 v8::Isolate* isolate = info.GetIsolate(); |
| 371 if (info.Length() < 1) { | 351 if (info.Length() < 1) { |
| 372 isolate->ThrowException(v8::Exception::Error(v8::String::NewFromUtf8(iso
late, "One argument expected."))); | 352 isolate->ThrowException(v8::Exception::Error(v8::String::NewFromUtf8(iso
late, "One argument expected."))); |
| 373 return; | 353 return; |
| 374 } | 354 } |
| 375 | 355 |
| 376 v8::Local<v8::String> expression = info[0]->ToString(isolate); | 356 v8::Local<v8::String> expression = info[0]->ToString(isolate); |
| 377 if (expression.IsEmpty()) { | 357 if (expression.IsEmpty()) { |
| 378 isolate->ThrowException(v8::Exception::Error(v8::String::NewFromUtf8(iso
late, "The argument must be a string."))); | 358 isolate->ThrowException(v8::Exception::Error(v8::String::NewFromUtf8(iso
late, "The argument must be a string."))); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 390 } | 370 } |
| 391 | 371 |
| 392 static void setExceptionAsReturnValue(const v8::FunctionCallbackInfo<v8::Value>&
info, v8::Local<v8::Object> returnValue, v8::TryCatch& tryCatch) | 372 static void setExceptionAsReturnValue(const v8::FunctionCallbackInfo<v8::Value>&
info, v8::Local<v8::Object> returnValue, v8::TryCatch& tryCatch) |
| 393 { | 373 { |
| 394 v8::Isolate* isolate = info.GetIsolate(); | 374 v8::Isolate* isolate = info.GetIsolate(); |
| 395 returnValue->Set(v8::String::NewFromUtf8(isolate, "result"), tryCatch.Except
ion()); | 375 returnValue->Set(v8::String::NewFromUtf8(isolate, "result"), tryCatch.Except
ion()); |
| 396 returnValue->Set(v8::String::NewFromUtf8(isolate, "exceptionDetails"), JavaS
criptCallFrame::createExceptionDetails(isolate, tryCatch.Message())); | 376 returnValue->Set(v8::String::NewFromUtf8(isolate, "exceptionDetails"), JavaS
criptCallFrame::createExceptionDetails(isolate, tryCatch.Message())); |
| 397 v8SetReturnValue(info, returnValue); | 377 v8SetReturnValue(info, returnValue); |
| 398 } | 378 } |
| 399 | 379 |
| 400 void V8InjectedScriptHost::evaluateWithExceptionDetailsMethodCustom(const v8::Fu
nctionCallbackInfo<v8::Value>& info) | 380 void V8InjectedScriptHost::evaluateWithExceptionDetailsCallback(const v8::Functi
onCallbackInfo<v8::Value>& info) |
| 401 { | 381 { |
| 402 v8::Isolate* isolate = info.GetIsolate(); | 382 v8::Isolate* isolate = info.GetIsolate(); |
| 403 if (info.Length() < 1) { | 383 if (info.Length() < 1) { |
| 404 isolate->ThrowException(v8::Exception::Error(v8::String::NewFromUtf8(iso
late, "One argument expected."))); | 384 isolate->ThrowException(v8::Exception::Error(v8::String::NewFromUtf8(iso
late, "One argument expected."))); |
| 405 return; | 385 return; |
| 406 } | 386 } |
| 407 | 387 |
| 408 v8::Local<v8::String> expression = info[0]->ToString(isolate); | 388 v8::Local<v8::String> expression = info[0]->ToString(isolate); |
| 409 if (expression.IsEmpty()) { | 389 if (expression.IsEmpty()) { |
| 410 isolate->ThrowException(v8::Exception::Error(v8::String::NewFromUtf8(iso
late, "The argument must be a string."))); | 390 isolate->ThrowException(v8::Exception::Error(v8::String::NewFromUtf8(iso
late, "The argument must be a string."))); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 425 if (!v8Call(V8ScriptRunner::runCompiledScript(isolate, script, currentExecut
ionContext(isolate)), result, tryCatch)) { | 405 if (!v8Call(V8ScriptRunner::runCompiledScript(isolate, script, currentExecut
ionContext(isolate)), result, tryCatch)) { |
| 426 setExceptionAsReturnValue(info, wrappedResult, tryCatch); | 406 setExceptionAsReturnValue(info, wrappedResult, tryCatch); |
| 427 return; | 407 return; |
| 428 } | 408 } |
| 429 | 409 |
| 430 wrappedResult->Set(v8::String::NewFromUtf8(isolate, "result"), result); | 410 wrappedResult->Set(v8::String::NewFromUtf8(isolate, "result"), result); |
| 431 wrappedResult->Set(v8::String::NewFromUtf8(isolate, "exceptionDetails"), v8:
:Undefined(isolate)); | 411 wrappedResult->Set(v8::String::NewFromUtf8(isolate, "exceptionDetails"), v8:
:Undefined(isolate)); |
| 432 v8SetReturnValue(info, wrappedResult); | 412 v8SetReturnValue(info, wrappedResult); |
| 433 } | 413 } |
| 434 | 414 |
| 435 void V8InjectedScriptHost::setFunctionVariableValueMethodCustom(const v8::Functi
onCallbackInfo<v8::Value>& info) | 415 void V8InjectedScriptHost::setFunctionVariableValueCallback(const v8::FunctionCa
llbackInfo<v8::Value>& info) |
| 436 { | 416 { |
| 437 if (info.Length() < 4 || !info[0]->IsFunction() || !info[1]->IsInt32() || !i
nfo[2]->IsString()) | 417 if (info.Length() < 4 || !info[0]->IsFunction() || !info[1]->IsInt32() || !i
nfo[2]->IsString()) |
| 438 return; | 418 return; |
| 439 | 419 |
| 440 v8::Local<v8::Value> functionValue = info[0]; | 420 v8::Local<v8::Value> functionValue = info[0]; |
| 441 int scopeIndex = info[1].As<v8::Int32>()->Value(); | 421 int scopeIndex = info[1].As<v8::Int32>()->Value(); |
| 442 String variableName = toCoreStringWithUndefinedOrNullCheck(info[2]); | 422 String variableName = toCoreStringWithUndefinedOrNullCheck(info[2]); |
| 443 v8::Local<v8::Value> newValue = info[3]; | 423 v8::Local<v8::Value> newValue = info[3]; |
| 444 | 424 |
| 445 InjectedScriptHost* host = V8InjectedScriptHost::toImpl(info.Holder()); | 425 InjectedScriptHost* host = V8InjectedScriptHost::toImpl(info.Holder()); |
| 446 V8Debugger& debugger = host->debugger(); | 426 V8Debugger& debugger = host->debugger(); |
| 447 v8SetReturnValue(info, debugger.setFunctionVariableValue(functionValue, scop
eIndex, variableName, newValue)); | 427 v8SetReturnValue(info, debugger.setFunctionVariableValue(functionValue, scop
eIndex, variableName, newValue)); |
| 448 } | 428 } |
| 449 | 429 |
| 450 static bool getFunctionLocation(const v8::FunctionCallbackInfo<v8::Value>& info,
String* scriptId, int* lineNumber, int* columnNumber) | 430 static bool getFunctionLocation(const v8::FunctionCallbackInfo<v8::Value>& info,
String* scriptId, int* lineNumber, int* columnNumber) |
| 451 { | 431 { |
| 452 if (info.Length() < 1 || !info[0]->IsFunction()) | 432 if (info.Length() < 1 || !info[0]->IsFunction()) |
| 453 return false; | 433 return false; |
| 454 v8::Local<v8::Function> function = v8::Local<v8::Function>::Cast(info[0]); | 434 v8::Local<v8::Function> function = v8::Local<v8::Function>::Cast(info[0]); |
| 455 *lineNumber = function->GetScriptLineNumber(); | 435 *lineNumber = function->GetScriptLineNumber(); |
| 456 *columnNumber = function->GetScriptColumnNumber(); | 436 *columnNumber = function->GetScriptColumnNumber(); |
| 457 if (*lineNumber == v8::Function::kLineOffsetNotFound || *columnNumber == v8:
:Function::kLineOffsetNotFound) | 437 if (*lineNumber == v8::Function::kLineOffsetNotFound || *columnNumber == v8:
:Function::kLineOffsetNotFound) |
| 458 return false; | 438 return false; |
| 459 *scriptId = String::number(function->ScriptId()); | 439 *scriptId = String::number(function->ScriptId()); |
| 460 return true; | 440 return true; |
| 461 } | 441 } |
| 462 | 442 |
| 463 void V8InjectedScriptHost::debugFunctionMethodCustom(const v8::FunctionCallbackI
nfo<v8::Value>& info) | 443 void V8InjectedScriptHost::debugFunctionCallback(const v8::FunctionCallbackInfo<
v8::Value>& info) |
| 464 { | 444 { |
| 465 String scriptId; | 445 String scriptId; |
| 466 int lineNumber; | 446 int lineNumber; |
| 467 int columnNumber; | 447 int columnNumber; |
| 468 if (!getFunctionLocation(info, &scriptId, &lineNumber, &columnNumber)) | 448 if (!getFunctionLocation(info, &scriptId, &lineNumber, &columnNumber)) |
| 469 return; | 449 return; |
| 470 | 450 |
| 471 InjectedScriptHost* host = V8InjectedScriptHost::toImpl(info.Holder()); | 451 InjectedScriptHost* host = V8InjectedScriptHost::toImpl(info.Holder()); |
| 472 host->debugFunction(scriptId, lineNumber, columnNumber); | 452 host->debugFunction(scriptId, lineNumber, columnNumber); |
| 473 } | 453 } |
| 474 | 454 |
| 475 void V8InjectedScriptHost::undebugFunctionMethodCustom(const v8::FunctionCallbac
kInfo<v8::Value>& info) | 455 void V8InjectedScriptHost::undebugFunctionCallback(const v8::FunctionCallbackInf
o<v8::Value>& info) |
| 476 { | 456 { |
| 477 String scriptId; | 457 String scriptId; |
| 478 int lineNumber; | 458 int lineNumber; |
| 479 int columnNumber; | 459 int columnNumber; |
| 480 if (!getFunctionLocation(info, &scriptId, &lineNumber, &columnNumber)) | 460 if (!getFunctionLocation(info, &scriptId, &lineNumber, &columnNumber)) |
| 481 return; | 461 return; |
| 482 | 462 |
| 483 InjectedScriptHost* host = V8InjectedScriptHost::toImpl(info.Holder()); | 463 InjectedScriptHost* host = V8InjectedScriptHost::toImpl(info.Holder()); |
| 484 host->undebugFunction(scriptId, lineNumber, columnNumber); | 464 host->undebugFunction(scriptId, lineNumber, columnNumber); |
| 485 } | 465 } |
| 486 | 466 |
| 487 void V8InjectedScriptHost::monitorFunctionMethodCustom(const v8::FunctionCallbac
kInfo<v8::Value>& info) | 467 void V8InjectedScriptHost::monitorFunctionCallback(const v8::FunctionCallbackInf
o<v8::Value>& info) |
| 488 { | 468 { |
| 489 String scriptId; | 469 String scriptId; |
| 490 int lineNumber; | 470 int lineNumber; |
| 491 int columnNumber; | 471 int columnNumber; |
| 492 if (!getFunctionLocation(info, &scriptId, &lineNumber, &columnNumber)) | 472 if (!getFunctionLocation(info, &scriptId, &lineNumber, &columnNumber)) |
| 493 return; | 473 return; |
| 494 | 474 |
| 495 v8::Local<v8::Value> name; | 475 v8::Local<v8::Value> name; |
| 496 if (info.Length() > 0 && info[0]->IsFunction()) { | 476 if (info.Length() > 0 && info[0]->IsFunction()) { |
| 497 v8::Local<v8::Function> function = v8::Local<v8::Function>::Cast(info[0]
); | 477 v8::Local<v8::Function> function = v8::Local<v8::Function>::Cast(info[0]
); |
| 498 name = function->GetName(); | 478 name = function->GetName(); |
| 499 if (!name->IsString() || !v8::Local<v8::String>::Cast(name)->Length()) | 479 if (!name->IsString() || !v8::Local<v8::String>::Cast(name)->Length()) |
| 500 name = function->GetInferredName(); | 480 name = function->GetInferredName(); |
| 501 } | 481 } |
| 502 | 482 |
| 503 InjectedScriptHost* host = V8InjectedScriptHost::toImpl(info.Holder()); | 483 InjectedScriptHost* host = V8InjectedScriptHost::toImpl(info.Holder()); |
| 504 host->monitorFunction(scriptId, lineNumber, columnNumber, toCoreStringWithUn
definedOrNullCheck(name)); | 484 host->monitorFunction(scriptId, lineNumber, columnNumber, toCoreStringWithUn
definedOrNullCheck(name)); |
| 505 } | 485 } |
| 506 | 486 |
| 507 void V8InjectedScriptHost::unmonitorFunctionMethodCustom(const v8::FunctionCallb
ackInfo<v8::Value>& info) | 487 void V8InjectedScriptHost::unmonitorFunctionCallback(const v8::FunctionCallbackI
nfo<v8::Value>& info) |
| 508 { | 488 { |
| 509 String scriptId; | 489 String scriptId; |
| 510 int lineNumber; | 490 int lineNumber; |
| 511 int columnNumber; | 491 int columnNumber; |
| 512 if (!getFunctionLocation(info, &scriptId, &lineNumber, &columnNumber)) | 492 if (!getFunctionLocation(info, &scriptId, &lineNumber, &columnNumber)) |
| 513 return; | 493 return; |
| 514 | 494 |
| 515 InjectedScriptHost* host = V8InjectedScriptHost::toImpl(info.Holder()); | 495 InjectedScriptHost* host = V8InjectedScriptHost::toImpl(info.Holder()); |
| 516 host->unmonitorFunction(scriptId, lineNumber, columnNumber); | 496 host->unmonitorFunction(scriptId, lineNumber, columnNumber); |
| 517 } | 497 } |
| 518 | 498 |
| 519 void V8InjectedScriptHost::callFunctionMethodCustom(const v8::FunctionCallbackIn
fo<v8::Value>& info) | 499 void V8InjectedScriptHost::callFunctionCallback(const v8::FunctionCallbackInfo<v
8::Value>& info) |
| 520 { | 500 { |
| 521 if (info.Length() < 2 || info.Length() > 3 || !info[0]->IsFunction()) { | 501 if (info.Length() < 2 || info.Length() > 3 || !info[0]->IsFunction()) { |
| 522 ASSERT_NOT_REACHED(); | 502 ASSERT_NOT_REACHED(); |
| 523 return; | 503 return; |
| 524 } | 504 } |
| 525 | 505 |
| 526 v8::Local<v8::Function> function = v8::Local<v8::Function>::Cast(info[0]); | 506 v8::Local<v8::Function> function = v8::Local<v8::Function>::Cast(info[0]); |
| 527 v8::Local<v8::Value> receiver = info[1]; | 507 v8::Local<v8::Value> receiver = info[1]; |
| 528 | 508 |
| 529 if (info.Length() < 3 || info[2]->IsUndefined()) { | 509 if (info.Length() < 3 || info[2]->IsUndefined()) { |
| (...skipping 12 matching lines...) Expand all Loading... |
| 542 OwnPtr<v8::Local<v8::Value>[]> argv = adoptArrayPtr(new v8::Local<v8::Value>
[argc]); | 522 OwnPtr<v8::Local<v8::Value>[]> argv = adoptArrayPtr(new v8::Local<v8::Value>
[argc]); |
| 543 for (size_t i = 0; i < argc; ++i) { | 523 for (size_t i = 0; i < argc; ++i) { |
| 544 if (!arguments->Get(info.GetIsolate()->GetCurrentContext(), v8::Integer:
:New(info.GetIsolate(), i)).ToLocal(&argv[i])) | 524 if (!arguments->Get(info.GetIsolate()->GetCurrentContext(), v8::Integer:
:New(info.GetIsolate(), i)).ToLocal(&argv[i])) |
| 545 return; | 525 return; |
| 546 } | 526 } |
| 547 | 527 |
| 548 v8::Local<v8::Value> result = function->Call(receiver, argc, argv.get()); | 528 v8::Local<v8::Value> result = function->Call(receiver, argc, argv.get()); |
| 549 v8SetReturnValue(info, result); | 529 v8SetReturnValue(info, result); |
| 550 } | 530 } |
| 551 | 531 |
| 552 void V8InjectedScriptHost::suppressWarningsAndCallFunctionMethodCustom(const v8:
:FunctionCallbackInfo<v8::Value>& info) | 532 void V8InjectedScriptHost::suppressWarningsAndCallFunctionCallback(const v8::Fun
ctionCallbackInfo<v8::Value>& info) |
| 553 { | 533 { |
| 554 InjectedScriptHost* host = V8InjectedScriptHost::toImpl(info.Holder()); | 534 InjectedScriptHost* host = V8InjectedScriptHost::toImpl(info.Holder()); |
| 555 host->client()->muteWarningsAndDeprecations(); | 535 host->client()->muteWarningsAndDeprecations(); |
| 556 | 536 |
| 557 callFunctionMethodCustom(info); | 537 callFunctionCallback(info); |
| 558 | 538 |
| 559 host->client()->unmuteWarningsAndDeprecations(); | 539 host->client()->unmuteWarningsAndDeprecations(); |
| 560 } | 540 } |
| 561 | 541 |
| 562 void V8InjectedScriptHost::setNonEnumPropertyMethodCustom(const v8::FunctionCall
backInfo<v8::Value>& info) | 542 void V8InjectedScriptHost::setNonEnumPropertyCallback(const v8::FunctionCallback
Info<v8::Value>& info) |
| 563 { | 543 { |
| 564 if (info.Length() < 3 || !info[0]->IsObject() || !info[1]->IsString()) | 544 if (info.Length() < 3 || !info[0]->IsObject() || !info[1]->IsString()) |
| 565 return; | 545 return; |
| 566 | 546 |
| 567 v8::Local<v8::Object> object = info[0].As<v8::Object>(); | 547 v8::Local<v8::Object> object = info[0].As<v8::Object>(); |
| 568 object->ForceSet(info.GetIsolate()->GetCurrentContext(), info[1], info[2], v
8::DontEnum); | 548 object->ForceSet(info.GetIsolate()->GetCurrentContext(), info[1], info[2], v
8::DontEnum); |
| 569 } | 549 } |
| 570 | 550 |
| 571 void V8InjectedScriptHost::bindMethodCustom(const v8::FunctionCallbackInfo<v8::V
alue>& info) | 551 void V8InjectedScriptHost::bindCallback(const v8::FunctionCallbackInfo<v8::Value
>& info) |
| 572 { | 552 { |
| 573 if (info.Length() < 2 || !info[1]->IsString()) | 553 if (info.Length() < 2 || !info[1]->IsString()) |
| 574 return; | 554 return; |
| 575 InjectedScriptNative* injectedScriptNative = InjectedScriptNative::fromInjec
tedScriptHost(info.Holder()); | 555 InjectedScriptNative* injectedScriptNative = InjectedScriptNative::fromInjec
tedScriptHost(info.Holder()); |
| 576 if (!injectedScriptNative) | 556 if (!injectedScriptNative) |
| 577 return; | 557 return; |
| 578 | 558 |
| 579 v8::Local<v8::String> v8groupName = info[1]->ToString(info.GetIsolate()); | 559 v8::Local<v8::String> v8groupName = info[1]->ToString(info.GetIsolate()); |
| 580 String groupName = toCoreStringWithUndefinedOrNullCheck(v8groupName); | 560 String groupName = toCoreStringWithUndefinedOrNullCheck(v8groupName); |
| 581 int id = injectedScriptNative->bind(info[0], groupName); | 561 int id = injectedScriptNative->bind(info[0], groupName); |
| 582 info.GetReturnValue().Set(id); | 562 info.GetReturnValue().Set(id); |
| 583 } | 563 } |
| 584 | 564 |
| 585 void V8InjectedScriptHost::objectForIdMethodCustom(const v8::FunctionCallbackInf
o<v8::Value>& info) | 565 void V8InjectedScriptHost::objectForIdCallback(const v8::FunctionCallbackInfo<v8
::Value>& info) |
| 586 { | 566 { |
| 587 if (info.Length() < 1 || !info[0]->IsInt32()) | 567 if (info.Length() < 1 || !info[0]->IsInt32()) |
| 588 return; | 568 return; |
| 589 InjectedScriptNative* injectedScriptNative = InjectedScriptNative::fromInjec
tedScriptHost(info.Holder()); | 569 InjectedScriptNative* injectedScriptNative = InjectedScriptNative::fromInjec
tedScriptHost(info.Holder()); |
| 590 if (!injectedScriptNative) | 570 if (!injectedScriptNative) |
| 591 return; | 571 return; |
| 592 int id = info[0].As<v8::Int32>()->Value(); | 572 int id = info[0].As<v8::Int32>()->Value(); |
| 593 v8::Local<v8::Value> value = injectedScriptNative->objectForId(id); | 573 v8::Local<v8::Value> value = injectedScriptNative->objectForId(id); |
| 594 if (!value.IsEmpty()) | 574 if (!value.IsEmpty()) |
| 595 info.GetReturnValue().Set(value); | 575 info.GetReturnValue().Set(value); |
| 596 } | 576 } |
| 597 | 577 |
| 598 void V8InjectedScriptHost::idToObjectGroupNameMethodCustom(const v8::FunctionCal
lbackInfo<v8::Value>& info) | 578 void V8InjectedScriptHost::idToObjectGroupNameCallback(const v8::FunctionCallbac
kInfo<v8::Value>& info) |
| 599 { | 579 { |
| 600 if (info.Length() < 1 || !info[0]->IsInt32()) | 580 if (info.Length() < 1 || !info[0]->IsInt32()) |
| 601 return; | 581 return; |
| 602 InjectedScriptNative* injectedScriptNative = InjectedScriptNative::fromInjec
tedScriptHost(info.Holder()); | 582 InjectedScriptNative* injectedScriptNative = InjectedScriptNative::fromInjec
tedScriptHost(info.Holder()); |
| 603 if (!injectedScriptNative) | 583 if (!injectedScriptNative) |
| 604 return; | 584 return; |
| 605 int id = info[0].As<v8::Int32>()->Value(); | 585 int id = info[0].As<v8::Int32>()->Value(); |
| 606 String groupName = injectedScriptNative->groupName(id); | 586 String groupName = injectedScriptNative->groupName(id); |
| 607 if (!groupName.isEmpty()) | 587 if (!groupName.isEmpty()) |
| 608 info.GetReturnValue().Set(v8String(info.GetIsolate(), groupName)); | 588 info.GetReturnValue().Set(v8String(info.GetIsolate(), groupName)); |
| 609 } | 589 } |
| 610 | 590 |
| 591 namespace { |
| 592 |
| 593 struct V8MethodConfiguration { |
| 594 const char* name; |
| 595 v8::FunctionCallback callback; |
| 596 }; |
| 597 |
| 598 const V8MethodConfiguration V8InjectedScriptHostMethods[] = { |
| 599 {"clearConsoleMessages", V8InjectedScriptHost::clearConsoleMessagesCallback}
, |
| 600 {"inspect", V8InjectedScriptHost::inspectCallback}, |
| 601 {"inspectedObject", V8InjectedScriptHost::inspectedObjectCallback}, |
| 602 {"internalConstructorName", V8InjectedScriptHost::internalConstructorNameCal
lback}, |
| 603 {"isDOMWrapper", V8InjectedScriptHost::isDOMWrapperCallback}, |
| 604 {"isHTMLAllCollection", V8InjectedScriptHost::isHTMLAllCollectionCallback}, |
| 605 {"isTypedArray", V8InjectedScriptHost::isTypedArrayCallback}, |
| 606 {"subtype", V8InjectedScriptHost::subtypeCallback}, |
| 607 {"functionDetails", V8InjectedScriptHost::functionDetailsCallback}, |
| 608 {"generatorObjectDetails", V8InjectedScriptHost::generatorObjectDetailsCallb
ack}, |
| 609 {"collectionEntries", V8InjectedScriptHost::collectionEntriesCallback}, |
| 610 {"getInternalProperties", V8InjectedScriptHost::getInternalPropertiesCallbac
k}, |
| 611 {"getEventListeners", V8InjectedScriptHost::getEventListenersCallback}, |
| 612 {"eval", V8InjectedScriptHost::evalCallback}, |
| 613 {"evaluateWithExceptionDetails", V8InjectedScriptHost::evaluateWithException
DetailsCallback}, |
| 614 {"debugFunction", V8InjectedScriptHost::debugFunctionCallback}, |
| 615 {"undebugFunction", V8InjectedScriptHost::undebugFunctionCallback}, |
| 616 {"monitorFunction", V8InjectedScriptHost::monitorFunctionCallback}, |
| 617 {"unmonitorFunction", V8InjectedScriptHost::unmonitorFunctionCallback}, |
| 618 {"callFunction", V8InjectedScriptHost::callFunctionCallback}, |
| 619 {"suppressWarningsAndCallFunction", V8InjectedScriptHost::suppressWarningsAn
dCallFunctionCallback}, |
| 620 {"setNonEnumProperty", V8InjectedScriptHost::setNonEnumPropertyCallback}, |
| 621 {"setFunctionVariableValue", V8InjectedScriptHost::setFunctionVariableValueC
allback}, |
| 622 {"bind", V8InjectedScriptHost::bindCallback}, |
| 623 {"objectForId", V8InjectedScriptHost::objectForIdCallback}, |
| 624 {"idToObjectGroupName", V8InjectedScriptHost::idToObjectGroupNameCallback}, |
| 625 }; |
| 626 |
| 627 class WeakCallbackData final { |
| 628 public: |
| 629 WeakCallbackData(v8::Isolate* isolate, PassRefPtr<InjectedScriptHost> host,
v8::Local<v8::Object> wrapper) |
| 630 : m_host(host) |
| 631 , m_persistent(isolate, wrapper) |
| 632 { |
| 633 m_persistent.SetWeak(this, &WeakCallbackData::weakCallback, v8::WeakCall
backType::kParameter); |
| 634 } |
| 635 |
| 636 RefPtr<InjectedScriptHost> m_host; |
| 637 |
| 638 private: |
| 639 static void weakCallback(const v8::WeakCallbackInfo<WeakCallbackData>& info) |
| 640 { |
| 641 delete info.GetParameter(); |
| 642 } |
| 643 |
| 644 v8::Global<v8::Object> m_persistent; |
| 645 }; |
| 646 |
| 647 } // namespace |
| 648 |
| 649 v8::Local<v8::FunctionTemplate> V8InjectedScriptHost::createWrapperTemplate(v8::
Isolate* isolate) |
| 650 { |
| 651 v8::Local<v8::FunctionTemplate> functionTemplate = v8::FunctionTemplate::New
(isolate); |
| 652 |
| 653 functionTemplate->SetClassName(v8::String::NewFromUtf8(isolate, "InjectedScr
iptHost", v8::NewStringType::kInternalized).ToLocalChecked()); |
| 654 v8::Local<v8::ObjectTemplate> instanceTemplate = functionTemplate->InstanceT
emplate(); |
| 655 |
| 656 for (auto& config : V8InjectedScriptHostMethods) { |
| 657 v8::Local<v8::Name> v8name = v8::String::NewFromUtf8(isolate, config.nam
e, v8::NewStringType::kInternalized).ToLocalChecked(); |
| 658 v8::Local<v8::FunctionTemplate> functionTemplate = v8::FunctionTemplate:
:New(isolate, config.callback); |
| 659 functionTemplate->RemovePrototype(); |
| 660 instanceTemplate->Set(v8name, functionTemplate, static_cast<v8::Property
Attribute>(v8::DontDelete | v8::DontEnum | v8::ReadOnly)); |
| 661 } |
| 662 |
| 663 return functionTemplate; |
| 664 } |
| 665 |
| 666 v8::Local<v8::Object> V8InjectedScriptHost::wrap(v8::Isolate* isolate, v8::Local
<v8::FunctionTemplate> constructorTemplate, PassRefPtr<InjectedScriptHost> host) |
| 667 { |
| 668 RefPtr<InjectedScriptHost> impl(host); |
| 669 v8::Local<v8::Function> function; |
| 670 if (!constructorTemplate->GetFunction(isolate->GetCurrentContext()).ToLocal(
&function)) |
| 671 return v8::Local<v8::Object>(); |
| 672 |
| 673 // FIXME: don't depend on V8ScriptRunner |
| 674 v8::MaybeLocal<v8::Object> maybeResult = V8ScriptRunner::instantiateObject(i
solate, function); |
| 675 v8::Local<v8::Object> result; |
| 676 if (!maybeResult.ToLocal(&result)) |
| 677 return v8::Local<v8::Object>(); |
| 678 |
| 679 v8::Local<v8::External> objectReference = v8::External::New(isolate, new Wea
kCallbackData(isolate, impl, result)); |
| 680 result->SetHiddenValue(hiddenPropertyName(isolate), objectReference); |
| 681 |
| 682 return result; |
| 683 } |
| 684 |
| 685 InjectedScriptHost* V8InjectedScriptHost::toImpl(v8::Local<v8::Object> object) |
| 686 { |
| 687 v8::Isolate* isolate = object->GetIsolate(); |
| 688 v8::Local<v8::Value> value = object->GetHiddenValue(hiddenPropertyName(isola
te)); |
| 689 if (value.IsEmpty()) |
| 690 return nullptr; |
| 691 if (!value->IsExternal()) |
| 692 return nullptr; |
| 693 void* data = value.As<v8::External>()->Value(); |
| 694 return reinterpret_cast<WeakCallbackData*>(data)->m_host.get(); |
| 695 } |
| 696 |
| 697 v8::Local<v8::String> V8InjectedScriptHost::hiddenPropertyName(v8::Isolate* isol
ate) |
| 698 { |
| 699 return v8::String::NewFromUtf8(isolate, "v8inspector::InjectedScriptHost", v
8::NewStringType::kInternalized).ToLocalChecked(); |
| 700 } |
| 701 |
| 611 } // namespace blink | 702 } // namespace blink |
| OLD | NEW |