Skip to content

Commit 5a2fc3b

Browse files
authored
feat(doc): Document all public APIs (#971)
1 parent f21fa0d commit 5a2fc3b

52 files changed

Lines changed: 1059 additions & 189 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

nova_vm/src/ecmascript.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// License, v. 2.0. If a copy of the MPL was not distributed with this
33
// file, You can obtain one at https://mozilla.org/MPL/2.0/.
44

5-
//!# [ECMAScript language](https://tc39.es/ecma262/)
5+
//! # [ECMAScript language](https://tc39.es/ecma262/)
66
//!
77
//! This module is the main entry point into the Nova JavaScript API and its
88
//! implementation of the ECMAScript language specification.

nova_vm/src/ecmascript/abstract_operations/operations_on_objects.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2683,7 +2683,7 @@ pub(crate) fn try_private_set<'gc>(
26832683
}
26842684
}
26852685

2686-
///### [7.3.33 InitializeInstanceElements ( O, constructor )](https://tc39.es/ecma262/#sec-initializeinstanceelements)
2686+
/// ### [7.3.33 InitializeInstanceElements ( O, constructor )](https://tc39.es/ecma262/#sec-initializeinstanceelements)
26872687
///
26882688
/// The abstract operation InitializeInstanceElements takes arguments O (an
26892689
/// Object) and constructor (an ECMAScript function object) and returns either

nova_vm/src/ecmascript/builtins/array.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,12 @@ use super::{
3838
};
3939

4040
/// ### [10.4.2 Array Exotic Objects](https://tc39.es/ecma262/#sec-array-exotic-objects)
41+
///
42+
/// ## Support status
43+
///
44+
/// `Array` in Nova does not support sparse storage. This means that setting the
45+
/// `length` property will grow the `Array`'s backing storage to the requested
46+
/// size or larger.
4147
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
4248
#[repr(transparent)]
4349
pub struct Array<'a>(BaseIndex<'a, ArrayHeapData<'static>>);

nova_vm/src/ecmascript/builtins/array_buffer.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,8 +290,10 @@ impl<'a> CreateHeapData<ArrayBufferHeapData<'a>, ArrayBuffer<'a>> for Heap {
290290
#[derive(Debug, Copy, Clone, Eq, PartialEq, PartialOrd, Ord, Hash)]
291291
#[repr(u8)]
292292
pub enum AnyArrayBuffer<'a> {
293+
/// ## [25.1 ArrayBuffer Objects](https://tc39.es/ecma262/#sec-arraybuffer-objects)
293294
ArrayBuffer(ArrayBuffer<'a>) = ARRAY_BUFFER_DISCRIMINANT,
294295
#[cfg(feature = "shared-array-buffer")]
296+
/// ## [25.2 SharedArrayBuffer Objects](https://tc39.es/ecma262/#sec-sharedarraybuffer-objects)
295297
SharedArrayBuffer(SharedArrayBuffer<'a>) = SHARED_ARRAY_BUFFER_DISCRIMINANT,
296298
}
297299
bindable_handle!(AnyArrayBuffer);

nova_vm/src/ecmascript/builtins/builtin_constructor.rs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ use super::ArgumentsList;
2424

2525
/// ### [4.4.36 built-in constructor](https://tc39.es/ecma262/#sec-built-in-constructor)
2626
///
27-
/// A class built-in default constructor created in step 14 of [ClassDefinitionEvaluation].
27+
/// A class built-in default constructor created in step 14 of
28+
/// [ClassDefinitionEvaluation].
2829
///
2930
/// #### Examples
3031
///
@@ -45,12 +46,6 @@ arena_vec_access!(
4546
builtin_constructors
4647
);
4748

48-
impl BuiltinConstructorFunction<'_> {
49-
pub const fn is_constructor(self) -> bool {
50-
true
51-
}
52-
}
53-
5449
impl<'a> FunctionInternalProperties<'a> for BuiltinConstructorFunction<'a> {
5550
fn get_name(self, agent: &Agent) -> &String<'a> {
5651
&self.get(agent).class_name

nova_vm/src/ecmascript/builtins/builtin_function.rs

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -387,7 +387,10 @@ pub type ConstructorFn = for<'gc> fn(
387387
#[allow(unpredictable_function_pointer_comparisons)]
388388
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
389389
pub enum Behaviour {
390+
/// Regular JavaScript function not callable with the `new` keyword.
390391
Regular(RegularFn),
392+
/// JavaScript function callable with the `new` keyword, and possibly
393+
/// without it.
391394
Constructor(ConstructorFn),
392395
}
393396

