From 9867e421342001aa5129ba28648d4285f093c3fa Mon Sep 17 00:00:00 2001 From: Seth Fowler Date: Wed, 13 Aug 2014 15:42:00 -0700 Subject: [PATCH] Bug 913586 (Part 6) - Update Maybe users in js. r=luke --HG-- extra : rebase_source : c5d23a7874de49e61b43f79b8eda744db0523c6e --- .../autoconfig/src/nsJSConfigTriggers.cpp | 12 ++-- js/src/asmjs/AsmJSFrameIterator.cpp | 8 +-- js/src/asmjs/AsmJSValidate.cpp | 8 +-- js/src/frontend/BytecodeCompiler.cpp | 52 +++++++------- js/src/gc/Zone.h | 20 +++--- js/src/irregexp/RegExpEngine.cpp | 10 +-- js/src/jit/CodeGenerator.cpp | 24 +++---- js/src/jit/IonMacroAssembler.h | 14 ++-- js/src/jit/MIR.cpp | 14 ++-- js/src/jit/shared/CodeGenerator-shared.cpp | 4 +- js/src/jsgc.cpp | 4 +- js/src/json.cpp | 6 +- js/src/jsproxy.cpp | 10 +-- js/src/jswrapper.cpp | 12 ++-- js/src/jswrapper.h | 8 +-- js/src/shell/js.cpp | 31 ++++---- js/src/vm/Debugger.cpp | 70 +++++++++---------- js/src/vm/HelperThreads.cpp | 21 +++--- js/src/vm/RegExpObject.cpp | 6 +- js/src/vm/Shape-inl.h | 2 +- js/xpconnect/loader/mozJSComponentLoader.cpp | 8 +-- js/xpconnect/src/ExportHelpers.cpp | 2 +- js/xpconnect/src/XPCComponents.cpp | 2 +- js/xpconnect/src/XPCJSRuntime.cpp | 6 +- js/xpconnect/src/XPCShellImpl.cpp | 14 ++-- js/xpconnect/src/XPCWrappedJSClass.cpp | 6 +- js/xpconnect/src/XPCWrappedNative.cpp | 4 +- js/xpconnect/src/nsCxPusher.cpp | 22 +++--- js/xpconnect/src/xpcprivate.h | 13 ++-- js/xpconnect/wrappers/XrayWrapper.cpp | 2 +- 30 files changed, 206 insertions(+), 209 deletions(-) diff --git a/extensions/pref/autoconfig/src/nsJSConfigTriggers.cpp b/extensions/pref/autoconfig/src/nsJSConfigTriggers.cpp index 03bd530ad96..99287dad61e 100644 --- a/extensions/pref/autoconfig/src/nsJSConfigTriggers.cpp +++ b/extensions/pref/autoconfig/src/nsJSConfigTriggers.cpp @@ -36,7 +36,7 @@ nsresult CentralizedAdminPrefManagerInit() nsresult rv; // If the sandbox is already created, no need to create it again. - if (!autoconfigSb.empty()) + if (autoconfigSb) return NS_OK; // Grab XPConnect. @@ -58,16 +58,16 @@ nsresult CentralizedAdminPrefManagerInit() // Unwrap, store and root the sandbox. NS_ENSURE_STATE(sandbox->GetJSObject()); - autoconfigSb.construct(cx, js::UncheckedUnwrap(sandbox->GetJSObject())); + autoconfigSb.emplace(cx, js::UncheckedUnwrap(sandbox->GetJSObject())); return NS_OK; } nsresult CentralizedAdminPrefManagerFinish() { - if (!autoconfigSb.empty()) { + if (autoconfigSb) { AutoSafeJSContext cx; - autoconfigSb.destroy(); + autoconfigSb.reset(); JS_MaybeGC(cx); } return NS_OK; @@ -108,12 +108,12 @@ nsresult EvaluateAdminConfigScript(const char *js_buffer, size_t length, } AutoSafeJSContext cx; - JSAutoCompartment ac(cx, autoconfigSb.ref()); + JSAutoCompartment ac(cx, *autoconfigSb); nsAutoCString script(js_buffer, length); JS::RootedValue v(cx); rv = xpc->EvalInSandboxObject(NS_ConvertASCIItoUTF16(script), filename, cx, - autoconfigSb.ref(), &v); + *autoconfigSb, &v); NS_ENSURE_SUCCESS(rv, rv); return NS_OK; diff --git a/js/src/asmjs/AsmJSFrameIterator.cpp b/js/src/asmjs/AsmJSFrameIterator.cpp index 70e8d254d50..3b8e20cdb31 100644 --- a/js/src/asmjs/AsmJSFrameIterator.cpp +++ b/js/src/asmjs/AsmJSFrameIterator.cpp @@ -271,9 +271,9 @@ js::GenerateAsmJSFunctionPrologue(MacroAssembler &masm, unsigned framePushed, // Overflow checks are omitted by CodeGenerator in some cases (leaf // functions with small framePushed). Perform overflow-checking after // pushing framePushed to catch cases with really large frames. - if (!labels->overflowThunk.empty()) { + if (labels->overflowThunk) { // If framePushed is zero, we don't need a thunk to adjust StackPointer. - Label *target = framePushed ? labels->overflowThunk.addr() : &labels->overflowExit; + Label *target = framePushed ? labels->overflowThunk.ptr() : &labels->overflowExit; masm.branchPtr(Assembler::AboveOrEqual, AsmJSAbsoluteAddress(AsmJSImm_StackLimit), StackPointer, @@ -330,11 +330,11 @@ js::GenerateAsmJSFunctionEpilogue(MacroAssembler &masm, unsigned framePushed, masm.bind(&labels->profilingEpilogue); GenerateProfilingEpilogue(masm, framePushed, AsmJSExit::None, &labels->profilingReturn); - if (!labels->overflowThunk.empty() && labels->overflowThunk.ref().used()) { + if (labels->overflowThunk && labels->overflowThunk->used()) { // The general throw stub assumes that only sizeof(AsmJSFrame) bytes // have been pushed. The overflow check occurs after incrementing by // framePushed, so pop that before jumping to the overflow exit. - masm.bind(labels->overflowThunk.addr()); + masm.bind(labels->overflowThunk.ptr()); masm.addPtr(Imm32(framePushed), StackPointer); masm.jump(&labels->overflowExit); } diff --git a/js/src/asmjs/AsmJSValidate.cpp b/js/src/asmjs/AsmJSValidate.cpp index bf735a45e4d..4cb1341ffa5 100644 --- a/js/src/asmjs/AsmJSValidate.cpp +++ b/js/src/asmjs/AsmJSValidate.cpp @@ -1959,7 +1959,7 @@ class FunctionCompiler JS_ASSERT(locals_.count() == argTypes.length() + varInitializers_.length()); alloc_ = lifo_.new_(&lifo_); - ionContext_.construct(m_.cx(), alloc_); + ionContext_.emplace(m_.cx(), alloc_); graph_ = lifo_.new_(alloc_); info_ = lifo_.new_(locals_.count(), SequentialExecution); @@ -1995,15 +1995,15 @@ class FunctionCompiler /******************************* For consistency of returns in a function */ bool hasAlreadyReturned() const { - return !alreadyReturned_.empty(); + return alreadyReturned_.isSome(); } RetType returnedType() const { - return alreadyReturned_.ref(); + return *alreadyReturned_; } void setReturnedType(RetType retType) { - alreadyReturned_.construct(retType); + alreadyReturned_.emplace(retType); } /************************* Read-only interface (after local scope setup) */ diff --git a/js/src/frontend/BytecodeCompiler.cpp b/js/src/frontend/BytecodeCompiler.cpp index 2c29a13918b..f6cd3f71800 100644 --- a/js/src/frontend/BytecodeCompiler.cpp +++ b/js/src/frontend/BytecodeCompiler.cpp @@ -260,15 +260,15 @@ frontend::CompileScript(ExclusiveContext *cx, LifoAlloc *alloc, HandleObject sco Maybe > syntaxParser; if (canLazilyParse) { - syntaxParser.construct(cx, alloc, options, srcBuf.get(), srcBuf.length(), - /* foldConstants = */ false, - (Parser *) nullptr, - (LazyScript *) nullptr); + syntaxParser.emplace(cx, alloc, options, srcBuf.get(), srcBuf.length(), + /* foldConstants = */ false, + (Parser *) nullptr, + (LazyScript *) nullptr); } Parser parser(cx, alloc, options, srcBuf.get(), srcBuf.length(), /* foldConstants = */ true, - canLazilyParse ? &syntaxParser.ref() : nullptr, nullptr); + canLazilyParse ? syntaxParser.ptr() : nullptr, nullptr); parser.sct = sct; parser.ss = ss; @@ -301,10 +301,10 @@ frontend::CompileScript(ExclusiveContext *cx, LifoAlloc *alloc, HandleObject sco // reset when this occurs. Maybe > pc; - pc.construct(&parser, (GenericParseContext *) nullptr, (ParseNode *) nullptr, &globalsc, - (Directives *) nullptr, staticLevel, /* bodyid = */ 0, - /* blockScopeDepth = */ 0); - if (!pc.ref().init(parser.tokenStream)) + pc.emplace(&parser, (GenericParseContext *) nullptr, (ParseNode *) nullptr, &globalsc, + (Directives *) nullptr, staticLevel, /* bodyid = */ 0, + /* blockScopeDepth = */ 0); + if (!pc->init(parser.tokenStream)) return nullptr; /* If this is a direct call to eval, inherit the caller's strictness. */ @@ -331,7 +331,7 @@ frontend::CompileScript(ExclusiveContext *cx, LifoAlloc *alloc, HandleObject sco */ JSFunction *fun = evalCaller->functionOrCallerFunction(); Directives directives(/* strict = */ fun->strict()); - ObjectBox *funbox = parser.newFunctionBox(/* fn = */ nullptr, fun, pc.addr(), + ObjectBox *funbox = parser.newFunctionBox(/* fn = */ nullptr, fun, pc.ptr(), directives, fun->generatorKind()); if (!funbox) return nullptr; @@ -365,16 +365,16 @@ frontend::CompileScript(ExclusiveContext *cx, LifoAlloc *alloc, HandleObject sco // Destroying the parse context will destroy its free // variables, so check if any deoptimization is needed. - if (!MaybeCheckEvalFreeVariables(cx, evalCaller, scopeChain, parser, pc.ref())) + if (!MaybeCheckEvalFreeVariables(cx, evalCaller, scopeChain, parser, *pc)) return nullptr; - pc.destroy(); - pc.construct(&parser, (GenericParseContext *) nullptr, (ParseNode *) nullptr, - &globalsc, (Directives *) nullptr, staticLevel, /* bodyid = */ 0, - script->bindings.numBlockScoped()); - if (!pc.ref().init(parser.tokenStream)) + pc.reset(); + pc.emplace(&parser, (GenericParseContext *) nullptr, (ParseNode *) nullptr, + &globalsc, (Directives *) nullptr, staticLevel, /* bodyid = */ 0, + script->bindings.numBlockScoped()); + if (!pc->init(parser.tokenStream)) return nullptr; - JS_ASSERT(parser.pc == pc.addr()); + JS_ASSERT(parser.pc == pc.ptr()); pn = parser.statement(); } @@ -387,7 +387,7 @@ frontend::CompileScript(ExclusiveContext *cx, LifoAlloc *alloc, HandleObject sco // Accumulate the maximum block scope depth, so that EmitTree can assert // when emitting JSOP_GETLOCAL that the local is indeed within the fixed // part of the stack frame. - script->bindings.updateNumBlockScoped(pc.ref().blockScopeDepth); + script->bindings.updateNumBlockScoped(pc->blockScopeDepth); if (canHaveDirectives) { if (!parser.maybeParseDirective(/* stmtList = */ nullptr, pn, &canHaveDirectives)) @@ -406,7 +406,7 @@ frontend::CompileScript(ExclusiveContext *cx, LifoAlloc *alloc, HandleObject sco parser.handler.freeTree(pn); } - if (!MaybeCheckEvalFreeVariables(cx, evalCaller, scopeChain, parser, pc.ref())) + if (!MaybeCheckEvalFreeVariables(cx, evalCaller, scopeChain, parser, *pc)) return nullptr; if (!SetDisplayURL(cx, parser.tokenStream, ss)) @@ -437,7 +437,7 @@ frontend::CompileScript(ExclusiveContext *cx, LifoAlloc *alloc, HandleObject sco // frame. InternalHandle bindings(script, &script->bindings); if (!Bindings::initWithTemporaryStorage(cx, bindings, 0, 0, nullptr, - pc.ref().blockScopeDepth)) + pc->blockScopeDepth)) return nullptr; if (!JSScript::fullyInitFromEmitter(cx, script, &bce)) @@ -555,11 +555,11 @@ CompileFunctionBody(JSContext *cx, MutableHandleFunction fun, const ReadOnlyComp Maybe > syntaxParser; if (canLazilyParse) { - syntaxParser.construct(cx, &cx->tempLifoAlloc(), - options, srcBuf.get(), srcBuf.length(), - /* foldConstants = */ false, - (Parser *) nullptr, - (LazyScript *) nullptr); + syntaxParser.emplace(cx, &cx->tempLifoAlloc(), + options, srcBuf.get(), srcBuf.length(), + /* foldConstants = */ false, + (Parser *) nullptr, + (LazyScript *) nullptr); } JS_ASSERT(!options.forEval); @@ -567,7 +567,7 @@ CompileFunctionBody(JSContext *cx, MutableHandleFunction fun, const ReadOnlyComp Parser parser(cx, &cx->tempLifoAlloc(), options, srcBuf.get(), srcBuf.length(), /* foldConstants = */ true, - canLazilyParse ? &syntaxParser.ref() : nullptr, nullptr); + canLazilyParse ? syntaxParser.ptr() : nullptr, nullptr); parser.sct = &sct; parser.ss = ss; diff --git a/js/src/gc/Zone.h b/js/src/gc/Zone.h index 26d36b269d5..0f3318da4cd 100644 --- a/js/src/gc/Zone.h +++ b/js/src/gc/Zone.h @@ -399,37 +399,37 @@ class CompartmentsIterT : zone(rt) { if (zone.done()) - comp.construct(); + comp.emplace(); else - comp.construct(zone); + comp.emplace(zone); } CompartmentsIterT(JSRuntime *rt, ZoneSelector selector) : zone(rt, selector) { if (zone.done()) - comp.construct(); + comp.emplace(); else - comp.construct(zone); + comp.emplace(zone); } bool done() const { return zone.done(); } void next() { JS_ASSERT(!done()); - JS_ASSERT(!comp.ref().done()); - comp.ref().next(); - if (comp.ref().done()) { - comp.destroy(); + JS_ASSERT(!comp->done()); + comp->next(); + if (comp->done()) { + comp.reset(); zone.next(); if (!zone.done()) - comp.construct(zone); + comp.emplace(zone); } } JSCompartment *get() const { JS_ASSERT(!done()); - return comp.ref(); + return *comp; } operator JSCompartment *() const { return get(); } diff --git a/js/src/irregexp/RegExpEngine.cpp b/js/src/irregexp/RegExpEngine.cpp index d897e368dd4..b9d37ebb6a6 100644 --- a/js/src/irregexp/RegExpEngine.cpp +++ b/js/src/irregexp/RegExpEngine.cpp @@ -1661,12 +1661,12 @@ irregexp::CompilePattern(JSContext *cx, RegExpShared *shared, RegExpCompileData is_ascii ? NativeRegExpMacroAssembler::ASCII : NativeRegExpMacroAssembler::JSCHAR; - ctx.construct(cx, (jit::TempAllocator *) nullptr); - native_assembler.construct(&alloc, shared, cx->runtime(), mode, (data->capture_count + 1) * 2); - assembler = native_assembler.addr(); + ctx.emplace(cx, (jit::TempAllocator *) nullptr); + native_assembler.emplace(&alloc, shared, cx->runtime(), mode, (data->capture_count + 1) * 2); + assembler = native_assembler.ptr(); } else { - interpreted_assembler.construct(&alloc, shared, (data->capture_count + 1) * 2); - assembler = interpreted_assembler.addr(); + interpreted_assembler.emplace(&alloc, shared, (data->capture_count + 1) * 2); + assembler = interpreted_assembler.ptr(); } // Inserted here, instead of in Assembler, because it depends on information diff --git a/js/src/jit/CodeGenerator.cpp b/js/src/jit/CodeGenerator.cpp index 4d497f34c25..55b5175b25d 100644 --- a/js/src/jit/CodeGenerator.cpp +++ b/js/src/jit/CodeGenerator.cpp @@ -3384,8 +3384,8 @@ CodeGenerator::generateBody() mozilla::Maybe blockCounts; if (counts) { - blockCounts.construct(&counts->block(i), &masm); - if (!blockCounts.ref().init()) + blockCounts.emplace(&counts->block(i), &masm); + if (!blockCounts->init()) return false; } @@ -3402,7 +3402,7 @@ CodeGenerator::generateBody() IonSpewFin(IonSpew_Codegen); if (counts) - blockCounts.ref().visitInstruction(*iter); + blockCounts->visitInstruction(*iter); if (iter->safepoint() && pushedArgumentSlots_.length()) { if (!markArgumentSlots(iter->safepoint())) @@ -4851,10 +4851,10 @@ CodeGenerator::visitIsNullOrLikeUndefined(LIsNullOrLikeUndefined *lir) nullOrLikeUndefined = ool->label1(); notNullOrLikeUndefined = ool->label2(); } else { - label1.construct(); - label2.construct(); - nullOrLikeUndefined = label1.addr(); - notNullOrLikeUndefined = label2.addr(); + label1.emplace(); + label2.emplace(); + nullOrLikeUndefined = label1.ptr(); + notNullOrLikeUndefined = label2.ptr(); } Register tag = masm.splitTagForTest(value); @@ -5561,10 +5561,10 @@ CodeGenerator::visitNotV(LNotV *lir) ifTruthy = ool->label1(); ifFalsy = ool->label2(); } else { - ifTruthyLabel.construct(); - ifFalsyLabel.construct(); - ifTruthy = ifTruthyLabel.addr(); - ifFalsy = ifFalsyLabel.addr(); + ifTruthyLabel.emplace(); + ifFalsyLabel.emplace(); + ifTruthy = ifTruthyLabel.ptr(); + ifFalsy = ifFalsyLabel.ptr(); } testValueTruthyKernel(ToValue(lir, LNotV::Input), lir->temp1(), lir->temp2(), @@ -6549,7 +6549,7 @@ CodeGenerator::generateAsmJS(AsmJSFunctionLabels *labels) sps_.disable(); if (!omitOverRecursedCheck()) - labels->overflowThunk.construct(); + labels->overflowThunk.emplace(); GenerateAsmJSFunctionPrologue(masm, frameSize(), labels); diff --git a/js/src/jit/IonMacroAssembler.h b/js/src/jit/IonMacroAssembler.h index 292a6dd824f..874445131b4 100644 --- a/js/src/jit/IonMacroAssembler.h +++ b/js/src/jit/IonMacroAssembler.h @@ -210,7 +210,7 @@ class MacroAssembler : public MacroAssemblerSpecific if (!icx->temp) { JS_ASSERT(cx); - alloc_.construct(cx); + alloc_.emplace(cx); } moveResolver_.setAllocator(*icx->temp); @@ -228,9 +228,9 @@ class MacroAssembler : public MacroAssemblerSpecific sps_(nullptr) { constructRoot(cx); - ionContext_.construct(cx, (js::jit::TempAllocator *)nullptr); - alloc_.construct(cx); - moveResolver_.setAllocator(*ionContext_.ref().temp); + ionContext_.emplace(cx, (js::jit::TempAllocator *)nullptr); + alloc_.emplace(cx); + moveResolver_.setAllocator(*ionContext_->temp); #ifdef JS_CODEGEN_ARM initWithAllocator(); m_buffer.id = GetIonContext()->getNextAssemblerId(); @@ -241,8 +241,8 @@ class MacroAssembler : public MacroAssemblerSpecific // We have to update the SPS pc when this IC stub calls into // the VM. spsPc_ = pc; - spsInstrumentation_.construct(&cx->runtime()->spsProfiler, &spsPc_); - sps_ = spsInstrumentation_.addr(); + spsInstrumentation_.emplace(&cx->runtime()->spsProfiler, &spsPc_); + sps_ = spsInstrumentation_.ptr(); sps_->setPushed(script); } } @@ -271,7 +271,7 @@ class MacroAssembler : public MacroAssemblerSpecific } void constructRoot(JSContext *cx) { - autoRooter_.construct(cx, this); + autoRooter_.emplace(cx, this); } MoveResolver &moveResolver() { diff --git a/js/src/jit/MIR.cpp b/js/src/jit/MIR.cpp index e2b1efaf127..39874ca4054 100644 --- a/js/src/jit/MIR.cpp +++ b/js/src/jit/MIR.cpp @@ -3844,20 +3844,20 @@ TryAddTypeBarrierForWrite(TempAllocator &alloc, types::CompilerConstraintList *c // potentially be removed. property.freeze(constraints); - if (aggregateProperty.empty()) { - aggregateProperty.construct(property); + if (!aggregateProperty) { + aggregateProperty.emplace(property); } else { - if (!aggregateProperty.ref().maybeTypes()->isSubset(property.maybeTypes()) || - !property.maybeTypes()->isSubset(aggregateProperty.ref().maybeTypes())) + if (!aggregateProperty->maybeTypes()->isSubset(property.maybeTypes()) || + !property.maybeTypes()->isSubset(aggregateProperty->maybeTypes())) { return false; } } } - JS_ASSERT(!aggregateProperty.empty()); + JS_ASSERT(aggregateProperty); - MIRType propertyType = aggregateProperty.ref().knownMIRType(constraints); + MIRType propertyType = aggregateProperty->knownMIRType(constraints); switch (propertyType) { case MIRType_Boolean: case MIRType_Int32: @@ -3883,7 +3883,7 @@ TryAddTypeBarrierForWrite(TempAllocator &alloc, types::CompilerConstraintList *c if ((*pvalue)->type() != MIRType_Value) return false; - types::TemporaryTypeSet *types = aggregateProperty.ref().maybeTypes()->clone(alloc.lifoAlloc()); + types::TemporaryTypeSet *types = aggregateProperty->maybeTypes()->clone(alloc.lifoAlloc()); if (!types) return false; diff --git a/js/src/jit/shared/CodeGenerator-shared.cpp b/js/src/jit/shared/CodeGenerator-shared.cpp index c089f7311c2..62eb529e99a 100644 --- a/js/src/jit/shared/CodeGenerator-shared.cpp +++ b/js/src/jit/shared/CodeGenerator-shared.cpp @@ -33,8 +33,8 @@ CodeGeneratorShared::ensureMasm(MacroAssembler *masmArg) { if (masmArg) return *masmArg; - maybeMasm_.construct(); - return maybeMasm_.ref(); + maybeMasm_.emplace(); + return *maybeMasm_; } CodeGeneratorShared::CodeGeneratorShared(MIRGenerator *gen, LIRGraph *graph, MacroAssembler *masmArg) diff --git a/js/src/jsgc.cpp b/js/src/jsgc.cpp index 4ee0ae2b3c2..07d3a4ffbc3 100644 --- a/js/src/jsgc.cpp +++ b/js/src/jsgc.cpp @@ -2237,7 +2237,7 @@ ArenaLists::refillFreeList(ThreadSafeContext *cx, AllocKind thingKind) mozilla::Maybe lock; JSRuntime *rt = zone->runtimeFromAnyThread(); if (rt->exclusiveThreadsPresent()) { - lock.construct(); + lock.emplace(); while (rt->isHeapBusy()) HelperThreadState().wait(GlobalHelperThreadState::PRODUCER); } @@ -2529,7 +2529,7 @@ GCRuntime::decommitArenasFromAvailableList(Chunk **availableListHeadp) */ Maybe maybeUnlock; if (!isHeapBusy()) - maybeUnlock.construct(rt); + maybeUnlock.emplace(rt); ok = MarkPagesUnused(aheader->getArena(), ArenaSize); } diff --git a/js/src/json.cpp b/js/src/json.cpp index 0b1fde5669f..03355bd2810 100644 --- a/js/src/json.cpp +++ b/js/src/json.cpp @@ -329,10 +329,10 @@ JO(JSContext *cx, HandleObject obj, StringifyContext *scx) props = &scx->propertyList; } else { JS_ASSERT_IF(scx->replacer, scx->propertyList.length() == 0); - ids.construct(cx); - if (!GetPropertyNames(cx, obj, JSITER_OWNONLY, ids.addr())) + ids.emplace(cx); + if (!GetPropertyNames(cx, obj, JSITER_OWNONLY, ids.ptr())) return false; - props = ids.addr(); + props = ids.ptr(); } /* My kingdom for not-quite-initialized-from-the-start references. */ diff --git a/js/src/jsproxy.cpp b/js/src/jsproxy.cpp index f1b14601d73..1fdfdc4f013 100644 --- a/js/src/jsproxy.cpp +++ b/js/src/jsproxy.cpp @@ -54,8 +54,8 @@ js::AutoEnterPolicy::recordEnter(JSContext *cx, HandleObject proxy, HandleId id, { if (allowed()) { context = cx; - enteredProxy.construct(proxy); - enteredId.construct(id); + enteredProxy.emplace(proxy); + enteredId.emplace(id); enteredAction = act; prev = cx->runtime()->enteredPolicy; cx->runtime()->enteredPolicy = this; @@ -65,7 +65,7 @@ js::AutoEnterPolicy::recordEnter(JSContext *cx, HandleObject proxy, HandleId id, void js::AutoEnterPolicy::recordLeave() { - if (!enteredProxy.empty()) { + if (enteredProxy) { JS_ASSERT(context->runtime()->enteredPolicy == this); context->runtime()->enteredPolicy = prev; } @@ -77,8 +77,8 @@ js::assertEnteredPolicy(JSContext *cx, JSObject *proxy, jsid id, { MOZ_ASSERT(proxy->is()); MOZ_ASSERT(cx->runtime()->enteredPolicy); - MOZ_ASSERT(cx->runtime()->enteredPolicy->enteredProxy.ref().get() == proxy); - MOZ_ASSERT(cx->runtime()->enteredPolicy->enteredId.ref().get() == id); + MOZ_ASSERT(cx->runtime()->enteredPolicy->enteredProxy->get() == proxy); + MOZ_ASSERT(cx->runtime()->enteredPolicy->enteredId->get() == id); MOZ_ASSERT(cx->runtime()->enteredPolicy->enteredAction & act); } #endif diff --git a/js/src/jswrapper.cpp b/js/src/jswrapper.cpp index b42780eba9d..1a629cba7dd 100644 --- a/js/src/jswrapper.cpp +++ b/js/src/jswrapper.cpp @@ -47,9 +47,9 @@ Wrapper::New(JSContext *cx, JSObject *obj, JSObject *parent, const Wrapper *hand RootedValue priv(cx, ObjectValue(*obj)); mozilla::Maybe opts; if (!options) { - opts.construct(); - opts.ref().selectDefaultClass(obj->isCallable()); - options = opts.addr(); + opts.emplace(); + opts->selectDefaultClass(obj->isCallable()); + options = opts.ptr(); } return NewProxyObject(cx, handler, priv, options->proto(), parent, *options); } @@ -152,12 +152,12 @@ js::TransparentObjectWrapper(JSContext *cx, HandleObject existing, HandleObject ErrorCopier::~ErrorCopier() { - JSContext *cx = ac.ref().context()->asJSContext(); - if (ac.ref().origin() != cx->compartment() && cx->isExceptionPending()) { + JSContext *cx = ac->context()->asJSContext(); + if (ac->origin() != cx->compartment() && cx->isExceptionPending()) { RootedValue exc(cx); if (cx->getPendingException(&exc) && exc.isObject() && exc.toObject().is()) { cx->clearPendingException(); - ac.destroy(); + ac.reset(); Rooted errObj(cx, &exc.toObject().as()); JSObject *copyobj = js_CopyErrorObject(cx, errObj); if (copyobj) diff --git a/js/src/jswrapper.h b/js/src/jswrapper.h index 3083d82ff4a..1cc0ff2789d 100644 --- a/js/src/jswrapper.h +++ b/js/src/jswrapper.h @@ -30,13 +30,13 @@ class MOZ_STACK_CLASS WrapperOptions : public ProxyOptions { explicit WrapperOptions(JSContext *cx) : ProxyOptions(false, nullptr), proto_() { - proto_.construct(cx); + proto_.emplace(cx); } inline JSObject *proto() const; WrapperOptions &setProto(JSObject *protoArg) { - JS_ASSERT(!proto_.empty()); - proto_.ref() = protoArg; + JS_ASSERT(proto_); + *proto_ = protoArg; return *this; } @@ -96,7 +96,7 @@ class JS_FRIEND_API(Wrapper) : public DirectProxyHandler inline JSObject * WrapperOptions::proto() const { - return proto_.empty() ? Wrapper::defaultProto : proto_.ref(); + return proto_ ? *proto_ : Wrapper::defaultProto; } /* Base class for all cross compartment wrapper handlers. */ diff --git a/js/src/shell/js.cpp b/js/src/shell/js.cpp index 5e33e14902c..5f33e7193a5 100644 --- a/js/src/shell/js.cpp +++ b/js/src/shell/js.cpp @@ -350,7 +350,7 @@ ShellInterruptCallback(JSContext *cx) return true; bool result; - RootedValue interruptFunc(cx, gInterruptFunc.ref()); + RootedValue interruptFunc(cx, *gInterruptFunc); if (!interruptFunc.isNull()) { JS::AutoSaveExceptionState savedExc(cx); JSAutoCompartment ac(cx, &interruptFunc.toObject()); @@ -960,8 +960,8 @@ class AutoNewContext JS::ContextOptionsRef(newcx).setDontReportUncaught(true); js::SetDefaultObjectForContext(newcx, JS::CurrentGlobalOrNull(cx)); - newRequest.construct(newcx); - newCompartment.construct(newcx, JS::CurrentGlobalOrNull(cx)); + newRequest.emplace(newcx); + newCompartment.emplace(newcx, JS::CurrentGlobalOrNull(cx)); return true; } @@ -973,8 +973,8 @@ class AutoNewContext bool throwing = JS_IsExceptionPending(newcx); if (throwing) JS_GetPendingException(newcx, &exc); - newCompartment.destroy(); - newRequest.destroy(); + newCompartment.reset(); + newRequest.reset(); if (throwing) JS_SetPendingException(oldcx, exc); DestroyContext(newcx, false); @@ -2426,7 +2426,7 @@ Clone(JSContext *cx, unsigned argc, jsval *vp) if (obj && obj->is()) { obj = UncheckedUnwrap(obj); - ac.construct(cx, obj); + ac.emplace(cx, obj); args[0].setObject(*obj); } if (obj && obj->is()) { @@ -2608,7 +2608,7 @@ EvalInContext(JSContext *cx, unsigned argc, jsval *vp) JSObject *unwrapped = UncheckedUnwrap(sobj, true, &flags); if (flags & Wrapper::CROSS_COMPARTMENT) { sobj = unwrapped; - ac.construct(cx, sobj); + ac.emplace(cx, sobj); } sobj = GetInnerObject(sobj); @@ -2666,7 +2666,7 @@ EvalInFrame(JSContext *cx, unsigned argc, jsval *vp) if (saveCurrent) { if (!sfc.save()) return false; - ac.construct(cx, DefaultObjectForContextOrNull(cx)); + ac.emplace(cx, DefaultObjectForContextOrNull(cx)); } AutoStableStringChars stableChars(cx); @@ -3110,7 +3110,7 @@ CancelExecution(JSRuntime *rt) gServiceInterrupt = true; JS_RequestInterruptCallback(rt); - if (!gInterruptFunc.ref().get().isNull()) { + if (!gInterruptFunc->get().isNull()) { static const char msg[] = "Script runs for too long, terminating.\n"; fputs(msg, stderr); } @@ -3157,7 +3157,7 @@ Timeout(JSContext *cx, unsigned argc, Value *vp) JS_ReportError(cx, "Second argument must be a timeout function"); return false; } - gInterruptFunc.ref() = value; + *gInterruptFunc = value; } args.rval().setUndefined(); @@ -3228,7 +3228,7 @@ SetInterruptCallback(JSContext *cx, unsigned argc, Value *vp) JS_ReportError(cx, "Argument must be a function"); return false; } - gInterruptFunc.ref() = value; + *gInterruptFunc = value; args.rval().setUndefined(); return true; @@ -6213,13 +6213,13 @@ main(int argc, char **argv, char **envp) if (!SetRuntimeOptions(rt, op)) return 1; - gInterruptFunc.construct(rt, NullValue()); + gInterruptFunc.emplace(rt, NullValue()); JS_SetGCParameter(rt, JSGC_MAX_BYTES, 0xffffffff); #ifdef JSGC_GENERATIONAL Maybe noggc; if (op.getBoolOption("no-ggc")) - noggc.construct(rt); + noggc.emplace(rt); #endif size_t availMem = op.getIntOption("available-memory"); @@ -6261,15 +6261,14 @@ main(int argc, char **argv, char **envp) KillWatchdog(); - gInterruptFunc.destroy(); + gInterruptFunc.reset(); MOZ_ASSERT_IF(!CanUseExtraThreads(), workerThreads.empty()); for (size_t i = 0; i < workerThreads.length(); i++) PR_JoinThread(workerThreads[i]); #ifdef JSGC_GENERATIONAL - if (!noggc.empty()) - noggc.destroy(); + noggc.reset(); #endif JS_DestroyRuntime(rt); diff --git a/js/src/vm/Debugger.cpp b/js/src/vm/Debugger.cpp index b9503edcb42..3810ba0e535 100644 --- a/js/src/vm/Debugger.cpp +++ b/js/src/vm/Debugger.cpp @@ -558,7 +558,7 @@ Debugger::slowPathOnLeaveFrame(JSContext *cx, AbstractFramePtr frame, bool frame RootedValue handler(cx, frameobj->getReservedSlot(JSSLOT_DEBUGFRAME_ONPOP_HANDLER)); Maybe ac; - ac.construct(cx, dbg->object); + ac.emplace(cx, dbg->object); RootedValue completion(cx); if (!dbg->newCompletionValue(cx, status, value, &completion)) { @@ -834,7 +834,7 @@ JSTrapStatus Debugger::handleUncaughtExceptionHelper(Maybe &ac, MutableHandleValue *vp, bool callHook) { - JSContext *cx = ac.ref().context()->asJSContext(); + JSContext *cx = ac->context()->asJSContext(); if (cx->isExceptionPending()) { if (callHook && uncaughtExceptionHook) { RootedValue exc(cx); @@ -852,7 +852,7 @@ Debugger::handleUncaughtExceptionHelper(Maybe &ac, cx->clearPendingException(); } } - ac.destroy(); + ac.reset(); return JSTRAP_ERROR; } @@ -937,12 +937,12 @@ Debugger::receiveCompletionValue(Maybe &ac, bool ok, HandleValue val, MutableHandleValue vp) { - JSContext *cx = ac.ref().context()->asJSContext(); + JSContext *cx = ac->context()->asJSContext(); JSTrapStatus status; RootedValue value(cx); resultToCompletion(cx, ok, val, &status, &value); - ac.destroy(); + ac.reset(); return newCompletionValue(cx, status, value, vp); } @@ -954,16 +954,16 @@ Debugger::parseResumptionValue(Maybe &ac, bool ok, const Value if (!ok) return handleUncaughtException(ac, vp, callHook); if (rv.isUndefined()) { - ac.destroy(); + ac.reset(); return JSTRAP_CONTINUE; } if (rv.isNull()) { - ac.destroy(); + ac.reset(); return JSTRAP_ERROR; } /* Check that rv is {return: val} or {throw: val}. */ - JSContext *cx = ac.ref().context()->asJSContext(); + JSContext *cx = ac->context()->asJSContext(); Rooted obj(cx); RootedShape shape(cx); RootedId returnId(cx, NameToId(cx->names().return_)); @@ -989,7 +989,7 @@ Debugger::parseResumptionValue(Maybe &ac, bool ok, const Value if (!NativeGet(cx, obj, obj, shape, &v) || !unwrapDebuggeeValue(cx, &v)) return handleUncaughtException(ac, &v, callHook); - ac.destroy(); + ac.reset(); if (!cx->compartment()->wrap(cx, &v)) { vp.setUndefined(); return JSTRAP_ERROR; @@ -1022,7 +1022,7 @@ Debugger::fireDebuggerStatement(JSContext *cx, MutableHandleValue vp) JS_ASSERT(hook->isCallable()); Maybe ac; - ac.construct(cx, object); + ac.emplace(cx, object); ScriptFrameIter iter(cx); @@ -1048,7 +1048,7 @@ Debugger::fireExceptionUnwind(JSContext *cx, MutableHandleValue vp) cx->clearPendingException(); Maybe ac; - ac.construct(cx, object); + ac.emplace(cx, object); JS::AutoValueArray<2> argv(cx); argv[0].setUndefined(); @@ -1074,7 +1074,7 @@ Debugger::fireEnterFrame(JSContext *cx, AbstractFramePtr frame, MutableHandleVal JS_ASSERT(hook->isCallable()); Maybe ac; - ac.construct(cx, object); + ac.emplace(cx, object); RootedValue scriptFrame(cx); if (!getScriptFrame(cx, frame, &scriptFrame)) @@ -1093,7 +1093,7 @@ Debugger::fireNewScript(JSContext *cx, HandleScript script) JS_ASSERT(hook->isCallable()); Maybe ac; - ac.construct(cx, object); + ac.emplace(cx, object); JSObject *dsobj = wrapScript(cx, script); if (!dsobj) { @@ -1248,7 +1248,7 @@ Debugger::onTrap(JSContext *cx, MutableHandleValue vp) Debugger *dbg = bp->debugger; if (dbg->enabled && dbg->debuggees.lookup(scriptGlobal)) { Maybe ac; - ac.construct(cx, dbg->object); + ac.emplace(cx, dbg->object); RootedValue scriptFrame(cx); if (!dbg->getScriptFrame(cx, iter, &scriptFrame)) @@ -1359,7 +1359,7 @@ Debugger::onSingleStep(JSContext *cx, MutableHandleValue vp) Debugger *dbg = Debugger::fromChildJSObject(frame); Maybe ac; - ac.construct(cx, dbg->object); + ac.emplace(cx, dbg->object); const Value &handler = frame->getReservedSlot(JSSLOT_DEBUGFRAME_ONSTEP_HANDLER); RootedValue rval(cx); @@ -1383,7 +1383,7 @@ Debugger::fireNewGlobalObject(JSContext *cx, Handle global, Muta JS_ASSERT(hook->isCallable()); Maybe ac; - ac.construct(cx, object); + ac.emplace(cx, object); RootedValue wrappedGlobal(cx, ObjectValue(*global)); if (!wrapDebuggeeValue(cx, &wrappedGlobal)) @@ -4389,11 +4389,11 @@ CheckThisFrame(JSContext *cx, const CallArgs &args, const char *fnname, bool che { \ AbstractFramePtr f = AbstractFramePtr::FromRaw(thisobj->getPrivate()); \ if (f.isScriptFrameIterData()) { \ - maybeIter.construct(*(ScriptFrameIter::Data *)(f.raw())); \ + maybeIter.emplace(*(ScriptFrameIter::Data *)(f.raw())); \ } else { \ - maybeIter.construct(cx, ScriptFrameIter::ALL_CONTEXTS, \ - ScriptFrameIter::GO_THROUGH_SAVED); \ - ScriptFrameIter &iter = maybeIter.ref(); \ + maybeIter.emplace(cx, ScriptFrameIter::ALL_CONTEXTS, \ + ScriptFrameIter::GO_THROUGH_SAVED); \ + ScriptFrameIter &iter = *maybeIter; \ while (iter.isIon() || iter.abstractFramePtr() != f) \ ++iter; \ AbstractFramePtr data = iter.copyDataAsAbstractFramePtr(); \ @@ -4402,7 +4402,7 @@ CheckThisFrame(JSContext *cx, const CallArgs &args, const char *fnname, bool che thisobj->setPrivate(data.raw()); \ } \ } \ - ScriptFrameIter &iter = maybeIter.ref() + ScriptFrameIter &iter = *maybeIter #define THIS_FRAME_OWNER(cx, argc, vp, fnname, args, thisobj, frame, dbg) \ THIS_FRAME(cx, argc, vp, fnname, args, thisobj, frame); \ @@ -4901,9 +4901,9 @@ DebuggerGenericEval(JSContext *cx, const char *fullMethodName, const Value &code Maybe ac; if (iter) - ac.construct(cx, iter->scopeChain()); + ac.emplace(cx, iter->scopeChain()); else - ac.construct(cx, scope); + ac.emplace(cx, scope); RootedValue thisv(cx); Rooted env(cx); @@ -5398,7 +5398,7 @@ DebuggerObject_getOwnPropertyDescriptor(JSContext *cx, unsigned argc, Value *vp) Rooted desc(cx); { Maybe ac; - ac.construct(cx, obj); + ac.emplace(cx, obj); ErrorCopier ec(ac); if (!GetOwnPropertyDescriptor(cx, obj, id, &desc)) @@ -5435,7 +5435,7 @@ DebuggerObject_getOwnPropertyNames(JSContext *cx, unsigned argc, Value *vp) AutoIdVector keys(cx); { Maybe ac; - ac.construct(cx, obj); + ac.emplace(cx, obj); ErrorCopier ec(ac); if (!GetPropertyNames(cx, obj, JSITER_OWNONLY | JSITER_HIDDEN, &keys)) return false; @@ -5488,7 +5488,7 @@ DebuggerObject_defineProperty(JSContext *cx, unsigned argc, Value *vp) { Maybe ac; - ac.construct(cx, obj); + ac.emplace(cx, obj); if (!cx->compartment()->wrap(cx, &desc)) return false; @@ -5529,7 +5529,7 @@ DebuggerObject_defineProperties(JSContext *cx, unsigned argc, Value *vp) { Maybe ac; - ac.construct(cx, obj); + ac.emplace(cx, obj); for (size_t i = 0; i < n; i++) { if (!cx->compartment()->wrap(cx, descs[i])) return false; @@ -5560,7 +5560,7 @@ DebuggerObject_deleteProperty(JSContext *cx, unsigned argc, Value *vp) return false; Maybe ac; - ac.construct(cx, obj); + ac.emplace(cx, obj); ErrorCopier ec(ac); bool succeeded; @@ -5578,7 +5578,7 @@ DebuggerObject_sealHelper(JSContext *cx, unsigned argc, Value *vp, SealHelperOp THIS_DEBUGOBJECT_REFERENT(cx, argc, vp, name, args, obj); Maybe ac; - ac.construct(cx, obj); + ac.emplace(cx, obj); ErrorCopier ec(ac); bool ok; if (op == Seal) { @@ -5627,7 +5627,7 @@ DebuggerObject_isSealedHelper(JSContext *cx, unsigned argc, Value *vp, SealHelpe THIS_DEBUGOBJECT_REFERENT(cx, argc, vp, name, args, obj); Maybe ac; - ac.construct(cx, obj); + ac.emplace(cx, obj); ErrorCopier ec(ac); bool r; if (op == Seal) { @@ -5721,7 +5721,7 @@ ApplyOrCall(JSContext *cx, unsigned argc, Value *vp, ApplyOrCallMode mode) * (Rewrapping always takes place in the destination compartment.) */ Maybe ac; - ac.construct(cx, obj); + ac.emplace(cx, obj); if (!cx->compartment()->wrap(cx, &calleev) || !cx->compartment()->wrap(cx, &thisv)) return false; @@ -6127,7 +6127,7 @@ DebuggerEnv_names(JSContext *cx, unsigned argc, Value *vp) AutoIdVector keys(cx); { Maybe ac; - ac.construct(cx, env); + ac.emplace(cx, env); ErrorCopier ec(ac); if (!GetPropertyNames(cx, env, JSITER_HIDDEN, &keys)) return false; @@ -6161,7 +6161,7 @@ DebuggerEnv_find(JSContext *cx, unsigned argc, Value *vp) { Maybe ac; - ac.construct(cx, env); + ac.emplace(cx, env); /* This can trigger resolve hooks. */ ErrorCopier ec(ac); @@ -6192,7 +6192,7 @@ DebuggerEnv_getVariable(JSContext *cx, unsigned argc, Value *vp) RootedValue v(cx); { Maybe ac; - ac.construct(cx, env); + ac.emplace(cx, env); /* This can trigger getters. */ ErrorCopier ec(ac); @@ -6233,7 +6233,7 @@ DebuggerEnv_setVariable(JSContext *cx, unsigned argc, Value *vp) { Maybe ac; - ac.construct(cx, env); + ac.emplace(cx, env); if (!cx->compartment()->wrap(cx, &v)) return false; diff --git a/js/src/vm/HelperThreads.cpp b/js/src/vm/HelperThreads.cpp index 9c3764482a5..78afbe13fd2 100644 --- a/js/src/vm/HelperThreads.cpp +++ b/js/src/vm/HelperThreads.cpp @@ -423,11 +423,11 @@ GlobalHelperThreadState::ensureInitialized() for (size_t i = 0; i < threadCount; i++) { HelperThread &helper = threads[i]; - helper.threadData.construct(static_cast(nullptr)); + helper.threadData.emplace(static_cast(nullptr)); helper.thread = PR_CreateThread(PR_USER_THREAD, HelperThread::ThreadMain, &helper, PR_PRIORITY_NORMAL, PR_GLOBAL_THREAD, PR_JOINABLE_THREAD, HELPER_STACK_SIZE); - if (!helper.thread || !helper.threadData.ref().init()) + if (!helper.thread || !helper.threadData->init()) CrashAtUnhandlableOOM("GlobalHelperThreadState::ensureInitialized"); } @@ -813,8 +813,7 @@ HelperThread::destroy() PR_JoinThread(thread); } - if (!threadData.empty()) - threadData.destroy(); + threadData.reset(); } #ifdef MOZ_NUWA_PROCESS @@ -852,7 +851,7 @@ HelperThread::handleAsmJSWorkload() do { AutoUnlockHelperThreadState unlock; - PerThreadData::AutoEnterRuntime enter(threadData.addr(), asmData->runtime); + PerThreadData::AutoEnterRuntime enter(threadData.ptr(), asmData->runtime); jit::IonContext icx(asmData->mir->compartment->runtime(), asmData->mir->compartment, @@ -922,7 +921,7 @@ HelperThread::handleIonWorkload() { AutoUnlockHelperThreadState unlock; - PerThreadData::AutoEnterRuntime enter(threadData.addr(), + PerThreadData::AutoEnterRuntime enter(threadData.ptr(), ionBuilder->script()->runtimeFromAnyThread()); jit::IonContext ictx(jit::CompileRuntime::get(rt), jit::CompileCompartment::get(ionBuilder->script()->compartment()), @@ -998,7 +997,7 @@ void ExclusiveContext::setHelperThread(HelperThread *thread) { helperThread_ = thread; - perThreadData = thread->threadData.addr(); + perThreadData = thread->threadData.ptr(); } frontend::CompileError & @@ -1031,7 +1030,7 @@ HelperThread::handleParseWorkload() { AutoUnlockHelperThreadState unlock; - PerThreadData::AutoEnterRuntime enter(threadData.addr(), + PerThreadData::AutoEnterRuntime enter(threadData.ptr(), parseTask->exclusiveContextGlobal->runtimeFromAnyThread()); SourceBufferHolder srcBuf(parseTask->chars, parseTask->length, SourceBufferHolder::NoOwnership); @@ -1187,7 +1186,7 @@ HelperThread::threadLoop() JS::AutoSuppressGCAnalysis nogc; AutoLockHelperThreadState lock; - js::TlsPerThreadData.set(threadData.addr()); + js::TlsPerThreadData.set(threadData.ptr()); // Compute the thread's stack limit, for over-recursed checks. uintptr_t stackLimit = GetNativeStackBase(); @@ -1196,8 +1195,8 @@ HelperThread::threadLoop() #else stackLimit -= HELPER_STACK_QUOTA; #endif - for (size_t i = 0; i < ArrayLength(threadData.ref().nativeStackLimit); i++) - threadData.ref().nativeStackLimit[i] = stackLimit; + for (size_t i = 0; i < ArrayLength(threadData->nativeStackLimit); i++) + threadData->nativeStackLimit[i] = stackLimit; while (true) { JS_ASSERT(idle()); diff --git a/js/src/vm/RegExpObject.cpp b/js/src/vm/RegExpObject.cpp index b24aee11ef5..d9fec7d7858 100644 --- a/js/src/vm/RegExpObject.cpp +++ b/js/src/vm/RegExpObject.cpp @@ -304,11 +304,11 @@ RegExpObject::createNoStatics(ExclusiveContext *cx, HandleAtom source, RegExpFla Maybe dummyOptions; Maybe dummyTokenStream; if (!tokenStream) { - dummyOptions.construct(cx->asJSContext()); - dummyTokenStream.construct(cx, dummyOptions.ref(), + dummyOptions.emplace(cx->asJSContext()); + dummyTokenStream.emplace(cx, *dummyOptions, (const jschar *) nullptr, 0, (frontend::StrictModeGetter *) nullptr); - tokenStream = dummyTokenStream.addr(); + tokenStream = dummyTokenStream.ptr(); } if (!irregexp::ParsePatternSyntax(*tokenStream, alloc, source)) diff --git a/js/src/vm/Shape-inl.h b/js/src/vm/Shape-inl.h index 85c6a7d9f7e..7f91e365852 100644 --- a/js/src/vm/Shape-inl.h +++ b/js/src/vm/Shape-inl.h @@ -202,7 +202,7 @@ AutoRooterGetterSetter::AutoRooterGetterSetter(ThreadSafeContext *cx, uint8_t at MOZ_GUARD_OBJECT_NOTIFIER_PARAM_IN_IMPL) { if (attrs & (JSPROP_GETTER | JSPROP_SETTER)) - inner.construct(cx, attrs, pgetter, psetter); + inner.emplace(cx, attrs, pgetter, psetter); MOZ_GUARD_OBJECT_NOTIFIER_INIT; } diff --git a/js/xpconnect/loader/mozJSComponentLoader.cpp b/js/xpconnect/loader/mozJSComponentLoader.cpp index d129637b071..e060e4aa7c0 100644 --- a/js/xpconnect/loader/mozJSComponentLoader.cpp +++ b/js/xpconnect/loader/mozJSComponentLoader.cpp @@ -341,11 +341,11 @@ class MOZ_STACK_CLASS ComponentLoaderInfo { return mScriptChannel->GetURI(getter_AddRefs(mResolvedURI)); } - nsAutoCString& Key() { return mKey.ref(); } + nsAutoCString& Key() { return *mKey; } nsresult EnsureKey() { ENSURE_DEPS(ResolvedURI); - mKey.construct(); - return mResolvedURI->GetSpec(mKey.ref()); + mKey.emplace(); + return mResolvedURI->GetSpec(*mKey); } private: @@ -1113,7 +1113,7 @@ mozJSComponentLoader::Import(const nsACString& registryLocation, Maybe ac; if (targetObject) { - ac.construct(cx, targetObject); + ac.emplace(cx, targetObject); } RootedObject global(cx); diff --git a/js/xpconnect/src/ExportHelpers.cpp b/js/xpconnect/src/ExportHelpers.cpp index 9e024244dbf..b1e208390f8 100644 --- a/js/xpconnect/src/ExportHelpers.cpp +++ b/js/xpconnect/src/ExportHelpers.cpp @@ -185,7 +185,7 @@ StackScopedClone(JSContext *cx, StackScopedCloneOptions &options, // (unless it's a primitive) Maybe ac; if (val.isObject()) { - ac.construct(cx, &val.toObject()); + ac.emplace(cx, &val.toObject()); } else if (val.isString() && !JS_WrapValue(cx, val)) { return false; } diff --git a/js/xpconnect/src/XPCComponents.cpp b/js/xpconnect/src/XPCComponents.cpp index d76b4b47f55..9a0b6073cd8 100644 --- a/js/xpconnect/src/XPCComponents.cpp +++ b/js/xpconnect/src/XPCComponents.cpp @@ -3191,7 +3191,7 @@ nsXPCComponents_Utils::Dispatch(HandleValue runnableArg, HandleValue scope, JSObject *scopeObj = js::UncheckedUnwrap(&scope.toObject()); if (!scopeObj) return NS_ERROR_FAILURE; - ac.construct(cx, scopeObj); + ac.emplace(cx, scopeObj); if (!JS_WrapValue(cx, &runnable)) return NS_ERROR_FAILURE; } diff --git a/js/xpconnect/src/XPCJSRuntime.cpp b/js/xpconnect/src/XPCJSRuntime.cpp index 166a8f0694e..45d1beeaf85 100644 --- a/js/xpconnect/src/XPCJSRuntime.cpp +++ b/js/xpconnect/src/XPCJSRuntime.cpp @@ -1187,7 +1187,7 @@ class WatchdogManager : public nsIObserver MOZ_ASSERT(NS_IsMainThread()); Maybe lock; if (mWatchdog) - lock.construct(mWatchdog); + lock.emplace(mWatchdog); // Write state. mTimestamps[TimestampRuntimeStateChange] = PR_Now(); @@ -1211,7 +1211,7 @@ class WatchdogManager : public nsIObserver // The watchdog thread always holds the lock when it runs. Maybe maybeLock; if (NS_IsMainThread() && mWatchdog) - maybeLock.construct(mWatchdog); + maybeLock.emplace(mWatchdog); mTimestamps[aCategory] = PR_Now(); } PRTime GetTimestamp(WatchdogTimestampCategory aCategory) @@ -1219,7 +1219,7 @@ class WatchdogManager : public nsIObserver // The watchdog thread always holds the lock when it runs. Maybe maybeLock; if (NS_IsMainThread() && mWatchdog) - maybeLock.construct(mWatchdog); + maybeLock.emplace(mWatchdog); return mTimestamps[aCategory]; } diff --git a/js/xpconnect/src/XPCShellImpl.cpp b/js/xpconnect/src/XPCShellImpl.cpp index 8e5faf3acc4..4d6e9aa90ad 100644 --- a/js/xpconnect/src/XPCShellImpl.cpp +++ b/js/xpconnect/src/XPCShellImpl.cpp @@ -648,8 +648,8 @@ static Maybe sScriptedInterruptCallback; static bool XPCShellInterruptCallback(JSContext *cx) { - MOZ_ASSERT(!sScriptedInterruptCallback.empty()); - RootedValue callback(cx, sScriptedInterruptCallback.ref()); + MOZ_ASSERT(sScriptedInterruptCallback); + RootedValue callback(cx, *sScriptedInterruptCallback); // If no interrupt callback was set by script, no-op. if (callback.isUndefined()) @@ -671,7 +671,7 @@ XPCShellInterruptCallback(JSContext *cx) static bool SetInterruptCallback(JSContext *cx, unsigned argc, jsval *vp) { - MOZ_ASSERT(!sScriptedInterruptCallback.empty()); + MOZ_ASSERT(sScriptedInterruptCallback); // Sanity-check args. JS::CallArgs args = JS::CallArgsFromVp(argc, vp); @@ -682,7 +682,7 @@ SetInterruptCallback(JSContext *cx, unsigned argc, jsval *vp) // Allow callers to remove the interrupt callback by passing undefined. if (args[0].isUndefined()) { - sScriptedInterruptCallback.ref() = UndefinedValue(); + *sScriptedInterruptCallback = UndefinedValue(); return true; } @@ -692,7 +692,7 @@ SetInterruptCallback(JSContext *cx, unsigned argc, jsval *vp) return false; } - sScriptedInterruptCallback.ref() = args[0]; + *sScriptedInterruptCallback = args[0]; return true; } @@ -1459,7 +1459,7 @@ XRE_XPCShellMain(int argc, char **argv, char **envp) // Override the default XPConnect interrupt callback. We could store the // old one and restore it before shutting down, but there's not really a // reason to bother. - sScriptedInterruptCallback.construct(rt, UndefinedValue()); + sScriptedInterruptCallback.emplace(rt, UndefinedValue()); JS_SetInterruptCallback(rt, XPCShellInterruptCallback); dom::AutoJSAPI jsapi; @@ -1590,7 +1590,7 @@ XRE_XPCShellMain(int argc, char **argv, char **envp) rv = NS_ShutdownXPCOM( nullptr ); MOZ_ASSERT(NS_SUCCEEDED(rv), "NS_ShutdownXPCOM failed"); - sScriptedInterruptCallback.destroyIfConstructed(); + sScriptedInterruptCallback.reset(); #ifdef TEST_CALL_ON_WRAPPED_JS_AFTER_SHUTDOWN // test of late call and release (see above) diff --git a/js/xpconnect/src/XPCWrappedJSClass.cpp b/js/xpconnect/src/XPCWrappedJSClass.cpp index 26f6f7f69fe..230a7bbfdde 100644 --- a/js/xpconnect/src/XPCWrappedJSClass.cpp +++ b/js/xpconnect/src/XPCWrappedJSClass.cpp @@ -46,7 +46,7 @@ bool AutoScriptEvaluate::StartEvaluating(HandleObject scope, JSErrorReporter err } JS_BeginRequest(mJSContext); - mAutoCompartment.construct(mJSContext, scope); + mAutoCompartment.emplace(mJSContext, scope); // Saving the exception state keeps us from interfering with another script // that may also be running on this context. This occurred first with the @@ -54,7 +54,7 @@ bool AutoScriptEvaluate::StartEvaluating(HandleObject scope, JSErrorReporter err // http://bugzilla.mozilla.org/show_bug.cgi?id=88130 but presumably could // show up in any situation where a script calls into a wrapped js component // on the same context, while the context has a nonzero exception state. - mState.construct(mJSContext); + mState.emplace(mJSContext); return true; } @@ -63,7 +63,7 @@ AutoScriptEvaluate::~AutoScriptEvaluate() { if (!mJSContext || !mEvaluated) return; - mState.ref().restore(); + mState->restore(); JS_EndRequest(mJSContext); diff --git a/js/xpconnect/src/XPCWrappedNative.cpp b/js/xpconnect/src/XPCWrappedNative.cpp index bf901b27848..75da46970b4 100644 --- a/js/xpconnect/src/XPCWrappedNative.cpp +++ b/js/xpconnect/src/XPCWrappedNative.cpp @@ -366,7 +366,7 @@ XPCWrappedNative::GetNewOrUsed(xpcObjectHelper& helper, MOZ_ASSERT(!xpc::WrapperFactory::IsXrayWrapper(parent), "Xray wrapper being used to parent XPCWrappedNative?"); - ac.construct(static_cast(cx), parent); + ac.emplace(static_cast(cx), parent); if (parent != plannedParent) { XPCWrappedNativeScope* betterScope = ObjectScope(parent); @@ -397,7 +397,7 @@ XPCWrappedNative::GetNewOrUsed(xpcObjectHelper& helper, return NS_OK; } } else { - ac.construct(static_cast(cx), parent); + ac.emplace(static_cast(cx), parent); } AutoMarkingWrappedNativeProtoPtr proto(cx); diff --git a/js/xpconnect/src/nsCxPusher.cpp b/js/xpconnect/src/nsCxPusher.cpp index df0cbd72476..7242c4a176a 100644 --- a/js/xpconnect/src/nsCxPusher.cpp +++ b/js/xpconnect/src/nsCxPusher.cpp @@ -39,21 +39,21 @@ AutoCxPusher::AutoCxPusher(JSContext* cx, bool allowNull) // Enter a request and a compartment for the duration that the cx is on the // stack if non-null. if (cx) { - mAutoRequest.construct(cx); + mAutoRequest.emplace(cx); // DOM JSContexts don't store their default compartment object on the cx. JSObject *compartmentObject = mScx ? mScx->GetWindowProxy() : js::DefaultObjectForContextOrNull(cx); if (compartmentObject) - mAutoCompartment.construct(cx, compartmentObject); + mAutoCompartment.emplace(cx, compartmentObject); } } AutoCxPusher::~AutoCxPusher() { // Leave the compartment and request before popping. - mAutoCompartment.destroyIfConstructed(); - mAutoRequest.destroyIfConstructed(); + mAutoCompartment.reset(); + mAutoRequest.reset(); // When we push a context, we may save the frame chain and pretend like we // haven't entered any compartment. This gets restored on Pop(), but we can @@ -103,7 +103,7 @@ AutoJSContext::Init(bool aSafe MOZ_GUARD_OBJECT_NOTIFIER_PARAM_IN_IMPL) if (!mCx) { mCx = xpc->GetSafeJSContext(); - mPusher.construct(mCx); + mPusher.emplace(mCx); } } @@ -118,10 +118,10 @@ ThreadsafeAutoJSContext::ThreadsafeAutoJSContext(MOZ_GUARD_OBJECT_NOTIFIER_ONLY_ if (NS_IsMainThread()) { mCx = nullptr; - mAutoJSContext.construct(); + mAutoJSContext.emplace(); } else { mCx = mozilla::dom::workers::GetCurrentThreadJSContext(); - mRequest.construct(mCx); + mRequest.emplace(mCx); } } @@ -130,7 +130,7 @@ ThreadsafeAutoJSContext::operator JSContext*() const if (mCx) { return mCx; } else { - return mAutoJSContext.ref(); + return *mAutoJSContext; } } @@ -146,10 +146,10 @@ ThreadsafeAutoSafeJSContext::ThreadsafeAutoSafeJSContext(MOZ_GUARD_OBJECT_NOTIFI if (NS_IsMainThread()) { mCx = nullptr; - mAutoSafeJSContext.construct(); + mAutoSafeJSContext.emplace(); } else { mCx = mozilla::dom::workers::GetCurrentThreadJSContext(); - mRequest.construct(mCx); + mRequest.emplace(mCx); } } @@ -158,7 +158,7 @@ ThreadsafeAutoSafeJSContext::operator JSContext*() const if (mCx) { return mCx; } else { - return mAutoSafeJSContext.ref(); + return *mAutoSafeJSContext; } } diff --git a/js/xpconnect/src/xpcprivate.h b/js/xpconnect/src/xpcprivate.h index 5962906ce4d..93dee6ca694 100644 --- a/js/xpconnect/src/xpcprivate.h +++ b/js/xpconnect/src/xpcprivate.h @@ -396,9 +396,9 @@ public: StringType* Create() { for (uint32_t i = 0; i < ArrayLength(mStrings); ++i) { - if (mStrings[i].empty()) { - mStrings[i].construct(); - return mStrings[i].addr(); + if (!mStrings[i]) { + mStrings[i].emplace(); + return mStrings[i].ptr(); } } @@ -409,11 +409,10 @@ public: void Destroy(StringType *string) { for (uint32_t i = 0; i < ArrayLength(mStrings); ++i) { - if (!mStrings[i].empty() && - mStrings[i].addr() == string) { + if (mStrings[i] && mStrings[i].ptr() == string) { // One of our internal strings is no longer in use, mark // it as such and free its data. - mStrings[i].destroy(); + mStrings[i].reset(); return; } } @@ -427,7 +426,7 @@ public: { #ifdef DEBUG for (uint32_t i = 0; i < ArrayLength(mStrings); ++i) { - MOZ_ASSERT(mStrings[i].empty(), "Short lived string still in use"); + MOZ_ASSERT(!mStrings[i], "Short lived string still in use"); } #endif } diff --git a/js/xpconnect/wrappers/XrayWrapper.cpp b/js/xpconnect/wrappers/XrayWrapper.cpp index aa32b88b81d..84a1aa07302 100644 --- a/js/xpconnect/wrappers/XrayWrapper.cpp +++ b/js/xpconnect/wrappers/XrayWrapper.cpp @@ -2282,7 +2282,7 @@ HasNativeProperty(JSContext *cx, HandleObject wrapper, HandleId id, bool *hasPro // Try resolveOwnProperty. Maybe resolvingId; if (traits == &XPCWrappedNativeXrayTraits::singleton) - resolvingId.construct(cx, wrapper, id); + resolvingId.emplace(cx, wrapper, id); if (!traits->resolveOwnProperty(cx, *handler, wrapper, holder, id, &desc)) return false; if (desc.object()) {