Ignore:
Timestamp:
Apr 15, 2016, 7:25:56 PM (9 years ago)
Author:
Darin Adler
Message:

Reduce use of Deprecated::ScriptXXX classes
https://bugs.webkit.org/show_bug.cgi?id=156632

Reviewed by Alex Christensen.

Source/JavaScriptCore:

  • bindings/ScriptFunctionCall.cpp:

(Deprecated::ScriptCallArgumentHandler::appendArgument): Deleted version that takes a Deprecated::ScriptValue.
(Deprecated::ScriptFunctionCall::call): Changed to return a JSValue.

  • bindings/ScriptFunctionCall.h: Updated for the above.
  • bindings/ScriptValue.cpp:

(Inspector::jsToInspectorValue): Moved from Deprecated namespace to Inspector namespace. Later, we should
move this to another source file in the inspector directory.
(Inspector::toInspectorValue): Added.
(Deprecated::ScriptValue::toInspectorValue): Updated for change to underlying function.

  • bindings/ScriptValue.h: Update for the above.
  • inspector/InjectedScript.cpp:

(Inspector::InjectedScript::evaluateOnCallFrame): Changed arguments and return values from
Deprecated::ScriptValue to JSC::JSValue.
(Inspector::InjectedScript::functionDetails): Ditto.
(Inspector::InjectedScript::wrapCallFrames): Ditto.
(Inspector::InjectedScript::wrapObject): Ditto.
(Inspector::InjectedScript::wrapTable): Ditto.
(Inspector::InjectedScript::previewValue): Ditto.
(Inspector::InjectedScript::setExceptionValue): Ditto.
(Inspector::InjectedScript::findObjectById): Ditto.
(Inspector::InjectedScript::inspectObject): Ditto.

  • inspector/InjectedScript.h: Ditto.
  • inspector/InjectedScriptBase.cpp:

(Inspector::InjectedScriptBase::callFunctionWithEvalEnabled): Ditto.
(Inspector::InjectedScriptBase::makeCall): Ditto.

  • inspector/InjectedScriptBase.h: Ditto.
  • inspector/InjectedScriptModule.cpp:

(Inspector::InjectedScriptModule::ensureInjected): Ditto.

  • inspector/ScriptDebugListener.h: Ditto.
  • inspector/ScriptDebugServer.cpp:

(Inspector::ScriptDebugServer::evaluateBreakpointAction): Ditto.
(Inspector::ScriptDebugServer::dispatchDidPause): Ditto.
(Inspector::ScriptDebugServer::dispatchBreakpointActionProbe): Ditto.
(Inspector::ScriptDebugServer::exceptionOrCaughtValue): Ditto.

  • inspector/ScriptDebugServer.h: Ditto.
  • inspector/agents/InspectorDebuggerAgent.cpp:

(Inspector::InspectorDebuggerAgent::buildExceptionPauseReason): Ditto.
(Inspector::InspectorDebuggerAgent::didPause): Ditto.
(Inspector::InspectorDebuggerAgent::breakpointActionProbe): Ditto.
(Inspector::InspectorDebuggerAgent::didContinue): Ditto.
(Inspector::InspectorDebuggerAgent::clearDebuggerBreakpointState): Ditto.

  • inspector/agents/InspectorDebuggerAgent.h: Ditto.
  • inspector/agents/InspectorHeapAgent.cpp:

(Inspector::InspectorHeapAgent::getPreview): Ditto.
(Inspector::InspectorHeapAgent::getRemoteObject): Ditto.

Source/WebCore:

  • Modules/mediastream/SDPProcessor.cpp: Removed unneeded include.
  • bindings/js/JSCommandLineAPIHostCustom.cpp:

(WebCore::JSCommandLineAPIHost::inspectedObject): Use JSValue.

  • bindings/js/JSCustomEventCustom.cpp:

(WebCore::JSCustomEvent::detail): Ditto.

  • bindings/js/ScriptController.cpp:

(WebCore::ScriptController::evaluateInWorld): Ditto.
(WebCore::ScriptController::evaluate): Ditto.
(WebCore::ScriptController::executeScriptInWorld): Ditto.
(WebCore::ScriptController::executeScript): Ditto.
(WebCore::ScriptController::executeIfJavaScriptURL): Ditto.

  • bindings/js/ScriptController.h: Ditto.
  • bindings/js/ScriptGlobalObject.cpp: Removed unused overload of set,

and unused remove and folded handleException function into its one call site.
(WebCore::ScriptGlobalObject::set): Take references instead of pointers.
(WebCore::ScriptGlobalObject::get): Use JSObject instead of Deprecated::ScriptObject.

  • bindings/js/ScriptGlobalObject.h: Updated for the above.
  • dom/CustomEvent.cpp:

