Bug 1470558: Use Completion type for Debugger eval-related methods. r=jorendorff

DebuggerFrame::eval and DebuggerObject::evalInGlobal are two more invocation
functions that can reasonably use Completion to report the results of the
operation.

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

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Jim Blandy 2019-07-07 09:47:52 +00:00
Родитель 0db9a27958
Коммит e97921f538
2 изменённых файлов: 47 добавлений и 79 удалений

Просмотреть файл

@ -9801,10 +9801,9 @@ static bool EvaluateInEnv(JSContext* cx, Handle<Env*> env,
return ExecuteKernel(cx, script, *env, NullValue(), frame, rval.address()); return ExecuteKernel(cx, script, *env, NullValue(), frame, rval.address());
} }
static bool DebuggerGenericEval( static Result<Completion> DebuggerGenericEval(
JSContext* cx, const mozilla::Range<const char16_t> chars, JSContext* cx, const mozilla::Range<const char16_t> chars,
HandleObject bindings, const EvalOptions& options, ResumeMode& resumeMode, HandleObject bindings, const EvalOptions& options, Debugger* dbg,
MutableHandleValue value, MutableHandleSavedFrame exnStack, Debugger* dbg,
HandleObject envArg, FrameIter* iter) { HandleObject envArg, FrameIter* iter) {
// Either we're specifying the frame, or a global. // Either we're specifying the frame, or a global.
MOZ_ASSERT_IF(iter, !envArg); MOZ_ASSERT_IF(iter, !envArg);
@ -9817,13 +9816,13 @@ static bool DebuggerGenericEval(
if (bindings) { if (bindings) {
if (!GetPropertyKeys(cx, bindings, JSITER_OWNONLY, &keys) || if (!GetPropertyKeys(cx, bindings, JSITER_OWNONLY, &keys) ||
!values.growBy(keys.length())) { !values.growBy(keys.length())) {
return false; return cx->alreadyReportedError();
} }
for (size_t i = 0; i < keys.length(); i++) { for (size_t i = 0; i < keys.length(); i++) {
MutableHandleValue valp = values[i]; MutableHandleValue valp = values[i];
if (!GetProperty(cx, bindings, bindings, keys[i], valp) || if (!GetProperty(cx, bindings, bindings, keys[i], valp) ||
!dbg->unwrapDebuggeeValue(cx, valp)) { !dbg->unwrapDebuggeeValue(cx, valp)) {
return false; return cx->alreadyReportedError();
} }
} }
} }
@ -9839,7 +9838,7 @@ static bool DebuggerGenericEval(
if (iter) { if (iter) {
env = GetDebugEnvironmentForFrame(cx, iter->abstractFramePtr(), iter->pc()); env = GetDebugEnvironmentForFrame(cx, iter->abstractFramePtr(), iter->pc());
if (!env) { if (!env) {
return false; return cx->alreadyReportedError();
} }
} else { } else {
env = envArg; env = envArg;
@ -9850,7 +9849,7 @@ static bool DebuggerGenericEval(
RootedPlainObject nenv(cx, RootedPlainObject nenv(cx,
NewObjectWithGivenProto<PlainObject>(cx, nullptr)); NewObjectWithGivenProto<PlainObject>(cx, nullptr));
if (!nenv) { if (!nenv) {
return false; return cx->alreadyReportedError();
} }
RootedId id(cx); RootedId id(cx);
for (size_t i = 0; i < keys.length(); i++) { for (size_t i = 0; i < keys.length(); i++) {
@ -9859,18 +9858,18 @@ static bool DebuggerGenericEval(
MutableHandleValue val = values[i]; MutableHandleValue val = values[i];
if (!cx->compartment()->wrap(cx, val) || if (!cx->compartment()->wrap(cx, val) ||
!NativeDefineDataProperty(cx, nenv, id, val, 0)) { !NativeDefineDataProperty(cx, nenv, id, val, 0)) {
return false; return cx->alreadyReportedError();
} }
} }
RootedObjectVector envChain(cx); RootedObjectVector envChain(cx);
if (!envChain.append(nenv)) { if (!envChain.append(nenv)) {
return false; return cx->alreadyReportedError();
} }
RootedObject newEnv(cx); RootedObject newEnv(cx);
if (!CreateObjectsForEnvironmentChain(cx, envChain, env, &newEnv)) { if (!CreateObjectsForEnvironmentChain(cx, envChain, env, &newEnv)) {
return false; return cx->alreadyReportedError();
} }
env = newEnv; env = newEnv;
@ -9885,31 +9884,29 @@ static bool DebuggerGenericEval(
cx, env, frame, chars, cx, env, frame, chars,
options.filename() ? options.filename() : "debugger eval code", options.filename() ? options.filename() : "debugger eval code",
options.lineno(), &rval); options.lineno(), &rval);
Debugger::resultToCompletion(cx, ok, rval, &resumeMode, value, exnStack); Rooted<Completion> completion(cx, Completion::fromJSResult(cx, ok, rval));
ar.reset(); ar.reset();
return dbg->wrapDebuggeeValue(cx, value); return completion.get();
} }
/* static */ /* static */
bool DebuggerFrame::eval(JSContext* cx, HandleDebuggerFrame frame, Result<Completion> DebuggerFrame::eval(JSContext* cx, HandleDebuggerFrame frame,
mozilla::Range<const char16_t> chars, mozilla::Range<const char16_t> chars,
HandleObject bindings, const EvalOptions& options, HandleObject bindings,
ResumeMode& resumeMode, MutableHandleValue value, const EvalOptions& options) {
MutableHandleSavedFrame exnStack) {
MOZ_ASSERT(frame->isLive()); MOZ_ASSERT(frame->isLive());
Debugger* dbg = frame->owner(); Debugger* dbg = frame->owner();
Maybe<FrameIter> maybeIter; Maybe<FrameIter> maybeIter;
if (!DebuggerFrame::getFrameIter(cx, frame, maybeIter)) { if (!DebuggerFrame::getFrameIter(cx, frame, maybeIter)) {
return false; return cx->alreadyReportedError();
} }
FrameIter& iter = *maybeIter; FrameIter& iter = *maybeIter;
UpdateFrameIterPc(iter); UpdateFrameIterPc(iter);
return DebuggerGenericEval(cx, chars, bindings, options, resumeMode, value, return DebuggerGenericEval(cx, chars, bindings, options, dbg, nullptr, &iter);
exnStack, dbg, nullptr, &iter);
} }
/* static */ /* static */
@ -10503,16 +10500,10 @@ bool DebuggerFrame::evalMethod(JSContext* cx, unsigned argc, Value* vp) {
return false; return false;
} }
ResumeMode resumeMode; Rooted<Completion> comp(cx);
RootedValue value(cx); JS_TRY_VAR_OR_RETURN_FALSE(
RootedSavedFrame exnStack(cx); cx, comp, DebuggerFrame::eval(cx, frame, chars, nullptr, options));
if (!DebuggerFrame::eval(cx, frame, chars, nullptr, options, resumeMode, return comp.get().buildCompletionValue(cx, frame->owner(), args.rval());
&value, &exnStack)) {
return false;
}
return frame->owner()->newCompletionValue(cx, resumeMode, value, exnStack,
args.rval());
} }
/* static */ /* static */
@ -10541,16 +10532,10 @@ bool DebuggerFrame::evalWithBindingsMethod(JSContext* cx, unsigned argc,
return false; return false;
} }
ResumeMode resumeMode; Rooted<Completion> comp(cx);
RootedValue value(cx); JS_TRY_VAR_OR_RETURN_FALSE(
RootedSavedFrame exnStack(cx); cx, comp, DebuggerFrame::eval(cx, frame, chars, bindings, options));
if (!DebuggerFrame::eval(cx, frame, chars, bindings, options, resumeMode, return comp.get().buildCompletionValue(cx, frame->owner(), args.rval());
&value, &exnStack)) {
return false;
}
return frame->owner()->newCompletionValue(cx, resumeMode, value, exnStack,
args.rval());
} }
/* static */ /* static */
@ -11680,16 +11665,11 @@ bool DebuggerObject::executeInGlobalMethod(JSContext* cx, unsigned argc,
return false; return false;
} }
ResumeMode resumeMode; Rooted<Completion> comp(cx);
RootedValue value(cx); JS_TRY_VAR_OR_RETURN_FALSE(
RootedSavedFrame exnStack(cx); cx, comp,
if (!DebuggerObject::executeInGlobal(cx, object, chars, nullptr, options, DebuggerObject::executeInGlobal(cx, object, chars, nullptr, options));
resumeMode, &value, &exnStack)) { return comp.get().buildCompletionValue(cx, object->owner(), args.rval());
return false;
}
return object->owner()->newCompletionValue(cx, resumeMode, value, exnStack,
args.rval());
} }
/* static */ /* static */
@ -11724,16 +11704,11 @@ bool DebuggerObject::executeInGlobalWithBindingsMethod(JSContext* cx,
return false; return false;
} }
ResumeMode resumeMode; Rooted<Completion> comp(cx);
RootedValue value(cx); JS_TRY_VAR_OR_RETURN_FALSE(
RootedSavedFrame exnStack(cx); cx, comp,
if (!DebuggerObject::executeInGlobal(cx, object, chars, bindings, options, DebuggerObject::executeInGlobal(cx, object, chars, bindings, options));
resumeMode, &value, &exnStack)) { return comp.get().buildCompletionValue(cx, object->owner(), args.rval());
return false;
}
return object->owner()->newCompletionValue(cx, resumeMode, value, exnStack,
args.rval());
} }
/* static */ /* static */
@ -12693,21 +12668,18 @@ bool DebuggerObject::forceLexicalInitializationByName(
} }
/* static */ /* static */
bool DebuggerObject::executeInGlobal(JSContext* cx, HandleDebuggerObject object, Result<Completion> DebuggerObject::executeInGlobal(
mozilla::Range<const char16_t> chars, JSContext* cx, HandleDebuggerObject object,
HandleObject bindings, mozilla::Range<const char16_t> chars, HandleObject bindings,
const EvalOptions& options, const EvalOptions& options) {
ResumeMode& resumeMode,
MutableHandleValue value,
MutableHandleSavedFrame exnStack) {
MOZ_ASSERT(object->isGlobal()); MOZ_ASSERT(object->isGlobal());
Rooted<GlobalObject*> referent(cx, &object->referent()->as<GlobalObject>()); Rooted<GlobalObject*> referent(cx, &object->referent()->as<GlobalObject>());
Debugger* dbg = object->owner(); Debugger* dbg = object->owner();
RootedObject globalLexical(cx, &referent->lexicalEnvironment()); RootedObject globalLexical(cx, &referent->lexicalEnvironment());
return DebuggerGenericEval(cx, chars, bindings, options, resumeMode, value, return DebuggerGenericEval(cx, chars, bindings, options, dbg, globalLexical,
exnStack, dbg, globalLexical, nullptr); nullptr);
} }
/* static */ /* static */

