diff options
author | Lorry Tar Creator <lorry-tar-importer@lorry> | 2016-05-24 08:28:08 +0000 |
---|---|---|
committer | Lorry Tar Creator <lorry-tar-importer@lorry> | 2016-05-24 08:28:08 +0000 |
commit | a4e969f4965059196ca948db781e52f7cfebf19e (patch) | |
tree | 6ca352808c8fdc52006a0f33f6ae3c593b23867d /Source/JavaScriptCore/inspector/InjectedScriptManager.cpp | |
parent | 41386e9cb918eed93b3f13648cbef387e371e451 (diff) | |
download | WebKitGtk-tarball-a4e969f4965059196ca948db781e52f7cfebf19e.tar.gz |
webkitgtk-2.12.3webkitgtk-2.12.3
Diffstat (limited to 'Source/JavaScriptCore/inspector/InjectedScriptManager.cpp')
-rw-r--r-- | Source/JavaScriptCore/inspector/InjectedScriptManager.cpp | 63 |
1 files changed, 38 insertions, 25 deletions
diff --git a/Source/JavaScriptCore/inspector/InjectedScriptManager.cpp b/Source/JavaScriptCore/inspector/InjectedScriptManager.cpp index 72d20df3e..812ad3d75 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,8 +31,6 @@ #include "config.h" #include "InjectedScriptManager.h" -#if ENABLE(INSPECTOR) - #include "Completion.h" #include "InjectedScriptHost.h" #include "InjectedScriptSource.h" @@ -60,7 +58,13 @@ InjectedScriptManager::~InjectedScriptManager() void InjectedScriptManager::disconnect() { discardInjectedScripts(); - m_injectedScriptHost = nullptr; +} + +void InjectedScriptManager::discardInjectedScripts() +{ + m_injectedScriptHost->clearAllWrappers(); + m_idToInjectedScript.clear(); + m_scriptStateToId.clear(); } InjectedScriptHost* InjectedScriptManager::injectedScriptHost() @@ -95,33 +99,36 @@ 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) @@ -132,9 +139,9 @@ Deprecated::ScriptObject InjectedScriptManager::createInjectedScript(const Strin 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(); @@ -144,11 +151,12 @@ Deprecated::ScriptObject InjectedScriptManager::createInjectedScript(const Strin return Deprecated::ScriptObject(); 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); + scriptState->clearException(); if (result.isObject()) return Deprecated::ScriptObject(scriptState, result.getObject()); @@ -169,17 +177,22 @@ InjectedScript InjectedScriptManager::injectedScriptFor(ExecState* inspectedExec int id = injectedScriptIdFor(inspectedExecState); Deprecated::ScriptObject injectedScriptObject = createInjectedScript(injectedScriptSource(), inspectedExecState, id); + if (injectedScriptObject.scriptState() != inspectedExecState) { + WTFLogAlways("Failed to parse/execute InjectedScriptSource.js!"); + WTFLogAlways("%s\n", injectedScriptSource().ascii().data()); + RELEASE_ASSERT_NOT_REACHED(); + } + InjectedScript result(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) |