summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--js/src/vm/GeneratorObject.cpp6
-rw-r--r--js/src/vm/Stack-inl.h21
-rw-r--r--js/src/vm/Stack.h1
3 files changed, 26 insertions, 2 deletions
diff --git a/js/src/vm/GeneratorObject.cpp b/js/src/vm/GeneratorObject.cpp
index be6a30a60a..082e382663 100644
--- a/js/src/vm/GeneratorObject.cpp
+++ b/js/src/vm/GeneratorObject.cpp
@@ -23,6 +23,7 @@ GeneratorObject::create(JSContext* cx, AbstractFramePtr frame)
MOZ_ASSERT(frame.script()->isStarGenerator() || frame.script()->isLegacyGenerator() ||
frame.script()->isAsync());
MOZ_ASSERT(frame.script()->nfixed() == 0);
+ MOZ_ASSERT_IF(frame.isConstructing(), frame.script()->isLegacyGenerator());
Rooted<GlobalObject*> global(cx, cx->global());
RootedNativeObject obj(cx);
@@ -52,7 +53,10 @@ GeneratorObject::create(JSContext* cx, AbstractFramePtr frame)
GeneratorObject* genObj = &obj->as<GeneratorObject>();
genObj->setCallee(*frame.callee());
- genObj->setNewTarget(frame.newTarget());
+ if (frame.script()->isLegacyGenerator()) {
+ // Only legacy generators can be called with |new|
+ genObj->setNewTarget(frame.newTarget());
+ }
genObj->setEnvironmentChain(*frame.environmentChain());
if (frame.script()->needsArgsObj())
genObj->setArgsObj(frame.argsObj());
diff --git a/js/src/vm/Stack-inl.h b/js/src/vm/Stack-inl.h
index 27c71d04aa..9114a6a79e 100644
--- a/js/src/vm/Stack-inl.h
+++ b/js/src/vm/Stack-inl.h
@@ -345,7 +345,14 @@ InterpreterStack::resumeGeneratorCallFrame(JSContext* cx, InterpreterRegs& regs,
LifoAlloc::Mark mark = allocator_.mark();
- MaybeConstruct constructing = MaybeConstruct(newTarget.isObject());
+ MaybeConstruct constructing = NO_CONSTRUCT;
+ // (Async) generators and async functions are never constructors, legacy generators may be
+ if (callee->isLegacyGenerator()) {
+ constructing = MaybeConstruct(newTarget.isObject());
+ MOZ_ASSERT_IF(constructing, callee->isConstructor());
+ } else {
+ MOZ_ASSERT(!callee->isConstructor());
+ }
// Include callee, |this|, and maybe |new.target|
unsigned nformal = callee->nargs();
@@ -668,6 +675,18 @@ AbstractFramePtr::unsetIsDebuggee()
}
inline bool
+AbstractFramePtr::isConstructing() const
+{
+ if (isInterpreterFrame())
+ return asInterpreterFrame()->isConstructing();
+ if (isBaselineFrame())
+ return asBaselineFrame()->isConstructing();
+ if (isRematerializedFrame())
+ return asRematerializedFrame()->isConstructing();
+ MOZ_CRASH("Unexpected frame");
+}
+
+inline bool
AbstractFramePtr::hasArgs() const {
return isFunctionFrame();
}
diff --git a/js/src/vm/Stack.h b/js/src/vm/Stack.h
index b0d29831a3..8c45d8d4d9 100644
--- a/js/src/vm/Stack.h
+++ b/js/src/vm/Stack.h
@@ -228,6 +228,7 @@ class AbstractFramePtr
inline Value calleev() const;
inline Value& thisArgument() const;
+ inline bool isConstructing() const;
inline Value newTarget() const;
inline bool debuggerNeedsCheckPrimitiveReturn() const;