Browse Source

Add early errors to dynamic function constructors (#2716)

This Pull Request fixes #2673.

It changes the following:

- Add early errors to dynamic function constructors.
- Add tests that check for syntax errors when `super` is passed to the function constructor.
pull/2721/head
raskad 2 years ago
parent
commit
0e01a74f59
  1. 14
      boa_engine/src/builtins/function/mod.rs
  2. 16
      boa_engine/src/builtins/function/tests.rs

14
boa_engine/src/builtins/function/mod.rs

@ -584,6 +584,20 @@ impl BuiltInFunctionObject {
.into());
}
// It is a Syntax Error if FunctionBody Contains SuperProperty is true.
if contains(&body, ContainsSymbol::SuperProperty) {
return Err(JsNativeError::syntax()
.with_message("invalid `super` reference")
.into());
}
// It is a Syntax Error if FunctionBody Contains SuperCall is true.
if contains(&body, ContainsSymbol::SuperCall) {
return Err(JsNativeError::syntax()
.with_message("invalid `super` call")
.into());
}
// It is a Syntax Error if any element of the BoundNames of FormalParameters
// also occurs in the LexicallyDeclaredNames of FunctionBody.
// https://tc39.es/ecma262/#sec-function-definitions-static-semantics-early-errors

16
boa_engine/src/builtins/function/tests.rs

@ -175,3 +175,19 @@ fn closure_capture_clone() {
TestAction::assert_eq("closure()", "Hello world!"),
]);
}
#[test]
fn function_constructor_early_errors_super() {
run_test_actions([
TestAction::assert_native_error(
"Function('super()')()",
ErrorKind::Syntax,
"invalid `super` call",
),
TestAction::assert_native_error(
"Function('super.a')()",
ErrorKind::Syntax,
"invalid `super` reference",
),
]);
}

Loading…
Cancel
Save