Bug 722345 part 3 - Remove request API. r=luke

Differential Revision: https://phabricator.services.mozilla.com/D4424

--HG--
extra : rebase_source : 1842588c00dbc8fb4294ce5436cdb787190909b4
This commit is contained in:
Jan de Mooij 2018-08-28 09:53:30 +02:00
parent d2d2258af8
commit cbb67627a3
29 changed files with 6 additions and 149 deletions

View File

@ -46,8 +46,6 @@ struct DevTools : public ::testing::Test {
if (!cx)
return;
JS_BeginRequest(cx);
global.init(cx, createGlobal());
if (!global)
return;
@ -111,8 +109,6 @@ struct DevTools : public ::testing::Test {
JS::LeaveRealm(cx, nullptr);
global = nullptr;
}
if (cx)
JS_EndRequest(cx);
}
};

View File

@ -1,7 +1,7 @@
#include "WindowDestroyedEvent.h"
#include "nsJSUtils.h"
#include "jsapi.h" // for JSAutoRequest
#include "jsapi.h"
#include "js/Wrapper.h"
#include "nsIPrincipal.h"
#include "nsISupportsPrimitives.h"

View File

@ -69,7 +69,7 @@
// Helper Classes
#include "nsJSUtils.h"
#include "jsapi.h" // for JSAutoRequest
#include "jsapi.h"
#include "js/Wrapper.h"
#include "nsCharSeparatedTokenizer.h"
#include "nsReadableUtils.h"

View File

@ -66,7 +66,7 @@
// Helper Classes
#include "nsJSUtils.h"
#include "jsapi.h" // for JSAutoRequest
#include "jsapi.h"
#include "js/Wrapper.h"
#include "nsCharSeparatedTokenizer.h"
#include "nsReadableUtils.h"

View File