@@ -446,27 +449,37 @@ pub(crate) trait BuiltinIntrinsic: Builtin {
446449
}
447450
/// Helper trait for defining builtin getter function properties.
448451
pub trait BuiltinGetter: Builtin {
452+
/// Accessor property's getter function's `name` property value.
449453
const GETTER_NAME: String<'static> = Self::NAME;
454+
/// Accessor property's getter function's call behaviour.
450455
const GETTER_BEHAVIOUR: Behaviour = Self::BEHAVIOUR;
451456
}
452457
/// Helper trait for defining builtin setter function properties.
453458
pub trait BuiltinSetter: Builtin {
459+
/// Accessor property's setter function's `name` property value.
454460
const SETTER_NAME: String<'static> = Self::NAME;
461+
/// Accessor property's setter function's call behaviour.
455462
const SETTER_BEHAVIOUR: Behaviour = Self::BEHAVIOUR;
456463
}
457464

458465
/// Builtin function creation arguments.
459466
#[derive(Debug, Default)]
460467
pub struct BuiltinFunctionArgs<'a> {
468+
/// The builtin function's `length` property initial value.
461469
pub length: u32,
470+
/// The builtin function's `name` property initial value.
462471
pub name: &'static str,
472+
/// The builtin function's Realm. Defaults to the current Realm.
463473
pub realm: Option<Realm<'a>>,
474+
/// The builtin function's prototype. Defaults to the current Realm's
475+
/// `Function.prototype`
464476
pub prototype: Option<Object<'a>>,
477+
/// An optional prefix for the builtin function's name.
465478
pub prefix: Option<&'static str>,
466479
}
467480

