Skip to content

Commit 67edb9c

Browse files
authored
feat(ecmascript): Promise.prototype.finally (#824)
1 parent 65f416e commit 67edb9c

File tree

25 files changed

+1228
-1134
lines changed

25 files changed

+1228
-1134
lines changed

nova_vm/src/ecmascript/builtins/bound_function.rs

Lines changed: 11 additions & 136 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,12 @@ use crate::{
1111
testing_and_comparison::is_constructor,
1212
},
1313
execution::{
14-
Agent, JsResult, ProtoIntrinsics,
14+
Agent, JsResult,
1515
agent::{TryResult, unwrap_try},
1616
},
1717
types::{
1818
BoundFunctionHeapData, Function, FunctionInternalProperties, InternalMethods,
19-
InternalSlots, IntoFunction, IntoValue, Object, OrdinaryObject, PropertyDescriptor,
20-
PropertyKey, SetResult, String, TryGetResult, TryHasResult, Value,
21-
function_create_backing_object, function_internal_define_own_property,
22-
function_internal_delete, function_internal_get, function_internal_get_own_property,
23-
function_internal_has_property, function_internal_own_property_keys,
24-
function_internal_set, function_try_get, function_try_has_property, function_try_set,
19+
IntoFunction, IntoValue, Object, OrdinaryObject, String, Value,
2520
},
2621
},
2722
engine::{
@@ -34,7 +29,7 @@ use crate::{
3429
},
3530
};
3631

37-
use super::{ArgumentsList, ordinary::caches::PropertyLookupCache};
32+
use super::ArgumentsList;
3833

3934
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
4035
#[repr(transparent)]
@@ -154,17 +149,17 @@ impl<'a> FunctionInternalProperties<'a> for BoundFunction<'a> {
154149
fn get_length(self, agent: &Agent) -> u8 {
155150
agent[self].length
156151
}
157-
}
158-
159-
impl<'a> InternalSlots<'a> for BoundFunction<'a> {
160-
const DEFAULT_PROTOTYPE: ProtoIntrinsics = ProtoIntrinsics::Function;
161152

162153
#[inline(always)]
163-
fn get_backing_object(self, agent: &Agent) -> Option<OrdinaryObject<'static>> {
154+
fn get_function_backing_object(self, agent: &Agent) -> Option<OrdinaryObject<'static>> {
164155
agent[self].object_index.unbind()
165156
}
166157

