mirror of
https://github.com/fluencelabs/wasm-bindgen
synced 2025-06-12 20:41:24 +00:00
Add support for getters, setters and deleters
This commit is contained in:
@ -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"),
|
||||
}
|
||||
};
|
||||
|
||||
|
Reference in New Issue
Block a user