(WebCore::CustomEvent::initCustomEvent): Take JSValue and ExecState instead of
Deprecated::ScriptValue.
(WebCore::CustomEvent::trySerializeDetail): Take a reference instead of a pointer.
Also removed an unneeded null check.

  • dom/CustomEvent.h: Use JSValue.
  • dom/CustomEvent.idl: Updated for the above.
  • html/HTMLMediaElement.cpp: Remove unneeded include.
  • inspector/CommandLineAPIHost.cpp:

(WebCore::CommandLineAPIHost::InspectableObject::get): Take reference instead of
pointer and return JSValue.

  • inspector/CommandLineAPIHost.h: Updated for the above.
  • inspector/InspectorDOMAgent.cpp:

(WebCore::InspectorDOMAgent::setDocument): Use "document" instead of "doc".
(WebCore::InspectorDOMAgent::setAttributesAsText): Omit redundant class name.
(WebCore::InspectorDOMAgent::focusNode): Ditto. Pass reference instead of pointer.
(WebCore::InspectorDOMAgent::undo): Ditto.
(WebCore::InspectorDOMAgent::redo): Ditto.
(WebCore::InspectorDOMAgent::nodeForObjectId): Stop using Deprecated::ScriptValue.
(WebCore::InspectorDOMAgent::resolveNode): Ditto.
(WebCore::InspectorDOMAgent::scriptValueAsNode): Removed unneeded isObject check,
which is already done by JSNode::toWrapped. Use JSValue.
(WebCore::InspectorDOMAgent::nodeAsScriptValue): Use JSValue.

  • inspector/InspectorDOMAgent.h: Updated for the above.
  • inspector/InspectorFrontendClientLocal.cpp:

(WebCore::InspectorFrontendClientLocal::windowObjectCleared): Use references instead of
pointers and removed unneeded local.
(WebCore::InspectorFrontendClientLocal::evaluateAsBoolean): More of the same.

  • inspector/InspectorFrontendHost.cpp:

(WebCore::InspectorFrontendHost::showContextMenu): Ditto.

  • inspector/InspectorTimelineAgent.cpp:

(WebCore::InspectorTimelineAgent::breakpointActionProbe): Updated to take
reference instead of pointer and JSValue instead of ScriptValue.

  • inspector/InspectorTimelineAgent.h: Ditto.
  • inspector/PageConsoleAgent.cpp: Ditto.
  • inspector/PageDebuggerAgent.cpp:

(WebCore::PageDebuggerAgent::breakpointActionLog): Ditto.

  • inspector/PageDebuggerAgent.h: Ditto.

Source/WebKit/mac:

  • WebView/WebFrame.mm:

(-[WebFrame _stringByEvaluatingJavaScriptFromString:forceUserGesture:]): Use references instead
of pointers.
(-[WebFrame _stringByEvaluatingJavaScriptFromString:withGlobalObject:inScriptWorld:]): Updated
since return value is a JSValue.

  • WebView/WebView.mm:

(-[WebView aeDescByEvaluatingJavaScriptFromString:]): Ditto.

Source/WebKit/win:

  • Plugins/PluginView.cpp:

(WebCore::PluginView::performRequest): Use JSValue.

  • WebFrame.cpp:

(WebFrame::stringByEvaluatingJavaScriptInScriptWorld): Ditto.

  • WebView.cpp:

(WebView::stringByEvaluatingJavaScriptFromString): Ditto.

Source/WebKit2:

  • WebProcess/Plugins/PluginView.cpp:

(WebKit::PluginView::performJavaScriptURLRequest): Use JSValue.

  • WebProcess/WebPage/WebInspectorUI.cpp:

(WebKit::WebInspectorUI::windowObjectCleared): Use references.

  • WebProcess/WebPage/WebPage.cpp:

