Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright (c) 2010, Google Inc. All rights reserved. | 2 * Copyright (c) 2010, 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 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 62 } | 62 } |
| 63 return m_caller.get(); | 63 return m_caller.get(); |
| 64 } | 64 } |
| 65 | 65 |
| 66 int JavaScriptCallFrame::callV8FunctionReturnInt(const char* name) const | 66 int JavaScriptCallFrame::callV8FunctionReturnInt(const char* name) const |
| 67 { | 67 { |
| 68 v8::HandleScope handleScope(m_isolate); | 68 v8::HandleScope handleScope(m_isolate); |
| 69 v8::Context::Scope contextScope(m_debuggerContext.newLocal(m_isolate)); | 69 v8::Context::Scope contextScope(m_debuggerContext.newLocal(m_isolate)); |
| 70 v8::Local<v8::Object> callFrame = m_callFrame.newLocal(m_isolate); | 70 v8::Local<v8::Object> callFrame = m_callFrame.newLocal(m_isolate); |
| 71 v8::Local<v8::Function> func = v8::Local<v8::Function>::Cast(callFrame->Get( v8AtomicString(m_isolate, name))); | 71 v8::Local<v8::Function> func = v8::Local<v8::Function>::Cast(callFrame->Get( v8AtomicString(m_isolate, name))); |
| 72 v8::Local<v8::Value> result = V8ScriptRunner::callInternalFunction(func, cal lFrame, 0, 0, m_isolate); | 72 v8::Local<v8::Value> result; |
| 73 if (result.IsEmpty() || !result->IsInt32()) | 73 if (!V8ScriptRunner::callInternalFunction(func, callFrame, 0, 0, m_isolate). ToLocal(&result) || !result->IsInt32()) |
| 74 return 0; | 74 return 0; |
| 75 return result->Int32Value(); | 75 return result.As<v8::Int32>()->Value(); |
| 76 } | 76 } |
| 77 | 77 |
| 78 String JavaScriptCallFrame::callV8FunctionReturnString(const char* name) const | 78 String JavaScriptCallFrame::callV8FunctionReturnString(const char* name) const |
| 79 { | 79 { |
| 80 v8::HandleScope handleScope(m_isolate); | 80 v8::HandleScope handleScope(m_isolate); |
| 81 v8::Context::Scope contextScope(m_debuggerContext.newLocal(m_isolate)); | 81 v8::Context::Scope contextScope(m_debuggerContext.newLocal(m_isolate)); |
| 82 v8::Local<v8::Object> callFrame = m_callFrame.newLocal(m_isolate); | 82 v8::Local<v8::Object> callFrame = m_callFrame.newLocal(m_isolate); |
| 83 v8::Local<v8::Function> func = v8::Local<v8::Function>::Cast(callFrame->Get( v8AtomicString(m_isolate, name))); | 83 v8::Local<v8::Function> func = v8::Local<v8::Function>::Cast(callFrame->Get( v8AtomicString(m_isolate, name))); |
| 84 v8::Local<v8::Value> result = V8ScriptRunner::callInternalFunction(func, cal lFrame, 0, 0, m_isolate); | 84 v8::Local<v8::Value> result = V8ScriptRunner::callInternalFunction(func, cal lFrame, 0, 0, m_isolate).ToLocalChecked(); |
|
haraken
2015/03/25 12:05:22
Ditto. I guess this callInternalFunction can retur
bashi
2015/03/27 00:39:50
Yes. If we have better option than crash (e.g. ret
yurys
2015/03/27 12:07:24
@aanrey would know better if his place is allowed
bashi
2015/03/31 05:46:08
Changed to return String() since this function see
| |
| 85 return toCoreStringWithUndefinedOrNullCheck(result); | 85 return toCoreStringWithUndefinedOrNullCheck(result); |
| 86 } | 86 } |
| 87 | 87 |
| 88 int JavaScriptCallFrame::sourceID() const | 88 int JavaScriptCallFrame::sourceID() const |
| 89 { | 89 { |
| 90 return callV8FunctionReturnInt("sourceID"); | 90 return callV8FunctionReturnInt("sourceID"); |
| 91 } | 91 } |
| 92 | 92 |
| 93 int JavaScriptCallFrame::line() const | 93 int JavaScriptCallFrame::line() const |
| 94 { | 94 { |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 117 | 117 |
| 118 int JavaScriptCallFrame::functionColumn() const | 118 int JavaScriptCallFrame::functionColumn() const |
| 119 { | 119 { |
| 120 return callV8FunctionReturnInt("functionColumn"); | 120 return callV8FunctionReturnInt("functionColumn"); |
| 121 } | 121 } |
| 122 | 122 |
| 123 v8::Local<v8::Value> JavaScriptCallFrame::scopeChain() const | 123 v8::Local<v8::Value> JavaScriptCallFrame::scopeChain() const |
| 124 { | 124 { |
| 125 v8::Local<v8::Object> callFrame = m_callFrame.newLocal(m_isolate); | 125 v8::Local<v8::Object> callFrame = m_callFrame.newLocal(m_isolate); |
| 126 v8::Local<v8::Function> func = v8::Local<v8::Function>::Cast(callFrame->Get( v8AtomicString(m_isolate, "scopeChain"))); | 126 v8::Local<v8::Function> func = v8::Local<v8::Function>::Cast(callFrame->Get( v8AtomicString(m_isolate, "scopeChain"))); |
| 127 v8::Local<v8::Array> scopeChain = v8::Local<v8::Array>::Cast(V8ScriptRunner: :callInternalFunction(func, callFrame, 0, 0, m_isolate)); | 127 v8::Local<v8::Array> scopeChain = v8::Local<v8::Array>::Cast(V8ScriptRunner: :callInternalFunction(func, callFrame, 0, 0, m_isolate).ToLocalChecked()); |
| 128 v8::Local<v8::Array> result = v8::Array::New(m_isolate, scopeChain->Length() ); | 128 v8::Local<v8::Array> result = v8::Array::New(m_isolate, scopeChain->Length() ); |
| 129 for (uint32_t i = 0; i < scopeChain->Length(); i++) | 129 for (uint32_t i = 0; i < scopeChain->Length(); i++) |
| 130 result->Set(i, scopeChain->Get(i)); | 130 result->Set(i, scopeChain->Get(i)); |
| 131 return result; | 131 return result; |
| 132 } | 132 } |
| 133 | 133 |
| 134 int JavaScriptCallFrame::scopeType(int scopeIndex) const | 134 int JavaScriptCallFrame::scopeType(int scopeIndex) const |
| 135 { | 135 { |
| 136 v8::Local<v8::Object> callFrame = m_callFrame.newLocal(m_isolate); | 136 v8::Local<v8::Object> callFrame = m_callFrame.newLocal(m_isolate); |
| 137 v8::Local<v8::Function> func = v8::Local<v8::Function>::Cast(callFrame->Get( v8AtomicString(m_isolate, "scopeType"))); | 137 v8::Local<v8::Function> func = v8::Local<v8::Function>::Cast(callFrame->Get( v8AtomicString(m_isolate, "scopeType"))); |
| 138 v8::Local<v8::Array> scopeType = v8::Local<v8::Array>::Cast(V8ScriptRunner:: callInternalFunction(func, callFrame, 0, 0, m_isolate)); | 138 v8::Local<v8::Array> scopeType = v8::Local<v8::Array>::Cast(V8ScriptRunner:: callInternalFunction(func, callFrame, 0, 0, m_isolate).ToLocalChecked()); |
| 139 return scopeType->Get(scopeIndex)->Int32Value(); | 139 return scopeType->Get(scopeIndex)->Int32Value(); |
| 140 } | 140 } |
| 141 | 141 |
| 142 v8::Local<v8::Value> JavaScriptCallFrame::thisObject() const | 142 v8::Local<v8::Value> JavaScriptCallFrame::thisObject() const |
| 143 { | 143 { |
| 144 return m_callFrame.newLocal(m_isolate)->Get(v8AtomicString(m_isolate, "thisO bject")); | 144 return m_callFrame.newLocal(m_isolate)->Get(v8AtomicString(m_isolate, "thisO bject")); |
| 145 } | 145 } |
| 146 | 146 |
| 147 String JavaScriptCallFrame::stepInPositions() const | 147 String JavaScriptCallFrame::stepInPositions() const |
| 148 { | 148 { |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 167 ScriptValue JavaScriptCallFrame::evaluateWithExceptionDetails(ScriptState* scrip tState, const String& expression, const ScriptValue& scopeExtension) | 167 ScriptValue JavaScriptCallFrame::evaluateWithExceptionDetails(ScriptState* scrip tState, const String& expression, const ScriptValue& scopeExtension) |
| 168 { | 168 { |
| 169 ScriptState::Scope scriptScope(scriptState); | 169 ScriptState::Scope scriptScope(scriptState); |
| 170 v8::Local<v8::Object> callFrame = m_callFrame.newLocal(m_isolate); | 170 v8::Local<v8::Object> callFrame = m_callFrame.newLocal(m_isolate); |
| 171 v8::Local<v8::Function> evalFunction = v8::Local<v8::Function>::Cast(callFra me->Get(v8AtomicString(m_isolate, "evaluate"))); | 171 v8::Local<v8::Function> evalFunction = v8::Local<v8::Function>::Cast(callFra me->Get(v8AtomicString(m_isolate, "evaluate"))); |
| 172 v8::Local<v8::Value> argv[] = { | 172 v8::Local<v8::Value> argv[] = { |
| 173 v8String(m_debuggerContext.newLocal(m_isolate)->GetIsolate(), expression ), | 173 v8String(m_debuggerContext.newLocal(m_isolate)->GetIsolate(), expression ), |
| 174 scopeExtension.isEmpty() ? v8::Handle<v8::Value>::Cast(v8::Undefined(m_i solate)) : scopeExtension.v8Value() | 174 scopeExtension.isEmpty() ? v8::Handle<v8::Value>::Cast(v8::Undefined(m_i solate)) : scopeExtension.v8Value() |
| 175 }; | 175 }; |
| 176 v8::TryCatch tryCatch; | 176 v8::TryCatch tryCatch; |
| 177 v8::Local<v8::Value> result = V8ScriptRunner::callInternalFunction(evalFunct ion, callFrame, WTF_ARRAY_LENGTH(argv), argv, m_isolate); | |
| 178 | |
| 179 v8::Local<v8::Object> wrappedResult = v8::Object::New(m_isolate); | 177 v8::Local<v8::Object> wrappedResult = v8::Object::New(m_isolate); |
| 180 if (tryCatch.HasCaught()) { | 178 v8::Local<v8::Value> result; |
| 179 if (V8ScriptRunner::callInternalFunction(evalFunction, callFrame, WTF_ARRAY_ LENGTH(argv), argv, m_isolate).ToLocal(&result)) { | |
| 180 wrappedResult->Set(v8::String::NewFromUtf8(m_isolate, "result"), result) ; | |
|
haraken
2015/03/25 12:05:22
Can we replace the v8::String::NewFromUtf8 with v8
yurys
2015/03/25 12:29:25
This is exactly one of the places in devtools code
Yuki
2015/03/25 12:34:01
ToLocalChecked crashes when V8_ENABLE_CHECKS is de
bashi
2015/03/27 00:39:50
Let's use ToLocalChecked() as this is going to be
yurys
2015/03/27 12:07:24
Current implementation with ToLocal call here look
| |
| 181 wrappedResult->Set(v8::String::NewFromUtf8(m_isolate, "exceptionDetails" ), v8::Undefined(m_isolate)); | |
| 182 } else { | |
| 181 wrappedResult->Set(v8::String::NewFromUtf8(m_isolate, "result"), tryCatc h.Exception()); | 183 wrappedResult->Set(v8::String::NewFromUtf8(m_isolate, "result"), tryCatc h.Exception()); |
| 182 wrappedResult->Set(v8::String::NewFromUtf8(m_isolate, "exceptionDetails" ), createExceptionDetails(m_isolate, tryCatch.Message())); | 184 wrappedResult->Set(v8::String::NewFromUtf8(m_isolate, "exceptionDetails" ), createExceptionDetails(m_isolate, tryCatch.Message())); |
| 183 } else { | |
| 184 wrappedResult->Set(v8::String::NewFromUtf8(m_isolate, "result"), result) ; | |
| 185 wrappedResult->Set(v8::String::NewFromUtf8(m_isolate, "exceptionDetails" ), v8::Undefined(m_isolate)); | |
| 186 } | 185 } |
| 187 return ScriptValue(scriptState, wrappedResult); | 186 return ScriptValue(scriptState, wrappedResult); |
| 188 } | 187 } |
| 189 | 188 |
| 190 v8::Local<v8::Value> JavaScriptCallFrame::restart() | 189 v8::Local<v8::Value> JavaScriptCallFrame::restart() |
| 191 { | 190 { |
| 192 v8::Local<v8::Object> callFrame = m_callFrame.newLocal(m_isolate); | 191 v8::Local<v8::Object> callFrame = m_callFrame.newLocal(m_isolate); |
| 193 v8::Local<v8::Function> restartFunction = v8::Local<v8::Function>::Cast(call Frame->Get(v8AtomicString(m_isolate, "restart"))); | 192 v8::Local<v8::Function> restartFunction = v8::Local<v8::Function>::Cast(call Frame->Get(v8AtomicString(m_isolate, "restart"))); |
| 194 v8::Debug::SetLiveEditEnabled(m_isolate, true); | 193 v8::Debug::SetLiveEditEnabled(m_isolate, true); |
| 195 v8::Local<v8::Value> result = V8ScriptRunner::callInternalFunction(restartFu nction, callFrame, 0, 0, m_isolate); | 194 v8::Local<v8::Value> result = V8ScriptRunner::callInternalFunction(restartFu nction, callFrame, 0, 0, m_isolate).ToLocalChecked(); |
| 196 v8::Debug::SetLiveEditEnabled(m_isolate, false); | 195 v8::Debug::SetLiveEditEnabled(m_isolate, false); |
| 197 return result; | 196 return result; |
| 198 } | 197 } |
| 199 | 198 |
| 200 ScriptValue JavaScriptCallFrame::setVariableValue(ScriptState* scriptState, int scopeNumber, const String& variableName, const ScriptValue& newValue) | 199 ScriptValue JavaScriptCallFrame::setVariableValue(ScriptState* scriptState, int scopeNumber, const String& variableName, const ScriptValue& newValue) |
| 201 { | 200 { |
| 202 ScriptState::Scope scriptScope(scriptState); | 201 ScriptState::Scope scriptScope(scriptState); |
| 203 v8::Local<v8::Object> callFrame = m_callFrame.newLocal(m_isolate); | 202 v8::Local<v8::Object> callFrame = m_callFrame.newLocal(m_isolate); |
| 204 v8::Local<v8::Function> setVariableValueFunction = v8::Local<v8::Function>:: Cast(callFrame->Get(v8AtomicString(m_isolate, "setVariableValue"))); | 203 v8::Local<v8::Function> setVariableValueFunction = v8::Local<v8::Function>:: Cast(callFrame->Get(v8AtomicString(m_isolate, "setVariableValue"))); |
| 205 v8::Local<v8::Value> argv[] = { | 204 v8::Local<v8::Value> argv[] = { |
| 206 v8::Local<v8::Value>(v8::Integer::New(m_isolate, scopeNumber)), | 205 v8::Local<v8::Value>(v8::Integer::New(m_isolate, scopeNumber)), |
| 207 v8String(m_isolate, variableName), | 206 v8String(m_isolate, variableName), |
| 208 newValue.v8Value() | 207 newValue.v8Value() |
| 209 }; | 208 }; |
| 210 return ScriptValue(scriptState, V8ScriptRunner::callInternalFunction(setVari ableValueFunction, callFrame, WTF_ARRAY_LENGTH(argv), argv, m_isolate)); | 209 return ScriptValue(scriptState, V8ScriptRunner::callInternalFunction(setVari ableValueFunction, callFrame, WTF_ARRAY_LENGTH(argv), argv, m_isolate).ToLocalCh ecked()); |
|
yurys
2015/03/27 12:07:24
In this case we may well fail to change local vari
bashi
2015/03/31 05:46:08
Thanks. Replaced with ToLocal(). In blink, we deci
| |
| 211 } | 210 } |
| 212 | 211 |
| 213 v8::Local<v8::Object> JavaScriptCallFrame::createExceptionDetails(v8::Isolate* i solate, v8::Local<v8::Message> message) | 212 v8::Local<v8::Object> JavaScriptCallFrame::createExceptionDetails(v8::Isolate* i solate, v8::Local<v8::Message> message) |
| 214 { | 213 { |
| 215 v8::Local<v8::Object> exceptionDetails = v8::Object::New(isolate); | 214 v8::Local<v8::Object> exceptionDetails = v8::Object::New(isolate); |
| 216 exceptionDetails->Set(v8::String::NewFromUtf8(isolate, "text"), message->Get ()); | 215 exceptionDetails->Set(v8::String::NewFromUtf8(isolate, "text"), message->Get ()); |
| 217 exceptionDetails->Set(v8::String::NewFromUtf8(isolate, "url"), message->GetS criptOrigin().ResourceName()); | 216 exceptionDetails->Set(v8::String::NewFromUtf8(isolate, "url"), message->GetS criptOrigin().ResourceName()); |
| 218 exceptionDetails->Set(v8::String::NewFromUtf8(isolate, "scriptId"), v8::Inte ger::New(isolate, message->GetScriptOrigin().ScriptID()->Value())); | 217 exceptionDetails->Set(v8::String::NewFromUtf8(isolate, "scriptId"), v8::Inte ger::New(isolate, message->GetScriptOrigin().ScriptID()->Value())); |
| 219 exceptionDetails->Set(v8::String::NewFromUtf8(isolate, "line"), v8::Integer: :New(isolate, message->GetLineNumber())); | 218 exceptionDetails->Set(v8::String::NewFromUtf8(isolate, "line"), v8::Integer: :New(isolate, message->GetLineNumber())); |
| 220 exceptionDetails->Set(v8::String::NewFromUtf8(isolate, "column"), v8::Intege r::New(isolate, message->GetStartColumn())); | 219 exceptionDetails->Set(v8::String::NewFromUtf8(isolate, "column"), v8::Intege r::New(isolate, message->GetStartColumn())); |
| 221 if (!message->GetStackTrace().IsEmpty()) | 220 if (!message->GetStackTrace().IsEmpty()) |
| 222 exceptionDetails->Set(v8::String::NewFromUtf8(isolate, "stackTrace"), me ssage->GetStackTrace()->AsArray()); | 221 exceptionDetails->Set(v8::String::NewFromUtf8(isolate, "stackTrace"), me ssage->GetStackTrace()->AsArray()); |
| 223 else | 222 else |
| 224 exceptionDetails->Set(v8::String::NewFromUtf8(isolate, "stackTrace"), v8 ::Undefined(isolate)); | 223 exceptionDetails->Set(v8::String::NewFromUtf8(isolate, "stackTrace"), v8 ::Undefined(isolate)); |
| 225 return exceptionDetails; | 224 return exceptionDetails; |
| 226 } | 225 } |
| 227 | 226 |
| 228 DEFINE_TRACE(JavaScriptCallFrame) | 227 DEFINE_TRACE(JavaScriptCallFrame) |
| 229 { | 228 { |
| 230 visitor->trace(m_caller); | 229 visitor->trace(m_caller); |
| 231 } | 230 } |
| 232 | 231 |
| 233 } // namespace blink | 232 } // namespace blink |
| OLD | NEW |