Diff
Modified: trunk/Source/_javascript_Core/ChangeLog (250123 => 250124)
--- trunk/Source/_javascript_Core/ChangeLog 2019-09-20 07:09:59 UTC (rev 250123)
+++ trunk/Source/_javascript_Core/ChangeLog 2019-09-20 08:28:09 UTC (rev 250124)
@@ -1,3 +1,41 @@
+2019-09-20 Devin Rousso <[email protected]>
+
+ ASSERT NOT REACHED in Inspector::InjectedScriptModule::ensureInjected() seen with inspector/heap/getRemoteObject.html
+ https://bugs.webkit.org/show_bug.cgi?id=201713
+ <rdar://problem/55290349>
+
+ Reviewed by Joseph Pecoraro.
+
+ Expose the `Exception` object by leveraging an `Expected` of `JSValue` as the return value
+ instead of using a referenced `bool` (which wouldn't include any of the exception's info).
+
+ * bindings/ScriptFunctionCall.h:
+ * bindings/ScriptFunctionCall.cpp:
+ (Deprecated::ScriptFunctionCall::call):
+
+ * inspector/InjectedScript.cpp:
+ (Inspector::InjectedScript::wrapCallFrames const):
+ (Inspector::InjectedScript::wrapObject const):
+ (Inspector::InjectedScript::wrapJSONString const):
+ (Inspector::InjectedScript::wrapTable const):
+ (Inspector::InjectedScript::previewValue const):
+ (Inspector::InjectedScript::findObjectById const):
+ (Inspector::InjectedScript::releaseObjectGroup):
+
+ * inspector/InjectedScriptBase.h:
+ * inspector/InjectedScriptBase.cpp:
+ (Inspector::InjectedScriptBase::callFunctionWithEvalEnabled const):
+ (Inspector::InjectedScriptBase::makeCall):
+ (Inspector::InjectedScriptBase::makeAsyncCall):
+
+ * inspector/InjectedScriptManager.h:
+ * inspector/InjectedScriptManager.cpp:
+ (Inspector::InjectedScriptManager::createInjectedScript):
+ (Inspector::InjectedScriptManager::injectedScriptFor):
+
+ * inspector/InjectedScriptModule.cpp:
+ (Inspector::InjectedScriptModule::ensureInjected):
+
2019-09-19 Yusuke Suzuki <[email protected]>
[JSC] DFG op_call_varargs should not assume that one-previous-local of freeReg is usable
Modified: trunk/Source/_javascript_Core/bindings/ScriptFunctionCall.cpp (250123 => 250124)
--- trunk/Source/_javascript_Core/bindings/ScriptFunctionCall.cpp 2019-09-20 07:09:59 UTC (rev 250123)
+++ trunk/Source/_javascript_Core/bindings/ScriptFunctionCall.cpp 2019-09-20 08:28:09 UTC (rev 250124)
@@ -102,7 +102,7 @@
{
}
-JSValue ScriptFunctionCall::call(bool& hadException)
+Expected<JSValue, NakedPtr<Exception>> ScriptFunctionCall::call()
{
JSObject* thisObject = m_thisObject.jsObject();
@@ -111,10 +111,8 @@
auto scope = DECLARE_THROW_SCOPE(vm);
JSValue function = thisObject->get(m_exec, Identifier::fromString(vm, m_name));
- if (UNLIKELY(scope.exception())) {
- hadException = true;
- return { };
- }
+ if (UNLIKELY(scope.exception()))
+ return makeUnexpected(scope.exception());
CallData callData;
CallType callType = getCallData(vm, function, callData);
@@ -130,7 +128,8 @@
if (exception) {
// Do not treat a terminated execution exception as having an exception. Just treat it as an empty result.
- hadException = !isTerminatedExecutionException(vm, exception);
+ if (!isTerminatedExecutionException(vm, exception))
+ return makeUnexpected(exception);
return { };
}
@@ -137,10 +136,4 @@
return result;
}
-JSC::JSValue ScriptFunctionCall::call()
-{
- bool hadException;
- return call(hadException);
-}
-
} // namespace Deprecated
Modified: trunk/Source/_javascript_Core/bindings/ScriptFunctionCall.h (250123 => 250124)
--- trunk/Source/_javascript_Core/bindings/ScriptFunctionCall.h 2019-09-20 07:09:59 UTC (rev 250123)
+++ trunk/Source/_javascript_Core/bindings/ScriptFunctionCall.h 2019-09-20 08:28:09 UTC (rev 250124)
@@ -32,7 +32,9 @@
#pragma once
#include "ArgList.h"
+#include "Exception.h"
#include "ScriptObject.h"
+#include <wtf/Expected.h>
#include <wtf/text/WTFString.h>
namespace JSC {
@@ -70,8 +72,7 @@
public:
typedef JSC::JSValue (*ScriptFunctionCallHandler)(JSC::ExecState* exec, JSC::JSValue functionObject, JSC::CallType callType, const JSC::CallData& callData, JSC::JSValue thisValue, const JSC::ArgList& args, NakedPtr<JSC::Exception>&);
ScriptFunctionCall(const ScriptObject& thisObject, const String& name, ScriptFunctionCallHandler handler = nullptr);
- JSC::JSValue call(bool& hadException);
- JSC::JSValue call();
+ Expected<JSC::JSValue, NakedPtr<JSC::Exception>> call();
protected:
ScriptFunctionCallHandler m_callHandler;
Modified: trunk/Source/_javascript_Core/inspector/InjectedScript.cpp (250123 => 250124)
--- trunk/Source/_javascript_Core/inspector/InjectedScript.cpp 2019-09-20 07:09:59 UTC (rev 250123)
+++ trunk/Source/_javascript_Core/inspector/InjectedScript.cpp 2019-09-20 08:28:09 UTC (rev 250124)
@@ -263,12 +263,12 @@
Deprecated::ScriptFunctionCall function(injectedScriptObject(), "wrapCallFrames"_s, inspectorEnvironment()->functionCallHandler());
function.appendArgument(callFrames);
- bool hadException = false;
- auto callFramesValue = callFunctionWithEvalEnabled(function, hadException);
- if (!callFramesValue)
+ auto callResult = callFunctionWithEvalEnabled(function);
+ ASSERT(callResult);
+ if (!callResult || !callResult.value())
return JSON::ArrayOf<Protocol::Debugger::CallFrame>::create();
- ASSERT(!hadException);
- RefPtr<JSON::Value> result = toInspectorValue(*scriptState(), callFramesValue);
+
+ RefPtr<JSON::Value> result = toInspectorValue(*scriptState(), callResult.value());
if (result->type() == JSON::Value::Type::Array)
return BindingTraits<JSON::ArrayOf<Protocol::Debugger::CallFrame>>::runtimeCast(WTFMove(result)).releaseNonNull();
@@ -284,13 +284,12 @@
wrapFunction.appendArgument(hasAccessToInspectedScriptState());
wrapFunction.appendArgument(generatePreview);
- bool hadException = false;
- auto r = callFunctionWithEvalEnabled(wrapFunction, hadException);
- if (hadException)
+ auto callResult = callFunctionWithEvalEnabled(wrapFunction);
+ if (!callResult)
return nullptr;
RefPtr<JSON::Object> resultObject;
- bool castSucceeded = toInspectorValue(*scriptState(), r)->asObject(resultObject);
+ bool castSucceeded = toInspectorValue(*scriptState(), callResult.value())->asObject(resultObject);
ASSERT_UNUSED(castSucceeded, castSucceeded);
return BindingTraits<Protocol::Runtime::RemoteObject>::runtimeCast(resultObject);
@@ -304,16 +303,15 @@
wrapFunction.appendArgument(groupName);
wrapFunction.appendArgument(generatePreview);
- bool hadException = false;
- auto evalResult = callFunctionWithEvalEnabled(wrapFunction, hadException);
- if (hadException)
+ auto callResult = callFunctionWithEvalEnabled(wrapFunction);
+ if (!callResult)
return nullptr;
- if (evalResult.isNull())
+ if (callResult.value().isNull())
return nullptr;
RefPtr<JSON::Object> resultObject;
- bool castSucceeded = toInspectorValue(*scriptState(), evalResult)->asObject(resultObject);
+ bool castSucceeded = toInspectorValue(*scriptState(), callResult.value())->asObject(resultObject);
ASSERT_UNUSED(castSucceeded, castSucceeded);
return BindingTraits<Protocol::Runtime::RemoteObject>::runtimeCast(resultObject);
@@ -330,13 +328,12 @@
else
wrapFunction.appendArgument(columns);
- bool hadException = false;
- auto r = callFunctionWithEvalEnabled(wrapFunction, hadException);
- if (hadException)
+ auto callResult = callFunctionWithEvalEnabled(wrapFunction);
+ if (!callResult)
return nullptr;
RefPtr<JSON::Object> resultObject;
- bool castSucceeded = toInspectorValue(*scriptState(), r)->asObject(resultObject);
+ bool castSucceeded = toInspectorValue(*scriptState(), callResult.value())->asObject(resultObject);
ASSERT_UNUSED(castSucceeded, castSucceeded);
return BindingTraits<Protocol::Runtime::RemoteObject>::runtimeCast(resultObject);
@@ -348,13 +345,12 @@
Deprecated::ScriptFunctionCall wrapFunction(injectedScriptObject(), "previewValue"_s, inspectorEnvironment()->functionCallHandler());
wrapFunction.appendArgument(value);
- bool hadException = false;
- auto r = callFunctionWithEvalEnabled(wrapFunction, hadException);
- if (hadException)
+ auto callResult = callFunctionWithEvalEnabled(wrapFunction);
+ if (!callResult)
return nullptr;
RefPtr<JSON::Object> resultObject;
- bool castSucceeded = toInspectorValue(*scriptState(), r)->asObject(resultObject);
+ bool castSucceeded = toInspectorValue(*scriptState(), callResult.value())->asObject(resultObject);
ASSERT_UNUSED(castSucceeded, castSucceeded);
return BindingTraits<Protocol::Runtime::ObjectPreview>::runtimeCast(resultObject);
@@ -396,11 +392,11 @@
Deprecated::ScriptFunctionCall function(injectedScriptObject(), "findObjectById"_s, inspectorEnvironment()->functionCallHandler());
function.appendArgument(objectId);
- bool hadException = false;
- auto resultValue = callFunctionWithEvalEnabled(function, hadException);
- ASSERT(!hadException);
-
- return resultValue;
+ auto callResult = callFunctionWithEvalEnabled(function);
+ ASSERT(callResult);
+ if (!callResult)
+ return { };
+ return callResult.value();
}
void InjectedScript::inspectObject(JSC::JSValue value)
@@ -424,9 +420,8 @@
Deprecated::ScriptFunctionCall releaseFunction(injectedScriptObject(), "releaseObjectGroup"_s, inspectorEnvironment()->functionCallHandler());
releaseFunction.appendArgument(objectGroup);
- bool hadException = false;
- callFunctionWithEvalEnabled(releaseFunction, hadException);
- ASSERT(!hadException);
+ auto callResult = callFunctionWithEvalEnabled(releaseFunction);
+ ASSERT_UNUSED(callResult, callResult);
}
JSC::JSValue InjectedScript::arrayFromVector(Vector<JSC::JSValue>&& vector)
Modified: trunk/Source/_javascript_Core/inspector/InjectedScriptBase.cpp (250123 => 250124)
--- trunk/Source/_javascript_Core/inspector/InjectedScriptBase.cpp 2019-09-20 07:09:59 UTC (rev 250123)
+++ trunk/Source/_javascript_Core/inspector/InjectedScriptBase.cpp 2019-09-20 08:28:09 UTC (rev 250124)
@@ -70,11 +70,11 @@
return m_injectedScriptObject;
}
-JSC::JSValue InjectedScriptBase::callFunctionWithEvalEnabled(Deprecated::ScriptFunctionCall& function, bool& hadException) const
+Expected<JSC::JSValue, NakedPtr<JSC::Exception>> InjectedScriptBase::callFunctionWithEvalEnabled(Deprecated::ScriptFunctionCall& function) const
{
JSC::ExecState* scriptState = m_injectedScriptObject.scriptState();
JSC::DebuggerEvalEnabler evalEnabler(scriptState);
- return function.call(hadException);
+ return function.call();
}
Ref<JSON::Value> InjectedScriptBase::makeCall(Deprecated::ScriptFunctionCall& function)
@@ -82,14 +82,11 @@
if (hasNoValue() || !hasAccessToInspectedScriptState())
return JSON::Value::null();
- bool hadException = false;
- auto resultJSValue = callFunctionWithEvalEnabled(function, hadException);
-
- ASSERT(!hadException);
- if (hadException)
+ auto result = callFunctionWithEvalEnabled(function);
+ if (!result)
return JSON::Value::create("Exception while making a call.");
- RefPtr<JSON::Value> resultJSONValue = toInspectorValue(*m_injectedScriptObject.scriptState(), resultJSValue);
+ RefPtr<JSON::Value> resultJSONValue = toInspectorValue(*m_injectedScriptObject.scriptState(), result.value());
if (!resultJSONValue)
return JSON::Value::create(makeString("Object has too long reference chain (must not be longer than ", JSON::Value::maxDepth, ')'));
@@ -129,12 +126,11 @@
function.appendArgument(JSC::JSValue(jsFunction));
- bool hadException = false;
- auto resultJSValue = callFunctionWithEvalEnabled(function, hadException);
- ASSERT_UNUSED(resultJSValue, resultJSValue.isUndefined());
+ auto result = callFunctionWithEvalEnabled(function);
+ ASSERT_UNUSED(result, result.value().isUndefined());
- ASSERT(!hadException);
- if (hadException) {
+ ASSERT(result);
+ if (!result) {
// Since `callback` is moved above, we can't call it if there's an exception while trying to
// execute the `JSNativeStdFunction` inside InjectedScriptSource.js.
jsFunction->nativeStdFunctionCell()->function()(nullptr);
Modified: trunk/Source/_javascript_Core/inspector/InjectedScriptBase.h (250123 => 250124)
--- trunk/Source/_javascript_Core/inspector/InjectedScriptBase.h 2019-09-20 07:09:59 UTC (rev 250123)
+++ trunk/Source/_javascript_Core/inspector/InjectedScriptBase.h 2019-09-20 08:28:09 UTC (rev 250124)
@@ -31,11 +31,14 @@
#pragma once
+#include "Exception.h"
#include "InspectorEnvironment.h"
#include "InspectorProtocolObjects.h"
#include "ScriptObject.h"
+#include <wtf/Expected.h>
#include <wtf/Forward.h>
#include <wtf/Function.h>
+#include <wtf/NakedPtr.h>
#include <wtf/RefPtr.h>
namespace Deprecated {
@@ -64,7 +67,7 @@
bool hasAccessToInspectedScriptState() const;
const Deprecated::ScriptObject& injectedScriptObject() const;
- JSC::JSValue callFunctionWithEvalEnabled(Deprecated::ScriptFunctionCall&, bool& hadException) const;
+ Expected<JSC::JSValue, NakedPtr<JSC::Exception>> callFunctionWithEvalEnabled(Deprecated::ScriptFunctionCall&) const;
Ref<JSON::Value> makeCall(Deprecated::ScriptFunctionCall&);
void makeEvalCall(ErrorString&, Deprecated::ScriptFunctionCall&, RefPtr<Protocol::Runtime::RemoteObject>& resultObject, Optional<bool>& wasThrown, Optional<int>& savedResultIndex);
void makeAsyncCall(Deprecated::ScriptFunctionCall&, AsyncCallCallback&&);
Modified: trunk/Source/_javascript_Core/inspector/InjectedScriptManager.cpp (250123 => 250124)
--- trunk/Source/_javascript_Core/inspector/InjectedScriptManager.cpp 2019-09-20 07:09:59 UTC (rev 250123)
+++ trunk/Source/_javascript_Core/inspector/InjectedScriptManager.cpp 2019-09-20 08:28:09 UTC (rev 250124)
@@ -143,7 +143,7 @@
return StringImpl::createWithoutCopying(InjectedScriptSource_js, sizeof(InjectedScriptSource_js));
}
-JSC::JSObject* InjectedScriptManager::createInjectedScript(const String& source, ExecState* scriptState, int id)
+Expected<JSObject*, NakedPtr<Exception>> InjectedScriptManager::createInjectedScript(const String& source, ExecState* scriptState, int id)
{
VM& vm = scriptState->vm();
JSLockHolder lock(vm);
@@ -157,7 +157,7 @@
InspectorEvaluateHandler evaluateHandler = m_environment.evaluateHandler();
JSValue functionValue = evaluateHandler(scriptState, sourceCode, globalThisValue, evaluationException);
if (evaluationException)
- return nullptr;
+ return makeUnexpected(evaluationException);
CallData callData;
CallType callType = getCallData(vm, functionValue, callData);
@@ -188,14 +188,27 @@
return InjectedScript();
int id = injectedScriptIdFor(inspectedExecState);
- auto injectedScriptObject = createInjectedScript(injectedScriptSource(), inspectedExecState, id);
- if (!injectedScriptObject) {
- WTFLogAlways("Failed to parse/execute InjectedScriptSource.js!");
- WTFLogAlways("%s\n", injectedScriptSource().ascii().data());
+ auto createResult = createInjectedScript(injectedScriptSource(), inspectedExecState, id);
+ if (!createResult) {
+ auto& error = createResult.error();
+ ASSERT(error);
+
+ unsigned line = 0;
+ unsigned column = 0;
+ auto& stack = error->stack();
+ if (stack.size() > 0)
+ stack[0].computeLineAndColumn(line, column);
+ WTFLogAlways("Error when creating injected script: %s (%d:%d)\n", error->value().toWTFString(inspectedExecState).utf8().data(), line, column);
+ WTFLogAlways("%s\n", injectedScriptSource().utf8().data());
RELEASE_ASSERT_NOT_REACHED();
}
+ if (!createResult.value()) {
+ WTFLogAlways("Missing injected script object");
+ WTFLogAlways("%s\n", injectedScriptSource().utf8().data());
+ RELEASE_ASSERT_NOT_REACHED();
+ }
- InjectedScript result({ inspectedExecState, injectedScriptObject }, &m_environment);
+ InjectedScript result({ inspectedExecState, createResult.value() }, &m_environment);
m_idToInjectedScript.set(id, result);
didCreateInjectedScript(result);
return result;
Modified: trunk/Source/_javascript_Core/inspector/InjectedScriptManager.h (250123 => 250124)
--- trunk/Source/_javascript_Core/inspector/InjectedScriptManager.h 2019-09-20 07:09:59 UTC (rev 250123)
+++ trunk/Source/_javascript_Core/inspector/InjectedScriptManager.h 2019-09-20 08:28:09 UTC (rev 250124)
@@ -29,10 +29,13 @@
#pragma once
+#include "Exception.h"
#include "InjectedScript.h"
#include "InspectorEnvironment.h"
+#include <wtf/Expected.h>
#include <wtf/Forward.h>
#include <wtf/HashMap.h>
+#include <wtf/NakedPtr.h>
#include <wtf/text/WTFString.h>
namespace JSC {
@@ -73,7 +76,7 @@
private:
String injectedScriptSource();
- JSC::JSObject* createInjectedScript(const String& source, JSC::ExecState*, int id);
+ Expected<JSC::JSObject*, NakedPtr<JSC::Exception>> createInjectedScript(const String& source, JSC::ExecState*, int id);
InspectorEnvironment& m_environment;
Ref<InjectedScriptHost> m_injectedScriptHost;
Modified: trunk/Source/_javascript_Core/inspector/InjectedScriptModule.cpp (250123 => 250124)
--- trunk/Source/_javascript_Core/inspector/InjectedScriptModule.cpp 2019-09-20 07:09:59 UTC (rev 250123)
+++ trunk/Source/_javascript_Core/inspector/InjectedScriptModule.cpp 2019-09-20 08:28:09 UTC (rev 250124)
@@ -64,19 +64,36 @@
JSC::JSLockHolder locker(injectedScript.scriptState());
Deprecated::ScriptFunctionCall function(injectedScript.injectedScriptObject(), "hasInjectedModule"_s, injectedScriptManager->inspectorEnvironment().functionCallHandler());
function.appendArgument(name());
- bool hadException = false;
- auto resultValue = injectedScript.callFunctionWithEvalEnabled(function, hadException);
- ASSERT(!hadException);
- if (hadException || !resultValue || !resultValue.isBoolean() || !resultValue.asBoolean()) {
+ auto hasInjectedModuleResult = injectedScript.callFunctionWithEvalEnabled(function);
+ ASSERT(hasInjectedModuleResult);
+ if (!hasInjectedModuleResult) {
+ auto& error = hasInjectedModuleResult.error();
+ ASSERT(error);
+ unsigned line = 0;
+ unsigned column = 0;
+ auto& stack = error->stack();
+ if (stack.size() > 0)
+ stack[0].computeLineAndColumn(line, column);
+ WTFLogAlways("Error when calling 'hasInjectedModule' for '%s': %s (%d:%d)\n", name().utf8().data(), error->value().toWTFString(injectedScript.scriptState()).utf8().data(), line, column);
+ WTFLogAlways("%s\n", source().utf8().data());
+ RELEASE_ASSERT_NOT_REACHED();
+ }
+ if (!hasInjectedModuleResult.value().isBoolean() || !hasInjectedModuleResult.value().asBoolean()) {
Deprecated::ScriptFunctionCall function(injectedScript.injectedScriptObject(), "injectModule"_s, injectedScriptManager->inspectorEnvironment().functionCallHandler());
function.appendArgument(name());
function.appendArgument(source());
function.appendArgument(host(injectedScriptManager, injectedScript.scriptState()));
- hadException = false;
- resultValue = injectedScript.callFunctionWithEvalEnabled(function, hadException);
- if (hadException) {
- WTFLogAlways("Failed to parse/execute %s!", name().ascii().data());
- WTFLogAlways("%s\n", source().ascii().data());
+ auto injectModuleResult = injectedScript.callFunctionWithEvalEnabled(function);
+ if (!injectModuleResult) {
+ auto& error = injectModuleResult.error();
+ ASSERT(error);
+ unsigned line = 0;
+ unsigned column = 0;
+ auto& stack = error->stack();
+ if (stack.size() > 0)
+ stack[0].computeLineAndColumn(line, column);
+ WTFLogAlways("Error when calling 'injectModule' for '%s': %s (%d:%d)\n", name().utf8().data(), error->value().toWTFString(injectedScript.scriptState()).utf8().data(), line, column);
+ WTFLogAlways("%s\n", source().utf8().data());
RELEASE_ASSERT_NOT_REACHED();
}
}