Browse Source

Fix destructuring assignment evaluation order (#3934)

pull/3936/head
raskad 4 months ago committed by GitHub
parent
commit
e205b567be
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 1
      core/engine/src/bytecompiler/declaration/declaration_pattern.rs
  2. 2
      core/engine/src/bytecompiler/declarations.rs
  3. 9
      core/engine/src/vm/opcode/iteration/iterator.rs

1
core/engine/src/bytecompiler/declaration/declaration_pattern.rs

@ -119,6 +119,7 @@ impl ByteCompiler<'_> {
self.emit_opcode(Opcode::Dup); self.emit_opcode(Opcode::Dup);
if let PropertyName::Computed(node) = &name { if let PropertyName::Computed(node) = &name {
self.compile_expr(node, true); self.compile_expr(node, true);
self.emit_opcode(Opcode::ToPropertyKey);
self.emit_opcode(Opcode::Swap); self.emit_opcode(Opcode::Swap);
} }

2
core/engine/src/bytecompiler/declarations.rs

@ -587,7 +587,7 @@ impl ByteCompiler<'_> {
.r#async(r#async) .r#async(r#async)
.strict(self.strict()) .strict(self.strict())
.in_with(self.in_with) .in_with(self.in_with)
.binding_identifier(Some(name.sym().to_js_string(self.interner()))) .binding_identifier(None)
.compile( .compile(
parameters, parameters,
body, body,

9
core/engine/src/vm/opcode/iteration/iterator.rs

@ -2,7 +2,7 @@ use crate::{
builtins::{iterable::create_iter_result_object, Array}, builtins::{iterable::create_iter_result_object, Array},
js_str, js_str,
vm::{opcode::Operation, CompletionType, GeneratorResumeKind}, vm::{opcode::Operation, CompletionType, GeneratorResumeKind},
Context, JsResult, Context, JsResult, JsValue,
}; };
/// `IteratorNext` implements the Opcode Operation for `Opcode::IteratorNext` /// `IteratorNext` implements the Opcode Operation for `Opcode::IteratorNext`
@ -184,7 +184,12 @@ impl Operation for IteratorValueWithoutPop {
.pop() .pop()
.expect("iterator on the call frame must exist"); .expect("iterator on the call frame must exist");
let value = iterator.value(context); let value = if iterator.done() {
Ok(JsValue::undefined())
} else {
iterator.value(context)
};
context.vm.frame_mut().iterators.push(iterator); context.vm.frame_mut().iterators.push(iterator);
context.vm.push(value?); context.vm.push(value?);

Loading…
Cancel
Save