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 { } else {
let location = if *is_static { "" } else { ".prototype" }; let (location, binding) = if *is_static {
("", format!(".bind({})", class))
} else {
(".prototype", "".into())
};
match kind { match kind {
shared::OperationKind::Regular => { shared::OperationKind::Regular => {
format!("{}{}.{}", class, location, import.function.name) format!("{}{}.{}{}", class, location, import.function.name, binding)
} }
shared::OperationKind::Getter(g) => { shared::OperationKind::Getter(g) => {
self.cx.expose_get_inherited_descriptor(); self.cx.expose_get_inherited_descriptor();
format!( format!(
"GetOwnOrInheritedPropertyDescriptor({}{}, '{}').get", "GetOwnOrInheritedPropertyDescriptor({}{}, '{}').get{}",
class, location, g, class, location, g, binding,
) )
} }
shared::OperationKind::Setter(s) => { shared::OperationKind::Setter(s) => {
self.cx.expose_get_inherited_descriptor(); self.cx.expose_get_inherited_descriptor();
format!( format!(
"GetOwnOrInheritedPropertyDescriptor({}{}, '{}').set", "GetOwnOrInheritedPropertyDescriptor({}{}, '{}').set{}",
class, location, s, class, location, s, binding,
) )
} }
shared::OperationKind::IndexingGetter => panic!("indexing getter should be structural"), shared::OperationKind::IndexingGetter => panic!("indexing getter should be structural"),