1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #include "mozilla/RefPtr.h"
8 #include "mozilla/Utf8.h"
12 #include "frontend/FrontendContext.h" // js::FrontendContext
13 #include "js/CompileOptions.h"
14 #include "js/experimental/CompileScript.h"
15 #include "js/SourceText.h"
17 #include "jsapi-tests/tests.h"
18 #include "util/NativeStack.h" // js::GetNativeStackBase
22 BEGIN_FRONTEND_TEST(testFrontendContextCompileGlobalScriptToStencil
) {
23 JS::FrontendContext
* fc
= JS::NewFrontendContext();
26 static constexpr JS::NativeStackSize stackSize
= 128 * sizeof(size_t) * 1024;
28 JS::SetNativeStackQuota(fc
, stackSize
);
31 CHECK(fc
->stackLimit() ==
32 JS::GetNativeStackLimit(js::GetNativeStackBase(), stackSize
- 1));
35 JS::PrefableCompileOptions prefableOptions
;
36 JS::CompileOptions
options(prefableOptions
);
39 const char source
[] = "var a = 10;";
41 JS::SourceText
<mozilla::Utf8Unit
> srcBuf
;
43 srcBuf
.init(fc
, source
, strlen(source
), JS::SourceOwnership::Borrowed
));
44 JS::CompilationStorage compileStorage
;
45 RefPtr
<JS::Stencil
> stencil
=
46 JS::CompileGlobalScriptToStencil(fc
, options
, srcBuf
, compileStorage
);
48 CHECK(compileStorage
.hasInput());
52 const char16_t source
[] = u
"var a = 10;";
54 JS::SourceText
<char16_t
> srcBuf
;
55 CHECK(srcBuf
.init(fc
, source
, std::char_traits
<char16_t
>::length(source
),
56 JS::SourceOwnership::Borrowed
));
57 JS::CompilationStorage compileStorage
;
58 RefPtr
<JS::Stencil
> stencil
=
59 JS::CompileGlobalScriptToStencil(fc
, options
, srcBuf
, compileStorage
);
61 CHECK(compileStorage
.hasInput());
64 JS::DestroyFrontendContext(fc
);
69 END_TEST(testFrontendContextCompileGlobalScriptToStencil
)