Merge remote-tracking branch 'origin/tracking' into custom

This commit is contained in:
roytam1 2024-09-06 09:18:37 +08:00
commit 8a8546f49f
12 changed files with 75 additions and 17 deletions

View file

@ -4143,8 +4143,15 @@ Parser<ParseHandler>::statementList(YieldHandling yieldHandling)
return null();
bool canHaveDirectives = pc->atBodyLevel();
if (canHaveDirectives)
if (canHaveDirectives) {
tokenStream.clearSawOctalEscape();
}
bool canHaveHashbangComment = pc->atTopLevel();
if (canHaveHashbangComment) {
tokenStream.consumeOptionalHashbangComment();
}
bool afterReturn = false;
bool warnedAboutStatementsAfterReturn = false;
uint32_t statementBegin = 0;

View file

@ -470,6 +470,12 @@ class ParseContext : public Nestable<ParseContext>
return atBodyLevel() && sc_->isModuleContext();
}
// True if we are at the topmost level of an entire script or module. For
// example, in the comment on |atBodyLevel()| above, we would encounter |f1|
// and the outermost |if (cond)| at top level, and everything else would not
// be at top level.
bool atTopLevel() { return atBodyLevel() && sc_->isTopLevelContext(); }
void setIsStandaloneFunctionBody() {
isStandaloneFunctionBody_ = true;
}

View file

@ -289,6 +289,16 @@ class SharedContext
bool isEvalContext() { return kind_ == Kind::Eval; }
inline EvalSharedContext* asEvalContext();
bool isTopLevelContext() const {
switch (kind_) {
case Kind::Module:
case Kind::Global:
case Kind::Eval:
return true;
}
return false;
}
ThisBinding thisBinding() const { return thisBinding_; }
bool hasModuleGoal() const { return hasModuleGoal_; }

View file

@ -1300,6 +1300,21 @@ TokenStream::putIdentInTokenbuf(const char16_t* identStart)
return true;
}
void
TokenStream::consumeOptionalHashbangComment() {
int c = userbuf.getRawChar();
if (c == '#') {
if (matchChar('!')) {
// Hashbang; ignore rest of line as comment.
while ((c = getChar()) != EOF && c != '\n')
continue;
}
}
ungetChar(c);
cursor = (cursor - 1) & ntokensMask;
}
enum FirstCharKind {
// A char16_t has the 'OneChar' kind if it, by itself, constitutes a valid
// token that cannot also be a prefix of a longer token. E.g. ';' has the

View file

@ -428,6 +428,13 @@ class MOZ_STACK_CLASS TokenStream
// asm.js reporter
void reportAsmJSError(uint32_t offset, unsigned errorNumber, ...);
/**
* Consume any hashbang comment at the start of a Script or Module, if one is
* present. Stops consuming just before any terminating LineTerminator or
* before an encoding error is encountered.
*/
void consumeOptionalHashbangComment();
JSAtom* getRawTemplateStringAtom() {
MOZ_ASSERT(currentToken().type == TOK_TEMPLATE_HEAD ||
currentToken().type == TOK_NO_SUBS_TEMPLATE);

View file

@ -188,21 +188,19 @@ FetchName(JSContext* cx, HandleObject obj, HandleObject obj2, HandlePropertyName
}
/* Take the slow path if shape was not found in a native object. */
if (!obj->isNative() || !obj2->isNative()) {
if (!obj->isNative() || !obj2->isNative() ||
obj->is<WithEnvironmentObject>()) {
Rooted<jsid> id(cx, NameToId(name));
if (!GetProperty(cx, obj, obj, id, vp))
return false;
} else {
RootedShape shape(cx, prop.shape());
RootedObject normalized(cx, obj);
if (normalized->is<WithEnvironmentObject>() && !shape->hasDefaultGetter())
normalized = &normalized->as<WithEnvironmentObject>().object();
if (shape->isDataDescriptor() && shape->hasDefaultGetter()) {
/* Fast path for Object instance properties. */
MOZ_ASSERT(shape->hasSlot());
vp.set(obj2->as<NativeObject>().getSlot(shape->slot()));
} else {
if (!NativeGetExistingProperty(cx, normalized, obj2.as<NativeObject>(), shape, vp))
if (!NativeGetExistingProperty(cx, obj, obj2.as<NativeObject>(), shape, vp))
return false;
}
}