-
-
Notifications
You must be signed in to change notification settings - Fork 411
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement runtime limits for loops (#2857)
- Loading branch information
Showing
37 changed files
with
620 additions
and
214 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
use boa_engine::{ | ||
object::{FunctionObjectBuilder, ObjectInitializer}, | ||
property::Attribute, | ||
Context, JsArgs, JsObject, JsResult, JsValue, NativeFunction, | ||
}; | ||
|
||
fn get_loop(_: &JsValue, _: &[JsValue], context: &mut Context<'_>) -> JsResult<JsValue> { | ||
let max = context.runtime_limits().loop_iteration_limit(); | ||
Ok(JsValue::from(max)) | ||
} | ||
|
||
fn set_loop(_: &JsValue, args: &[JsValue], context: &mut Context<'_>) -> JsResult<JsValue> { | ||
let value = args.get_or_undefined(0).to_length(context)?; | ||
context.runtime_limits_mut().set_loop_iteration_limit(value); | ||
Ok(JsValue::undefined()) | ||
} | ||
|
||
pub(super) fn create_object(context: &mut Context<'_>) -> JsObject { | ||
let get_loop = FunctionObjectBuilder::new(context, NativeFunction::from_fn_ptr(get_loop)) | ||
.name("get loop") | ||
.length(0) | ||
.build(); | ||
let set_loop = FunctionObjectBuilder::new(context, NativeFunction::from_fn_ptr(set_loop)) | ||
.name("set loop") | ||
.length(1) | ||
.build(); | ||
ObjectInitializer::new(context) | ||
.accessor( | ||
"loop", | ||
Some(get_loop), | ||
Some(set_loop), | ||
Attribute::WRITABLE | Attribute::CONFIGURABLE | Attribute::NON_ENUMERABLE, | ||
) | ||
.build() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.