Skip to content

Commit 9e14a59

Browse files
committed
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. Canonical link: https://commits.webkit.org/174754@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@199619 268f45cc-cd09-0410-ab3c-d52691b4dbfc
1 parent 6cc392e commit 9e14a59

52 files changed

Lines changed: 483 additions & 367 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎Source/JavaScriptCore/ChangeLog‎

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,58 @@
1+
2016-04-15 Darin Adler <darin@apple.com>
2+
3+
Reduce use of Deprecated::ScriptXXX classes
4+
https://bugs.webkit.org/show_bug.cgi?id=156632
5+
6+
Reviewed by Alex Christensen.
7+
8+
* bindings/ScriptFunctionCall.cpp:
9+
(Deprecated::ScriptCallArgumentHandler::appendArgument): Deleted version that takes a Deprecated::ScriptValue.
10+
(Deprecated::ScriptFunctionCall::call): Changed to return a JSValue.
11+
* bindings/ScriptFunctionCall.h: Updated for the above.
12+
13+
* bindings/ScriptValue.cpp:
14+
(Inspector::jsToInspectorValue): Moved from Deprecated namespace to Inspector namespace. Later, we should
15+
move this to another source file in the inspector directory.
16+
(Inspector::toInspectorValue): Added.
17+
(Deprecated::ScriptValue::toInspectorValue): Updated for change to underlying function.
18+
* bindings/ScriptValue.h: Update for the above.
19+
20+
* inspector/InjectedScript.cpp:
21+
(Inspector::InjectedScript::evaluateOnCallFrame): Changed arguments and return values from
22+
Deprecated::ScriptValue to JSC::JSValue.
23+
(Inspector::InjectedScript::functionDetails): Ditto.
24+
(Inspector::InjectedScript::wrapCallFrames): Ditto.
25+
(Inspector::InjectedScript::wrapObject): Ditto.
26+
(Inspector::InjectedScript::wrapTable): Ditto.
27+
(Inspector::InjectedScript::previewValue): Ditto.
28+
(Inspector::InjectedScript::setExceptionValue): Ditto.
29+
(Inspector::InjectedScript::findObjectById): Ditto.
30+
(Inspector::InjectedScript::inspectObject): Ditto.
31+
* inspector/InjectedScript.h: Ditto.
32+
* inspector/InjectedScriptBase.cpp:
33+
(Inspector::InjectedScriptBase::callFunctionWithEvalEnabled): Ditto.
34+
(Inspector::InjectedScriptBase::makeCall): Ditto.
35+
* inspector/InjectedScriptBase.h: Ditto.
36+
* inspector/InjectedScriptModule.cpp:
37+
(Inspector::InjectedScriptModule::ensureInjected): Ditto.
38+
* inspector/ScriptDebugListener.h: Ditto.
39+
* inspector/ScriptDebugServer.cpp:
40+
(Inspector::ScriptDebugServer::evaluateBreakpointAction): Ditto.
41+
(Inspector::ScriptDebugServer::dispatchDidPause): Ditto.
42+
(Inspector::ScriptDebugServer::dispatchBreakpointActionProbe): Ditto.
43+
(Inspector::ScriptDebugServer::exceptionOrCaughtValue): Ditto.
44+
* inspector/ScriptDebugServer.h: Ditto.
45+
* inspector/agents/InspectorDebuggerAgent.cpp:
46+
(Inspector::InspectorDebuggerAgent::buildExceptionPauseReason): Ditto.
47+
(Inspector::InspectorDebuggerAgent::didPause): Ditto.
48+
(Inspector::InspectorDebuggerAgent::breakpointActionProbe): Ditto.
49+
(Inspector::InspectorDebuggerAgent::didContinue): Ditto.
50+
(Inspector::InspectorDebuggerAgent::clearDebuggerBreakpointState): Ditto.
51+
* inspector/agents/InspectorDebuggerAgent.h: Ditto.
52+
* inspector/agents/InspectorHeapAgent.cpp:
53+
(Inspector::InspectorHeapAgent::getPreview): Ditto.
54+
(Inspector::InspectorHeapAgent::getRemoteObject): Ditto.
55+
156
2016-04-15 Keith Miller <keith_miller@apple.com>
257