167-
fn set_backing_object(self, agent: &mut Agent, backing_object: OrdinaryObject<'static>) {
158+
fn set_function_backing_object(
159+
self,
160+
agent: &mut Agent,
161+
backing_object: OrdinaryObject<'static>,
162+
) {
168163
assert!(
169164
agent[self]
170165
.object_index
@@ -173,134 +168,14 @@ impl<'a> InternalSlots<'a> for BoundFunction<'a> {
173168
);
174169
}
175170

176-
fn create_backing_object(self, agent: &mut Agent) -> OrdinaryObject<'static> {
177-
function_create_backing_object(self, agent)
178-
}
179-
}
180-
181-
impl<'a> InternalMethods<'a> for BoundFunction<'a> {
182-
fn try_get_own_property<'gc>(
183-
self,
184-
agent: &mut Agent,
185-
property_key: PropertyKey,
186-
cache: Option<PropertyLookupCache>,
187-
gc: NoGcScope<'gc, '_>,
188-
) -> TryResult<'gc, Option<PropertyDescriptor<'gc>>> {
189-
TryResult::Continue(function_internal_get_own_property(
190-
self,
191-
agent,
192-
property_key,
193-
cache,
194-
gc,
195-
))
196-
}
197-
198-
fn try_define_own_property<'gc>(
199-
self,
200-
agent: &mut Agent,
201-
property_key: PropertyKey,
202-
property_descriptor: PropertyDescriptor,
203-
cache: Option<PropertyLookupCache>,
204-
gc: NoGcScope<'gc, '_>,
205-
) -> TryResult<'gc, bool> {
206-
function_internal_define_own_property(
207-
self,
208-
agent,
209-
property_key,
210-
property_descriptor,
211-
cache,
212-
gc,
213-
)
214-
}
215-
216-
fn try_has_property<'gc>(
217-
self,
218-
agent: &mut Agent,
219-
property_key: PropertyKey,
220-
cache: Option<PropertyLookupCache>,
221-
gc: NoGcScope<'gc, '_>,
222-
) -> TryResult<'gc, TryHasResult<'gc>> {
223-
function_try_has_property(self, agent, property_key, cache, gc)
224-
}
225-
226-
fn internal_has_property<'gc>(
227-
self,
228-
agent: &mut Agent,
229-
property_key: PropertyKey,
230-
gc: GcScope<'gc, '_>,
231-
) -> JsResult<'gc, bool> {
232-
function_internal_has_property(self, agent, property_key, gc)
233-
}
234-
235-
fn try_get<'gc>(
236-
self,
237-
agent: &mut Agent,
238-
property_key: PropertyKey,
239-
receiver: Value,
240-
cache: Option<PropertyLookupCache>,
241-
gc: NoGcScope<'gc, '_>,
242-
) -> TryResult<'gc, TryGetResult<'gc>> {
243-
function_try_get(self, agent, property_key, receiver, cache, gc)
244-
}
245-
246-
fn internal_get<'gc>(
247-
self,
248-
agent: &mut Agent,
249-
property_key: PropertyKey,
250-
receiver: Value,
251-
gc: GcScope<'gc, '_>,
252-
) -> JsResult<'gc, Value<'gc>> {
253-
function_internal_get(self, agent, property_key, receiver, gc)
254-
}
255-
256-
fn try_set<'gc>(
257-
self,
258-
agent: &mut Agent,
259-
property_key: PropertyKey,
260-
value: Value,
261-
receiver: Value,
262-
cache: Option<PropertyLookupCache>,
263-
gc: NoGcScope<'gc, '_>,
264-
) -> TryResult<'gc, SetResult<'gc>> {
265-
function_try_set(self, agent, property_key, value, receiver, cache, gc)
266-
}
267-
268-
fn internal_set<'gc>(
269-
self,
270-
agent: &mut Agent,
271-
property_key: PropertyKey,
272-
value: Value,
273-
receiver: Value,
274-
gc: GcScope<'gc, '_>,
275-
) -> JsResult<'gc, bool> {
276-
function_internal_set(self, agent, property_key, value, receiver, gc)
277-
}
278-
279-
fn try_delete<'gc>(
280-
self,
281-
agent: &mut Agent,
282-
property_key: PropertyKey,
283-
gc: NoGcScope<'gc, '_>,
284-
) -> TryResult<'gc, bool> {
285-
TryResult::Continue(function_internal_delete(self, agent, property_key, gc))
286-
}
287-
288-
fn try_own_property_keys<'gc>(
289-
self,
290-
agent: &mut Agent,
291-
gc: NoGcScope<'gc, '_>,
292-
) -> TryResult<'gc, Vec<PropertyKey<'gc>>> {
293-
TryResult::Continue(function_internal_own_property_keys(self, agent, gc))
294-
}
295-
296171
/// ### [10.4.1.1 \[\[Call\]\] ( thisArgument, argumentsList )](https://tc39.es/ecma262/#sec-bound-function-exotic-objects-call-thisargument-argumentslist)
297172
///
298173
/// The \[\[Call]] internal method of a bound function exotic object F
299174
/// takes arguments thisArgument (an ECMAScript language value) and
300175
/// argumentsList (a List of ECMAScript language values) and returns either
301176
/// a normal completion containing an ECMAScript language value or a throw
302177
/// completion.
303-
fn internal_call<'gc>(
178+
fn function_call<'gc>(
304179
self,
305180
agent: &mut Agent,
306181
_: Value,
@@ -350,7 +225,7 @@ impl<'a> InternalMethods<'a> for BoundFunction<'a> {
350225
/// takes arguments argumentsList (a List of ECMAScript language values)
351226
/// and newTarget (a constructor) and returns either a normal completion
352227
/// containing an Object or a throw completion.
353-
fn internal_construct<'gc>(
228+
fn function_construct<'gc>(
354229
self,
355230
agent: &mut Agent,
356231
arguments_list: ArgumentsList,

nova_vm/src/ecmascript/builtins/builtin_constructor.rs

