diff --git a/js/public/experimental/CompileScript.h b/js/public/experimental/CompileScript.h index 0d419f6ddea7..723ce6a05d15 100644 --- a/js/public/experimental/CompileScript.h +++ b/js/public/experimental/CompileScript.h @@ -33,6 +33,9 @@ JS_PUBLIC_API JS::FrontendContext* NewFrontendContext(); // Destroy a front-end context allocated with NewFrontendContext. JS_PUBLIC_API void DestroyFrontendContext(JS::FrontendContext* fc); +JS_PUBLIC_API void SetNativeStackQuota(JS::FrontendContext* fc, + JS::NativeStackSize stackSize); + /* * Set supported import assertions on a FrontendContext to be used with * CompileModuleScriptToStencil. May only be set once for each FrontendContext. diff --git a/js/src/frontend/CompileScript.cpp b/js/src/frontend/CompileScript.cpp index a7a49c56d539..0c75b40ccb83 100644 --- a/js/src/frontend/CompileScript.cpp +++ b/js/src/frontend/CompileScript.cpp @@ -27,6 +27,11 @@ JS_PUBLIC_API void JS::DestroyFrontendContext(FrontendContext* fc) { return js::DestroyFrontendContext(fc); } +JS_PUBLIC_API void JS::SetNativeStackQuota(JS::FrontendContext* fc, + JS::NativeStackSize stackSize) { + fc->setStackQuota(stackSize); +} + JS_PUBLIC_API bool JS::SetSupportedImportAssertions( FrontendContext* fc, const JS::ImportAssertionVector& supportedImportAssertions) { diff --git a/js/src/jsapi-tests/testFrontendCompileStencil.cpp b/js/src/jsapi-tests/testFrontendCompileStencil.cpp index 616ef3703288..a148ff133a0d 100644 --- a/js/src/jsapi-tests/testFrontendCompileStencil.cpp +++ b/js/src/jsapi-tests/testFrontendCompileStencil.cpp @@ -9,11 +9,13 @@ #include +#include "frontend/FrontendContext.h" // js::FrontendContext #include "js/CompileOptions.h" #include "js/experimental/CompileScript.h" #include "js/SourceText.h" #include "js/Stack.h" #include "jsapi-tests/tests.h" +#include "util/NativeStack.h" // js::GetNativeStackBase using namespace JS; @@ -21,6 +23,15 @@ BEGIN_FRONTEND_TEST(testFrontendContextCompileGlobalScriptToStencil) { JS::FrontendContext* fc = JS::NewFrontendContext(); CHECK(fc); + static constexpr JS::NativeStackSize stackSize = 128 * sizeof(size_t) * 1024; + + JS::SetNativeStackQuota(fc, stackSize); + +#ifndef __wasi__ + CHECK(fc->stackLimit() == + JS::GetNativeStackLimit(js::GetNativeStackBase(), stackSize - 1)); +#endif + JS::CompileOptions options((JS::CompileOptions::ForFrontendContext())); {