void InjectedScript::wrapEvaluateResult(ErrorString* errorString, v8::MaybeLocal<v8::Value> maybeResultValue, const v8::TryCatch& tryCatch, const String16& objectGroup, bool returnByValue, bool generatePreview, std::unique_ptr<protocol::Runtime::RemoteObject>* result, Maybe<bool>* wasThrown, Maybe<protocol::Runtime::ExceptionDetails>* exceptionDetails) { v8::Local<v8::Value> resultValue; if (!tryCatch.HasCaught()) { if (hasInternalError(errorString, !maybeResultValue.ToLocal(&resultValue))) return; std::unique_ptr<RemoteObject> remoteObject = wrapObject(errorString, resultValue, objectGroup, returnByValue, generatePreview); if (!remoteObject) return; if (objectGroup == "console") m_lastEvaluationResult.Reset(m_context->isolate(), resultValue); *result = std::move(remoteObject); if (wasThrown) *wasThrown = false; } else { v8::Local<v8::Value> exception = tryCatch.Exception(); std::unique_ptr<RemoteObject> remoteObject = wrapObject(errorString, exception, objectGroup, false, generatePreview && !exception->IsNativeError()); if (!remoteObject) return; *result = std::move(remoteObject); if (exceptionDetails) *exceptionDetails = createExceptionDetails(tryCatch.Message()); if (wasThrown) *wasThrown = true; } }
void InjectedScript::getProperties(ErrorString* errorString, v8::Local<v8::Object> object, const String16& groupName, bool ownProperties, bool accessorPropertiesOnly, bool generatePreview, std::unique_ptr<Array<PropertyDescriptor>>* properties, Maybe<protocol::Runtime::ExceptionDetails>* exceptionDetails) { v8::HandleScope handles(m_context->isolate()); V8FunctionCall function(m_context->inspector(), m_context->context(), v8Value(), "getProperties"); function.appendArgument(object); function.appendArgument(groupName); function.appendArgument(ownProperties); function.appendArgument(accessorPropertiesOnly); function.appendArgument(generatePreview); v8::TryCatch tryCatch(m_context->isolate()); v8::Local<v8::Value> resultValue = function.callWithoutExceptionHandling(); if (tryCatch.HasCaught()) { *exceptionDetails = createExceptionDetails(tryCatch.Message()); // FIXME: make properties optional *properties = Array<PropertyDescriptor>::create(); return; } std::unique_ptr<protocol::Value> protocolValue = toProtocolValue(m_context->context(), resultValue); if (hasInternalError(errorString, !protocolValue)) return; protocol::ErrorSupport errors(errorString); std::unique_ptr<Array<PropertyDescriptor>> result = Array<PropertyDescriptor>::parse(protocolValue.get(), &errors); if (!hasInternalError(errorString, errors.hasErrors())) *properties = std::move(result); }
v8::Local<v8::Value> JavaScriptCallFrame::evaluateWithExceptionDetails(v8::Local<v8::Value> expression, v8::Local<v8::Value> scopeExtension) { v8::Local<v8::Object> callFrame = m_callFrame.newLocal(m_isolate); v8::Local<v8::Function> evalFunction = v8::Local<v8::Function>::Cast(callFrame->Get(v8AtomicString(m_isolate, "evaluate"))); v8::Local<v8::Value> argv[] = { expression, scopeExtension }; v8::TryCatch tryCatch(m_isolate); v8::Local<v8::Object> wrappedResult = v8::Object::New(m_isolate); v8::Local<v8::Value> result; if (V8ScriptRunner::callInternalFunction(evalFunction, callFrame, WTF_ARRAY_LENGTH(argv), argv, m_isolate).ToLocal(&result)) { wrappedResult->Set(v8::String::NewFromUtf8(m_isolate, "result"), result); wrappedResult->Set(v8::String::NewFromUtf8(m_isolate, "exceptionDetails"), v8::Undefined(m_isolate)); } else { wrappedResult->Set(v8::String::NewFromUtf8(m_isolate, "result"), tryCatch.Exception()); wrappedResult->Set(v8::String::NewFromUtf8(m_isolate, "exceptionDetails"), createExceptionDetails(m_isolate, tryCatch.Message())); } return wrappedResult; }