Lines changed: 12 additions & 137 deletions
Original file line numberDiff line numberDiff line change
@@ -9,22 +9,17 @@ use oxc_span::Span;
99
use crate::{
1010
ecmascript::{
1111
execution::{
12-
Agent, Environment, ExecutionContext, JsResult, PrivateEnvironment, ProtoIntrinsics,
13-
agent::{ExceptionType, TryResult},
12+
Agent, Environment, ExecutionContext, JsResult, PrivateEnvironment,
13+
agent::ExceptionType,
1414
},
1515
scripts_and_modules::source_code::SourceCode,
1616
syntax_directed_operations::class_definitions::{
1717
base_class_default_constructor, derived_class_default_constructor,
1818
},
1919
types::{
2020
BUILTIN_STRING_MEMORY, BuiltinConstructorHeapData, Function,
21-
FunctionInternalProperties, InternalMethods, InternalSlots, IntoFunction, IntoObject,
22-
IntoValue, Object, OrdinaryObject, PropertyDescriptor, PropertyKey, SetResult, String,
23-
TryGetResult, TryHasResult, Value, function_create_backing_object,
24-
function_internal_define_own_property, function_internal_delete, function_internal_get,
25-
function_internal_get_own_property, function_internal_has_property,
26-
function_internal_own_property_keys, function_internal_set, function_try_get,
27-
function_try_has_property, function_try_set,
21+
FunctionInternalProperties, IntoFunction, IntoObject, IntoValue, Object,
22+
OrdinaryObject, PropertyKey, String, Value,
2823
},
2924
},
3025
engine::{
@@ -38,7 +33,7 @@ use crate::{
3833
},
3934
};
4035

41-
use super::{ArgumentsList, ordinary::caches::PropertyLookupCache};
36+
use super::ArgumentsList;
4237

4338
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
4439
pub struct BuiltinConstructorFunction<'a>(pub(crate) BuiltinConstructorIndex<'a>);
@@ -171,138 +166,18 @@ impl<'a> FunctionInternalProperties<'a> for BuiltinConstructorFunction<'a> {
171166
fn get_length(self, _: &Agent) -> u8 {
172167
unreachable!();
173168
}
174-
}
175-
176-
impl<'a> InternalSlots<'a> for BuiltinConstructorFunction<'a> {
177-
const DEFAULT_PROTOTYPE: ProtoIntrinsics = ProtoIntrinsics::Function;
178169

179170
#[inline(always)]
180-
fn get_backing_object(self, agent: &Agent) -> Option<OrdinaryObject<'static>> {
171+
fn get_function_backing_object(self, agent: &Agent) -> Option<OrdinaryObject<'static>> {
181172
agent[self].object_index
182173
}
183174

