Use asString instead of toWTFString, toString, or getString when we already checked...
authordarin@apple.com <darin@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 16 Dec 2016 04:52:20 +0000 (04:52 +0000)
committerdarin@apple.com <darin@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 16 Dec 2016 04:52:20 +0000 (04:52 +0000)
https://bugs.webkit.org/show_bug.cgi?id=165895

Reviewed by Yusuke Suzuki.

Source/JavaScriptCore:

Once we have called isString, we should always use asString and value rather than using
functions that have to deal with non-JSString objects. This leads to slightly fewer branches,
slightly less reference count churn, since the string is stored right inside the JSString,
and obviates the need for exception handling.

* bindings/ScriptValue.cpp:
(Inspector::jsToInspectorValue): Use asString/value instead of getString.
* dfg/DFGOperations.cpp:
(JSC::DFG::operationMapHash): Call jsMapHash with its new arguments.
* inspector/JSInjectedScriptHost.cpp:
(Inspector::JSInjectedScriptHost::evaluateWithScopeExtension): Use asString/value instead
of toWTFString.
* inspector/JSJavaScriptCallFrame.cpp:
(Inspector::JSJavaScriptCallFrame::evaluateWithScopeExtension): Ditto.
* inspector/agents/InspectorHeapAgent.cpp:
(Inspector::InspectorHeapAgent::getPreview): Use asString/tryGetValue, instead of the
peculiar getString(nullptr) that was here before.
* jsc.cpp:
(functionGetGetterSetter): Use asString/toIdentifier instead of the much less efficient
toWTFString/Identifier::fromString.
(functionIsRope): Use asString instead of jsCast<JSString*>; same thing, but we should
prefer the asString function, since it exists.
(functionFindTypeForExpression): Use asString/value instead of getString.
(functionHasBasicBlockExecuted): Ditto.
(functionBasicBlockExecutionCount): Ditto.
(functionCreateBuiltin): Use asString/value instead of toWTFString and removed
unneeded RETURN_IF_EXCEPTION.
(valueWithTypeOfWasmValue): Use asString instead of jsCast<String*>.
(box): Ditto.
* runtime/DateConstructor.cpp:
(JSC::constructDate): Use asString/values instead of getString.
* runtime/ExceptionHelpers.cpp:
(JSC::errorDescriptionForValue): Tweaked formatting.

* runtime/HashMapImpl.h:
(JSC::jsMapHash): Changed this function to use asString/value.

* runtime/JSCJSValue.cpp:
(JSC::JSValue::dumpInContextAssumingStructure): Use asString instead of
jsCast<JSString*>.
(JSC::JSValue::dumpForBacktrace): Ditto.
* runtime/JSCJSValueInlines.h:
(JSC::toPreferredPrimitiveType): Ditto.

* runtime/JSGlobalObjectFunctions.cpp:
(JSC::globalFuncEval): Use asString/value instead of toWTFString.

* runtime/JSString.cpp:
(JSC::JSString::destroy): Streamlined by removing local variable.
(JSC::JSString::estimatedSize): Use asString instead of jsCast<JSString*>.
(JSC::JSString::visitChildren): Ditto.
(JSC::JSString::toThis): Ditto.
* runtime/JSString.h:
(JSC::JSValue::toString): Ditto.
(JSC::JSValue::toStringOrNull): Ditto.
* runtime/NumberPrototype.cpp:
(JSC::numberProtoFuncValueOf): Ditto.
* runtime/ObjectPrototype.cpp:
(JSC::objectProtoFuncToString): Ditto.
* runtime/StringPrototype.cpp:
(JSC::stringProtoFuncRepeatCharacter): Ditto.
(JSC::stringProtoFuncSubstr): Ditto.
(JSC::builtinStringSubstrInternal): Simplified assertion by removing local variable.

Source/WebCore:

* Modules/fetch/FetchBody.cpp:
(WebCore::FetchBody::extract): Use asString/value instead of toWTFString.

* Modules/mediastream/SDPProcessor.cpp:
(WebCore::SDPProcessor::callScript): Use asString/value instead of getString.

* bindings/js/ArrayValue.cpp:
(WebCore::ArrayValue::get): Use asString/value instead of toWTFString.

* bindings/js/IDBBindingUtilities.cpp:
(WebCore::get): Use asString/length instead of toString/length.
(WebCore::createIDBKeyFromValue): Use asString/value instead of toWTFString.
* bindings/js/JSCryptoAlgorithmDictionary.cpp:
(WebCore::JSCryptoAlgorithmDictionary::getAlgorithmIdentifier): Ditto.
* bindings/js/JSDataCueCustom.cpp:
(WebCore::constructJSDataCue): Use asString/value instead of getString.
* bindings/js/JSInspectorFrontendHostCustom.cpp:
(WebCore::populateContextMenuItems): Use asString/value instead of toWTFString.

* bindings/js/ScriptController.cpp:
(WebCore::jsValueToModuleKey): Use asString/toIdentifier instead of
jsCast<JSString*>/value/Identifier::fromString.

* bindings/js/SerializedScriptValue.cpp:
(WebCore::CloneSerializer::dumpIfTerminal): Streamline by getting rid of local variable.

* contentextensions/ContentExtensionParser.cpp:
(WebCore::ContentExtensions::getDomainList): Use asString instead of jsCast<JSString*>.
(WebCore::ContentExtensions::loadTrigger): Use asString/value instead of toWTFString.
(WebCore::ContentExtensions::loadAction): Ditto.

