Ignore:
Timestamp:
Mar 9, 2011, 6:22:50 PM (14 years ago)
Author:
[email protected]
Message:

Bug 56041 - RexExp constructor should only accept flags "gim"
Fix for issues introduced in r80667.

Reviewed by Sam Weinig.

Source/JavaScriptCore:

Invalid flags to a RegExp literal are a late syntax error!

  • bytecode/CodeBlock.h:

(JSC::CodeBlock::addRegExp):

  • Pass a PassRefPtr<RegExp>
  • bytecompiler/BytecodeGenerator.cpp:

(JSC::BytecodeGenerator::addRegExp):
(JSC::BytecodeGenerator::emitNewRegExp):

  • bytecompiler/BytecodeGenerator.h:
    • Pass a PassRefPtr<RegExp>
  • bytecompiler/NodesCodegen.cpp:

(JSC::RegExpNode::emitBytecode):

  • Should not be ASSERTing that the flags are valid - this is a late(er) error.
  • interpreter/Interpreter.cpp:

(JSC::Interpreter::privateExecute):

  • Need to check for error from RegExp constructor.
  • jit/JITStubs.cpp:

(JSC::DEFINE_STUB_FUNCTION):

  • Need to check for error from RegExp constructor.
  • runtime/RegExp.h:

(JSC::RegExp::isValid):

  • Make isValid check that the regexp was created with valid flags.
  • runtime/RegExpKey.h:
    • Since we'll not create RegExp objects with invalid flags, separate out the deleted value.

LayoutTests:

  • fast/regex/script-tests/parentheses.js:
  • fast/regex/script-tests/pcre-test-1.js:
    • Providing invalid flags to RegExp literals is an error in ES5.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/jit/JITStubs.cpp

    r80598 r80684  
    30703070    STUB_INIT_STACK_FRAME(stackFrame);
    30713071
    3072     return new (stackFrame.globalData) RegExpObject(stackFrame.callFrame->lexicalGlobalObject(), stackFrame.callFrame->lexicalGlobalObject()->regExpStructure(), stackFrame.args[0].regExp());
     3072    CallFrame* callFrame = stackFrame.callFrame;
     3073
     3074    RegExp* regExp = stackFrame.args[0].regExp();
     3075    if (!regExp->isValid()) {
     3076        stackFrame.globalData->exception = createSyntaxError(callFrame, "Invalid flags supplied to RegExp constructor.");
     3077        VM_THROW_EXCEPTION();
     3078    }
     3079
     3080    return new (stackFrame.globalData) RegExpObject(stackFrame.callFrame->lexicalGlobalObject(), stackFrame.callFrame->lexicalGlobalObject()->regExpStructure(), regExp);
    30733081}
    30743082
Note: See TracChangeset for help on using the changeset viewer.