Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature get/set $boa.limits.stack #3385

Merged
merged 1 commit into from
Oct 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions boa_cli/src/debug/limits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,22 @@ fn set_loop(_: &JsValue, args: &[JsValue], context: &mut Context<'_>) -> JsResul
Ok(JsValue::undefined())
}

fn get_stack(_: &JsValue, _: &[JsValue], context: &mut Context<'_>) -> JsResult<JsValue> {
let max = context.runtime_limits().stack_size_limit();
Ok(JsValue::from(max))
}

fn set_stack(_: &JsValue, args: &[JsValue], context: &mut Context<'_>) -> JsResult<JsValue> {
let value = args.get_or_undefined(0).to_length(context)?;
let Ok(value) = value.try_into() else {
return Err(JsNativeError::range()
.with_message(format!("Argument {value} greater than usize::MAX"))
.into());
};
context.runtime_limits_mut().set_stack_size_limit(value);
Ok(JsValue::undefined())
}
jedel1043 marked this conversation as resolved.
Show resolved Hide resolved

fn get_recursion(_: &JsValue, _: &[JsValue], context: &mut Context<'_>) -> JsResult<JsValue> {
let max = context.runtime_limits().recursion_limit();
Ok(JsValue::from(max))
Expand Down Expand Up @@ -44,6 +60,17 @@ pub(super) fn create_object(context: &mut Context<'_>) -> JsObject {
.length(1)
.build();

let get_stack =
FunctionObjectBuilder::new(context.realm(), NativeFunction::from_fn_ptr(get_stack))
.name("get stack")
.length(0)
.build();
let set_stack =
FunctionObjectBuilder::new(context.realm(), NativeFunction::from_fn_ptr(set_stack))
.name("set stack")
.length(1)
.build();

let get_recursion =
FunctionObjectBuilder::new(context.realm(), NativeFunction::from_fn_ptr(get_recursion))
.name("get recursion")
Expand All @@ -61,6 +88,12 @@ pub(super) fn create_object(context: &mut Context<'_>) -> JsObject {
Some(set_loop),
Attribute::WRITABLE | Attribute::CONFIGURABLE | Attribute::NON_ENUMERABLE,
)
.accessor(
js_string!("stack"),
Some(get_stack),
Some(set_stack),
Attribute::WRITABLE | Attribute::CONFIGURABLE | Attribute::NON_ENUMERABLE,
)
.accessor(
js_string!("recursion"),
Some(get_recursion),
Expand Down
2 changes: 1 addition & 1 deletion boa_engine/src/vm/runtime_limits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ impl Default for RuntimeLimits {
fn default() -> Self {
Self {
loop_iteration_limit: u64::MAX,
resursion_limit: 400,
resursion_limit: 512,
stack_size_limit: 1024,
}
}
Expand Down
14 changes: 14 additions & 0 deletions docs/boa_object.md
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,20 @@ $boa.limits.loop = 10;
while (true) {} // RuntimeLimit: Maximum loop iteration limit 10 exceeded
```

### Getter & Setter `$boa.limits.stack`

This is an accessor property on the module, its getter returns the value stack limit before an error is thrown.
Its setter can be used to set the recursion limit.

```javascript
$boa.limits.stack = 10;

function x() {
return;
}
x(1, 2, 3, 4, 5, 6, 7, 8, 9, 10); // RuntimeLimit: exceeded maximum call stack length
```

### Getter & Setter `$boa.limits.recursion`

This is an accessor property on the module, its getter returns the recursion limit before an error is thrown.
Expand Down
Loading