Skip to content

Commit

Permalink
Restore runtime flag validation and unbump bytecode version
Browse files Browse the repository at this point in the history
Summary: Temporarily avoid incrementing bytecode version.

Reviewed By: avp

Differential Revision: D22055456

fbshipit-source-id: 4aa3e0e153a79f6d416ea270cc8a3c672f9d6ee9
  • Loading branch information
neildhar authored and facebook-github-bot committed Jun 16, 2020
1 parent 9a7d040 commit e9c80a0
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 9 deletions.
4 changes: 2 additions & 2 deletions include/hermes/BCGen/HBC/BytecodeFileFormat.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ const static uint64_t MAGIC = 0x1F1903C103BC1FC6;
const static uint64_t DELTA_MAGIC = ~MAGIC;

// Bytecode version generated by this version of the compiler.
// Updated: Jun 12, 2020
const static uint32_t BYTECODE_VERSION = 75;
// Updated: Jun 15, 2020
const static uint32_t BYTECODE_VERSION = 74;

/// Property cache index which indicates no caching.
static constexpr uint8_t PROPERTY_CACHING_DISABLED = 0;
Expand Down
17 changes: 11 additions & 6 deletions lib/VM/JSRegExp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,12 +136,20 @@ ExecutionStatus JSRegExp::initialize(
res != ExecutionStatus::EXCEPTION && *res &&
"defineOwnProperty() failed");

// Validate flags.
llvm::SmallVector<char16_t, 16> flagsText16;
flags->copyUTF16String(flagsText16);

auto sflags = regex::SyntaxFlags::fromString(flagsText16);
if (!sflags) {
runtime->raiseSyntaxError("Invalid RegExp: Invalid flags");
return ExecutionStatus::EXCEPTION;
}
selfHandle->syntaxFlags_ = *sflags;

if (bytecode) {
return selfHandle->initializeBytecode(*bytecode, runtime);
} else {
llvm::SmallVector<char16_t, 6> flagsText16;
flags->copyUTF16String(flagsText16);

llvm::SmallVector<char16_t, 16> patternText16;
pattern->copyUTF16String(patternText16);

Expand Down Expand Up @@ -169,9 +177,6 @@ ExecutionStatus JSRegExp::initializeBytecode(
runtime->raiseRangeError("RegExp size overflow");
return ExecutionStatus::EXCEPTION;
}
auto header =
reinterpret_cast<const regex::RegexBytecodeHeader *>(bytecode.data());
syntaxFlags_ = regex::SyntaxFlags::fromByte(header->syntaxFlags);
bytecodeSize_ = sz;
bytecode_ = (uint8_t *)checkedMalloc(sz);
memcpy(bytecode_, bytecode.data(), sz);
Expand Down
2 changes: 1 addition & 1 deletion tools/hbc-attribute/hbc-attribute.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ using SLG = hermes::hbc::SerializedLiteralGenerator;
* If you have added or modified sections, make sure they're counted properly.
*/
static_assert(
BYTECODE_VERSION == 75,
BYTECODE_VERSION == 74,
"Bytecode version changed. Please verify that hbc-attribute counts correctly..");

static llvm::cl::opt<std::string> InputFilename(
Expand Down

0 comments on commit e9c80a0

Please sign in to comment.