mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-12-13 18:27:35 +00:00
Bug 1834809 - Add JS::DecodeStencil with JS::FrontendContext. r=nbp
Differential Revision: https://phabricator.services.mozilla.com/D179013
This commit is contained in:
parent
c053846bd3
commit
345e3894a3
@ -206,6 +206,10 @@ extern JS_PUBLIC_API TranscodeResult DecodeStencil(JSContext* cx,
|
||||
const DecodeOptions& options,
|
||||
const TranscodeRange& range,
|
||||
Stencil** stencilOut);
|
||||
extern JS_PUBLIC_API TranscodeResult DecodeStencil(JS::FrontendContext* fc,
|
||||
const DecodeOptions& options,
|
||||
const TranscodeRange& range,
|
||||
Stencil** stencilOut);
|
||||
|
||||
// Register an encoder on its script source, such that all functions can be
|
||||
// encoded as they are delazified.
|
||||
|
@ -5325,16 +5325,23 @@ JS::TranscodeResult JS::DecodeStencil(JSContext* cx,
|
||||
const JS::TranscodeRange& range,
|
||||
JS::Stencil** stencilOut) {
|
||||
AutoReportFrontendContext fc(cx);
|
||||
RefPtr<ScriptSource> source = fc.getAllocator()->new_<ScriptSource>();
|
||||
return JS::DecodeStencil(&fc, options, range, stencilOut);
|
||||
}
|
||||
|
||||
JS::TranscodeResult JS::DecodeStencil(JS::FrontendContext* fc,
|
||||
const JS::DecodeOptions& options,
|
||||
const JS::TranscodeRange& range,
|
||||
JS::Stencil** stencilOut) {
|
||||
RefPtr<ScriptSource> source = fc->getAllocator()->new_<ScriptSource>();
|
||||
if (!source) {
|
||||
return TranscodeResult::Throw;
|
||||
}
|
||||
RefPtr<JS::Stencil> stencil(
|
||||
fc.getAllocator()->new_<CompilationStencil>(source));
|
||||
fc->getAllocator()->new_<CompilationStencil>(source));
|
||||
if (!stencil) {
|
||||
return TranscodeResult::Throw;
|
||||
}
|
||||
XDRStencilDecoder decoder(&fc, range);
|
||||
XDRStencilDecoder decoder(fc, range);
|
||||
XDRResult res = decoder.codeStencil(options, *stencil);
|
||||
if (res.isErr()) {
|
||||
return res.unwrapErr();
|
||||
|
@ -11,6 +11,7 @@
|
||||
|
||||
#include "frontend/CompilationStencil.h"
|
||||
#include "js/CompilationAndEvaluation.h"
|
||||
#include "js/experimental/CompileScript.h"
|
||||
#include "js/experimental/JSStencil.h"
|
||||
#include "js/Modules.h"
|
||||
#include "js/OffThreadScriptCompilation.h"
|
||||
@ -248,6 +249,16 @@ BEGIN_TEST(testStencil_Transcode) {
|
||||
CHECK(res == JS::TranscodeResult::Ok);
|
||||
}
|
||||
|
||||
{
|
||||
JS::FrontendContext* fc = JS::NewFrontendContext();
|
||||
JS::DecodeOptions decodeOptions;
|
||||
JS::TranscodeRange range(buffer.begin(), buffer.length());
|
||||
JS::TranscodeResult res =
|
||||
JS::DecodeStencil(fc, decodeOptions, range, getter_AddRefs(stencil));
|
||||
CHECK(res == JS::TranscodeResult::Ok);
|
||||
JS::DestroyFrontendContext(fc);
|
||||
}
|
||||
|
||||
// Delete the buffer to verify that the decoded stencil has no dependency
|
||||
// to the buffer.
|
||||
memset(buffer.begin(), 0, buffer.length());
|
||||
|
Loading…
Reference in New Issue
Block a user