Skip to content

Commit

Permalink
Add documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
jedel1043 committed Sep 16, 2022
1 parent 6a84f78 commit 74baea6
Show file tree
Hide file tree
Showing 9 changed files with 295 additions and 101 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions boa_engine/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ unicode-normalization = "0.1.21"
dyn-clone = "1.0.9"
once_cell = "1.14.0"
tap = "1.0.1"
thiserror = "1.0.35"
icu_locale_canonicalizer = { version = "0.6.0", features = ["serde"], optional = true }
icu_locid = { version = "0.6.0", features = ["serde"], optional = true }
icu_datetime = { version = "0.6.0", features = ["serde"], optional = true }
Expand Down
13 changes: 8 additions & 5 deletions boa_engine/src/builtins/async_generator/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use crate::{
symbol::WellKnownSymbols,
value::JsValue,
vm::GeneratorResumeKind,
Context, JsResult,
Context, JsError, JsResult,
};
use boa_gc::{Cell, Finalize, Gc, Trace};
use boa_profiler::Profiler;
Expand Down Expand Up @@ -399,7 +399,10 @@ impl AsyncGenerator {
}

// 8. Let completion be ThrowCompletion(exception).
let completion = (Err(args.get_or_undefined(0).clone().into()), false);
let completion = (
Err(JsError::from_opaque(args.get_or_undefined(0).clone())),
false,
);