184-
fn set_backing_object(self, agent: &mut Agent, backing_object: OrdinaryObject<'static>) {
185-
assert!(agent[self].object_index.replace(backing_object).is_none());
186-
}
187-
188-
fn create_backing_object(self, agent: &mut Agent) -> OrdinaryObject<'static> {
189-
function_create_backing_object(self, agent)
190-
}
191-
}
192-
193-
impl<'a> InternalMethods<'a> for BuiltinConstructorFunction<'a> {
194-
fn try_get_own_property<'gc>(
195-
self,
196-
agent: &mut Agent,
197-
property_key: PropertyKey,
198-
cache: Option<PropertyLookupCache>,
199-
gc: NoGcScope<'gc, '_>,
200-
) -> TryResult<'gc, Option<PropertyDescriptor<'gc>>> {
201-
TryResult::Continue(function_internal_get_own_property(
202-
self,
203-
agent,
204-
property_key,
205-
cache,
206-
gc,
207-
))
208-
}
209-
210-
fn try_define_own_property<'gc>(
211-
self,
212-
agent: &mut Agent,
213-
property_key: PropertyKey,
214-
property_descriptor: PropertyDescriptor,
215-
cache: Option<PropertyLookupCache>,
216-
gc: NoGcScope<'gc, '_>,
217-
) -> TryResult<'gc, bool> {
218-
function_internal_define_own_property(
219-
self,
220-
agent,
221-
property_key,
222-
property_descriptor,
223-
cache,
224-
gc,
225-
)
226-
}
227-
228-
fn try_has_property<'gc>(
175+
fn set_function_backing_object(
229176
self,
230177
agent: &mut Agent,
231-
property_key: PropertyKey,
232-
cache: Option<PropertyLookupCache>,
233-
gc: NoGcScope<'gc, '_>,
234-
) -> TryResult<'gc, TryHasResult<'gc>> {
235-
function_try_has_property(self, agent, property_key, cache, gc)
236-
}
237-
238-
fn internal_has_property<'gc>(
239-
self,
240-
agent: &mut Agent,
241-
property_key: PropertyKey,
242-
gc: GcScope<'gc, '_>,
243-
) -> JsResult<'gc, bool> {
244-
function_internal_has_property(self, agent, property_key, gc)
245-
}
246-
247-
fn try_get<'gc>(
248-
self,
249-
agent: &mut Agent,
250-
property_key: PropertyKey,
251-
receiver: Value,
252-
cache: Option<PropertyLookupCache>,
253-
gc: NoGcScope<'gc, '_>,
254-
) -> TryResult<'gc, TryGetResult<'gc>> {
255-
function_try_get(self, agent, property_key, receiver, cache, gc)
256-
}
257-
258-
fn internal_get<'gc>(
259-
self,
260-
agent: &mut Agent,
261-
property_key: PropertyKey,
262-
receiver: Value,
263-
gc: GcScope<'gc, '_>,
264-
) -> JsResult<'gc, Value<'gc>> {
265-
function_internal_get(self, agent, property_key, receiver, gc)
266-
}
267-
268-
fn try_set<'gc>(
269-
self,
270-
agent: &mut Agent,
271-
property_key: PropertyKey,
272-
value: Value,
273-
receiver: Value,
274-
cache: Option<PropertyLookupCache>,
275-
gc: NoGcScope<'gc, '_>,
276-
) -> TryResult<'gc, SetResult<'gc>> {
277-
function_try_set(self, agent, property_key, value, receiver, cache, gc)
278-
}
279-
280-
fn internal_set<'gc>(
281-
self,
282-
agent: &mut Agent,
283-
property_key: PropertyKey,
284-
value: Value,
285-
receiver: Value,
286-
gc: GcScope<'gc, '_>,
287-
) -> JsResult<'gc, bool> {
288-
function_internal_set(self, agent, property_key, value, receiver, gc)
289-
}
290-
291-
fn try_delete<'gc>(
292-
self,
293-
agent: &mut Agent,
294-
property_key: PropertyKey,
295-
gc: NoGcScope<'gc, '_>,
296-
) -> TryResult<'gc, bool> {
297-
TryResult::Continue(function_internal_delete(self, agent, property_key, gc))
298-
}
299-
300-
fn try_own_property_keys<'gc>(
301-
self,
302-
agent: &mut Agent,
303-
gc: NoGcScope<'gc, '_>,
304-
) -> TryResult<'gc, Vec<PropertyKey<'gc>>> {
305-
TryResult::Continue(function_internal_own_property_keys(self, agent, gc))
178+
backing_object: OrdinaryObject<'static>,
179+
) {
180+
assert!(agent[self].object_index.replace(backing_object).is_none());
306181
}
307182

308183
/// ### [10.3.1 \[\[Call\]\] ( thisArgument, argumentsList )](https://tc39.es/ecma262/#sec-built-in-function-objects-call-thisargument-argumentslist)
@@ -312,7 +187,7 @@ impl<'a> InternalMethods<'a> for BuiltinConstructorFunction<'a> {
312187
/// (a List of ECMAScript language values) and returns either a normal
313188
/// completion containing an ECMAScript language value or a throw
314189
/// completion.
315-
fn internal_call<'gc>(
190+
fn function_call<'gc>(
316191
self,
317192
agent: &mut Agent,
318193
_: Value,
@@ -334,7 +209,7 @@ impl<'a> InternalMethods<'a> for BuiltinConstructorFunction<'a> {
334209
/// the method is present) takes arguments argumentsList (a List of
335210
/// ECMAScript language values) and newTarget (a constructor) and returns
336211
/// either a normal completion containing an Object or a throw completion.
337-
fn internal_construct<'gc>(
212+
fn function_construct<'gc>(
338213
self,
339214
agent: &mut Agent,
340215
arguments_list: ArgumentsList,

0 commit comments

Comments
 (0)