Package org.mozilla.javascript.regexp
Class NativeRegExp
java.lang.Object
org.mozilla.javascript.ScriptableObject
org.mozilla.javascript.IdScriptableObject
org.mozilla.javascript.regexp.NativeRegExp
- All Implemented Interfaces:
Serializable
,ConstProperties
,DebuggableObject
,IdFunctionCall
,Scriptable
,SymbolScriptable
- Direct Known Subclasses:
NativeRegExpCallable
This class implements the RegExp native object.
Revision History: Implementation in C by Brendan Eich Initial port to Java by Norris Boyd from jsregexp.c version 1.36 Merged up to version 1.38, which included Unicode support. Merged bug fixes in version 1.39. Merged JSFUN13_BRANCH changes up to 1.32.2.13
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from class org.mozilla.javascript.ScriptableObject
ScriptableObject.KeyComparator
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final int
private static final boolean
private static final int
private static final int
private static final int
private static final int
private static final int
private static final int
private static final int
private static final int
private static final int
private static final int
private static final int
private static final int
static final int
static final int
static final int
(package private) Object
private int
static final int
private static final int
private static final int
static final int
private RECompiled
private static final Object
private static final byte
private static final byte
private static final byte
private static final byte
private static final byte
private static final byte
private static final byte
private static final byte
private static final byte
private static final byte
private static final byte
private static final byte
private static final byte
private static final byte
private static final byte
private static final byte
private static final byte
private static final byte
private static final byte
private static final byte
private static final byte
private static final byte
private static final byte
private static final byte
private static final byte
private static final byte
private static final byte
private static final byte
private static final byte
private static final byte
private static final byte
private static final byte
private static final byte
private static final byte
private static final byte
private static final byte
private static final byte
private static final byte
private static final byte
private static final byte
private static final byte
private static final byte
private static final byte
private static final byte
private static final byte
private static final byte
private static final long
private static final int
private static final int
static final int
Fields inherited from class org.mozilla.javascript.ScriptableObject
CONST, DONTENUM, EMPTY, PERMANENT, READONLY, UNINITIALIZED_CONST
Fields inherited from interface org.mozilla.javascript.Scriptable
NOT_FOUND
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate static void
addCharacterRangeToCharSet
(RECharSet cs, char c1, char c2) private static void
addCharacterToCharSet
(RECharSet cs, char c) private static int
addIndex
(byte[] array, int pc, int index) private static boolean
backrefMatcher
(REGlobalData gData, int parenIndex, String input, int end) private static boolean
calculateBitmapSize
(CompilerState state, RENode target, char[] src, int index, int end) private static boolean
classMatcher
(REGlobalData gData, RECharSet charSet, char ch) (package private) Scriptable
compile
(Context cx, Scriptable scope, Object[] args) (package private) static RECompiled
private static void
doFlat
(CompilerState state, char c) private static char
downcase
(char ch) private static int
emitREBytecode
(CompilerState state, RECompiled re, int pc, RENode t) private static String
escapeRegExp
(Object src) execIdCall
(IdFunctionObject f, Context cx, Scriptable scope, Scriptable thisObj, Object[] args) 'thisObj' will be null if invoked as constructor, in which case * instance of Scriptable should be returned.(package private) Object
execSub
(Context cx, Scriptable scopeObj, Object[] args, int matchType) private static boolean
executeREBytecode
(REGlobalData gData, String input, int end) (package private) Object
executeRegExp
(Context cx, Scriptable scope, RegExpImpl res, String str, int[] indexp, int matchType) protected int
Map name to id of instance property.protected int
protected int
private static boolean
flatNIMatcher
(REGlobalData gData, int matchChars, int length, String input, int end) private static boolean
flatNMatcher
(REGlobalData gData, int matchChars, int length, String input, int end) Return the name of the class.private static int
getDecimalValue
(char c, CompilerState state, int maxValue, String overflowMessageId) (package private) int
getFlags()
private static RegExpImpl
private static int
getIndex
(byte[] array, int pc) protected String
getInstanceIdName
(int id) Map id back to property name it defines.protected Object
getInstanceIdValue
(int id) Get id value.protected int
Get maximum id findInstanceIdInfo can generate.private static int
getOffset
(byte[] array, int pc) Gets the value to be returned by the typeof operator called on this object.static void
init
(Context cx, Scriptable scope, boolean sealed) protected void
initPrototypeId
(int id) private static boolean
isControlLetter
(char c) (package private) static boolean
isDigit
(char c) private static boolean
isLineTerm
(char c) private static boolean
isREWhiteSpace
(int c) private static boolean
isWord
(char c) private static boolean
matchRegExp
(REGlobalData gData, RECompiled re, String input, int start, int end, boolean multiline) private static boolean
parseAlternative
(CompilerState state) private static boolean
parseDisjunction
(CompilerState state) private static boolean
parseTerm
(CompilerState state) private static REProgState
popProgState
(REGlobalData gData) private static void
processCharSet
(REGlobalData gData, RECharSet charSet) private static void
processCharSetImpl
(REGlobalData gData, RECharSet charSet) private static void
pushBackTrackState
(REGlobalData gData, byte op, int pc) private static void
pushBackTrackState
(REGlobalData gData, byte op, int pc, int cp, int continuationOp, int continuationPc) private static void
pushProgState
(REGlobalData gData, int min, int max, int cp, REBackTrackData backTrackLastToSave, int continuationOp, int continuationPc) private static NativeRegExp
realThis
(Scriptable thisObj, IdFunctionObject f) private static boolean
reopIsSimple
(int op) private static void
reportError
(String messageId, String arg) private static void
reportWarning
(Context cx, String messageId, String arg) private static void
resolveForwardJump
(byte[] array, int from, int pc) protected void
setInstanceIdAttributes
(int id, int attr) Update the attributes of the given instance property.protected void
setInstanceIdValue
(int id, Object value) Set or delete id value.private void
setLastIndex
(Object value) private static int
simpleMatch
(REGlobalData gData, String input, int op, byte[] program, int pc, int end, boolean updatecp) private static int
toASCIIHexDigit
(int c) toString()
private static char
upcase
(char ch) Methods inherited from class org.mozilla.javascript.IdScriptableObject
activatePrototypeMap, addIdFunctionProperty, defaultGet, defaultHas, defaultPut, defineOwnProperty, delete, delete, ensureType, exportAsJSClass, fillConstructorProperties, findInstanceIdInfo, get, get, getAttributes, getAttributes, getOwnPropertyDescriptor, has, has, hasPrototypeMap, initPrototypeConstructor, initPrototypeMethod, initPrototypeMethod, initPrototypeMethod, initPrototypeValue, initPrototypeValue, instanceIdInfo, put, put, setAttributes
Methods inherited from class org.mozilla.javascript.ScriptableObject
applyDescriptorToAttributeBitset, associateValue, avoidObjectDetection, buildDataDescriptor, callMethod, callMethod, checkPropertyChange, checkPropertyDefinition, defineClass, defineClass, defineClass, defineConst, defineConstProperty, defineFunctionProperties, defineOwnProperties, defineOwnProperty, defineProperty, defineProperty, defineProperty, defineProperty, defineProperty, defineProperty, delete, deleteProperty, deleteProperty, ensureScriptable, ensureScriptableObject, ensureSymbolScriptable, equivalentValues, get, get, getAllIds, getArrayPrototype, getAssociatedValue, getAttributes, getAttributes, getAttributes, getClassPrototype, getDefaultValue, getDefaultValue, getExternalArrayData, getExternalArrayLength, getFunctionPrototype, getGeneratorFunctionPrototype, getGetterOrSetter, getGetterOrSetter, getIds, getObjectPrototype, getParentScope, getProperty, getProperty, getProperty, getPropertyIds, getPrototype, getTopLevelScope, getTopScopeValue, getTypedProperty, getTypedProperty, has, hasInstance, hasProperty, hasProperty, hasProperty, isAccessorDescriptor, isConst, isDataDescriptor, isEmpty, isExtensible, isFalse, isGenericDescriptor, isGetterOrSetter, isSealed, isTrue, preventExtensions, put, putConst, putConstProperty, putProperty, putProperty, putProperty, querySlot, redefineProperty, sameValue, sealObject, setAttributes, setAttributes, setAttributes, setAttributes, setCommonDescriptorProperties, setExternalArrayData, setGetterOrSetter, setParentScope, setPrototype, size
-
Field Details
-
serialVersionUID
private static final long serialVersionUID- See Also:
-
REGEXP_TAG
-
JSREG_GLOB
public static final int JSREG_GLOB- See Also:
-
JSREG_FOLD
public static final int JSREG_FOLD- See Also:
-
JSREG_MULTILINE
public static final int JSREG_MULTILINE- See Also:
-
TEST
public static final int TEST- See Also:
-
MATCH
public static final int MATCH- See Also:
-
PREFIX
public static final int PREFIX- See Also:
-
debug
private static final boolean debug- See Also:
-
REOP_SIMPLE_START
private static final byte REOP_SIMPLE_START- See Also:
-
REOP_EMPTY
private static final byte REOP_EMPTY- See Also:
-
REOP_BOL
private static final byte REOP_BOL- See Also:
-
REOP_EOL
private static final byte REOP_EOL- See Also:
-
REOP_WBDRY
private static final byte REOP_WBDRY- See Also:
-
REOP_WNONBDRY
private static final byte REOP_WNONBDRY- See Also:
-
REOP_DOT
private static final byte REOP_DOT- See Also:
-
REOP_DIGIT
private static final byte REOP_DIGIT- See Also:
-
REOP_NONDIGIT
private static final byte REOP_NONDIGIT- See Also:
-
REOP_ALNUM
private static final byte REOP_ALNUM- See Also:
-
REOP_NONALNUM
private static final byte REOP_NONALNUM- See Also:
-
REOP_SPACE
private static final byte REOP_SPACE- See Also:
-
REOP_NONSPACE
private static final byte REOP_NONSPACE- See Also:
-
REOP_BACKREF
private static final byte REOP_BACKREF- See Also:
-
REOP_FLAT
private static final byte REOP_FLAT- See Also:
-
REOP_FLAT1
private static final byte REOP_FLAT1- See Also:
-
REOP_FLATi
private static final byte REOP_FLATi- See Also:
-
REOP_FLAT1i
private static final byte REOP_FLAT1i- See Also:
-
REOP_UCFLAT1
private static final byte REOP_UCFLAT1- See Also:
-
REOP_UCFLAT1i
private static final byte REOP_UCFLAT1i- See Also:
-
REOP_CLASS
private static final byte REOP_CLASS- See Also:
-
REOP_NCLASS
private static final byte REOP_NCLASS- See Also:
-
REOP_SIMPLE_END
private static final byte REOP_SIMPLE_END- See Also:
-
REOP_QUANT
private static final byte REOP_QUANT- See Also:
-
REOP_STAR
private static final byte REOP_STAR- See Also:
-
REOP_PLUS
private static final byte REOP_PLUS- See Also:
-
REOP_OPT
private static final byte REOP_OPT- See Also:
-
REOP_LPAREN
private static final byte REOP_LPAREN- See Also:
-
REOP_RPAREN
private static final byte REOP_RPAREN- See Also:
-
REOP_ALT
private static final byte REOP_ALT- See Also:
-
REOP_JUMP
private static final byte REOP_JUMP- See Also:
-
REOP_ASSERT
private static final byte REOP_ASSERT- See Also:
-
REOP_ASSERT_NOT
private static final byte REOP_ASSERT_NOT- See Also:
-
REOP_ASSERTTEST
private static final byte REOP_ASSERTTEST- See Also:
-
REOP_ASSERTNOTTEST
private static final byte REOP_ASSERTNOTTEST- See Also:
-
REOP_MINIMALSTAR
private static final byte REOP_MINIMALSTAR- See Also:
-
REOP_MINIMALPLUS
private static final byte REOP_MINIMALPLUS- See Also:
-
REOP_MINIMALOPT
private static final byte REOP_MINIMALOPT- See Also:
-
REOP_MINIMALQUANT
private static final byte REOP_MINIMALQUANT- See Also:
-
REOP_ENDCHILD
private static final byte REOP_ENDCHILD- See Also:
-
REOP_REPEAT
private static final byte REOP_REPEAT- See Also:
-
REOP_MINIMALREPEAT
private static final byte REOP_MINIMALREPEAT- See Also:
-
REOP_ALTPREREQ
private static final byte REOP_ALTPREREQ- See Also:
-
REOP_ALTPREREQi
private static final byte REOP_ALTPREREQi- See Also:
-
REOP_ALTPREREQ2
private static final byte REOP_ALTPREREQ2- See Also:
-
REOP_END
private static final byte REOP_END- See Also:
-
ANCHOR_BOL
private static final int ANCHOR_BOL- See Also:
-
INDEX_LEN
private static final int INDEX_LEN- See Also:
-
Id_lastIndex
private static final int Id_lastIndex- See Also:
-
Id_source
private static final int Id_source- See Also:
-
Id_global
private static final int Id_global- See Also:
-
Id_ignoreCase
private static final int Id_ignoreCase- See Also:
-
Id_multiline
private static final int Id_multiline- See Also:
-
MAX_INSTANCE_ID
private static final int MAX_INSTANCE_ID- See Also:
-
Id_compile
private static final int Id_compile- See Also:
-
Id_toString
private static final int Id_toString- See Also:
-
Id_toSource
private static final int Id_toSource- See Also:
-
Id_exec
private static final int Id_exec- See Also:
-
Id_test
private static final int Id_test- See Also:
-
Id_prefix
private static final int Id_prefix- See Also:
-
SymbolId_match
private static final int SymbolId_match- See Also:
-
SymbolId_search
private static final int SymbolId_search- See Also:
-
MAX_PROTOTYPE_ID
private static final int MAX_PROTOTYPE_ID- See Also:
-
re
-
lastIndex
Object lastIndex -
lastIndexAttr
private int lastIndexAttr
-
-
Constructor Details
-
NativeRegExp
NativeRegExp(Scriptable scope, RECompiled regexpCompiled) -
NativeRegExp
NativeRegExp()
-
-
Method Details
-
init
-
getClassName
Description copied from class:ScriptableObject
Return the name of the class.This is typically the same name as the constructor. Classes extending ScriptableObject must implement this abstract method.
- Specified by:
getClassName
in interfaceScriptable
- Specified by:
getClassName
in classScriptableObject
-
getTypeOf
Gets the value to be returned by the typeof operator called on this object.- Overrides:
getTypeOf
in classScriptableObject
- Returns:
- "object"
- See Also:
-
compile
-
toString
-
getImpl
-
escapeRegExp
-
execSub
-
compileRE
-
isDigit
static boolean isDigit(char c) -
isWord
private static boolean isWord(char c) -
isControlLetter
private static boolean isControlLetter(char c) -
isLineTerm
private static boolean isLineTerm(char c) -
isREWhiteSpace
private static boolean isREWhiteSpace(int c) -
upcase
private static char upcase(char ch) -
downcase
private static char downcase(char ch) -
toASCIIHexDigit
private static int toASCIIHexDigit(int c) -
parseDisjunction
-
parseAlternative
-
calculateBitmapSize
private static boolean calculateBitmapSize(CompilerState state, RENode target, char[] src, int index, int end) -
doFlat
-
getDecimalValue
private static int getDecimalValue(char c, CompilerState state, int maxValue, String overflowMessageId) -
parseTerm
-
resolveForwardJump
private static void resolveForwardJump(byte[] array, int from, int pc) -
getOffset
private static int getOffset(byte[] array, int pc) -
addIndex
private static int addIndex(byte[] array, int pc, int index) -
getIndex
private static int getIndex(byte[] array, int pc) -
emitREBytecode
-
pushProgState
private static void pushProgState(REGlobalData gData, int min, int max, int cp, REBackTrackData backTrackLastToSave, int continuationOp, int continuationPc) -
popProgState
-
pushBackTrackState
-
pushBackTrackState
private static void pushBackTrackState(REGlobalData gData, byte op, int pc, int cp, int continuationOp, int continuationPc) -
flatNMatcher
private static boolean flatNMatcher(REGlobalData gData, int matchChars, int length, String input, int end) -
flatNIMatcher
private static boolean flatNIMatcher(REGlobalData gData, int matchChars, int length, String input, int end) -
backrefMatcher
-
addCharacterToCharSet
-
addCharacterRangeToCharSet
-
processCharSet
-
processCharSetImpl
-
classMatcher
-
reopIsSimple
private static boolean reopIsSimple(int op) -
simpleMatch
private static int simpleMatch(REGlobalData gData, String input, int op, byte[] program, int pc, int end, boolean updatecp) -
executeREBytecode
-
matchRegExp
private static boolean matchRegExp(REGlobalData gData, RECompiled re, String input, int start, int end, boolean multiline) -
executeRegExp
Object executeRegExp(Context cx, Scriptable scope, RegExpImpl res, String str, int[] indexp, int matchType) -
getFlags
int getFlags() -
reportWarning
-
reportError
-
getMaxInstanceId
protected int getMaxInstanceId()Description copied from class:IdScriptableObject
Get maximum id findInstanceIdInfo can generate.- Overrides:
getMaxInstanceId
in classIdScriptableObject
-
findInstanceIdInfo
Description copied from class:IdScriptableObject
Map name to id of instance property. Should return 0 if not found or the result ofIdScriptableObject.instanceIdInfo(int, int)
.- Overrides:
findInstanceIdInfo
in classIdScriptableObject
-
getInstanceIdName
Description copied from class:IdScriptableObject
Map id back to property name it defines.- Overrides:
getInstanceIdName
in classIdScriptableObject
-
getInstanceIdValue
Description copied from class:IdScriptableObject
Get id value. * If id value is constant, descendant can call cacheIdValue to store * value in the permanent cache. * Default implementation creates IdFunctionObject instance for given id * and cache its value- Overrides:
getInstanceIdValue
in classIdScriptableObject
-
setLastIndex
-
setInstanceIdValue
Description copied from class:IdScriptableObject
Set or delete id value. If value == NOT_FOUND , the implementation should make sure that the following getInstanceIdValue return NOT_FOUND.- Overrides:
setInstanceIdValue
in classIdScriptableObject
-
setInstanceIdAttributes
protected void setInstanceIdAttributes(int id, int attr) Description copied from class:IdScriptableObject
Update the attributes of the given instance property. Classes which want to support changing property attributes via Object.defineProperty must override this method. The default implementation throws InternalError.- Overrides:
setInstanceIdAttributes
in classIdScriptableObject
- Parameters:
id
- the instance property idattr
- the new attribute bitset
-
initPrototypeId
protected void initPrototypeId(int id) - Overrides:
initPrototypeId
in classIdScriptableObject
-
execIdCall
public Object execIdCall(IdFunctionObject f, Context cx, Scriptable scope, Scriptable thisObj, Object[] args) Description copied from class:IdScriptableObject
'thisObj' will be null if invoked as constructor, in which case * instance of Scriptable should be returned.- Specified by:
execIdCall
in interfaceIdFunctionCall
- Overrides:
execIdCall
in classIdScriptableObject
-
realThis
-
findPrototypeId
- Overrides:
findPrototypeId
in classIdScriptableObject
-
findPrototypeId
- Overrides:
findPrototypeId
in classIdScriptableObject
-