Add support for getters, setters and deleters

This commit is contained in:
Anton Danilkin
2018-08-05 23:32:31 +03:00
parent b4601295d0
commit fd2b2140a9
7 changed files with 213 additions and 44 deletions

View File

@ -1869,18 +1869,6 @@ impl<'a, 'b> SubContext<'a, 'b> {
let location = if *is_static { &class } else { "this" };
match kind {
shared::OperationKind::Getter(g) => format!(
"function() {{
return {}.{};
}}",
location, g
),
shared::OperationKind::Setter(s) => format!(
"function(y) {{
{}.{} = y;
}}",
location, s
),
shared::OperationKind::Regular => {
let nargs = descriptor.unwrap_function().arguments.len();
let mut s = format!("function(");
@ -1902,11 +1890,44 @@ impl<'a, 'b> SubContext<'a, 'b> {
s.push_str(");\n}");
s
}
shared::OperationKind::Getter(g) => format!(
"function() {{
return {}.{};
}}",
location, g
),
shared::OperationKind::Setter(s) => format!(
"function(y) {{
{}.{} = y;
}}",
location, s
),
shared::OperationKind::SpecialGetter => format!(
"function(y) {{
return {}[y];
}}",
location
),
shared::OperationKind::SpecialSetter => format!(
"function(y, z) {{
{}[y] = z;
}}",
location
),
shared::OperationKind::SpecialDeleter => format!(
"function(y) {{
delete {}[y];
}}",
location
),
}
} else {
let location = if *is_static { "" } else { ".prototype" };
match kind {
shared::OperationKind::Regular => {
format!("{}{}.{}", class, location, import.function.name)
}
shared::OperationKind::Getter(g) => {
self.cx.expose_get_inherited_descriptor();
format!(
@ -1921,9 +1942,9 @@ impl<'a, 'b> SubContext<'a, 'b> {
class, location, s,
)
}
shared::OperationKind::Regular => {
format!("{}{}.{}", class, location, import.function.name)
}
shared::OperationKind::SpecialGetter => panic!("getter should be structural"),
shared::OperationKind::SpecialSetter => panic!("setter should be structural"),
shared::OperationKind::SpecialDeleter => panic!("deleter should be structural"),
}
};