Diff
Modified: trunk/Source/_javascript_Core/ChangeLog (273616 => 273617)
--- trunk/Source/_javascript_Core/ChangeLog 2021-02-27 05:27:48 UTC (rev 273616)
+++ trunk/Source/_javascript_Core/ChangeLog 2021-02-27 06:52:05 UTC (rev 273617)
@@ -1,3 +1,33 @@
+2021-02-26 Yusuke Suzuki <[email protected]>
+
+ [JSC] Avoid creating functions unnecessarily in builtins
+ https://bugs.webkit.org/show_bug.cgi?id=222509
+
+ Reviewed by Ross Kirsling.
+
+ Avoid unnecessary function creation and make them @globalPrivate.
+
+ * builtins/ArrayPrototype.js:
+ (globalPrivate.maxWithPositives):
+ (globalPrivate.minWithMaybeNegativeZeroAndPositive):
+ (copyWithin):
+ (maxWithPositives): Deleted.
+ (minWithMaybeNegativeZeroAndPositive): Deleted.
+ * builtins/DatePrototype.js:
+ (globalPrivate.toDateTimeOptionsAnyAll):
+ (toLocaleString):
+ (globalPrivate.toDateTimeOptionsDateDate):
+ (toLocaleDateString):
+ (globalPrivate.toDateTimeOptionsTimeTime):
+ (toLocaleTimeString):
+ (toLocaleString.toDateTimeOptionsAnyAll): Deleted.
+ (toLocaleDateString.toDateTimeOptionsDateDate): Deleted.
+ (toLocaleTimeString.toDateTimeOptionsTimeTime): Deleted.
+ * builtins/RegExpPrototype.js:
+ (globalPrivate.getSubstitution):
+ (overriddenName.string_appeared_here.replace):
+ (getSubstitution): Deleted.
+
2021-02-26 Saam Barati <[email protected]>
Remove bad assertion of AI ArrayMode state in various "by val" opcodes
Modified: trunk/Source/_javascript_Core/builtins/ArrayPrototype.js (273616 => 273617)
--- trunk/Source/_javascript_Core/builtins/ArrayPrototype.js 2021-02-27 05:27:48 UTC (rev 273616)
+++ trunk/Source/_javascript_Core/builtins/ArrayPrototype.js 2021-02-27 06:52:05 UTC (rev 273617)
@@ -559,28 +559,34 @@
return @tailCallForwardArguments(@concatSlowPath, this);
}
-function copyWithin(target, start /*, end */)
+@globalPrivate
+function maxWithPositives(a, b)
{
"use strict";
- function maxWithPositives(a, b)
- {
- return (a < b) ? b : a;
- }
+ return (a < b) ? b : a;
+}
- function minWithMaybeNegativeZeroAndPositive(maybeNegativeZero, positive)
- {
- return (maybeNegativeZero < positive) ? maybeNegativeZero : positive;
- }
+@globalPrivate
+function minWithMaybeNegativeZeroAndPositive(maybeNegativeZero, positive)
+{
+ "use strict";
+ return (maybeNegativeZero < positive) ? maybeNegativeZero : positive;
+}
+
+function copyWithin(target, start /*, end */)
+{
+ "use strict";
+
var array = @toObject(this, "Array.prototype.copyWithin requires that |this| not be null or undefined");
var length = @toLength(array.length);
var relativeTarget = @toIntegerOrInfinity(target);
- var to = (relativeTarget < 0) ? maxWithPositives(length + relativeTarget, 0) : minWithMaybeNegativeZeroAndPositive(relativeTarget, length);
+ var to = (relativeTarget < 0) ? @maxWithPositives(length + relativeTarget, 0) : @minWithMaybeNegativeZeroAndPositive(relativeTarget, length);
var relativeStart = @toIntegerOrInfinity(start);
- var from = (relativeStart < 0) ? maxWithPositives(length + relativeStart, 0) : minWithMaybeNegativeZeroAndPositive(relativeStart, length);
+ var from = (relativeStart < 0) ? @maxWithPositives(length + relativeStart, 0) : @minWithMaybeNegativeZeroAndPositive(relativeStart, length);
var relativeEnd;
var end = @argument(2);
@@ -589,9 +595,9 @@
else
relativeEnd = @toIntegerOrInfinity(end);
- var finalValue = (relativeEnd < 0) ? maxWithPositives(length + relativeEnd, 0) : minWithMaybeNegativeZeroAndPositive(relativeEnd, length);
+ var finalValue = (relativeEnd < 0) ? @maxWithPositives(length + relativeEnd, 0) : @minWithMaybeNegativeZeroAndPositive(relativeEnd, length);
- var count = minWithMaybeNegativeZeroAndPositive(finalValue - from, length - to);
+ var count = @minWithMaybeNegativeZeroAndPositive(finalValue - from, length - to);
var direction = 1;
if (from < to && to < from + count) {
Modified: trunk/Source/_javascript_Core/builtins/DatePrototype.js (273616 => 273617)
--- trunk/Source/_javascript_Core/builtins/DatePrototype.js 2021-02-27 05:27:48 UTC (rev 273616)
+++ trunk/Source/_javascript_Core/builtins/DatePrototype.js 2021-02-27 06:52:05 UTC (rev 273617)
@@ -23,58 +23,61 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-function toLocaleString(/* locales, options */)
+@globalPrivate
+function toDateTimeOptionsAnyAll(opts)
{
"use strict";
- function toDateTimeOptionsAnyAll(opts)
- {
- // ToDateTimeOptions(options, "any", "all")
- // http://www.ecma-international.org/ecma-402/2.0/#sec-InitializeDateTimeFormat
+ // ToDateTimeOptions(options, "any", "all")
+ // http://www.ecma-international.org/ecma-402/2.0/#sec-InitializeDateTimeFormat
- var options;
- if (opts === @undefined)
- options = null;
- else if (opts === null)
- @throwTypeError("null is not an object");
- else
- options = @toObject(opts);
+ var options;
+ if (opts === @undefined)
+ options = null;
+ else if (opts === null)
+ @throwTypeError("null is not an object");
+ else
+ options = @toObject(opts);
- // Check original instead of descendant to reduce lookups up the prototype chain.
- var needsDefaults = !options || (
- options.weekday === @undefined &&
- options.year === @undefined &&
- options.month === @undefined &&
- options.day === @undefined &&
- (!@useIntlDateTimeFormatDayPeriod || options.dayPeriod === @undefined) &&
- options.hour === @undefined &&
- options.minute === @undefined &&
- options.second === @undefined &&
- options.fractionalSecondDigits === @undefined
- );
+ // Check original instead of descendant to reduce lookups up the prototype chain.
+ var needsDefaults = !options || (
+ options.weekday === @undefined &&
+ options.year === @undefined &&
+ options.month === @undefined &&
+ options.day === @undefined &&
+ (!@useIntlDateTimeFormatDayPeriod || options.dayPeriod === @undefined) &&
+ options.hour === @undefined &&
+ options.minute === @undefined &&
+ options.second === @undefined &&
+ options.fractionalSecondDigits === @undefined
+ );
- if (options) {
- var dateStyle = options.dateStyle;
- var timeStyle = options.timeStyle;
- if (dateStyle !== @undefined || timeStyle !== @undefined)
- needsDefaults = false;
- }
+ if (options) {
+ var dateStyle = options.dateStyle;
+ var timeStyle = options.timeStyle;
+ if (dateStyle !== @undefined || timeStyle !== @undefined)
+ needsDefaults = false;
+ }
- // Only create descendant if it will have own properties.
- if (needsDefaults) {
- options = @Object.@create(options);
- options.year = "numeric";
- options.month = "numeric";
- options.day = "numeric";
- options.hour = "numeric";
- options.minute = "numeric";
- options.second = "numeric";
- }
-
- // 9. Return options.
- return options;
+ // Only create descendant if it will have own properties.
+ if (needsDefaults) {
+ options = @Object.@create(options);
+ options.year = "numeric";
+ options.month = "numeric";
+ options.day = "numeric";
+ options.hour = "numeric";
+ options.minute = "numeric";
+ options.second = "numeric";
}
+ // 9. Return options.
+ return options;
+}
+
+function toLocaleString(/* locales, options */)
+{
+ "use strict";
+
// 13.3.1 Date.prototype.toLocaleString ([locales [, options ]]) (ECMA-402 2.0)
// http://www.ecma-international.org/ecma-402/2.0/#sec-Date.prototype.toLocaleString
@@ -82,56 +85,59 @@
if (@isNaN(value))
return "Invalid Date";
- var options = toDateTimeOptionsAnyAll(@argument(1));
+ var options = @toDateTimeOptionsAnyAll(@argument(1));
var locales = @argument(0);
return @dateTimeFormat(locales, options, value);
}
-function toLocaleDateString(/* locales, options */)
+@globalPrivate
+function toDateTimeOptionsDateDate(opts)
{
"use strict";
- function toDateTimeOptionsDateDate(opts)
- {
- // ToDateTimeOptions(options, "date", "date")
- // http://www.ecma-international.org/ecma-402/2.0/#sec-InitializeDateTimeFormat
+ // ToDateTimeOptions(options, "date", "date")
+ // http://www.ecma-international.org/ecma-402/2.0/#sec-InitializeDateTimeFormat
- var options;
- if (opts === @undefined)
- options = null;
- else if (opts === null)
- @throwTypeError("null is not an object");
- else
- options = @toObject(opts);
+ var options;
+ if (opts === @undefined)
+ options = null;
+ else if (opts === null)
+ @throwTypeError("null is not an object");
+ else
+ options = @toObject(opts);
- // Check original instead of descendant to reduce lookups up the prototype chain.
- var needsDefaults = !options || (
- options.weekday === @undefined &&
- options.year === @undefined &&
- options.month === @undefined &&
- options.day === @undefined
- );
+ // Check original instead of descendant to reduce lookups up the prototype chain.
+ var needsDefaults = !options || (
+ options.weekday === @undefined &&
+ options.year === @undefined &&
+ options.month === @undefined &&
+ options.day === @undefined
+ );
- if (options) {
- var dateStyle = options.dateStyle;
- var timeStyle = options.timeStyle;
- if (timeStyle !== @undefined)
- @throwTypeError("timeStyle cannot be specified");
- if (dateStyle !== @undefined)
- needsDefaults = false;
- }
+ if (options) {
+ var dateStyle = options.dateStyle;
+ var timeStyle = options.timeStyle;
+ if (timeStyle !== @undefined)
+ @throwTypeError("timeStyle cannot be specified");
+ if (dateStyle !== @undefined)
+ needsDefaults = false;
+ }
- // Only create descendant if it will have own properties.
- if (needsDefaults) {
- options = @Object.@create(options);
- options.year = "numeric";
- options.month = "numeric";
- options.day = "numeric";
- }
-
- return options;
+ // Only create descendant if it will have own properties.
+ if (needsDefaults) {
+ options = @Object.@create(options);
+ options.year = "numeric";
+ options.month = "numeric";
+ options.day = "numeric";
}
+ return options;
+}
+
+function toLocaleDateString(/* locales, options */)
+{
+ "use strict";
+
// 13.3.2 Date.prototype.toLocaleDateString ([locales [, options ]]) (ECMA-402 2.0)
// http://www.ecma-international.org/ecma-402/2.0/#sec-Date.prototype.toLocaleDateString
@@ -139,57 +145,60 @@
if (@isNaN(value))
return "Invalid Date";
- var options = toDateTimeOptionsDateDate(@argument(1));
+ var options = @toDateTimeOptionsDateDate(@argument(1));
var locales = @argument(0);
return @dateTimeFormat(locales, options, value);
}
-function toLocaleTimeString(/* locales, options */)
+@globalPrivate
+function toDateTimeOptionsTimeTime(opts)
{
"use strict";
- function toDateTimeOptionsTimeTime(opts)
- {
- // ToDateTimeOptions(options, "time", "time")
- // http://www.ecma-international.org/ecma-402/2.0/#sec-InitializeDateTimeFormat
+ // ToDateTimeOptions(options, "time", "time")
+ // http://www.ecma-international.org/ecma-402/2.0/#sec-InitializeDateTimeFormat
- var options;
- if (opts === @undefined)
- options = null;
- else if (opts === null)
- @throwTypeError("null is not an object");
- else
- options = @toObject(opts);
+ var options;
+ if (opts === @undefined)
+ options = null;
+ else if (opts === null)
+ @throwTypeError("null is not an object");
+ else
+ options = @toObject(opts);
- // Check original instead of descendant to reduce lookups up the prototype chain.
- var needsDefaults = !options || (
- (!@useIntlDateTimeFormatDayPeriod || options.dayPeriod === @undefined) &&
- options.hour === @undefined &&
- options.minute === @undefined &&
- options.second === @undefined &&
- options.fractionalSecondDigits === @undefined
- );
+ // Check original instead of descendant to reduce lookups up the prototype chain.
+ var needsDefaults = !options || (
+ (!@useIntlDateTimeFormatDayPeriod || options.dayPeriod === @undefined) &&
+ options.hour === @undefined &&
+ options.minute === @undefined &&
+ options.second === @undefined &&
+ options.fractionalSecondDigits === @undefined
+ );
- if (options) {
- var dateStyle = options.dateStyle;
- var timeStyle = options.timeStyle;
- if (dateStyle !== @undefined)
- @throwTypeError("dateStyle cannot be specified");
- if (timeStyle !== @undefined)
- needsDefaults = false;
- }
+ if (options) {
+ var dateStyle = options.dateStyle;
+ var timeStyle = options.timeStyle;
+ if (dateStyle !== @undefined)
+ @throwTypeError("dateStyle cannot be specified");
+ if (timeStyle !== @undefined)
+ needsDefaults = false;
+ }
- // Only create descendant if it will have own properties.
- if (needsDefaults) {
- options = @Object.@create(options);
- options.hour = "numeric";
- options.minute = "numeric";
- options.second = "numeric";
- }
-
- return options;
+ // Only create descendant if it will have own properties.
+ if (needsDefaults) {
+ options = @Object.@create(options);
+ options.hour = "numeric";
+ options.minute = "numeric";
+ options.second = "numeric";
}
+ return options;
+}
+
+function toLocaleTimeString(/* locales, options */)
+{
+ "use strict";
+
// 13.3.3 Date.prototype.toLocaleTimeString ([locales [, options ]]) (ECMA-402 2.0)
// http://www.ecma-international.org/ecma-402/2.0/#sec-Date.prototype.toLocaleTimeString
@@ -197,7 +206,7 @@
if (@isNaN(value))
return "Invalid Date";
- var options = toDateTimeOptionsTimeTime(@argument(1));
+ var options = @toDateTimeOptionsTimeTime(@argument(1));
var locales = @argument(0);
return @dateTimeFormat(locales, options, value);
}
Modified: trunk/Source/_javascript_Core/builtins/RegExpPrototype.js (273616 => 273617)
--- trunk/Source/_javascript_Core/builtins/RegExpPrototype.js 2021-02-27 05:27:48 UTC (rev 273616)
+++ trunk/Source/_javascript_Core/builtins/RegExpPrototype.js 2021-02-27 06:52:05 UTC (rev 273617)
@@ -174,110 +174,111 @@
return new @RegExpStringIterator(matcher, string, global, fullUnicode);
}
-@overriddenName="[Symbol.replace]"
-function replace(strArg, replace)
+@globalPrivate
+function getSubstitution(matched, str, position, captures, namedCaptures, replacement)
{
"use strict";
- function getSubstitution(matched, str, position, captures, namedCaptures, replacement)
- {
- "use strict";
+ var matchLength = matched.length;
+ var stringLength = str.length;
+ var tailPos = position + matchLength;
+ var m = captures.length;
+ var replacementLength = replacement.length;
+ var result = "";
+ var lastStart = 0;
- var matchLength = matched.length;
- var stringLength = str.length;
- var tailPos = position + matchLength;
- var m = captures.length;
- var replacementLength = replacement.length;
- var result = "";
- var lastStart = 0;
-
- for (var start = 0; start = @stringIndexOfInternal.@call(replacement, "$", lastStart), start !== -1; lastStart = start) {
- if (start - lastStart > 0)
- result = result + @stringSubstringInternal.@call(replacement, lastStart, start);
- start++;
- if (start >= replacementLength)
+ for (var start = 0; start = @stringIndexOfInternal.@call(replacement, "$", lastStart), start !== -1; lastStart = start) {
+ if (start - lastStart > 0)
+ result = result + @stringSubstringInternal.@call(replacement, lastStart, start);
+ start++;
+ if (start >= replacementLength)
+ result = result + "$";
+ else {
+ var ch = replacement[start];
+ switch (ch)
+ {
+ case "$":
result = result + "$";
- else {
- var ch = replacement[start];
- switch (ch)
- {
- case "$":
- result = result + "$";
- start++;
- break;
- case "&":
- result = result + matched;
- start++;
- break;
- case "`":
- if (position > 0)
- result = result + @stringSubstringInternal.@call(str, 0, position);
- start++;
- break;
- case "'":
- if (tailPos < stringLength)
- result = result + @stringSubstringInternal.@call(str, tailPos);
- start++;
- break;
- case "<":
- if (namedCaptures !== @undefined) {
- var groupNameStartIndex = start + 1;
- var groupNameEndIndex = @stringIndexOfInternal.@call(replacement, ">", groupNameStartIndex);
- if (groupNameEndIndex !== -1) {
- var groupName = @stringSubstringInternal.@call(replacement, groupNameStartIndex, groupNameEndIndex);
- var capture = namedCaptures[groupName];
- if (capture !== @undefined)
- result = result + @toString(capture);
+ start++;
+ break;
+ case "&":
+ result = result + matched;
+ start++;
+ break;
+ case "`":
+ if (position > 0)
+ result = result + @stringSubstringInternal.@call(str, 0, position);
+ start++;
+ break;
+ case "'":
+ if (tailPos < stringLength)
+ result = result + @stringSubstringInternal.@call(str, tailPos);
+ start++;
+ break;
+ case "<":
+ if (namedCaptures !== @undefined) {
+ var groupNameStartIndex = start + 1;
+ var groupNameEndIndex = @stringIndexOfInternal.@call(replacement, ">", groupNameStartIndex);
+ if (groupNameEndIndex !== -1) {
+ var groupName = @stringSubstringInternal.@call(replacement, groupNameStartIndex, groupNameEndIndex);
+ var capture = namedCaptures[groupName];
+ if (capture !== @undefined)
+ result = result + @toString(capture);
- start = groupNameEndIndex + 1;
- break;
- }
+ start = groupNameEndIndex + 1;
+ break;
}
+ }
- result = result + "$<";
+ result = result + "$<";
+ start++;
+ break;
+ default:
+ var chCode = ch.@charCodeAt(0);
+ if (chCode >= 0x30 && chCode <= 0x39) {
+ var originalStart = start - 1;
start++;
- break;
- default:
- var chCode = ch.@charCodeAt(0);
- if (chCode >= 0x30 && chCode <= 0x39) {
- var originalStart = start - 1;
- start++;
- var n = chCode - 0x30;
- if (n > m) {
- result = result + @stringSubstringInternal.@call(replacement, originalStart, start);
- break;
- }
+ var n = chCode - 0x30;
+ if (n > m) {
+ result = result + @stringSubstringInternal.@call(replacement, originalStart, start);
+ break;
+ }
- if (start < replacementLength) {
- var nextChCode = replacement.@charCodeAt(start);
- if (nextChCode >= 0x30 && nextChCode <= 0x39) {
- var nn = 10 * n + nextChCode - 0x30;
- if (nn <= m) {
- n = nn;
- start++;
- }
+ if (start < replacementLength) {
+ var nextChCode = replacement.@charCodeAt(start);
+ if (nextChCode >= 0x30 && nextChCode <= 0x39) {
+ var nn = 10 * n + nextChCode - 0x30;
+ if (nn <= m) {
+ n = nn;
+ start++;
}
}
+ }
- if (n == 0) {
- result = result + @stringSubstringInternal.@call(replacement, originalStart, start);
- break;
- }
+ if (n == 0) {
+ result = result + @stringSubstringInternal.@call(replacement, originalStart, start);
+ break;
+ }
- var capture = captures[n - 1];
- if (capture !== @undefined)
- result = result + capture;
- } else
- result = result + "$";
- break;
- }
+ var capture = captures[n - 1];
+ if (capture !== @undefined)
+ result = result + capture;
+ } else
+ result = result + "$";
+ break;
}
}
-
- return result + @stringSubstringInternal.@call(replacement, lastStart);
}
+ return result + @stringSubstringInternal.@call(replacement, lastStart);
+}
+
+@overriddenName="[Symbol.replace]"
+function replace(strArg, replace)
+{
+ "use strict";
+
if (!@isObject(this))
@throwTypeError("RegExp.prototype.@@replace requires that |this| be an Object");
@@ -363,7 +364,7 @@
if (namedCaptures !== @undefined)
namedCaptures = @toObject(namedCaptures, "RegExp.prototype[Symbol.replace] requires 'groups' property of a match not be null");
- replacement = getSubstitution(matched, str, position, captures, namedCaptures, replace);
+ replacement = @getSubstitution(matched, str, position, captures, namedCaptures, replace);
}
if (position >= nextSourcePosition) {