@ -1150,8 +1150,6 @@ IDBObjectStore::DeserializeValue(JSContext* aCx,
MOZ_ASSERT(!(aCloneReadInfo.mData.Size() % sizeof(uint64_t)));
JSAutoRequest ar(aCx);
static const JSStructuredCloneCallbacks callbacks = {
CommonStructuredCloneReadCallback,
nullptr,

View File

@ -322,11 +322,6 @@ AutoJSAPI::~AutoJSAPI()
JS::SetWarningReporter(cx(), mOldWarningReporter.value());
}
// Leave the request before popping.
if (mIsMainThread) {
mAutoRequest.reset();
}
ScriptSettingsStack::Pop(this);
}
@ -349,12 +344,6 @@ AutoJSAPI::InitInternal(nsIGlobalObject* aGlobalObject, JSObject* aGlobal,
mCx = aCx;
mIsMainThread = aIsMainThread;
mGlobalObject = aGlobalObject;
if (aIsMainThread) {
// We _could_ just unconditionally emplace mAutoRequest here. It's just not
// needed on worker threads, and we're hoping to kill it on the main thread
// too.
mAutoRequest.emplace(mCx);
}
if (aGlobal) {
JS::ExposeObjectToActiveJS(aGlobal);
}

View File

@ -186,7 +186,6 @@ private:
* previously entered compartment for that JSContext is not used by mistake.
* * Reporting any exceptions left on the JSRuntime, unless the caller steals
* or silences them.
* * On main thread, entering a JSAutoRequest.
*
* Additionally, the following duties are planned, but not yet implemented:
*
@ -295,7 +294,6 @@ protected:
// AutoJSAPI, so Init must NOT be called on subclasses that use this.
AutoJSAPI(nsIGlobalObject* aGlobalObject, bool aIsMainThread, Type aType);
mozilla::Maybe<JSAutoRequest> mAutoRequest;
mozilla::Maybe<JSAutoNullableRealm> mAutoNullableRealm;
JSContext *mCx;

View File

@ -2756,12 +2756,9 @@ WorkerThreadPrimaryRunnable::Run()
PROFILER_SET_JS_CONTEXT(cx);
{
JSAutoRequest ar(cx);
mWorkerPrivate->DoRunLoop(cx);
// The AutoJSAPI in DoRunLoop should have reported any exceptions left
// on cx. Note that we still need the JSAutoRequest above because
// AutoJSAPI on workers does NOT enter a request!
// on cx.
MOZ_ASSERT(!JS_IsExceptionPending(cx));
}

View File

@ -382,7 +382,6 @@ ExecutionRunnable::RunOnWorkletThread()
MOZ_ASSERT(workletThread);
JSContext* cx = workletThread->GetJSContext();
JSAutoRequest areq(cx);
AutoJSAPI jsapi;
jsapi.Init();

View File

@ -334,7 +334,6 @@ nsXBLProtoImpl::ResolveAllFields(JSContext *cx, JS::Handle<JSObject*> obj) const
void
nsXBLProtoImpl::UndefineFields(JSContext *cx, JS::Handle<JSObject*> obj) const
{
JSAutoRequest ar(cx);
for (nsXBLProtoImplField* f = mFields; f; f = f->GetNext()) {
nsDependentString name(f->GetName());

View File

@ -1002,7 +1002,6 @@ Proxy::HandleEvent(Event* aEvent)
{
AutoSafeJSContext cx;
JSAutoRequest ar(cx);
JS::Rooted<JS::Value> value(cx);
if (!GetOrCreateDOMReflectorNoWrap(cx, mXHR, &value)) {
@ -1446,7 +1445,6 @@ SendRunnable::RunOnMainThread(ErrorResult& aRv)
if (HasData()) {
AutoSafeJSContext cx;
JSAutoRequest ar(cx);
JS::Rooted<JSObject*> globalObject(cx, JS::CurrentGlobalOrNull(cx));
if (NS_WARN_IF(!globalObject)) {

View File

@ -307,7 +307,6 @@ const WHITELIST_FUNCTIONS: &'static [&'static str] = &[
"JS::InitSelfHostedCode",
"JS::IsConstructor",
"JS::IsPromiseObject",
"JS_BeginRequest",
"JS_ClearPendingException",
"JS_DefineElement",
"JS_DefineFunction",
@ -321,7 +320,6 @@ const WHITELIST_FUNCTIONS: &'static [&'static str] = &[
"JS::DisableIncrementalGC",
"js::Dump.*",
"JS_EncodeStringToUTF8",
"JS_EndRequest",
"JS::EnterRealm",
"JS_EnumerateStandardClasses",
"JS_ErrorFromException",

View File

@ -196,8 +196,6 @@ impl Runtime {
JS::SetWarningReporter(js_context, Some(report_warning));
JS_BeginRequest(js_context);
Ok(Runtime {
cx: js_context,
})
@ -256,7 +254,6 @@ impl Runtime {
impl Drop for Runtime {
fn drop(&mut self) {
unsafe {
JS_EndRequest(self.cx);
JS_DestroyContext(self.cx);
CONTEXT.with(|context| {

View File

@ -76,7 +76,6 @@ jsfuzz_init(JSContext** cx, JS::PersistentRootedObject* global)
js::UseInternalJobQueues(*cx);
if (!JS::InitSelfHostedCode(*cx))
return false;
JS_BeginRequest(*cx);
global->init(*cx);
*global = jsfuzz_createGlobal(*cx, nullptr);
if (!*global)
@ -89,7 +88,6 @@ static void
jsfuzz_uninit(JSContext* cx)
{
if (cx) {
JS_EndRequest(cx);
JS_DestroyContext(cx);
cx = nullptr;
}

View File

@ -82,8 +82,6 @@ main(int argc, const char** argv)
checkBool(JS::InitSelfHostedCode(cx));
JS::SetWarningReporter(cx, reportWarning);
JSAutoRequest areq(cx);
/* Create the global object. */
JS::RealmOptions options;
RootedObject global(cx, checkPtr(JS_NewGlobalObject(cx, &global_class,

View File

@ -22,7 +22,6 @@ bool JSAPITest::init()
js::UseInternalJobQueues(cx);
if (!JS::InitSelfHostedCode(cx))
return false;
JS_BeginRequest(cx);
global.init(cx);
createGlobal();
if (!global)
@ -38,7 +37,6 @@ void JSAPITest::uninit()
global = nullptr;
}
if (cx) {
JS_EndRequest(cx);
destroyContext();
cx = nullptr;
}

View File

@ -531,47 +531,6 @@ JS_SetFutexCanWait(JSContext* cx)
cx->fx.setCanWait(true);
}
static void
StartRequest(JSContext* cx)
{
MOZ_ASSERT(CurrentThreadCanAccessRuntime(cx->runtime()));
if (cx->requestDepth) {
cx->requestDepth++;
} else {
/* Indicate that a request is running. */
cx->requestDepth = 1;
}
}
static void
StopRequest(JSContext* cx)
{
MOZ_ASSERT(CurrentThreadCanAccessRuntime(cx->runtime()));
MOZ_ASSERT(cx->requestDepth != 0);
if (cx->requestDepth != 1) {
cx->requestDepth--;
} else {
cx->requestDepth = 0;
}
}
JS_PUBLIC_API(void)
JS_BeginRequest(JSContext* cx)
{
cx->outstandingRequests++;
StartRequest(cx);
}
JS_PUBLIC_API(void)
JS_EndRequest(JSContext* cx)
{
MOZ_ASSERT(cx->outstandingRequests != 0);
cx->outstandingRequests--;
StopRequest(cx);
}
JS_PUBLIC_API(JSRuntime*)
JS_GetParentRuntime(JSContext* cx)
{
@ -600,7 +559,6 @@ JS::InitSelfHostedCode(JSContext* cx)
JSRuntime* rt = cx->runtime();
JSAutoRequest ar(cx);
if (!rt->initializeAtoms(cx))
return false;
@ -1592,7 +1550,7 @@ JS_PUBLIC_API(void)
JS_SetNativeStackQuota(JSContext* cx, size_t systemCodeStackSize, size_t trustedScriptStackSize,
size_t untrustedScriptStackSize)
{
MOZ_ASSERT(cx->requestDepth == 0);
MOZ_ASSERT(!cx->activation());
if (!trustedScriptStackSize)
trustedScriptStackSize = systemCodeStackSize;

View File

@ -467,12 +467,6 @@ JS_GetParentRuntime(JSContext* cx);
extern JS_PUBLIC_API(JSRuntime*)
JS_GetRuntime(JSContext* cx);
extern JS_PUBLIC_API(void)
JS_BeginRequest(JSContext* cx);
extern JS_PUBLIC_API(void)
JS_EndRequest(JSContext* cx);
extern JS_PUBLIC_API(void)
JS_SetFutexCanWait(JSContext* cx);
@ -483,31 +477,6 @@ AssertHeapIsIdle();
} /* namespace js */
class MOZ_RAII JSAutoRequest
{
public:
explicit JSAutoRequest(JSContext* cx
MOZ_GUARD_OBJECT_NOTIFIER_PARAM)
: mContext(cx)
{
MOZ_GUARD_OBJECT_NOTIFIER_INIT;
JS_BeginRequest(mContext);
}
~JSAutoRequest() {
JS_EndRequest(mContext);
}
protected:
JSContext* mContext;
MOZ_DECL_USE_GUARD_OBJECT_NOTIFIER
#if 0
private:
static void* operator new(size_t) CPP_THROW_NEW { return 0; }
static void operator delete(void*, size_t) { }
#endif
};
namespace JS {
class JS_PUBLIC_API(ContextOptions) {

View File

@ -3649,8 +3649,6 @@ WorkerMain(WorkerInput* input)
EnvironmentPreparer environmentPreparer(cx);
do {
JSAutoRequest areq(cx);
JS::RealmOptions compartmentOptions;
SetStandardRealmOptions(compartmentOptions);
@ -9474,8 +9472,6 @@ Shell(JSContext* cx, OptionParser* op, char** envp)
if (op->getBoolOption("no-cgc"))
nocgc.emplace(cx);
JSAutoRequest areq(cx);
if (op->getBoolOption("fuzzing-safe"))
fuzzingSafe = true;
else

View File

@ -194,9 +194,6 @@ js::DestroyContext(JSContext* cx)
{
JS_AbortIfWrongThread(cx);
if (cx->outstandingRequests != 0)
MOZ_CRASH("Attempted to destroy a context while it is in a request.");
cx->checkNoGCRooters();
// Cancel all off thread Ion compiles. Completed Ion compiles may try to
@ -1269,7 +1266,6 @@ JSContext::JSContext(JSRuntime* runtime, const JS::ContextOptions& options)
nativeStackBase(GetNativeStackBase()),
entryMonitor(nullptr),
noExecuteDebuggerTop(nullptr),
requestDepth(0),
#ifdef DEBUG
inUnsafeCallWithABI(false),
hasAutoUnsafeCallWithABI(false),
@ -1316,7 +1312,6 @@ JSContext::JSContext(JSRuntime* runtime, const JS::ContextOptions& options)
generatingError(false),
cycleDetectorVector_(this),
data(nullptr),
outstandingRequests(0),
jitIsBroken(false),
asyncCauseForNewActivations(nullptr),
asyncCallIsExplicit(false),

View File

@ -470,9 +470,6 @@ struct JSContext : public JS::RootingContext,
*/
js::ThreadData<js::EnterDebuggeeNoExecute*> noExecuteDebuggerTop;
/* The request depth for this thread. */
js::ThreadData<unsigned> requestDepth;
#ifdef DEBUG
js::ThreadData<uint32_t> inUnsafeCallWithABI;
js::ThreadData<bool> hasAutoUnsafeCallWithABI;
@ -707,9 +704,6 @@ struct JSContext : public JS::RootingContext,
return runtime_ == rt;
}
// Number of JS_BeginRequest calls without the corresponding JS_EndRequest.
js::ThreadData<unsigned> outstandingRequests;
js::ThreadData<bool> jitIsBroken;
void updateJITEnabled();

View File

@ -404,7 +404,6 @@ JSRuntime::addSizeOfIncludingThis(mozilla::MallocSizeOf mallocSizeOf, JS::Runtim
static bool
HandleInterrupt(JSContext* cx, bool invokeCallback)
{
MOZ_ASSERT(cx->requestDepth >= 1);
MOZ_ASSERT(!cx->zone()->isAtomsZone());
// Interrupts can occur at different points between recording and replay,

View File

@ -2678,7 +2678,6 @@ js::PrintTypes(JSContext* cx, Compartment* comp, bool force)
{
#ifdef DEBUG
gc::AutoSuppressGC suppressGC(cx);
JSAutoRequest request(cx);
Zone* zone = comp->zone();
AutoEnterAnalysis enter(nullptr, zone);

View File

@ -27,8 +27,7 @@ XPCCallContext::XPCCallContext(JSContext* cx,
unsigned argc /* = NO_ARGS */,
Value* argv /* = nullptr */,
Value* rval /* = nullptr */)
: mAr(cx),
mState(INIT_FAILED),
: mState(INIT_FAILED),
mXPC(nsXPConnect::XPConnect()),
mXPCJSContext(nullptr),
mJSContext(cx),

View File

@ -3014,8 +3014,6 @@ XPCJSRuntime::Initialize(JSContext* cx)
bool
XPCJSRuntime::InitializeStrings(JSContext* cx)
{
JSAutoRequest ar(cx);
// if it is our first context then we need to generate our string ids
if (JSID_IS_VOID(mStrIDs[0])) {
RootedString str(cx);
@ -3227,7 +3225,6 @@ XPCJSRuntime::InitSingletonScopes()
{
// This all happens very early, so we don't bother with cx pushing.
JSContext* cx = XPCJSContext::Get()->Context();
JSAutoRequest ar(cx);
RootedValue v(cx);
nsresult rv;

View File

@ -45,7 +45,6 @@ bool AutoScriptEvaluate::StartEvaluating(HandleObject scope)
mEvaluated = true;
JS_BeginRequest(mJSContext);
mAutoRealm.emplace(mJSContext, scope);
// Saving the exception state keeps us from interfering with another script
@ -64,8 +63,6 @@ AutoScriptEvaluate::~AutoScriptEvaluate()
if (!mJSContext || !mEvaluated)
return;
mState->restore();
JS_EndRequest(mJSContext);
}
// It turns out that some errors may be not worth reporting. So, this

View File

@ -772,7 +772,6 @@ inline void CHECK_STATE(int s) const {MOZ_ASSERT(mState >= s, "bad state");}
#endif
private:
JSAutoRequest mAr;
State mState;
RefPtr<nsXPConnect> mXPC;

View File

@ -662,8 +662,6 @@ private:
return NS_ERROR_OUT_OF_MEMORY;
}
JSAutoRequest areq(mContext);
JS::RealmOptions options;
options.creationOptions().setNewCompartmentInSystemZone();
mGlobal = JS_NewGlobalObject(mContext, &sGlobalClass, nullptr,
@ -750,7 +748,6 @@ ProxyAutoConfig::SetupJS()
return NS_ERROR_FAILURE;
JSContext* cx = mJSContext->Context();
JSAutoRequest areq(cx);
JSAutoRealm ar(cx, mJSContext->Global());
AutoPACErrorReporter aper(cx);
@ -810,7 +807,6 @@ ProxyAutoConfig::GetProxyForURI(const nsCString &aTestURI,
return NS_ERROR_NOT_AVAILABLE;
JSContext *cx = mJSContext->Context();
JSAutoRequest areq(cx);
JSAutoRealm ar(cx, mJSContext->Global());
AutoPACErrorReporter aper(cx);

View File

@ -130,9 +130,5 @@ TEST(GCPostBarriers, nsTArray) {
JSContext* cx = ccjscx->Context();
ASSERT_TRUE(cx != nullptr);
JS_BeginRequest(cx);
CreateGlobalAndRunTest(cx);
JS_EndRequest(cx);
}