(WebKit::WebPage::runJavaScriptInMainFrame): Use JSValue.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/bindings/ScriptValue.cpp

    r199320 r199619  
    3838using namespace JSC;
    3939using namespace Inspector;
     40
     41namespace Inspector {
     42
     43static RefPtr<InspectorValue> jsToInspectorValue(ExecState& scriptState, JSValue value, int maxDepth)
     44{
     45    if (!value) {
     46        ASSERT_NOT_REACHED();
     47        return nullptr;
     48    }
     49
     50    if (!maxDepth)
     51        return nullptr;
     52
     53    maxDepth--;
     54
     55    if (value.isUndefinedOrNull())
     56        return InspectorValue::null(); // FIXME: Why is it OK to turn undefined into null?
     57    if (value.isBoolean())
     58        return InspectorValue::create(value.asBoolean());
     59    if (value.isNumber() && value.isDouble())
     60        return InspectorValue::create(value.asNumber());
     61    if (value.isNumber() && value.isMachineInt())
     62        return InspectorValue::create(static_cast<int>(value.asMachineInt()));
     63    if (value.isString())
     64        return InspectorValue::create(value.getString(&scriptState));
     65
     66    if (value.isObject()) {
     67        if (isJSArray(value)) {
     68            auto inspectorArray = InspectorArray::create();
     69            auto& array = *asArray(value);
     70            unsigned length = array.length();
     71            for (unsigned i = 0; i < length; i++) {
     72                auto elementValue = jsToInspectorValue(scriptState, array.getIndex(&scriptState, i), maxDepth);
     73                if (!elementValue)
     74                    return nullptr;
     75                inspectorArray->pushValue(WTFMove(elementValue));
     76            }
     77            return WTFMove(inspectorArray);
     78        }
     79        auto inspectorObject = InspectorObject::create();
     80        auto& object = *value.getObject();
     81        PropertyNameArray propertyNames(&scriptState, PropertyNameMode::Strings);
     82        object.methodTable()->getOwnPropertyNames(&object, &scriptState, propertyNames, EnumerationMode());
     83        for (auto& name : propertyNames) {
     84            auto inspectorValue = jsToInspectorValue(scriptState, object.get(&scriptState, name), maxDepth);
     85            if (!inspectorValue)
     86                return nullptr;
     87            inspectorObject->setValue(name.string(), WTFMove(inspectorValue));
     88        }
     89        return WTFMove(inspectorObject);
     90    }
     91
     92    ASSERT_NOT_REACHED();
     93    return nullptr;
     94}
     95
     96RefPtr<InspectorValue> toInspectorValue(ExecState& state, JSValue value)
     97{
     98    // FIXME: Maybe we should move the JSLockHolder stuff to the callers since this function takes a JSValue directly.
     99    // Doing the locking here made sense when we were trying to abstract the difference between multiple JavaScript engines.
     100    JSLockHolder holder(&state);
     101    return jsToInspectorValue(state, value, InspectorValue::maxDepth);
     102}
     103
     104} // namespace Inspector
    40105
    41106namespace Deprecated {
     
    98163}
    99164
    100 static RefPtr<InspectorValue> jsToInspectorValue(ExecState* scriptState, JSValue value, int maxDepth)
    101 {
    102     if (!value) {
    103         ASSERT_NOT_REACHED();
    104         return nullptr;
    105     }
    106 
    107     if (!maxDepth)
    108         return nullptr;
    109 
    110     maxDepth--;
    111 
    112     if (value.isNull() || value.isUndefined())
    113         return InspectorValue::null();
    114     if (value.isBoolean())
    115         return InspectorValue::create(value.asBoolean());
    116     if (value.isNumber() && value.isDouble())
    117         return InspectorValue::create(value.asNumber());
    118     if (value.isNumber() && value.isMachineInt())
    119         return InspectorValue::create(static_cast<int>(value.asMachineInt()));
    120     if (value.isString())
    121         return InspectorValue::create(value.getString(scriptState));
    122 
    123     if (value.isObject()) {
    124         if (isJSArray(value)) {
    125             Ref<InspectorArray> inspectorArray = InspectorArray::create();
    126             JSArray* array = asArray(value);
    127             unsigned length = array->length();
    128             for (unsigned i = 0; i < length; i++) {
    129                 JSValue element = array->getIndex(scriptState, i);
    130                 RefPtr<InspectorValue> elementValue = jsToInspectorValue(scriptState, element, maxDepth);
    131                 if (!elementValue)
    132                     return nullptr;
    133                 inspectorArray->pushValue(WTFMove(elementValue));
    134             }
    135             return WTFMove(inspectorArray);
    136         }
    137         Ref<InspectorObject> inspectorObject = InspectorObject::create();
    138         JSObject* object = value.getObject();
    139         PropertyNameArray propertyNames(scriptState, PropertyNameMode::Strings);
    140         object->methodTable()->getOwnPropertyNames(object, scriptState, propertyNames, EnumerationMode());
    141         for (size_t i = 0; i < propertyNames.size(); i++) {
    142             const Identifier& name = propertyNames[i];
    143             JSValue propertyValue = object->get(scriptState, name);
    144             RefPtr<InspectorValue> inspectorValue = jsToInspectorValue(scriptState, propertyValue, maxDepth);
    145             if (!inspectorValue)
    146                 return nullptr;
    147             inspectorObject->setValue(name.string(), WTFMove(inspectorValue));
    148         }
    149         return WTFMove(inspectorObject);
    150     }
    151 
    152     ASSERT_NOT_REACHED();
    153     return nullptr;
    154 }
    155 
    156165RefPtr<InspectorValue> ScriptValue::toInspectorValue(ExecState* scriptState) const
    157166{
    158167    JSLockHolder holder(scriptState);
    159     return jsToInspectorValue(scriptState, m_value.get(), InspectorValue::maxDepth);
     168    return jsToInspectorValue(*scriptState, m_value.get(), InspectorValue::maxDepth);
    160169}
    161170
Note: See TracChangeset for help on using the changeset viewer.