Skip to content

Commit 13b9429

Browse files
committed
Overhaul OP whitelist
1 parent 03dd1a4 commit 13b9429

29 files changed

Lines changed: 496 additions & 525 deletions

.github/workflows/op_whitelist.yml

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,19 @@
11
name: Sandbox integrity checks
22
on:
33
push:
4-
branches: [ master ]
4+
branches: [master]
55
pull_request:
6-
branches: [ master ]
6+
branches: [master]
77

88
env:
99
CARGO_TERM_COLOR: always
1010

1111
jobs:
1212
build:
13-
1413
runs-on: ubuntu-latest
1514

1615
steps:
17-
- uses: actions/checkout@v4
16+
- uses: actions/checkout@v4
1817

19-
- name: Run whitelist check for default-feature provided ops
20-
run: cargo test --lib -- test::check_op_whitelist --exact --show-output
18+
- name: Run whitelist check for default-feature provided ops
19+
run: cargo run --example op_whitelist --features op_whitelist

Cargo.toml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,10 @@ snapshot_builder = []
148148
# Enables the threaded worker API
149149
worker = []
150150

151+
# Grants access to op_whitelist::get_whitelist
152+
# Used in CI to prevent vulnerabilities!
153+
op_whitelist = []
154+
151155
#
152156
# End of feature definitions
153157
#
@@ -291,6 +295,10 @@ required-features = ["node_experimental"]
291295
name = "background_tasks"
292296
required-features = ["web"]
293297

298+
[[example]]
299+
name = "op_whitelist"
300+
required-features = ["op_whitelist"]
301+
294302
[[bench]]
295303
name = "runtime"
296304
harness = false

examples/async_eval.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
///
2-
/// This example shows how to use `Runtime::eval` to run async code
3-
/// Note that there is no support for top-level await but you can use `Promise` to work around this
4-
///
1+
//!
2+
//! This example shows how to use `Runtime::eval` to run async code
3+
//! Note that there is no support for top-level await but you can use `Promise` to work around this
4+
//!
55
use rustyscript::{js_value::Promise, Error, Runtime};
66

77
fn main() -> Result<(), Error> {

examples/async_javascript.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
///
2-
/// This example shows the use of async functions in JS
3-
///
4-
/// Here we have a module with 4 async functions that resolve after a given time
5-
/// We call them in sequence and await the results
6-
///
7-
/// Notes:
8-
/// - When using the async variants of the functions it is important to complete the JS event loop with [Runtime::await_event_loop]
9-
/// - Async variants will wait for the function's return value to resolve, but will not wait for the event loop to complete
10-
///
1+
//!
2+
//! This example shows the use of async functions in JS
3+
//!
4+
//! Here we have a module with 4 async functions that resolve after a given time
5+
//! We call them in sequence and await the results
6+
//!
7+
//! Notes:
8+
//! - When using the async variants of the functions it is important to complete the JS event loop with [Runtime::await_event_loop]
9+
//! - Async variants will wait for the function's return value to resolve, but will not wait for the event loop to complete
10+
//!
1111
use rustyscript::{js_value::Promise, json_args, Error, Module, Runtime};
1212

1313
fn main() -> Result<(), Error> {

examples/background_tasks.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1+
//!
2+
//! This example the use of async module loading, and the handing of ongoing
3+
//! background tasks.
4+
//!
15
use std::time::Duration;
26

37
use deno_core::PollEventLoopOptions;
4-
///
5-
/// This example the use of async module loading, and the handing of ongoing
6-
/// background tasks.
7-
///
88
use rustyscript::{Error, Module, ModuleHandle, Runtime, RuntimeOptions};
99

1010
fn main() -> Result<(), Error> {

examples/call_rust_from_js.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
///
2-
/// This example is meant to demonstrate the use of the runtime state, as well as the
3-
/// registration of rust functions that are callable from JS
4-
///
1+
//!
2+
//! This example is meant to demonstrate the use of the runtime state, as well as the
3+
//! registration of rust functions that are callable from JS
4+
//!
55
use rustyscript::{async_callback, serde_json, sync_callback, Error, Module, Runtime};
66

77
fn main() -> Result<(), Error> {

examples/create_snapshot.rs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
1-
///
2-
/// This example demonstrates how to create a snapshot from a module and save it to a file.
3-
/// Snapshots can be used to massively decrease the startup time of a Runtime instance (15ms -> 3ms) by pre-loading
4-
/// extensions and modules into the runtime state before it is created. A snapshot can be used on any runtime with
5-
/// the same set of extensions and options as the runtime that created it.
6-
///
7-
use rustyscript::{Error, Module, SnapshotBuilder};
1+
//!
2+
//! This example demonstrates how to create a snapshot from a module and save it to a file.
3+
//! Snapshots can be used to massively decrease the startup time of a Runtime instance (15ms -> 3ms) by pre-loading
4+
//! extensions and modules into the runtime state before it is created. A snapshot can be used on any runtime with
5+
//! the same set of extensions and options as the runtime that created it.
6+
//!
87
use std::fs;
98

9+
use rustyscript::{Error, Module, SnapshotBuilder};
10+
1011
fn main() -> Result<(), Error> {
1112
// A module we want pre-loaded into the snapshot
1213
let module = Module::new(

examples/custom_runtimes.rs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
1-
///
2-
/// This example demonstrates extending Runtime to inline your own extensions and modules
3-
/// as well as enforce values for the Runtime's options
4-
///
5-
/// This example creates a runtime which will timeout after 0.5s, imports an exension,
6-
/// And ensures that a preset module is always available for import.
7-
///
8-
/// Extensions like the one being used (see examples/ext/example_extension.rs)
9-
/// allow you to call rust code from within JS
10-
///
11-
/// Extensions consist of a set of #[op2] functions, an extension! macro,
12-
/// and one or more optional JS modules.
13-
///
1+
//!
2+
//! This example demonstrates extending Runtime to inline your own extensions and modules
3+
//! as well as enforce values for the Runtime's options
4+
//!
5+
//! This example creates a runtime which will timeout after 0.5s, imports an exension,
6+
//! And ensures that a preset module is always available for import.
7+
//!
8+
//! Extensions like the one being used (see examples/ext/example_extension.rs)
9+
//! allow you to call rust code from within JS
10+
//!
11+
//! Extensions consist of a set of #[op2] functions, an extension! macro,
12+
//! and one or more optional JS modules.
13+
//!
1414
use rustyscript::{module, Error, Module, ModuleHandle, Runtime, RuntimeOptions};
1515
use std::time::Duration;
1616

examples/custom_threaded_worker.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1+
//!
2+
//! This example shows how to use the threaded worker feature using a custom implementation of a worker
3+
//! We will create a basic worker implementation able to execute snippets of non-emca JS
4+
//!
15
use deno_core::serde_json;
2-
///
3-
/// This example shows how to use the threaded worker feature using a custom implementation of a worker
4-
/// We will create a basic worker implementation able to execute snippets of non-emca JS
5-
///
66
use rustyscript::{
77
worker::{InnerWorker, Worker},
88
Error, Runtime,

examples/default_threaded_worker.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
///
2-
/// This example shows how to use the threaded worker feature using the default worker implementation
3-
/// In this example we load a module, and execute a function from it
4-
///
1+
//!
2+
//! This example shows how to use the threaded worker feature using the default worker implementation
3+
//! In this example we load a module, and execute a function from it
4+
//!
55
use rustyscript::{worker::DefaultWorker, Error, Module};
66

77
fn main() -> Result<(), Error> {

0 commit comments

Comments
 (0)