Просмотреть файл

@ -1648,13 +1648,10 @@ class DebuggerFrame : public NativeObject {
HandleDebuggerFrame frame, HandleDebuggerFrame frame,
OnStepHandler* handler); OnStepHandler* handler);
static MOZ_MUST_USE bool eval(JSContext* cx, HandleDebuggerFrame frame, static MOZ_MUST_USE JS::Result<Completion> eval(
mozilla::Range<const char16_t> chars, JSContext* cx, HandleDebuggerFrame frame,
HandleObject bindings, mozilla::Range<const char16_t> chars, HandleObject bindings,
const EvalOptions& options, const EvalOptions& options);
ResumeMode& resumeMode,
MutableHandleValue value,
MutableHandleSavedFrame exnStack);
MOZ_MUST_USE bool requireLive(JSContext* cx); MOZ_MUST_USE bool requireLive(JSContext* cx);
static MOZ_MUST_USE DebuggerFrame* checkThis(JSContext* cx, static MOZ_MUST_USE DebuggerFrame* checkThis(JSContext* cx,
@ -1877,11 +1874,10 @@ class DebuggerObject : public NativeObject {
MutableHandleValue result); MutableHandleValue result);
static MOZ_MUST_USE bool forceLexicalInitializationByName( static MOZ_MUST_USE bool forceLexicalInitializationByName(
JSContext* cx, HandleDebuggerObject object, HandleId id, bool& result); JSContext* cx, HandleDebuggerObject object, HandleId id, bool& result);
static MOZ_MUST_USE bool executeInGlobal( static MOZ_MUST_USE JS::Result<Completion> executeInGlobal(
JSContext* cx, HandleDebuggerObject object, JSContext* cx, HandleDebuggerObject object,
mozilla::Range<const char16_t> chars, HandleObject bindings, mozilla::Range<const char16_t> chars, HandleObject bindings,
const EvalOptions& options, ResumeMode& resumeMode, const EvalOptions& options);
MutableHandleValue value, MutableHandleSavedFrame exnStack);
static MOZ_MUST_USE bool makeDebuggeeValue(JSContext* cx, static MOZ_MUST_USE bool makeDebuggeeValue(JSContext* cx,
HandleDebuggerObject object, HandleDebuggerObject object,
HandleValue value, HandleValue value,