Always bind static operations to their class

For example, `Promise.resolve` must always be called with the `Promise`
constructor as its `this`, or else it will throw an error.
This commit is contained in:
Nick Fitzgerald 2018-08-09 16:17:34 -07:00
parent 96ad97a9f9
commit f9ac4e9c90

View File

@ -1868,24 +1868,28 @@ impl<'a, 'b> SubContext<'a, 'b> {
),
}
} else {
let location = if *is_static { "" } else { ".prototype" };
let (location, binding) = if *is_static {
("", format!(".bind({})", class))
} else {
(".prototype", "".into())
};
match kind {
shared::OperationKind::Regular => {
format!("{}{}.{}", class, location, import.function.name)
format!("{}{}.{}{}", class, location, import.function.name, binding)
}
shared::OperationKind::Getter(g) => {
self.cx.expose_get_inherited_descriptor();
format!(
"GetOwnOrInheritedPropertyDescriptor({}{}, '{}').get",
class, location, g,
"GetOwnOrInheritedPropertyDescriptor({}{}, '{}').get{}",
class, location, g, binding,
)
}
shared::OperationKind::Setter(s) => {
self.cx.expose_get_inherited_descriptor();
format!(
"GetOwnOrInheritedPropertyDescriptor({}{}, '{}').set",
class, location, s,
"GetOwnOrInheritedPropertyDescriptor({}{}, '{}').set{}",
class, location, s, binding,
)
}
shared::OperationKind::IndexingGetter => panic!("indexing getter should be structural"),