-
-
Notifications
You must be signed in to change notification settings - Fork 630
Expand file tree
/
Copy pathmod.rs
More file actions
98 lines (85 loc) · 2.94 KB
/
mod.rs
File metadata and controls
98 lines (85 loc) · 2.94 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
use super::{IndexOperand, RegisterOperand};
use crate::{Context, JsResult, JsValue, vm::opcode::Operation};
pub(crate) mod class;
pub(crate) mod own_property;
pub(crate) use class::*;
pub(crate) use own_property::*;
/// `DefVar` implements the Opcode Operation for `Opcode::DefVar`
///
/// Operation:
/// - Declare `var` type variable.
#[derive(Debug, Clone, Copy)]
pub(crate) struct DefVar;
impl DefVar {
#[inline(always)]
pub(super) fn operation(index: IndexOperand, context: &mut Context) -> JsResult<()> {
// TODO: spec specifies to return `empty` on empty vars, but we're trying to initialize.
let binding_locator = context.vm.frame().code_block.bindings[usize::from(index)].clone();
context
.vm
.frame_mut()
.environments
.put_value_if_uninitialized(
binding_locator.scope(),
binding_locator.binding_index(),
JsValue::undefined(),
)
}
}
impl Operation for DefVar {
const NAME: &'static str = "DefVar";
const INSTRUCTION: &'static str = "INST - DefVar";
const COST: u8 = 3;
}
/// `DefInitVar` implements the Opcode Operation for `Opcode::DefInitVar`
///
/// Operation:
/// - Declare and initialize a function argument.
#[derive(Debug, Clone, Copy)]
pub(crate) struct DefInitVar;
impl DefInitVar {
#[inline(always)]
pub(super) fn operation(
(value, index): (RegisterOperand, IndexOperand),
context: &mut Context,
) -> JsResult<()> {
let value = context.vm.get_register(value.into()).clone();
let frame = context.vm.frame();
let strict = frame.code_block.strict();
let mut binding_locator = frame.code_block.bindings[usize::from(index)].clone();
context.find_runtime_binding(&mut binding_locator)?;
context.set_binding(&binding_locator, value.clone(), strict)?;
Ok(())
}
}
impl Operation for DefInitVar {
const NAME: &'static str = "DefInitVar";
const INSTRUCTION: &'static str = "INST - DefInitVar";
const COST: u8 = 3;
}
/// `PutLexicalValue` implements the Opcode Operation for `Opcode::PutLexicalValue`
///
/// Operation:
/// - Initialize a lexical binding.
#[derive(Debug, Clone, Copy)]
pub(crate) struct PutLexicalValue;
impl PutLexicalValue {
#[inline(always)]
pub(super) fn operation(
(value, index): (RegisterOperand, IndexOperand),
context: &mut Context,
) -> JsResult<()> {
let value = context.vm.get_register(value.into()).clone();
let binding_locator = context.vm.frame().code_block.bindings[usize::from(index)].clone();
context.vm.frame_mut().environments.put_lexical_value(
binding_locator.scope(),
binding_locator.binding_index(),
value,
)
}
}
impl Operation for PutLexicalValue {
const NAME: &'static str = "PutLexicalValue";
const INSTRUCTION: &'static str = "INST - PutLexicalValue";
const COST: u8 = 3;
}