* css/FontFace.cpp:
(WebCore::FontFace::create): Use asString/value instead of getString.

Source/WebKit/mac:

* Plugins/Hosted/NetscapePluginInstanceProxy.mm:
(WebKit::NetscapePluginInstanceProxy::addValueToArray): Use asString/value instead of
toWTFString.
* WebView/WebView.mm:
(aeDescFromJSValue): Use asString/value instead of getString.

Source/WebKit2:

* WebProcess/Plugins/Netscape/NPRuntimeObjectMap.cpp:
(WebKit::NPRuntimeObjectMap::convertJSValueToNPVariant): Use asString/value instead of toWTFString.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@209906 268f45cc-cd09-0410-ab3c-d52691b4dbfc

34 files changed:
Source/JavaScriptCore/ChangeLog
Source/JavaScriptCore/bindings/ScriptValue.cpp
Source/JavaScriptCore/inspector/JSInjectedScriptHost.cpp
Source/JavaScriptCore/inspector/JSJavaScriptCallFrame.cpp
Source/JavaScriptCore/inspector/agents/InspectorHeapAgent.cpp
Source/JavaScriptCore/jsc.cpp
Source/JavaScriptCore/runtime/DateConstructor.cpp
Source/JavaScriptCore/runtime/ExceptionHelpers.cpp
Source/JavaScriptCore/runtime/HashMapImpl.h
Source/JavaScriptCore/runtime/JSCJSValue.cpp
Source/JavaScriptCore/runtime/JSCJSValueInlines.h
Source/JavaScriptCore/runtime/JSGlobalObjectFunctions.cpp
Source/JavaScriptCore/runtime/JSString.cpp
Source/JavaScriptCore/runtime/JSString.h
Source/JavaScriptCore/runtime/NumberPrototype.cpp
Source/JavaScriptCore/runtime/ObjectPrototype.cpp
Source/JavaScriptCore/runtime/StringPrototype.cpp
Source/WebCore/ChangeLog
Source/WebCore/Modules/fetch/FetchBody.cpp
Source/WebCore/Modules/mediastream/SDPProcessor.cpp
Source/WebCore/bindings/js/ArrayValue.cpp
Source/WebCore/bindings/js/IDBBindingUtilities.cpp
Source/WebCore/bindings/js/JSCryptoAlgorithmDictionary.cpp
Source/WebCore/bindings/js/JSDataCueCustom.cpp
Source/WebCore/bindings/js/JSInspectorFrontendHostCustom.cpp
Source/WebCore/bindings/js/ScriptController.cpp
Source/WebCore/bindings/js/SerializedScriptValue.cpp
Source/WebCore/contentextensions/ContentExtensionParser.cpp
Source/WebCore/css/FontFace.cpp
Source/WebKit/mac/ChangeLog
Source/WebKit/mac/Plugins/Hosted/NetscapePluginInstanceProxy.mm
Source/WebKit/mac/WebView/WebView.mm
Source/WebKit2/ChangeLog
Source/WebKit2/WebProcess/Plugins/Netscape/NPRuntimeObjectMap.cpp

index 744c9b5..dd13632 100644 (file)
@@ -1,3 +1,74 @@
+2016-12-15  Darin Adler  <darin@apple.com>
+
+        Use asString instead of toWTFString, toString, or getString when we already checked isString
+        https://bugs.webkit.org/show_bug.cgi?id=165895
+
+        Reviewed by Yusuke Suzuki.
+
+        Once we have called isString, we should always use asString and value rather than using
+        functions that have to deal with non-JSString objects. This leads to slightly fewer branches,
+        slightly less reference count churn, since the string is stored right inside the JSString,
+        and obviates the need for exception handling.
+
+        * bindings/ScriptValue.cpp:
+        (Inspector::jsToInspectorValue): Use asString/value instead of getString.
+        * dfg/DFGOperations.cpp:
+        (JSC::DFG::operationMapHash): Call jsMapHash with its new arguments.
+        * inspector/JSInjectedScriptHost.cpp:
+        (Inspector::JSInjectedScriptHost::evaluateWithScopeExtension): Use asString/value instead
+        of toWTFString.
+        * inspector/JSJavaScriptCallFrame.cpp:
+        (Inspector::JSJavaScriptCallFrame::evaluateWithScopeExtension): Ditto.
+        * inspector/agents/InspectorHeapAgent.cpp:
+        (Inspector::InspectorHeapAgent::getPreview): Use asString/tryGetValue, instead of the
+        peculiar getString(nullptr) that was here before.
+        * jsc.cpp:
+        (functionGetGetterSetter): Use asString/toIdentifier instead of the much less efficient
+        toWTFString/Identifier::fromString.
+        (functionIsRope): Use asString instead of jsCast<JSString*>; same thing, but we should
+        prefer the asString function, since it exists.
+        (functionFindTypeForExpression): Use asString/value instead of getString.
+        (functionHasBasicBlockExecuted): Ditto.
+        (functionBasicBlockExecutionCount): Ditto.
+        (functionCreateBuiltin): Use asString/value instead of toWTFString and removed
+        unneeded RETURN_IF_EXCEPTION.
+        (valueWithTypeOfWasmValue): Use asString instead of jsCast<String*>.
+        (box): Ditto.
+        * runtime/DateConstructor.cpp:
+        (JSC::constructDate): Use asString/values instead of getString.
+        * runtime/ExceptionHelpers.cpp:
+        (JSC::errorDescriptionForValue): Tweaked formatting.
+
+        * runtime/HashMapImpl.h:
+        (JSC::jsMapHash): Changed this function to use asString/value.
+
+        * runtime/JSCJSValue.cpp:
+        (JSC::JSValue::dumpInContextAssumingStructure): Use asString instead of
+        jsCast<JSString*>.
+        (JSC::JSValue::dumpForBacktrace): Ditto.
+        * runtime/JSCJSValueInlines.h:
+        (JSC::toPreferredPrimitiveType): Ditto.
+
+        * runtime/JSGlobalObjectFunctions.cpp:
+        (JSC::globalFuncEval): Use asString/value instead of toWTFString.
+
+        * runtime/JSString.cpp:
+        (JSC::JSString::destroy): Streamlined by removing local variable.
+        (JSC::JSString::estimatedSize): Use asString instead of jsCast<JSString*>.
+        (JSC::JSString::visitChildren): Ditto.
+        (JSC::JSString::toThis): Ditto.
+        * runtime/JSString.h:
+        (JSC::JSValue::toString): Ditto.
+        (JSC::JSValue::toStringOrNull): Ditto.
+        * runtime/NumberPrototype.cpp:
+        (JSC::numberProtoFuncValueOf): Ditto.
+        * runtime/ObjectPrototype.cpp:
+        (JSC::objectProtoFuncToString): Ditto.
+        * runtime/StringPrototype.cpp:
+        (JSC::stringProtoFuncRepeatCharacter): Ditto.
+        (JSC::stringProtoFuncSubstr): Ditto.
+        (JSC::builtinStringSubstrInternal): Simplified assertion by removing local variable.
+
 2016-12-15  Keith Miller  <keith_miller@apple.com>
 
         Fix validation of non-void if blocks with no else
index 25568a3..2a94f3b 100644 (file)
@@ -61,7 +61,7 @@ static RefPtr<InspectorValue> jsToInspectorValue(ExecState& scriptState, JSValue
     if (value.isNumber() && value.isAnyInt())
         return InspectorValue::create(static_cast<int>(value.asAnyInt()));
     if (value.isString())
-        return InspectorValue::create(value.getString(&scriptState));
+        return InspectorValue::create(asString(value)->value(&scriptState));
 
     if (value.isObject()) {
         if (isJSArray(value)) {
index 3f26fe6..eb59171 100644 (file)
@@ -102,7 +102,7 @@ JSValue JSInjectedScriptHost::evaluateWithScopeExtension(ExecState* exec)
     if (!scriptValue.isString())
         return throwTypeError(exec, scope, ASCIILiteral("InjectedScriptHost.evaluateWithScopeExtension first argument must be a string."));
 
-    String program = scriptValue.toWTFString(exec);
+    String program = asString(scriptValue)->value(exec);
     RETURN_IF_EXCEPTION(scope, JSValue());
 
     NakedPtr<Exception> exception;
index c6aa4a7..f4ed3f7 100644 (file)
@@ -82,7 +82,7 @@ JSValue JSJavaScriptCallFrame::evaluateWithScopeExtension(ExecState* exec)
     if (!scriptValue.isString())
         return throwTypeError(exec, scope, ASCIILiteral("JSJavaScriptCallFrame.evaluateWithScopeExtension first argument must be a string."));
 
-    String script = scriptValue.toWTFString(exec);
+    String script = asString(scriptValue)->value(exec);
     RETURN_IF_EXCEPTION(scope, JSValue());
 
     NakedPtr<Exception> exception;
index 8a39a84..ad86c07 100644 (file)
@@ -251,7 +251,7 @@ void InspectorHeapAgent::getPreview(ErrorString& errorString, int heapObjectId,
     // String preview.
     JSCell* cell = optionalNode->cell;
     if (cell->isString()) {
-        *resultString = cell->getString(nullptr);
+        *resultString = asString(cell)->tryGetValue();
         return;
     }
 
index d588651..29238a0 100644 (file)
@@ -1876,10 +1876,8 @@ static EncodedJSValue JSC_HOST_CALL functionGetGetterSetter(ExecState* exec)
     if (!property.isString())
         return JSValue::encode(jsUndefined());
 
-    Identifier ident = Identifier::fromString(&exec->vm(), property.toWTFString(exec));
-
     PropertySlot slot(value, PropertySlot::InternalMethodType::VMInquiry);
-    value.getPropertySlot(exec, ident, slot);
+    value.getPropertySlot(exec, asString(property)->toIdentifier(exec), slot);
 
     JSValue result;
     if (slot.isCacheableGetter())
@@ -2104,7 +2102,7 @@ EncodedJSValue JSC_HOST_CALL functionIsRope(ExecState* exec)
     JSValue argument = exec->argument(0);
     if (!argument.isString())
         return JSValue::encode(jsBoolean(false));
-    const StringImpl* impl = jsCast<JSString*>(argument)->tryGetValueImpl();
+    const StringImpl* impl = asString(argument)->tryGetValueImpl();
     return JSValue::encode(jsBoolean(!impl));
 }
 
@@ -2282,7 +2280,7 @@ EncodedJSValue JSC_HOST_CALL functionFindTypeForExpression(ExecState* exec)
     FunctionExecutable* executable = (jsDynamicCast<JSFunction*>(functionValue.asCell()->getObject()))->jsExecutable();
 
     RELEASE_ASSERT(exec->argument(1).isString());
-    String substring = exec->argument(1).getString(exec);
+    String substring = asString(exec->argument(1))->value(exec);
     String sourceCodeText = executable->source().view().toString();
     unsigned offset = static_cast<unsigned>(sourceCodeText.find(substring) + executable->source().startOffset());
     
@@ -2320,7 +2318,7 @@ EncodedJSValue JSC_HOST_CALL functionHasBasicBlockExecuted(ExecState* exec)
     FunctionExecutable* executable = (jsDynamicCast<JSFunction*>(functionValue.asCell()->getObject()))->jsExecutable();
 
     RELEASE_ASSERT(exec->argument(1).isString());
-    String substring = exec->argument(1).getString(exec);
+    String substring = asString(exec->argument(1))->value(exec);
     String sourceCodeText = executable->source().view().toString();
     RELEASE_ASSERT(sourceCodeText.contains(substring));
     int offset = sourceCodeText.find(substring) + executable->source().startOffset();
@@ -2338,7 +2336,7 @@ EncodedJSValue JSC_HOST_CALL functionBasicBlockExecutionCount(ExecState* exec)
     FunctionExecutable* executable = (jsDynamicCast<JSFunction*>(functionValue.asCell()->getObject()))->jsExecutable();
 
     RELEASE_ASSERT(exec->argument(1).isString());
-    String substring = exec->argument(1).getString(exec);
+    String substring = asString(exec->argument(1))->value(exec);
     String sourceCodeText = executable->source().view().toString();
     RELEASE_ASSERT(sourceCodeText.contains(substring));
     int offset = sourceCodeText.find(substring) + executable->source().startOffset();
@@ -2403,7 +2401,7 @@ EncodedJSValue JSC_HOST_CALL functionCreateBuiltin(ExecState* exec)
     if (exec->argumentCount() < 1 || !exec->argument(0).isString())
         return JSValue::encode(jsUndefined());
 
-    String functionText = exec->argument(0).toWTFString(exec);
+    String functionText = asString(exec->argument(0))->value(exec);
     RETURN_IF_EXCEPTION(scope, encodedJSValue());
 
     const SourceCode& source = makeSource(functionText);
@@ -2510,7 +2508,7 @@ EncodedJSValue JSC_HOST_CALL functionMaxArguments(ExecState*)
 
 static CString valueWithTypeOfWasmValue(ExecState* exec, VM& vm, JSValue value, JSValue wasmValue)
 {
-    JSString* type = jsCast<JSString*>(wasmValue.get(exec, makeIdentifier(vm, "type")));
+    JSString* type = asString(wasmValue.get(exec, makeIdentifier(vm, "type")));
 
     const String& typeString = type->value(exec);
     if (typeString == "i64" || typeString == "i32")
@@ -2523,14 +2521,14 @@ static CString valueWithTypeOfWasmValue(ExecState* exec, VM& vm, JSValue value,
 static JSValue box(ExecState* exec, VM& vm, JSValue wasmValue)
 {
 
-    JSString* type = jsCast<JSString*>(wasmValue.get(exec, makeIdentifier(vm, "type")));
+    JSString* type = asString(wasmValue.get(exec, makeIdentifier(vm, "type")));
     JSValue value = wasmValue.get(exec, makeIdentifier(vm, "value"));
 
     auto unboxString = [&] (const char* hexFormat, const char* decFormat, auto& result) {
         if (!value.isString())
             return false;
 
-        const char* str = toCString(jsCast<JSString*>(value)->value(exec)).data();
+        const char* str = toCString(asString(value)->value(exec)).data();
         int scanResult;
         int length = std::strlen(str);
         if ((length > 2 && (str[0] == '0' && str[1] == 'x'))
index a825017..405074b 100644 (file)
@@ -160,7 +160,7 @@ JSObject* constructDate(ExecState* exec, JSGlobalObject* globalObject, JSValue n
             JSValue primitive = args.at(0).toPrimitive(exec);
             RETURN_IF_EXCEPTION(scope, nullptr);
             if (primitive.isString())
-                value = parseDate(vm, primitive.getString(exec));
+                value = parseDate(vm, asString(primitive)->value(exec));
             else
                 value = primitive.toNumber(exec);
         }
index fc07553..fb67e21 100644 (file)
@@ -85,7 +85,7 @@ JSObject* createUndefinedVariableError(ExecState* exec, const Identifier& ident)
 JSString* errorDescriptionForValue(ExecState* exec, JSValue v)
 {
     if (v.isString())
-        return jsNontrivialString(exec, makeString('"',  asString(v)->value(exec), '"'));
+        return jsNontrivialString(exec, makeString('"', asString(v)->value(exec), '"'));
     if (v.isSymbol())
         return jsNontrivialString(exec, asSymbol(v)->descriptiveString());
     if (v.isObject()) {
index 5bd0117..f88fa83 100644 (file)
@@ -240,17 +240,14 @@ ALWAYS_INLINE uint32_t jsMapHash(ExecState* exec, VM& vm, JSValue value)
 {
     ASSERT_WITH_MESSAGE(normalizeMapKey(value) == value, "We expect normalized values flowing into this function.");
 
-    auto scope = DECLARE_THROW_SCOPE(vm);
-
     if (value.isString()) {
-        JSString* string = asString(value);
-        const String& wtfString = string->value(exec);
+        auto scope = DECLARE_THROW_SCOPE(vm);
+        const String& wtfString = asString(value)->value(exec);
         RETURN_IF_EXCEPTION(scope, UINT_MAX);
         return wtfString.impl()->hash();
     }
 
-    uint64_t rawValue = JSValue::encode(value);
-    return wangsInt64Hash(rawValue);
+    return wangsInt64Hash(JSValue::encode(value));
 }
 
 ALWAYS_INLINE std::optional<uint32_t> concurrentJSMapHash(JSValue key)
index 1f8c6d5..0d5f495 100644 (file)
@@ -247,7 +247,7 @@ void JSValue::dumpInContextAssumingStructure(
 #endif
     } else if (isCell()) {
         if (structure->classInfo()->isSubClassOf(JSString::info())) {
-            JSString* string = jsCast<JSString*>(asCell());
+            JSString* string = asString(asCell());
             out.print("String");
             if (string->isRope())
                 out.print(" (rope)");
@@ -299,7 +299,7 @@ void JSValue::dumpForBacktrace(PrintStream& out) const
         out.printf("%lf", asDouble());
     else if (isCell()) {
         if (asCell()->inherits(JSString::info())) {
-            JSString* string = jsCast<JSString*>(asCell());
+            JSString* string = asString(asCell());
             const StringImpl* impl = string->tryGetValueImpl();
             if (impl)
                 out.print("\"", impl, "\"");
index bf9f59f..74963ac 100644 (file)
@@ -662,7 +662,7 @@ inline PreferredPrimitiveType toPreferredPrimitiveType(ExecState* exec, JSValue
         return NoPreference;
     }
 
-    StringImpl* hintString = jsCast<JSString*>(value)->value(exec).impl();
+    StringImpl* hintString = asString(value)->value(exec).impl();
     RETURN_IF_EXCEPTION(scope, NoPreference);
 
     if (WTF::equal(hintString, "default"))
index c62e4f7..5ce0903 100644 (file)
@@ -666,7 +666,7 @@ EncodedJSValue JSC_HOST_CALL globalFuncEval(ExecState* exec)
         return JSValue::encode(jsUndefined());
     }
 
-    String s = x.toWTFString(exec);
+    String s = asString(x)->value(exec);
     RETURN_IF_EXCEPTION(scope, encodedJSValue());
 
     if (s.is8Bit()) {
index db631c0..6b7d94a 100644 (file)
@@ -52,8 +52,7 @@ void JSRopeString::RopeBuilder::expand()
 
 void JSString::destroy(JSCell* cell)
 {
-    JSString* thisObject = static_cast<JSString*>(cell);
-    thisObject->JSString::~JSString();
+    static_cast<JSString*>(cell)->JSString::~JSString();
 }
 
 void JSString::dumpToStream(const JSCell* cell, PrintStream& out)
@@ -84,7 +83,7 @@ bool JSString::equalSlowCase(ExecState* exec, JSString* other) const
 
 size_t JSString::estimatedSize(JSCell* cell)
 {
-    JSString* thisObject = jsCast<JSString*>(cell);
+    JSString* thisObject = asString(cell);
     if (thisObject->isRope())
         return Base::estimatedSize(cell);
     return Base::estimatedSize(cell) + thisObject->m_value.impl()->costDuringGC();
@@ -92,7 +91,7 @@ size_t JSString::estimatedSize(JSCell* cell)
 
 void JSString::visitChildren(JSCell* cell, SlotVisitor& visitor)
 {
-    JSString* thisObject = jsCast<JSString*>(cell);
+    JSString* thisObject = asString(cell);
     Base::visitChildren(thisObject, visitor);
     
     if (thisObject->isRope())
@@ -421,7 +420,7 @@ JSValue JSString::toThis(JSCell* cell, ExecState* exec, ECMAMode ecmaMode)
 {
     if (ecmaMode == StrictMode)
         return cell;
-    return StringObject::create(exec->vm(), exec->lexicalGlobalObject(), jsCast<JSString*>(cell));
+    return StringObject::create(exec->vm(), exec->lexicalGlobalObject(), asString(cell));
 }
 
 bool JSString::getStringPropertyDescriptor(ExecState* exec, PropertyName propertyName, PropertyDescriptor& descriptor)
index 95b0b0d..1f77819 100644 (file)
@@ -755,7 +755,7 @@ inline bool JSValue::toBoolean(ExecState* exec) const
 inline JSString* JSValue::toString(ExecState* exec) const
 {
     if (isString())
-        return jsCast<JSString*>(asCell());
+        return asString(asCell());
     bool returnEmptyStringOnError = true;
     return toStringSlowCase(exec, returnEmptyStringOnError);
 }
@@ -763,7 +763,7 @@ inline JSString* JSValue::toString(ExecState* exec) const
 inline JSString* JSValue::toStringOrNull(ExecState* exec) const
 {
     if (isString())
-        return jsCast<JSString*>(asCell());
+        return asString(asCell());
     bool returnEmptyStringOnError = false;
     return toStringSlowCase(exec, returnEmptyStringOnError);
 }
index 9666e65..dc96ee4 100644 (file)
@@ -539,7 +539,7 @@ EncodedJSValue JSC_HOST_CALL numberProtoFuncValueOf(ExecState* exec)
     double x;
     JSValue thisValue = exec->thisValue();
     if (!toThisNumber(thisValue, x))
-        return throwVMTypeError(exec, scope, WTF::makeString("thisNumberValue called on incompatible ", jsCast<JSString*>(jsTypeStringForValue(exec, thisValue))->value(exec)));
+        return throwVMTypeError(exec, scope, WTF::makeString("thisNumberValue called on incompatible ", asString(jsTypeStringForValue(exec, thisValue))->value(exec)));
     return JSValue::encode(jsNumber(x));
 }
 
index 69d313f..18a1f7d 100644 (file)
@@ -326,7 +326,7 @@ EncodedJSValue JSC_HOST_CALL objectProtoFuncToString(ExecState* exec)
             if (stringTag.isString()) {
                 JSRopeString::RopeBuilder ropeBuilder(vm);
                 ropeBuilder.append(vm.smallStrings.objectStringStart());
-                ropeBuilder.append(jsCast<JSString*>(stringTag));
+                ropeBuilder.append(asString(stringTag));
                 ropeBuilder.append(vm.smallStrings.singleCharacterString(']'));
                 JSString* result = ropeBuilder.release();
 
index aeee4bc..f313a8a 100644 (file)
@@ -810,7 +810,7 @@ EncodedJSValue JSC_HOST_CALL stringProtoFuncRepeatCharacter(ExecState* exec)
     ASSERT(exec->argumentCount() == 2);
 
     ASSERT(exec->uncheckedArgument(0).isString());
-    JSString* string = jsCast<JSString*>(exec->uncheckedArgument(0));
+    JSString* string = asString(exec->uncheckedArgument(0));
     ASSERT(string->length() == 1);
 
     JSValue repeatCountValue = exec->uncheckedArgument(1);
@@ -1321,7 +1321,7 @@ EncodedJSValue JSC_HOST_CALL stringProtoFuncSubstr(ExecState* exec)
     JSString* jsString = 0;
     String uString;
     if (thisValue.isString()) {
-        jsString = jsCast<JSString*>(thisValue.asCell());
+        jsString = asString(thisValue);
         len = jsString->length();
     } else {
         uString = thisValue.toWTFString(exec);
@@ -1360,10 +1360,7 @@ EncodedJSValue JSC_HOST_CALL builtinStringSubstrInternal(ExecState* exec)
     // guarantee that we only pass it a string thisValue. As a result, stringProtoFuncSubstr
     // will not need to call toString() on the thisValue, and there will be no observable
     // side-effects.
-#if !ASSERT_DISABLED
-    JSValue thisValue = exec->thisValue();
-    ASSERT(thisValue.isString());
-#endif
+    ASSERT(exec->thisValue().isString());
     return stringProtoFuncSubstr(exec);
 }
 
index 0ffde60..b2cf245 100644 (file)
@@ -1,3 +1,44 @@
+2016-12-15  Darin Adler  <darin@apple.com>
+
+        Use asString instead of toWTFString, toString, or getString when we already checked isString
+        https://bugs.webkit.org/show_bug.cgi?id=165895
+
+        Reviewed by Yusuke Suzuki.
+
+        * Modules/fetch/FetchBody.cpp:
+        (WebCore::FetchBody::extract): Use asString/value instead of toWTFString.
+
+        * Modules/mediastream/SDPProcessor.cpp:
+        (WebCore::SDPProcessor::callScript): Use asString/value instead of getString.
+
+        * bindings/js/ArrayValue.cpp:
+        (WebCore::ArrayValue::get): Use asString/value instead of toWTFString.
+
+        * bindings/js/IDBBindingUtilities.cpp:
+        (WebCore::get): Use asString/length instead of toString/length.
+        (WebCore::createIDBKeyFromValue): Use asString/value instead of toWTFString.
+        * bindings/js/JSCryptoAlgorithmDictionary.cpp:
+        (WebCore::JSCryptoAlgorithmDictionary::getAlgorithmIdentifier): Ditto.
+        * bindings/js/JSDataCueCustom.cpp:
+        (WebCore::constructJSDataCue): Use asString/value instead of getString.
+        * bindings/js/JSInspectorFrontendHostCustom.cpp:
+        (WebCore::populateContextMenuItems): Use asString/value instead of toWTFString.
+
+        * bindings/js/ScriptController.cpp:
+        (WebCore::jsValueToModuleKey): Use asString/toIdentifier instead of
+        jsCast<JSString*>/value/Identifier::fromString.
+
+        * bindings/js/SerializedScriptValue.cpp:
+        (WebCore::CloneSerializer::dumpIfTerminal): Streamline by getting rid of local variable.
+
+        * contentextensions/ContentExtensionParser.cpp:
+        (WebCore::ContentExtensions::getDomainList): Use asString instead of jsCast<JSString*>.
+        (WebCore::ContentExtensions::loadTrigger): Use asString/value instead of toWTFString.
+        (WebCore::ContentExtensions::loadAction): Ditto.
+
+        * css/FontFace.cpp:
+        (WebCore::FontFace::create): Use asString/value instead of getString.
+
 2016-12-15  Zalan Bujtas  <zalan@apple.com>
 
         Change ::computeLogicalHeight's computedValues out argument to the return value.
index a6cfe05..c709b69 100644 (file)
@@ -62,7 +62,7 @@ std::optional<FetchBody> FetchBody::extract(ScriptExecutionContext& context, JSC
     }
     if (value.isString()) {
         contentType = HTTPHeaderValues::textPlainContentType();
-        return FetchBody(value.toWTFString(&state));
+        return FetchBody(String { asString(value)->value(&state) });
     }
     if (value.inherits(JSURLSearchParams::info())) {
         contentType = HTTPHeaderValues::formURLEncodedContentType();
index 61d11b6..9254fdc 100644 (file)
@@ -538,7 +538,7 @@ bool SDPProcessor::callScript(const String& functionName, const String& argument
     if (!result.isString())
         return false;
 
-    outResult = result.getString(exec);
+    outResult = asString(result)->value(exec);
     return true;
 }
 
index 140eea5..63c9538 100644 (file)
@@ -93,7 +93,7 @@ bool ArrayValue::get(size_t index, String& value) const
     if (indexedValue.isUndefinedOrNull() || !indexedValue.isString())
         return false;
 
-    value = indexedValue.toWTFString(m_exec);
+    value = asString(indexedValue)->value(m_exec);
     RETURN_IF_EXCEPTION(scope, false);
 
     return true;
index 0a061a2..2b2e9f9 100644 (file)
@@ -56,7 +56,7 @@ namespace WebCore {
 static bool get(ExecState& exec, JSValue object, const String& keyPathElement, JSValue& result)
 {
     if (object.isString() && keyPathElement == "length") {
-        result = jsNumber(object.toString(&exec)->length());
+        result = jsNumber(asString(object)->length());
         return true;
     }
     if (!object.isObject())
@@ -148,7 +148,7 @@ static RefPtr<IDBKey> createIDBKeyFromValue(ExecState& exec, JSValue value, Vect
         return IDBKey::createNumber(value.toNumber(&exec));
 
     if (value.isString())
-        return IDBKey::createString(value.toWTFString(&exec));
+        return IDBKey::createString(asString(value)->value(&exec));
 
     if (value.inherits(DateInstance::info()) && !std::isnan(valueToDate(&exec, value)))
         return IDBKey::createDate(valueToDate(&exec, value));
index f87a17b..959f9d8 100644 (file)
@@ -66,7 +66,7 @@ bool JSCryptoAlgorithmDictionary::getAlgorithmIdentifier(ExecState& state, JSVal
     String algorithmName;
 
     if (value.isString()) {
-        algorithmName = value.toWTFString(&state);
+        algorithmName = asString(value)->value(&state);
         RETURN_IF_EXCEPTION(scope, false);
     } else if (value.isObject()) {
         if (asObject(value)->inherits(StringObject::info())) {
index 53c5d50..c7efc51 100644 (file)
@@ -72,7 +72,7 @@ EncodedJSValue JSC_HOST_CALL constructJSDataCue(ExecState& exec)
     if (exec.argumentCount() > 3) {
         if (!exec.uncheckedArgument(3).isString())
             return throwArgumentTypeError(exec, scope, 3, "type", "DataCue", nullptr, "DOMString");
-        type = exec.uncheckedArgument(3).getString(&exec);
+        type = asString(exec.uncheckedArgument(3))->value(&exec);
     }
 #endif
 
index 42b432f..ab93c5e 100644 (file)
@@ -62,7 +62,7 @@ static void populateContextMenuItems(ExecState* exec, JSArray* array, ContextMen
         if (!type.isString())
             continue;
 
-        String typeString = type.toWTFString(exec);
+        String typeString = asString(type)->value(exec);
         if (typeString == "separator") {
             ContextMenuItem item(SeparatorType, ContextMenuItemTagNoAction, String());
             menu.appendItem(item);
index 90510e8..7b87495 100644 (file)
@@ -355,7 +355,7 @@ static Identifier jsValueToModuleKey(ExecState* exec, JSValue value)
     if (value.isSymbol())
         return Identifier::fromUid(jsCast<Symbol*>(value)->privateName());
     ASSERT(value.isString());
-    return Identifier::fromString(exec, jsCast<JSString*>(value)->value(exec));
+    return asString(value)->toIdentifier(exec);
 }
 
 void ScriptController::setupModuleScriptHandlers(CachedModuleScript& moduleScriptRef, JSInternalPromise& promise, DOMWrapperWorld& world)
index 2b12b01..ebf0494 100644 (file)
@@ -749,8 +749,7 @@ private:
         }
 
         if (value.isString()) {
-            String str = asString(value)->value(m_exec);
-            dumpString(str);
+            dumpString(asString(value)->value(m_exec));
             return true;
         }
 
index ce395fb..c0b3e3b 100644 (file)
@@ -75,7 +75,7 @@ static std::error_code getDomainList(ExecState& exec, const JSObject* arrayObjec
             return ContentExtensionError::JSONInvalidDomainList;
         
         // Domains should be punycode encoded lower case.
-        const String& domain = jsCast<JSString*>(value)->value(&exec);
+        const String& domain = asString(value)->value(&exec);
         if (domain.isEmpty())
             return ContentExtensionError::JSONInvalidDomainList;
         if (!containsOnlyASCIIWithNoUppercase(domain))
@@ -130,7 +130,7 @@ static std::error_code loadTrigger(ExecState& exec, const JSObject& ruleObject,
     if (!urlFilterObject || scope.exception() || !urlFilterObject.isString())
         return ContentExtensionError::JSONInvalidURLFilterInTrigger;
 
-    String urlFilter = urlFilterObject.toWTFString(&exec);
+    String urlFilter = asString(urlFilterObject)->value(&exec);
     if (urlFilter.isEmpty())
         return ContentExtensionError::JSONInvalidURLFilterInTrigger;
 
@@ -207,7 +207,7 @@ static std::error_code loadAction(ExecState& exec, const JSObject& ruleObject, A
     if (!typeObject || scope.exception() || !typeObject.isString())
         return ContentExtensionError::JSONInvalidActionType;
 
-    String actionType = typeObject.toWTFString(&exec);
+    String actionType = asString(typeObject)->value(&exec);
 
     if (actionType == "block")
         action = ActionType::BlockLoad;
@@ -220,13 +220,13 @@ static std::error_code loadAction(ExecState& exec, const JSObject& ruleObject, A
         if (!selector || scope.exception() || !selector.isString())
             return ContentExtensionError::JSONInvalidCSSDisplayNoneActionType;
 
-        String s = selector.toWTFString(&exec);
-        if (!isValidSelector(s)) {
+        String selectorString = asString(selector)->value(&exec);
+        if (!isValidSelector(selectorString)) {
             // Skip rules with invalid selectors to be backwards-compatible.
             validSelector = false;
             return { };
         }
-        action = Action(ActionType::CSSDisplayNoneSelector, s);
+        action = Action(ActionType::CSSDisplayNoneSelector, selectorString);
     } else if (actionType == "make-https") {
         action = ActionType::MakeHTTPS;
     } else
index 28191aa..c9fb733 100644 (file)
@@ -57,7 +57,7 @@ ExceptionOr<Ref<FontFace>> FontFace::create(JSC::ExecState& state, Document& doc
         return setFamilyResult.releaseException();
 
     if (source.isString()) {
-        auto value = FontFace::parseString(source.getString(&state), CSSPropertySrc);
+        auto value = FontFace::parseString(asString(source)->value(&state), CSSPropertySrc);
         if (!is<CSSValueList>(value.get()))
             return Exception { SYNTAX_ERR };
         CSSFontFace::appendSources(result->backing(), downcast<CSSValueList>(*value), &document, false);
index 0bf8531..a031526 100644 (file)
@@ -1,3 +1,16 @@
+2016-12-15  Darin Adler  <darin@apple.com>
+
+        Use asString instead of toWTFString, toString, or getString when we already checked isString
+        https://bugs.webkit.org/show_bug.cgi?id=165895
+
+        Reviewed by Yusuke Suzuki.
+
+        * Plugins/Hosted/NetscapePluginInstanceProxy.mm:
+        (WebKit::NetscapePluginInstanceProxy::addValueToArray): Use asString/value instead of
+        toWTFString.
+        * WebView/WebView.mm:
+        (aeDescFromJSValue): Use asString/value instead of getString.
+
 2016-12-15  Chris Dumez  <cdumez@apple.com>
 
         Make sure HTML validation bubble's state is updated after layout
index b9ab8a0..0e1de48 100644 (file)
@@ -1320,7 +1320,7 @@ void NetscapePluginInstanceProxy::addValueToArray(NSMutableArray *array, ExecSta
 
     if (value.isString()) {
         [array addObject:[NSNumber numberWithInt:StringValueType]];
-        [array addObject:value.toWTFString(exec)];
+        [array addObject:asString(value)->value(exec)];
     } else if (value.isNumber()) {
         [array addObject:[NSNumber numberWithInt:DoubleValueType]];
         [array addObject:[NSNumber numberWithDouble:value.toNumber(exec)]];
index e63b149..1706416 100644 (file)
@@ -7369,7 +7369,7 @@ static NSAppleEventDescriptor* aeDescFromJSValue(ExecState* exec, JSC::JSValue j
     if (jsValue.isBoolean())
         return [NSAppleEventDescriptor descriptorWithBoolean:jsValue.asBoolean()];
     if (jsValue.isString())
-        return [NSAppleEventDescriptor descriptorWithString:jsValue.getString(exec)];
+        return [NSAppleEventDescriptor descriptorWithString:asString(jsValue)->value(exec)];
     if (jsValue.isNumber()) {
         double value = jsValue.asNumber();
         int intValue = value;
index 0c5b736..6436900 100644 (file)
@@ -1,3 +1,13 @@
+2016-12-15  Darin Adler  <darin@apple.com>
+
+        Use asString instead of toWTFString, toString, or getString when we already checked isString
+        https://bugs.webkit.org/show_bug.cgi?id=165895
+
+        Reviewed by Yusuke Suzuki.
+
+        * WebProcess/Plugins/Netscape/NPRuntimeObjectMap.cpp:
+        (WebKit::NPRuntimeObjectMap::convertJSValueToNPVariant): Use asString/value instead of toWTFString.
+
 2016-12-15  Chris Dumez  <cdumez@apple.com>
 
         Make sure HTML validation bubble's state is updated after layout
index 2593289..08a219f 100644 (file)
@@ -168,7 +168,7 @@ void NPRuntimeObjectMap::convertJSValueToNPVariant(ExecState* exec, JSValue valu
     }
 
     if (value.isString()) {
-        NPString npString = createNPString(value.toWTFString(exec).utf8());
+        NPString npString = createNPString(asString(value)->value(exec).utf8());
         STRINGN_TO_NPVARIANT(npString.UTF8Characters, npString.UTF8Length, variant);
         return;
     }