- Revision
- 261601
- Author
- [email protected]
- Date
- 2020-05-13 00:08:13 -0700 (Wed, 13 May 2020)
Log Message
Move @isConstructor checks from fast paths of Array.from and Array.of
https://bugs.webkit.org/show_bug.cgi?id=211805
Reviewed by Keith Miller.
JSTests:
* microbenchmarks/array-from-arraylike.js: Added.
* microbenchmarks/array-of.js: Added.
* stress/new-promise-capabilities-requires-constructor.js:
Source/_javascript_Core:
This semantically equivalent change advances provided Array.{from,of} microbenchmarks by ~60%.
Also, this patch removes @isConstructor check from @newPromiseCapabilitySlow (that is heavily
used by Promise subclasses) since it comes right before [[Construct]], its message doesn't add
more clarity, and constructability of its argument was likely checked by @speciesConstructor.
* builtins/ArrayConstructor.js:
(of):
(from):
* builtins/PromiseOperations.js:
(globalPrivate.newPromiseCapabilitySlow):
Modified Paths
Added Paths
Diff
Modified: trunk/JSTests/ChangeLog (261600 => 261601)
--- trunk/JSTests/ChangeLog 2020-05-13 06:41:34 UTC (rev 261600)
+++ trunk/JSTests/ChangeLog 2020-05-13 07:08:13 UTC (rev 261601)
@@ -1,3 +1,14 @@
+2020-05-13 Alexey Shvayka <[email protected]>
+
+ Move @isConstructor checks from fast paths of Array.from and Array.of
+ https://bugs.webkit.org/show_bug.cgi?id=211805
+
+ Reviewed by Keith Miller.
+
+ * microbenchmarks/array-from-arraylike.js: Added.
+ * microbenchmarks/array-of.js: Added.
+ * stress/new-promise-capabilities-requires-constructor.js:
+
2020-05-12 Alexey Shvayka <[email protected]>
Implement @isConstructor bytecode intrinsic and bytecode for that
Added: trunk/JSTests/microbenchmarks/array-from-arraylike.js (0 => 261601)
--- trunk/JSTests/microbenchmarks/array-from-arraylike.js (rev 0)
+++ trunk/JSTests/microbenchmarks/array-from-arraylike.js 2020-05-13 07:08:13 UTC (rev 261601)
@@ -0,0 +1,3 @@
+const items = {0:0, 1:1, 2:2, 3:3, 4:4, length: 5};
+for (let i = 0; i < 1e6; ++i)
+ Array.from(items);
Added: trunk/JSTests/microbenchmarks/array-of.js (0 => 261601)
--- trunk/JSTests/microbenchmarks/array-of.js (rev 0)
+++ trunk/JSTests/microbenchmarks/array-of.js 2020-05-13 07:08:13 UTC (rev 261601)
@@ -0,0 +1,2 @@
+for (let i = 0; i < 1e6; ++i)
+ Array.of(0, 1, 2, 3, 4);
Modified: trunk/JSTests/stress/new-promise-capabilities-requires-constructor.js (261600 => 261601)
--- trunk/JSTests/stress/new-promise-capabilities-requires-constructor.js 2020-05-13 06:41:34 UTC (rev 261600)
+++ trunk/JSTests/stress/new-promise-capabilities-requires-constructor.js 2020-05-13 07:08:13 UTC (rev 261601)
@@ -15,4 +15,4 @@
shouldThrow(() => {
Promise.race.call(() => { }, []);
-}, `TypeError: promise capability requires a constructor function`);
+}, `TypeError: function is not a constructor`);
Modified: trunk/Source/_javascript_Core/ChangeLog (261600 => 261601)
--- trunk/Source/_javascript_Core/ChangeLog 2020-05-13 06:41:34 UTC (rev 261600)
+++ trunk/Source/_javascript_Core/ChangeLog 2020-05-13 07:08:13 UTC (rev 261601)
@@ -1,3 +1,22 @@
+2020-05-13 Alexey Shvayka <[email protected]>
+
+ Move @isConstructor checks from fast paths of Array.from and Array.of
+ https://bugs.webkit.org/show_bug.cgi?id=211805
+
+ Reviewed by Keith Miller.
+
+ This semantically equivalent change advances provided Array.{from,of} microbenchmarks by ~60%.
+
+ Also, this patch removes @isConstructor check from @newPromiseCapabilitySlow (that is heavily
+ used by Promise subclasses) since it comes right before [[Construct]], its message doesn't add
+ more clarity, and constructability of its argument was likely checked by @speciesConstructor.
+
+ * builtins/ArrayConstructor.js:
+ (of):
+ (from):
+ * builtins/PromiseOperations.js:
+ (globalPrivate.newPromiseCapabilitySlow):
+
2020-05-12 Alexey Shvayka <[email protected]>
Implement @isConstructor bytecode intrinsic and bytecode for that
Modified: trunk/Source/_javascript_Core/builtins/ArrayConstructor.js (261600 => 261601)
--- trunk/Source/_javascript_Core/builtins/ArrayConstructor.js 2020-05-13 06:41:34 UTC (rev 261600)
+++ trunk/Source/_javascript_Core/builtins/ArrayConstructor.js 2020-05-13 07:08:13 UTC (rev 261601)
@@ -28,7 +28,7 @@
"use strict";
var length = arguments.length;
- var array = @isConstructor(this) ? new this(length) : @newArrayWithSize(length);
+ var array = this !== @Array && @isConstructor(this) ? new this(length) : @newArrayWithSize(length);
for (var k = 0; k < length; ++k)
@putByValDirect(array, k, arguments[k]);
array.length = length;
@@ -39,8 +39,6 @@
{
"use strict";
- var thisObj = this;
-
var mapFn = @argument(1);
var thisArg;
@@ -59,7 +57,7 @@
if (typeof iteratorMethod !== "function")
@throwTypeError("Array.from requires that the property of the first argument, items[Symbol.iterator], when exists, be a function");
- var result = @isConstructor(thisObj) ? new thisObj() : [];
+ var result = this !== @Array && @isConstructor(this) ? new this() : [];
var k = 0;
var iterator = iteratorMethod.@call(items);
@@ -84,7 +82,7 @@
var arrayLikeLength = @toLength(arrayLike.length);
- var result = @isConstructor(thisObj) ? new thisObj(arrayLikeLength) : @newArrayWithSize(arrayLikeLength);
+ var result = this !== @Array && @isConstructor(this) ? new this(arrayLikeLength) : @newArrayWithSize(arrayLikeLength);
var k = 0;
while (k < arrayLikeLength) {
Modified: trunk/Source/_javascript_Core/builtins/PromiseOperations.js (261600 => 261601)
--- trunk/Source/_javascript_Core/builtins/PromiseOperations.js 2020-05-13 06:41:34 UTC (rev 261600)
+++ trunk/Source/_javascript_Core/builtins/PromiseOperations.js 2020-05-13 07:08:13 UTC (rev 261601)
@@ -48,9 +48,6 @@
@promise: @undefined,
};
- if (!@isConstructor(constructor))
- @throwTypeError("promise capability requires a constructor function");
-
var promise = new constructor(function (resolve, reject) {
if (promiseCapability.@resolve !== @undefined)
@throwTypeError("resolve function is already set");