Added support for Javascript RegExp constructor from string.

git-svn-id: http://yate.null.ro/svn/yate/trunk@5825 acf43c95-373e-0410-b603-e72c3f656dc1
This commit is contained in:
oana 2014-04-18 13:37:49 +00:00
parent 92ec1d54be
commit 06536919fe
2 changed files with 50 additions and 0 deletions

View File

@ -1060,6 +1060,47 @@ bool JsRegExp::runNative(ObjList& stack, const ExpOperation& oper, GenObject* co
return true;
}
JsObject* JsRegExp::runConstructor(ObjList& stack, const ExpOperation& oper, GenObject* context)
{
ObjList args;
switch (extractArgs(stack,oper,context,args)) {
case 1:
case 2:
break;
default:
return 0;
}
ExpOperation* pattern = static_cast<ExpOperation*>(args[0]);
ExpOperation* flags = static_cast<ExpOperation*>(args[1]);
if (!pattern)
return 0;
bool insensitive = false;
bool extended = true;
if (flags) {
const char* f = *flags;
char c = *f++;
while (c) {
switch (c) {
case 'i':
c = *f++;
insensitive = true;
break;
case 'b':
c = *f++;
extended = false;
break;
default:
c = 0;
}
}
}
if (!ref())
return 0;
JsRegExp* obj = new JsRegExp(mutex(),*pattern,*pattern,insensitive,extended);
obj->params().addParam(new ExpWrapper(this,protoName()));
return obj;
}
bool JsMath::runNative(ObjList& stack, const ExpOperation& oper, GenObject* context)
{

View File

@ -2355,6 +2355,15 @@ public:
inline Regexp& regexp()
{ return m_regexp; }
/**
* RegExp object constructor, it's run on the prototype
* @param stack Evaluation stack in use
* @param oper Constructor function to evaluate
* @param context Pointer to arbitrary object passed from evaluation methods
* @return New created and populated Javascript RegExp object
*/
virtual JsObject* runConstructor(ObjList& stack, const ExpOperation& oper, GenObject* context);
protected:
/**
* Clone and rename method