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, ...@@ -2159,19 +2159,18 @@ void Genesis::InitializeGlobal(Handle<JSGlobalObject> global_object,
native_context()->set_promise_then(*promise_then); native_context()->set_promise_then(*promise_then);
Handle<JSFunction> promise_catch = SimpleInstallFunction( 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); native_context()->set_promise_catch(*promise_catch);
InstallSpeciesGetter(promise_fun); InstallSpeciesGetter(promise_fun);
SimpleInstallFunction(promise_fun, "all", Builtins::kPromiseAll, 1, true, SimpleInstallFunction(promise_fun, "all", Builtins::kPromiseAll, 1, true);
DONT_ENUM);
SimpleInstallFunction(promise_fun, "resolve", Builtins::kPromiseResolve, 1, SimpleInstallFunction(promise_fun, "resolve", Builtins::kPromiseResolve, 1,
true, DONT_ENUM); true);
SimpleInstallFunction(promise_fun, "reject", Builtins::kPromiseReject, 1, SimpleInstallFunction(promise_fun, "reject", Builtins::kPromiseReject, 1,
true, DONT_ENUM); true);
Handle<Map> prototype_map(prototype->map()); Handle<Map> prototype_map(prototype->map());
Map::SetShouldBeFastPrototypeMap(prototype_map, true, isolate); Map::SetShouldBeFastPrototypeMap(prototype_map, true, isolate);
...@@ -2253,6 +2252,15 @@ void Genesis::InitializeGlobal(Handle<JSGlobalObject> global_object, ...@@ -2253,6 +2252,15 @@ void Genesis::InitializeGlobal(Handle<JSGlobalObject> global_object,
info->set_length(1); info->set_length(1);
native_context()->set_promise_all_resolve_element_shared_fun(*info); 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 { // -- R e g E x p
......
...@@ -25,9 +25,11 @@ var GlobalPromise = global.Promise; ...@@ -25,9 +25,11 @@ var GlobalPromise = global.Promise;
// ES#sec-promise.race // ES#sec-promise.race
// Promise.race ( iterable ) // Promise.race ( iterable )
function PromiseRace(iterable) { DEFINE_METHOD(
GlobalPromise,
race(iterable) {
if (!IS_RECEIVER(this)) { if (!IS_RECEIVER(this)) {
throw %make_type_error(kCalledOnNonObject, PromiseRace); throw %make_type_error(kCalledOnNonObject, this);
} }
// false debugEvent so that forwarding the rejection through race does not // false debugEvent so that forwarding the rejection through race does not
...@@ -55,13 +57,7 @@ function PromiseRace(iterable) { ...@@ -55,13 +57,7 @@ function PromiseRace(iterable) {
%_Call(deferred.reject, UNDEFINED, 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