Commit 3088ae38 authored by Igor Sheludko's avatar Igor Sheludko Committed by Commit Bot

[runtime] Cleanup native methods creation in js/promise.js.

This CL replaces usages of utils.InstallFunctions and utils.InstallGetter()
with the DEFINE_METHOD* macros that ensure that the native function is
created in proper form from the beginning. Thus the function will not
require further reconfiguring like adding a computed name or removing of
'prototype' property.

This CL is one of a series of cleanup CL which are the preliminary steps for
improving function closures creation.

Bug: v8:6459
Change-Id: Ic9ad538828ccd9d9e437d426e2948e987681fc5a
Reviewed-on: https://chromium-review.googlesource.com/548175
Commit-Queue: Igor Sheludko <ishell@chromium.org>
Reviewed-by: 's avatarToon Verwaest <verwaest@chromium.org>
Cr-Commit-Position: refs/heads/master@{#46292}
parent bd808e7a
......@@ -2159,19 +2159,18 @@ void Genesis::InitializeGlobal(Handle<JSGlobalObject> global_object,
native_context()->set_promise_then(*promise_then);
Handle<JSFunction> promise_catch = SimpleInstallFunction(
prototype, "catch", Builtins::kPromiseCatch, 1, true, DONT_ENUM);
prototype, "catch", Builtins::kPromiseCatch, 1, true);
native_context()->set_promise_catch(*promise_catch);
InstallSpeciesGetter(promise_fun);
SimpleInstallFunction(promise_fun, "all", Builtins::kPromiseAll, 1, true,
DONT_ENUM);
SimpleInstallFunction(promise_fun, "all", Builtins::kPromiseAll, 1, true);
SimpleInstallFunction(promise_fun, "resolve", Builtins::kPromiseResolve, 1,
true, DONT_ENUM);
true);
SimpleInstallFunction(promise_fun, "reject", Builtins::kPromiseReject, 1,
true, DONT_ENUM);
true);
Handle<Map> prototype_map(prototype->map());
Map::SetShouldBeFastPrototypeMap(prototype_map, true, isolate);
......@@ -2253,6 +2252,15 @@ void Genesis::InitializeGlobal(Handle<JSGlobalObject> global_object,
info->set_length(1);
native_context()->set_promise_all_resolve_element_shared_fun(*info);
}
// Force the Promise constructor to fast properties, so that we can use the
// fast paths for various things like
//
// x instanceof Promise
//
// etc. We should probably come up with a more principled approach once
// the JavaScript builtins are gone.
JSObject::MigrateSlowToFast(promise_fun, 0, "Bootstrapping");
}
{ // -- R e g E x p
......
......@@ -25,43 +25,39 @@ var GlobalPromise = global.Promise;
// ES#sec-promise.race
// Promise.race ( iterable )
function PromiseRace(iterable) {
if (!IS_RECEIVER(this)) {
throw %make_type_error(kCalledOnNonObject, PromiseRace);
}
DEFINE_METHOD(
GlobalPromise,
race(iterable) {
if (!IS_RECEIVER(this)) {
throw %make_type_error(kCalledOnNonObject, this);
}
// false debugEvent so that forwarding the rejection through race does not
// trigger redundant ExceptionEvents
var deferred = %new_promise_capability(this, false);
// false debugEvent so that forwarding the rejection through race does not
// trigger redundant ExceptionEvents
var deferred = %new_promise_capability(this, false);
// For catch prediction, don't treat the .then calls as handling it;
// instead, recurse outwards.
var instrumenting = DEBUG_IS_ACTIVE;
if (instrumenting) {
SET_PRIVATE(deferred.reject, promiseForwardingHandlerSymbol, true);
}
// For catch prediction, don't treat the .then calls as handling it;
// instead, recurse outwards.
var instrumenting = DEBUG_IS_ACTIVE;
if (instrumenting) {
SET_PRIVATE(deferred.reject, promiseForwardingHandlerSymbol, true);
}
try {
for (var value of iterable) {
var throwawayPromise = this.resolve(value).then(deferred.resolve,
deferred.reject);
// For catch prediction, mark that rejections here are semantically
// handled by the combined Promise.
if (instrumenting && %is_promise(throwawayPromise)) {
SET_PRIVATE(throwawayPromise, promiseHandledBySymbol, deferred.promise);
try {
for (var value of iterable) {
var throwawayPromise = this.resolve(value).then(deferred.resolve,
deferred.reject);
// For catch prediction, mark that rejections here are semantically
// handled by the combined Promise.
if (instrumenting && %is_promise(throwawayPromise)) {
SET_PRIVATE(throwawayPromise, promiseHandledBySymbol, deferred.promise);
}
}
} catch (e) {
%_Call(deferred.reject, UNDEFINED, e);
}
} catch (e) {
%_Call(deferred.reject, UNDEFINED, e);
return deferred.promise;
}
return deferred.promise;
}
// -------------------------------------------------------------------
// Install exported functions.
utils.InstallFunctions(GlobalPromise, DONT_ENUM, [
"race", PromiseRace,
]);
);
})
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment