Bug 1852740: add tests for the `fetchpriority` attribute in Link headers. r=necko...
[gecko.git] / js / src / jsapi-tests / testFrontendCompileStencil.cpp
blobba29b5aea2381ca6f63ca634a35ea112088c6235
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"
10 #include <string>
12 #include "frontend/FrontendContext.h" // js::FrontendContext
13 #include "js/CompileOptions.h"
14 #include "js/experimental/CompileScript.h"
15 #include "js/SourceText.h"
16 #include "js/Stack.h"
17 #include "jsapi-tests/tests.h"
18 #include "util/NativeStack.h" // js::GetNativeStackBase
20 using namespace JS;
22 BEGIN_FRONTEND_TEST(testFrontendContextCompileGlobalScriptToStencil) {
23 JS::FrontendContext* fc = JS::NewFrontendContext();
24 CHECK(fc);
26 static constexpr JS::NativeStackSize stackSize = 128 * sizeof(size_t) * 1024;
28 JS::SetNativeStackQuota(fc, stackSize);
30 #ifndef __wasi__
31 CHECK(fc->stackLimit() ==
32 JS::GetNativeStackLimit(js::GetNativeStackBase(), stackSize - 1));
33 #endif
35 JS::PrefableCompileOptions prefableOptions;
36 JS::CompileOptions options(prefableOptions);
39 const char source[] = "var a = 10;";
41 JS::SourceText<mozilla::Utf8Unit> srcBuf;
42 CHECK(
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);
47 CHECK(stencil);
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);
60 CHECK(stencil);
61 CHECK(compileStorage.hasInput());
64 JS::DestroyFrontendContext(fc);
66 return true;
69 END_TEST(testFrontendContextCompileGlobalScriptToStencil)