mirror of
https://repo.dactyloidae.xyz/Dactyloidae/UXP.git
synced 2026-09-28 11:27:32 +09:00
Issue #1691 - Part 7f: Split up compile and execute so we can use ClassicScript. https://bugzilla.mozilla.org/show_bug.cgi?id=1342012 Refactor nsJSUtils::ExecutionContext to separate compilation and execution steps and allow extraction of compiled JSScript. https://bugzilla.mozilla.org/show_bug.cgi?id=1366773 Move buffer argument from JS::StartIncrementalEncoding to JS::FinishIncrementalEncoding.
(cherry picked from commit d4b520b08b958e116dfeeffdc61f3425610d1ce9)
This commit is contained in:
parent
993476283d
commit
c69a47c393
10 changed files with 154 additions and 125 deletions
|
|
@ -76,6 +76,9 @@ public:
|
|||
// Scope chain in which the execution takes place.
|
||||
JS::AutoObjectVector mScopeChain;
|
||||
|
||||
// The compiled script.
|
||||
JS::Rooted<JSScript*> mScript;
|
||||
|
||||
// returned value forwarded when we have to interupt the execution eagerly
|
||||
// with mSkip.
|
||||
nsresult mRv;
|
||||
|
|
@ -92,6 +95,8 @@ public:
|
|||
bool mWantsReturnValue;
|
||||
|
||||
bool mExpectScopeChain;
|
||||
|
||||
bool mScriptUsed;
|
||||
#endif
|
||||
|
||||
public:
|
||||
|
|
@ -105,8 +110,12 @@ public:
|
|||
ExecutionContext(ExecutionContext&&) = delete;
|
||||
|
||||
~ExecutionContext() {
|
||||
// This flag is resetted, when the returned value is extracted.
|
||||
MOZ_ASSERT(!mWantsReturnValue);
|
||||
// This flag is reset when the returned value is extracted.
|
||||
MOZ_ASSERT_IF(!mSkip, !mWantsReturnValue);
|
||||
|
||||
// If encoding was started we expect the script to have been
|
||||
// used when ending the encoding.
|
||||
MOZ_ASSERT_IF(mEncodeBytecode && mScript && mRv == NS_OK, mScriptUsed);
|
||||
}
|
||||
|
||||
// The returned value would be converted to a string if the
|
||||
|
|
@ -119,10 +128,41 @@ public:
|
|||
// Set the scope chain in which the code should be executed.
|
||||
void SetScopeChain(const JS::AutoObjectVector& aScopeChain);
|
||||
|
||||
// Copy the returned value in the mutable handle argument, in case of a
|
||||
// After getting a notification that an off-thread compilation terminated,
|
||||
// this function will take the result of the parser and move it to the main
|
||||
// thread.
|
||||
MOZ_MUST_USE nsresult JoinCompile(void** aOffThreadToken);
|
||||
|
||||
// Compile a script contained in a SourceText.
|
||||
nsresult Compile(JS::CompileOptions& aCompileOptions,
|
||||
JS::SourceBufferHolder& aSrcBuf);
|
||||
|
||||
// Compile a script contained in a string.
|
||||
nsresult Compile(JS::CompileOptions& aCompileOptions,
|
||||
const nsAString& aScript);
|
||||
|
||||
// Decode a script contained in a buffer.
|
||||
nsresult Decode(JS::CompileOptions& aCompileOptions,
|
||||
mozilla::Vector<uint8_t>& aBytecodeBuf,
|
||||
size_t aBytecodeIndex);
|
||||
|
||||
// After getting a notification that an off-thread decoding terminated, this
|
||||
// function will get the result of the decoder and move it to the main
|
||||
// thread.
|
||||
nsresult JoinDecode(void** aOffThreadToken);
|
||||
|
||||
// Get a successfully compiled script.
|
||||
JSScript* GetScript();
|
||||
|
||||
// Execute the compiled script and ignore the return value.
|
||||
MOZ_MUST_USE nsresult ExecScript();
|
||||
|
||||
// Execute the compiled script a get the return value.
|
||||
//
|
||||
// Copy the returned value into the mutable handle argument. In case of a
|
||||
// evaluation failure either during the execution or the conversion of the
|
||||
// result to a string, the nsresult would be set to the corresponding result
|
||||
// code, and the mutable handle argument would remain unchanged.
|
||||
// result to a string, the nsresult is be set to the corresponding result
|
||||
// code and the mutable handle argument remains unchanged.
|
||||
//
|
||||
// The value returned in the mutable handle argument is part of the
|
||||
// compartment given as argument to the ExecutionContext constructor. If the
|
||||
|
|
@ -131,37 +171,7 @@ public:
|
|||
MOZ_MUST_USE nsresult
|
||||
ExtractReturnValue(JS::MutableHandle<JS::Value> aRetValue);
|
||||
|
||||
// After getting a notification that an off-thread compilation terminated,
|
||||
// this function will take the result of the parser by moving it to the main
|
||||
// thread before starting the execution of the script.
|
||||
//
|
||||
// The compiled script would be returned in the |aScript| out-param.
|
||||
MOZ_MUST_USE nsresult JoinAndExec(void **aOffThreadToken,
|
||||
JS::MutableHandle<JSScript*> aScript);
|
||||
|
||||
// Compile a script contained in a SourceBuffer, and execute it.
|
||||
nsresult CompileAndExec(JS::CompileOptions& aCompileOptions,
|
||||
JS::SourceBufferHolder& aSrcBuf);
|
||||
|
||||
// Compile a script contained in a string, and execute it.
|
||||
nsresult CompileAndExec(JS::CompileOptions& aCompileOptions,
|
||||
const nsAString& aScript);
|
||||
|
||||
// Decode a script contained in a buffer, and execute it.
|
||||
MOZ_MUST_USE nsresult DecodeAndExec(JS::CompileOptions& aCompileOptions,
|
||||
mozilla::Vector<uint8_t>& aBytecodeBuf,
|
||||
size_t aBytecodeIndex);
|
||||
|
||||
// After getting a notification that an off-thread decoding terminated, this
|
||||
// function will get the result of the decoder by moving it to the main
|
||||
// thread before starting the execution of the script.
|
||||
MOZ_MUST_USE nsresult DecodeJoinAndExec(void **aOffThreadToken);
|
||||
|
||||
// Similar to JoinAndExec, except that in addition to fecthing the source,
|
||||
// we register the fact that we plan to encode its bytecode later.
|
||||
MOZ_MUST_USE nsresult JoinEncodeAndExec(void **aOffThreadToken,
|
||||
mozilla::Vector<uint8_t>& aBytecodeBuf,
|
||||
JS::MutableHandle<JSScript*> aScript);
|
||||
MOZ_MUST_USE nsresult ExecScript(JS::MutableHandle<JS::Value> aRetValue);
|
||||
};
|
||||
|
||||
struct MOZ_STACK_CLASS EvaluateOptions {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue