Title: [252753] trunk
Revision
252753
Author
[email protected]
Date
2019-11-21 15:18:48 -0800 (Thu, 21 Nov 2019)

Log Message

Unreviewed, rolling out r252683 and r252721.
https://bugs.webkit.org/show_bug.cgi?id=204475

13% regression in JetStream2/prepack-wtb (Requested by
yusukesuzuki on #webkit).

Reverted changesets:

"Implement String.prototype.replaceAll"
https://bugs.webkit.org/show_bug.cgi?id=202471
https://trac.webkit.org/changeset/252683

"Unreviewed, address Darin's feedback on r252683."
https://trac.webkit.org/changeset/252721

Modified Paths

Removed Paths

Diff

Modified: trunk/JSTests/ChangeLog (252752 => 252753)


--- trunk/JSTests/ChangeLog	2019-11-21 22:42:39 UTC (rev 252752)
+++ trunk/JSTests/ChangeLog	2019-11-21 23:18:48 UTC (rev 252753)
@@ -1,3 +1,20 @@
+2019-11-21  Commit Queue  <[email protected]>
+
+        Unreviewed, rolling out r252683 and r252721.
+        https://bugs.webkit.org/show_bug.cgi?id=204475
+
+        13% regression in JetStream2/prepack-wtb (Requested by
+        yusukesuzuki on #webkit).
+
+        Reverted changesets:
+
+        "Implement String.prototype.replaceAll"
+        https://bugs.webkit.org/show_bug.cgi?id=202471
+        https://trac.webkit.org/changeset/252683
+
+        "Unreviewed, address Darin's feedback on r252683."
+        https://trac.webkit.org/changeset/252721
+
 2019-11-20  Ross Kirsling  <[email protected]>
 
         Unreviewed, address Darin's feedback on r252683.

Deleted: trunk/JSTests/stress/string-replaceall.js (252752 => 252753)


--- trunk/JSTests/stress/string-replaceall.js	2019-11-21 22:42:39 UTC (rev 252752)
+++ trunk/JSTests/stress/string-replaceall.js	2019-11-21 23:18:48 UTC (rev 252753)
@@ -1,41 +0,0 @@
-function shouldBe(actual, expected) {
-    if (actual !== expected)
-        throw new Error(`expected ${expected} but got ${actual}`);
-}
-
-function shouldThrowTypeError(func) {
-    let error;
-    try {
-        func();
-    } catch (e) {
-        error = e;
-    }
-
-    if (!(error instanceof TypeError))
-        throw new Error('Expected TypeError!');
-}
-
-shouldThrowTypeError(() => { String.prototype.replaceAll.call(undefined, 'def', 'xyz'); });
-shouldThrowTypeError(() => { String.prototype.replaceAll.call(null, 'def', 'xyz'); });
-
-shouldThrowTypeError(() => { 'abcdefabcdefabc'.replaceAll(/def/, 'xyz'); });
-shouldThrowTypeError(() => { 'abcdefabcdefabc'.replaceAll(new RegExp('def'), 'xyz'); });
-shouldThrowTypeError(() => { 'abcdefabcdefabc'.replaceAll({ [Symbol.match]() {}, toString: () => 'def' }, 'xyz'); });
-
-shouldBe('abcdefabcdefabc'.replaceAll('def', 'xyz'), 'abcxyzabcxyzabc');
-shouldBe('abcdefabcdefabc'.replaceAll(/def/g, 'xyz'), 'abcxyzabcxyzabc');
-shouldBe('abcdefabcdefabc'.replaceAll(new RegExp('def', 'g'), 'xyz'), 'abcxyzabcxyzabc');
-shouldBe('abcdefabcdefabc'.replaceAll({ [Symbol.match]() {}, toString: () => 'def', flags: 'g' }, 'xyz'), 'abcxyzabcxyzabc');
-
-const search = /def/g;
-search[Symbol.replace] = undefined;
-shouldBe('abcdefabcdefabc'.replaceAll(search, 'xyz'), 'abcdefabcdefabc');
-search[Symbol.replace] = () => 'q';
-shouldBe('abcdefabcdefabc'.replaceAll(search, 'xyz'), 'q');
-search[Symbol.replace] = RegExp.prototype[Symbol.replace].bind(search);
-shouldBe('abcdefabcdefabc'.replaceAll(search, 'xyz'), 'abcxyzabcxyzabc');
-
-shouldBe('abc'.replaceAll('', 'z'), 'zazbzcz');
-shouldBe(''.replaceAll('', 'z'), 'z');
-shouldBe('abc'.replaceAll('', ''), 'abc');
-shouldBe(''.replaceAll('', ''), '');

Modified: trunk/LayoutTests/ChangeLog (252752 => 252753)


--- trunk/LayoutTests/ChangeLog	2019-11-21 22:42:39 UTC (rev 252752)
+++ trunk/LayoutTests/ChangeLog	2019-11-21 23:18:48 UTC (rev 252753)
@@ -1,3 +1,20 @@
+2019-11-21  Commit Queue  <[email protected]>
+
+        Unreviewed, rolling out r252683 and r252721.
+        https://bugs.webkit.org/show_bug.cgi?id=204475
+
+        13% regression in JetStream2/prepack-wtb (Requested by
+        yusukesuzuki on #webkit).
+
+        Reverted changesets:
+
+        "Implement String.prototype.replaceAll"
+        https://bugs.webkit.org/show_bug.cgi?id=202471
+        https://trac.webkit.org/changeset/252683
+
+        "Unreviewed, address Darin's feedback on r252683."
+        https://trac.webkit.org/changeset/252721
+
 2019-11-21  Simon Fraser  <[email protected]>
 
         Flaky Test: compositing/backing/backing-store-attachment-with-rotation.html

Modified: trunk/LayoutTests/js/Object-getOwnPropertyNames-expected.txt (252752 => 252753)


--- trunk/LayoutTests/js/Object-getOwnPropertyNames-expected.txt	2019-11-21 22:42:39 UTC (rev 252752)
+++ trunk/LayoutTests/js/Object-getOwnPropertyNames-expected.txt	2019-11-21 23:18:48 UTC (rev 252753)
@@ -49,7 +49,7 @@
 PASS getSortedOwnPropertyNames(Array) is ['from', 'isArray', 'length', 'name', 'of', 'prototype']
 PASS getSortedOwnPropertyNames(Array.prototype) is ['concat', 'constructor', 'copyWithin', 'entries', 'every', 'fill', 'filter', 'find', 'findIndex', 'flat', 'flatMap', 'forEach', 'includes', 'indexOf', 'join', 'keys', 'lastIndexOf', 'length', 'map', 'pop', 'push', 'reduce', 'reduceRight', 'reverse', 'shift', 'slice', 'some', 'sort', 'splice', 'toLocaleString', 'toString', 'unshift', 'values']
 PASS getSortedOwnPropertyNames(String) is ['fromCharCode', 'fromCodePoint', 'length', 'name', 'prototype', 'raw']
-PASS getSortedOwnPropertyNames(String.prototype) is ['anchor', 'big', 'blink', 'bold', 'charAt', 'charCodeAt', 'codePointAt', 'concat', 'constructor', 'endsWith', 'fixed', 'fontcolor', 'fontsize', 'includes', 'indexOf', 'italics', 'lastIndexOf', 'length', 'link', 'localeCompare', 'match', 'matchAll', 'normalize', 'padEnd', 'padStart', 'repeat', 'replace', 'replaceAll', 'search', 'slice', 'small', 'split', 'startsWith', 'strike', 'sub', 'substr', 'substring', 'sup', 'toLocaleLowerCase', 'toLocaleUpperCase', 'toLowerCase', 'toString', 'toUpperCase', 'trim', 'trimEnd', 'trimLeft', 'trimRight', 'trimStart', 'valueOf']
+PASS getSortedOwnPropertyNames(String.prototype) is ['anchor', 'big', 'blink', 'bold', 'charAt', 'charCodeAt', 'codePointAt', 'concat', 'constructor', 'endsWith', 'fixed', 'fontcolor', 'fontsize', 'includes', 'indexOf', 'italics', 'lastIndexOf', 'length', 'link', 'localeCompare', 'match', 'matchAll', 'normalize', 'padEnd', 'padStart', 'repeat', 'replace', 'search', 'slice', 'small', 'split', 'startsWith', 'strike', 'sub', 'substr', 'substring', 'sup', 'toLocaleLowerCase', 'toLocaleUpperCase', 'toLowerCase', 'toString', 'toUpperCase', 'trim', 'trimEnd', 'trimLeft', 'trimRight', 'trimStart', 'valueOf']
 PASS getSortedOwnPropertyNames(Boolean) is ['length', 'name', 'prototype']
 PASS getSortedOwnPropertyNames(Boolean.prototype) is ['constructor', 'toString', 'valueOf']
 PASS getSortedOwnPropertyNames(Number) is ['EPSILON', 'MAX_SAFE_INTEGER', 'MAX_VALUE', 'MIN_SAFE_INTEGER', 'MIN_VALUE', 'NEGATIVE_INFINITY', 'NaN', 'POSITIVE_INFINITY', 'isFinite', 'isInteger', 'isNaN', 'isSafeInteger', 'length', 'name', 'parseFloat', 'parseInt', 'prototype']

Modified: trunk/LayoutTests/js/script-tests/Object-getOwnPropertyNames.js (252752 => 252753)


--- trunk/LayoutTests/js/script-tests/Object-getOwnPropertyNames.js	2019-11-21 22:42:39 UTC (rev 252752)
+++ trunk/LayoutTests/js/script-tests/Object-getOwnPropertyNames.js	2019-11-21 23:18:48 UTC (rev 252753)
@@ -58,7 +58,7 @@
     "Array": "['from', 'isArray', 'length', 'name', 'of', 'prototype']",
     "Array.prototype": "['concat', 'constructor', 'copyWithin', 'entries', 'every', 'fill', 'filter', 'find', 'findIndex', 'flat', 'flatMap', 'forEach', 'includes', 'indexOf', 'join', 'keys', 'lastIndexOf', 'length', 'map', 'pop', 'push', 'reduce', 'reduceRight', 'reverse', 'shift', 'slice', 'some', 'sort', 'splice', 'toLocaleString', 'toString', 'unshift', 'values']",
     "String": "['fromCharCode', 'fromCodePoint', 'length', 'name', 'prototype', 'raw']",
-    "String.prototype": "['anchor', 'big', 'blink', 'bold', 'charAt', 'charCodeAt', 'codePointAt', 'concat', 'constructor', 'endsWith', 'fixed', 'fontcolor', 'fontsize', 'includes', 'indexOf', 'italics', 'lastIndexOf', 'length', 'link', 'localeCompare', 'match', 'matchAll', 'normalize', 'padEnd', 'padStart', 'repeat', 'replace', 'replaceAll', 'search', 'slice', 'small', 'split', 'startsWith', 'strike', 'sub', 'substr', 'substring', 'sup', 'toLocaleLowerCase', 'toLocaleUpperCase', 'toLowerCase', 'toString', 'toUpperCase', 'trim', 'trimEnd', 'trimLeft', 'trimRight', 'trimStart', 'valueOf']",
+    "String.prototype": "['anchor', 'big', 'blink', 'bold', 'charAt', 'charCodeAt', 'codePointAt', 'concat', 'constructor', 'endsWith', 'fixed', 'fontcolor', 'fontsize', 'includes', 'indexOf', 'italics', 'lastIndexOf', 'length', 'link', 'localeCompare', 'match', 'matchAll', 'normalize', 'padEnd', 'padStart', 'repeat', 'replace', 'search', 'slice', 'small', 'split', 'startsWith', 'strike', 'sub', 'substr', 'substring', 'sup', 'toLocaleLowerCase', 'toLocaleUpperCase', 'toLowerCase', 'toString', 'toUpperCase', 'trim', 'trimEnd', 'trimLeft', 'trimRight', 'trimStart', 'valueOf']",
     "Boolean": "['length', 'name', 'prototype']",
     "Boolean.prototype": "['constructor', 'toString', 'valueOf']",
     "Number": "['EPSILON', 'MAX_SAFE_INTEGER', 'MAX_VALUE', 'MIN_SAFE_INTEGER', 'MIN_VALUE', 'NEGATIVE_INFINITY', 'NaN', 'POSITIVE_INFINITY', 'isFinite', 'isInteger', 'isNaN', 'isSafeInteger', 'length', 'name', 'parseFloat', 'parseInt', 'prototype']",

Modified: trunk/Source/_javascript_Core/ChangeLog (252752 => 252753)


--- trunk/Source/_javascript_Core/ChangeLog	2019-11-21 22:42:39 UTC (rev 252752)
+++ trunk/Source/_javascript_Core/ChangeLog	2019-11-21 23:18:48 UTC (rev 252753)
@@ -1,3 +1,20 @@
+2019-11-21  Commit Queue  <[email protected]>
+
+        Unreviewed, rolling out r252683 and r252721.
+        https://bugs.webkit.org/show_bug.cgi?id=204475
+
+        13% regression in JetStream2/prepack-wtb (Requested by
+        yusukesuzuki on #webkit).
+
+        Reverted changesets:
+
+        "Implement String.prototype.replaceAll"
+        https://bugs.webkit.org/show_bug.cgi?id=202471
+        https://trac.webkit.org/changeset/252683
+
+        "Unreviewed, address Darin's feedback on r252683."
+        https://trac.webkit.org/changeset/252721
+
 2019-11-21  Devin Rousso  <[email protected]>
 
         Web Inspector: removing the blackbox for a specific script doesn't actually remove the blackbox

Modified: trunk/Source/_javascript_Core/builtins/BuiltinNames.h (252752 => 252753)


--- trunk/Source/_javascript_Core/builtins/BuiltinNames.h	2019-11-21 22:42:39 UTC (rev 252752)
+++ trunk/Source/_javascript_Core/builtins/BuiltinNames.h	2019-11-21 23:18:48 UTC (rev 252753)
@@ -132,7 +132,6 @@
     macro(isRegExp) \
     macro(replaceUsingRegExp) \
     macro(replaceUsingStringSearch) \
-    macro(replaceAllUsingStringSearch) \
     macro(makeTypeError) \
     macro(mapBucket) \
     macro(mapBucketHead) \

Modified: trunk/Source/_javascript_Core/builtins/StringPrototype.js (252752 => 252753)


--- trunk/Source/_javascript_Core/builtins/StringPrototype.js	2019-11-21 22:42:39 UTC (rev 252752)
+++ trunk/Source/_javascript_Core/builtins/StringPrototype.js	2019-11-21 23:18:48 UTC (rev 252753)
@@ -259,30 +259,6 @@
     return thisString.@replaceUsingStringSearch(searchString, replace);
 }
 
-function replaceAll(search, replace)
-{
-    "use strict";
-
-    if (@isUndefinedOrNull(this))
-        @throwTypeError("String.prototype.replaceAll requires |this| not to be null nor undefined");
-
-    if (search != null) {
-        if (@isRegExp(search) && !@stringIncludesInternal.@call(@toString(search.flags), "g"))
-            @throwTypeError("String.prototype.replaceAll argument must not be a non-global regular _expression_");
-
-        var replacer = search.@replaceSymbol;
-        if (replacer !== @undefined) {
-            if (!@hasObservableSideEffectsForStringReplace(search, replacer))
-                return @toString(this).@replaceUsingRegExp(search, replace);
-            return replacer.@call(search, this, replace);
-        }
-    }
-
-    var thisString = @toString(this);
-    var searchString = @toString(search);
-    return thisString.@replaceAllUsingStringSearch(searchString, replace);
-}
-
 function search(regexp)
 {
     "use strict";

Modified: trunk/Source/_javascript_Core/runtime/StringPrototype.cpp (252752 => 252753)


--- trunk/Source/_javascript_Core/runtime/StringPrototype.cpp	2019-11-21 22:42:39 UTC (rev 252752)
+++ trunk/Source/_javascript_Core/runtime/StringPrototype.cpp	2019-11-21 23:18:48 UTC (rev 252753)
@@ -70,7 +70,6 @@
 EncodedJSValue JSC_HOST_CALL stringProtoFuncLastIndexOf(JSGlobalObject*, CallFrame*);
 EncodedJSValue JSC_HOST_CALL stringProtoFuncReplaceUsingRegExp(JSGlobalObject*, CallFrame*);
 EncodedJSValue JSC_HOST_CALL stringProtoFuncReplaceUsingStringSearch(JSGlobalObject*, CallFrame*);
-EncodedJSValue JSC_HOST_CALL stringProtoFuncReplaceAllUsingStringSearch(JSGlobalObject*, CallFrame*);
 EncodedJSValue JSC_HOST_CALL stringProtoFuncSlice(JSGlobalObject*, CallFrame*);
 EncodedJSValue JSC_HOST_CALL stringProtoFuncSubstr(JSGlobalObject*, CallFrame*);
 EncodedJSValue JSC_HOST_CALL stringProtoFuncSubstring(JSGlobalObject*, CallFrame*);
@@ -98,29 +97,28 @@
 
 /* Source for StringConstructor.lut.h
 @begin stringPrototypeTable
-    concat        JSBuiltin    DontEnum|Function 1
-    match         JSBuiltin    DontEnum|Function 1
-    matchAll      JSBuiltin    DontEnum|Function 1
-    padStart      JSBuiltin    DontEnum|Function 1
-    padEnd        JSBuiltin    DontEnum|Function 1
-    repeat        JSBuiltin    DontEnum|Function 1
-    replace       JSBuiltin    DontEnum|Function 2
-    replaceAll    JSBuiltin    DontEnum|Function 2
-    search        JSBuiltin    DontEnum|Function 1
-    split         JSBuiltin    DontEnum|Function 1
-    anchor        JSBuiltin    DontEnum|Function 1
-    big           JSBuiltin    DontEnum|Function 0
-    bold          JSBuiltin    DontEnum|Function 0
-    blink         JSBuiltin    DontEnum|Function 0
-    fixed         JSBuiltin    DontEnum|Function 0
-    fontcolor     JSBuiltin    DontEnum|Function 1
-    fontsize      JSBuiltin    DontEnum|Function 1
-    italics       JSBuiltin    DontEnum|Function 0
-    link          JSBuiltin    DontEnum|Function 1
-    small         JSBuiltin    DontEnum|Function 0
-    strike        JSBuiltin    DontEnum|Function 0
-    sub           JSBuiltin    DontEnum|Function 0
-    sup           JSBuiltin    DontEnum|Function 0
+    concat    JSBuiltin    DontEnum|Function 1
+    match     JSBuiltin    DontEnum|Function 1
+    matchAll  JSBuiltin    DontEnum|Function 1
+    padStart  JSBuiltin    DontEnum|Function 1
+    padEnd    JSBuiltin    DontEnum|Function 1
+    repeat    JSBuiltin    DontEnum|Function 1
+    replace   JSBuiltin    DontEnum|Function 2
+    search    JSBuiltin    DontEnum|Function 1
+    split     JSBuiltin    DontEnum|Function 1
+    anchor    JSBuiltin    DontEnum|Function 1
+    big       JSBuiltin    DontEnum|Function 0
+    bold      JSBuiltin    DontEnum|Function 0
+    blink     JSBuiltin    DontEnum|Function 0
+    fixed     JSBuiltin    DontEnum|Function 0
+    fontcolor JSBuiltin    DontEnum|Function 1
+    fontsize  JSBuiltin    DontEnum|Function 1
+    italics   JSBuiltin    DontEnum|Function 0
+    link      JSBuiltin    DontEnum|Function 1
+    small     JSBuiltin    DontEnum|Function 0
+    strike    JSBuiltin    DontEnum|Function 0
+    sub       JSBuiltin    DontEnum|Function 0
+    sup       JSBuiltin    DontEnum|Function 0
 @end
 */
 
@@ -144,7 +142,6 @@
     JSC_NATIVE_FUNCTION_WITHOUT_TRANSITION("lastIndexOf", stringProtoFuncLastIndexOf, static_cast<unsigned>(PropertyAttribute::DontEnum), 1);
     JSC_NATIVE_INTRINSIC_FUNCTION_WITHOUT_TRANSITION(vm.propertyNames->builtinNames().replaceUsingRegExpPrivateName(), stringProtoFuncReplaceUsingRegExp, static_cast<unsigned>(PropertyAttribute::DontEnum), 2, StringPrototypeReplaceRegExpIntrinsic);
     JSC_NATIVE_FUNCTION_WITHOUT_TRANSITION(vm.propertyNames->builtinNames().replaceUsingStringSearchPrivateName(), stringProtoFuncReplaceUsingStringSearch, static_cast<unsigned>(PropertyAttribute::DontEnum), 2);
-    JSC_NATIVE_FUNCTION_WITHOUT_TRANSITION(vm.propertyNames->builtinNames().replaceAllUsingStringSearchPrivateName(), stringProtoFuncReplaceAllUsingStringSearch, static_cast<unsigned>(PropertyAttribute::DontEnum), 2);
     JSC_NATIVE_INTRINSIC_FUNCTION_WITHOUT_TRANSITION("slice", stringProtoFuncSlice, static_cast<unsigned>(PropertyAttribute::DontEnum), 2, StringPrototypeSliceIntrinsic);
     JSC_NATIVE_FUNCTION_WITHOUT_TRANSITION("substr", stringProtoFuncSubstr, static_cast<unsigned>(PropertyAttribute::DontEnum), 2);
     JSC_NATIVE_FUNCTION_WITHOUT_TRANSITION("substring", stringProtoFuncSubstring, static_cast<unsigned>(PropertyAttribute::DontEnum), 2);
@@ -397,12 +394,6 @@
         RELEASE_AND_RETURN(scope, jsString(vm, StringImpl::createSubstringSharingImpl(*source.impl(), std::max(0, position), std::min(sourceSize, length))));
     }
 
-    if (rangeCount == 2 && separatorCount == 1) {
-        String leftPart(StringImpl::createSubstringSharingImpl(*source.impl(), substringRanges[0].position, substringRanges[0].length));
-        String rightPart(StringImpl::createSubstringSharingImpl(*source.impl(), substringRanges[1].position, substringRanges[1].length));
-        RELEASE_AND_RETURN(scope, jsString(globalObject, leftPart, separators[0], rightPart));
-    }
-
     Checked<int, RecordOverflow> totalLength = 0;
     bool allSeparators8Bit = true;
     for (int i = 0; i < rangeCount; i++)
@@ -776,9 +767,7 @@
         vm, globalObject, callFrame, string, searchValue, callData, callType, replacementString, replaceValue));
 }
 
