зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1701305 - Add char16_t overload for JS::Stencil API. r=arai
Differential Revision: https://phabricator.services.mozilla.com/D109956
This commit is contained in:
Родитель
a02d2f3656
Коммит
ad4995ae80
|
@ -52,6 +52,9 @@ JS_PUBLIC_API void StencilRelease(Stencil* stencil);
|
|||
extern JS_PUBLIC_API already_AddRefed<Stencil> CompileGlobalScriptToStencil(
|
||||
JSContext* cx, const ReadOnlyCompileOptions& options,
|
||||
SourceText<mozilla::Utf8Unit>& srcBuf);
|
||||
extern JS_PUBLIC_API already_AddRefed<Stencil> CompileGlobalScriptToStencil(
|
||||
JSContext* cx, const ReadOnlyCompileOptions& options,
|
||||
SourceText<char16_t>& srcBuf);
|
||||
|
||||
// Instantiate the Stencil into current Realm and return the JSScript.
|
||||
extern JS_PUBLIC_API JSScript* InstantiateGlobalStencil(
|
||||
|
|
|
@ -3449,9 +3449,10 @@ void JS::StencilRelease(JS::Stencil* stencil) {
|
|||
}
|
||||
}
|
||||
|
||||
already_AddRefed<JS::Stencil> JS::CompileGlobalScriptToStencil(
|
||||
JSContext* cx, const ReadOnlyCompileOptions& options,
|
||||
SourceText<mozilla::Utf8Unit>& srcBuf) {
|
||||
template <typename CharT>
|
||||
static already_AddRefed<JS::Stencil> CompileGlobalScriptToStencilImpl(
|
||||
JSContext* cx, const JS::ReadOnlyCompileOptions& options,
|
||||
JS::SourceText<CharT>& srcBuf) {
|
||||
ScopeKind scopeKind =
|
||||
options.nonSyntacticScope ? ScopeKind::NonSyntactic : ScopeKind::Global;
|
||||
|
||||
|
@ -3466,6 +3467,18 @@ already_AddRefed<JS::Stencil> JS::CompileGlobalScriptToStencil(
|
|||
return do_AddRef(stencil.release());
|
||||
}
|
||||
|
||||
already_AddRefed<JS::Stencil> JS::CompileGlobalScriptToStencil(
|
||||
JSContext* cx, const JS::ReadOnlyCompileOptions& options,
|
||||
JS::SourceText<mozilla::Utf8Unit>& srcBuf) {
|
||||
return CompileGlobalScriptToStencilImpl(cx, options, srcBuf);
|
||||
}
|
||||
|
||||
already_AddRefed<JS::Stencil> JS::CompileGlobalScriptToStencil(
|
||||
JSContext* cx, const JS::ReadOnlyCompileOptions& options,
|
||||
JS::SourceText<char16_t>& srcBuf) {
|
||||
return CompileGlobalScriptToStencilImpl(cx, options, srcBuf);
|
||||
}
|
||||
|
||||
JSScript* JS::InstantiateGlobalStencil(
|
||||
JSContext* cx, const JS::ReadOnlyCompileOptions& options,
|
||||
RefPtr<JS::Stencil> stencil) {
|
||||
|
|
|
@ -18,9 +18,24 @@ BEGIN_TEST(testStencil_Basic) {
|
|||
const char* chars =
|
||||
"function f() { return 42; }"
|
||||
"f();";
|
||||
auto result = basic_test<char, mozilla::Utf8Unit>(chars);
|
||||
CHECK(result);
|
||||
|
||||
JS::SourceText<mozilla::Utf8Unit> srcBuf;
|
||||
CHECK(srcBuf.init(cx, chars, strlen(chars), JS::SourceOwnership::Borrowed));
|
||||
const char16_t* chars16 =
|
||||
u"function f() { return 42; }"
|
||||
u"f();";
|
||||
auto result16 = basic_test<char16_t, char16_t>(chars16);
|
||||
CHECK(result16);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
template <typename CharT, typename SourceT>
|
||||
bool basic_test(const CharT* chars) {
|
||||
size_t length = std::char_traits<CharT>::length(chars);
|
||||
|
||||
JS::SourceText<SourceT> srcBuf;
|
||||
CHECK(srcBuf.init(cx, chars, length, JS::SourceOwnership::Borrowed));
|
||||
|
||||
JS::CompileOptions options(cx);
|
||||
RefPtr<JS::Stencil> stencil =
|
||||
|
|
Загрузка…
Ссылка в новой задаче