diff options
Diffstat (limited to 'Source/JavaScriptCore/inspector/InjectedScriptManager.cpp')
-rw-r--r-- | Source/JavaScriptCore/inspector/InjectedScriptManager.cpp | 93 |
1 files changed, 53 insertions, 40 deletions
diff --git a/Source/JavaScriptCore/inspector/InjectedScriptManager.cpp b/Source/JavaScriptCore/inspector/InjectedScriptManager.cpp index 72d20df3e..097615b10 100644 --- a/Source/JavaScriptCore/inspector/InjectedScriptManager.cpp +++ b/Source/JavaScriptCore/inspector/InjectedScriptManager.cpp @@ -12,7 +12,7 @@ * 2. 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. - * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of + * 3. Neither the name of Apple Inc. ("Apple") nor the names of * its contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * @@ -31,12 +31,11 @@ #include "config.h" #include "InjectedScriptManager.h" -#if ENABLE(INSPECTOR) - #include "Completion.h" #include "InjectedScriptHost.h" #include "InjectedScriptSource.h" #include "InspectorValues.h" +#include "JSCInlines.h" #include "JSInjectedScriptHost.h" #include "JSLock.h" #include "ScriptObject.h" @@ -46,9 +45,9 @@ using namespace JSC; namespace Inspector { -InjectedScriptManager::InjectedScriptManager(InspectorEnvironment& environment, PassRefPtr<InjectedScriptHost> injectedScriptHost) +InjectedScriptManager::InjectedScriptManager(InspectorEnvironment& environment, Ref<InjectedScriptHost>&& injectedScriptHost) : m_environment(environment) - , m_injectedScriptHost(injectedScriptHost) + , m_injectedScriptHost(WTFMove(injectedScriptHost)) , m_nextInjectedScriptId(1) { } @@ -60,10 +59,16 @@ InjectedScriptManager::~InjectedScriptManager() void InjectedScriptManager::disconnect() { discardInjectedScripts(); - m_injectedScriptHost = nullptr; } -InjectedScriptHost* InjectedScriptManager::injectedScriptHost() +void InjectedScriptManager::discardInjectedScripts() +{ + m_injectedScriptHost->clearAllWrappers(); + m_idToInjectedScript.clear(); + m_scriptStateToId.clear(); +} + +InjectedScriptHost& InjectedScriptManager::injectedScriptHost() { return m_injectedScriptHost.get(); } @@ -95,64 +100,67 @@ int InjectedScriptManager::injectedScriptIdFor(ExecState* scriptState) InjectedScript InjectedScriptManager::injectedScriptForObjectId(const String& objectId) { - RefPtr<InspectorValue> parsedObjectId = InspectorValue::parseJSON(objectId); - if (parsedObjectId && parsedObjectId->type() == InspectorValue::TypeObject) { - long injectedScriptId = 0; - bool success = parsedObjectId->asObject()->getNumber(ASCIILiteral("injectedScriptId"), &injectedScriptId); - if (success) - return m_idToInjectedScript.get(injectedScriptId); - } + RefPtr<InspectorValue> parsedObjectId; + if (!InspectorValue::parseJSON(objectId, parsedObjectId)) + return InjectedScript(); - return InjectedScript(); + RefPtr<InspectorObject> resultObject; + if (!parsedObjectId->asObject(resultObject)) + return InjectedScript(); + + long injectedScriptId = 0; + if (!resultObject->getInteger(ASCIILiteral("injectedScriptId"), injectedScriptId)) + return InjectedScript(); + + return m_idToInjectedScript.get(injectedScriptId); } -void InjectedScriptManager::discardInjectedScripts() +void InjectedScriptManager::releaseObjectGroup(const String& objectGroup) { - m_injectedScriptHost->clearAllWrappers(); - m_idToInjectedScript.clear(); - m_scriptStateToId.clear(); + for (auto& injectedScript : m_idToInjectedScript.values()) + injectedScript.releaseObjectGroup(objectGroup); } -void InjectedScriptManager::releaseObjectGroup(const String& objectGroup) +void InjectedScriptManager::clearExceptionValue() { - for (auto it = m_idToInjectedScript.begin(); it != m_idToInjectedScript.end(); ++it) - it->value.releaseObjectGroup(objectGroup); + for (auto& injectedScript : m_idToInjectedScript.values()) + injectedScript.clearExceptionValue(); } String InjectedScriptManager::injectedScriptSource() { - return String(reinterpret_cast<const char*>(InjectedScriptSource_js), sizeof(InjectedScriptSource_js)); + return StringImpl::createWithoutCopying(InjectedScriptSource_js, sizeof(InjectedScriptSource_js)); } -Deprecated::ScriptObject InjectedScriptManager::createInjectedScript(const String& source, ExecState* scriptState, int id) +JSC::JSObject* InjectedScriptManager::createInjectedScript(const String& source, ExecState* scriptState, int id) { - JSLockHolder lock(scriptState); + VM& vm = scriptState->vm(); + JSLockHolder lock(vm); + auto scope = DECLARE_CATCH_SCOPE(vm); - SourceCode sourceCode = makeSource(source); + SourceCode sourceCode = makeSource(source, { }); JSGlobalObject* globalObject = scriptState->lexicalGlobalObject(); JSValue globalThisValue = scriptState->globalThisValue(); - JSValue evaluationException; + NakedPtr<Exception> evaluationException; InspectorEvaluateHandler evaluateHandler = m_environment.evaluateHandler(); - JSValue functionValue = evaluateHandler(scriptState, sourceCode, globalThisValue, &evaluationException); + JSValue functionValue = evaluateHandler(scriptState, sourceCode, globalThisValue, evaluationException); if (evaluationException) - return Deprecated::ScriptObject(); + return nullptr; CallData callData; CallType callType = getCallData(functionValue, callData); - if (callType == CallTypeNone) - return Deprecated::ScriptObject(); + if (callType == CallType::None) + return nullptr; MarkedArgumentBuffer args; - args.append(m_injectedScriptHost->jsWrapper(scriptState, globalObject)); + args.append(m_injectedScriptHost->wrapper(scriptState, globalObject)); args.append(globalThisValue); args.append(jsNumber(id)); JSValue result = JSC::call(scriptState, functionValue, callType, callData, globalThisValue, args); - if (result.isObject()) - return Deprecated::ScriptObject(scriptState, result.getObject()); - - return Deprecated::ScriptObject(); + scope.clearException(); + return result.getObject(); } InjectedScript InjectedScriptManager::injectedScriptFor(ExecState* inspectedExecState) @@ -168,18 +176,23 @@ InjectedScript InjectedScriptManager::injectedScriptFor(ExecState* inspectedExec return InjectedScript(); int id = injectedScriptIdFor(inspectedExecState); - Deprecated::ScriptObject injectedScriptObject = createInjectedScript(injectedScriptSource(), inspectedExecState, id); - InjectedScript result(injectedScriptObject, &m_environment); + auto injectedScriptObject = createInjectedScript(injectedScriptSource(), inspectedExecState, id); + if (!injectedScriptObject) { + WTFLogAlways("Failed to parse/execute InjectedScriptSource.js!"); + WTFLogAlways("%s\n", injectedScriptSource().ascii().data()); + RELEASE_ASSERT_NOT_REACHED(); + } + + InjectedScript result({ inspectedExecState, injectedScriptObject }, &m_environment); m_idToInjectedScript.set(id, result); didCreateInjectedScript(result); return result; } -void InjectedScriptManager::didCreateInjectedScript(InjectedScript) +void InjectedScriptManager::didCreateInjectedScript(const InjectedScript&) { // Intentionally empty. This allows for subclasses to inject additional scripts. } } // namespace Inspector -#endif // ENABLE(INSPECTOR) |