468481
impl<'a> BuiltinFunctionArgs<'a> {
469-
// Create new builtin function creation arguments with length and name.
482+
/// Create new builtin function creation arguments with length and name.
470483
pub fn new(length: u32, name: &'static str) -> Self {
471484
Self {
472485
length,
@@ -475,7 +488,7 @@ impl<'a> BuiltinFunctionArgs<'a> {
475488
}
476489
}
477490

478-
// Create new builtin function creation arguments with length, name, and a realm.
491+
/// Create new builtin function creation arguments with length, name, and a realm.
479492
pub fn new_with_realm(length: u32, name: &'static str, realm: Realm<'a>) -> Self {
480493
Self {
481494
length,

nova_vm/src/ecmascript/builtins/control_abstraction_objects/generator_objects.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ object_handle!(Generator);
3232
arena_vec_access!(Generator, 'a, GeneratorHeapData, generators);
3333

3434
impl Generator<'_> {
35-
///### [27.5.3.3 GeneratorResume ( generator, value, generatorBrand )](https://tc39.es/ecma262/#sec-generatorresume)
35+
/// ### [27.5.3.3 GeneratorResume ( generator, value, generatorBrand )](https://tc39.es/ecma262/#sec-generatorresume)
3636
pub(crate) fn resume<'a>(
3737
self,
3838
agent: &mut Agent,
@@ -152,7 +152,7 @@ impl Generator<'_> {
152152
}
153153
}
154154

155-
///### [27.5.3.4 GeneratorResumeAbrupt ( generator, abruptCompletion, generatorBrand )](https://tc39.es/ecma262/#sec-generatorresumeabrupt)
155+
/// ### [27.5.3.4 GeneratorResumeAbrupt ( generator, abruptCompletion, generatorBrand )](https://tc39.es/ecma262/#sec-generatorresumeabrupt)
156156
/// NOTE: This method only accepts throw completions.
157157
pub(crate) fn resume_throw<'a>(
158158
self,
@@ -262,7 +262,7 @@ impl Generator<'_> {
262262
}
263263
}
264264

265-
///### [27.5.3.4 GeneratorResumeAbrupt ( generator, abruptCompletion, generatorBrand )](https://tc39.es/ecma262/#sec-generatorresumeabrupt)
265+
/// ### [27.5.3.4 GeneratorResumeAbrupt ( generator, abruptCompletion, generatorBrand )](https://tc39.es/ecma262/#sec-generatorresumeabrupt)
266266
/// NOTE: This method only accepts return completions.
267267
pub(crate) fn resume_return<'a>(
268268
self,

nova_vm/src/ecmascript/builtins/control_abstraction_objects/iteration/iterator_prototype.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ impl Builtin for IteratorPrototypeToStringTag {
8181
const BEHAVIOUR: Behaviour = Behaviour::Regular(IteratorPrototype::get_to_string_tag);
8282
}
8383
impl BuiltinGetter for IteratorPrototypeToStringTag {
84+
/// Accessor property's getter function's `name` property value.
8485
const GETTER_NAME: String<'static> = BUILTIN_STRING_MEMORY.get__Symbol_toStringTag_;
8586
}
8687
impl BuiltinSetter for IteratorPrototypeToStringTag {

nova_vm/src/ecmascript/builtins/control_abstraction_objects/promise_objects/promise_abstract_operations/promise_capability_records.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ pub struct PromiseCapability<'a> {
4040
}
4141

4242
impl<'a> PromiseCapability<'a> {
43-
///### [27.2.1.5 NewPromiseCapability ( C )](https://tc39.es/ecma262/#sec-newpromisecapability)
43+
/// ### [27.2.1.5 NewPromiseCapability ( C )](https://tc39.es/ecma262/#sec-newpromisecapability)
4444
///
4545
/// Create a new PromiseCapability
4646
///
@@ -84,7 +84,7 @@ impl<'a> PromiseCapability<'a> {
8484
}
8585
}
8686

87-
///### [27.2.1.4 FulfillPromise ( promise, value )](https://tc39.es/ecma262/#sec-fulfillpromise)
87+
/// ### [27.2.1.4 FulfillPromise ( promise, value )](https://tc39.es/ecma262/#sec-fulfillpromise)
8888
pub(crate) fn internal_fulfill(&self, agent: &mut Agent, value: Value, gc: NoGcScope) {
8989
// 1. Assert: The value of promise.[[PromiseState]] is pending.
9090
// 2. Let reactions be promise.[[PromiseFulfillReactions]].
@@ -108,7 +108,7 @@ impl<'a> PromiseCapability<'a> {
108108
}
109109
}
110110

111-
///### [27.2.1.7 RejectPromise ( promise, reason )](https://tc39.es/ecma262/#sec-rejectpromise)
111+
/// ### [27.2.1.7 RejectPromise ( promise, reason )](https://tc39.es/ecma262/#sec-rejectpromise)
112112
fn internal_reject(&self, agent: &mut Agent, reason: Value, gc: NoGcScope) {
113113
// 1. Assert: The value of promise.[[PromiseState]] is pending.
114114
// 2. Let reactions be promise.[[PromiseRejectReactions]].
@@ -141,7 +141,7 @@ impl<'a> PromiseCapability<'a> {
141141
}
142142
}
143143

144-
///### [27.2.1.3.2 Promise Resolve Functions](https://tc39.es/ecma262/#sec-promise-resolve-functions)
144+
/// ### [27.2.1.3.2 Promise Resolve Functions](https://tc39.es/ecma262/#sec-promise-resolve-functions)
145145
///
146146
/// Resolve the associated [`Promise`] with a given value. Ignored if the
147147
/// [`Promise`] is already resolved.
@@ -246,7 +246,7 @@ impl<'a> PromiseCapability<'a> {
246246
// 16. Return undefined.
247247
}
248248

249-
///### [27.2.1.3.2 Promise Resolve Functions](https://tc39.es/ecma262/#sec-promise-resolve-functions)
249+
/// ### [27.2.1.3.2 Promise Resolve Functions](https://tc39.es/ecma262/#sec-promise-resolve-functions)
250250
///
251251
/// Try resolve the associated [`Promise`] with a given value. Fails if
252252
/// resolving would require calling into user-code. Ignored if the
@@ -335,7 +335,7 @@ impl<'a> PromiseCapability<'a> {
335335
TryResult::Continue(())
336336
}
337337

338-
///### [27.2.1.3.1 Promise Reject Functions](https://tc39.es/ecma262/#sec-promise-reject-functions)
338+
/// ### [27.2.1.3.1 Promise Reject Functions](https://tc39.es/ecma262/#sec-promise-reject-functions)
339339
///
340340
/// Reject the associated [`Promise`] with a given value. Ignored if the
341341
/// [`Promise`] is already resolved.

nova_vm/src/ecmascript/builtins/data_view.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -366,8 +366,12 @@ impl HeapSweepWeakReference for SharedDataView<'static> {
366366
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
367367
#[repr(u8)]
368368
pub enum AnyDataView<'a> {
369+
/// ## [25.3 DataView Objects](https://tc39.es/ecma262/#sec-dataview-objects)
369370
DataView(DataView<'a>) = DATA_VIEW_DISCRIMINANT,
370371
#[cfg(feature = "shared-array-buffer")]
372+
/// ## [25.3 DataView Objects](https://tc39.es/ecma262/#sec-dataview-objects)
373+
///
374+
/// A variant of DataView Objects viewing a SharedArrayBuffer.
371375
SharedDataView(SharedDataView<'a>) = SHARED_DATA_VIEW_DISCRIMINANT,
372376
}
373377
bindable_handle!(AnyDataView);

0 commit comments

Comments
 (0)