|
|
@ -19,7 +19,7 @@ impl Operation for SetPrivateField { |
|
|
|
|
|
|
|
|
|
|
|
fn execute(context: &mut Context<'_>) -> JsResult<CompletionType> { |
|
|
|
fn execute(context: &mut Context<'_>) -> JsResult<CompletionType> { |
|
|
|
let index = context.vm.read::<u32>(); |
|
|
|
let index = context.vm.read::<u32>(); |
|
|
|
let name = context.vm.frame().code_block.private_names[index as usize]; |
|
|
|
let name = context.vm.frame().code_block.names[index as usize].clone(); |
|
|
|
let value = context.vm.pop(); |
|
|
|
let value = context.vm.pop(); |
|
|
|
let object = context.vm.pop(); |
|
|
|
let object = context.vm.pop(); |
|
|
|
let base_obj = object.to_object(context)?; |
|
|
|
let base_obj = object.to_object(context)?; |
|
|
@ -27,7 +27,7 @@ impl Operation for SetPrivateField { |
|
|
|
let name = context |
|
|
|
let name = context |
|
|
|
.vm |
|
|
|
.vm |
|
|
|
.environments |
|
|
|
.environments |
|
|
|
.resolve_private_identifier(name.description()) |
|
|
|
.resolve_private_identifier(name) |
|
|
|
.expect("private name must be in environment"); |
|
|
|
.expect("private name must be in environment"); |
|
|
|
|
|
|
|
|
|
|
|
base_obj.private_set(&name, value.clone(), context)?; |
|
|
|
base_obj.private_set(&name, value.clone(), context)?; |
|
|
@ -49,17 +49,16 @@ impl Operation for DefinePrivateField { |
|
|
|
|
|
|
|
|
|
|
|
fn execute(context: &mut Context<'_>) -> JsResult<CompletionType> { |
|
|
|
fn execute(context: &mut Context<'_>) -> JsResult<CompletionType> { |
|
|
|
let index = context.vm.read::<u32>(); |
|
|
|
let index = context.vm.read::<u32>(); |
|
|
|
let name = context.vm.frame().code_block.private_names[index as usize]; |
|
|
|
let name = context.vm.frame().code_block.names[index as usize].clone(); |
|
|
|
let value = context.vm.pop(); |
|
|
|
let value = context.vm.pop(); |
|
|
|
let object = context.vm.pop(); |
|
|
|
let object = context.vm.pop(); |
|
|
|
let object = object |
|
|
|
let object = object |
|
|
|
.as_object() |
|
|
|
.as_object() |
|
|
|
.expect("class prototype must be an object"); |
|
|
|
.expect("class prototype must be an object"); |
|
|
|
|
|
|
|
|
|
|
|
object.borrow_mut().append_private_element( |
|
|
|
object |
|
|
|
object.private_name(name.description()), |
|
|
|
.borrow_mut() |
|
|
|
PrivateElement::Field(value), |
|
|
|
.append_private_element(object.private_name(name), PrivateElement::Field(value)); |
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Ok(CompletionType::Normal) |
|
|
|
Ok(CompletionType::Normal) |
|
|
|
} |
|
|
|
} |
|
|
@ -78,11 +77,11 @@ impl Operation for SetPrivateMethod { |
|
|
|
|
|
|
|
|
|
|
|
fn execute(context: &mut Context<'_>) -> JsResult<CompletionType> { |
|
|
|
fn execute(context: &mut Context<'_>) -> JsResult<CompletionType> { |
|
|
|
let index = context.vm.read::<u32>(); |
|
|
|
let index = context.vm.read::<u32>(); |
|
|
|
let name = context.vm.frame().code_block.private_names[index as usize]; |
|
|
|
let name = context.vm.frame().code_block.names[index as usize].clone(); |
|
|
|
let value = context.vm.pop(); |
|
|
|
let value = context.vm.pop(); |
|
|
|
let value = value.as_callable().expect("method must be callable"); |
|
|
|
let value = value.as_callable().expect("method must be callable"); |
|
|
|
|
|
|
|
|
|
|
|
let name_string = format!("#{}", context.interner().resolve_expect(name.description())); |
|
|
|
let name_string = format!("#{}", name.to_std_string_escaped()); |
|
|
|
let desc = PropertyDescriptor::builder() |
|
|
|
let desc = PropertyDescriptor::builder() |
|
|
|
.value(name_string) |
|
|
|
.value(name_string) |
|
|
|
.writable(false) |
|
|
|
.writable(false) |
|
|
@ -99,7 +98,7 @@ impl Operation for SetPrivateMethod { |
|
|
|
.expect("class prototype must be an object"); |
|
|
|
.expect("class prototype must be an object"); |
|
|
|
|
|
|
|
|
|
|
|
object.borrow_mut().append_private_element( |
|
|
|
object.borrow_mut().append_private_element( |
|
|
|
object.private_name(name.description()), |
|
|
|
object.private_name(name), |
|
|
|
PrivateElement::Method(value.clone()), |
|
|
|
PrivateElement::Method(value.clone()), |
|
|
|
); |
|
|
|
); |
|
|
|
let mut value_mut = value.borrow_mut(); |
|
|
|
let mut value_mut = value.borrow_mut(); |
|
|
@ -125,7 +124,7 @@ impl Operation for SetPrivateSetter { |
|
|
|
|
|
|
|
|
|
|
|
fn execute(context: &mut Context<'_>) -> JsResult<CompletionType> { |
|
|
|
fn execute(context: &mut Context<'_>) -> JsResult<CompletionType> { |
|
|
|
let index = context.vm.read::<u32>(); |
|
|
|
let index = context.vm.read::<u32>(); |
|
|
|
let name = context.vm.frame().code_block.private_names[index as usize]; |
|
|
|
let name = context.vm.frame().code_block.names[index as usize].clone(); |
|
|
|
let value = context.vm.pop(); |
|
|
|
let value = context.vm.pop(); |
|
|
|
let value = value.as_callable().expect("setter must be callable"); |
|
|
|
let value = value.as_callable().expect("setter must be callable"); |
|
|
|
let object = context.vm.pop(); |
|
|
|
let object = context.vm.pop(); |
|
|
@ -134,7 +133,7 @@ impl Operation for SetPrivateSetter { |
|
|
|
.expect("class prototype must be an object"); |
|
|
|
.expect("class prototype must be an object"); |
|
|
|
|
|
|
|
|
|
|
|
object.borrow_mut().append_private_element( |
|
|
|
object.borrow_mut().append_private_element( |
|
|
|
object.private_name(name.description()), |
|
|
|
object.private_name(name), |
|
|
|
PrivateElement::Accessor { |
|
|
|
PrivateElement::Accessor { |
|
|
|
getter: None, |
|
|
|
getter: None, |
|
|
|
setter: Some(value.clone()), |
|
|
|
setter: Some(value.clone()), |
|
|
@ -163,7 +162,7 @@ impl Operation for SetPrivateGetter { |
|
|
|
|
|
|
|
|
|
|
|
fn execute(context: &mut Context<'_>) -> JsResult<CompletionType> { |
|
|
|
fn execute(context: &mut Context<'_>) -> JsResult<CompletionType> { |
|
|
|
let index = context.vm.read::<u32>(); |
|
|
|
let index = context.vm.read::<u32>(); |
|
|
|
let name = context.vm.frame().code_block.private_names[index as usize]; |
|
|
|
let name = context.vm.frame().code_block.names[index as usize].clone(); |
|
|
|
let value = context.vm.pop(); |
|
|
|
let value = context.vm.pop(); |
|
|
|
let value = value.as_callable().expect("getter must be callable"); |
|
|
|
let value = value.as_callable().expect("getter must be callable"); |
|
|
|
let object = context.vm.pop(); |
|
|
|
let object = context.vm.pop(); |
|
|
@ -172,7 +171,7 @@ impl Operation for SetPrivateGetter { |
|
|
|
.expect("class prototype must be an object"); |
|
|
|
.expect("class prototype must be an object"); |
|
|
|
|
|
|
|
|
|
|
|
object.borrow_mut().append_private_element( |
|
|
|
object.borrow_mut().append_private_element( |
|
|
|
object.private_name(name.description()), |
|
|
|
object.private_name(name), |
|
|
|
PrivateElement::Accessor { |
|
|
|
PrivateElement::Accessor { |
|
|
|
getter: Some(value.clone()), |
|
|
|
getter: Some(value.clone()), |
|
|
|
setter: None, |
|
|
|
setter: None, |
|
|
|