Backed out changeset 6705f67ab798 (bug 1253137)

--HG--
extra : rebase_source : 50109cbdf90d54c1b8d82374381680fec407bd07
This commit is contained in:
Carsten "Tomcat" Book 2016-03-03 09:21:13 +01:00
Родитель ae2683ef0c
Коммит 6a28be1924
2 изменённых файлов: 21 добавлений и 45 удалений

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

@ -454,19 +454,14 @@ class Encoder
return bytecode_.append(bytes, numBytes);
}
// A "section" is a contiguous range of bytes that stores its own size so
// A "section" is a contiguous region of bytes that stores its own size so
// that it may be trivially skipped without examining the contents. Sections
// require backpatching since the size of the section is only known at the
// end while the size's uint32 must be stored at the beginning. Immediately
// after the section length is the string id of the section.
// end while the size's uint32 must be stored at the beginning.
template <size_t IdSizeWith0>
MOZ_WARN_UNUSED_RESULT bool startSection(const char (&id)[IdSizeWith0], size_t* offset) {
static const size_t IdSize = IdSizeWith0 - 1;
MOZ_ASSERT(id[IdSize] == '\0');
MOZ_WARN_UNUSED_RESULT bool startSection(const char* name, size_t* offset) {
return writePatchableVarU32(offset) &&
writeVarU32(IdSize) &&
writeRawData(reinterpret_cast<const uint8_t*>(id), IdSize);
writeCString(name);
}
void finishSection(size_t offset) {
return patchVarU32(offset, bytecode_.length() - offset - varU32ByteLength(offset));
@ -692,44 +687,32 @@ class Decoder
static const uint32_t NotStarted = UINT32_MAX;
template <size_t IdSizeWith0>
MOZ_WARN_UNUSED_RESULT bool startSection(const char (&id)[IdSizeWith0], uint32_t* startOffset) {
static const size_t IdSize = IdSizeWith0 - 1;
MOZ_ASSERT(id[IdSize] == '\0');
MOZ_WARN_UNUSED_RESULT bool startSection(const char* name, uint32_t* startOffset) {
const uint8_t* before = cur_;
uint32_t size;
if (!readVarU32(&size))
goto backup;
if (bytesRemain() < size)
uint32_t numBytes;
if (!readVarU32(&numBytes) || bytesRemain() < numBytes)
return false;
uint32_t idSize;
if (!readVarU32(&idSize))
goto backup;
if (bytesRemain() < idSize)
return false;
if (idSize != IdSize || !!memcmp(cur_, id, IdSize))
goto backup;
cur_ += IdSize;
if (!readCStringIf(name)) {
cur_ = before;
*startOffset = NotStarted;
return true;
}
*startOffset = before - beg_;
return true;
backup:
cur_ = before;
*startOffset = NotStarted;
return true;
}
MOZ_WARN_UNUSED_RESULT bool finishSection(uint32_t startOffset) {
uint32_t currentOffset = cur_ - beg_;
cur_ = beg_ + startOffset;
uint32_t size = uncheckedReadVarU32();
uint32_t afterSize = cur_ - beg_;
uint32_t numBytes = uncheckedReadVarU32();
uint32_t afterNumBytes = cur_ - beg_;
cur_ = beg_ + currentOffset;
return size == (currentOffset - afterSize);
return numBytes == (currentOffset - afterNumBytes);
}
MOZ_WARN_UNUSED_RESULT bool skipSection() {
uint32_t size;
if (!readVarU32(&size) || bytesRemain() < size)
uint32_t numBytes;
if (!readVarU32(&numBytes) || bytesRemain() < numBytes)
return false;
cur_ += size;
cur_ += numBytes;
return true;
}

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

@ -66,24 +66,17 @@ var o = wasmEval(toBuf(moduleHeaderThen(0)));
assertEq(Object.getOwnPropertyNames(o).length, 0);
assertErrorMessage(() => wasmEval(toBuf(moduleHeaderThen(1))), TypeError, sectionError);
assertErrorMessage(() => wasmEval(toBuf(moduleHeaderThen(0, 0))), TypeError, extraError);
assertErrorMessage(() => wasmEval(toBuf(moduleHeaderThen(0, 1))), TypeError, sectionError);
assertErrorMessage(() => wasmEval(toBuf(moduleHeaderThen(0, 1))), TypeError, extraError);
function cstring(name) {
return (name + '\0').split('').map(c => c.charCodeAt(0));
}
function string(name) {
return name.split('').map(c => c.charCodeAt(0));
}
function moduleWithSections(sectionArray) {
var bytes = moduleHeaderThen();
for (let section of sectionArray) {
var nameLength = varU32(section.name.length);
bytes.push(...varU32(nameLength.length + section.name.length + section.body.length));
bytes.push(...nameLength);
bytes.push(...string(section.name));
bytes.push(...varU32(section.name.length + 1 + section.body.length));
bytes.push(...cstring(section.name));
bytes.push(...section.body);
}
bytes.push(0);