tc39 / ecma262

Status, process, and documents for ECMA-262
https://tc39.es/ecma262/
Other
15.08k stars 1.29k forks source link

Determination of the type of an object with uninitialized fields #3482

Open d01c2 opened 1 week ago

d01c2 commented 1 week ago

I have a question about how to determine the type of an object with uninitialized fields, as a continuation of the discussion in PR #3383.

Let’s assume the execution process of the program below:

new Promise(function () {});

This program follows the step of 27.2.3.1 Promise ( executor ) during execution. In step 8, it calls 27.2.1.3 CreateResolvingFunctions( promise ) with an argument _promise_, whose [[PromiseResult]] field is uninitialized. In this example, the annotated parameter type of the callee is a Promise, and 27.2.6 Properties of Promise Instances says the [[PromiseResult]] field of a promise instance should hold an ECMAScript language value.

I'm unsure if we can interpret the actual argument above as a Promise.

Similarly, the same JavaScript program also follows the steps of 27.5.3.8 CreateIteratorFromClosure ( closure, generatorBrand, generatorPrototype [ , extraSlots ] ). It calls27.5.3.1 GeneratorStart ( generator, generatorBody ) in step 14. The passed argument _generator_ has an uninitialized [[GeneratorContext]] field, which should be initialized in this case.

Additionally, I'm aware of the following statement:

Unless specified otherwise, the initial value of an internal slot is the value undefined.

which is specified in 6.1.7.2 Object Internal Methods and Internal Slots. Does this statement mean that the value of uninitialized field should be considered as undefined in case of type determination of an object?

michaelficarra commented 1 week ago

I'm unsure if we can interpret the actual argument above as a Promise.

I agree that this is unclear. We're going to try to clear up the initialisation of internal slots for objects created this way as part of https://github.com/tc39/ecma262/issues/3399.

I'll leave this open as a reminder for us to update our description of the various types of objects that are created in this way to define them in terms of their essential internal slots. I think those two changes together should resolve your concerns.

bakkot commented 1 week ago

3491 handles the Promise part of this.