/* * Copyright (C) 2012 Google Inc. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following disclaimer * in the documentation and/or other materials provided with the * distribution. * * Neither the name of Google Inc. nor the names of its * contributors may be used to endorse or promote products derived from * this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef V8_INSPECTOR_INJECTEDSCRIPT_H_ #define V8_INSPECTOR_INJECTEDSCRIPT_H_ #include "src/base/macros.h" #include "src/inspector/injected-script-native.h" #include "src/inspector/inspected-context.h" #include "src/inspector/protocol/Forward.h" #include "src/inspector/protocol/Runtime.h" #include "src/inspector/v8-console.h" #include "src/inspector/v8-debugger.h" #include "include/v8.h" namespace v8_inspector { class RemoteObjectId; class V8FunctionCall; class V8InspectorImpl; class V8InspectorSessionImpl; using protocol::Maybe; using protocol::Response; class InjectedScript final { public: static std::unique_ptr create(InspectedContext*); ~InjectedScript(); InspectedContext* context() const { return m_context; } Response getProperties( v8::Local, const String16& groupName, bool ownProperties, bool accessorPropertiesOnly, bool generatePreview, std::unique_ptr>* result, Maybe*); void releaseObject(const String16& objectId); Response wrapObject( v8::Local, const String16& groupName, bool forceValueType, bool generatePreview, std::unique_ptr* result) const; Response wrapObjectProperty(v8::Local, v8::Local key, const String16& groupName, bool forceValueType = false, bool generatePreview = false) const; Response wrapPropertyInArray(v8::Local, v8::Local property, const String16& groupName, bool forceValueType = false, bool generatePreview = false) const; std::unique_ptr wrapTable( v8::Local table, v8::Local columns) const; Response findObject(const RemoteObjectId&, v8::Local*) const; String16 objectGroupName(const RemoteObjectId&) const; void releaseObjectGroup(const String16&); void setCustomObjectFormatterEnabled(bool); Response resolveCallArgument(protocol::Runtime::CallArgument*, v8::Local* result); Response createExceptionDetails( const v8::TryCatch&, const String16& groupName, bool generatePreview, Maybe* result); Response wrapEvaluateResult( v8::MaybeLocal maybeResultValue, const v8::TryCatch&, const String16& objectGroup, bool returnByValue, bool generatePreview, std::unique_ptr* result, Maybe*); v8::Local lastEvaluationResult() const; class Scope { public: Response initialize(); void installCommandLineAPI(); void ignoreExceptionsAndMuteConsole(); void pretendUserGesture(); v8::Local context() const { return m_context; } InjectedScript* injectedScript() const { return m_injectedScript; } const v8::TryCatch& tryCatch() const { return m_tryCatch; } protected: Scope(V8InspectorImpl*, int contextGroupId); virtual ~Scope(); virtual Response findInjectedScript(V8InspectorSessionImpl*) = 0; V8InspectorImpl* m_inspector; int m_contextGroupId; InjectedScript* m_injectedScript; private: void cleanup(); v8::debug::ExceptionBreakState setPauseOnExceptionsState( v8::debug::ExceptionBreakState); v8::HandleScope m_handleScope; v8::TryCatch m_tryCatch; v8::Local m_context; std::unique_ptr m_commandLineAPIScope; bool m_ignoreExceptionsAndMuteConsole; v8::debug::ExceptionBreakState m_previousPauseOnExceptionsState; bool m_userGesture; }; class ContextScope : public Scope { public: ContextScope(V8InspectorImpl*, int contextGroupId, int executionContextId); ~ContextScope(); private: Response findInjectedScript(V8InspectorSessionImpl*) override; int m_executionContextId; DISALLOW_COPY_AND_ASSIGN(ContextScope); }; class ObjectScope : public Scope { public: ObjectScope(V8InspectorImpl*, int contextGroupId, const String16& remoteObjectId); ~ObjectScope(); const String16& objectGroupName() const { return m_objectGroupName; } v8::Local object() const { return m_object; } private: Response findInjectedScript(V8InspectorSessionImpl*) override; String16 m_remoteObjectId; String16 m_objectGroupName; v8::Local m_object; DISALLOW_COPY_AND_ASSIGN(ObjectScope); }; class CallFrameScope : public Scope { public: CallFrameScope(V8InspectorImpl*, int contextGroupId, const String16& remoteCallFrameId); ~CallFrameScope(); size_t frameOrdinal() const { return m_frameOrdinal; } private: Response findInjectedScript(V8InspectorSessionImpl*) override; String16 m_remoteCallFrameId; size_t m_frameOrdinal; DISALLOW_COPY_AND_ASSIGN(CallFrameScope); }; private: InjectedScript(InspectedContext*, v8::Local, std::unique_ptr); v8::Local v8Value() const; Response wrapValue(v8::Local, const String16& groupName, bool forceValueType, bool generatePreview, v8::Local* result) const; v8::Local commandLineAPI(); InspectedContext* m_context; v8::Global m_value; v8::Global m_lastEvaluationResult; std::unique_ptr m_native; v8::Global m_commandLineAPI; DISALLOW_COPY_AND_ASSIGN(InjectedScript); }; } // namespace v8_inspector #endif // V8_INSPECTOR_INJECTEDSCRIPT_H_