-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[promise] Lookup the resolve property only once
In the PerformPromise{All, Race, AllSettled} operations, the resolve property of the constructor is looked up only once. In the implementation, for the fast path, where the constructor's resolve property is untainted, the resolve function is set to undefined. Since undefined can't be a valid value for the resolve function, we can switch on it (in CallResolve) to directly call the PromiseResolve builtin. If the resolve property is tainted, we do an observable property lookup, save this value, and call this property later (in CallResolve). I ran this CL against the test262 tests locally and they all pass: tc39/test262#2131 Spec: - tc39/ecma262#1506 - tc39/proposal-promise-allSettled#40 Bug: v8:9152 Change-Id: Icb36a90b5a244a67a729611c7b3315d2c29de6e9 Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1574705 Commit-Queue: Sathya Gunasekaran <gsathya@chromium.org> Reviewed-by: Jakob Gruber <jgruber@chromium.org> Cr-Commit-Position: refs/heads/master@{#60957}
- Loading branch information
Showing
8 changed files
with
186 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
// Copyright 2019 the V8 project authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
// | ||
// Flags: --allow-natives-syntax | ||
|
||
let count = 0; | ||
class MyPromise extends Promise { | ||
static get resolve() { | ||
count++; | ||
return super.resolve; | ||
} | ||
} | ||
|
||
MyPromise.all([1, 2, 3, 4, 5]); | ||
assertEquals(1, count); | ||
%PerformMicrotaskCheckpoint(); | ||
assertEquals(1, count); | ||
|
||
count = 0; | ||
MyPromise.all([ | ||
Promise.resolve(1), | ||
Promise.resolve(2), | ||
Promise.reject(3) | ||
]); | ||
assertEquals(1, count); | ||
%PerformMicrotaskCheckpoint(); | ||
assertEquals(1, count); |
28 changes: 28 additions & 0 deletions
28
test/mjsunit/promise-perform-all-settled-resolve-lookup.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
// Copyright 2019 the V8 project authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
// | ||
// Flags: --allow-natives-syntax --harmony-promise-all-settled | ||
|
||
let count = 0; | ||
class MyPromise extends Promise { | ||
static get resolve() { | ||
count++; | ||
return super.resolve; | ||
} | ||
} | ||
|
||
MyPromise.allSettled([1, 2, 3, 4, 5]); | ||
assertEquals(1, count); | ||
%PerformMicrotaskCheckpoint(); | ||
assertEquals(1, count); | ||
|
||
count = 0; | ||
MyPromise.allSettled([ | ||
Promise.resolve(1), | ||
Promise.resolve(2), | ||
Promise.reject(3) | ||
]); | ||
assertEquals(1, count); | ||
%PerformMicrotaskCheckpoint(); | ||
assertEquals(1, count); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
// Copyright 2019 the V8 project authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
// | ||
// Flags: --allow-natives-syntax | ||
|
||
let count = 0; | ||
class MyPromise extends Promise { | ||
static get resolve() { | ||
count++; | ||
return super.resolve; | ||
} | ||
} | ||
|
||
MyPromise.race([1, 2, 3, 4, 5]); | ||
assertEquals(1, count); | ||
%PerformMicrotaskCheckpoint(); | ||
assertEquals(1, count); | ||
|
||
count = 0; | ||
MyPromise.race([ | ||
Promise.resolve(1), | ||
Promise.resolve(2), | ||
Promise.reject(3) | ||
]); | ||
assertEquals(1, count); | ||
%PerformMicrotaskCheckpoint(); | ||
assertEquals(1, count); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters