mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-25 13:51:41 +00:00
Bug 1486577 - Move script/function transcoding API into a new public js/Transcoding.h header. r=jandem
--HG-- extra : rebase_source : a0daf7931594e418b1a97ec48a3667d3dc74ff95
This commit is contained in:
parent
da612e85ea
commit
f90686816a
100
js/public/Transcoding.h
Normal file
100
js/public/Transcoding.h
Normal file
@ -0,0 +1,100 @@
|
||||
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
/*
|
||||
* Structures and functions for transcoding compiled scripts and functions to
|
||||
* and from memory.
|
||||
*/
|
||||
|
||||
#ifndef js_Transcoding_h
|
||||
#define js_Transcoding_h
|
||||
|
||||
#include "mozilla/Range.h" // mozilla::Range
|
||||
#include "mozilla/Vector.h" // mozilla::Vector
|
||||
|
||||
#include <stddef.h> // size_t
|
||||
#include <stdint.h> // uint8_t, uint32_t
|
||||
|
||||
#include "js/RootingAPI.h" // JS::Handle, JS::MutableHandle
|
||||
|
||||
struct JSContext;
|
||||
class JSFunction;
|
||||
class JSObject;
|
||||
class JSScript;
|
||||
|
||||
namespace JS {
|
||||
|
||||
using TranscodeBuffer = mozilla::Vector<uint8_t>;
|
||||
using TranscodeRange = mozilla::Range<uint8_t>;
|
||||
|
||||
struct TranscodeSource final
|
||||
{
|
||||
TranscodeSource(const TranscodeRange& range_, const char* file, uint32_t line)
|
||||
: range(range_), filename(file), lineno(line)
|
||||
{}
|
||||
|
||||
const TranscodeRange range;
|
||||
const char* filename;
|
||||
const uint32_t lineno;
|
||||
};
|
||||
|
||||
using TranscodeSources = mozilla::Vector<TranscodeSource>;
|
||||
|
||||
enum TranscodeResult : uint8_t
|
||||
{
|
||||
// Successful encoding / decoding.
|
||||
TranscodeResult_Ok = 0,
|
||||
|
||||
// A warning message, is set to the message out-param.
|
||||
TranscodeResult_Failure = 0x10,
|
||||
TranscodeResult_Failure_BadBuildId = TranscodeResult_Failure | 0x1,
|
||||
TranscodeResult_Failure_RunOnceNotSupported = TranscodeResult_Failure | 0x2,
|
||||
TranscodeResult_Failure_AsmJSNotSupported = TranscodeResult_Failure | 0x3,
|
||||
TranscodeResult_Failure_BadDecode = TranscodeResult_Failure | 0x4,
|
||||
TranscodeResult_Failure_WrongCompileOption = TranscodeResult_Failure | 0x5,
|
||||
TranscodeResult_Failure_NotInterpretedFun = TranscodeResult_Failure | 0x6,
|
||||
|
||||
// There is a pending exception on the context.
|
||||
TranscodeResult_Throw = 0x20
|
||||
};
|
||||
|
||||
extern JS_PUBLIC_API(TranscodeResult)
|
||||
EncodeScript(JSContext* cx, TranscodeBuffer& buffer, Handle<JSScript*> script);
|
||||
|
||||
extern JS_PUBLIC_API(TranscodeResult)
|
||||
EncodeInterpretedFunction(JSContext* cx, TranscodeBuffer& buffer, Handle<JSObject*> funobj);
|
||||
|
||||
extern JS_PUBLIC_API(TranscodeResult)
|
||||
DecodeScript(JSContext* cx, TranscodeBuffer& buffer, MutableHandle<JSScript*> scriptp,
|
||||
size_t cursorIndex = 0);
|
||||
|
||||
extern JS_PUBLIC_API(TranscodeResult)
|
||||
DecodeScript(JSContext* cx, const TranscodeRange& range, MutableHandle<JSScript*> scriptp);
|
||||
|
||||
extern JS_PUBLIC_API(TranscodeResult)
|
||||
DecodeInterpretedFunction(JSContext* cx, TranscodeBuffer& buffer, MutableHandle<JSFunction*> funp,
|
||||
size_t cursorIndex = 0);
|
||||
|
||||
// Register an encoder on the given script source, such that all functions can
|
||||
// be encoded as they are parsed. This strategy is used to avoid blocking the
|
||||
// main thread in a non-interruptible way.
|
||||
//
|
||||
// The |script| argument of |StartIncrementalEncoding| and
|
||||
// |FinishIncrementalEncoding| should be the top-level script returned either as
|
||||
// an out-param of any of the |Compile| functions, or the result of
|
||||
// |FinishOffThreadScript|.
|
||||
//
|
||||
// The |buffer| argument of |FinishIncrementalEncoding| is used for appending
|
||||
// the encoded bytecode into the buffer. If any of these functions failed, the
|
||||
// content of |buffer| would be undefined.
|
||||
extern JS_PUBLIC_API(bool)
|
||||
StartIncrementalEncoding(JSContext* cx, Handle<JSScript*> script);
|
||||
|
||||
extern JS_PUBLIC_API(bool)
|
||||
FinishIncrementalEncoding(JSContext* cx, Handle<JSScript*> script, TranscodeBuffer& buffer);
|
||||
|
||||
} // namespace JS
|
||||
|
||||
#endif /* js_Transcoding_h */
|
@ -41,6 +41,7 @@
|
||||
#include "js/SourceBufferHolder.h"
|
||||
#include "js/Stream.h"
|
||||
#include "js/TracingAPI.h"
|
||||
#include "js/Transcoding.h"
|
||||
#include "js/UniquePtr.h"
|
||||
#include "js/Utility.h"
|
||||
#include "js/Value.h"
|
||||
@ -300,12 +301,6 @@ JS_NumberValue(double d)
|
||||
JS_PUBLIC_API(bool)
|
||||
JS_StringHasBeenPinned(JSContext* cx, JSString* str);
|
||||
|
||||
namespace JS {
|
||||
|
||||
struct TranscodeSource;
|
||||
|
||||
} /* namespace JS */
|
||||
|
||||
/************************************************************************/
|
||||
|
||||
/* Property attributes, set in JSPropertySpec and passed to API functions.
|
||||
@ -4843,79 +4838,6 @@ class MOZ_RAII AutoHideScriptedCaller
|
||||
MOZ_DECL_USE_GUARD_OBJECT_NOTIFIER
|
||||
};
|
||||
|
||||
/*
|
||||
* Encode/Decode interpreted scripts and functions to/from memory.
|
||||
*/
|
||||
|
||||
typedef mozilla::Vector<uint8_t> TranscodeBuffer;
|
||||
typedef mozilla::Range<uint8_t> TranscodeRange;
|
||||
|
||||
struct TranscodeSource
|
||||
{
|
||||
TranscodeSource(const TranscodeRange& range_, const char* file, uint32_t line)
|
||||
: range(range_), filename(file), lineno(line)
|
||||
{}
|
||||
|
||||
const TranscodeRange range;
|
||||
const char* filename;
|
||||
const uint32_t lineno;
|
||||
};
|
||||
|
||||
typedef mozilla::Vector<JS::TranscodeSource> TranscodeSources;
|
||||
|
||||
enum TranscodeResult: uint8_t
|
||||
{
|
||||
// Successful encoding / decoding.
|
||||
TranscodeResult_Ok = 0,
|
||||
|
||||
// A warning message, is set to the message out-param.
|
||||
TranscodeResult_Failure = 0x10,
|
||||
TranscodeResult_Failure_BadBuildId = TranscodeResult_Failure | 0x1,
|
||||
TranscodeResult_Failure_RunOnceNotSupported = TranscodeResult_Failure | 0x2,
|
||||
TranscodeResult_Failure_AsmJSNotSupported = TranscodeResult_Failure | 0x3,
|
||||
TranscodeResult_Failure_BadDecode = TranscodeResult_Failure | 0x4,
|
||||
TranscodeResult_Failure_WrongCompileOption = TranscodeResult_Failure | 0x5,
|
||||
TranscodeResult_Failure_NotInterpretedFun = TranscodeResult_Failure | 0x6,
|
||||
|
||||
// There is a pending exception on the context.
|
||||
TranscodeResult_Throw = 0x20
|
||||
};
|
||||
|
||||
extern JS_PUBLIC_API(TranscodeResult)
|
||||
EncodeScript(JSContext* cx, TranscodeBuffer& buffer, JS::HandleScript script);
|
||||
|
||||
extern JS_PUBLIC_API(TranscodeResult)
|
||||
EncodeInterpretedFunction(JSContext* cx, TranscodeBuffer& buffer, JS::HandleObject funobj);
|
||||
|
||||
extern JS_PUBLIC_API(TranscodeResult)
|
||||
DecodeScript(JSContext* cx, TranscodeBuffer& buffer, JS::MutableHandleScript scriptp,
|
||||
size_t cursorIndex = 0);
|
||||
|
||||
extern JS_PUBLIC_API(TranscodeResult)
|
||||
DecodeScript(JSContext* cx, const TranscodeRange& range, JS::MutableHandleScript scriptp);
|
||||
|
||||
extern JS_PUBLIC_API(TranscodeResult)
|
||||
DecodeInterpretedFunction(JSContext* cx, TranscodeBuffer& buffer, JS::MutableHandleFunction funp,
|
||||
size_t cursorIndex = 0);
|
||||
|
||||
// Register an encoder on the given script source, such that all functions can
|
||||
// be encoded as they are parsed. This strategy is used to avoid blocking the
|
||||
// main thread in a non-interruptible way.
|
||||
//
|
||||
// The |script| argument of |StartIncrementalEncoding| and
|
||||
// |FinishIncrementalEncoding| should be the top-level script returned either as
|
||||
// an out-param of any of the |Compile| functions, or the result of
|
||||
// |FinishOffThreadScript|.
|
||||
//
|
||||
// The |buffer| argument of |FinishIncrementalEncoding| is used for appending
|
||||
// the encoded bytecode into the buffer. If any of these functions failed, the
|
||||
// content of |buffer| would be undefined.
|
||||
extern JS_PUBLIC_API(bool)
|
||||
StartIncrementalEncoding(JSContext* cx, JS::HandleScript script);
|
||||
|
||||
extern JS_PUBLIC_API(bool)
|
||||
FinishIncrementalEncoding(JSContext* cx, JS::HandleScript script, TranscodeBuffer& buffer);
|
||||
|
||||
} /* namespace JS */
|
||||
|
||||
namespace js {
|
||||
|
@ -169,6 +169,7 @@ EXPORTS.js += [
|
||||
'../public/TraceKind.h',
|
||||
'../public/TracingAPI.h',
|
||||
'../public/TrackedOptimizationInfo.h',
|
||||
'../public/Transcoding.h',
|
||||
'../public/TypeDecls.h',
|
||||
'../public/UbiNode.h',
|
||||
'../public/UbiNodeBreadthFirst.h',
|
||||
|
@ -14,6 +14,7 @@
|
||||
#include "jsfriendapi.h"
|
||||
#include "NamespaceImports.h"
|
||||
|
||||
#include "js/Transcoding.h"
|
||||
#include "js/TypeDecls.h"
|
||||
#include "vm/JSAtom.h"
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user