Added prototypes to parsed JSON objects and arrays.

git-svn-id: http://voip.null.ro/svn/yate@6020 acf43c95-373e-0410-b603-e72c3f656dc1
This commit is contained in:
paulc 2015-08-21 13:07:19 +00:00
parent 1580dfbbab
commit 9bb6e439e1
3 changed files with 9 additions and 6 deletions

View File

@ -2558,7 +2558,7 @@ void JsCode::resolveObjectParams(JsObject* object, ObjList& stack, GenObject* co
temp = new NamedString(op->name(),*ns);
object->params().setParam(temp);
}
if (object->frozen())
if (object->frozen() || object->params().getParam(JsObject::protoName()))
return;
JsArray* arr = YOBJECT(JsArray,object);
if (arr) {
@ -2587,7 +2587,6 @@ void JsCode::resolveObjectParams(JsObject* object, ObjList& stack, GenObject* co
if (objCtr)
arrayProto = YOBJECT(JsArray,objCtr->params().getParam(YSTRING("prototype")));
resolveObjectParams(object,stack,context,ctx,objProto,arrayProto);
}
@ -3566,7 +3565,7 @@ ScriptRun::Status JsParser::eval(const String& text, ExpOperation** result, Scri
}
// Parse JSON using native methods
ExpOperation* JsParser::parseJSON(const char* text, Mutex* mtx)
ExpOperation* JsParser::parseJSON(const char* text, Mutex* mtx, ObjList* stack, GenObject* context)
{
if (!text)
return 0;
@ -3575,6 +3574,8 @@ ExpOperation* JsParser::parseJSON(const char* text, Mutex* mtx)
ParsePoint pp(text,code);
if (code->parseSimple(pp,true,mtx))
ret = code->popOpcode();
if (stack)
code->resolveObjectParams(YOBJECT(JsObject,ret),*stack,context);
TelEngine::destruct(code);
return ret;
}

View File

@ -2597,9 +2597,11 @@ public:
* Parse a complete block of JSON text
* @param text JSON text to parse
* @param mtx Pointer to the mutex that serializes this object
* @param stack Pointer to an execution stack, required for adding prototypes
* @param context Pointer to an execution context, required for adding prototypes
* @return ExpOperation holding the content of JSON, must be dereferenced after use, NULL if parse error
*/
static ExpOperation* parseJSON(const char* text, Mutex* mtx = 0);
static ExpOperation* parseJSON(const char* text, Mutex* mtx = 0, ObjList* stack = 0, GenObject* context = 0);
/**
* Get a "null" object wrapper that will identity match another "null"

View File

@ -3028,7 +3028,7 @@ bool JsJSON::runNative(ObjList& stack, const ExpOperation& oper, GenObject* cont
if (oper.name() == YSTRING("parse")) {
if (extractArgs(stack,oper,context,args) != 1)
return false;
ExpOperation* op = JsParser::parseJSON(static_cast<ExpOperation*>(args[0])->c_str(),mutex());
ExpOperation* op = JsParser::parseJSON(static_cast<ExpOperation*>(args[0])->c_str(),mutex(),&stack,context);
if (!op)
op = new ExpWrapper(0,"JSON");
ExpEvaluator::pushOne(stack,op);
@ -3056,7 +3056,7 @@ bool JsJSON::runNative(ObjList& stack, const ExpOperation& oper, GenObject* cont
char* text = (char*)buf.data();
if (f.readData(text,len) == len) {
text[len] = '\0';
op = JsParser::parseJSON(text,mutex());
op = JsParser::parseJSON(text,mutex(),&stack,context);
}
}
}