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

fix: stack overflow of mockjs #183

Merged
merged 3 commits into from
May 17, 2022
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
51 changes: 51 additions & 0 deletions crates/rspack/fixtures/stack_overflow_mockjs/foo.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
(function (module, exports) {
var parser = (function () {
function u(n) {
function q() {
return (
null === n &&
((n = D()),
null === n &&
((n = Y()),
null === n &&
((n = H()),
null === n &&
((n = O()),
null === n &&
((n = W()),
null === n &&
((n = z()),
null === n &&
((n = I()),
null === n &&
((n = J()),
null === n &&
((n = K()),
null === n &&
((n = N()),
null === n &&
((n = P()),
null === n &&
((n = V()),
null === n &&
((n = X()),
null === n &&
((n = Z()),
null === n &&
((n = _()),
null === n &&
((n = nl()),
null === n &&
((n = ll()),
null === n &&
((n = ul()),
null === n &&
(n = tl()))))))))))))))))))),
n
);
}
}
})();

module.exports = parser;
});
1 change: 1 addition & 0 deletions crates/rspack/fixtures/stack_overflow_mockjs/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import "./foo";
2 changes: 2 additions & 0 deletions crates/rspack/src/bundler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ use tracing::instrument;
use crate::chunk_spliter::ChunkSpliter;
use crate::utils::inject_built_in_plugins;
use crate::utils::log::enable_tracing_by_env;
use crate::utils::rayon::init_rayon_thread_poll;
use rspack_core::get_swc_compiler;
pub use rspack_core::hmr::hmr_module;
use rspack_core::Plugin;
Expand Down Expand Up @@ -51,6 +52,7 @@ pub struct Bundler {
impl Bundler {
pub fn new(options: BundleOptions, plugins: Vec<Box<dyn Plugin>>) -> Self {
enable_tracing_by_env();
init_rayon_thread_poll();
println!(
"create bundler with options:\n {:#?} \nplugins:\n {:#?}\n",
options, plugins
Expand Down
1 change: 1 addition & 0 deletions crates/rspack/src/utils/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use rspack_core::{BundleOptions, NormalizedBundleOptions, Plugin};
use rspack_plugin_css::plugin::CssSourcePlugin;

pub mod log;
pub mod rayon;

pub fn inject_built_in_plugins(
mut user_plugins: Vec<Box<dyn Plugin>>,
Expand Down
11 changes: 11 additions & 0 deletions crates/rspack/src/utils/rayon.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
use once_cell::sync::OnceCell;

pub fn init_rayon_thread_poll() -> () {
static INSTANCE: OnceCell<()> = OnceCell::new();
INSTANCE.get_or_init(|| {
rayon::ThreadPoolBuilder::new()
.stack_size(16777216)
.build_global()
.unwrap()
});
}
6 changes: 6 additions & 0 deletions crates/rspack/tests/fixture.rs
Original file line number Diff line number Diff line change
Expand Up @@ -277,4 +277,10 @@ mod testing {
assert!(source.contains("ok.js"));
assert!(source.contains("at.js"));
}

#[test]

fn stack_overflow_mockjs() {
compile("stack_overflow_mockjs", vec![]);
}
}
2 changes: 1 addition & 1 deletion crates/rspack_plugin_mock_buitins/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ impl Plugin for MockBuitinsPlugin {
}

async fn load(&self, _ctx: &BundleContext, id: &str) -> PluginLoadHookOutput {
if is_builtin_module(id) || id.contains("mockjs") {
if is_builtin_module(id) {
Some(LoadedSource {
loader: Some(Loader::Null),
content: Some(String::new()),
Expand Down