OLD | NEW |
---|---|
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "platform/v8_inspector/V8InjectedScriptHost.h" | 5 #include "platform/v8_inspector/V8InjectedScriptHost.h" |
6 | 6 |
7 #include "platform/inspector_protocol/Values.h" | 7 #include "platform/inspector_protocol/Values.h" |
8 #include "platform/v8_inspector/InjectedScript.h" | 8 #include "platform/v8_inspector/InjectedScript.h" |
9 #include "platform/v8_inspector/InjectedScriptHost.h" | 9 #include "platform/v8_inspector/InjectedScriptHost.h" |
10 #include "platform/v8_inspector/InspectorWrapper.h" | 10 #include "platform/v8_inspector/InspectorWrapper.h" |
(...skipping 270 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
281 } | 281 } |
282 | 282 |
283 v8::Local<v8::String> expression = info[0]->ToString(isolate); | 283 v8::Local<v8::String> expression = info[0]->ToString(isolate); |
284 if (expression.IsEmpty()) { | 284 if (expression.IsEmpty()) { |
285 isolate->ThrowException(v8::Exception::Error(v8::String::NewFromUtf8(iso late, "The argument must be a string."))); | 285 isolate->ThrowException(v8::Exception::Error(v8::String::NewFromUtf8(iso late, "The argument must be a string."))); |
286 return; | 286 return; |
287 } | 287 } |
288 | 288 |
289 ASSERT(isolate->InContext()); | 289 ASSERT(isolate->InContext()); |
290 v8::TryCatch tryCatch(isolate); | 290 v8::TryCatch tryCatch(isolate); |
291 v8::Local<v8::Value> result; | |
292 InjectedScriptHost* host = V8InjectedScriptHost::unwrap(isolate->GetCurrentC ontext(), info.Holder()); | 291 InjectedScriptHost* host = V8InjectedScriptHost::unwrap(isolate->GetCurrentC ontext(), info.Holder()); |
293 if (!host->debugger()) | 292 if (!host->debugger()) |
294 return; | 293 return; |
295 if (!host->debugger()->client()->compileAndRunInternalScript(expression).ToL ocal(&result)) { | 294 v8::Local<v8::Value> result = host->debugger()->compileAndRunInternalScript( isolate->GetCurrentContext(), expression); |
pfeldman
2016/03/08 20:23:21
Do we have to change the contract here? Returning
dgozman
2016/03/09 22:01:53
Yeah, lost in transition. Reverted back.
| |
295 if (result.IsEmpty()) { | |
296 v8SetReturnValue(info, tryCatch.ReThrow()); | 296 v8SetReturnValue(info, tryCatch.ReThrow()); |
297 return; | 297 return; |
298 } | 298 } |
299 v8SetReturnValue(info, result); | 299 v8SetReturnValue(info, result); |
300 } | 300 } |
301 | 301 |
302 static void setExceptionAsReturnValue(const v8::FunctionCallbackInfo<v8::Value>& info, v8::Local<v8::Object> returnValue, v8::TryCatch& tryCatch) | 302 static void setExceptionAsReturnValue(const v8::FunctionCallbackInfo<v8::Value>& info, v8::Local<v8::Object> returnValue, v8::TryCatch& tryCatch) |
303 { | 303 { |
304 v8::Isolate* isolate = info.GetIsolate(); | 304 v8::Isolate* isolate = info.GetIsolate(); |
305 returnValue->Set(v8::String::NewFromUtf8(isolate, "result"), tryCatch.Except ion()); | 305 returnValue->Set(v8::String::NewFromUtf8(isolate, "result"), tryCatch.Except ion()); |
(...skipping 19 matching lines...) Expand all Loading... | |
325 v8::Local<v8::Object> wrappedResult = v8::Object::New(isolate); | 325 v8::Local<v8::Object> wrappedResult = v8::Object::New(isolate); |
326 if (wrappedResult.IsEmpty()) | 326 if (wrappedResult.IsEmpty()) |
327 return; | 327 return; |
328 | 328 |
329 v8::TryCatch tryCatch(isolate); | 329 v8::TryCatch tryCatch(isolate); |
330 v8::Local<v8::Context> context = isolate->GetCurrentContext(); | 330 v8::Local<v8::Context> context = isolate->GetCurrentContext(); |
331 InjectedScriptHost* host = V8InjectedScriptHost::unwrap(context, info.Holder ()); | 331 InjectedScriptHost* host = V8InjectedScriptHost::unwrap(context, info.Holder ()); |
332 if (!host->debugger()) | 332 if (!host->debugger()) |
333 return; | 333 return; |
334 | 334 |
335 // TODO(dgozman): get rid of this check. | |
336 if (!host->debugger()->client()->isExecutionAllowed()) | |
pfeldman
2016/03/08 20:23:21
ditto
dgozman
2016/03/09 22:01:53
Done.
| |
337 return; | |
338 | |
335 v8::Local<v8::Script> script = host->debugger()->compileInternalScript(conte xt, expression, String()); | 339 v8::Local<v8::Script> script = host->debugger()->compileInternalScript(conte xt, expression, String()); |
336 if (script.IsEmpty()) { | 340 if (script.IsEmpty()) { |
337 setExceptionAsReturnValue(info, wrappedResult, tryCatch); | 341 setExceptionAsReturnValue(info, wrappedResult, tryCatch); |
338 return; | 342 return; |
339 } | 343 } |
340 | 344 |
341 v8::Local<v8::Symbol> commandLineAPISymbolValue = V8Debugger::commandLineAPI Symbol(isolate); | 345 v8::Local<v8::Symbol> commandLineAPISymbolValue = V8Debugger::commandLineAPI Symbol(isolate); |
342 v8::Local<v8::Object> global = context->Global(); | 346 v8::Local<v8::Object> global = context->Global(); |
343 if (info.Length() >= 2 && info[1]->IsObject()) { | 347 if (info.Length() >= 2 && info[1]->IsObject()) { |
344 v8::Local<v8::Object> commandLineAPI = info[1]->ToObject(isolate); | 348 v8::Local<v8::Object> commandLineAPI = info[1]->ToObject(isolate); |
345 global->Set(commandLineAPISymbolValue, commandLineAPI); | 349 global->Set(commandLineAPISymbolValue, commandLineAPI); |
346 } | 350 } |
347 | 351 |
348 v8::MaybeLocal<v8::Value> result = host->debugger()->client()->runCompiledSc ript(context, script); | 352 v8::MaybeLocal<v8::Value> result = host->debugger()->runCompiledScript(conte xt, script); |
349 if (result.IsEmpty()) { | 353 if (result.IsEmpty()) { |
350 global->Delete(context, commandLineAPISymbolValue); | 354 global->Delete(context, commandLineAPISymbolValue); |
351 setExceptionAsReturnValue(info, wrappedResult, tryCatch); | 355 setExceptionAsReturnValue(info, wrappedResult, tryCatch); |
352 return; | 356 return; |
353 } | 357 } |
354 | 358 |
355 global->Delete(context, commandLineAPISymbolValue); | 359 global->Delete(context, commandLineAPISymbolValue); |
356 wrappedResult->Set(v8::String::NewFromUtf8(isolate, "result"), result.ToLoca lChecked()); | 360 wrappedResult->Set(v8::String::NewFromUtf8(isolate, "result"), result.ToLoca lChecked()); |
357 wrappedResult->Set(v8::String::NewFromUtf8(isolate, "exceptionDetails"), v8: :Undefined(isolate)); | 361 wrappedResult->Set(v8::String::NewFromUtf8(isolate, "exceptionDetails"), v8: :Undefined(isolate)); |
358 v8SetReturnValue(info, wrappedResult); | 362 v8SetReturnValue(info, wrappedResult); |
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
591 } // namespace | 595 } // namespace |
592 | 596 |
593 v8::Local<v8::FunctionTemplate> V8InjectedScriptHost::createWrapperTemplate(v8:: Isolate* isolate) | 597 v8::Local<v8::FunctionTemplate> V8InjectedScriptHost::createWrapperTemplate(v8:: Isolate* isolate) |
594 { | 598 { |
595 protocol::Vector<InspectorWrapperBase::V8MethodConfiguration> methods(WTF_AR RAY_LENGTH(V8InjectedScriptHostMethods)); | 599 protocol::Vector<InspectorWrapperBase::V8MethodConfiguration> methods(WTF_AR RAY_LENGTH(V8InjectedScriptHostMethods)); |
596 std::copy(V8InjectedScriptHostMethods, V8InjectedScriptHostMethods + WTF_ARR AY_LENGTH(V8InjectedScriptHostMethods), methods.begin()); | 600 std::copy(V8InjectedScriptHostMethods, V8InjectedScriptHostMethods + WTF_ARR AY_LENGTH(V8InjectedScriptHostMethods), methods.begin()); |
597 protocol::Vector<InspectorWrapperBase::V8AttributeConfiguration> attributes; | 601 protocol::Vector<InspectorWrapperBase::V8AttributeConfiguration> attributes; |
598 return InjectedScriptHostWrapper::createWrapperTemplate(isolate, methods, at tributes); | 602 return InjectedScriptHostWrapper::createWrapperTemplate(isolate, methods, at tributes); |
599 } | 603 } |
600 | 604 |
601 v8::Local<v8::Object> V8InjectedScriptHost::wrap(V8DebuggerClient* client, v8::L ocal<v8::FunctionTemplate> constructorTemplate, v8::Local<v8::Context> context, InjectedScriptHost* host) | 605 v8::Local<v8::Object> V8InjectedScriptHost::wrap(v8::Local<v8::FunctionTemplate> constructorTemplate, v8::Local<v8::Context> context, InjectedScriptHost* host) |
602 { | 606 { |
603 return InjectedScriptHostWrapper::wrap(client, constructorTemplate, context, host); | 607 return InjectedScriptHostWrapper::wrap(constructorTemplate, context, host); |
604 } | 608 } |
605 | 609 |
606 InjectedScriptHost* V8InjectedScriptHost::unwrap(v8::Local<v8::Context> context, v8::Local<v8::Object> object) | 610 InjectedScriptHost* V8InjectedScriptHost::unwrap(v8::Local<v8::Context> context, v8::Local<v8::Object> object) |
607 { | 611 { |
608 return InjectedScriptHostWrapper::unwrap(context, object); | 612 return InjectedScriptHostWrapper::unwrap(context, object); |
609 } | 613 } |
610 | 614 |
611 } // namespace blink | 615 } // namespace blink |
OLD | NEW |