- Revision
- 263222
- Author
- shvaikal...@gmail.com
- Date
- 2020-06-18 11:22:15 -0700 (Thu, 18 Jun 2020)
Log Message
Promise built-in functions should be anonymous non-constructors
https://bugs.webkit.org/show_bug.cgi?id=213317
Reviewed by Darin Adler.
JSTests:
* test262/expectations.yaml: Mark 20 test cases as passing.
Source/_javascript_Core:
This patch makes userland-exposed Promise built-in functions
non-constructors and sets their "name" properties to empty strings
as per spec [1], aligning JSC with V8 and SpiderMonkey.
@createResolvingFunctionsWithoutPromise change is covered by test262's
async-generator/yield-thenable-create-resolving-functions-*.js cases.
Promise microbenchmarks are neutral. Promise constructors bytecode is
unchanged, while @createResolvingFunctions* bytecode is reduced by 2
instructions.
[1]: https://tc39.es/ecma262/#sec-ecmascript-standard-built-in-objects
* builtins/PromiseConstructor.js:
(nakedConstructor.Promise):
(nakedConstructor.InternalPromise):
* builtins/PromiseOperations.js:
(globalPrivate.newPromiseCapabilitySlow):
(globalPrivate.createResolvingFunctions):
(globalPrivate.createResolvingFunctionsWithoutPromise):
(globalPrivate.createResolvingFunctions.resolve): Deleted.
(globalPrivate.createResolvingFunctions.reject): Deleted.
(resolve): Deleted.
(reject): Deleted.
* builtins/PromisePrototype.js:
(globalPrivate.getThenFinally):
(globalPrivate.getCatchFinally):
(valueThunk): Deleted.
(thrower): Deleted.
Modified Paths
Diff
Modified: trunk/JSTests/ChangeLog (263221 => 263222)
--- trunk/JSTests/ChangeLog 2020-06-18 17:47:01 UTC (rev 263221)
+++ trunk/JSTests/ChangeLog 2020-06-18 18:22:15 UTC (rev 263222)
@@ -1,5 +1,14 @@
2020-06-18 Alexey Shvayka <shvaikal...@gmail.com>
+ Promise built-in functions should be anonymous non-constructors
+ https://bugs.webkit.org/show_bug.cgi?id=213317
+
+ Reviewed by Darin Adler.
+
+ * test262/expectations.yaml: Mark 20 test cases as passing.
+
+2020-06-18 Alexey Shvayka <shvaikal...@gmail.com>
+
TypedArray.prototype.set is incorrect with primitives
https://bugs.webkit.org/show_bug.cgi?id=212730
Modified: trunk/JSTests/test262/expectations.yaml (263221 => 263222)
--- trunk/JSTests/test262/expectations.yaml 2020-06-18 17:47:01 UTC (rev 263221)
+++ trunk/JSTests/test262/expectations.yaml 2020-06-18 18:22:15 UTC (rev 263222)
@@ -994,30 +994,6 @@
test/built-ins/Object/values/order-after-define-property.js:
default: 'Test262Error: Expected [b, a] and [a, b] to have the same contents. '
strict mode: 'Test262Error: Expected [b, a] and [a, b] to have the same contents. '
-test/built-ins/Promise/create-resolving-functions-reject.js:
- default: 'Test262:AsyncTestFailure:Test262Error: Test262Error: Expected true but got false'
- strict mode: 'Test262:AsyncTestFailure:Test262Error: Test262Error: Expected true but got false'
-test/built-ins/Promise/create-resolving-functions-resolve.js:
- default: 'Test262:AsyncTestFailure:Test262Error: Test262Error: Expected true but got false'
- strict mode: 'Test262:AsyncTestFailure:Test262Error: Test262Error: Expected true but got false'
-test/built-ins/Promise/executor-function-nonconstructor.js:
- default: 'Test262Error: Expected SameValue(«true», «false») to be true'
- strict mode: 'Test262Error: Expected SameValue(«true», «false») to be true'
-test/built-ins/Promise/prototype/finally/invokes-then-with-function.js:
- default: 'Test262Error: fulfillment handler is not constructor'
- strict mode: 'Test262Error: fulfillment handler is not constructor'
-test/built-ins/Promise/prototype/finally/rejected-observable-then-calls-argument.js:
- default: 'Test262:AsyncTestFailure:Test262Error: Test262Error: Expected true but got false'
- strict mode: 'Test262:AsyncTestFailure:Test262Error: Test262Error: Expected true but got false'
-test/built-ins/Promise/prototype/finally/resolved-observable-then-calls-argument.js:
- default: 'Test262:AsyncTestFailure:Test262Error: Test262Error: Expected true but got false'
- strict mode: 'Test262:AsyncTestFailure:Test262Error: Test262Error: Expected true but got false'
-test/built-ins/Promise/reject-function-nonconstructor.js:
- default: 'Test262Error: Expected a TypeError to be thrown but no exception was thrown at all'
- strict mode: 'Test262Error: Expected a TypeError to be thrown but no exception was thrown at all'
-test/built-ins/Promise/resolve-function-nonconstructor.js:
- default: 'Test262Error: Expected a TypeError to be thrown but no exception was thrown at all'
- strict mode: 'Test262Error: Expected a TypeError to be thrown but no exception was thrown at all'
test/built-ins/Proxy/apply/arguments-realm.js:
default: 'Test262Error: Expected SameValue(«function Array() {'
strict mode: 'Test262Error: Expected SameValue(«function Array() {'
@@ -2108,12 +2084,6 @@
strict mode: 'Test262Error: Expected SameValue(«[object AsyncGenerator]», «[object AsyncGenerator]») to be false'
test/language/expressions/async-generator/named-eval-var-scope-syntax-err.js:
default: 'Test262Error: Expected a SyntaxError to be thrown but no exception was thrown at all'
-test/language/expressions/async-generator/yield-thenable-create-resolving-functions-reject.js:
- default: 'Test262:AsyncTestFailure:Test262Error: Test262Error: Expected true but got false'
- strict mode: 'Test262:AsyncTestFailure:Test262Error: Test262Error: Expected true but got false'
-test/language/expressions/async-generator/yield-thenable-create-resolving-functions-resolve.js:
- default: 'Test262:AsyncTestFailure:Test262Error: Test262Error: Expected true but got false'
- strict mode: 'Test262:AsyncTestFailure:Test262Error: Test262Error: Expected true but got false'
test/language/expressions/await/async-await-interleaved.js:
default: 'Test262:AsyncTestFailure:Test262Error: Test262Error: Expected [Await: 1, Promise: 1, Promise: 2, Await: 2] and [Await: 1, Promise: 1, Await: 2, Promise: 2] to have the same contents. Async/await and promises should be interleaved'
strict mode: 'Test262:AsyncTestFailure:Test262Error: Test262Error: Expected [Await: 1, Promise: 1, Promise: 2, Await: 2] and [Await: 1, Promise: 1, Await: 2, Promise: 2] to have the same contents. Async/await and promises should be interleaved'
Modified: trunk/Source/_javascript_Core/ChangeLog (263221 => 263222)
--- trunk/Source/_javascript_Core/ChangeLog 2020-06-18 17:47:01 UTC (rev 263221)
+++ trunk/Source/_javascript_Core/ChangeLog 2020-06-18 18:22:15 UTC (rev 263222)
@@ -1,5 +1,42 @@
2020-06-18 Alexey Shvayka <shvaikal...@gmail.com>
+ Promise built-in functions should be anonymous non-constructors
+ https://bugs.webkit.org/show_bug.cgi?id=213317
+
+ Reviewed by Darin Adler.
+
+ This patch makes userland-exposed Promise built-in functions
+ non-constructors and sets their "name" properties to empty strings
+ as per spec [1], aligning JSC with V8 and SpiderMonkey.
+
+ @createResolvingFunctionsWithoutPromise change is covered by test262's
+ async-generator/yield-thenable-create-resolving-functions-*.js cases.
+
+ Promise microbenchmarks are neutral. Promise constructors bytecode is
+ unchanged, while @createResolvingFunctions* bytecode is reduced by 2
+ instructions.
+
+ [1]: https://tc39.es/ecma262/#sec-ecmascript-standard-built-in-objects
+
+ * builtins/PromiseConstructor.js:
+ (nakedConstructor.Promise):
+ (nakedConstructor.InternalPromise):
+ * builtins/PromiseOperations.js:
+ (globalPrivate.newPromiseCapabilitySlow):
+ (globalPrivate.createResolvingFunctions):
+ (globalPrivate.createResolvingFunctionsWithoutPromise):
+ (globalPrivate.createResolvingFunctions.resolve): Deleted.
+ (globalPrivate.createResolvingFunctions.reject): Deleted.
+ (resolve): Deleted.
+ (reject): Deleted.
+ * builtins/PromisePrototype.js:
+ (globalPrivate.getThenFinally):
+ (globalPrivate.getCatchFinally):
+ (valueThunk): Deleted.
+ (thrower): Deleted.
+
+2020-06-18 Alexey Shvayka <shvaikal...@gmail.com>
+
TypedArray.prototype.set is incorrect with primitives
https://bugs.webkit.org/show_bug.cgi?id=212730
Modified: trunk/Source/_javascript_Core/builtins/PromiseConstructor.js (263221 => 263222)
--- trunk/Source/_javascript_Core/builtins/PromiseConstructor.js 2020-06-18 17:47:01 UTC (rev 263221)
+++ trunk/Source/_javascript_Core/builtins/PromiseConstructor.js 2020-06-18 18:22:15 UTC (rev 263222)
@@ -291,10 +291,10 @@
try {
executor(
- function (resolution) {
+ (resolution) => {
return @resolvePromiseWithFirstResolvingFunctionCallCheck(capturedPromise, resolution);
},
- function (reason) {
+ (reason) => {
return @rejectPromiseWithFirstResolvingFunctionCallCheck(capturedPromise, reason);
});
} catch (error) {
@@ -317,10 +317,10 @@
try {
executor(
- function (resolution) {
+ (resolution) => {
return @resolvePromiseWithFirstResolvingFunctionCallCheck(capturedPromise, resolution);
},
- function (reason) {
+ (reason) => {
return @rejectPromiseWithFirstResolvingFunctionCallCheck(capturedPromise, reason);
});
} catch (error) {
Modified: trunk/Source/_javascript_Core/builtins/PromiseOperations.js (263221 => 263222)
--- trunk/Source/_javascript_Core/builtins/PromiseOperations.js 2020-06-18 17:47:01 UTC (rev 263221)
+++ trunk/Source/_javascript_Core/builtins/PromiseOperations.js 2020-06-18 18:22:15 UTC (rev 263222)
@@ -48,7 +48,7 @@
@promise: @undefined,
};
- var promise = new constructor(function (resolve, reject) {
+ var promise = new constructor((resolve, reject) => {
if (promiseCapability.@resolve !== @undefined)
@throwTypeError("resolve function is already set");
if (promiseCapability.@reject !== @undefined)
@@ -236,28 +236,27 @@
function createResolvingFunctions(promise)
{
"use strict";
-
@assert(@isPromise(promise));
var alreadyResolved = false;
- function @resolve(resolution) {
+ var resolve = (0, /* prevent function name inference */ (resolution) => {
if (alreadyResolved)
return @undefined;
alreadyResolved = true;
return @resolvePromise(promise, resolution);
- }
+ });
- function @reject(reason) {
+ var reject = (0, /* prevent function name inference */ (reason) => {
if (alreadyResolved)
return @undefined;
alreadyResolved = true;
return @rejectPromise(promise, reason);
- }
+ });
- return { @resolve, @reject };
+ return { @resolve: resolve, @reject: reject };
}
@globalPrivate
@@ -330,23 +329,23 @@
var alreadyResolved = false;
- function @resolve(resolution) {
+ var resolve = (0, /* prevent function name inference */ (resolution) => {
if (alreadyResolved)
return @undefined;
alreadyResolved = true;
@resolveWithoutPromise(resolution, onFulfilled, onRejected);
- }
+ });
- function @reject(reason) {
+ var reject = (0, /* prevent function name inference */ (reason) => {
if (alreadyResolved)
return @undefined;
alreadyResolved = true;
@rejectWithoutPromise(reason, onFulfilled, onRejected);
- }
+ });
- return { @resolve, @reject };
+ return { @resolve: resolve, @reject: reject };
}
@globalPrivate
Modified: trunk/Source/_javascript_Core/builtins/PromisePrototype.js (263221 => 263222)
--- trunk/Source/_javascript_Core/builtins/PromisePrototype.js 2020-06-18 17:47:01 UTC (rev 263221)
+++ trunk/Source/_javascript_Core/builtins/PromisePrototype.js 2020-06-18 18:22:15 UTC (rev 263222)
@@ -102,7 +102,7 @@
{
"use strict";
- return function(value)
+ return (value) =>
{
@assert(typeof _onFinally_ === "function");
var result = onFinally();
@@ -113,9 +113,7 @@
resultCapability.@resolve.@call(@undefined, result);
var promise = resultCapability.@promise;
- var valueThunk = function () { return value; };
-
- return promise.then(valueThunk);
+ return promise.then(() => value);
}
}
@@ -124,7 +122,7 @@
{
"use strict";
- return function(reason)
+ return (reason) =>
{
@assert(typeof _onFinally_ === "function");
var result = onFinally();
@@ -135,8 +133,6 @@
resultCapability.@resolve.@call(@undefined, result);
var promise = resultCapability.@promise;
- var thrower = function () { throw reason; };
-
- return promise.then(thrower);
+ return promise.then(() => { throw reason; });
}
}