Bug 1834483 - Part 11: Add JS::SetNativeStackQuota for JS::FrontendContext. r=bthrall

Differential Revision: https://phabricator.services.mozilla.com/D179012
This commit is contained in:
Tooru Fujisawa 2023-05-31 01:26:46 +00:00
parent ac6e513814
commit c053846bd3
3 changed files with 19 additions and 0 deletions

View File

@ -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.

View File

@ -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) {

View File

@ -9,11 +9,13 @@
#include <string>
#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()));
{