358
Some JIT/DFG operations need NativeCallFrameTracers

‎Source/JavaScriptCore/bindings/ScriptFunctionCall.cpp‎

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,6 @@ void ScriptCallArgumentHandler::appendArgument(const Deprecated::ScriptObject& a
5050
m_arguments.append(argument.jsObject());
5151
}
5252

53-
void ScriptCallArgumentHandler::appendArgument(const Deprecated::ScriptValue& argument)
54-
{
55-
m_arguments.append(argument.jsValue());
56-
}
57-
5853
void ScriptCallArgumentHandler::appendArgument(const String& argument)
5954
{
6055
JSLockHolder lock(m_exec);
@@ -115,7 +110,7 @@ ScriptFunctionCall::ScriptFunctionCall(const Deprecated::ScriptObject& thisObjec
115110
{
116111
}
117112

118-
Deprecated::ScriptValue ScriptFunctionCall::call(bool& hadException)
113+
JSValue ScriptFunctionCall::call(bool& hadException)
119114
{
120115
JSObject* thisObject = m_thisObject.jsObject();
121116

@@ -124,13 +119,13 @@ Deprecated::ScriptValue ScriptFunctionCall::call(bool& hadException)
124119
JSValue function = thisObject->get(m_exec, Identifier::fromString(m_exec, m_name));
125120
if (m_exec->hadException()) {
126121
hadException = true;
127-
return Deprecated::ScriptValue();
122+
return { };
128123
}
129124

130125
CallData callData;
131126
CallType callType = getCallData(function, callData);
132127
if (callType == CallType::None)
133-
return Deprecated::ScriptValue();
128+
return { };
134129

135130
JSValue result;
136131
NakedPtr<Exception> exception;
@@ -142,15 +137,15 @@ Deprecated::ScriptValue ScriptFunctionCall::call(bool& hadException)
142137
if (exception) {
143138
// Do not treat a terminated execution exception as having an exception. Just treat it as an empty result.
144139
hadException = !isTerminatedExecutionException(exception);
145-
return Deprecated::ScriptValue();
140+
return { };
146141
}
147142

148-
return Deprecated::ScriptValue(m_exec->vm(), result);
143+
return result;
149144
}
150145

151-
Deprecated::ScriptValue ScriptFunctionCall::call()
146+
JSC::JSValue ScriptFunctionCall::call()
152147
{
153-
bool hadException = false;
148+
bool hadException;
154149
return call(hadException);
155150
}
156151

‎Source/JavaScriptCore/bindings/ScriptFunctionCall.h‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,8 @@ class JS_EXPORT_PRIVATE ScriptFunctionCall : public ScriptCallArgumentHandler {
7373
public:
7474
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>&);
7575
ScriptFunctionCall(const ScriptObject& thisObject, const String& name, ScriptFunctionCallHandler handler = nullptr);
76-
ScriptValue call(bool& hadException);
77-
ScriptValue call();
76+
JSC::JSValue call(bool& hadException);
77+
JSC::JSValue call();
7878

7979
protected:
8080
ScriptFunctionCallHandler m_callHandler;

‎Source/JavaScriptCore/bindings/ScriptValue.cpp‎

Lines changed: 66 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,71 @@
3838
using namespace JSC;
3939
using namespace Inspector;
4040

41+
namespace Inspector {
42+
43+
static 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+
96+
RefPtr<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
105+
41106
namespace Deprecated {
42107

43108
ScriptValue::~ScriptValue()
@@ -97,66 +162,10 @@ bool ScriptValue::isFunction() const
97162
return getCallData(m_value.get(), callData) != CallType::None;
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-
156165
RefPtr<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

162171
} // namespace Deprecated

‎Source/JavaScriptCore/bindings/ScriptValue.h‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,14 @@
3737
#include "Operations.h"
3838
#include "Strong.h"
3939
#include "StrongInlines.h"
40-
#include <wtf/PassRefPtr.h>
4140
#include <wtf/text/WTFString.h>
4241

4342
namespace Inspector {
43+
4444
class InspectorValue;
45+
46+
RefPtr<InspectorValue> toInspectorValue(JSC::ExecState&, JSC::JSValue);
47+
4548
}
4649

4750
namespace Deprecated {

0 commit comments

Comments
 (0)