Commit b8320b6f authored by Benedikt Meurer's avatar Benedikt Meurer Committed by Commit Bot

[turbofan] Properly type Promise builtins.

Add missing typing rules for calls to Promise builtins. All of these
return receivers always, since PromiseCapabilities.[[Promise]] can be
any receiver essentially. Adding the typing rules here helps to rule
out unnecessary Smi checks in the general case.

Bug: v8:7253
Change-Id: Ia51546420f331431872183a92702855f91b7daba
Reviewed-on: https://chromium-review.googlesource.com/c/1293956Reviewed-by: 's avatarSathya Gunasekaran <gsathya@chromium.org>
Commit-Queue: Benedikt Meurer <bmeurer@chromium.org>
Cr-Commit-Position: refs/heads/master@{#56876}
parent 1b4436e7
......@@ -2387,16 +2387,18 @@ void Genesis::InitializeGlobal(Handle<JSGlobalObject> global_object,
InstallSpeciesGetter(isolate_, promise_fun);
SimpleInstallFunction(isolate_, promise_fun, "all", Builtins::kPromiseAll,
1, true);
1, true, BuiltinFunctionId::kPromiseAll);
SimpleInstallFunction(isolate_, promise_fun, "race", Builtins::kPromiseRace,
1, true);
1, true, BuiltinFunctionId::kPromiseRace);
SimpleInstallFunction(isolate_, promise_fun, "resolve",
Builtins::kPromiseResolveTrampoline, 1, true);
Builtins::kPromiseResolveTrampoline, 1, true,
BuiltinFunctionId::kPromiseResolve);
SimpleInstallFunction(isolate_, promise_fun, "reject",
Builtins::kPromiseReject, 1, true);
Builtins::kPromiseReject, 1, true,
BuiltinFunctionId::kPromiseReject);
// Setup %PromisePrototype%.
Handle<JSObject> prototype(
......@@ -2411,17 +2413,18 @@ void Genesis::InitializeGlobal(Handle<JSGlobalObject> global_object,
Handle<JSFunction> promise_then = SimpleInstallFunction(
isolate_, prototype, isolate_->factory()->then_string(),
Builtins::kPromisePrototypeThen, 2, true);
Builtins::kPromisePrototypeThen, 2, true, DONT_ENUM,
BuiltinFunctionId::kPromisePrototypeThen);
native_context()->set_promise_then(*promise_then);
Handle<JSFunction> promise_catch =
SimpleInstallFunction(isolate_, prototype, "catch",
Builtins::kPromisePrototypeCatch, 1, true);
Handle<JSFunction> promise_catch = SimpleInstallFunction(
isolate_, prototype, "catch", Builtins::kPromisePrototypeCatch, 1, true,
BuiltinFunctionId::kPromisePrototypeCatch);
native_context()->set_promise_catch(*promise_catch);
SimpleInstallFunction(isolate_, prototype, "finally",
Builtins::kPromisePrototypeFinally, 1, true,
DONT_ENUM);
SimpleInstallFunction(
isolate_, prototype, "finally", Builtins::kPromisePrototypeFinally, 1,
true, DONT_ENUM, BuiltinFunctionId::kPromisePrototypeFinally);
{
Handle<SharedFunctionInfo> info = SimpleCreateSharedFunctionInfo(
......
......@@ -1626,6 +1626,21 @@ Type Typer::Visitor::JSCallTyper(Type fun, Typer* t) {
case BuiltinFunctionId::kObjectToString:
return Type::String();
case BuiltinFunctionId::kPromiseAll:
return Type::Receiver();
case BuiltinFunctionId::kPromisePrototypeCatch:
return Type::Receiver();
case BuiltinFunctionId::kPromisePrototypeFinally:
return Type::Receiver();
case BuiltinFunctionId::kPromisePrototypeThen:
return Type::Receiver();
case BuiltinFunctionId::kPromiseRace:
return Type::Receiver();
case BuiltinFunctionId::kPromiseReject:
return Type::Receiver();
case BuiltinFunctionId::kPromiseResolve:
return Type::Receiver();
// RegExp functions.
case BuiltinFunctionId::kRegExpCompile:
return Type::OtherObject();
......
......@@ -192,6 +192,13 @@ enum class BuiltinFunctionId : uint8_t {
kGlobalIsFinite,
kGlobalIsNaN,
kNumberConstructor,
kPromiseAll,
kPromisePrototypeCatch,
kPromisePrototypeFinally,
kPromisePrototypeThen,
kPromiseRace,
kPromiseReject,
kPromiseResolve,
kSymbolConstructor,
kSymbolPrototypeToString,
kSymbolPrototypeValueOf,
......
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