// 9. Perform AsyncGeneratorEnqueue(generator, completion, promiseCapability).
generator.enqueue(completion.clone(), promise_capability.clone());
Expand Down Expand Up @@ -473,7 +476,7 @@ impl AsyncGenerator {
// a. Perform ! Call(promiseCapability.[[Reject]], undefined, « value »).
promise_capability
.reject()
.call(&JsValue::undefined(), &[e.to_value(context)], context)
.call(&JsValue::undefined(), &[e.to_opaque(context)], context)
.expect("cannot fail per spec");
}
// 8. Else,
Expand Down Expand Up @@ -552,7 +555,7 @@ impl AsyncGenerator {
}
}
(Err(value), _) => {
let value = value.to_value(context);
let value = value.to_opaque(context);
context.vm.push(value);
context.vm.frame_mut().generator_resume_kind = GeneratorResumeKind::Throw;
}
Expand Down Expand Up @@ -669,7 +672,7 @@ impl AsyncGenerator {
gen.state = AsyncGeneratorState::Completed;

// b. Let result be ThrowCompletion(reason).
let result = Err(args.get_or_undefined(0).clone().into());
let result = Err(JsError::from_opaque(args.get_or_undefined(0).clone()));

// c. Perform AsyncGeneratorCompleteStep(generator, result, true).
let next = gen.queue.pop_front().expect("must have one entry");
Expand Down
10 changes: 7 additions & 3 deletions boa_engine/src/builtins/generator/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use crate::{
symbol::WellKnownSymbols,
value::JsValue,
vm::{CallFrame, GeneratorResumeKind, ReturnType},
Context, JsResult,
Context, JsError, JsResult,
};
use boa_gc::{Cell, Finalize, Gc, Trace};
use boa_profiler::Profiler;
Expand Down Expand Up @@ -198,7 +198,11 @@ impl Generator {
// 1. Let g be the this value.
// 2. Let C be ThrowCompletion(exception).
// 3. Return ? GeneratorResumeAbrupt(g, C, empty).
Self::generator_resume_abrupt(this, Err(args.get_or_undefined(0).clone().into()), context)
Self::generator_resume_abrupt(
this,
Err(JsError::from_opaque(args.get_or_undefined(0).clone())),
context,
)
}

/// `27.5.3.3 GeneratorResume ( generator, value, generatorBrand )`
Expand Down Expand Up @@ -386,7 +390,7 @@ impl Generator {
context.run()
}
Err(value) => {
let value = value.to_value(context);
let value = value.to_opaque(context);
context.vm.push(value);
context.vm.frame_mut().generator_resume_kind = GeneratorResumeKind::Throw;
context.run()
Expand Down
16 changes: 8 additions & 8 deletions boa_engine/src/builtins/promise/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use crate::{
property::{Attribute, PropertyDescriptorBuilder},
symbol::WellKnownSymbols,
value::JsValue,
Context, JsResult,
Context, JsError, JsResult,
};
use boa_gc::{Cell as GcCell, Finalize, Gc, Trace};
use boa_profiler::Profiler;
Expand All @@ -39,7 +39,7 @@ macro_rules! if_abrupt_reject_promise {
let $value = match $value {
// 1. If value is an abrupt completion, then
Err(err) => {
let err = err.to_value($context);
let err = err.to_opaque($context);
// a. Perform ? Call(capability.[[Reject]], undefined, « value.[[Value]] »).
$context.call(
&$capability.reject().clone().into(),
Expand Down Expand Up @@ -338,7 +338,7 @@ impl Promise {

// 10. If completion is an abrupt completion, then
if let Err(e) = completion {
let e = e.to_value(context);
let e = e.to_opaque(context);
// a. Perform ? Call(resolvingFunctions.[[Reject]], undefined, « completion.[[Value]] »).
context.call(&resolving_functions.reject, &JsValue::Undefined, &[e])?;
}
Expand Down Expand Up @@ -1064,7 +1064,7 @@ impl Promise {
.expect("cannot fail per spec");

// 3. Return ThrowCompletion(error).
return Err(error.into());
return Err(JsError::from_opaque(error.into()));
}

// iv. Return resultCapability.[[Promise]].
Expand Down Expand Up @@ -1255,14 +1255,14 @@ impl Promise {
// a. Let selfResolutionError be a newly created TypeError object.
let self_resolution_error = JsNativeError::typ()
.with_message("SameValue(resolution, promise) is true")
.to_value(context);
.to_opaque(context);

// b. Perform RejectPromise(promise, selfResolutionError).
promise
.borrow_mut()
.as_promise_mut()
.expect("Expected promise to be a Promise")
.reject_promise(&self_resolution_error, context);
.reject_promise(&self_resolution_error.into(), context);

// c. Return undefined.
return Ok(JsValue::Undefined);
Expand Down Expand Up @@ -1292,7 +1292,7 @@ impl Promise {
.borrow_mut()
.as_promise_mut()
.expect("Expected promise to be a Promise")
.reject_promise(&e.to_value(context), context);
.reject_promise(&e.to_opaque(context), context);

// b. Return undefined.
return Ok(JsValue::Undefined);
Expand Down Expand Up @@ -1834,7 +1834,7 @@ impl Promise {
context,
|_this, _args, captures, _context| {
// 1. Return ThrowCompletion(reason).
Err(captures.reason.clone().into())
Err(JsError::from_opaque(captures.reason.clone()))
},
ThrowReasonCaptures {
reason: reason.clone(),
Expand Down
4 changes: 2 additions & 2 deletions boa_engine/src/builtins/promise/promise_job.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ impl PromiseJob {
// e. Else, let handlerResult be Completion(HostCallJobCallback(handler, undefined, « argument »)).
Some(handler) => handler
.call_job_callback(&JsValue::Undefined, &[argument.clone()], context)
.map_err(|e| e.to_value(context)),
.map_err(|e| e.to_opaque(context)),
};

match promise_capability {
Expand Down Expand Up @@ -146,7 +146,7 @@ impl PromiseJob {

// c. If thenCallResult is an abrupt completion, then
if let Err(value) = then_call_result {
let value = value.to_value(context);
let value = value.to_opaque(context);
// i. Return ? Call(resolvingFunctions.[[Reject]], undefined, « thenCallResult.[[Value]] »).
return context.call(
&resolving_functions.reject,
Expand Down
Loading

0 comments on commit 74baea6

Please sign in to comment.