 Chromium Code Reviews
 Chromium Code Reviews Issue 2695753002:
  [ESnext] Implement Promise.prototype.finally  (Closed)
    
  
    Issue 2695753002:
  [ESnext] Implement Promise.prototype.finally  (Closed) 
  | Index: src/bootstrapper.cc | 
| diff --git a/src/bootstrapper.cc b/src/bootstrapper.cc | 
| index 7ab076aa2d4c5facaba8471d492be81c22a0ba56..17f7933e63e1c71334579c6f3b3ce37d9f31ad49 100644 | 
| --- a/src/bootstrapper.cc | 
| +++ b/src/bootstrapper.cc | 
| @@ -3624,6 +3624,55 @@ void Genesis::InitializeGlobal_harmony_async_iteration() { | 
| factory()->async_iterator_symbol()); | 
| } | 
| +void Genesis::InitializeGlobal_harmony_promise_finally() { | 
| + if (!FLAG_harmony_promise_finally) return; | 
| + | 
| + Handle<JSFunction> constructor(native_context()->promise_function()); | 
| + Handle<JSObject> prototype(JSObject::cast(constructor->instance_prototype())); | 
| + SimpleInstallFunction(prototype, "finally", Builtins::kPromiseFinally, 1, | 
| + true, DONT_ENUM); | 
| + | 
| + // The promise prototype map has changed because we added a property | 
| + // to prototype, so we update the saved map. | 
| + Handle<Map> prototype_map(prototype->map()); | 
| + Map::SetShouldBeFastPrototypeMap(prototype_map, true, isolate()); | 
| + native_context()->set_promise_prototype_map(*prototype_map); | 
| + | 
| + Handle<Code> code = handle( | 
| + isolate()->builtins()->builtin(Builtins::kPromiseThenFinally), isolate()); | 
| + Handle<SharedFunctionInfo> info = | 
| + factory()->NewSharedFunctionInfo(factory()->empty_string(), code, false); | 
| + info->set_internal_formal_parameter_count(1); | 
| + info->set_length(1); | 
| + native_context()->set_promise_then_finally_shared_fun(*info); | 
| 
neis
2017/02/15 12:40:39
Nit: put this block in { }.  Same below.
Should w
 
gsathya
2017/02/16 15:05:29
Why?
 
neis
2017/02/17 10:22:54
I find it easier to read if it's immediately clear
 
gsathya
2017/02/17 11:26:15
Ok. I made each SFI creation its own block
 | 
| + | 
| + code = handle(isolate()->builtins()->builtin(Builtins::kPromiseCatchFinally), | 
| + isolate()); | 
| + info = | 
| + factory()->NewSharedFunctionInfo(factory()->empty_string(), code, false); | 
| + info->set_internal_formal_parameter_count(1); | 
| + info->set_length(1); | 
| + native_context()->set_promise_catch_finally_shared_fun(*info); | 
| + | 
| + code = handle( | 
| + isolate()->builtins()->builtin(Builtins::kPromiseValueThunkFinally), | 
| + isolate()); | 
| + info = | 
| + factory()->NewSharedFunctionInfo(factory()->empty_string(), code, false); | 
| + info->set_internal_formal_parameter_count(0); | 
| + info->set_length(0); | 
| + native_context()->set_promise_value_thunk_finally_shared_fun(*info); | 
| + | 
| + code = | 
| + handle(isolate()->builtins()->builtin(Builtins::kPromiseThrowerFinally), | 
| + isolate()); | 
| + info = | 
| + factory()->NewSharedFunctionInfo(factory()->empty_string(), code, false); | 
| + info->set_internal_formal_parameter_count(0); | 
| + info->set_length(0); | 
| + native_context()->set_promise_thrower_finally_shared_fun(*info); | 
| +} | 
| + | 
| Handle<JSFunction> Genesis::InstallArrayBuffer(Handle<JSObject> target, | 
| const char* name, | 
| Builtins::Name call, | 
| @@ -4090,6 +4139,7 @@ bool Genesis::InstallExperimentalNatives() { | 
| static const char* harmony_object_rest_spread_natives[] = {nullptr}; | 
| static const char* harmony_async_iteration_natives[] = {nullptr}; | 
| static const char* harmony_dynamic_import_natives[] = {nullptr}; | 
| + static const char* harmony_promise_finally_natives[] = {nullptr}; | 
| for (int i = ExperimentalNatives::GetDebuggerCount(); | 
| i < ExperimentalNatives::GetBuiltinsCount(); i++) { |