зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1688534 - Part 3: Add HasIndexOrDuplicatePropName flags. r=tcampbell
This flag is used in the next patch. Differential Revision: https://phabricator.services.mozilla.com/D103552
This commit is contained in:
Родитель
13df350334
Коммит
16905203c9
|
@ -1689,13 +1689,13 @@ bool BytecodeEmitter::iteratorResultShape(GCThingIndex* outShape) {
|
|||
ObjLiteralWriter writer;
|
||||
writer.beginObject(flags);
|
||||
|
||||
writer.setPropName(compilationState.parserAtoms,
|
||||
TaggedParserAtomIndex::WellKnown::value());
|
||||
writer.setPropNameNoDuplicateCheck(compilationState.parserAtoms,
|
||||
TaggedParserAtomIndex::WellKnown::value());
|
||||
if (!writer.propWithUndefinedValue(cx)) {
|
||||
return false;
|
||||
}
|
||||
writer.setPropName(compilationState.parserAtoms,
|
||||
TaggedParserAtomIndex::WellKnown::done());
|
||||
writer.setPropNameNoDuplicateCheck(compilationState.parserAtoms,
|
||||
TaggedParserAtomIndex::WellKnown::done());
|
||||
if (!writer.propWithUndefinedValue(cx)) {
|
||||
return false;
|
||||
}
|
||||
|
@ -8940,8 +8940,10 @@ bool BytecodeEmitter::emitPropertyListObjLiteral(ListNode* obj,
|
|||
ParseNode* key = prop->left();
|
||||
|
||||
if (key->is<NameNode>()) {
|
||||
writer.setPropName(compilationState.parserAtoms,
|
||||
key->as<NameNode>().atom());
|
||||
if (!writer.setPropName(cx, compilationState.parserAtoms,
|
||||
key->as<NameNode>().atom())) {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
double numValue = key->as<NumericLiteral>().value();
|
||||
int32_t i = 0;
|
||||
|
@ -9004,7 +9006,9 @@ bool BytecodeEmitter::emitDestructuringRestExclusionSetObjLiteral(
|
|||
atom = key->as<NameNode>().atom();
|
||||
}
|
||||
|
||||
writer.setPropName(compilationState.parserAtoms, atom);
|
||||
if (!writer.setPropName(cx, compilationState.parserAtoms, atom)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!writer.propWithUndefinedValue(cx)) {
|
||||
return false;
|
||||
|
|
|
@ -158,6 +158,10 @@ static void DumpObjLiteralFlagsItems(js::JSONPrinter& json,
|
|||
json.value("Singleton");
|
||||
flags -= ObjLiteralFlag::Singleton;
|
||||
}
|
||||
if (flags.contains(ObjLiteralFlag::HasIndexOrDuplicatePropName)) {
|
||||
json.value("HasIndexOrDuplicatePropName");
|
||||
flags -= ObjLiteralFlag::HasIndexOrDuplicatePropName;
|
||||
}
|
||||
|
||||
if (!flags.isEmpty()) {
|
||||
json.value("Unknown(%x)", flags.serialize());
|
||||
|
|
|
@ -10,9 +10,11 @@
|
|||
|
||||
#include "mozilla/EndianUtils.h"
|
||||
#include "mozilla/EnumSet.h"
|
||||
#include "mozilla/HashTable.h" // HashSet
|
||||
#include "mozilla/Span.h"
|
||||
|
||||
#include "frontend/ParserAtom.h" // ParserAtomsTable, TaggedParserAtomIndex
|
||||
#include "frontend/TaggedParserAtomIndexHasher.h" // TaggedParserAtomIndexHasher
|
||||
#include "js/AllocPolicy.h"
|
||||
#include "js/GCPolicyAPI.h"
|
||||
#include "js/Value.h"
|
||||
|
@ -138,6 +140,11 @@ enum class ObjLiteralFlag : uint8_t {
|
|||
// If set, this is an object literal in a singleton context and property
|
||||
// values are included. See also JSOp::Object.
|
||||
Singleton = 2,
|
||||
|
||||
// If set, this object contains index property, or duplicate non-index
|
||||
// property.
|
||||
// This flag is valid only if Array flag isn't set.
|
||||
HasIndexOrDuplicatePropName = 3,
|
||||
};
|
||||
|
||||
using ObjLiteralFlags = mozilla::EnumSet<ObjLiteralFlag>;
|
||||
|
@ -288,9 +295,30 @@ struct ObjLiteralWriter : private ObjLiteralWriterBase {
|
|||
uint32_t getPropertyCount() const { return propertyCount_; }
|
||||
|
||||
void beginObject(ObjLiteralFlags flags) { flags_ = flags; }
|
||||
void setPropName(frontend::ParserAtomsTable& parserAtoms,
|
||||
bool setPropName(JSContext* cx, frontend::ParserAtomsTable& parserAtoms,
|
||||
const frontend::TaggedParserAtomIndex propName) {
|
||||
// Only valid in object-mode.
|
||||
setPropNameNoDuplicateCheck(parserAtoms, propName);
|
||||
|
||||
if (flags_.contains(ObjLiteralFlag::HasIndexOrDuplicatePropName)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
auto p = propNames_.lookupForAdd(propName);
|
||||
if (!p) {
|
||||
if (!propNames_.add(p, propName)) {
|
||||
js::ReportOutOfMemory(cx);
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
flags_ += ObjLiteralFlag::HasIndexOrDuplicatePropName;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
void setPropNameNoDuplicateCheck(
|
||||
frontend::ParserAtomsTable& parserAtoms,
|
||||
const frontend::TaggedParserAtomIndex propName) {
|
||||
// Only valid in object-mode.
|
||||
MOZ_ASSERT(!flags_.contains(ObjLiteralFlag::Array));
|
||||
parserAtoms.markUsedByStencil(propName);
|
||||
nextKey_ = ObjLiteralKey::fromPropName(propName);
|
||||
|
@ -300,6 +328,7 @@ struct ObjLiteralWriter : private ObjLiteralWriterBase {
|
|||
MOZ_ASSERT(!flags_.contains(ObjLiteralFlag::Array));
|
||||
MOZ_ASSERT(propIndex <= ATOM_INDEX_MASK);
|
||||
nextKey_ = ObjLiteralKey::fromArrayIndex(propIndex);
|
||||
flags_ += ObjLiteralFlag::HasIndexOrDuplicatePropName;
|
||||
}
|
||||
void beginDenseArrayElements() {
|
||||
// Only valid in array-mode.
|
||||
|
@ -355,6 +384,9 @@ struct ObjLiteralWriter : private ObjLiteralWriterBase {
|
|||
ObjLiteralFlags flags_;
|
||||
ObjLiteralKey nextKey_;
|
||||
uint32_t propertyCount_ = 0;
|
||||
mozilla::HashSet<frontend::TaggedParserAtomIndex,
|
||||
frontend::TaggedParserAtomIndexHasher>
|
||||
propNames_;
|
||||
};
|
||||
|
||||
struct ObjLiteralReaderBase {
|
||||
|
|
Загрузка…
Ссылка в новой задаче