-enum class ReplaceMode : bool { Single, Global };
-
-static ALWAYS_INLINE JSString* replaceUsingStringSearch(VM& vm, JSGlobalObject* globalObject, CallFrame* callFrame, JSString* jsString, JSValue searchValue, JSValue replaceValue, ReplaceMode mode)
+static ALWAYS_INLINE JSString* replaceUsingStringSearch(VM& vm, JSGlobalObject* globalObject, JSString* jsString, JSValue searchValue, JSValue replaceValue)
 {
     auto scope = DECLARE_THROW_SCOPE(vm);
 
@@ -788,64 +777,46 @@
     RETURN_IF_EXCEPTION(scope, nullptr);
 
     size_t matchStart = string.find(searchString);
+
     if (matchStart == notFound)
         return jsString;
 
     CallData callData;
     CallType callType = getCallData(vm, replaceValue, callData);
-    Optional<CachedCall> cachedCall;
-    String replaceString;
-    if (callType == CallType::None) {
-        replaceString = replaceValue.toWTFString(globalObject);
+    if (callType != CallType::None) {
+        MarkedArgumentBuffer args;
+        auto* substring = jsSubstring(vm, string, matchStart, searchString.impl()->length());
         RETURN_IF_EXCEPTION(scope, nullptr);
-    } else {
-        cachedCall.emplace(globalObject, callFrame, jsCast<JSFunction*>(replaceValue), 3);
-        cachedCall->setThis(jsUndefined());
+        args.append(substring);
+        args.append(jsNumber(matchStart));
+        args.append(jsString);
+        ASSERT(!args.hasOverflowed());
+        replaceValue = call(globalObject, replaceValue, callType, callData, jsUndefined(), args);
+        RETURN_IF_EXCEPTION(scope, nullptr);
     }
 
-    size_t endOfLastMatch = 0;
-    size_t searchStringLength = searchString.length();
-    Vector<StringRange, 16> sourceRanges;
-    Vector<String, 16> replacements;
-    do {
-        if (cachedCall) {
-            auto* substring = jsSubstring(vm, string, matchStart, searchStringLength);
-            RETURN_IF_EXCEPTION(scope, nullptr);
-            cachedCall->clearArguments();
-            cachedCall->appendArgument(substring);
-            cachedCall->appendArgument(jsNumber(matchStart));
-            cachedCall->appendArgument(jsString);
-            ASSERT(!cachedCall->hasOverflowedArguments());
-            JSValue replacement = cachedCall->call();
-            RETURN_IF_EXCEPTION(scope, nullptr);
-            replaceString = replacement.toWTFString(globalObject);
-            RETURN_IF_EXCEPTION(scope, nullptr);
-        }
+    String replaceString = replaceValue.toWTFString(globalObject);
+    RETURN_IF_EXCEPTION(scope, nullptr);
 
-        if (UNLIKELY(!sourceRanges.tryConstructAndAppend(endOfLastMatch, matchStart - endOfLastMatch)))
+    StringImpl* stringImpl = string.impl();
+    String leftPart(StringImpl::createSubstringSharingImpl(*stringImpl, 0, matchStart));
+
+    size_t matchEnd = matchStart + searchString.impl()->length();
+    int ovector[2] = { static_cast<int>(matchStart),  static_cast<int>(matchEnd)};
+    String middlePart;
+    if (callType != CallType::None)
+        middlePart = replaceString;
+    else {
+        StringBuilder replacement(StringBuilder::OverflowHandler::RecordOverflow);
+        substituteBackreferences(replacement, replaceString, string, ovector, 0);
+        if (UNLIKELY(replacement.hasOverflowed()))
             OUT_OF_MEMORY(globalObject, scope);
+        middlePart = replacement.toString();
+    }
 
-        size_t matchEnd = matchStart + searchStringLength;
-        if (cachedCall)
-            replacements.append(replaceString);
-        else {
-            StringBuilder replacement(StringBuilder::OverflowHandler::RecordOverflow);
-            int ovector[2] = { static_cast<int>(matchStart),  static_cast<int>(matchEnd) };
-            substituteBackreferences(replacement, replaceString, string, ovector, nullptr);
-            if (UNLIKELY(replacement.hasOverflowed()))
-                OUT_OF_MEMORY(globalObject, scope);
-            replacements.append(replacement.toString());
-        }
-
-        endOfLastMatch = matchEnd;
-        if (mode == ReplaceMode::Single)
-            break;
-        matchStart = string.find(searchString, !searchStringLength ? endOfLastMatch + 1 : endOfLastMatch);
-    } while (matchStart != notFound);
-
-    if (UNLIKELY(!sourceRanges.tryConstructAndAppend(endOfLastMatch, string.length() - endOfLastMatch)))
-        OUT_OF_MEMORY(globalObject, scope);
-    RELEASE_AND_RETURN(scope, jsSpliceSubstringsWithSeparators(globalObject, jsString, string, sourceRanges.data(), sourceRanges.size(), replacements.data(), replacements.size()));
+    size_t leftLength = stringImpl->length() - matchEnd;
+    String rightPart(StringImpl::createSubstringSharingImpl(*stringImpl, matchEnd, leftLength));
+    RELEASE_AND_RETURN(scope, JSC::jsString(globalObject, leftPart, middlePart, rightPart));
 }
 
 static inline bool checkObjectCoercible(JSValue thisValue)
@@ -901,7 +872,7 @@
 {
     if (searchValue.inherits<RegExpObject>(vm))
         return replaceUsingRegExpSearch(vm, globalObject, callFrame, string, searchValue, replaceValue);
-    return replaceUsingStringSearch(vm, globalObject, callFrame, string, searchValue, replaceValue, ReplaceMode::Single);
+    return replaceUsingStringSearch(vm, globalObject, string, searchValue, replaceValue);
 }
 
 ALWAYS_INLINE JSString* replace(
@@ -941,20 +912,9 @@
     JSString* string = callFrame->thisValue().toString(globalObject);
     RETURN_IF_EXCEPTION(scope, encodedJSValue());
 
-    RELEASE_AND_RETURN(scope, JSValue::encode(replaceUsingStringSearch(vm, globalObject, callFrame, string, callFrame->argument(0), callFrame->argument(1), ReplaceMode::Single)));
+    RELEASE_AND_RETURN(scope, JSValue::encode(replaceUsingStringSearch(vm, globalObject, string, callFrame->argument(0), callFrame->argument(1))));
 }
 
-EncodedJSValue JSC_HOST_CALL stringProtoFuncReplaceAllUsingStringSearch(JSGlobalObject* globalObject, CallFrame* callFrame)
-{
-    VM& vm = globalObject->vm();
-    auto scope = DECLARE_THROW_SCOPE(vm);
-
-    JSString* string = callFrame->thisValue().toString(globalObject);
-    RETURN_IF_EXCEPTION(scope, encodedJSValue());
-
-    RELEASE_AND_RETURN(scope, JSValue::encode(replaceUsingStringSearch(vm, globalObject, callFrame, string, callFrame->argument(0), callFrame->argument(1), ReplaceMode::Global)));
-}
-
 JSCell* JIT_OPERATION operationStringProtoFuncReplaceGeneric(JSGlobalObject* globalObject, EncodedJSValue thisValue, EncodedJSValue searchValue, EncodedJSValue replaceValue)
 {
     VM& vm = globalObject->vm();

Modified: trunk/Source/WTF/ChangeLog (252752 => 252753)


--- trunk/Source/WTF/ChangeLog	2019-11-21 22:42:39 UTC (rev 252752)
+++ trunk/Source/WTF/ChangeLog	2019-11-21 23:18:48 UTC (rev 252753)
@@ -1,3 +1,20 @@
+2019-11-21  Commit Queue  <[email protected]>
+
+        Unreviewed, rolling out r252683 and r252721.
+        https://bugs.webkit.org/show_bug.cgi?id=204475
+
+        13% regression in JetStream2/prepack-wtb (Requested by
+        yusukesuzuki on #webkit).
+
+        Reverted changesets:
+
+        "Implement String.prototype.replaceAll"
+        https://bugs.webkit.org/show_bug.cgi?id=202471
+        https://trac.webkit.org/changeset/252683
+
+        "Unreviewed, address Darin's feedback on r252683."
+        https://trac.webkit.org/changeset/252721
+
 2019-11-21  Tuomas Karkkainen  <[email protected]>
 
         add ASSERT_NOT_REACHED_WITH_MESSAGE and RELEASE_ASSERT_NOT_REACHED_WITH_MESSAGE

Modified: trunk/Source/WTF/wtf/text/StringCommon.h (252752 => 252753)


--- trunk/Source/WTF/wtf/text/StringCommon.h	2019-11-21 22:42:39 UTC (rev 252752)
+++ trunk/Source/WTF/wtf/text/StringCommon.h	2019-11-21 23:18:48 UTC (rev 252753)
@@ -570,12 +570,11 @@
         return WTF::find(haystack.characters16(), haystack.length(), needle[0], start);
     }
 
+    if (!needleLength)
+        return std::min(start, haystack.length());
+
     if (start > haystack.length())
         return notFound;
-
-    if (!needleLength)
-        return start;
-
     unsigned searchLength = haystack.length() - start;
     if (needleLength > searchLength)
         return notFound;
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to