Skip to content

Commit

Permalink
Use destructuring instead of tuple access
Browse files Browse the repository at this point in the history
  • Loading branch information
raskad committed Jul 4, 2022
1 parent 4977ab7 commit 31b0358
Showing 1 changed file with 14 additions and 14 deletions.
28 changes: 14 additions & 14 deletions boa_engine/src/vm/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2291,28 +2291,28 @@ impl Context {
// 4. Let onFulfilled be CreateBuiltinFunction(fulfilledClosure, 1, "", « »).
let on_fulfilled = FunctionBuilder::closure_with_captures(
self,
|_this, args, captures, context| {
|_this, args, (environment, stack, frame), context| {
// a. Let prevContext be the running execution context.
// b. Suspend prevContext.
// c. Push asyncContext onto the execution context stack; asyncContext is now the running execution context.
// d. Resume the suspended evaluation of asyncContext using NormalCompletion(value) as the result of the operation that suspended it.
// e. Assert: When we reach this step, asyncContext has already been removed from the execution context stack and prevContext is the currently running execution context.
// f. Return undefined.

std::mem::swap(&mut context.realm.environments, &mut captures.0);
std::mem::swap(&mut context.vm.stack, &mut captures.1);
context.vm.push_frame(captures.2.clone());
std::mem::swap(&mut context.realm.environments, environment);
std::mem::swap(&mut context.vm.stack, stack);
context.vm.push_frame(frame.clone());

context.vm.frame_mut().generator_resume_kind = GeneratorResumeKind::Normal;
context.vm.push(args.get_or_undefined(0));
context.run()?;

captures.2 = *context
*frame = *context
.vm
.pop_frame()
.expect("generator call frame must exist");
std::mem::swap(&mut context.realm.environments, &mut captures.0);
std::mem::swap(&mut context.vm.stack, &mut captures.1);
std::mem::swap(&mut context.realm.environments, environment);
std::mem::swap(&mut context.vm.stack, stack);

Ok(JsValue::undefined())
},
Expand All @@ -2330,28 +2330,28 @@ impl Context {
// 6. Let onRejected be CreateBuiltinFunction(rejectedClosure, 1, "", « »).
let on_rejected = FunctionBuilder::closure_with_captures(
self,
|_this, args, captures, context| {
|_this, args, (environment, stack, frame), context| {
// a. Let prevContext be the running execution context.
// b. Suspend prevContext.
// c. Push asyncContext onto the execution context stack; asyncContext is now the running execution context.
// d. Resume the suspended evaluation of asyncContext using ThrowCompletion(reason) as the result of the operation that suspended it.
// e. Assert: When we reach this step, asyncContext has already been removed from the execution context stack and prevContext is the currently running execution context.
// f. Return undefined.

std::mem::swap(&mut context.realm.environments, &mut captures.0);
std::mem::swap(&mut context.vm.stack, &mut captures.1);
context.vm.push_frame(captures.2.clone());
std::mem::swap(&mut context.realm.environments, environment);
std::mem::swap(&mut context.vm.stack, stack);
context.vm.push_frame(frame.clone());

context.vm.frame_mut().generator_resume_kind = GeneratorResumeKind::Throw;
context.vm.push(args.get_or_undefined(0));
context.run()?;

captures.2 = *context
*frame = *context
.vm
.pop_frame()
.expect("generator call frame must exist");
std::mem::swap(&mut context.realm.environments, &mut captures.0);
std::mem::swap(&mut context.vm.stack, &mut captures.1);
std::mem::swap(&mut context.realm.environments, environment);
std::mem::swap(&mut context.vm.stack, stack);

Ok(JsValue::undefined())
},
Expand Down

0 comments on commit 31b0358

Please sign in to comment.